Merge "Add KEY_ONLY_SINGLE_DC_ALLOWED_INT_ARRAY"
diff --git a/Android.mk b/Android.mk
index e352bc7..4fea0d4 100644
--- a/Android.mk
+++ b/Android.mk
@@ -288,7 +288,6 @@
 	core/java/android/view/accessibility/IAccessibilityManagerClient.aidl \
 	core/java/android/view/IApplicationToken.aidl \
 	core/java/android/view/IAppTransitionAnimationSpecsFuture.aidl \
-	core/java/android/view/IAssetAtlas.aidl \
 	core/java/android/view/IDockedStackListener.aidl \
 	core/java/android/view/IGraphicsStats.aidl \
 	core/java/android/view/IInputFilter.aidl \
@@ -860,6 +859,7 @@
     -since $(SRC_API_DIR)/22.txt 22 \
     -since $(SRC_API_DIR)/23.txt 23 \
     -since $(SRC_API_DIR)/24.txt 24 \
+    -since $(SRC_API_DIR)/25.txt 25 \
 		-werror -hide 111 -hide 113 \
 		-overview $(LOCAL_PATH)/core/java/overview.html
 
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
new file mode 100644
index 0000000..f5bd945
--- /dev/null
+++ b/PREUPLOAD.cfg
@@ -0,0 +1,7 @@
+[Hook Scripts]
+checkstyle_hook = ../../development/tools/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
+                  -fw core/java/android/animation/
+                      core/java/android/text/
+                      core/java/android/view/
+                      core/java/android/transition/
+                      core/java/android/widget/
diff --git a/apct-tests/perftests/core/src/android/graphics/perftests/CanvasPerfTest.java b/apct-tests/perftests/core/src/android/graphics/perftests/CanvasPerfTest.java
new file mode 100644
index 0000000..519d1f4
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/graphics/perftests/CanvasPerfTest.java
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2016 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.graphics.perftests;
+
+import android.graphics.Bitmap;
+import android.graphics.Color;
+import android.graphics.Bitmap.Config;
+import android.graphics.Paint;
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.support.test.filters.LargeTest;
+import android.view.DisplayListCanvas;
+import android.view.RenderNode;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+@LargeTest
+public class CanvasPerfTest {
+    @Rule
+    public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+    @Test
+    public void testBasicViewGroupDraw() {
+        // This test is a clone of BM_DisplayListCanvas_basicViewGroupDraw
+
+        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        RenderNode node = RenderNode.create("benchmark", null);
+        RenderNode child = RenderNode.create("child", null);
+        child.setLeftTopRightBottom(50, 50, 100, 100);
+
+        DisplayListCanvas canvas = node.start(100, 100);
+        node.end(canvas);
+        canvas = child.start(50, 50);
+        canvas.drawColor(Color.WHITE);
+        child.end(canvas);
+
+        while (state.keepRunning()) {
+            canvas = node.start(200, 200);
+            canvas.setHighContrastText(false);
+            int save = canvas.save();
+            canvas.clipRect(1, 1, 199, 199);
+            canvas.insertReorderBarrier();
+            for (int i = 0; i < 5; i++) {
+                canvas.drawRenderNode(child);
+            }
+            canvas.insertInorderBarrier();
+            canvas.restoreToCount(save);
+            node.end(canvas);
+        }
+    }
+
+    @Test
+    public void testRecordSimpleBitmapView() {
+        // This test is a clone of BM_DisplayListCanvas_record_simpleBitmapView
+
+        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        RenderNode node = RenderNode.create("benchmark", null);
+
+        DisplayListCanvas canvas = node.start(100, 100);
+        node.end(canvas);
+        Bitmap bitmap = Bitmap.createBitmap(80, 80, Config.ARGB_8888);
+        Paint paint = new Paint();
+        paint.setColor(Color.BLACK);
+
+        while (state.keepRunning()) {
+            canvas = node.start(100, 100);
+            {
+                canvas.save();
+                canvas.drawRect(0, 0, 100, 100, paint);
+                canvas.restore();
+            }
+            {
+                canvas.save();
+                canvas.translate(10, 10);
+                canvas.drawBitmap(bitmap, 0, 0, null);
+                canvas.restore();
+            }
+            node.end(canvas);
+        }
+    }
+}
diff --git a/apct-tests/perftests/core/src/java/lang/perftests/SystemPerfTest.java b/apct-tests/perftests/core/src/java/lang/perftests/SystemPerfTest.java
index 6a49c03..80ce22e 100644
--- a/apct-tests/perftests/core/src/java/lang/perftests/SystemPerfTest.java
+++ b/apct-tests/perftests/core/src/java/lang/perftests/SystemPerfTest.java
@@ -37,4 +37,10 @@
             System.nanoTime();
         }
     }
+
+    @Test
+    public void testBenchmarkOverhead() {
+        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+        while (state.keepRunning()) {}
+    }
 }
diff --git a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTest.java b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTest.java
index cdbca63..88cb8e6 100644
--- a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTest.java
+++ b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTest.java
@@ -57,8 +57,6 @@
 @LargeTest
 @RunWith(AndroidJUnit4.class)
 public class UserLifecycleTest {
-    private final int MIN_REPEAT_TIMES = 4;
-
     private final int TIMEOUT_REMOVE_USER_MS = 4 * 1000; // 4 sec
     private final int CHECK_USER_REMOVED_INTERVAL_MS = 200; // 0.2 sec
 
@@ -90,7 +88,6 @@
         mAm = context.getSystemService(ActivityManager.class);
         mIam = ActivityManagerNative.getDefault();
         mState = mPerfStatusReporter.getBenchmarkState();
-        mState.setMinRepeatTimes(MIN_REPEAT_TIMES);
         mUsersToRemove = new ArrayList<>();
     }
 
@@ -300,4 +297,4 @@
             mUsersToRemove.add(userId);
         }
     }
-}
\ No newline at end of file
+}
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java
index b27d71b..bf04f6d 100644
--- a/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/BenchmarkState.java
@@ -23,6 +23,7 @@
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.concurrent.TimeUnit;
 
 /**
  * Provides a benchmark framework.
@@ -41,39 +42,47 @@
  *     System.out.println(state.summaryLine());
  * }
  */
-public class BenchmarkState {
+public final class BenchmarkState {
     private static final String TAG = "BenchmarkState";
 
-    private static final int NOT_STARTED = 1;  // The benchmark has not started yet.
+    private static final int NOT_STARTED = 0;  // The benchmark has not started yet.
+    private static final int WARMUP = 1; // The benchmark is warming up.
     private static final int RUNNING = 2;  // The benchmark is running.
     private static final int RUNNING_PAUSED = 3;  // The benchmark is temporary paused.
     private static final int FINISHED = 4;  // The benchmark has stopped.
 
     private int mState = NOT_STARTED;  // Current benchmark state.
 
-    private long mNanoPreviousTime = 0;  // Previously captured System.nanoTime().
-    private long mNanoFinishTime = 0;  // Finish if System.nanoTime() returns after than this value.
-    private long mNanoPausedTime = 0; // The System.nanoTime() when the pauseTiming() is called.
-    private long mNanoPausedDuration = 0;  // The duration of paused state in nano sec.
-    private long mNanoTimeLimit = 1 * 1000 * 1000 * 1000;  // 1 sec. Default time limit.
+    private static final long WARMUP_DURATION_NS = ms2ns(250); // warm-up for at least 250ms
+    private static final int WARMUP_MIN_ITERATIONS = 16; // minimum iterations to warm-up for
+
+    // TODO: Tune these values.
+    private static final long TARGET_TEST_DURATION_NS = ms2ns(500); // target testing for 500 ms
+    private static final int MAX_TEST_ITERATIONS = 1000000;
+    private static final int MIN_TEST_ITERATIONS = 100;
+    private static final int REPEAT_COUNT = 5;
+
+    private long mStartTimeNs = 0;  // Previously captured System.nanoTime().
+    private long mPausedTimeNs = 0; // The System.nanoTime() when the pauseTiming() is called.
+    private long mPausedDurationNs = 0;  // The duration of paused state in nano sec.
+
+    private int mIteration = 0;
+    private int mMaxIterations = 0;
+
+    private int mRepeatCount = 0;
 
     // Statistics. These values will be filled when the benchmark has finished.
     // The computation needs double precision, but long int is fine for final reporting.
     private long mMedian = 0;
     private double mMean = 0.0;
     private double mStandardDeviation = 0.0;
-
-    // Number of iterations needed for calculating the stats.
-    private int mMinRepeatTimes = 16;
+    private long mMin = 0;
 
     // Individual duration in nano seconds.
     private ArrayList<Long> mResults = new ArrayList<>();
 
-    /**
-     * Sets the number of iterations needed for calculating the stats. Default is 16.
-     */
-    public void setMinRepeatTimes(int minRepeatTimes) {
-        mMinRepeatTimes = minRepeatTimes;
+    private static final long ms2ns(long ms) {
+        return TimeUnit.MILLISECONDS.toNanos(ms);
     }
 
     /**
@@ -89,8 +98,13 @@
         mMedian = size % 2 == 0 ? (mResults.get(size / 2) + mResults.get(size / 2 + 1)) / 2 :
                 mResults.get(size / 2);
 
+        mMin = mResults.get(0);
         for (int i = 0; i < size; ++i) {
-            mMean += mResults.get(i);
+            long result = mResults.get(i);
+            mMean += result;
+            if (result < mMin) {
+                mMin = result;
+            }
         }
         mMean /= (double) size;
 
@@ -108,7 +122,7 @@
             throw new IllegalStateException(
                     "Unable to pause the benchmark. The benchmark has already paused.");
         }
-        mNanoPausedTime = System.nanoTime();
+        mPausedTimeNs = System.nanoTime();
         mState = RUNNING_PAUSED;
     }
 
@@ -119,11 +133,43 @@
             throw new IllegalStateException(
                     "Unable to resume the benchmark. The benchmark is already running.");
         }
-        mNanoPausedDuration += System.nanoTime() - mNanoPausedTime;
-        mNanoPausedTime = 0;
+        mPausedDurationNs += System.nanoTime() - mPausedTimeNs;
+        mPausedTimeNs = 0;
         mState = RUNNING;
     }
 
+    private void beginWarmup() {
+        mStartTimeNs = System.nanoTime();
+        mIteration = 0;
+        mState = WARMUP;
+    }
+
+    private void beginBenchmark(long warmupDuration, int iterations) {
+        mMaxIterations = (int) (TARGET_TEST_DURATION_NS / (warmupDuration / iterations));
+        mMaxIterations = Math.min(MAX_TEST_ITERATIONS,
+                Math.max(mMaxIterations, MIN_TEST_ITERATIONS));
+        mPausedDurationNs = 0;
+        mIteration = 0;
+        mRepeatCount = 0;
+        mState = RUNNING;
+        mStartTimeNs = System.nanoTime();
+    }
+
+    private boolean startNextTestRun() {
+        final long currentTime = System.nanoTime();
+        mResults.add((currentTime - mStartTimeNs - mPausedDurationNs) / mMaxIterations);
+        mRepeatCount++;
+        if (mRepeatCount >= REPEAT_COUNT) {
+            calculateSatistics();
+            mState = FINISHED;
+            return false;
+        }
+        mPausedDurationNs = 0;
+        mIteration = 0;
+        mStartTimeNs = System.nanoTime();
+        return true;
+    }
+
     /**
      * Judges whether the benchmark needs more samples.
      *
@@ -132,23 +178,22 @@
     public boolean keepRunning() {
         switch (mState) {
             case NOT_STARTED:
-                mNanoPreviousTime = System.nanoTime();
-                mNanoFinishTime = mNanoPreviousTime + mNanoTimeLimit;
-                mState = RUNNING;
+                beginWarmup();
+                return true;
+            case WARMUP:
+                mIteration++;
+                // Only check nanoTime on every iteration in WARMUP since we
+                // don't yet have a target iteration count.
+                final long duration = System.nanoTime() - mStartTimeNs;
+                if (mIteration >= WARMUP_MIN_ITERATIONS && duration >= WARMUP_DURATION_NS) {
+                    beginBenchmark(duration, mIteration);
+                }
                 return true;
             case RUNNING:
-                final long currentTime = System.nanoTime();
-                mResults.add(currentTime - mNanoPreviousTime - mNanoPausedDuration);
-                mNanoPausedDuration = 0;
-
-                // To calculate statistics, needs two or more samples.
-                if (mResults.size() > mMinRepeatTimes && currentTime > mNanoFinishTime) {
-                    calculateSatistics();
-                    mState = FINISHED;
-                    return false;
+                mIteration++;
+                if (mIteration >= mMaxIterations) {
+                    return startNextTestRun();
                 }
-
-                mNanoPreviousTime = currentTime;
                 return true;
             case RUNNING_PAUSED:
                 throw new IllegalStateException(
@@ -161,21 +206,28 @@
         }
     }
 
-    public long mean() {
+    private long mean() {
         if (mState != FINISHED) {
             throw new IllegalStateException("The benchmark hasn't finished");
         }
         return (long) mMean;
     }
 
-    public long median() {
+    private long median() {
         if (mState != FINISHED) {
             throw new IllegalStateException("The benchmark hasn't finished");
         }
         return mMedian;
     }
 
-    public long standardDeviation() {
+    private long min() {
+        if (mState != FINISHED) {
+            throw new IllegalStateException("The benchmark hasn't finished");
+        }
+        return mMin;
+    }
+
+    private long standardDeviation() {
         if (mState != FINISHED) {
             throw new IllegalStateException("The benchmark hasn't finished");
         }
@@ -187,10 +239,11 @@
         sb.append("Summary: ");
         sb.append("median=").append(median()).append("ns, ");
         sb.append("mean=").append(mean()).append("ns, ");
+        sb.append("min=").append(min()).append("ns, ");
         sb.append("sigma=").append(standardDeviation()).append(", ");
         sb.append("iteration=").append(mResults.size()).append(", ");
         // print out the first few iterations' number for double checking.
-        int sampleNumber = Math.min(mResults.size(), mMinRepeatTimes);
+        int sampleNumber = Math.min(mResults.size(), 16);
         for (int i = 0; i < sampleNumber; i++) {
             sb.append("No ").append(i).append(" result is ").append(mResults.get(i)).append(", ");
         }
@@ -202,6 +255,7 @@
         Bundle status = new Bundle();
         status.putLong(key + "_median", median());
         status.putLong(key + "_mean", mean());
+        status.putLong(key + "_min", min());
         status.putLong(key + "_standardDeviation", standardDeviation());
         instrumentation.sendStatus(Activity.RESULT_OK, status);
     }
diff --git a/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java b/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java
index 3933b57..64b0bf5 100644
--- a/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java
+++ b/apct-tests/perftests/utils/src/android/perftests/utils/PerfStatusReporter.java
@@ -18,8 +18,9 @@
 
 import android.support.test.InstrumentationRegistry;
 
-import org.junit.rules.TestWatcher;
+import org.junit.rules.TestRule;
 import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
 
 import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertTrue;
@@ -47,7 +48,7 @@
  * name when using parameterization.
  */
 
-public class PerfStatusReporter extends TestWatcher {
+public class PerfStatusReporter implements TestRule {
     private final BenchmarkState mState = new BenchmarkState();
 
     public BenchmarkState getBenchmarkState() {
@@ -55,33 +56,39 @@
     }
 
     @Override
-    protected void succeeded(Description description) {
-        String invokeMethodName = description.getMethodName();
-        // validate and simplify the function name.
-        // First, remove the "test" prefix which normally comes from CTS test.
-        // Then make sure the [subTestName] is valid, not just numbers like [0].
-        if (invokeMethodName.startsWith("test")) {
-            assertTrue("The test name " + invokeMethodName + " is too short",
-                    invokeMethodName.length() > 5);
-            invokeMethodName = invokeMethodName.substring(4, 5).toLowerCase()
-                    + invokeMethodName.substring(5);
-        }
-
-        int index = invokeMethodName.lastIndexOf('[');
-        if (index > 0) {
-            boolean allDigits = true;
-            for (int i = index + 1; i < invokeMethodName.length() - 1; i++) {
-                if (!Character.isDigit(invokeMethodName.charAt(i))) {
-                    allDigits = false;
-                    break;
+    public Statement apply(Statement base, Description description) {
+        return new Statement() {
+            @Override
+            public void evaluate() throws Throwable {
+                String invokeMethodName = description.getMethodName();
+                // validate and simplify the function name.
+                // First, remove the "test" prefix which normally comes from CTS test.
+                // Then make sure the [subTestName] is valid, not just numbers like [0].
+                if (invokeMethodName.startsWith("test")) {
+                    assertTrue("The test name " + invokeMethodName + " is too short",
+                            invokeMethodName.length() > 5);
+                    invokeMethodName = invokeMethodName.substring(4, 5).toLowerCase()
+                            + invokeMethodName.substring(5);
                 }
+
+                int index = invokeMethodName.lastIndexOf('[');
+                if (index > 0) {
+                    boolean allDigits = true;
+                    for (int i = index + 1; i < invokeMethodName.length() - 1; i++) {
+                        if (!Character.isDigit(invokeMethodName.charAt(i))) {
+                            allDigits = false;
+                            break;
+                        }
+                    }
+                    assertFalse("The name in [] can't contain only digits for " + invokeMethodName,
+                            allDigits);
+                }
+
+                base.evaluate();
+
+                mState.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(),
+                        invokeMethodName);
             }
-            assertFalse("The name in [] can't contain only digits for " + invokeMethodName,
-                    allDigits);
-        }
-
-        mState.sendFullStatusReport(InstrumentationRegistry.getInstrumentation(),
-                invokeMethodName);
+        };
     }
-
 }
diff --git a/api/current.txt b/api/current.txt
index 66fea4a..225297a 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -855,6 +855,7 @@
     field public static final int mediaRouteTypes = 16843694; // 0x10103ae
     field public static final int menuCategory = 16843230; // 0x10101de
     field public static final int mimeType = 16842790; // 0x1010026
+    field public static final int min = 16843367; // 0x1010267
     field public static final int minDate = 16843583; // 0x101033f
     field public static final int minEms = 16843098; // 0x101015a
     field public static final int minHeight = 16843072; // 0x1010140
@@ -31682,6 +31683,7 @@
     method public static void notifyDirectoryChange(android.content.ContentResolver);
     field public static final java.lang.String ACCOUNT_NAME = "accountName";
     field public static final java.lang.String ACCOUNT_TYPE = "accountType";
+    field public static final java.lang.String CALLER_PACKAGE_PARAM_KEY = "callerPackage";
     field public static final java.lang.String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_directory";
     field public static final java.lang.String CONTENT_TYPE = "vnd.android.cursor.dir/contact_directories";
     field public static final android.net.Uri CONTENT_URI;
@@ -34852,6 +34854,7 @@
     method public static void requestRebind(android.content.ComponentName);
     method public final void requestUnbind();
     method public final void setNotificationsShown(java.lang.String[]);
+    method public final void snoozeNotification(java.lang.String, long);
     field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
     field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
     field public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS = 2; // 0x2
@@ -45843,6 +45846,7 @@
     method public deprecated void freeMemory();
     method public android.net.http.SslCertificate getCertificate();
     method public int getContentHeight();
+    method public static android.content.pm.PackageInfo getCurrentWebViewPackage();
     method public android.graphics.Bitmap getFavicon();
     method public android.webkit.WebView.HitTestResult getHitTestResult();
     method public deprecated java.lang.String[] getHttpAuthUsernamePassword(java.lang.String, java.lang.String);
@@ -47476,6 +47480,7 @@
     method public android.graphics.PorterDuff.Mode getIndeterminateTintMode();
     method public android.view.animation.Interpolator getInterpolator();
     method public synchronized int getMax();
+    method public synchronized int getMin();
     method public synchronized int getProgress();
     method public android.content.res.ColorStateList getProgressBackgroundTintList();
     method public android.graphics.PorterDuff.Mode getProgressBackgroundTintMode();
@@ -47498,6 +47503,7 @@
     method public void setInterpolator(android.content.Context, int);
     method public void setInterpolator(android.view.animation.Interpolator);
     method public synchronized void setMax(int);
+    method public synchronized void setMin(int);
     method public synchronized void setProgress(int);
     method public void setProgress(int, boolean);
     method public void setProgressBackgroundTintList(android.content.res.ColorStateList);
diff --git a/api/system-current.txt b/api/system-current.txt
index fa2489d..de1bbd3 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -962,6 +962,7 @@
     field public static final int mediaRouteTypes = 16843694; // 0x10103ae
     field public static final int menuCategory = 16843230; // 0x10101de
     field public static final int mimeType = 16842790; // 0x1010026
+    field public static final int min = 16843367; // 0x1010267
     field public static final int minDate = 16843583; // 0x101033f
     field public static final int minEms = 16843098; // 0x101015a
     field public static final int minHeight = 16843072; // 0x1010140
@@ -34306,6 +34307,7 @@
     method public static void notifyDirectoryChange(android.content.ContentResolver);
     field public static final java.lang.String ACCOUNT_NAME = "accountName";
     field public static final java.lang.String ACCOUNT_TYPE = "accountType";
+    field public static final java.lang.String CALLER_PACKAGE_PARAM_KEY = "callerPackage";
     field public static final java.lang.String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_directory";
     field public static final java.lang.String CONTENT_TYPE = "vnd.android.cursor.dir/contact_directories";
     field public static final android.net.Uri CONTENT_URI;
@@ -37632,6 +37634,7 @@
     method public final void requestUnbind();
     method public final void setNotificationsShown(java.lang.String[]);
     method public final void setOnNotificationPostedTrim(int);
+    method public final void snoozeNotification(java.lang.String, long);
     method public void unregisterAsSystemService() throws android.os.RemoteException;
     field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
     field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
@@ -37693,6 +37696,7 @@
     field public static final int REASON_PACKAGE_CHANGED = 5; // 0x5
     field public static final int REASON_PACKAGE_SUSPENDED = 14; // 0xe
     field public static final int REASON_PROFILE_TURNED_OFF = 15; // 0xf
+    field public static final int REASON_SNOOZED = 18; // 0x12
     field public static final int REASON_UNAUTOBUNDLED = 16; // 0x10
     field public static final int REASON_USER_STOPPED = 6; // 0x6
     field public static final java.lang.String SERVICE_INTERFACE = "android.service.notification.NotificationRankerService";
@@ -49119,6 +49123,7 @@
     method public deprecated void freeMemory();
     method public android.net.http.SslCertificate getCertificate();
     method public int getContentHeight();
+    method public static android.content.pm.PackageInfo getCurrentWebViewPackage();
     method public android.graphics.Bitmap getFavicon();
     method public android.webkit.WebView.HitTestResult getHitTestResult();
     method public deprecated java.lang.String[] getHttpAuthUsernamePassword(java.lang.String, java.lang.String);
@@ -51015,6 +51020,7 @@
     method public android.graphics.PorterDuff.Mode getIndeterminateTintMode();
     method public android.view.animation.Interpolator getInterpolator();
     method public synchronized int getMax();
+    method public synchronized int getMin();
     method public synchronized int getProgress();
     method public android.content.res.ColorStateList getProgressBackgroundTintList();
     method public android.graphics.PorterDuff.Mode getProgressBackgroundTintMode();
@@ -51037,6 +51043,7 @@
     method public void setInterpolator(android.content.Context, int);
     method public void setInterpolator(android.view.animation.Interpolator);
     method public synchronized void setMax(int);
+    method public synchronized void setMin(int);
     method public synchronized void setProgress(int);
     method public void setProgress(int, boolean);
     method public void setProgressBackgroundTintList(android.content.res.ColorStateList);
diff --git a/api/test-current.txt b/api/test-current.txt
index 065f4ff..2d0fa49 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -855,6 +855,7 @@
     field public static final int mediaRouteTypes = 16843694; // 0x10103ae
     field public static final int menuCategory = 16843230; // 0x10101de
     field public static final int mimeType = 16842790; // 0x1010026
+    field public static final int min = 16843367; // 0x1010267
     field public static final int minDate = 16843583; // 0x101033f
     field public static final int minEms = 16843098; // 0x101015a
     field public static final int minHeight = 16843072; // 0x1010140
@@ -31760,6 +31761,7 @@
     method public static void notifyDirectoryChange(android.content.ContentResolver);
     field public static final java.lang.String ACCOUNT_NAME = "accountName";
     field public static final java.lang.String ACCOUNT_TYPE = "accountType";
+    field public static final java.lang.String CALLER_PACKAGE_PARAM_KEY = "callerPackage";
     field public static final java.lang.String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/contact_directory";
     field public static final java.lang.String CONTENT_TYPE = "vnd.android.cursor.dir/contact_directories";
     field public static final android.net.Uri CONTENT_URI;
@@ -34933,6 +34935,7 @@
     method public static void requestRebind(android.content.ComponentName);
     method public final void requestUnbind();
     method public final void setNotificationsShown(java.lang.String[]);
+    method public final void snoozeNotification(java.lang.String, long);
     field public static final int HINT_HOST_DISABLE_CALL_EFFECTS = 4; // 0x4
     field public static final int HINT_HOST_DISABLE_EFFECTS = 1; // 0x1
     field public static final int HINT_HOST_DISABLE_NOTIFICATION_EFFECTS = 2; // 0x2
@@ -41025,6 +41028,156 @@
 
 }
 
+package android.util.proto {
+
+  public final class EncodedBuffer {
+    ctor public EncodedBuffer();
+    ctor public EncodedBuffer(int);
+    method public void dumpBuffers(java.lang.String);
+    method public static void dumpByteString(java.lang.String, java.lang.String, byte[]);
+    method public void editRawFixed32(int, int);
+    method public byte[] getBytes(int);
+    method public int getChunkCount();
+    method public java.lang.String getDebugString();
+    method public int getRawFixed32At(int);
+    method public static int getRawVarint32Size(int);
+    method public static int getRawVarint64Size(long);
+    method public static int getRawZigZag32Size(int);
+    method public static int getRawZigZag64Size(long);
+    method public int getReadPos();
+    method public int getReadableSize();
+    method public int getWriteBufIndex();
+    method public int getWriteIndex();
+    method public int getWritePos();
+    method public byte readRawByte();
+    method public int readRawFixed32();
+    method public long readRawUnsigned();
+    method public void rewindRead();
+    method public void rewindWriteTo(int);
+    method public void skipRead(int);
+    method public void startEditing();
+    method public void writeFromThisBuffer(int, int);
+    method public void writeRawBuffer(byte[]);
+    method public void writeRawBuffer(byte[], int, int);
+    method public void writeRawByte(byte);
+    method public void writeRawFixed32(int);
+    method public void writeRawFixed64(long);
+    method public void writeRawVarint32(int);
+    method public void writeRawVarint64(long);
+    method public void writeRawZigZag32(int);
+    method public void writeRawZigZag64(long);
+  }
+
+  public final class ProtoOutputStream {
+    ctor public ProtoOutputStream();
+    ctor public ProtoOutputStream(int);
+    method public static int checkFieldId(long, long);
+    method public static int convertObjectIdToOrdinal(int);
+    method public void dump(java.lang.String);
+    method public void endObject(long);
+    method public void endRepeatedObject(long);
+    method public byte[] getBytes();
+    method public static int getDepthFromToken(long);
+    method public static int getObjectIdFromToken(long);
+    method public static boolean getRepeatedFromToken(long);
+    method public static int getSizePosFromToken(long);
+    method public static int getTagSizeFromToken(long);
+    method public static long makeFieldId(int, long);
+    method public static long makeToken(int, boolean, int, int, int);
+    method public long startObject(long);
+    method public long startRepeatedObject(long);
+    method public static java.lang.String token2String(long);
+    method public void writeBool(long, boolean);
+    method public void writeBytes(long, byte[]);
+    method public void writeDouble(long, double);
+    method public void writeEnum(long, int);
+    method public void writeFixed32(long, int);
+    method public void writeFixed64(long, long);
+    method public void writeFloat(long, float);
+    method public void writeInt32(long, int);
+    method public void writeInt64(long, long);
+    method public void writePackedBool(long, boolean[]);
+    method public void writePackedDouble(long, double[]);
+    method public void writePackedEnum(long, int[]);
+    method public void writePackedFixed32(long, int[]);
+    method public void writePackedFixed64(long, long[]);
+    method public void writePackedFloat(long, float[]);
+    method public void writePackedInt32(long, int[]);
+    method public void writePackedInt64(long, long[]);
+    method public void writePackedSFixed32(long, int[]);
+    method public void writePackedSFixed64(long, long[]);
+    method public void writePackedSInt32(long, int[]);
+    method public void writePackedSInt64(long, long[]);
+    method public void writePackedUInt32(long, int[]);
+    method public void writePackedUInt64(long, long[]);
+    method public void writeRepeatedBool(long, boolean);
+    method public void writeRepeatedBytes(long, byte[]);
+    method public void writeRepeatedDouble(long, double);
+    method public void writeRepeatedEnum(long, int);
+    method public void writeRepeatedFixed32(long, int);
+    method public void writeRepeatedFixed64(long, long);
+    method public void writeRepeatedFloat(long, float);
+    method public void writeRepeatedInt32(long, int);
+    method public void writeRepeatedInt64(long, long);
+    method public void writeRepeatedSFixed32(long, int);
+    method public void writeRepeatedSFixed64(long, long);
+    method public void writeRepeatedSInt32(long, int);
+    method public void writeRepeatedSInt64(long, long);
+    method public void writeRepeatedString(long, java.lang.String);
+    method public void writeRepeatedUInt32(long, int);
+    method public void writeRepeatedUInt64(long, long);
+    method public void writeSFixed32(long, int);
+    method public void writeSFixed64(long, long);
+    method public void writeSInt32(long, int);
+    method public void writeSInt64(long, long);
+    method public void writeString(long, java.lang.String);
+    method public void writeTag(int, int);
+    method public void writeUInt32(long, int);
+    method public void writeUInt64(long, long);
+    field public static final long FIELD_COUNT_MASK = 16492674416640L; // 0xf0000000000L
+    field public static final long FIELD_COUNT_PACKED = 5497558138880L; // 0x50000000000L
+    field public static final long FIELD_COUNT_REPEATED = 2199023255552L; // 0x20000000000L
+    field public static final int FIELD_COUNT_SHIFT = 40; // 0x28
+    field public static final long FIELD_COUNT_SINGLE = 1099511627776L; // 0x10000000000L
+    field public static final long FIELD_COUNT_UNKNOWN = 0L; // 0x0L
+    field public static final int FIELD_ID_MASK = -8; // 0xfffffff8
+    field public static final int FIELD_ID_SHIFT = 3; // 0x3
+    field public static final long FIELD_TYPE_BOOL = 55834574848L; // 0xd00000000L
+    field public static final long FIELD_TYPE_BYTES = 64424509440L; // 0xf00000000L
+    field public static final long FIELD_TYPE_DOUBLE = 4294967296L; // 0x100000000L
+    field public static final long FIELD_TYPE_ENUM = 68719476736L; // 0x1000000000L
+    field public static final long FIELD_TYPE_FIXED32 = 38654705664L; // 0x900000000L
+    field public static final long FIELD_TYPE_FIXED64 = 42949672960L; // 0xa00000000L
+    field public static final long FIELD_TYPE_FLOAT = 8589934592L; // 0x200000000L
+    field public static final long FIELD_TYPE_INT32 = 12884901888L; // 0x300000000L
+    field public static final long FIELD_TYPE_INT64 = 17179869184L; // 0x400000000L
+    field public static final long FIELD_TYPE_MASK = 1095216660480L; // 0xff00000000L
+    field public static final long FIELD_TYPE_OBJECT = 73014444032L; // 0x1100000000L
+    field public static final long FIELD_TYPE_SFIXED32 = 47244640256L; // 0xb00000000L
+    field public static final long FIELD_TYPE_SFIXED64 = 51539607552L; // 0xc00000000L
+    field public static final int FIELD_TYPE_SHIFT = 32; // 0x20
+    field public static final long FIELD_TYPE_SINT32 = 30064771072L; // 0x700000000L
+    field public static final long FIELD_TYPE_SINT64 = 34359738368L; // 0x800000000L
+    field public static final long FIELD_TYPE_STRING = 60129542144L; // 0xe00000000L
+    field public static final long FIELD_TYPE_UINT32 = 21474836480L; // 0x500000000L
+    field public static final long FIELD_TYPE_UINT64 = 25769803776L; // 0x600000000L
+    field public static final long FIELD_TYPE_UNKNOWN = 0L; // 0x0L
+    field public static final java.lang.String TAG = "ProtoOutputStream";
+    field public static final int WIRE_TYPE_END_GROUP = 4; // 0x4
+    field public static final int WIRE_TYPE_FIXED32 = 5; // 0x5
+    field public static final int WIRE_TYPE_FIXED64 = 1; // 0x1
+    field public static final int WIRE_TYPE_LENGTH_DELIMITED = 2; // 0x2
+    field public static final int WIRE_TYPE_MASK = 7; // 0x7
+    field public static final int WIRE_TYPE_START_GROUP = 3; // 0x3
+    field public static final int WIRE_TYPE_VARINT = 0; // 0x0
+  }
+
+  public class ProtoParseException extends java.lang.RuntimeException {
+    ctor public ProtoParseException(java.lang.String);
+  }
+
+}
+
 package android.view {
 
   public abstract class AbsSavedState implements android.os.Parcelable {
@@ -45931,6 +46084,7 @@
     method public deprecated void freeMemory();
     method public android.net.http.SslCertificate getCertificate();
     method public int getContentHeight();
+    method public static android.content.pm.PackageInfo getCurrentWebViewPackage();
     method public android.graphics.Bitmap getFavicon();
     method public android.webkit.WebView.HitTestResult getHitTestResult();
     method public deprecated java.lang.String[] getHttpAuthUsernamePassword(java.lang.String, java.lang.String);
@@ -47569,6 +47723,7 @@
     method public android.graphics.PorterDuff.Mode getIndeterminateTintMode();
     method public android.view.animation.Interpolator getInterpolator();
     method public synchronized int getMax();
+    method public synchronized int getMin();
     method public synchronized int getProgress();
     method public android.content.res.ColorStateList getProgressBackgroundTintList();
     method public android.graphics.PorterDuff.Mode getProgressBackgroundTintMode();
@@ -47591,6 +47746,7 @@
     method public void setInterpolator(android.content.Context, int);
     method public void setInterpolator(android.view.animation.Interpolator);
     method public synchronized void setMax(int);
+    method public synchronized void setMin(int);
     method public synchronized void setProgress(int);
     method public void setProgress(int, boolean);
     method public void setProgressBackgroundTintList(android.content.res.ColorStateList);
diff --git a/cmds/am/src/com/android/commands/am/Am.java b/cmds/am/src/com/android/commands/am/Am.java
index 1996174..e197bfc 100644
--- a/cmds/am/src/com/android/commands/am/Am.java
+++ b/cmds/am/src/com/android/commands/am/Am.java
@@ -63,6 +63,7 @@
 import android.text.TextUtils;
 import android.util.AndroidException;
 import android.util.ArrayMap;
+import android.util.Log;
 import android.view.IWindowManager;
 
 import com.android.internal.os.BaseCommand;
@@ -385,7 +386,9 @@
 
         String op = nextArgRequired();
 
-        if (op.equals("instrument")) {
+        if (op.equals("broadcast")) {
+            sendBroadcast();
+        } else if (op.equals("instrument")) {
             runInstrument();
         } else {
             runAmCmd(getRawArgs());
@@ -456,6 +459,90 @@
         }
     }
 
+    private Intent makeIntent(int defUser) throws URISyntaxException {
+        mStartFlags = 0;
+        mWaitOption = false;
+        mStopOption = false;
+        mRepeat = 0;
+        mProfileFile = null;
+        mSamplingInterval = 0;
+        mAutoStop = false;
+        mUserId = defUser;
+        mStackId = INVALID_STACK_ID;
+
+        return Intent.parseCommandArgs(mArgs, new Intent.CommandOptionHandler() {
+            @Override
+            public boolean handleOption(String opt, ShellCommand cmd) {
+                if (opt.equals("-D")) {
+                    mStartFlags |= ActivityManager.START_FLAG_DEBUG;
+                } else if (opt.equals("-N")) {
+                    mStartFlags |= ActivityManager.START_FLAG_NATIVE_DEBUGGING;
+                } else if (opt.equals("-W")) {
+                    mWaitOption = true;
+                } else if (opt.equals("-P")) {
+                    mProfileFile = nextArgRequired();
+                    mAutoStop = true;
+                } else if (opt.equals("--start-profiler")) {
+                    mProfileFile = nextArgRequired();
+                    mAutoStop = false;
+                } else if (opt.equals("--sampling")) {
+                    mSamplingInterval = Integer.parseInt(nextArgRequired());
+                } else if (opt.equals("-R")) {
+                    mRepeat = Integer.parseInt(nextArgRequired());
+                } else if (opt.equals("-S")) {
+                    mStopOption = true;
+                } else if (opt.equals("--track-allocation")) {
+                    mStartFlags |= ActivityManager.START_FLAG_TRACK_ALLOCATION;
+                } else if (opt.equals("--user")) {
+                    mUserId = UserHandle.parseUserArg(nextArgRequired());
+                } else if (opt.equals("--receiver-permission")) {
+                    mReceiverPermission = nextArgRequired();
+                } else if (opt.equals("--stack")) {
+                    mStackId = Integer.parseInt(nextArgRequired());
+                } else {
+                    return false;
+                }
+                return true;
+            }
+        });
+    }
+
+    private class IntentReceiver extends IIntentReceiver.Stub {
+        private boolean mFinished = false;
+
+        @Override
+        public void performReceive(Intent intent, int resultCode, String data, Bundle extras,
+                boolean ordered, boolean sticky, int sendingUser) {
+            String line = "Broadcast completed: result=" + resultCode;
+            if (data != null) line = line + ", data=\"" + data + "\"";
+            if (extras != null) line = line + ", extras: " + extras;
+            System.out.println(line);
+            synchronized (this) {
+                mFinished = true;
+                notifyAll();
+            }
+        }
+
+        public synchronized void waitForFinish() {
+            try {
+                while (!mFinished) wait();
+            } catch (InterruptedException e) {
+                throw new IllegalStateException(e);
+            }
+        }
+    }
+
+    private void sendBroadcast() throws Exception {
+        Intent intent = makeIntent(UserHandle.USER_CURRENT);
+        IntentReceiver receiver = new IntentReceiver();
+        String[] requiredPermissions = mReceiverPermission == null ? null
+                : new String[] {mReceiverPermission};
+        System.out.println("Broadcasting: " + intent);
+        mAm.broadcastIntent(null, intent, null, receiver, 0, null, null, requiredPermissions,
+                android.app.AppOpsManager.OP_NONE, null, true, false, mUserId);
+        receiver.waitForFinish();
+    }
+
     private void runInstrument() throws Exception {
         String profileFile = null;
         boolean wait = false;
diff --git a/cmds/idmap/scan.cpp b/cmds/idmap/scan.cpp
index 6d30f0d..ab6adfb 100644
--- a/cmds/idmap/scan.cpp
+++ b/cmds/idmap/scan.cpp
@@ -1,5 +1,6 @@
 #include <dirent.h>
 #include <inttypes.h>
+#include <sys/file.h>
 #include <sys/stat.h>
 
 #include "idmap.h"
@@ -35,16 +36,31 @@
 
     bool writePackagesList(const char *filename, const SortedVector<Overlay>& overlayVector)
     {
-        FILE* fout = fopen(filename, "w");
+        // the file is opened for appending so that it doesn't get truncated
+        // before we can guarantee mutual exclusion via the flock
+        FILE* fout = fopen(filename, "a");
         if (fout == NULL) {
             return false;
         }
 
+        if (TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_EX)) != 0) {
+            fclose(fout);
+            return false;
+        }
+
+        if (TEMP_FAILURE_RETRY(ftruncate(fileno(fout), 0)) != 0) {
+            TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_UN));
+            fclose(fout);
+            return false;
+        }
+
         for (size_t i = 0; i < overlayVector.size(); ++i) {
             const Overlay& overlay = overlayVector[i];
             fprintf(fout, "%s %s\n", overlay.apk_path.string(), overlay.idmap_path.string());
         }
 
+        TEMP_FAILURE_RETRY(fflush(fout));
+        TEMP_FAILURE_RETRY(flock(fileno(fout), LOCK_UN));
         fclose(fout);
 
         // Make file world readable since Zygote (running as root) will read
@@ -171,9 +187,6 @@
 {
     String8 filename = String8(idmap_dir);
     filename.appendPath("overlays.list");
-    if (unlink(filename.string()) != 0 && errno != ENOENT) {
-        return EXIT_FAILURE;
-    }
 
     SortedVector<Overlay> overlayVector;
     const size_t N = overlay_dirs->size();
diff --git a/cmds/svc/src/com/android/commands/svc/UsbCommand.java b/cmds/svc/src/com/android/commands/svc/UsbCommand.java
index a6ef25f..4dcb05e 100644
--- a/cmds/svc/src/com/android/commands/svc/UsbCommand.java
+++ b/cmds/svc/src/com/android/commands/svc/UsbCommand.java
@@ -50,7 +50,7 @@
                 IUsbManager usbMgr = IUsbManager.Stub.asInterface(ServiceManager.getService(
                         Context.USB_SERVICE));
                 try {
-                    usbMgr.setCurrentFunction((args.length >=3 ? args[2] : null));
+                    usbMgr.setCurrentFunction((args.length >=3 ? args[2] : null), false);
                 } catch (RemoteException e) {
                     System.err.println("Error communicating with UsbManager: " + e);
                 }
diff --git a/compiled-classes-phone b/compiled-classes-phone
index 221d687..6214306 100644
--- a/compiled-classes-phone
+++ b/compiled-classes-phone
@@ -1168,14 +1168,6 @@
 android.drm.DrmManagerClient$OnInfoListener
 android.drm.DrmOutputStream
 android.drm.DrmSupportInfo
-android.graphics.Atlas
-android.graphics.Atlas$Entry
-android.graphics.Atlas$Policy
-android.graphics.Atlas$SlicePolicy
-android.graphics.Atlas$SlicePolicy$Cell
-android.graphics.Atlas$SlicePolicy$MinAreaSplitDecision
-android.graphics.Atlas$SlicePolicy$SplitDecision
-android.graphics.Atlas$Type
 android.graphics.Bitmap
 android.graphics.Bitmap$1
 android.graphics.Bitmap$CompressFormat
@@ -4264,9 +4256,6 @@
 android.view.IAppTransitionAnimationSpecsFuture$Stub$Proxy
 android.view.IApplicationToken
 android.view.IApplicationToken$Stub
-android.view.IAssetAtlas
-android.view.IAssetAtlas$Stub
-android.view.IAssetAtlas$Stub$Proxy
 android.view.IDockedStackListener
 android.view.IDockedStackListener$Stub
 android.view.IDockedStackListener$Stub$Proxy
diff --git a/core/java/android/animation/KeyframeSet.java b/core/java/android/animation/KeyframeSet.java
index fd0bf0b..116d063 100644
--- a/core/java/android/animation/KeyframeSet.java
+++ b/core/java/android/animation/KeyframeSet.java
@@ -16,15 +16,15 @@
 
 package android.animation;
 
-import java.util.Arrays;
-import java.util.List;
-
-import android.animation.Keyframe.IntKeyframe;
 import android.animation.Keyframe.FloatKeyframe;
+import android.animation.Keyframe.IntKeyframe;
 import android.animation.Keyframe.ObjectKeyframe;
 import android.graphics.Path;
 import android.util.Log;
 
+import java.util.Arrays;
+import java.util.List;
+
 /**
  * This class holds a collection of Keyframe objects and is called by ValueAnimator to calculate
  * values between those keyframes for a given animation. The class internal to the animation
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl
index 28224e8..c87eef9 100644
--- a/core/java/android/app/INotificationManager.aidl
+++ b/core/java/android/app/INotificationManager.aidl
@@ -78,6 +78,8 @@
     void cancelNotificationFromListener(in INotificationListener token, String pkg, String tag, int id);
     void cancelNotificationsFromListener(in INotificationListener token, in String[] keys);
 
+    void snoozeNotificationFromListener(in INotificationListener token, String key, long until);
+
     void requestBindListener(in ComponentName component);
     void requestUnbindListener(in INotificationListener token);
     void requestBindProvider(in ComponentName component);
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 7be77c5..bdb2685 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -1053,6 +1053,7 @@
             this(Icon.createWithResource("", icon), title, intent, new Bundle(), null, false);
         }
 
+        /** Keep in sync with {@link Notification.Action.Builder#Builder(Action)}! */
         private Action(Icon icon, CharSequence title, PendingIntent intent, Bundle extras,
                 RemoteInput[] remoteInputs, boolean allowGeneratedReplies) {
             this.mIcon = icon;
@@ -1119,7 +1120,7 @@
              */
             @Deprecated
             public Builder(int icon, CharSequence title, PendingIntent intent) {
-                this(Icon.createWithResource("", icon), title, intent, new Bundle(), null);
+                this(Icon.createWithResource("", icon), title, intent);
             }
 
             /**
@@ -1129,7 +1130,7 @@
              * @param intent the {@link PendingIntent} to fire when users trigger this action
              */
             public Builder(Icon icon, CharSequence title, PendingIntent intent) {
-                this(icon, title, intent, new Bundle(), null);
+                this(icon, title, intent, new Bundle(), null, false);
             }
 
             /**
@@ -1138,12 +1139,13 @@
              * @param action the action to read fields from.
              */
             public Builder(Action action) {
-                this(action.getIcon(), action.title, action.actionIntent, new Bundle(action.mExtras),
-                        action.getRemoteInputs());
+                this(action.getIcon(), action.title, action.actionIntent,
+                        new Bundle(action.mExtras), action.getRemoteInputs(),
+                        action.getAllowGeneratedReplies());
             }
 
             private Builder(Icon icon, CharSequence title, PendingIntent intent, Bundle extras,
-                    RemoteInput[] remoteInputs) {
+                    RemoteInput[] remoteInputs, boolean allowGeneratedReplies) {
                 mIcon = icon;
                 mTitle = title;
                 mIntent = intent;
@@ -1152,6 +1154,7 @@
                     mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length);
                     Collections.addAll(mRemoteInputs, remoteInputs);
                 }
+                mAllowGeneratedReplies = allowGeneratedReplies;
             }
 
             /**
diff --git a/core/java/android/app/ResourcesManager.java b/core/java/android/app/ResourcesManager.java
index c88cea0..c171a14 100644
--- a/core/java/android/app/ResourcesManager.java
+++ b/core/java/android/app/ResourcesManager.java
@@ -839,19 +839,19 @@
                             tmpConfig = new Configuration();
                         }
                         tmpConfig.setTo(config);
-                        if (!isDefaultDisplay) {
-                            // Get new DisplayMetrics based on the DisplayAdjustments given
-                            // to the ResourcesImpl. Udate a copy if the CompatibilityInfo
-                            // changed, because the ResourcesImpl object will handle the
-                            // update internally.
-                            DisplayAdjustments daj = r.getDisplayAdjustments();
-                            if (compat != null) {
-                                daj = new DisplayAdjustments(daj);
-                                daj.setCompatibilityInfo(compat);
-                            }
-                            dm = getDisplayMetrics(displayId, daj);
-                            applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
+
+                        // Get new DisplayMetrics based on the DisplayAdjustments given
+                        // to the ResourcesImpl. Update a copy if the CompatibilityInfo
+                        // changed, because the ResourcesImpl object will handle the
+                        // update internally.
+                        DisplayAdjustments daj = r.getDisplayAdjustments();
+                        if (compat != null) {
+                            daj = new DisplayAdjustments(daj);
+                            daj.setCompatibilityInfo(compat);
                         }
+                        dm = getDisplayMetrics(displayId, daj);
+                        applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
+
                         if (hasOverrideConfiguration) {
                             tmpConfig.updateFrom(key.mOverrideConfiguration);
                         }
diff --git a/core/java/android/app/backup/BackupAgent.java b/core/java/android/app/backup/BackupAgent.java
index 3ba81c8..bad6325 100644
--- a/core/java/android/app/backup/BackupAgent.java
+++ b/core/java/android/app/backup/BackupAgent.java
@@ -649,10 +649,11 @@
                 File file = scanQueue.remove(0);
                 String filePath;
                 try {
-                    // Ignore symlinks outright
+                    // Ignore things that aren't "real" files or dirs
                     StructStat stat = Os.lstat(file.getPath());
-                    if (OsConstants.S_ISLNK(stat.st_mode)) {
-                        if (DEBUG) Log.i(TAG, "Symlink (skipping)!: " + file);
+                    if (!OsConstants.S_ISREG(stat.st_mode)
+                            && !OsConstants.S_ISDIR(stat.st_mode)) {
+                        if (DEBUG) Log.i(TAG, "Not a file/dir (skipping)!: " + file);
                         continue;
                     }
 
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 02c8f0c..e031275 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -4196,6 +4196,16 @@
             "android.intent.extra.MEDIA_RESOURCE_TYPE";
 
     /**
+     * Used as a boolean extra field in {@link #ACTION_CHOOSER} intents to specify
+     * whether to show the chooser or not when there is only one application available
+     * to choose from.
+     *
+     * @hide
+     */
+    public static final String EXTRA_AUTO_LAUNCH_SINGLE_CHOICE =
+            "android.intent.extra.AUTO_LAUNCH_SINGLE_CHOICE";
+
+    /**
      * Used as an int value for {@link #EXTRA_MEDIA_RESOURCE_TYPE}
      * to represent that a video codec is allowed to use.
      *
@@ -6586,7 +6596,7 @@
      */
     public void removeUnsafeExtras() {
         if (mExtras != null) {
-            mExtras.filterValues();
+            mExtras = mExtras.filterValues();
         }
     }
 
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 5d2c6cd..4cbff5f 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -163,13 +163,14 @@
      */
     public static final int RESIZE_MODE_UNRESIZEABLE = 0;
     /**
-     * Activity can not be resized and always occupies the fullscreen area with all windows cropped
-     * to either the task or stack bounds.
+     * Activity didn't explicitly request to be resizeable, but we are making it resizeable because
+     * of the SDK version it targets. Only affects apps with target SDK >= N where the app is
+     * implied to be resizeable if it doesn't explicitly set the attribute to any value.
      * @hide
      */
-    public static final int RESIZE_MODE_CROP_WINDOWS = 1;
+    public static final int RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION = 1;
     /**
-     * Activity is resizeable.
+     * Activity explicitly requested to be resizeable.
      * @hide
      */
     public static final int RESIZE_MODE_RESIZEABLE = 2;
@@ -179,7 +180,8 @@
      */
     public static final int RESIZE_MODE_RESIZEABLE_AND_PIPABLE = 3;
     /**
-     * Activity is does not support resizing, but we are forcing it to be resizeable.
+     * Activity is does not support resizing, but we are forcing it to be resizeable. Only affects
+     * certain pre-N apps where we force them to be resizeable.
      * @hide
      */
     public static final int RESIZE_MODE_FORCE_RESIZEABLE = 4;
@@ -862,7 +864,8 @@
     public static boolean isResizeableMode(int mode) {
         return mode == RESIZE_MODE_RESIZEABLE
                 || mode == RESIZE_MODE_RESIZEABLE_AND_PIPABLE
-                || mode == RESIZE_MODE_FORCE_RESIZEABLE;
+                || mode == RESIZE_MODE_FORCE_RESIZEABLE
+                || mode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
     }
 
     /** @hide */
@@ -870,8 +873,8 @@
         switch (mode) {
             case RESIZE_MODE_UNRESIZEABLE:
                 return "RESIZE_MODE_UNRESIZEABLE";
-            case RESIZE_MODE_CROP_WINDOWS:
-                return "RESIZE_MODE_CROP_WINDOWS";
+            case RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION:
+                return "RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION";
             case RESIZE_MODE_RESIZEABLE:
                 return "RESIZE_MODE_RESIZEABLE";
             case RESIZE_MODE_RESIZEABLE_AND_PIPABLE:
diff --git a/core/java/android/content/pm/ApplicationInfo.java b/core/java/android/content/pm/ApplicationInfo.java
index b7364e2..ecfc00f 100644
--- a/core/java/android/content/pm/ApplicationInfo.java
+++ b/core/java/android/content/pm/ApplicationInfo.java
@@ -520,12 +520,26 @@
     public static final int PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER = 1 << 10;
 
     /**
-     * When set, the activities associated with this application are resizeable by default.
+     * When set, the application explicitly requested that its activities by resizeable by default.
      * @see android.R.styleable#AndroidManifestActivity_resizeableActivity
      *
      * @hide
      */
-    public static final int PRIVATE_FLAG_RESIZEABLE_ACTIVITIES = 1 << 11;
+    public static final int PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_EXPLICITLY_SET = 1 << 11;
+
+    /**
+     * The application isn't requesting explicitly requesting for its activities to be resizeable or
+     * non-resizeable by default. So, we are making it activities resizeable by default based on the
+     * target SDK version of the app.
+     * @see android.R.styleable#AndroidManifestActivity_resizeableActivity
+     *
+     * NOTE: This only affects apps with target SDK >= N where the resizeableActivity attribute was
+     * introduced. It shouldn't be confused with {@link ActivityInfo#RESIZE_MODE_FORCE_RESIZEABLE}
+     * where certain pre-N apps are forced to the resizeable.
+     *
+     * @hide
+     */
+    public static final int PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_VIA_SDK_VERSION = 1 << 12;
 
     /**
      * Value for {@link #privateFlags}: {@code true} means the OS should go ahead and
@@ -533,7 +547,7 @@
      * foreground-equivalent run state.  Defaults to {@code false} if unspecified.
      * @hide
      */
-    public static final int PRIVATE_FLAG_BACKUP_IN_FOREGROUND = 1 << 12;
+    public static final int PRIVATE_FLAG_BACKUP_IN_FOREGROUND = 1 << 13;
 
     /**
      * Private/hidden flags. See {@code PRIVATE_FLAG_...} constants.
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index 201ada1..12e8d48 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -83,10 +83,12 @@
 import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
 import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
 import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
+import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
 import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
 import static android.content.pm.ApplicationInfo.FLAG_SUSPENDED;
-import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_RESIZEABLE_ACTIVITIES;
+import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_EXPLICITLY_SET;
+import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_VIA_SDK_VERSION;
 import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_MANIFEST;
 import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
 import static android.content.pm.PackageManager.INSTALL_PARSE_FAILED_CERTIFICATE_ENCODING;
@@ -2940,9 +2942,12 @@
             ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_DIRECT_BOOT_AWARE;
         }
 
-        if (sa.getBoolean(R.styleable.AndroidManifestApplication_resizeableActivity,
-                owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N)) {
-            ai.privateFlags |= PRIVATE_FLAG_RESIZEABLE_ACTIVITIES;
+        if (sa.hasValueOrEmpty(R.styleable.AndroidManifestApplication_resizeableActivity)) {
+            if (sa.getBoolean(R.styleable.AndroidManifestApplication_resizeableActivity, true)) {
+                ai.privateFlags |= PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_EXPLICITLY_SET;
+            }
+        } else if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N) {
+            ai.privateFlags |= PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_VIA_SDK_VERSION;
         }
 
         ai.networkSecurityConfigRes = sa.getResourceId(
@@ -3548,31 +3553,7 @@
                     R.styleable.AndroidManifestActivity_screenOrientation,
                     SCREEN_ORIENTATION_UNSPECIFIED);
 
-            a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
-            final boolean appDefault = (owner.applicationInfo.privateFlags
-                    & PRIVATE_FLAG_RESIZEABLE_ACTIVITIES) != 0;
-            // This flag is used to workaround the issue with ignored resizeableActivity param when
-            // either targetSdkVersion is not set at all or <uses-sdk> tag is below <application>
-            // tag in AndroidManifest. If this param was explicitly set to 'false' we need to set
-            // corresponding resizeMode regardless of targetSdkVersion value at this point in time.
-            final boolean resizeableSetExplicitly
-                    = sa.hasValue(R.styleable.AndroidManifestActivity_resizeableActivity);
-            final boolean resizeable = sa.getBoolean(
-                    R.styleable.AndroidManifestActivity_resizeableActivity, appDefault);
-
-            if (resizeable) {
-                if (sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture,
-                        false)) {
-                    a.info.resizeMode = RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
-                } else {
-                    a.info.resizeMode = RESIZE_MODE_RESIZEABLE;
-                }
-            } else if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.N
-                    || resizeableSetExplicitly) {
-                a.info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
-            } else if (!a.info.isFixedOrientation() && (a.info.flags & FLAG_IMMERSIVE) == 0) {
-                a.info.resizeMode = RESIZE_MODE_FORCE_RESIZEABLE;
-            }
+            setActivityResizeMode(a.info, sa, owner);
 
             if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysFocusable, false)) {
                 a.info.flags |= FLAG_ALWAYS_FOCUSABLE;
@@ -3706,6 +3687,39 @@
         return a;
     }
 
+    private void setActivityResizeMode(ActivityInfo aInfo, TypedArray sa, Package owner) {
+        final boolean appExplicitDefault = (owner.applicationInfo.privateFlags
+                & PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_EXPLICITLY_SET) != 0;
+        final boolean supportsPip =
+                sa.getBoolean(R.styleable.AndroidManifestActivity_supportsPictureInPicture, false);
+
+        if (sa.hasValue(R.styleable.AndroidManifestActivity_resizeableActivity)
+                || appExplicitDefault) {
+            // Activity or app explicitly set if it is resizeable or not;
+            if (sa.getBoolean(R.styleable.AndroidManifestActivity_resizeableActivity,
+                    appExplicitDefault)) {
+                aInfo.resizeMode =
+                        supportsPip ? RESIZE_MODE_RESIZEABLE_AND_PIPABLE : RESIZE_MODE_RESIZEABLE;
+            } else {
+                aInfo.resizeMode = RESIZE_MODE_UNRESIZEABLE;
+            }
+            return;
+        }
+
+        if ((owner.applicationInfo.privateFlags
+                & PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_VIA_SDK_VERSION) != 0) {
+            // The activity or app didn't explicitly set the resizing option, however we want to
+            // make it resize due to the sdk version it is targeting.
+            aInfo.resizeMode = RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
+            return;
+        }
+
+        // resize preference isn't set and target sdk version doesn't support resizing apps by
+        // default. For the app to be resizeable if it isn't fixed orientation or immersive.
+        aInfo.resizeMode = (aInfo.isFixedOrientation() || (aInfo.flags & FLAG_IMMERSIVE) != 0)
+                ? RESIZE_MODE_UNRESIZEABLE : RESIZE_MODE_FORCE_RESIZEABLE;
+    }
+
     private void parseLayout(Resources res, AttributeSet attrs, Activity a) {
         TypedArray sw = res.obtainAttributes(attrs,
                 com.android.internal.R.styleable.AndroidManifestLayout);
diff --git a/core/java/android/content/pm/ShortcutManager.java b/core/java/android/content/pm/ShortcutManager.java
index cd248ea..96ad67c 100644
--- a/core/java/android/content/pm/ShortcutManager.java
+++ b/core/java/android/content/pm/ShortcutManager.java
@@ -329,7 +329,7 @@
  * <p>Applications with a foreground activity or service are not rate-limited.
  *
  * <p>Rate-limiting will be reset upon certain events, so that even background applications
- * can call these APIs again until they are rate limit is reached again.
+ * can call these APIs again until the rate limit is reached again.
  * These events include the following:
  * <ul>
  *   <li>When an application comes to the foreground.
diff --git a/core/java/android/content/res/ResourcesKey.java b/core/java/android/content/res/ResourcesKey.java
index 64b6bf1..b03ed1e 100644
--- a/core/java/android/content/res/ResourcesKey.java
+++ b/core/java/android/content/res/ResourcesKey.java
@@ -59,7 +59,8 @@
         mOverlayDirs = overlayDirs;
         mLibDirs = libDirs;
         mDisplayId = displayId;
-        mOverrideConfiguration = overrideConfig != null ? overrideConfig : Configuration.EMPTY;
+        mOverrideConfiguration = new Configuration(overrideConfig != null
+                ? overrideConfig : Configuration.EMPTY);
         mCompatInfo = compatInfo != null ? compatInfo : CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
 
         int hash = 17;
diff --git a/core/java/android/hardware/usb/IUsbManager.aidl b/core/java/android/hardware/usb/IUsbManager.aidl
index fafe116..45aeb4a 100644
--- a/core/java/android/hardware/usb/IUsbManager.aidl
+++ b/core/java/android/hardware/usb/IUsbManager.aidl
@@ -88,15 +88,13 @@
     /* Returns true if the specified USB function is enabled. */
     boolean isFunctionEnabled(String function);
 
-    /* Sets the current USB function. */
-    void setCurrentFunction(String function);
-
-    /* Sets whether USB data (for example, MTP exposed pictures) should be made
-     * available on the USB connection. Unlocking data should only be done with
-     * user involvement, since exposing pictures or other data could leak sensitive
-     * user information.
+    /* Sets the current USB function as well as whether USB data 
+     * (for example, MTP exposed pictures) should be made available 
+     * on the USB connection. Unlocking data should only be done with
+     * user involvement, since exposing pictures or other data could 
+     * leak sensitive user information.
      */
-    void setUsbDataUnlocked(boolean unlock);
+    void setCurrentFunction(String function, boolean usbDataUnlocked);
 
     /* Allow USB debugging from the attached host. If alwaysAllow is true, add the
      * the public key to list of host keys that the user has approved.
diff --git a/core/java/android/hardware/usb/UsbManager.java b/core/java/android/hardware/usb/UsbManager.java
index 1d20c78..3636e4e 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -542,33 +542,23 @@
      * {@link #USB_FUNCTION_MIDI}, {@link #USB_FUNCTION_MTP}, {@link #USB_FUNCTION_PTP},
      * or {@link #USB_FUNCTION_RNDIS}.
      * </p><p>
+     * Also sets whether USB data (for example, MTP exposed pictures) should be made available
+     * on the USB connection when in device mode. Unlocking usb data should only be done with
+     * user involvement, since exposing pictures or other data could leak sensitive
+     * user information.
+     * </p><p>
      * Note: This function is asynchronous and may fail silently without applying
      * the requested changes.
      * </p>
      *
      * @param function name of the USB function, or null to restore the default function
+     * @param usbDataUnlocked whether user data is accessible
      *
      * {@hide}
      */
-    public void setCurrentFunction(String function) {
+    public void setCurrentFunction(String function, boolean usbDataUnlocked) {
         try {
-            mService.setCurrentFunction(function);
-        } catch (RemoteException e) {
-            throw e.rethrowFromSystemServer();
-        }
-    }
-
-    /**
-     * Sets whether USB data (for example, MTP exposed pictures) should be made available
-     * on the USB connection when in device mode. Unlocking usb data should only be done with
-     * user involvement, since exposing pictures or other data could leak sensitive
-     * user information.
-     *
-     * {@hide}
-     */
-    public void setUsbDataUnlocked(boolean unlocked) {
-        try {
-            mService.setUsbDataUnlocked(unlocked);
+            mService.setCurrentFunction(function, usbDataUnlocked);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
diff --git a/core/java/android/net/InterfaceConfiguration.java b/core/java/android/net/InterfaceConfiguration.java
index ea53a71..eace8b2 100644
--- a/core/java/android/net/InterfaceConfiguration.java
+++ b/core/java/android/net/InterfaceConfiguration.java
@@ -124,6 +124,10 @@
         return false;
     }
 
+    public boolean isUp() {
+        return hasFlag(FLAG_UP);
+    }
+
     /** {@inheritDoc} */
     public int describeContents() {
         return 0;
diff --git a/core/java/android/os/BatteryStats.java b/core/java/android/os/BatteryStats.java
index 95dd148..3d5d900 100644
--- a/core/java/android/os/BatteryStats.java
+++ b/core/java/android/os/BatteryStats.java
@@ -5433,7 +5433,8 @@
         if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
             if (dumpDurationSteps(pw, "  ", "Discharge step durations:",
                     getDischargeLevelStepTracker(), false)) {
-                long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
+                long timeRemaining = computeBatteryTimeRemaining(
+                    SystemClock.elapsedRealtime() * 1000);
                 if (timeRemaining >= 0) {
                     pw.print("  Estimated discharge time remaining: ");
                     TimeUtils.formatDuration(timeRemaining / 1000, pw);
@@ -5449,7 +5450,8 @@
             }
             if (dumpDurationSteps(pw, "  ", "Charge step durations:",
                     getChargeLevelStepTracker(), false)) {
-                long timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
+                long timeRemaining = computeChargeTimeRemaining(
+                    SystemClock.elapsedRealtime() * 1000);
                 if (timeRemaining >= 0) {
                     pw.print("  Estimated charge time remaining: ");
                     TimeUtils.formatDuration(timeRemaining / 1000, pw);
@@ -5612,14 +5614,14 @@
         if (!filtering || (flags&DUMP_CHARGED_ONLY) != 0) {
             dumpDurationSteps(pw, "", DISCHARGE_STEP_DATA, getDischargeLevelStepTracker(), true);
             String[] lineArgs = new String[1];
-            long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime());
+            long timeRemaining = computeBatteryTimeRemaining(SystemClock.elapsedRealtime() * 1000);
             if (timeRemaining >= 0) {
                 lineArgs[0] = Long.toString(timeRemaining);
                 dumpLine(pw, 0 /* uid */, "i" /* category */, DISCHARGE_TIME_REMAIN_DATA,
                         (Object[])lineArgs);
             }
             dumpDurationSteps(pw, "", CHARGE_STEP_DATA, getChargeLevelStepTracker(), true);
-            timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime());
+            timeRemaining = computeChargeTimeRemaining(SystemClock.elapsedRealtime() * 1000);
             if (timeRemaining >= 0) {
                 lineArgs[0] = Long.toString(timeRemaining);
                 dumpLine(pw, 0 /* uid */, "i" /* category */, CHARGE_TIME_REMAIN_DATA,
diff --git a/core/java/android/os/Bundle.java b/core/java/android/os/Bundle.java
index 7061589..d04d6c2 100644
--- a/core/java/android/os/Bundle.java
+++ b/core/java/android/os/Bundle.java
@@ -329,25 +329,49 @@
      * Filter values in Bundle to only basic types.
      * @hide
      */
-    public void filterValues() {
+    public Bundle filterValues() {
         unparcel();
+        Bundle bundle = this;
         if (mMap != null) {
-            for (int i = mMap.size() - 1; i >= 0; i--) {
-                Object value = mMap.valueAt(i);
+            ArrayMap<String, Object> map = mMap;
+            for (int i = map.size() - 1; i >= 0; i--) {
+                Object value = map.valueAt(i);
                 if (PersistableBundle.isValidType(value)) {
                     continue;
                 }
                 if (value instanceof Bundle) {
-                    ((Bundle)value).filterValues();
+                    Bundle newBundle = ((Bundle)value).filterValues();
+                    if (newBundle != value) {
+                        if (map == mMap) {
+                            // The filter had to generate a new bundle, but we have not yet
+                            // created a new one here.  Do that now.
+                            bundle = new Bundle(this);
+                            // Note the ArrayMap<> constructor is guaranteed to generate
+                            // a new object with items in the same order as the original.
+                            map = bundle.mMap;
+                        }
+                        // Replace this current entry with the new child bundle.
+                        map.setValueAt(i, newBundle);
+                    }
+                    continue;
                 }
                 if (value.getClass().getName().startsWith("android.")) {
                     continue;
                 }
-                mMap.removeAt(i);
+                if (map == mMap) {
+                    // This is the first time we have had to remove something, that means we
+                    // need to switch to a new Bundle.
+                    bundle = new Bundle(this);
+                    // Note the ArrayMap<> constructor is guaranteed to generate
+                    // a new object with items in the same order as the original.
+                    map = bundle.mMap;
+                }
+                map.removeAt(i);
             }
         }
         mFlags |= FLAG_HAS_FDS_KNOWN;
         mFlags &= ~FLAG_HAS_FDS;
+        return bundle;
     }
 
     /**
diff --git a/core/java/android/os/IUserManager.aidl b/core/java/android/os/IUserManager.aidl
index 427add1..65c6093 100644
--- a/core/java/android/os/IUserManager.aidl
+++ b/core/java/android/os/IUserManager.aidl
@@ -85,4 +85,5 @@
     boolean isDemoUser(int userId);
     UserInfo createProfileForUserEvenWhenDisallowed(in String name, int flags, int userHandle,
             in String[] disallowedPackages);
+    boolean isUserUnlockingOrUnlocked(int userId);
 }
diff --git a/core/java/android/os/PowerManagerInternal.java b/core/java/android/os/PowerManagerInternal.java
index 9bbe8f9..c153184 100644
--- a/core/java/android/os/PowerManagerInternal.java
+++ b/core/java/android/os/PowerManagerInternal.java
@@ -53,24 +53,6 @@
      */
     public static final int WAKEFULNESS_DOZING = 3;
 
-
-    /**
-     * Power hint:
-     * Interaction: The user is interacting with the device. The corresponding data field must be
-     * the expected duration of the interaction, or 0 if unknown.
-     *
-     * Sustained Performance Mode: The corresponding data field must be Enable/Disable
-     * Sustained Performance Mode.
-     *
-     * Launch: This is specific for activity launching. The corresponding data field must be
-     * the expected duration of the required boost, or 0 if unknown.
-     *
-     * These must be kept in sync with the values in hardware/libhardware/include/hardware/power.h
-     */
-    public static final int POWER_HINT_INTERACTION = 2;
-    public static final int POWER_HINT_SUSTAINED_PERFORMANCE_MODE = 6;
-    public static final int POWER_HINT_LAUNCH = 8;
-
     public static String wakefulnessToString(int wakefulness) {
         switch (wakefulness) {
             case WAKEFULNESS_ASLEEP:
@@ -169,5 +151,9 @@
 
     public abstract void uidGone(int uid);
 
+    /**
+     * The hintId sent through this method should be in-line with the
+     * PowerHint defined in android/hardware/power/<version 1.0 & up>/IPower.h
+     */
     public abstract void powerHint(int hintId, int data);
 }
diff --git a/core/java/android/os/Process.java b/core/java/android/os/Process.java
index e9ebe2d..f9dee92 100644
--- a/core/java/android/os/Process.java
+++ b/core/java/android/os/Process.java
@@ -17,8 +17,6 @@
 package android.os;
 
 import android.annotation.TestApi;
-import android.net.LocalSocket;
-import android.net.LocalSocketAddress;
 import android.system.Os;
 import android.system.OsConstants;
 import android.util.Log;
diff --git a/core/java/android/os/UserManager.java b/core/java/android/os/UserManager.java
index c656b06..bc5af81 100644
--- a/core/java/android/os/UserManager.java
+++ b/core/java/android/os/UserManager.java
@@ -1094,10 +1094,8 @@
 
     /** {@hide} */
     public boolean isUserUnlockingOrUnlocked(@UserIdInt int userId) {
-        // TODO Switch to using UMS internal isUserUnlockingOrUnlocked
         try {
-            return ActivityManagerNative.getDefault().isUserRunning(userId,
-                    ActivityManager.FLAG_AND_UNLOCKING_OR_UNLOCKED);
+            return mService.isUserUnlockingOrUnlocked(userId);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
diff --git a/core/java/android/provider/Contacts.java b/core/java/android/provider/Contacts.java
index d409030..b31b295 100644
--- a/core/java/android/provider/Contacts.java
+++ b/core/java/android/provider/Contacts.java
@@ -438,21 +438,11 @@
         public static final String PRIMARY_ORGANIZATION_ID = "primary_organization";
 
         /**
-         * Mark a person as having been contacted.
-         *
-         * @param resolver the ContentResolver to use
-         * @param personId the person who was contacted
-         * @deprecated see {@link android.provider.ContactsContract}
+         * This API is no longer supported as of O.
          */
         @Deprecated
         public static void markAsContacted(ContentResolver resolver, long personId) {
-            Uri uri = ContentUris.withAppendedId(CONTENT_URI, personId);
-            uri = Uri.withAppendedPath(uri, "update_contact_time");
-            ContentValues values = new ContentValues();
-            // There is a trigger in place that will update TIMES_CONTACTED when
-            // LAST_TIME_CONTACTED is modified.
-            values.put(LAST_TIME_CONTACTED, System.currentTimeMillis());
-            resolver.update(uri, values, null, null);
+            // No longer supported.
         }
 
         /**
diff --git a/core/java/android/provider/ContactsContract.java b/core/java/android/provider/ContactsContract.java
index a1763c0..a07aee5 100644
--- a/core/java/android/provider/ContactsContract.java
+++ b/core/java/android/provider/ContactsContract.java
@@ -19,8 +19,6 @@
 import android.accounts.Account;
 import android.annotation.SystemApi;
 import android.app.Activity;
-import android.app.admin.DevicePolicyManager;
-import android.content.ActivityNotFoundException;
 import android.content.ContentProviderClient;
 import android.content.ContentProviderOperation;
 import android.content.ContentResolver;
@@ -44,7 +42,6 @@
 import android.util.DisplayMetrics;
 import android.util.Pair;
 import android.view.View;
-import android.widget.Toast;
 
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -118,6 +115,12 @@
     public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
 
     /**
+     * Prefix for column names that are not visible to client apps.
+     * @hide
+     */
+    public static final String HIDDEN_COLUMN_PREFIX = "x_";
+
+    /**
      * An optional URI parameter for insert, update, or delete queries
      * that allows the caller
      * to specify that it is a sync adapter. The default value is false. If true
@@ -661,6 +664,12 @@
             ContentValues contentValues = new ContentValues();
             resolver.update(Directory.CONTENT_URI, contentValues, null, null);
         }
+
+        /**
+         * A query parameter that's passed to directory providers which indicates the client
+         * package name that has made the query requests.
+         */
+        public static final String CALLER_PACKAGE_PARAM_KEY = "callerPackage";
     }
 
     /**
@@ -863,6 +872,25 @@
          */
         public static final String LAST_TIME_CONTACTED = "last_time_contacted";
 
+        /** @hide Raw value. */
+        public static final String RAW_TIMES_CONTACTED = HIDDEN_COLUMN_PREFIX + TIMES_CONTACTED;
+
+        /** @hide Raw value. */
+        public static final String RAW_LAST_TIME_CONTACTED =
+                HIDDEN_COLUMN_PREFIX + LAST_TIME_CONTACTED;
+
+        /**
+         * @hide
+         * Low res version.  Same as {@link #TIMES_CONTACTED} but use it in CP2 for clarification.
+         */
+        public static final String LR_TIMES_CONTACTED = TIMES_CONTACTED;
+
+        /**
+         * @hide
+         * Low res version.  Same as {@link #TIMES_CONTACTED} but use it in CP2 for clarification.
+         */
+        public static final String LR_LAST_TIME_CONTACTED = LAST_TIME_CONTACTED;
+
         /**
          * Is the contact starred?
          * <P>Type: INTEGER (boolean)</P>
@@ -1669,7 +1697,7 @@
             Uri uri = ContentUris.withAppendedId(CONTENT_URI, contactId);
             ContentValues values = new ContentValues();
             // TIMES_CONTACTED will be incremented when LAST_TIME_CONTACTED is modified.
-            values.put(LAST_TIME_CONTACTED, System.currentTimeMillis());
+            values.put(LR_LAST_TIME_CONTACTED, System.currentTimeMillis());
             resolver.update(uri, values, null, null);
         }
 
@@ -4224,6 +4252,24 @@
 
         /** The number of times the referenced {@link Data} has been used. */
         public static final String TIMES_USED = "times_used";
+
+        /** @hide Raw value. */
+        public static final String RAW_LAST_TIME_USED = HIDDEN_COLUMN_PREFIX + LAST_TIME_USED;
+
+        /** @hide Raw value. */
+        public static final String RAW_TIMES_USED = HIDDEN_COLUMN_PREFIX + TIMES_USED;
+
+        /**
+         * @hide
+         * Low res version.  Same as {@link #LAST_TIME_USED} but use it in CP2 for clarification.
+         */
+        public static final String LR_LAST_TIME_USED = LAST_TIME_USED;
+
+        /**
+         * @hide
+         * Low res version.  Same as {@link #TIMES_USED} but use it in CP2 for clarification.
+         */
+        public static final String LR_TIMES_USED = TIMES_USED;
     }
 
     /**
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index d7d8d50..0f4afae 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -6460,6 +6460,12 @@
         public static final String WEB_ACTION_ENABLED = "web_action_enabled";
 
         /**
+         * Has this pairable device been paired or upgraded from a previously paired system.
+         * @hide
+         */
+        public static final String DEVICE_PAIRED = "device_paired";
+
+        /**
          * This are the settings to be backed up.
          *
          * NOTE: Settings are backed up and restored in the order they appear
diff --git a/core/java/android/service/notification/NotificationListenerService.java b/core/java/android/service/notification/NotificationListenerService.java
index b13e162..e6f58f5 100644
--- a/core/java/android/service/notification/NotificationListenerService.java
+++ b/core/java/android/service/notification/NotificationListenerService.java
@@ -450,6 +450,28 @@
     }
 
     /**
+     * Inform the notification manager about snoozing a specific notification.
+     * <p>
+     * Use this if your listener has a user interface that allows the user to snooze a notification
+     * until a given time.  It should be called after the user snoozes a single notification using
+     * your UI; upon being informed, the notification manager will actually remove the notification
+     * and you will get an {@link #onNotificationRemoved(StatusBarNotification)} callback. When the
+     * snoozing period expires, you will get a
+     * {@link #onNotificationPosted(StatusBarNotification, RankingMap)} callback for the
+     * notification.
+     * @param key The key of the notification to snooze
+     * @param snoozeUntil A time in the future, in milliseconds.
+     */
+    public final void snoozeNotification(String key, long snoozeUntil) {
+        if (!isBound()) return;
+        try {
+            getNotificationInterface().snoozeNotificationFromListener(mWrapper, key, snoozeUntil);
+        } catch (android.os.RemoteException ex) {
+            Log.v(TAG, "Unable to contact notification manager", ex);
+        }
+    }
+
+    /**
      * Inform the notification manager that these notifications have been viewed by the
      * user. This should only be called when there is sufficient confidence that the user is
      * looking at the notifications, such as when the notifications appear on the screen due to
diff --git a/core/java/android/service/notification/NotificationRankerService.java b/core/java/android/service/notification/NotificationRankerService.java
index 261d82d..928d5d8 100644
--- a/core/java/android/service/notification/NotificationRankerService.java
+++ b/core/java/android/service/notification/NotificationRankerService.java
@@ -102,6 +102,9 @@
     /** Notification was canceled by the user banning the channel. */
     public static final int REASON_CHANNEL_BANNED = 17;
 
+    /** Notification was snoozed. */
+    public static final int REASON_SNOOZED = 18;
+
     private Handler mHandler;
 
     /** @hide */
diff --git a/core/java/android/text/AutoText.java b/core/java/android/text/AutoText.java
index 04730ec..c5339a4 100644
--- a/core/java/android/text/AutoText.java
+++ b/core/java/android/text/AutoText.java
@@ -18,11 +18,10 @@
 
 import android.content.res.Resources;
 import android.content.res.XmlResourceParser;
+import android.view.View;
 
 import com.android.internal.util.XmlUtils;
 
-import android.view.View;
-
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
@@ -97,10 +96,10 @@
                 sInstance = instance;
             }
         }
-        
+
         return instance;
     }
-    
+
     /**
      * Retrieves a possible spelling correction for the specified range
      * of text.  Returns null if no correction can be found.
@@ -119,7 +118,7 @@
      */
     public static int getSize(View view) {
 
-        return getInstance(view).getSize(); 
+        return getInstance(view).getSize();
     }
 
     /**
@@ -137,7 +136,7 @@
 
             for (; here != TRIE_NULL; here = mTrie[here + TRIE_NEXT]) {
                 if (c == mTrie[here + TRIE_C]) {
-                    if ((i == end - 1) 
+                    if ((i == end - 1)
                             && (mTrie[here + TRIE_OFF] != TRIE_NULL)) {
                         int off = mTrie[here + TRIE_OFF];
                         int len = mText.charAt(off);
@@ -174,7 +173,7 @@
             while (true) {
                 XmlUtils.nextElement(parser);
 
-                String element = parser.getName(); 
+                String element = parser.getName();
                 if (element == null || !(element.equals("word"))) {
                     break;
                 }
@@ -214,7 +213,7 @@
         int herep = TRIE_ROOT;
         // Keep track of the size of the dictionary
         mSize++;
-        
+
         for (int i = 0; i < slen; i++) {
             char c = src.charAt(i);
             boolean found = false;
diff --git a/core/java/android/text/BidiFormatter.java b/core/java/android/text/BidiFormatter.java
index 59273f4..d84502f 100644
--- a/core/java/android/text/BidiFormatter.java
+++ b/core/java/android/text/BidiFormatter.java
@@ -16,11 +16,11 @@
 
 package android.text;
 
+import static android.text.TextDirectionHeuristics.FIRSTSTRONG_LTR;
+
 import android.annotation.Nullable;
 import android.view.View;
 
-import static android.text.TextDirectionHeuristics.FIRSTSTRONG_LTR;
-
 import java.util.Locale;
 
 /**
diff --git a/core/java/android/text/Html.java b/core/java/android/text/Html.java
index 409994d..de8aa5a 100644
--- a/core/java/android/text/Html.java
+++ b/core/java/android/text/Html.java
@@ -16,19 +16,8 @@
 
 package android.text;
 
-import com.android.internal.util.ArrayUtils;
-import org.ccil.cowan.tagsoup.HTMLSchema;
-import org.ccil.cowan.tagsoup.Parser;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-
 import android.app.ActivityThread;
 import android.app.Application;
-import android.content.res.ColorStateList;
 import android.content.res.Resources;
 import android.graphics.Color;
 import android.graphics.Typeface;
@@ -47,11 +36,21 @@
 import android.text.style.StyleSpan;
 import android.text.style.SubscriptSpan;
 import android.text.style.SuperscriptSpan;
-import android.text.style.TextAppearanceSpan;
 import android.text.style.TypefaceSpan;
 import android.text.style.URLSpan;
 import android.text.style.UnderlineSpan;
 
+import com.android.internal.util.ArrayUtils;
+
+import org.ccil.cowan.tagsoup.HTMLSchema;
+import org.ccil.cowan.tagsoup.Parser;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
 import java.io.IOException;
 import java.io.StringReader;
 import java.util.HashMap;
diff --git a/core/java/android/text/InputType.java b/core/java/android/text/InputType.java
index c596388..8967b70 100644
--- a/core/java/android/text/InputType.java
+++ b/core/java/android/text/InputType.java
@@ -16,8 +16,6 @@
 
 package android.text;
 
-import android.text.TextUtils;
-
 /**
  * Bit definitions for an integer defining the basic content type of text
  * held in an {@link Editable} object. Supported classes may be combined
@@ -51,19 +49,19 @@
      * or flags.<p>
      */
     public static final int TYPE_MASK_CLASS = 0x0000000f;
-    
+
     /**
      * Mask of bits that determine the variation of
      * the base content class.
      */
     public static final int TYPE_MASK_VARIATION = 0x00000ff0;
-    
+
     /**
      * Mask of bits that provide addition bit flags
      * of options.
      */
     public static final int TYPE_MASK_FLAGS = 0x00fff000;
-    
+
     /**
      * Special content type for when no explicit type has been specified.
      * This should be interpreted to mean that the target input connection
@@ -75,11 +73,11 @@
      * flag is set.
      */
     public static final int TYPE_NULL = 0x00000000;
-    
+
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
-    
+
     /**
      * Class for normal text.  This class supports the following flags (only
      * one of which should be set):
@@ -92,7 +90,7 @@
      * variation, normal should be assumed.
      */
     public static final int TYPE_CLASS_TEXT = 0x00000001;
-    
+
     /**
      * Flag for {@link #TYPE_CLASS_TEXT}: capitalize all characters.  Overrides
      * {@link #TYPE_TEXT_FLAG_CAP_WORDS} and
@@ -101,7 +99,7 @@
      * this only affects languages where there are upper-case and lower-case letters.
      */
     public static final int TYPE_TEXT_FLAG_CAP_CHARACTERS = 0x00001000;
-    
+
     /**
      * Flag for {@link #TYPE_CLASS_TEXT}: capitalize the first character of
      * every word.  Overrides {@link #TYPE_TEXT_FLAG_CAP_SENTENCES}.  This
@@ -110,7 +108,7 @@
      * this only affects languages where there are upper-case and lower-case letters.
      */
     public static final int TYPE_TEXT_FLAG_CAP_WORDS = 0x00002000;
-    
+
     /**
      * Flag for {@link #TYPE_CLASS_TEXT}: capitalize the first character of
      * each sentence.  This value is explicitly defined
@@ -121,7 +119,7 @@
      * this only affects languages where there are upper-case and lower-case letters.
      */
     public static final int TYPE_TEXT_FLAG_CAP_SENTENCES = 0x00004000;
-    
+
     /**
      * Flag for {@link #TYPE_CLASS_TEXT}: the user is entering free-form
      * text that should have auto-correction applied to it. Without this flag,
@@ -135,7 +133,7 @@
      * the IME offers an interface to show suggestions.
      */
     public static final int TYPE_TEXT_FLAG_AUTO_CORRECT = 0x00008000;
-    
+
     /**
      * Flag for {@link #TYPE_CLASS_TEXT}: the text editor (which means
      * the application) is performing auto-completion of the text being entered
@@ -154,23 +152,23 @@
      * it will rely on the Editor to pass completions/corrections.
      */
     public static final int TYPE_TEXT_FLAG_AUTO_COMPLETE = 0x00010000;
-    
+
     /**
      * Flag for {@link #TYPE_CLASS_TEXT}: multiple lines of text can be
-     * entered into the field.  If this flag is not set, the text field 
+     * entered into the field.  If this flag is not set, the text field
      * will be constrained to a single line. The IME may also choose not to
      * display an enter key when this flag is not set, as there should be no
      * need to create new lines.
      */
     public static final int TYPE_TEXT_FLAG_MULTI_LINE = 0x00020000;
-    
+
     /**
      * Flag for {@link #TYPE_CLASS_TEXT}: the regular text view associated
      * with this should not be multi-line, but when a fullscreen input method
      * is providing text it should use multiple lines if it can.
      */
     public static final int TYPE_TEXT_FLAG_IME_MULTI_LINE = 0x00040000;
-    
+
     /**
      * Flag for {@link #TYPE_CLASS_TEXT}: the input method does not need to
      * display any dictionary-based candidates. This is useful for text views that
@@ -191,36 +189,36 @@
     public static final int TYPE_TEXT_FLAG_NO_SUGGESTIONS = 0x00080000;
 
     // ----------------------------------------------------------------------
-    
+
     /**
      * Default variation of {@link #TYPE_CLASS_TEXT}: plain old normal text.
      */
     public static final int TYPE_TEXT_VARIATION_NORMAL = 0x00000000;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering a URI.
      */
     public static final int TYPE_TEXT_VARIATION_URI = 0x00000010;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering an e-mail address.
      */
     public static final int TYPE_TEXT_VARIATION_EMAIL_ADDRESS = 0x00000020;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering the subject line of
      * an e-mail.
      */
     public static final int TYPE_TEXT_VARIATION_EMAIL_SUBJECT = 0x00000030;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering a short, possibly informal
      * message such as an instant message or a text message.
      */
     public static final int TYPE_TEXT_VARIATION_SHORT_MESSAGE = 0x00000040;
-    
+
     /**
-     * Variation of {@link #TYPE_CLASS_TEXT}: entering the content of a long, possibly 
+     * Variation of {@link #TYPE_CLASS_TEXT}: entering the content of a long, possibly
      * formal message such as the body of an e-mail.
      */
     public static final int TYPE_TEXT_VARIATION_LONG_MESSAGE = 0x00000050;
@@ -229,34 +227,34 @@
      * Variation of {@link #TYPE_CLASS_TEXT}: entering the name of a person.
      */
     public static final int TYPE_TEXT_VARIATION_PERSON_NAME = 0x00000060;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering a postal mailing address.
      */
     public static final int TYPE_TEXT_VARIATION_POSTAL_ADDRESS = 0x00000070;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering a password.
      */
     public static final int TYPE_TEXT_VARIATION_PASSWORD = 0x00000080;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering a password, which should
      * be visible to the user.
      */
     public static final int TYPE_TEXT_VARIATION_VISIBLE_PASSWORD = 0x00000090;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering text inside of a web form.
      */
     public static final int TYPE_TEXT_VARIATION_WEB_EDIT_TEXT = 0x000000a0;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering text to filter contents
      * of a list etc.
      */
     public static final int TYPE_TEXT_VARIATION_FILTER = 0x000000b0;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering text for phonetic
      * pronunciation, such as a phonetic name field in contacts. This is mostly
@@ -264,7 +262,7 @@
      * readings, like Japanese.
      */
     public static final int TYPE_TEXT_VARIATION_PHONETIC = 0x000000c0;
-    
+
     /**
      * Variation of {@link #TYPE_CLASS_TEXT}: entering e-mail address inside
      * of a web form.  This was added in
@@ -290,7 +288,7 @@
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
-    
+
     /**
      * Class for numeric text.  This class supports the following flags:
      * {@link #TYPE_NUMBER_FLAG_SIGNED} and
@@ -301,19 +299,19 @@
      * the variation, normal should be assumed.</p>
      */
     public static final int TYPE_CLASS_NUMBER = 0x00000002;
-    
+
     /**
      * Flag of {@link #TYPE_CLASS_NUMBER}: the number is signed, allowing
      * a positive or negative sign at the start.
      */
     public static final int TYPE_NUMBER_FLAG_SIGNED = 0x00001000;
-    
+
     /**
      * Flag of {@link #TYPE_CLASS_NUMBER}: the number is decimal, allowing
      * a decimal point to provide fractional values.
      */
     public static final int TYPE_NUMBER_FLAG_DECIMAL = 0x00002000;
-    
+
     // ----------------------------------------------------------------------
 
     /**
@@ -340,17 +338,17 @@
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
-    
+
     /**
      * Class for a phone number.  This class currently supports no variations
      * or flags.
      */
     public static final int TYPE_CLASS_PHONE = 0x00000003;
-    
+
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
     // ----------------------------------------------------------------------
-    
+
     /**
      * Class for dates and times.  It supports the
      * following variations:
@@ -359,19 +357,19 @@
      * {@link #TYPE_DATETIME_VARIATION_TIME}.
      */
     public static final int TYPE_CLASS_DATETIME = 0x00000004;
-    
+
     /**
      * Default variation of {@link #TYPE_CLASS_DATETIME}: allows entering
      * both a date and time.
      */
     public static final int TYPE_DATETIME_VARIATION_NORMAL = 0x00000000;
-    
+
     /**
      * Default variation of {@link #TYPE_CLASS_DATETIME}: allows entering
      * only a date.
      */
     public static final int TYPE_DATETIME_VARIATION_DATE = 0x00000010;
-    
+
     /**
      * Default variation of {@link #TYPE_CLASS_DATETIME}: allows entering
      * only a time.
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java
index 2a52961..03a2d62 100644
--- a/core/java/android/text/TextLine.java
+++ b/core/java/android/text/TextLine.java
@@ -16,11 +16,9 @@
 
 package android.text;
 
-import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.Paint.FontMetricsInt;
-import android.graphics.RectF;
 import android.text.Layout.Directions;
 import android.text.Layout.TabStops;
 import android.text.style.CharacterStyle;
diff --git a/core/java/android/text/TextUtils.java b/core/java/android/text/TextUtils.java
index 23b22d1..6262fc2 100644
--- a/core/java/android/text/TextUtils.java
+++ b/core/java/android/text/TextUtils.java
@@ -60,8 +60,6 @@
 import com.android.internal.R;
 import com.android.internal.util.ArrayUtils;
 
-import libcore.icu.ICU;
-
 import java.lang.reflect.Array;
 import java.util.Iterator;
 import java.util.List;
diff --git a/core/java/android/text/format/DateFormat.java b/core/java/android/text/format/DateFormat.java
index 3ed37b36..b5a8aca 100755
--- a/core/java/android/text/format/DateFormat.java
+++ b/core/java/android/text/format/DateFormat.java
@@ -23,15 +23,15 @@
 import android.text.Spanned;
 import android.text.SpannedString;
 
+import libcore.icu.ICU;
+import libcore.icu.LocaleData;
+
+import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.Locale;
 import java.util.TimeZone;
-import java.text.SimpleDateFormat;
-
-import libcore.icu.ICU;
-import libcore.icu.LocaleData;
 
 /**
  * Utility class for producing strings with formatted date/time.
diff --git a/core/java/android/text/format/DateUtils.java b/core/java/android/text/format/DateUtils.java
index cb8852c..f16e714 100644
--- a/core/java/android/text/format/DateUtils.java
+++ b/core/java/android/text/format/DateUtils.java
@@ -16,12 +16,16 @@
 
 package android.text.format;
 
-import com.android.internal.R;
-
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 
+import com.android.internal.R;
+
+import libcore.icu.DateIntervalFormat;
+import libcore.icu.LocaleData;
+import libcore.icu.RelativeDateTimeFormatter;
+
 import java.io.IOException;
 import java.util.Calendar;
 import java.util.Date;
@@ -30,10 +34,6 @@
 import java.util.Locale;
 import java.util.TimeZone;
 
-import libcore.icu.DateIntervalFormat;
-import libcore.icu.LocaleData;
-import libcore.icu.RelativeDateTimeFormatter;
-
 /**
  * This class contains various date-related utilities for creating text for things like
  * elapsed time and date ranges, strings for days of the week and months, and AM/PM text etc.
diff --git a/core/java/android/text/format/Formatter.java b/core/java/android/text/format/Formatter.java
index be52464..b67ac98 100644
--- a/core/java/android/text/format/Formatter.java
+++ b/core/java/android/text/format/Formatter.java
@@ -20,11 +20,10 @@
 import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.Resources;
+import android.net.NetworkUtils;
 import android.text.BidiFormatter;
 import android.text.TextUtils;
 import android.view.View;
-import android.net.NetworkUtils;
-import android.net.TrafficStats;
 
 import java.util.Locale;
 
diff --git a/core/java/android/text/format/Time.java b/core/java/android/text/format/Time.java
index 69c2cff..bbd9c9c 100644
--- a/core/java/android/text/format/Time.java
+++ b/core/java/android/text/format/Time.java
@@ -18,13 +18,13 @@
 
 import android.util.TimeFormatException;
 
+import libcore.util.ZoneInfo;
+import libcore.util.ZoneInfoDB;
+
 import java.io.IOException;
 import java.util.Locale;
 import java.util.TimeZone;
 
-import libcore.util.ZoneInfo;
-import libcore.util.ZoneInfoDB;
-
 /**
  * An alternative to the {@link java.util.Calendar} and
  * {@link java.util.GregorianCalendar} classes. An instance of the Time class represents
diff --git a/core/java/android/text/format/TimeFormatter.java b/core/java/android/text/format/TimeFormatter.java
index 3a63805..5a14092 100644
--- a/core/java/android/text/format/TimeFormatter.java
+++ b/core/java/android/text/format/TimeFormatter.java
@@ -22,12 +22,13 @@
 
 import android.content.res.Resources;
 
+import libcore.icu.LocaleData;
+import libcore.util.ZoneInfo;
+
 import java.nio.CharBuffer;
 import java.util.Formatter;
 import java.util.Locale;
 import java.util.TimeZone;
-import libcore.icu.LocaleData;
-import libcore.util.ZoneInfo;
 
 /**
  * Formatting logic for {@link Time}. Contains a port of Bionic's broken strftime_tz to Java.
diff --git a/core/java/android/text/method/BaseKeyListener.java b/core/java/android/text/method/BaseKeyListener.java
index 14e0b4f..90559dc 100644
--- a/core/java/android/text/method/BaseKeyListener.java
+++ b/core/java/android/text/method/BaseKeyListener.java
@@ -19,19 +19,22 @@
 import android.graphics.Paint;
 import android.icu.lang.UCharacter;
 import android.icu.lang.UProperty;
-import android.view.KeyEvent;
-import android.view.View;
-import android.text.*;
+import android.text.Editable;
+import android.text.Emoji;
+import android.text.InputType;
+import android.text.Layout;
+import android.text.NoCopySpan;
+import android.text.Selection;
+import android.text.Spanned;
 import android.text.method.TextKeyListener.Capitalize;
 import android.text.style.ReplacementSpan;
+import android.view.KeyEvent;
+import android.view.View;
 import android.widget.TextView;
 
 import com.android.internal.annotations.GuardedBy;
 
 import java.text.BreakIterator;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
 
 /**
  * Abstract base class for key listeners.
diff --git a/core/java/android/text/method/CharacterPickerDialog.java b/core/java/android/text/method/CharacterPickerDialog.java
index 880e46d..7d838e0 100644
--- a/core/java/android/text/method/CharacterPickerDialog.java
+++ b/core/java/android/text/method/CharacterPickerDialog.java
@@ -16,24 +16,25 @@
 
 package android.text.method;
 
-import com.android.internal.R;
-
 import android.app.Dialog;
 import android.content.Context;
 import android.os.Bundle;
-import android.text.*;
+import android.text.Editable;
+import android.text.Selection;
 import android.view.LayoutInflater;
-import android.view.View.OnClickListener;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
-import android.widget.AdapterView.OnItemClickListener;
 import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
 import android.widget.BaseAdapter;
 import android.widget.Button;
 import android.widget.GridView;
 
+import com.android.internal.R;
+
 /**
  * Dialog for choosing accented characters related to a base character.
  */
diff --git a/core/java/android/text/method/DateKeyListener.java b/core/java/android/text/method/DateKeyListener.java
index e6f63d1..88ef388 100644
--- a/core/java/android/text/method/DateKeyListener.java
+++ b/core/java/android/text/method/DateKeyListener.java
@@ -16,8 +16,8 @@
 
 package android.text.method;
 
-import android.view.KeyEvent;
 import android.text.InputType;
+import android.view.KeyEvent;
 
 /**
  * For entering dates in a text field.
@@ -32,7 +32,7 @@
         return InputType.TYPE_CLASS_DATETIME
                 | InputType.TYPE_DATETIME_VARIATION_DATE;
     }
-    
+
     @Override
     protected char[] getAcceptedChars()
     {
diff --git a/core/java/android/text/method/DialerKeyListener.java b/core/java/android/text/method/DialerKeyListener.java
index bb8b0de..17abed6 100644
--- a/core/java/android/text/method/DialerKeyListener.java
+++ b/core/java/android/text/method/DialerKeyListener.java
@@ -16,10 +16,10 @@
 
 package android.text.method;
 
-import android.view.KeyEvent;
-import android.view.KeyCharacterMap.KeyData;
 import android.text.InputType;
 import android.text.Spannable;
+import android.view.KeyCharacterMap.KeyData;
+import android.view.KeyEvent;
 
 /**
  * For dialing-only text entry
@@ -47,7 +47,7 @@
     public int getInputType() {
         return InputType.TYPE_CLASS_PHONE;
     }
-    
+
     /**
      * Overrides the superclass's lookup method to prefer the number field
      * from the KeyEvent.
diff --git a/core/java/android/text/method/DigitsKeyListener.java b/core/java/android/text/method/DigitsKeyListener.java
index c95df46..4aeb39a 100644
--- a/core/java/android/text/method/DigitsKeyListener.java
+++ b/core/java/android/text/method/DigitsKeyListener.java
@@ -17,8 +17,8 @@
 package android.text.method;
 
 import android.text.InputType;
-import android.text.Spanned;
 import android.text.SpannableStringBuilder;
+import android.text.Spanned;
 import android.view.KeyEvent;
 
 
@@ -133,7 +133,7 @@
         }
         return contentType;
     }
-    
+
     @Override
     public CharSequence filter(CharSequence source, int start, int end,
                                Spanned dest, int dstart, int dend) {
diff --git a/core/java/android/text/method/MetaKeyKeyListener.java b/core/java/android/text/method/MetaKeyKeyListener.java
index e9db5fd..c3c7302 100644
--- a/core/java/android/text/method/MetaKeyKeyListener.java
+++ b/core/java/android/text/method/MetaKeyKeyListener.java
@@ -20,9 +20,9 @@
 import android.text.NoCopySpan;
 import android.text.Spannable;
 import android.text.Spanned;
+import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
 import android.view.View;
-import android.view.KeyCharacterMap;
 
 /**
  * This base class encapsulates the behavior for tracking the state of
@@ -86,7 +86,7 @@
      * Value equals {@link KeyEvent#META_SYM_ON}.
      */
     public static final int META_SYM_ON = KeyEvent.META_SYM_ON;
-    
+
     /**
      * Flag that indicates that the SHIFT key is locked in CAPS mode.
      */
@@ -111,11 +111,11 @@
     private static final long META_CAP_USED = 1L << 32;
     private static final long META_ALT_USED = 1L << 33;
     private static final long META_SYM_USED = 1L << 34;
-    
+
     private static final long META_CAP_PRESSED = 1L << 40;
     private static final long META_ALT_PRESSED = 1L << 41;
     private static final long META_SYM_PRESSED = 1L << 42;
-    
+
     private static final long META_CAP_RELEASED = 1L << 48;
     private static final long META_ALT_RELEASED = 1L << 49;
     private static final long META_SYM_RELEASED = 1L << 50;
@@ -129,7 +129,7 @@
     private static final long META_SYM_MASK = META_SYM_ON
             | META_SYM_LOCKED | META_SYM_USED
             | META_SYM_PRESSED | META_SYM_RELEASED;
-    
+
     private static final Object CAP = new NoCopySpan.Concrete();
     private static final Object ALT = new NoCopySpan.Concrete();
     private static final Object SYM = new NoCopySpan.Concrete();
@@ -150,7 +150,7 @@
 
     /**
      * Gets the state of the meta keys.
-     * 
+     *
      * @param text the buffer in which the meta key would have been pressed.
      *
      * @return an integer in which each bit set to one represents a pressed
@@ -448,7 +448,7 @@
 
     /**
      * Gets the state of the meta keys.
-     * 
+     *
      * @param state the current meta state bits.
      *
      * @return an integer in which each bit set to one represents a pressed
@@ -635,26 +635,26 @@
     /**
      * The meta key has been pressed but has not yet been used.
      */
-    private static final int PRESSED = 
+    private static final int PRESSED =
         Spannable.SPAN_MARK_MARK | (1 << Spannable.SPAN_USER_SHIFT);
 
     /**
      * The meta key has been pressed and released but has still
      * not yet been used.
      */
-    private static final int RELEASED = 
+    private static final int RELEASED =
         Spannable.SPAN_MARK_MARK | (2 << Spannable.SPAN_USER_SHIFT);
 
     /**
      * The meta key has been pressed and used but has not yet been released.
      */
-    private static final int USED = 
+    private static final int USED =
         Spannable.SPAN_MARK_MARK | (3 << Spannable.SPAN_USER_SHIFT);
 
     /**
      * The meta key has been pressed and released without use, and then
      * pressed again; it may also have been released again.
      */
-    private static final int LOCKED = 
+    private static final int LOCKED =
         Spannable.SPAN_MARK_MARK | (4 << Spannable.SPAN_USER_SHIFT);
 }
diff --git a/core/java/android/text/method/MovementMethod.java b/core/java/android/text/method/MovementMethod.java
index 01979fd..f6fe575 100644
--- a/core/java/android/text/method/MovementMethod.java
+++ b/core/java/android/text/method/MovementMethod.java
@@ -16,10 +16,10 @@
 
 package android.text.method;
 
-import android.widget.TextView;
+import android.text.Spannable;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
-import android.text.*;
+import android.widget.TextView;
 
 /**
  * Provides cursor positioning, scrolling and text selection functionality in a {@link TextView}.
diff --git a/core/java/android/text/method/MultiTapKeyListener.java b/core/java/android/text/method/MultiTapKeyListener.java
index 95ac0a1..5770482 100644
--- a/core/java/android/text/method/MultiTapKeyListener.java
+++ b/core/java/android/text/method/MultiTapKeyListener.java
@@ -16,13 +16,16 @@
 
 package android.text.method;
 
-import android.view.KeyEvent;
-import android.view.View;
 import android.os.Handler;
 import android.os.SystemClock;
-import android.text.*;
+import android.text.Editable;
+import android.text.Selection;
+import android.text.SpanWatcher;
+import android.text.Spannable;
 import android.text.method.TextKeyListener.Capitalize;
 import android.util.SparseArray;
+import android.view.KeyEvent;
+import android.view.View;
 
 /**
  * This is the standard key listener for alphabetic input on 12-key
@@ -81,7 +84,7 @@
     public int getInputType() {
         return makeTextContentType(mCapitalize, mAutoText);
     }
-    
+
     public boolean onKeyDown(View view, Editable content,
                              int keyCode, KeyEvent event) {
         int selStart, selEnd;
@@ -198,7 +201,7 @@
             if (selEnd != oldStart) {
                 Selection.setSelection(content, oldStart, selEnd);
 
-                content.setSpan(TextKeyListener.LAST_TYPED, 
+                content.setSpan(TextKeyListener.LAST_TYPED,
                                 oldStart, selEnd,
                                 Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 
diff --git a/core/java/android/text/method/NumberKeyListener.java b/core/java/android/text/method/NumberKeyListener.java
index 988d566..6b12b7e 100644
--- a/core/java/android/text/method/NumberKeyListener.java
+++ b/core/java/android/text/method/NumberKeyListener.java
@@ -16,14 +16,14 @@
 
 package android.text.method;
 
-import android.view.KeyEvent;
-import android.view.View;
 import android.text.Editable;
 import android.text.InputFilter;
 import android.text.Selection;
 import android.text.Spannable;
 import android.text.SpannableStringBuilder;
 import android.text.Spanned;
+import android.view.KeyEvent;
+import android.view.View;
 
 /**
  * For numeric text entry
@@ -91,7 +91,7 @@
 
         return false;
     }
-    
+
     @Override
     public boolean onKeyDown(View view, Editable content,
                              int keyCode, KeyEvent event) {
diff --git a/core/java/android/text/method/PasswordTransformationMethod.java b/core/java/android/text/method/PasswordTransformationMethod.java
index 88a69b9..4485e38 100644
--- a/core/java/android/text/method/PasswordTransformationMethod.java
+++ b/core/java/android/text/method/PasswordTransformationMethod.java
@@ -16,18 +16,18 @@
 
 package android.text.method;
 
+import android.graphics.Rect;
 import android.os.Handler;
 import android.os.SystemClock;
-import android.graphics.Rect;
-import android.view.View;
 import android.text.Editable;
 import android.text.GetChars;
 import android.text.NoCopySpan;
+import android.text.Spannable;
+import android.text.Spanned;
 import android.text.TextUtils;
 import android.text.TextWatcher;
-import android.text.Spanned;
-import android.text.Spannable;
 import android.text.style.UpdateLayout;
+import android.view.View;
 
 import java.lang.ref.WeakReference;
 
diff --git a/core/java/android/text/method/QwertyKeyListener.java b/core/java/android/text/method/QwertyKeyListener.java
index b17f502..bea68b1 100644
--- a/core/java/android/text/method/QwertyKeyListener.java
+++ b/core/java/android/text/method/QwertyKeyListener.java
@@ -16,7 +16,12 @@
 
 package android.text.method;
 
-import android.text.*;
+import android.text.AutoText;
+import android.text.Editable;
+import android.text.NoCopySpan;
+import android.text.Selection;
+import android.text.Spannable;
+import android.text.TextUtils;
 import android.text.method.TextKeyListener.Capitalize;
 import android.util.SparseArray;
 import android.view.KeyCharacterMap;
@@ -80,7 +85,7 @@
     public int getInputType() {
         return makeTextContentType(mAutoCap, mAutoText);
     }
-    
+
     public boolean onKeyDown(View view, Editable content,
                              int keyCode, KeyEvent event) {
         int selStart, selEnd;
@@ -191,9 +196,9 @@
                 }
             }
 
-            if ((pref & TextKeyListener.AUTO_CAP) != 0 &&
-                Character.isLowerCase(i) && 
-                TextKeyListener.shouldCap(mAutoCap, content, selStart)) {
+            if ((pref & TextKeyListener.AUTO_CAP) != 0
+                    && Character.isLowerCase(i)
+                    && TextKeyListener.shouldCap(mAutoCap, content, selStart)) {
                 int where = content.getSpanEnd(TextKeyListener.CAPPED);
                 int flags = content.getSpanFlags(TextKeyListener.CAPPED);
 
@@ -361,9 +366,9 @@
                                   View view) {
         int len = end - start;
         boolean changecase = false;
-        
+
         String replacement = AutoText.get(src, start, end, view);
-        
+
         if (replacement == null) {
             String key = TextUtils.substring(src, start, end).toLowerCase();
             replacement = AutoText.get(key, 0, end - start, view);
@@ -372,7 +377,7 @@
             if (replacement == null)
                 return null;
         }
-        
+
         int caps = 0;
 
         if (changecase) {
diff --git a/core/java/android/text/method/ScrollingMovementMethod.java b/core/java/android/text/method/ScrollingMovementMethod.java
index b9f5d5f4..4f422cb 100644
--- a/core/java/android/text/method/ScrollingMovementMethod.java
+++ b/core/java/android/text/method/ScrollingMovementMethod.java
@@ -16,10 +16,11 @@
 
 package android.text.method;
 
+import android.text.Layout;
+import android.text.Spannable;
 import android.view.MotionEvent;
-import android.text.*;
-import android.widget.TextView;
 import android.view.View;
+import android.widget.TextView;
 
 /**
  * A movement method that interprets movement keys by scrolling the text buffer.
diff --git a/core/java/android/text/method/TextKeyListener.java b/core/java/android/text/method/TextKeyListener.java
index 994f3d7..9cbda9c 100644
--- a/core/java/android/text/method/TextKeyListener.java
+++ b/core/java/android/text/method/TextKeyListener.java
@@ -22,11 +22,16 @@
 import android.os.Handler;
 import android.provider.Settings;
 import android.provider.Settings.System;
-import android.text.*;
+import android.text.Editable;
+import android.text.InputType;
+import android.text.NoCopySpan;
+import android.text.Selection;
+import android.text.SpanWatcher;
+import android.text.Spannable;
+import android.text.TextUtils;
 import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
 import android.view.View;
-import android.text.InputType;
 
 import java.lang.ref.WeakReference;
 
@@ -127,7 +132,7 @@
     public int getInputType() {
         return makeTextContentType(mAutoCap, mAutoText);
     }
-    
+
     @Override
     public boolean onKeyDown(View view, Editable content,
                              int keyCode, KeyEvent event) {
@@ -213,7 +218,7 @@
         public int getInputType() {
             return InputType.TYPE_NULL;
         }
-        
+
         public boolean onKeyDown(View view, Editable content,
                                  int keyCode, KeyEvent event) {
             return false;
@@ -230,7 +235,7 @@
 
         public void clearMetaKeyState(View view, Editable content, int states) {
         }
-        
+
         public static NullKeyListener getInstance() {
             if (sInstance != null)
                 return sInstance;
diff --git a/core/java/android/text/method/TimeKeyListener.java b/core/java/android/text/method/TimeKeyListener.java
index c5bfd5c..01f4086 100644
--- a/core/java/android/text/method/TimeKeyListener.java
+++ b/core/java/android/text/method/TimeKeyListener.java
@@ -16,8 +16,8 @@
 
 package android.text.method;
 
-import android.view.KeyEvent;
 import android.text.InputType;
+import android.view.KeyEvent;
 
 /**
  * For entering times in a text field.
@@ -32,7 +32,7 @@
         return InputType.TYPE_CLASS_DATETIME
         | InputType.TYPE_DATETIME_VARIATION_TIME;
     }
-    
+
     @Override
     protected char[] getAcceptedChars()
     {
diff --git a/core/java/android/text/method/WordIterator.java b/core/java/android/text/method/WordIterator.java
index 89ed08c..17938a8 100644
--- a/core/java/android/text/method/WordIterator.java
+++ b/core/java/android/text/method/WordIterator.java
@@ -18,8 +18,8 @@
 
 import android.annotation.NonNull;
 import android.icu.text.BreakIterator;
-import android.text.Selection;
 import android.text.CharSequenceCharacterIterator;
+import android.text.Selection;
 
 import java.util.Locale;
 
diff --git a/core/java/android/text/style/DrawableMarginSpan.java b/core/java/android/text/style/DrawableMarginSpan.java
index 20b6886..3524179 100644
--- a/core/java/android/text/style/DrawableMarginSpan.java
+++ b/core/java/android/text/style/DrawableMarginSpan.java
@@ -16,11 +16,11 @@
 
 package android.text.style;
 
-import android.graphics.drawable.Drawable;
-import android.graphics.Paint;
 import android.graphics.Canvas;
-import android.text.Spanned;
+import android.graphics.Paint;
+import android.graphics.drawable.Drawable;
 import android.text.Layout;
+import android.text.Spanned;
 
 public class DrawableMarginSpan
 implements LeadingMarginSpan, LineHeightSpan
diff --git a/core/java/android/text/style/IconMarginSpan.java b/core/java/android/text/style/IconMarginSpan.java
index cf9a705..304c83f 100644
--- a/core/java/android/text/style/IconMarginSpan.java
+++ b/core/java/android/text/style/IconMarginSpan.java
@@ -16,11 +16,11 @@
 
 package android.text.style;
 
-import android.graphics.Paint;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
-import android.text.Spanned;
+import android.graphics.Paint;
 import android.text.Layout;
+import android.text.Spanned;
 
 public class IconMarginSpan
 implements LeadingMarginSpan, LineHeightSpan
diff --git a/core/java/android/text/style/LeadingMarginSpan.java b/core/java/android/text/style/LeadingMarginSpan.java
index 339d885..5bd2d60 100644
--- a/core/java/android/text/style/LeadingMarginSpan.java
+++ b/core/java/android/text/style/LeadingMarginSpan.java
@@ -16,8 +16,8 @@
 
 package android.text.style;
 
-import android.graphics.Paint;
 import android.graphics.Canvas;
+import android.graphics.Paint;
 import android.os.Parcel;
 import android.text.Layout;
 import android.text.ParcelableSpan;
@@ -39,7 +39,7 @@
      * Returns the amount by which to adjust the leading margin. Positive values
      * move away from the leading edge of the paragraph, negative values move
      * towards it.
-     * 
+     *
      * @param first true if the request is for the first line of a paragraph,
      * false for subsequent lines
      * @return the offset for the margin.
@@ -49,7 +49,7 @@
     /**
      * Renders the leading margin.  This is called before the margin has been
      * adjusted by the value returned by {@link #getLeadingMargin(boolean)}.
-     * 
+     *
      * @param c the canvas
      * @param p the paint. The this should be left unchanged on exit.
      * @param x the current position of the margin
@@ -98,11 +98,11 @@
      */
     public static class Standard implements LeadingMarginSpan, ParcelableSpan {
         private final int mFirst, mRest;
-        
+
         /**
          * Constructor taking separate indents for the first and subsequent
          * lines.
-         * 
+         *
          * @param first the indent for the first line of the paragraph
          * @param rest the indent for the remaining lines of the paragraph
          */
@@ -123,7 +123,7 @@
             mFirst = src.readInt();
             mRest = src.readInt();
         }
-        
+
         public int getSpanTypeId() {
         return getSpanTypeIdInternal();
     }
@@ -132,7 +132,7 @@
     public int getSpanTypeIdInternal() {
             return TextUtils.LEADING_MARGIN_SPAN;
         }
-        
+
         public int describeContents() {
             return 0;
         }
diff --git a/core/java/android/text/style/LineBackgroundSpan.java b/core/java/android/text/style/LineBackgroundSpan.java
index 854aeaf..9c7859f 100644
--- a/core/java/android/text/style/LineBackgroundSpan.java
+++ b/core/java/android/text/style/LineBackgroundSpan.java
@@ -16,8 +16,8 @@
 
 package android.text.style;
 
-import android.graphics.Paint;
 import android.graphics.Canvas;
+import android.graphics.Paint;
 
 public interface LineBackgroundSpan
 extends ParagraphStyle
diff --git a/core/java/android/text/style/LocaleSpan.java b/core/java/android/text/style/LocaleSpan.java
index b842851..479ff0e 100644
--- a/core/java/android/text/style/LocaleSpan.java
+++ b/core/java/android/text/style/LocaleSpan.java
@@ -16,8 +16,6 @@
 
 package android.text.style;
 
-import com.android.internal.util.Preconditions;
-
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.graphics.Paint;
@@ -27,6 +25,8 @@
 import android.text.TextPaint;
 import android.text.TextUtils;
 
+import com.android.internal.util.Preconditions;
+
 import java.util.Locale;
 
 /**
diff --git a/core/java/android/text/style/QuoteSpan.java b/core/java/android/text/style/QuoteSpan.java
index 0b0a82c..7217e1e 100644
--- a/core/java/android/text/style/QuoteSpan.java
+++ b/core/java/android/text/style/QuoteSpan.java
@@ -17,8 +17,8 @@
 package android.text.style;
 
 import android.annotation.ColorInt;
-import android.graphics.Paint;
 import android.graphics.Canvas;
+import android.graphics.Paint;
 import android.os.Parcel;
 import android.text.Layout;
 import android.text.ParcelableSpan;
@@ -34,7 +34,7 @@
         super();
         mColor = 0xff0000ff;
     }
-    
+
     public QuoteSpan(@ColorInt int color) {
         super();
         mColor = color;
@@ -43,7 +43,7 @@
     public QuoteSpan(Parcel src) {
         mColor = src.readInt();
     }
-    
+
     public int getSpanTypeId() {
         return getSpanTypeIdInternal();
     }
@@ -52,7 +52,7 @@
     public int getSpanTypeIdInternal() {
         return TextUtils.QUOTE_SPAN;
     }
-    
+
     public int describeContents() {
         return 0;
     }
@@ -70,7 +70,7 @@
     public int getColor() {
         return mColor;
     }
-    
+
     public int getLeadingMargin(boolean first) {
         return STRIPE_WIDTH + GAP_WIDTH;
     }
diff --git a/core/java/android/text/style/ReplacementSpan.java b/core/java/android/text/style/ReplacementSpan.java
index 07190b2..5f94ad0 100644
--- a/core/java/android/text/style/ReplacementSpan.java
+++ b/core/java/android/text/style/ReplacementSpan.java
@@ -19,8 +19,8 @@
 import android.annotation.IntRange;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.graphics.Paint;
 import android.graphics.Canvas;
+import android.graphics.Paint;
 import android.text.TextPaint;
 
 public abstract class ReplacementSpan extends MetricAffectingSpan {
diff --git a/core/java/android/text/style/TtsSpan.java b/core/java/android/text/style/TtsSpan.java
index e9153dd..c5e5df0 100644
--- a/core/java/android/text/style/TtsSpan.java
+++ b/core/java/android/text/style/TtsSpan.java
@@ -16,14 +16,14 @@
 
 package android.text.style;
 
-import java.text.NumberFormat;
-import java.util.Locale;
-
 import android.os.Parcel;
 import android.os.PersistableBundle;
 import android.text.ParcelableSpan;
 import android.text.TextUtils;
 
+import java.text.NumberFormat;
+import java.util.Locale;
+
 /**
  * A span that supplies additional meta-data for the associated text intended
  * for text-to-speech engines. If the text is being processed by a
diff --git a/core/java/android/text/util/Linkify.java b/core/java/android/text/util/Linkify.java
index ca037a2..7e6eb49 100644
--- a/core/java/android/text/util/Linkify.java
+++ b/core/java/android/text/util/Linkify.java
@@ -20,16 +20,21 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.telephony.PhoneNumberUtils;
-import android.text.method.LinkMovementMethod;
-import android.text.method.MovementMethod;
-import android.text.style.URLSpan;
 import android.text.Spannable;
 import android.text.SpannableString;
 import android.text.Spanned;
+import android.text.method.LinkMovementMethod;
+import android.text.method.MovementMethod;
+import android.text.style.URLSpan;
 import android.util.Patterns;
 import android.webkit.WebView;
 import android.widget.TextView;
 
+import com.android.i18n.phonenumbers.PhoneNumberMatch;
+import com.android.i18n.phonenumbers.PhoneNumberUtil;
+import com.android.i18n.phonenumbers.PhoneNumberUtil.Leniency;
+
+import libcore.util.EmptyArray;
 
 import java.io.UnsupportedEncodingException;
 import java.lang.annotation.Retention;
@@ -42,12 +47,6 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import com.android.i18n.phonenumbers.PhoneNumberMatch;
-import com.android.i18n.phonenumbers.PhoneNumberUtil;
-import com.android.i18n.phonenumbers.PhoneNumberUtil.Leniency;
-
-import libcore.util.EmptyArray;
-
 /**
  *  Linkify take a piece of text and a regular expression and turns all of the
  *  regex matches in the text into clickable links.  This is particularly
diff --git a/core/java/android/transition/ChangeBounds.java b/core/java/android/transition/ChangeBounds.java
index a95da97..b6d8aa4 100644
--- a/core/java/android/transition/ChangeBounds.java
+++ b/core/java/android/transition/ChangeBounds.java
@@ -16,19 +16,18 @@
 
 package android.transition;
 
-import android.animation.AnimatorSet;
-import android.content.Context;
-import android.content.res.TypedArray;
-import android.graphics.PointF;
-
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
+import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.animation.PropertyValuesHolder;
 import android.animation.RectEvaluator;
+import android.content.Context;
+import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Path;
+import android.graphics.PointF;
 import android.graphics.Rect;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
diff --git a/core/java/android/transition/ChangeScroll.java b/core/java/android/transition/ChangeScroll.java
index e092685..8a3fd1c 100644
--- a/core/java/android/transition/ChangeScroll.java
+++ b/core/java/android/transition/ChangeScroll.java
@@ -19,8 +19,6 @@
 import android.animation.Animator;
 import android.animation.ObjectAnimator;
 import android.content.Context;
-import android.transition.Transition;
-import android.transition.TransitionValues;
 import android.util.AttributeSet;
 import android.view.View;
 import android.view.ViewGroup;
diff --git a/core/java/android/transition/ChangeTransform.java b/core/java/android/transition/ChangeTransform.java
index 9749121..4b0b065 100644
--- a/core/java/android/transition/ChangeTransform.java
+++ b/core/java/android/transition/ChangeTransform.java
@@ -30,6 +30,7 @@
 import android.view.GhostView;
 import android.view.View;
 import android.view.ViewGroup;
+
 import com.android.internal.R;
 
 /**
diff --git a/core/java/android/transition/Explode.java b/core/java/android/transition/Explode.java
index 3445ef2..5f078ca 100644
--- a/core/java/android/transition/Explode.java
+++ b/core/java/android/transition/Explode.java
@@ -15,8 +15,6 @@
  */
 package android.transition;
 
-import com.android.internal.R;
-
 import android.animation.Animator;
 import android.animation.TimeInterpolator;
 import android.content.Context;
@@ -26,6 +24,8 @@
 import android.view.ViewGroup;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
+
+import com.android.internal.R;
 /**
  * This transition tracks changes to the visibility of target views in the
  * start and end scenes and moves views in or out from the edges of the
diff --git a/core/java/android/transition/PatternPathMotion.java b/core/java/android/transition/PatternPathMotion.java
index f23863f..7a2c191 100644
--- a/core/java/android/transition/PatternPathMotion.java
+++ b/core/java/android/transition/PatternPathMotion.java
@@ -15,8 +15,6 @@
  */
 package android.transition;
 
-import com.android.internal.R;
-
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Matrix;
@@ -25,6 +23,8 @@
 import android.util.AttributeSet;
 import android.util.PathParser;
 
+import com.android.internal.R;
+
 /**
  * A PathMotion that takes a Path pattern and applies it to the separation between two points.
  * The starting point of the Path will be moved to the origin and the end point will be scaled
diff --git a/core/java/android/transition/Slide.java b/core/java/android/transition/Slide.java
index 2645f86..9cf3210 100644
--- a/core/java/android/transition/Slide.java
+++ b/core/java/android/transition/Slide.java
@@ -26,6 +26,7 @@
 import android.view.ViewGroup;
 import android.view.animation.AccelerateInterpolator;
 import android.view.animation.DecelerateInterpolator;
+
 import com.android.internal.R;
 
 import java.lang.annotation.Retention;
diff --git a/core/java/android/transition/TransitionInflater.java b/core/java/android/transition/TransitionInflater.java
index cbf76bc..4c5a717 100644
--- a/core/java/android/transition/TransitionInflater.java
+++ b/core/java/android/transition/TransitionInflater.java
@@ -17,11 +17,6 @@
 package android.transition;
 
 import android.annotation.TransitionRes;
-import com.android.internal.R;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
 import android.content.Context;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
@@ -32,6 +27,11 @@
 import android.view.InflateException;
 import android.view.ViewGroup;
 
+import com.android.internal.R;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
diff --git a/core/java/android/transition/TranslationAnimationCreator.java b/core/java/android/transition/TranslationAnimationCreator.java
index b07f3f8..ae76e62 100644
--- a/core/java/android/transition/TranslationAnimationCreator.java
+++ b/core/java/android/transition/TranslationAnimationCreator.java
@@ -15,8 +15,6 @@
  */
 package android.transition;
 
-import com.android.internal.R;
-
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.ObjectAnimator;
@@ -25,6 +23,8 @@
 import android.transition.Transition.TransitionListener;
 import android.view.View;
 
+import com.android.internal.R;
+
 /**
  * This class is used by Slide and Explode to create an animator that goes from the start
  * position to the end position. It takes into account the canceled position so that it
diff --git a/core/java/android/util/DisplayMetrics.java b/core/java/android/util/DisplayMetrics.java
index f4db4d6..b7099b6 100644
--- a/core/java/android/util/DisplayMetrics.java
+++ b/core/java/android/util/DisplayMetrics.java
@@ -268,6 +268,10 @@
     }
     
     public void setTo(DisplayMetrics o) {
+        if (this == o) {
+            return;
+        }
+
         widthPixels = o.widthPixels;
         heightPixels = o.heightPixels;
         density = o.density;
diff --git a/core/java/android/util/proto/EncodedBuffer.java b/core/java/android/util/proto/EncodedBuffer.java
new file mode 100644
index 0000000..ed38e6f
--- /dev/null
+++ b/core/java/android/util/proto/EncodedBuffer.java
@@ -0,0 +1,678 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.util.proto;
+
+import android.annotation.TestApi;
+import android.util.Log;
+
+import java.util.ArrayList;
+
+/**
+ * A stream of bytes containing a read pointer and a write pointer,
+ * backed by a set of fixed-size buffers.  There are write functions for the
+ * primitive types stored by protocol buffers, but none of the logic
+ * for tags, inner objects, or any of that.
+ *
+ * Terminology:
+ *      *Pos:       Position in the whole data set (as if it were a single buffer).
+ *      *Index:     Position within a buffer.
+ *      *BufIndex:  Index of a buffer within the mBuffers list
+ * @hide
+ */
+@TestApi
+public final class EncodedBuffer {
+    private static final String TAG = "EncodedBuffer";
+
+    private final ArrayList<byte[]> mBuffers = new ArrayList<byte[]>();
+
+    private final int mChunkSize;
+
+    /**
+     * The number of buffers in mBuffers. Stored separately to avoid the extra
+     * function call to size() everywhere for bounds checking.
+     */
+    private int mBufferCount;
+
+    /**
+     * The buffer we are currently writing to.
+     */
+    private byte[] mWriteBuffer;
+
+    /**
+     * The index into mWriteBuffer that we will write to next.
+     * It may point to the end of the buffer, in which case,
+     * the NEXT write will allocate a new buffer.
+     */
+    private int mWriteIndex;
+
+    /**
+     * The index of mWriteBuffer in mBuffers.
+     */
+    private int mWriteBufIndex;
+
+    /**
+     * The buffer we are currently reading from.
+     */
+    private byte[] mReadBuffer;
+
+    /**
+     * The index of mReadBuffer in mBuffers.
+     */
+    private int mReadBufIndex;
+
+    /**
+     * The index into mReadBuffer that we will read from next.
+     * It may point to the end of the buffer, in which case,
+     * the NEXT read will advance to the next buffer.
+     */
+    private int mReadIndex;
+
+    /**
+     * The amount of data in the last buffer.
+     */
+    private int mReadLimit = -1;
+
+    /**
+     * How much data there is total.
+     */
+    private int mReadableSize = -1;
+
+    public EncodedBuffer() {
+        this(0);
+    }
+
+    /**
+     * Construct an EncodedBuffer object.
+     *
+     * @param chunkSize The size of the buffers to use.  If chunkSize &lt;= 0, a default
+     *                  size will be used instead.
+     */
+    public EncodedBuffer(int chunkSize) {
+        if (chunkSize <= 0) {
+            chunkSize = 8 * 1024;
+        }
+        mChunkSize = chunkSize;
+        mWriteBuffer = new byte[mChunkSize];
+        mBuffers.add(mWriteBuffer);
+        mBufferCount = 1;
+    }
+
+    //
+    // Buffer management.
+    //
+
+    /**
+     * Rewind the read and write pointers, and record how much data was last written.
+     */
+    public void startEditing() {
+        mReadableSize = ((mWriteBufIndex) * mChunkSize) + mWriteIndex;
+        mReadLimit = mWriteIndex;
+
+        mWriteBuffer = mBuffers.get(0);
+        mWriteIndex = 0;
+        mWriteBufIndex = 0;
+
+        mReadBuffer = mWriteBuffer;
+        mReadBufIndex = 0;
+        mReadIndex = 0;
+    }
+
+    /**
+     * Rewind the read pointer. Don't touch the write pointer.
+     */
+    public void rewindRead() {
+        mReadBuffer = mBuffers.get(0);
+        mReadBufIndex = 0;
+        mReadIndex = 0;
+    }
+
+    /**
+     * Only valid after startEditing. Returns -1 before that.
+     */
+    public int getReadableSize() {
+        return mReadableSize;
+    }
+
+    //
+    // Reading from the read position.
+    //
+
+    /**
+     * Only valid after startEditing.
+     */
+    public int getReadPos() {
+        return ((mReadBufIndex) * mChunkSize) + mReadIndex;
+    }
+
+    /**
+     * Skip over _amount_ bytes.
+     */
+    public void skipRead(int amount) {
+        if (amount < 0) {
+            throw new RuntimeException("skipRead with negative amount=" + amount);
+        }
+        if (amount == 0) {
+            return;
+        }
+        if (amount <= mChunkSize - mReadIndex) {
+            mReadIndex += amount;
+        } else {
+            amount -= mChunkSize - mReadIndex;
+            mReadIndex = amount % mChunkSize;
+            if (mReadIndex == 0) {
+                mReadIndex = mChunkSize;
+                mReadBufIndex += (amount / mChunkSize);
+            } else {
+                mReadBufIndex += 1 + (amount / mChunkSize);
+            }
+            mReadBuffer = mBuffers.get(mReadBufIndex);
+        }
+    }
+
+    /**
+     * Read one byte from the stream and advance the read pointer.
+     *
+     * @throws IndexOutOfBoundsException if the read point is past the end of
+     * the buffer or past the read limit previously set by startEditing().
+     */
+    public byte readRawByte() {
+        if (mReadBufIndex > mBufferCount
+                || (mReadBufIndex == mBufferCount - 1 && mReadIndex >= mReadLimit)) {
+            throw new IndexOutOfBoundsException("Trying to read too much data"
+                    + " mReadBufIndex=" + mReadBufIndex + " mBufferCount=" + mBufferCount
+                    + " mReadIndex=" + mReadIndex + " mReadLimit=" + mReadLimit);
+        }
+        if (mReadIndex >= mChunkSize) {
+            mReadBufIndex++;
+            mReadBuffer = mBuffers.get(mReadBufIndex);
+            mReadIndex = 0;
+        }
+        return mReadBuffer[mReadIndex++];
+    }
+
+    /**
+     * Read an unsigned varint. The value will be returend in a java signed long.
+     */
+    public long readRawUnsigned() {
+        int bits = 0;
+        long result = 0;
+        while (true) {
+            final byte b = readRawByte();
+            result |= ((long)(b & 0x7F)) << bits;
+            if ((b & 0x80) == 0) {
+                return result;
+            }
+            bits += 7;
+            if (bits > 64) {
+                throw new ProtoParseException("Varint too long -- " + getDebugString());
+            }
+        }
+    }
+
+    /**
+     * Read 32 little endian bits from the stream.
+     */
+    public int readRawFixed32() {
+        return (readRawByte() & 0x0ff)
+                | ((readRawByte() & 0x0ff) << 8)
+                | ((readRawByte() & 0x0ff) << 16)
+                | ((readRawByte() & 0x0ff) << 24);
+    }
+
+    //
+    // Writing at a the end of the stream.
+    //
+
+    /**
+     * Advance to the next write buffer, allocating it if necessary.
+     *
+     * Must be called immediately <b>before</b> the next write, not after a write,
+     * so that a dangling empty buffer is not created.  Doing so will interfere
+     * with the expectation that mWriteIndex will point past the end of the buffer
+     * until the next read happens.
+     */
+    private void nextWriteBuffer() {
+        mWriteBufIndex++;
+        if (mWriteBufIndex >= mBufferCount) {
+            mWriteBuffer = new byte[mChunkSize];
+            mBuffers.add(mWriteBuffer);
+            mBufferCount++;
+        } else {
+            mWriteBuffer = mBuffers.get(mWriteBufIndex);
+        }
+        mWriteIndex = 0;
+    }
+
+    /**
+     * Write a single byte to the stream.
+     */
+    public void writeRawByte(byte val) {
+        if (mWriteIndex >= mChunkSize) {
+            nextWriteBuffer();
+        }
+        mWriteBuffer[mWriteIndex++] = val;
+    }
+
+    /**
+     * Return how many bytes a 32 bit unsigned varint will take when written to the stream.
+     */
+    public static int getRawVarint32Size(int val) {
+        if ((val & (0xffffffff << 7)) == 0) return 1;
+        if ((val & (0xffffffff << 14)) == 0) return 2;
+        if ((val & (0xffffffff << 21)) == 0) return 3;
+        if ((val & (0xffffffff << 28)) == 0) return 4;
+        return 5;
+    }
+
+    /**
+     * Write an unsigned varint to the stream. A signed value would need to take 10 bytes.
+     *
+     * @param val treated as unsigned.
+     */
+    public void writeRawVarint32(int val) {
+        while (true) {
+            if ((val & ~0x7F) == 0) {
+                writeRawByte((byte)val);
+                return;
+            } else {
+                writeRawByte((byte)((val & 0x7F) | 0x80));
+                val >>>= 7;
+            }
+        }
+    }
+
+    /**
+     * Return how many bytes a 32 bit signed zig zag value will take when written to the stream.
+     */
+    public static int getRawZigZag32Size(int val) {
+        return getRawVarint32Size(zigZag32(val));
+    }
+
+    /**
+     *  Write a zig-zag encoded value.
+     *
+     *  @param val treated as signed
+     */
+    public void writeRawZigZag32(int val) {
+        writeRawVarint32(zigZag32(val));
+    }
+
+    /**
+     * Return how many bytes a 64 bit varint will take when written to the stream.
+     */
+    public static int getRawVarint64Size(long val) {
+        if ((val & (0xffffffffffffffffL << 7)) == 0) return 1;
+        if ((val & (0xffffffffffffffffL << 14)) == 0) return 2;
+        if ((val & (0xffffffffffffffffL << 21)) == 0) return 3;
+        if ((val & (0xffffffffffffffffL << 28)) == 0) return 4;
+        if ((val & (0xffffffffffffffffL << 35)) == 0) return 5;
+        if ((val & (0xffffffffffffffffL << 42)) == 0) return 6;
+        if ((val & (0xffffffffffffffffL << 49)) == 0) return 7;
+        if ((val & (0xffffffffffffffffL << 56)) == 0) return 8;
+        if ((val & (0xffffffffffffffffL << 63)) == 0) return 9;
+        return 10;
+    }
+
+    /**
+     * Write a 64 bit varint to the stream.
+     */
+    public void writeRawVarint64(long val) {
+        while (true) {
+            if ((val & ~0x7FL) == 0) {
+                writeRawByte((byte)val);
+                return;
+            } else {
+                writeRawByte((byte)((val & 0x7F) | 0x80));
+                val >>>= 7;
+            }
+        }
+    }
+
+    /**
+     * Return how many bytes a signed 64 bit zig zag value will take when written to the stream.
+     */
+    public static int getRawZigZag64Size(long val) {
+        return getRawVarint64Size(zigZag64(val));
+    }
+
+    /**
+     * Write a 64 bit signed zig zag value to the stream.
+     */
+    public void writeRawZigZag64(long val) {
+        writeRawVarint64(zigZag64(val));
+    }
+
+    /**
+     * Write 4 little endian bytes to the stream.
+     */
+    public void writeRawFixed32(int val) {
+        writeRawByte((byte)(val));
+        writeRawByte((byte)(val >> 8));
+        writeRawByte((byte)(val >> 16));
+        writeRawByte((byte)(val >> 24));
+    }
+
+    /**
+     * Write 8 little endian bytes to the stream.
+     */
+    public void writeRawFixed64(long val) {
+        writeRawByte((byte)(val));
+        writeRawByte((byte)(val >> 8));
+        writeRawByte((byte)(val >> 16));
+        writeRawByte((byte)(val >> 24));
+        writeRawByte((byte)(val >> 32));
+        writeRawByte((byte)(val >> 40));
+        writeRawByte((byte)(val >> 48));
+        writeRawByte((byte)(val >> 56));
+    }
+
+    /**
+     * Write a buffer to the stream. Writes nothing if val is null or zero-length.
+     */
+    public void writeRawBuffer(byte[] val) {
+        if (val != null && val.length > 0) {
+            writeRawBuffer(val, 0, val.length);
+        }
+    }
+
+    /**
+     * Write part of an array of bytes.
+     */
+    public void writeRawBuffer(byte[] val, int offset, int length) {
+        if (val == null) {
+            return;
+        }
+        // Write up to the amount left in the first chunk to write.
+        int amt = length < (mChunkSize - mWriteIndex) ? length : (mChunkSize - mWriteIndex);
+        if (amt > 0) {
+            System.arraycopy(val, offset, mWriteBuffer, mWriteIndex, amt);
+            mWriteIndex += amt;
+            length -= amt;
+            offset += amt;
+        }
+        while (length > 0) {
+            // We know we're now at the beginning of a chunk
+            nextWriteBuffer();
+            amt = length < mChunkSize ? length : mChunkSize;
+            System.arraycopy(val, offset, mWriteBuffer, mWriteIndex, amt);
+            mWriteIndex += amt;
+            length -= amt;
+            offset += amt;
+        }
+    }
+
+    /**
+     * Copies data _size_ bytes of data within this buffer from _srcOffset_
+     * to the current write position. Like memmov but handles the chunked buffer.
+     */
+    public void writeFromThisBuffer(int srcOffset, int size) {
+        if (mReadLimit < 0) {
+            throw new IllegalStateException("writeFromThisBuffer before startEditing");
+        }
+        if (srcOffset < getWritePos()) {
+            throw new IllegalArgumentException("Can only move forward in the buffer --"
+                    + " srcOffset=" + srcOffset + " size=" + size + " " + getDebugString());
+        }
+        if (srcOffset + size > mReadableSize) {
+            throw new IllegalArgumentException("Trying to move more data than there is --"
+                    + " srcOffset=" + srcOffset + " size=" + size + " " + getDebugString());
+        }
+        if (size == 0) {
+            return;
+        }
+        if (srcOffset == ((mWriteBufIndex) * mChunkSize) + mWriteIndex /* write pos */) {
+            // Writing to the same location. Just advance the write pointer.  We already
+            // checked that size is in bounds, so we don't need to do any more range
+            // checking.
+            if (size <= mChunkSize - mWriteIndex) {
+                mWriteIndex += size;
+            } else {
+                size -= mChunkSize - mWriteIndex;
+                mWriteIndex = size % mChunkSize;
+                if (mWriteIndex == 0) {
+                    // Roll it back so nextWriteBuffer can do its job
+                    // on the next call (also makes mBuffers.get() not
+                    // fail if we're at the end).
+                    mWriteIndex = mChunkSize;
+                    mWriteBufIndex += (size / mChunkSize);
+                } else {
+                    mWriteBufIndex += 1 + (size / mChunkSize);
+                }
+                mWriteBuffer = mBuffers.get(mWriteBufIndex);
+            }
+        } else {
+            // Loop through the buffer, copying as much as we can each time.
+            // We already bounds checked so we don't need to do it again here,
+            // and nextWriteBuffer will never allocate.
+            int readBufIndex = srcOffset / mChunkSize;
+            byte[] readBuffer = mBuffers.get(readBufIndex);
+            int readIndex = srcOffset % mChunkSize;
+            while (size > 0) {
+                if (mWriteIndex >= mChunkSize) {
+                    nextWriteBuffer();
+                }
+                if (readIndex >= mChunkSize) {
+                    readBufIndex++;
+                    readBuffer = mBuffers.get(readBufIndex);
+                    readIndex = 0;
+                }
+                final int spaceInWriteBuffer = mChunkSize - mWriteIndex;
+                final int availableInReadBuffer = mChunkSize - readIndex;
+                final int amt = Math.min(size, Math.min(spaceInWriteBuffer, availableInReadBuffer));
+                System.arraycopy(readBuffer, readIndex, mWriteBuffer, mWriteIndex, amt);
+                mWriteIndex += amt;
+                readIndex += amt;
+                size -= amt;
+            }
+        }
+    }
+
+    //
+    // Writing at a particular location.
+    //
+
+    /**
+     * Returns the index into the virtual array of the write pointer.
+     */
+    public int getWritePos() {
+        return ((mWriteBufIndex) * mChunkSize) + mWriteIndex;
+    }
+
+    /**
+     * Resets the write pointer to a virtual location as returned by getWritePos.
+     */
+    public void rewindWriteTo(int writePos) {
+        if (writePos > getWritePos()) {
+            throw new RuntimeException("rewindWriteTo only can go backwards" + writePos);
+        }
+        mWriteBufIndex = writePos / mChunkSize;
+        mWriteIndex = writePos % mChunkSize;
+        if (mWriteIndex == 0 && mWriteBufIndex != 0) {
+            // Roll back so nextWriteBuffer can do its job on the next call
+            // but at the first write we're at 0.
+            mWriteIndex = mChunkSize;
+            mWriteBufIndex--;
+        }
+        mWriteBuffer = mBuffers.get(mWriteBufIndex);
+    }
+
+    /**
+     * Read a 32 bit value from the stream.
+     *
+     * Doesn't touch or affect mWritePos.
+     */
+    public int getRawFixed32At(int pos) {
+        return (0x00ff & (int)mBuffers.get(pos / mChunkSize)[pos % mChunkSize])
+                | ((0x0ff & (int)mBuffers.get((pos+1) / mChunkSize)[(pos+1) % mChunkSize]) << 8)
+                | ((0x0ff & (int)mBuffers.get((pos+2) / mChunkSize)[(pos+2) % mChunkSize]) << 16)
+                | ((0x0ff & (int)mBuffers.get((pos+3) / mChunkSize)[(pos+3) % mChunkSize]) << 24);
+    }
+
+    /**
+     * Overwrite a 32 bit value in the stream.
+     *
+     * Doesn't touch or affect mWritePos.
+     */
+    public void editRawFixed32(int pos, int val) {
+        mBuffers.get(pos / mChunkSize)[pos % mChunkSize] = (byte)(val);
+        mBuffers.get((pos+1) / mChunkSize)[(pos+1) % mChunkSize] = (byte)(val >> 8);
+        mBuffers.get((pos+2) / mChunkSize)[(pos+2) % mChunkSize] = (byte)(val >> 16);
+        mBuffers.get((pos+3) / mChunkSize)[(pos+3) % mChunkSize] = (byte)(val >> 24);
+    }
+
+    //
+    // Zigging and zagging
+    //
+
+    /**
+     * Zig-zag encode a 32 bit value.
+     */
+    private static int zigZag32(int val) {
+        return (val << 1) ^ (val >> 31);
+    }
+
+    /**
+     * Zig-zag encode a 64 bit value.
+     */
+    private static long zigZag64(long val) {
+        return (val << 1) ^ (val >> 63);
+    }
+
+    //
+    // Debugging / testing
+    //
+    // VisibleForTesting
+
+    /**
+     * Get a copy of the first _size_ bytes of data. This is not range
+     * checked, and if the bounds are outside what has been written you will
+     * get garbage and if it is outside the buffers that have been allocated,
+     * you will get an exception.
+     */
+    public byte[] getBytes(int size) {
+        final byte[] result = new byte[size];
+
+        final int bufCount = size / mChunkSize;
+        int bufIndex;
+        int writeIndex = 0;
+
+        for (bufIndex=0; bufIndex<bufCount; bufIndex++) {
+            System.arraycopy(mBuffers.get(bufIndex), 0, result, writeIndex, mChunkSize);
+            writeIndex += mChunkSize;
+        }
+
+        final int lastSize = size - (bufCount * mChunkSize);
+        if (lastSize > 0) {
+            System.arraycopy(mBuffers.get(bufIndex), 0, result, writeIndex, lastSize);
+        }
+
+        return result;
+    }
+
+    /**
+     * Get the number of chunks allocated.
+     */
+    // VisibleForTesting
+    public int getChunkCount() {
+        return mBuffers.size();
+    }
+
+    /**
+     * Get the write position inside the current write chunk.
+     */
+     // VisibleForTesting
+    public int getWriteIndex() {
+        return mWriteIndex;
+    }
+
+    /**
+     * Get the index of the current write chunk in the list of chunks.
+     */
+    // VisibleForTesting
+    public int getWriteBufIndex() {
+        return mWriteBufIndex;
+    }
+
+    /**
+     * Return debugging information about this EncodedBuffer object.
+     */
+    public String getDebugString() {
+        return "EncodedBuffer( mChunkSize=" + mChunkSize + " mBuffers.size=" + mBuffers.size()
+                + " mBufferCount=" + mBufferCount + " mWriteIndex=" + mWriteIndex
+                + " mWriteBufIndex=" + mWriteBufIndex + " mReadBufIndex=" + mReadBufIndex
+                + " mReadIndex=" + mReadIndex + " mReadableSize=" + mReadableSize
+                + " mReadLimit=" + mReadLimit + " )";
+    }
+
+    /**
+     * Print the internal buffer chunks.
+     */
+    public void dumpBuffers(String tag) {
+        final int N = mBuffers.size();
+        int start = 0;
+        for (int i=0; i<N; i++) {
+            start += dumpByteString(tag, "{" + i + "} ", start, mBuffers.get(i));
+        }
+    }
+
+    /**
+     * Print the internal buffer chunks.
+     */
+    public static void dumpByteString(String tag, String prefix, byte[] buf) {
+        dumpByteString(tag, prefix, 0, buf);
+    }
+
+    /**
+     * Print the internal buffer chunks.
+     */
+    private static int dumpByteString(String tag, String prefix, int start, byte[] buf) {
+        StringBuffer sb = new StringBuffer();
+        final int length = buf.length;
+        final int lineLen = 16;
+        int i;
+        for (i=0; i<length; i++) {
+            if (i % lineLen == 0) {
+                if (i != 0) {
+                    Log.d(tag, sb.toString());
+                    sb = new StringBuffer();
+                }
+                sb.append(prefix);
+                sb.append('[');
+                sb.append(start + i);
+                sb.append(']');
+                sb.append(' ');
+            } else {
+                sb.append(' ');
+            }
+            byte b = buf[i];
+            byte c = (byte)((b >> 4) & 0x0f);
+            if (c < 10) {
+                sb.append((char)('0' + c));
+            } else {
+                sb.append((char)('a' - 10 + c));
+            }
+            byte d = (byte)(b & 0x0f);
+            if (d < 10) {
+                sb.append((char)('0' + d));
+            } else {
+                sb.append((char)('a' - 10 + d));
+            }
+        }
+        Log.d(tag, sb.toString());
+        return length;
+    }
+}
diff --git a/core/java/android/util/proto/ProtoOutputStream.java b/core/java/android/util/proto/ProtoOutputStream.java
new file mode 100644
index 0000000..8f99399
--- /dev/null
+++ b/core/java/android/util/proto/ProtoOutputStream.java
@@ -0,0 +1,1599 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.util.proto;
+
+import android.annotation.TestApi;
+import android.util.Log;
+
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+/**
+ * Class to write to a protobuf stream.
+ *
+ * Each write method takes an ID code from the protoc generated classes
+ * and the value to write.  To make a nested object, call startObject
+ * and then endObject when you are done.
+ *
+ * The ID codes have type information embedded into them, so if you call
+ * the incorrect function you will get an IllegalArgumentException.
+ *
+ * To retrieve the encoded protobuf stream, call getBytes().
+ *
+ * TODO: Add a constructor that takes an OutputStream and write to that
+ * stream as the top-level objects are finished.
+ *
+ * @hide
+ */
+
+/* IMPLEMENTATION NOTES
+ *
+ * Because protobuf has inner values, and they are length prefixed, and
+ * those sizes themselves are stored with a variable length encoding, it
+ * is impossible to know how big an object will be in a single pass.
+ *
+ * The traditional way is to copy the in-memory representation of an object
+ * into the generated proto Message objects, do a traversal of those to
+ * cache the size, and then write the size-prefixed buffers.
+ *
+ * We are trying to avoid too much generated code here, but this class still
+ * needs to have a somewhat sane API.  We can't have the multiple passes be
+ * done by the calling code.  In addition, we want to avoid the memory high
+ * water mark of duplicating all of the values into the traditional in-memory
+ * Message objects. We need to find another way.
+ *
+ * So what we do here is to let the calling code write the data into a
+ * byte[] (actually a collection of them wrapped in the EncodedBuffer) class,
+ * but not do the varint encoding of the sub-message sizes.  Then, we do a
+ * recursive traversal of the buffer itself, calculating the sizes (which are
+ * then knowable, although still not the actual sizes in the buffer because of
+ * possible further nesting).  Then we do a third pass, compacting the
+ * buffer and varint encoding the sizes.
+ *
+ * This gets us a relatively small number number of fixed-size allocations,
+ * which is less likely to cause memory fragmentation or churn the GC, and
+ * the same number of data copies as would have gotten with setting it
+ * field-by-field in generated code, and no code bloat from generated code.
+ * The final data copy is also done with System.arraycopy, which will be
+ * more efficient, in general, than doing the individual fields twice (as in
+ * the traditional way).
+ *
+ * To accomplish the multiple passes, whenever we write a
+ * WIRE_TYPE_LENGTH_DELIMITED field, we write the size occupied in our
+ * buffer as a fixed 32 bit int (called childRawSize), not variable length
+ * one. We reserve another 32 bit slot for the computed size (called
+ * childEncodedSize).  If we know the size up front, as we do for strings
+ * and byte[], then we also put that into childEncodedSize, if we don't, we
+ * write the negative of childRawSize, as a sentiel that we need to
+ * compute it during the second pass and recursively compact it during the
+ * third pass.
+ *
+ * Unsgigned size varints can be up to five bytes long, but we reserve eight
+ * bytes for overhead, so we know that when we compact the buffer, there
+ * will always be space for the encoded varint.
+ *
+ * When we can figure out the size ahead of time, we do, in order
+ * to save overhead with recalculating it, and with the later arraycopy.
+ *
+ * During the period between when the caller has called startObject, but
+ * not yet called endObject, we maintain a linked list of the tokens
+ * returned by startObject, stored in those 8 bytes of size storage space.
+ * We use that linked list of tokens to ensure that the caller has
+ * correctly matched pairs of startObject and endObject calls, and issue
+ * errors if they are not matched.
+ */
+@TestApi
+public final class ProtoOutputStream {
+    public static final String TAG = "ProtoOutputStream";
+
+    public static final int FIELD_ID_SHIFT = 3;
+    public static final int WIRE_TYPE_MASK = (1<<FIELD_ID_SHIFT)-1;
+    public static final int FIELD_ID_MASK = ~WIRE_TYPE_MASK;
+
+    public static final int WIRE_TYPE_VARINT = 0;
+    public static final int WIRE_TYPE_FIXED64 = 1;
+    public static final int WIRE_TYPE_LENGTH_DELIMITED = 2;
+    public static final int WIRE_TYPE_START_GROUP = 3;
+    public static final int WIRE_TYPE_END_GROUP = 4;
+    public static final int WIRE_TYPE_FIXED32 = 5;
+
+    /**
+     * Position of the field type in a (long) fieldId.
+     */
+    public static final int FIELD_TYPE_SHIFT = 32;
+
+    /**
+     * Mask for the field types stored in a fieldId.  Leaves a whole
+     * byte for future expansion, even though there are currently only 17 types.
+     */
+    public static final long FIELD_TYPE_MASK = 0x0ffL << FIELD_TYPE_SHIFT;
+
+    public static final long FIELD_TYPE_UNKNOWN = 0;
+
+    public static final long FIELD_TYPE_DOUBLE = 1L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_FLOAT = 2L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_INT32 = 3L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_INT64 = 4L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_UINT32 = 5L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_UINT64 = 6L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_SINT32 = 7L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_SINT64 = 8L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_FIXED32 = 9L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_FIXED64 = 10L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_SFIXED32 = 11L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_SFIXED64 = 12L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_BOOL = 13L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_STRING = 14L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_BYTES = 15L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_ENUM = 16L << FIELD_TYPE_SHIFT;
+    public static final long FIELD_TYPE_OBJECT = 17L << FIELD_TYPE_SHIFT;
+
+    private static final String[] FIELD_TYPE_NAMES = new String[] {
+        "Double",
+        "Float",
+        "Int32",
+        "Int64",
+        "UInt32",
+        "UInt64",
+        "SInt32",
+        "SInt64",
+        "Fixed32",
+        "Fixed64",
+        "SFixed32",
+        "SFixed64",
+        "Bool",
+        "String",
+        "Bytes",
+        "Enum",
+        "Object",
+    };
+
+    //
+    // FieldId flags for whether the field is single, repeated or packed.
+    //
+    public static final int FIELD_COUNT_SHIFT = 40;
+    public static final long FIELD_COUNT_MASK = 0x0fL << FIELD_COUNT_SHIFT;
+
+    public static final long FIELD_COUNT_UNKNOWN = 0;
+    public static final long FIELD_COUNT_SINGLE = 1L << FIELD_COUNT_SHIFT;
+    public static final long FIELD_COUNT_REPEATED = 2L << FIELD_COUNT_SHIFT;
+    public static final long FIELD_COUNT_PACKED = 5L << FIELD_COUNT_SHIFT;
+
+    /**
+     * Our buffer.
+     */
+    private EncodedBuffer mBuffer;
+
+    /**
+     * Current nesting depth of startObject calls.
+     */
+    private int mDepth;
+
+    /**
+     * An ID given to objects and returned in the token from startObject
+     * and stored in the buffer until endObject is called, where the two
+     * are checked.  Starts at -1 and becomes more negative, so the values
+     * aren't likely to alias with the size it will be overwritten with,
+     * which tend to be small, and we will be more likely to catch when
+     * the caller of endObject uses a stale token that they didn't intend
+     * to (e.g. copy and paste error).
+     */
+    private int mNextObjectId = -1;
+
+    /**
+     * The object token we are expecting in endObject.  If another call to
+     * startObject happens, this is written to that location, which gives
+     * us a stack, stored in the space for the as-yet unused size fields.
+     */
+    private long mExpectedObjectToken;
+
+    /**
+     * Index in mBuffer that we should start copying from on the next
+     * pass of compaction.
+     */
+    private int mCopyBegin;
+
+    /**
+     * Whether we've already compacted
+     */
+    private boolean mCompacted;
+
+    /**
+     * Construct a ProtoOutputStream with the default chunk size.
+     */
+    public ProtoOutputStream() {
+        this(0);
+    }
+
+    /**
+     * Construct a ProtoOutputStream with the given chunk size.
+     */
+    public ProtoOutputStream(int chunkSize) {
+        mBuffer = new EncodedBuffer(chunkSize);
+    }
+
+    //
+    // proto3 type: double
+    // java type: double
+    // encoding: fixed64
+    // wire type: WIRE_TYPE_FIXED64
+    //
+
+    /**
+     * Write a single proto "double" type field value.
+     */
+    public void writeDouble(long fieldId, double val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_DOUBLE);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_FIXED64);
+            mBuffer.writeRawFixed64(Double.doubleToLongBits(val));
+        }
+    }
+
+    /**
+     * Write a single repeated proto "double" type field value.
+     */
+    public void writeRepeatedDouble(long fieldId, double val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_DOUBLE);
+
+        writeTag(id, WIRE_TYPE_FIXED64);
+        mBuffer.writeRawFixed64(Double.doubleToLongBits(val));
+    }
+
+    /**
+     * Write a list of packed proto "double" type field values.
+     */
+    public void writePackedDouble(long fieldId, double[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_DOUBLE);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            writeKnownLengthHeader(id, N * 8);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawFixed64(Double.doubleToLongBits(val[i]));
+            }
+        }
+    }
+
+    //
+    // proto3 type: float
+    // java type: float
+    // encoding: fixed32
+    // wire type: WIRE_TYPE_FIXED32
+    //
+
+    /**
+     * Write a single proto "float" type field value.
+     */
+    public void writeFloat(long fieldId, float val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_FLOAT);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_FIXED32);
+            mBuffer.writeRawFixed32(Float.floatToIntBits(val));
+        }
+    }
+
+    /**
+     * Write a single repeated proto "float" type field value.
+     */
+    public void writeRepeatedFloat(long fieldId, float val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_FLOAT);
+
+        writeTag(id, WIRE_TYPE_FIXED32);
+        mBuffer.writeRawFixed32(Float.floatToIntBits(val));
+    }
+
+    /**
+     * Write a list of packed proto "float" type field value.
+     */
+    public void writePackedFloat(long fieldId, float[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_FLOAT);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            writeKnownLengthHeader(id, N * 4);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawFixed32(Float.floatToIntBits(val[i]));
+            }
+        }
+    }
+
+    //
+    // proto3 type: int32
+    // java type: int
+    // signed/unsigned: signed
+    // encoding: varint
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Writes a java int as an usigned varint.
+     *
+     * The unadorned int32 type in protobuf is unfortunate because it
+     * is stored in memory as a signed value, but encodes as unsigned
+     * varints, which are formally always longs.  So here, we encode
+     * negative values as 64 bits, which will get the sign-extension,
+     * and positive values as 32 bits, which saves a marginal amount
+     * of work in that it processes ints instead of longs.
+     */
+    private void writeUnsignedVarintFromSignedInt(int val) {
+        if (val >= 0) {
+            mBuffer.writeRawVarint32(val);
+        } else {
+            mBuffer.writeRawVarint64(val);
+        }
+    }
+
+    /**
+     * Write a single proto "int32" type field value.
+     *
+     * Note that these are stored in memory as signed values and written as unsigned
+     * varints, which if negative, are 10 bytes long. If you know the data is likely
+     * to be negative, use "sint32".
+     */
+    public void writeInt32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_INT32);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_VARINT);
+            writeUnsignedVarintFromSignedInt(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "int32" type field value.
+     *
+     * Note that these are stored in memory as signed values and written as unsigned
+     * varints, which if negative, are 10 bytes long. If you know the data is likely
+     * to be negative, use "sint32".
+     */
+    public void writeRepeatedInt32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_INT32);
+
+        writeTag(id, WIRE_TYPE_VARINT);
+        writeUnsignedVarintFromSignedInt(val);
+    }
+
+    /**
+     * Write a list of packed proto "int32" type field value.
+     *
+     * Note that these are stored in memory as signed values and written as unsigned
+     * varints, which if negative, are 10 bytes long. If you know the data is likely
+     * to be negative, use "sint32".
+     */
+    public void writePackedInt32(long fieldId, int[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_INT32);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            int size = 0;
+            for (int i=0; i<N; i++) {
+                final int v = val[i];
+                size += v >= 0 ? EncodedBuffer.getRawVarint32Size(v) : 10;
+            }
+            writeKnownLengthHeader(id, size);
+            for (int i=0; i<N; i++) {
+                writeUnsignedVarintFromSignedInt(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: int64
+    // java type: int
+    // signed/unsigned: signed
+    // encoding: varint
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Write a single proto "int64" type field value.
+     */
+    public void writeInt64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_INT64);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_VARINT);
+            mBuffer.writeRawVarint64(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "int64" type field value.
+     */
+    public void writeRepeatedInt64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_INT64);
+
+        writeTag(id, WIRE_TYPE_VARINT);
+        mBuffer.writeRawVarint64(val);
+    }
+
+    /**
+     * Write a list of packed proto "int64" type field value.
+     */
+    public void writePackedInt64(long fieldId, long[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_INT64);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            int size = 0;
+            for (int i=0; i<N; i++) {
+                size += EncodedBuffer.getRawVarint64Size(val[i]);
+            }
+            writeKnownLengthHeader(id, size);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawVarint64(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: uint32
+    // java type: int
+    // signed/unsigned: unsigned
+    // encoding: varint
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Write a single proto "uint32" type field value.
+     */
+    public void writeUInt32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_UINT32);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_VARINT);
+            mBuffer.writeRawVarint32(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "uint32" type field value.
+     */
+    public void writeRepeatedUInt32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_UINT32);
+
+        writeTag(id, WIRE_TYPE_VARINT);
+        mBuffer.writeRawVarint32(val);
+    }
+
+    /**
+     * Write a list of packed proto "uint32" type field value.
+     */
+    public void writePackedUInt32(long fieldId, int[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_UINT32);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            int size = 0;
+            for (int i=0; i<N; i++) {
+                size += EncodedBuffer.getRawVarint32Size(val[i]);
+            }
+            writeKnownLengthHeader(id, size);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawVarint32(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: uint64
+    // java type: int
+    // signed/unsigned: unsigned
+    // encoding: varint
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Write a single proto "uint64" type field value.
+     */
+    public void writeUInt64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_UINT64);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_VARINT);
+            mBuffer.writeRawVarint64(val);
+        }
+    }
+
+    /**
+     * Write a single proto "uint64" type field value.
+     */
+    public void writeRepeatedUInt64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_UINT64);
+
+        writeTag(id, WIRE_TYPE_VARINT);
+        mBuffer.writeRawVarint64(val);
+    }
+
+    /**
+     * Write a single proto "uint64" type field value.
+     */
+    public void writePackedUInt64(long fieldId, long[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_UINT64);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            int size = 0;
+            for (int i=0; i<N; i++) {
+                size += EncodedBuffer.getRawVarint64Size(val[i]);
+            }
+            writeKnownLengthHeader(id, size);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawVarint64(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: sint32
+    // java type: int
+    // signed/unsigned: signed
+    // encoding: zig-zag
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Write a single proto "sint32" type field value.
+     */
+    public void writeSInt32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_SINT32);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_VARINT);
+            mBuffer.writeRawZigZag32(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "sint32" type field value.
+     */
+    public void writeRepeatedSInt32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_SINT32);
+
+        writeTag(id, WIRE_TYPE_VARINT);
+        mBuffer.writeRawZigZag32(val);
+    }
+
+    /**
+     * Write a list of packed proto "sint32" type field value.
+     */
+    public void writePackedSInt32(long fieldId, int[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_SINT32);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            int size = 0;
+            for (int i=0; i<N; i++) {
+                size += EncodedBuffer.getRawZigZag32Size(val[i]);
+            }
+            writeKnownLengthHeader(id, size);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawZigZag32(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: sint64
+    // java type: int
+    // signed/unsigned: signed
+    // encoding: zig-zag
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Write a single proto "sint64" type field value.
+     */
+    public void writeSInt64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_SINT64);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_VARINT);
+            mBuffer.writeRawZigZag64(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "sint64" type field value.
+     */
+    public void writeRepeatedSInt64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_SINT64);
+
+        writeTag(id, WIRE_TYPE_VARINT);
+        mBuffer.writeRawZigZag64(val);
+    }
+
+    /**
+     * Write a list of packed proto "sint64" type field value.
+     */
+    public void writePackedSInt64(long fieldId, long[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_SINT64);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            int size = 0;
+            for (int i=0; i<N; i++) {
+                size += EncodedBuffer.getRawZigZag64Size(val[i]);
+            }
+            writeKnownLengthHeader(id, size);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawZigZag64(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: fixed32
+    // java type: int
+    // encoding: little endian
+    // wire type: WIRE_TYPE_FIXED32
+    //
+
+    /**
+     * Write a single proto "fixed32" type field value.
+     */
+    public void writeFixed32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_FIXED32);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_FIXED32);
+            mBuffer.writeRawFixed32(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "fixed32" type field value.
+     */
+    public void writeRepeatedFixed32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_FIXED32);
+
+        writeTag(id, WIRE_TYPE_FIXED32);
+        mBuffer.writeRawFixed32(val);
+    }
+
+    /**
+     * Write a list of packed proto "fixed32" type field value.
+     */
+    public void writePackedFixed32(long fieldId, int[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_FIXED32);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            writeKnownLengthHeader(id, N * 4);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawFixed32(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: fixed64
+    // java type: long
+    // encoding: fixed64
+    // wire type: WIRE_TYPE_FIXED64
+    //
+
+    /**
+     * Write a single proto "fixed64" type field value.
+     */
+    public void writeFixed64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_FIXED64);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_FIXED64);
+            mBuffer.writeRawFixed64(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "fixed64" type field value.
+     */
+    public void writeRepeatedFixed64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_FIXED64);
+
+        writeTag(id, WIRE_TYPE_FIXED64);
+        mBuffer.writeRawFixed64(val);
+    }
+
+    /**
+     * Write a list of packed proto "fixed64" type field value.
+     */
+    public void writePackedFixed64(long fieldId, long[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_FIXED64);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            writeKnownLengthHeader(id, N * 8);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawFixed64(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: sfixed32
+    // java type: int
+    // encoding: little endian
+    // wire type: WIRE_TYPE_FIXED32
+    //
+    /**
+     * Write a single proto "sfixed32" type field value.
+     */
+    public void writeSFixed32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_SFIXED32);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_FIXED32);
+            mBuffer.writeRawFixed32(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "sfixed32" type field value.
+     */
+    public void writeRepeatedSFixed32(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_SFIXED32);
+
+        writeTag(id, WIRE_TYPE_FIXED32);
+        mBuffer.writeRawFixed32(val);
+    }
+
+    /**
+     * Write a list of packed proto "sfixed32" type field value.
+     */
+    public void writePackedSFixed32(long fieldId, int[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_SFIXED32);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            writeKnownLengthHeader(id, N * 4);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawFixed32(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: sfixed64
+    // java type: long
+    // encoding: little endian
+    // wire type: WIRE_TYPE_FIXED64
+    //
+
+    /**
+     * Write a single proto "sfixed64" type field value.
+     */
+    public void writeSFixed64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_SFIXED64);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_FIXED64);
+            mBuffer.writeRawFixed64(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "sfixed64" type field value.
+     */
+    public void writeRepeatedSFixed64(long fieldId, long val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_SFIXED64);
+
+        writeTag(id, WIRE_TYPE_FIXED64);
+        mBuffer.writeRawFixed64(val);
+    }
+
+    /**
+     * Write a list of packed proto "sfixed64" type field value.
+     */
+    public void writePackedSFixed64(long fieldId, long[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_SFIXED64);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            writeKnownLengthHeader(id, N * 8);
+            for (int i=0; i<N; i++) {
+                mBuffer.writeRawFixed64(val[i]);
+            }
+        }
+    }
+
+    //
+    // proto3 type: bool
+    // java type: boolean
+    // encoding: varint
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Write a single proto "bool" type field value.
+     */
+    public void writeBool(long fieldId, boolean val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_BOOL);
+
+        if (val) {
+            writeTag(id, WIRE_TYPE_VARINT);
+            // 0 and 1 are the same as their varint counterparts
+            mBuffer.writeRawByte((byte)1);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "bool" type field value.
+     */
+    public void writeRepeatedBool(long fieldId, boolean val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_BOOL);
+
+        writeTag(id, WIRE_TYPE_VARINT);
+        mBuffer.writeRawByte((byte)(val ? 1 : 0));
+    }
+
+    /**
+     * Write a list of packed proto "bool" type field value.
+     */
+    public void writePackedBool(long fieldId, boolean[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_BOOL);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            // Write the header
+            writeKnownLengthHeader(id, N);
+
+            // Write the data
+            for (int i=0; i<N; i++) {
+                // 0 and 1 are the same as their varint counterparts
+                mBuffer.writeRawByte((byte)(val[i] ? 1 : 0));
+            }
+        }
+    }
+
+    //
+    // proto3 type: string
+    // java type: String
+    // encoding: utf-8
+    // wire type: WIRE_TYPE_LENGTH_DELIMITED
+    //
+
+    /**
+     * Write a single proto "string" type field value.
+     */
+    public void writeString(long fieldId, String val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_STRING);
+
+        if (val != null && val.length() > 0) {
+            writeUtf8String(id, val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "string" type field value.
+     */
+    public void writeRepeatedString(long fieldId, String val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_STRING);
+
+        if (val == null || val.length() == 0) {
+            writeKnownLengthHeader(id, 0);
+        } else {
+            writeUtf8String(id, val);
+        }
+    }
+
+    /**
+     * Write a list of packed proto "string" type field value.
+     */
+    private void writeUtf8String(int id, String val) {
+        // TODO: Is it worth converting by hand in order to not allocate?
+        try {
+            final byte[] buf = val.getBytes("UTF-8");
+            writeKnownLengthHeader(id, buf.length);
+            mBuffer.writeRawBuffer(buf);
+        } catch (UnsupportedEncodingException ex) {
+            throw new RuntimeException("not possible");
+        }
+    }
+
+    //
+    // proto3 type: bytes
+    // java type: byte[]
+    // encoding: varint
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Write a single proto "bytes" type field value.
+     */
+    public void writeBytes(long fieldId, byte[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_BYTES);
+
+        if (val != null && val.length > 0) {
+            writeKnownLengthHeader(id, val.length);
+            mBuffer.writeRawBuffer(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto "bytes" type field value.
+     */
+    public void writeRepeatedBytes(long fieldId, byte[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_BYTES);
+
+        writeKnownLengthHeader(id, val == null ? 0 : val.length);
+        mBuffer.writeRawBuffer(val);
+    }
+
+    //
+    // proto3 type: enum
+    // java type: int
+    // signed/unsigned: unsigned
+    // encoding: varint
+    // wire type: WIRE_TYPE_VARINT
+    //
+
+    /**
+     * Write a single proto enum type field value.
+     */
+    public void writeEnum(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_ENUM);
+
+        if (val != 0) {
+            writeTag(id, WIRE_TYPE_VARINT);
+            writeUnsignedVarintFromSignedInt(val);
+        }
+    }
+
+    /**
+     * Write a single repeated proto enum type field value.
+     */
+    public void writeRepeatedEnum(long fieldId, int val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_ENUM);
+
+        writeTag(id, WIRE_TYPE_VARINT);
+        writeUnsignedVarintFromSignedInt(val);
+    }
+
+    /**
+     * Write a list of packed proto enum type field value.
+     */
+    public void writePackedEnum(long fieldId, int[] val) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_PACKED | FIELD_TYPE_ENUM);
+
+        final int N = val != null ? val.length : 0;
+        if (N > 0) {
+            int size = 0;
+            for (int i=0; i<N; i++) {
+                final int v = val[i];
+                size += v >= 0 ? EncodedBuffer.getRawVarint32Size(v) : 10;
+            }
+            writeKnownLengthHeader(id, size);
+            for (int i=0; i<N; i++) {
+                writeUnsignedVarintFromSignedInt(val[i]);
+            }
+        }
+    }
+
+    //
+    // Child objects
+    //
+
+    /**
+     * Make a token.
+     *  Bits 61-63 - tag size (So we can go backwards later if the object had not data)
+     *                - 3 bits, max value 7, max value needed 5
+     *  Bit  60    - true if the object is repeated (lets us require endObject or endRepeatedObject)
+     *  Bits 59-51 - depth (For error checking)
+     *                - 9 bits, max value 512, when checking, value is masked (if we really
+     *                  are more than 512 levels deep)
+     *  Bits 32-50 - objectId (For error checking)
+     *                - 19 bits, max value 524,288. that's a lot of objects. IDs will wrap
+     *                  because of the overflow, and only the tokens are compared.
+     *  Bits  0-31 - offset of the first size field in the buffer.
+     */
+    // VisibleForTesting
+    public static long makeToken(int tagSize, boolean repeated, int depth, int objectId,
+            int sizePos) {
+        return ((0x07L & (long)tagSize) << 61)
+                | (repeated ? (1L << 60) : 0)
+                | (0x01ffL & (long)depth) << 51
+                | (0x07ffffL & (long)objectId) << 32
+                | (0x0ffffffffL & (long)sizePos);
+    }
+
+    /**
+     * Get the encoded tag size from the token.
+     */
+    public static int getTagSizeFromToken(long token) {
+        return (int)(0x7 & (token >> 61));
+    }
+
+    /**
+     * Get whether this is a call to startObject (false) or startRepeatedObject (true).
+     */
+    public static boolean getRepeatedFromToken(long token) {
+        return (0x1 & (token >> 60)) != 0;
+    }
+
+    /**
+     * Get the nesting depth of startObject calls from the token.
+     */
+    public static int getDepthFromToken(long token) {
+        return (int)(0x01ff & (token >> 51));
+    }
+
+    /**
+     * Get the object ID from the token. The object ID is a serial number for the
+     * startObject calls that have happened on this object.  The values are truncated
+     * to 9 bits, but that is sufficient for error checking.
+     */
+    public static int getObjectIdFromToken(long token) {
+        return (int)(0x07ffff & (token >> 32));
+    }
+
+    /**
+     * Get the location of the childRawSize (the first 32 bit size field) in this object.
+     */
+    public static int getSizePosFromToken(long token) {
+        return (int)token;
+    }
+
+    /**
+     * Convert the object ID to the ordinal value -- the n-th call to startObject.
+     * The object IDs start at -1 and count backwards, so that the value is unlikely
+     * to alias with an actual size field that had been written.
+     */
+    public static int convertObjectIdToOrdinal(int objectId) {
+        return (-1 & 0x07ffff) - objectId;
+    }
+
+    /**
+     * Return a debugging string of a token.
+     */
+    public static String token2String(long token) {
+        if (token == 0L) {
+            return "Token(0)";
+        } else {
+            return "Token(val=0x" + Long.toHexString(token)
+                    + " depth=" + getDepthFromToken(token)
+                    + " object=" + convertObjectIdToOrdinal(getObjectIdFromToken(token))
+                    + " tagSize=" + getTagSizeFromToken(token)
+                    + " sizePos=" + getSizePosFromToken(token)
+                    + ')';
+        }
+    }
+
+    /**
+     * Start a child object.
+     *
+     * Returns a token which should be passed to endObject.  Calls to endObject must be
+     * nested properly.
+     */
+    public long startObject(long fieldId) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_SINGLE | FIELD_TYPE_OBJECT);
+
+        return startObjectImpl(id, false);
+    }
+
+    /**
+     * End a child object. Pass in the token from the correspoinding startObject call.
+     */
+    public void endObject(long token) {
+        assertNotCompacted();
+
+        endObjectImpl(token, false);
+    }
+
+    /**
+     * Start a repeated child object.
+     *
+     * Returns a token which should be passed to endObject.  Calls to endObject must be
+     * nested properly.
+     */
+    public long startRepeatedObject(long fieldId) {
+        assertNotCompacted();
+        final int id = checkFieldId(fieldId, FIELD_COUNT_REPEATED | FIELD_TYPE_OBJECT);
+
+        return startObjectImpl(id, true);
+    }
+
+    /**
+     * End a child object. Pass in the token from the correspoinding startRepeatedObject call.
+     */
+    public void endRepeatedObject(long token) {
+        assertNotCompacted();
+
+        endObjectImpl(token, true);
+    }
+
+    /**
+     * Common implementation of startObject and startRepeatedObject.
+     */
+    private long startObjectImpl(final int id, boolean repeated) {
+        writeTag(id, WIRE_TYPE_LENGTH_DELIMITED);
+        final int sizePos = mBuffer.getWritePos();
+        mDepth++;
+        mNextObjectId--;
+
+        // Write the previous token, giving us a stack of expected tokens.
+        // After endObject returns, the first fixed32 becomeschildRawSize (set in endObject)
+        // and the second one becomes childEncodedSize (set in editEncodedSize).
+        mBuffer.writeRawFixed32((int)(mExpectedObjectToken >> 32));
+        mBuffer.writeRawFixed32((int)mExpectedObjectToken);
+
+        long old = mExpectedObjectToken;
+
+        mExpectedObjectToken = makeToken(getTagSize(id), repeated, mDepth, mNextObjectId, sizePos);
+        return mExpectedObjectToken;
+    }
+
+    /**
+     * Common implementation of endObject and endRepeatedObject.
+     */
+    private void endObjectImpl(long token, boolean repeated) {
+        // The upper 32 bits of the token is the depth of startObject /
+        // endObject calls.  We could get aritrarily sophisticated, but
+        // that's enough to prevent the common error of missing an
+        // endObject somewhere.
+        // The lower 32 bits of the token is the offset in the buffer
+        // at which to write the size.
+        final int depth = getDepthFromToken(token);
+        final boolean expectedRepeated = getRepeatedFromToken(token);
+        final int sizePos = getSizePosFromToken(token);
+        final int childRawSize = mBuffer.getWritePos() - sizePos - 8;
+
+        if (repeated != expectedRepeated) {
+            if (repeated) {
+                throw new IllegalArgumentException("endRepeatedObject called where endObject should"
+                        + " have been");
+            } else {
+                throw new IllegalArgumentException("endObject called where endRepeatedObject should"
+                        + " have been");
+            }
+        }
+
+        // Check that we're getting the token and depth that we are expecting.
+        if ((mDepth & 0x01ff) != depth || mExpectedObjectToken != token) {
+            // This text of exception is united tested.  That test also implicity checks
+            // that we're tracking the objectIds and depths correctly.
+            throw new IllegalArgumentException("Mismatched startObject/endObject calls."
+                    + " Current depth " + mDepth
+                    + " token=" + token2String(token)
+                    + " expectedToken=" + token2String(mExpectedObjectToken));
+        }
+
+        // Get the next expected token that we stashed away in the buffer.
+        mExpectedObjectToken = (((long)mBuffer.getRawFixed32At(sizePos)) << 32)
+                | (0x0ffffffffL & (long)mBuffer.getRawFixed32At(sizePos+4));
+
+        mDepth--;
+        if (childRawSize > 0) {
+            mBuffer.editRawFixed32(sizePos, -childRawSize);
+            mBuffer.editRawFixed32(sizePos+4, -1);
+        } else if (repeated) {
+            mBuffer.editRawFixed32(sizePos, 0);
+            mBuffer.editRawFixed32(sizePos+4, 0);
+        } else {
+            // The object has no data.  Don't include it.
+            mBuffer.rewindWriteTo(sizePos - getTagSizeFromToken(token));
+        }
+    }
+
+    //
+    // Tags
+    //
+
+    /**
+     * Combine a fieldId (the field keys in the proto file) and the field flags.
+     * Mostly useful for testing because the generated code contains the fieldId
+     * constants.
+     */
+    public static long makeFieldId(int id, long fieldFlags) {
+        return fieldFlags | (((long)id) & 0x0ffffffffL);
+    }
+
+    /**
+     * Validates that the fieldId providied is of the type and count from expectedType.
+     *
+     * The type must match exactly to pass this check.
+     *
+     * The count must match according to this truth table to pass the check:
+     *
+     *                  expectedFlags
+     *                  UNKNOWN     SINGLE      REPEATED    PACKED
+     *    fieldId
+     *    UNKNOWN       true        false       false       false
+     *    SINGLE        x           true        false       false
+     *    REPEATED      x           false       true        false
+     *    PACKED        x           false       true        true
+     *
+     * @throws IllegalArgumentException if it is not.
+     *
+     * @return The raw ID of that field.
+     */
+    public static int checkFieldId(long fieldId, long expectedFlags) {
+        final long fieldCount = fieldId & FIELD_COUNT_MASK;
+        final long fieldType = fieldId & FIELD_TYPE_MASK;
+        final long expectedCount = expectedFlags & FIELD_COUNT_MASK;
+        final long expectedType = expectedFlags & FIELD_TYPE_MASK;
+        if (((int)fieldId) == 0) {
+            throw new IllegalArgumentException("Invalid proto field " + (int)fieldId
+                    + " fieldId=" + Long.toHexString(fieldId));
+        }
+        if (fieldType != expectedType
+                || !((fieldCount == expectedCount)
+                    || (fieldCount == FIELD_COUNT_PACKED
+                        && expectedCount == FIELD_COUNT_REPEATED))) {
+            final String countString = getFieldCountString(fieldCount);
+            final String typeString = getFieldTypeString(fieldType);
+            if (typeString != null && countString != null) {
+                final StringBuilder sb = new StringBuilder();
+                if (expectedType == FIELD_TYPE_OBJECT) {
+                    sb.append("start");
+                } else {
+                    sb.append("write");
+                }
+                sb.append(getFieldCountString(expectedCount));
+                sb.append(getFieldTypeString(expectedType));
+                sb.append(" called for field ");
+                sb.append((int)fieldId);
+                sb.append(" which should be used with ");
+                if (fieldType == FIELD_TYPE_OBJECT) {
+                    sb.append("start");
+                } else {
+                    sb.append("write");
+                }
+                sb.append(countString);
+                sb.append(typeString);
+                if (fieldCount == FIELD_COUNT_PACKED) {
+                    sb.append(" or writeRepeated");
+                    sb.append(typeString);
+                }
+                sb.append('.');
+                throw new IllegalArgumentException(sb.toString());
+            } else {
+                final StringBuilder sb = new StringBuilder();
+                if (expectedType == FIELD_TYPE_OBJECT) {
+                    sb.append("start");
+                } else {
+                    sb.append("write");
+                }
+                sb.append(getFieldCountString(expectedCount));
+                sb.append(getFieldTypeString(expectedType));
+                sb.append(" called with an invalid fieldId: 0x");
+                sb.append(Long.toHexString(fieldId));
+                sb.append(". The proto field ID might be ");
+                sb.append((int)fieldId);
+                sb.append('.');
+                throw new IllegalArgumentException(sb.toString());
+            }
+        }
+        return (int)fieldId;
+    }
+
+    /**
+     * Get the developer-usable name of a field type.
+     */
+    private static String getFieldTypeString(long fieldType) {
+        int index = ((int)((fieldType & FIELD_TYPE_MASK) >>> FIELD_TYPE_SHIFT)) - 1;
+        if (index >= 0 && index < FIELD_TYPE_NAMES.length) {
+            return FIELD_TYPE_NAMES[index];
+        } else {
+            return null;
+        }
+    }
+
+    /**
+     * Get the developer-usable name of a field count.
+     */
+    private static String getFieldCountString(long fieldCount) {
+        if (fieldCount == FIELD_COUNT_SINGLE) {
+            return "";
+        } else if (fieldCount == FIELD_COUNT_REPEATED) {
+            return "Repeated";
+        } else if (fieldCount == FIELD_COUNT_PACKED) {
+            return "Packed";
+        } else {
+            return null;
+        }
+    }
+
+
+    /**
+     * Return how many bytes an encoded field tag will require.
+     */
+    private static int getTagSize(int id) {
+        return EncodedBuffer.getRawVarint32Size(id << FIELD_ID_SHIFT);
+    }
+
+    /**
+     * Write a field tage to the stream.
+     */
+    public void writeTag(int id, int wireType) {
+        mBuffer.writeRawVarint32((id << FIELD_ID_SHIFT) | wireType);
+    }
+
+    /**
+     * Write the header of a WIRE_TYPE_LENGTH_DELIMITED field for one where
+     * we know the size in advance and do not need to compute and compact.
+     */
+    private void writeKnownLengthHeader(int id, int size) {
+        // Write the tag
+        writeTag(id, WIRE_TYPE_LENGTH_DELIMITED);
+        // Size will be compacted later, but we know the size, so write it,
+        // once for the rawSize and once for the encodedSize.
+        mBuffer.writeRawFixed32(size);
+        mBuffer.writeRawFixed32(size);
+    }
+
+    //
+    // Getting the buffer and compaction
+    //
+
+    /**
+     * Assert that the compact call has not already occured.
+     *
+     * TODO: Will change when we add the OutputStream version of ProtoOutputStream.
+     */
+    private void assertNotCompacted() {
+        if (mCompacted) {
+            throw new IllegalArgumentException("write called after compact");
+        }
+    }
+
+    /**
+     * Finish the encoding of the data, and return a byte[] with
+     * the protobuf formatted data.
+     *
+     * After this call, do not call any of the write* functions. The
+     * behavior is undefined.
+     */
+    public byte[] getBytes() {
+        compactIfNecessary();
+
+        return mBuffer.getBytes(mBuffer.getReadableSize());
+    }
+
+    /**
+     * If the buffer hasn't already had the nested object size fields compacted
+     * and turned into an actual protobuf format, then do so.
+     */
+    private void compactIfNecessary() {
+        if (!mCompacted) {
+            if (mDepth != 0) {
+                throw new IllegalArgumentException("Trying to compact with " + mDepth
+                        + " missing calls to endObject");
+            }
+
+            // The buffer must be compacted.
+            mBuffer.startEditing();
+            final int readableSize = mBuffer.getReadableSize();
+
+            // Cache the sizes of the objects
+            editEncodedSize(readableSize);
+
+            // Re-write the buffer with the sizes as proper varints instead
+            // of pairs of uint32s. We know this will always fit in the same
+            // buffer because the pair of uint32s is exactly 8 bytes long, and
+            // the single varint size will be no more than 5 bytes long.
+            mBuffer.rewindRead();
+            compactSizes(readableSize);
+
+            // If there is any data left over that wasn't copied yet, copy it.
+            if (mCopyBegin < readableSize) {
+                mBuffer.writeFromThisBuffer(mCopyBegin, readableSize - mCopyBegin);
+            }
+
+            // Set the new readableSize
+            mBuffer.startEditing();
+
+            // It's not valid to write to this object anymore. The write
+            // pointers are off, and then some of the data would be compacted
+            // and some not.
+            mCompacted = true;
+        }
+    }
+
+    /**
+     * First compaction pass.  Iterate through the data, and fill in the
+     * nested object sizes so the next pass can compact them.
+     */
+    private int editEncodedSize(int rawSize) {
+        int objectStart = mBuffer.getReadPos();
+        int objectEnd = objectStart + rawSize;
+        int encodedSize = 0;
+        int tagPos;
+
+        while ((tagPos = mBuffer.getReadPos()) < objectEnd) {
+            int tag = readRawTag();
+            encodedSize += EncodedBuffer.getRawVarint32Size(tag);
+
+            final int wireType = tag & WIRE_TYPE_MASK;
+            switch (wireType) {
+                case WIRE_TYPE_VARINT:
+                    encodedSize++;
+                    while ((mBuffer.readRawByte() & 0x80) != 0) {
+                        encodedSize++;
+                    }
+                    break;
+                case WIRE_TYPE_FIXED64:
+                    encodedSize += 8;
+                    mBuffer.skipRead(8);
+                    break;
+                case WIRE_TYPE_LENGTH_DELIMITED: {
+                    // This object is not of a fixed-size type.  So we need to figure
+                    // out how big it should be.
+                    final int childRawSize = mBuffer.readRawFixed32();
+                    final int childEncodedSizePos = mBuffer.getReadPos();
+                    int childEncodedSize = mBuffer.readRawFixed32();
+                    if (childRawSize >= 0) {
+                        // We know the size, just skip ahead.
+                        if (childEncodedSize != childRawSize) {
+                            throw new RuntimeException("Pre-computed size where the"
+                                    + " precomputed size and the raw size in the buffer"
+                                    + " don't match! childRawSize=" + childRawSize
+                                    + " childEncodedSize=" + childEncodedSize
+                                    + " childEncodedSizePos=" + childEncodedSizePos);
+                        }
+                        mBuffer.skipRead(childRawSize);
+                    } else {
+                        // We need to compute the size.  Recurse.
+                        childEncodedSize = editEncodedSize(-childRawSize);
+                        mBuffer.editRawFixed32(childEncodedSizePos, childEncodedSize);
+                    }
+                    encodedSize += EncodedBuffer.getRawVarint32Size(childEncodedSize)
+                            + childEncodedSize;
+                    break;
+                }
+                case WIRE_TYPE_START_GROUP:
+                case WIRE_TYPE_END_GROUP:
+                    throw new RuntimeException("groups not supported at index " + tagPos);
+                case WIRE_TYPE_FIXED32:
+                    encodedSize += 4;
+                    mBuffer.skipRead(4);
+                    break;
+                default:
+                    throw new ProtoParseException("editEncodedSize Bad tag tag=0x"
+                            + Integer.toHexString(tag) + " wireType=" + wireType
+                            + " -- " + mBuffer.getDebugString());
+            }
+        }
+
+        return encodedSize;
+    }
+
+    /**
+     * Second compaction pass.  Iterate through the data, and copy the data
+     * forward in the buffer, converting the pairs of uint32s into a single
+     * unsigned varint of the size.
+     */
+    private void compactSizes(int rawSize) {
+        int objectStart = mBuffer.getReadPos();
+        int objectEnd = objectStart + rawSize;
+        int tagPos;
+        while ((tagPos = mBuffer.getReadPos()) < objectEnd) {
+            int tag = readRawTag();
+
+            // For all the non-length-delimited field types, just skip over them,
+            // and we'll just System.arraycopy it later, either in the case for
+            // WIRE_TYPE_LENGTH_DELIMITED or at the top of the stack in compactIfNecessary().
+            final int wireType = tag & WIRE_TYPE_MASK;
+            switch (wireType) {
+                case WIRE_TYPE_VARINT:
+                    while ((mBuffer.readRawByte() & 0x80) != 0) { }
+                    break;
+                case WIRE_TYPE_FIXED64:
+                    mBuffer.skipRead(8);
+                    break;
+                case WIRE_TYPE_LENGTH_DELIMITED: {
+                    // Copy everything up to now, including the tag for this field.
+                    mBuffer.writeFromThisBuffer(mCopyBegin, mBuffer.getReadPos() - mCopyBegin);
+                    // Write the new size.
+                    final int childRawSize = mBuffer.readRawFixed32();
+                    final int childEncodedSize = mBuffer.readRawFixed32();
+                    mBuffer.writeRawVarint32(childEncodedSize);
+                    // Next time, start copying from here.
+                    mCopyBegin = mBuffer.getReadPos();
+                    if (childRawSize >= 0) {
+                        // This is raw data, not an object. Skip ahead by the size.
+                        // Recurse into the child
+                        mBuffer.skipRead(childEncodedSize);
+                    } else {
+                        compactSizes(-childRawSize);
+                    }
+                    break;
+                    // TODO: What does regular proto do if the object would be 0 size
+                    // (e.g. if it is all default values).
+                }
+                case WIRE_TYPE_START_GROUP:
+                case WIRE_TYPE_END_GROUP:
+                    throw new RuntimeException("groups not supported at index " + tagPos);
+                case WIRE_TYPE_FIXED32:
+                    mBuffer.skipRead(4);
+                    break;
+                default:
+                    throw new ProtoParseException("compactSizes Bad tag tag=0x"
+                            + Integer.toHexString(tag) + " wireType=" + wireType
+                            + " -- " + mBuffer.getDebugString());
+            }
+        }
+    }
+
+    /**
+     * Read a raw tag from the buffer.
+     */
+    private int readRawTag() {
+        if (mBuffer.getReadPos() == mBuffer.getReadableSize()) {
+            return 0;
+        }
+        return (int)mBuffer.readRawUnsigned();
+    }
+
+    /**
+     * Dump debugging data about the buffers with the given log tag.
+     */
+    public void dump(String tag) {
+        Log.d(tag, mBuffer.getDebugString());
+        mBuffer.dumpBuffers(tag);
+    }
+}
diff --git a/core/java/android/util/proto/ProtoParseException.java b/core/java/android/util/proto/ProtoParseException.java
new file mode 100644
index 0000000..5ba9bf8
--- /dev/null
+++ b/core/java/android/util/proto/ProtoParseException.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.util.proto;
+
+import android.annotation.TestApi;
+
+/**
+ * Thrown when there is an error parsing protobuf data.
+ *
+ * @hide
+ */
+@TestApi
+public class ProtoParseException extends RuntimeException {
+
+    /**
+     * Construct a ProtoParseException.
+     *
+     * @param msg The message.
+     */
+    public ProtoParseException(String msg) {
+        super(msg);
+    }
+}
+
diff --git a/core/java/android/util/proto/package.html b/core/java/android/util/proto/package.html
new file mode 100644
index 0000000..a636bd4
--- /dev/null
+++ b/core/java/android/util/proto/package.html
@@ -0,0 +1,5 @@
+<body>
+Provides utility classes to export protocol buffers from the system.
+
+{@hide}
+</body>
diff --git a/core/java/android/view/Display.java b/core/java/android/view/Display.java
index 85a4bf9..3beb00f 100644
--- a/core/java/android/view/Display.java
+++ b/core/java/android/view/Display.java
@@ -16,11 +16,11 @@
 
 package android.view;
 
+import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE;
+
 import android.annotation.IntDef;
 import android.annotation.RequiresPermission;
-import android.content.Context;
 import android.content.res.CompatibilityInfo;
-import android.content.res.Resources;
 import android.graphics.PixelFormat;
 import android.graphics.Point;
 import android.graphics.Rect;
@@ -36,8 +36,6 @@
 import java.lang.annotation.RetentionPolicy;
 import java.util.Arrays;
 
-import static android.Manifest.permission.CONFIGURE_DISPLAY_COLOR_MODE;
-
 /**
  * Provides information about the size and density of a logical display.
  * <p>
diff --git a/core/java/android/view/DisplayAdjustments.java b/core/java/android/view/DisplayAdjustments.java
index dd86062..790029b 100644
--- a/core/java/android/view/DisplayAdjustments.java
+++ b/core/java/android/view/DisplayAdjustments.java
@@ -26,18 +26,20 @@
     public static final DisplayAdjustments DEFAULT_DISPLAY_ADJUSTMENTS = new DisplayAdjustments();
 
     private volatile CompatibilityInfo mCompatInfo = CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO;
-    private Configuration mConfiguration = Configuration.EMPTY;
+    private Configuration mConfiguration;
 
     public DisplayAdjustments() {
     }
 
     public DisplayAdjustments(Configuration configuration) {
-        mConfiguration = configuration;
+        mConfiguration = new Configuration(configuration != null
+                ? configuration : Configuration.EMPTY);
     }
 
     public DisplayAdjustments(DisplayAdjustments daj) {
         setCompatibilityInfo(daj.mCompatInfo);
-        mConfiguration = daj.mConfiguration;
+        mConfiguration = new Configuration(daj.mConfiguration != null
+                ? daj.mConfiguration : Configuration.EMPTY);
     }
 
     public void setCompatibilityInfo(CompatibilityInfo compatInfo) {
@@ -62,7 +64,7 @@
             throw new IllegalArgumentException(
                     "setConfiguration: Cannot modify DEFAULT_DISPLAY_ADJUSTMENTS");
         }
-        mConfiguration = configuration != null ? configuration : Configuration.EMPTY;
+        mConfiguration.setTo(configuration != null ? configuration : Configuration.EMPTY);
     }
 
     public Configuration getConfiguration() {
diff --git a/core/java/android/view/DisplayEventReceiver.java b/core/java/android/view/DisplayEventReceiver.java
index 4393992..67cdfc5 100644
--- a/core/java/android/view/DisplayEventReceiver.java
+++ b/core/java/android/view/DisplayEventReceiver.java
@@ -16,13 +16,13 @@
 
 package android.view;
 
-import dalvik.annotation.optimization.FastNative;
-import dalvik.system.CloseGuard;
-
 import android.os.Looper;
 import android.os.MessageQueue;
 import android.util.Log;
 
+import dalvik.annotation.optimization.FastNative;
+import dalvik.system.CloseGuard;
+
 import java.lang.ref.WeakReference;
 
 /**
diff --git a/core/java/android/view/DisplayInfo.java b/core/java/android/view/DisplayInfo.java
index bc40849..1aef6ec 100644
--- a/core/java/android/view/DisplayInfo.java
+++ b/core/java/android/view/DisplayInfo.java
@@ -23,10 +23,10 @@
 import android.util.ArraySet;
 import android.util.DisplayMetrics;
 
-import java.util.Arrays;
-
 import libcore.util.Objects;
 
+import java.util.Arrays;
+
 /**
  * Describes the characteristics of a particular logical display.
  * @hide
diff --git a/core/java/android/view/FallbackEventHandler.java b/core/java/android/view/FallbackEventHandler.java
index dd68d89..8e00d6d 100644
--- a/core/java/android/view/FallbackEventHandler.java
+++ b/core/java/android/view/FallbackEventHandler.java
@@ -24,4 +24,3 @@
     public void preDispatchKeyEvent(KeyEvent event);
     public boolean dispatchKeyEvent(KeyEvent event);
 }
-
diff --git a/core/java/android/view/FrameMetrics.java b/core/java/android/view/FrameMetrics.java
index 2b938d0..800a63f 100644
--- a/core/java/android/view/FrameMetrics.java
+++ b/core/java/android/view/FrameMetrics.java
@@ -17,7 +17,6 @@
 package android.view;
 
 import android.annotation.IntDef;
-import android.view.Window;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
diff --git a/core/java/android/view/FrameMetricsObserver.java b/core/java/android/view/FrameMetricsObserver.java
index 6331357..9e81de0 100644
--- a/core/java/android/view/FrameMetricsObserver.java
+++ b/core/java/android/view/FrameMetricsObserver.java
@@ -17,15 +17,12 @@
 package android.view;
 
 import android.annotation.NonNull;
-import android.util.Log;
 import android.os.Looper;
 import android.os.MessageQueue;
 
 import com.android.internal.util.VirtualRefBasePtr;
 
-import java.lang.NullPointerException;
 import java.lang.ref.WeakReference;
-import java.lang.SuppressWarnings;
 
 /**
  * Provides streaming access to frame stats information from the rendering
diff --git a/core/java/android/view/HandlerActionQueue.java b/core/java/android/view/HandlerActionQueue.java
index 4758a34..d016a74 100644
--- a/core/java/android/view/HandlerActionQueue.java
+++ b/core/java/android/view/HandlerActionQueue.java
@@ -16,11 +16,9 @@
 
 package android.view;
 
-import com.android.internal.util.GrowingArrayUtils;
-
 import android.os.Handler;
 
-import java.util.ArrayList;
+import com.android.internal.util.GrowingArrayUtils;
 
 /**
  * Class used to enqueue pending work from Views when no Handler is attached.
diff --git a/core/java/android/view/IAssetAtlas.aidl b/core/java/android/view/IAssetAtlas.aidl
deleted file mode 100644
index edce059..0000000
--- a/core/java/android/view/IAssetAtlas.aidl
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright (c) 2013, 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;
-
-import android.view.GraphicBuffer;
-
-/**
- * Programming interface to the system assets atlas. This atlas, when
- * present, holds preloaded drawable in a single, shareable graphics
- * buffer. This allows multiple processes to share the same data to
- * save up on memory.
- *
- * @hide
- */
-interface IAssetAtlas {
-    /**
-     * Indicates whether the atlas is compatible with the specified
-     * parent process id. If the atlas' ppid does not match, this
-     * method will return false.
-     */
-    boolean isCompatible(int ppid);
-
-    /**
-     * Returns the atlas buffer (texture) or null if the atlas is
-     * not available yet.
-     */
-    GraphicBuffer getBuffer();
-
-    /**
-     * Returns the map of the bitmaps stored in the atlas or null
-     * if the atlas is not available yet.
-     *
-     * Each bitmap is represented by several entries in the array:
-     * long0: SkBitmap*, the native bitmap object
-     * long1: x position
-     * long2: y position
-     * long3: rotated, 1 if the bitmap must be rotated, 0 otherwise
-     */
-    long[] getMap();
-}
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index 897e29b..717b675 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -454,12 +454,13 @@
     void registerShortcutKey(in long shortcutCode, IShortcutService keySubscriber);
 
     /**
-     * Create the input consumer for wallpaper events.
+     * Create an input consumer by name.
      */
-    void createWallpaperInputConsumer(out InputChannel inputChannel);
+    void createInputConsumer(String name, out InputChannel inputChannel);
 
     /**
-     * Remove the input consumer for wallpaper events.
+     * Destroy an input consumer by name.  This method will also dispose the input channels
+     * associated with that InputConsumer.
      */
-    void removeWallpaperInputConsumer();
+    boolean destroyInputConsumer(String name);
 }
diff --git a/core/java/android/view/InputDevice.java b/core/java/android/view/InputDevice.java
index f8796c3..55f64d9 100644
--- a/core/java/android/view/InputDevice.java
+++ b/core/java/android/view/InputDevice.java
@@ -19,10 +19,10 @@
 import android.content.Context;
 import android.hardware.input.InputDeviceIdentifier;
 import android.hardware.input.InputManager;
+import android.os.NullVibrator;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.os.Vibrator;
-import android.os.NullVibrator;
 
 import java.util.ArrayList;
 import java.util.List;
diff --git a/core/java/android/view/InputEventReceiver.java b/core/java/android/view/InputEventReceiver.java
index 91ef50d..20ab539 100644
--- a/core/java/android/view/InputEventReceiver.java
+++ b/core/java/android/view/InputEventReceiver.java
@@ -16,13 +16,13 @@
 
 package android.view;
 
-import dalvik.system.CloseGuard;
-
 import android.os.Looper;
 import android.os.MessageQueue;
 import android.util.Log;
 import android.util.SparseIntArray;
 
+import dalvik.system.CloseGuard;
+
 import java.lang.ref.WeakReference;
 
 /**
diff --git a/core/java/android/view/InputEventSender.java b/core/java/android/view/InputEventSender.java
index 304ea3f..b25fb65 100644
--- a/core/java/android/view/InputEventSender.java
+++ b/core/java/android/view/InputEventSender.java
@@ -16,12 +16,12 @@
 
 package android.view;
 
-import dalvik.system.CloseGuard;
-
 import android.os.Looper;
 import android.os.MessageQueue;
 import android.util.Log;
 
+import dalvik.system.CloseGuard;
+
 import java.lang.ref.WeakReference;
 
 /**
diff --git a/core/java/android/view/InputFilter.java b/core/java/android/view/InputFilter.java
index 4aba30c..d0dab40 100644
--- a/core/java/android/view/InputFilter.java
+++ b/core/java/android/view/InputFilter.java
@@ -20,12 +20,6 @@
 import android.os.Looper;
 import android.os.Message;
 import android.os.RemoteException;
-import android.view.IInputFilter;
-import android.view.InputEvent;
-import android.view.InputEventConsistencyVerifier;
-import android.view.KeyEvent;
-import android.view.MotionEvent;
-import android.view.WindowManagerPolicy;
 
 /**
  * Filters input events before they are dispatched to the system.
diff --git a/core/java/android/view/InputQueue.java b/core/java/android/view/InputQueue.java
index aebc601..582ae79 100644
--- a/core/java/android/view/InputQueue.java
+++ b/core/java/android/view/InputQueue.java
@@ -16,13 +16,13 @@
 
 package android.view;
 
-import dalvik.system.CloseGuard;
-
 import android.os.Looper;
 import android.os.MessageQueue;
+import android.util.LongSparseArray;
 import android.util.Pools.Pool;
 import android.util.Pools.SimplePool;
-import android.util.LongSparseArray;
+
+import dalvik.system.CloseGuard;
 
 import java.lang.ref.WeakReference;
 
diff --git a/core/java/android/view/KeyCharacterMap.java b/core/java/android/view/KeyCharacterMap.java
index c8b89e7..88f2d34 100644
--- a/core/java/android/view/KeyCharacterMap.java
+++ b/core/java/android/view/KeyCharacterMap.java
@@ -16,14 +16,13 @@
 
 package android.view;
 
+import android.hardware.input.InputManager;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.text.method.MetaKeyKeyListener;
 import android.util.AndroidRuntimeException;
 import android.util.SparseIntArray;
-import android.hardware.input.InputManager;
 
-import java.lang.Character;
 import java.text.Normalizer;
 
 /**
diff --git a/core/java/android/view/KeyEvent.java b/core/java/android/view/KeyEvent.java
index b73acda..5d8f336 100644
--- a/core/java/android/view/KeyEvent.java
+++ b/core/java/android/view/KeyEvent.java
@@ -21,7 +21,6 @@
 import android.text.method.MetaKeyKeyListener;
 import android.util.Log;
 import android.util.SparseIntArray;
-import android.view.KeyCharacterMap;
 import android.view.KeyCharacterMap.KeyData;
 
 /**
diff --git a/core/java/android/view/KeyboardShortcutGroup.java b/core/java/android/view/KeyboardShortcutGroup.java
index 57d07c0..78f0b30 100644
--- a/core/java/android/view/KeyboardShortcutGroup.java
+++ b/core/java/android/view/KeyboardShortcutGroup.java
@@ -15,6 +15,8 @@
  */
 package android.view;
 
+import static com.android.internal.util.Preconditions.checkNotNull;
+
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.os.Parcel;
@@ -24,8 +26,6 @@
 import java.util.Collections;
 import java.util.List;
 
-import static com.android.internal.util.Preconditions.checkNotNull;
-
 /**
  * A group of {@link KeyboardShortcutInfo}.
  */
diff --git a/core/java/android/view/KeyboardShortcutInfo.java b/core/java/android/view/KeyboardShortcutInfo.java
index a9f2699..c934a4e 100644
--- a/core/java/android/view/KeyboardShortcutInfo.java
+++ b/core/java/android/view/KeyboardShortcutInfo.java
@@ -15,14 +15,15 @@
  */
 package android.view;
 
+import static com.android.internal.util.Preconditions.checkArgument;
+
+import static java.lang.Character.MIN_VALUE;
+
 import android.annotation.Nullable;
 import android.graphics.drawable.Icon;
 import android.os.Parcel;
 import android.os.Parcelable;
 
-import static com.android.internal.util.Preconditions.checkArgument;
-import static java.lang.Character.MIN_VALUE;
-
 /**
  * Information about a Keyboard Shortcut.
  */
diff --git a/core/java/android/view/LayoutInflater.java b/core/java/android/view/LayoutInflater.java
index 914bd56..e3ac40c 100644
--- a/core/java/android/view/LayoutInflater.java
+++ b/core/java/android/view/LayoutInflater.java
@@ -16,11 +16,6 @@
 
 package android.view;
 
-import com.android.internal.R;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
 import android.annotation.LayoutRes;
 import android.annotation.Nullable;
 import android.content.Context;
@@ -37,6 +32,11 @@
 import android.util.Xml;
 import android.widget.FrameLayout;
 
+import com.android.internal.R;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.util.HashMap;
@@ -51,20 +51,20 @@
  *
  * <pre>LayoutInflater inflater = (LayoutInflater)context.getSystemService
  *      (Context.LAYOUT_INFLATER_SERVICE);</pre>
- * 
+ *
  * <p>
  * To create a new LayoutInflater with an additional {@link Factory} for your
  * own views, you can use {@link #cloneInContext} to clone an existing
  * ViewFactory, and then call {@link #setFactory} on it to include your
  * Factory.
- * 
+ *
  * <p>
  * For performance reasons, view inflation relies heavily on pre-processing of
  * XML files that is done at build time. Therefore, it is not currently possible
  * to use LayoutInflater with an XmlPullParser over a plain XML file at runtime;
  * it only works with an XmlPullParser returned from a compiled resource
  * (R.<em>something</em> file.)
- * 
+ *
  * @see Context#getSystemService
  */
 public abstract class LayoutInflater {
@@ -95,7 +95,7 @@
 
     private static final HashMap<String, Constructor<? extends View>> sConstructorMap =
             new HashMap<String, Constructor<? extends View>>();
-    
+
     private HashMap<String, Boolean> mFilterMap;
 
     private TypedValue mTempValue;
@@ -114,36 +114,36 @@
     /**
      * Hook to allow clients of the LayoutInflater to restrict the set of Views that are allowed
      * to be inflated.
-     * 
+     *
      */
     public interface Filter {
         /**
-         * Hook to allow clients of the LayoutInflater to restrict the set of Views 
+         * Hook to allow clients of the LayoutInflater to restrict the set of Views
          * that are allowed to be inflated.
-         * 
+         *
          * @param clazz The class object for the View that is about to be inflated
-         * 
+         *
          * @return True if this class is allowed to be inflated, or false otherwise
          */
         @SuppressWarnings("unchecked")
         boolean onLoadClass(Class clazz);
     }
-    
+
     public interface Factory {
         /**
          * Hook you can supply that is called when inflating from a LayoutInflater.
          * You can use this to customize the tag names available in your XML
          * layout files.
-         * 
+         *
          * <p>
          * Note that it is good practice to prefix these custom names with your
          * package (i.e., com.coolcompany.apps) to avoid conflicts with system
          * names.
-         * 
+         *
          * @param name Tag name to be inflated.
          * @param context The context the view is being created in.
          * @param attrs Inflation attributes as specified in XML file.
-         * 
+         *
          * @return View Newly created view. Return null for the default
          *         behavior.
          */
@@ -171,14 +171,14 @@
     private static class FactoryMerger implements Factory2 {
         private final Factory mF1, mF2;
         private final Factory2 mF12, mF22;
-        
+
         FactoryMerger(Factory f1, Factory2 f12, Factory f2, Factory2 f22) {
             mF1 = f1;
             mF2 = f2;
             mF12 = f12;
             mF22 = f22;
         }
-        
+
         public View onCreateView(String name, Context context, AttributeSet attrs) {
             View v = mF1.onCreateView(name, context, attrs);
             if (v != null) return v;
@@ -193,13 +193,13 @@
                     : mF2.onCreateView(name, context, attrs);
         }
     }
-    
+
     /**
      * Create a new LayoutInflater instance associated with a particular Context.
      * Applications will almost always want to use
      * {@link Context#getSystemService Context.getSystemService()} to retrieve
      * the standard {@link Context#LAYOUT_INFLATER_SERVICE Context.INFLATER_SERVICE}.
-     * 
+     *
      * @param context The Context in which this LayoutInflater will create its
      * Views; most importantly, this supplies the theme from which the default
      * values for their attributes are retrieved.
@@ -212,7 +212,7 @@
      * Create a new LayoutInflater instance that is a copy of an existing
      * LayoutInflater, optionally with its Context changed.  For use in
      * implementing {@link #cloneInContext}.
-     * 
+     *
      * @param original The original LayoutInflater to copy.
      * @param newContext The new Context to use.
      */
@@ -223,7 +223,7 @@
         mPrivateFactory = original.mPrivateFactory;
         setFilter(original.mFilter);
     }
-    
+
     /**
      * Obtains the LayoutInflater from the given context.
      */
@@ -241,15 +241,15 @@
      * pointing to a different Context than the original.  This is used by
      * {@link ContextThemeWrapper} to create a new LayoutInflater to go along
      * with the new Context theme.
-     * 
+     *
      * @param newContext The new Context to associate with the new LayoutInflater.
      * May be the same as the original Context if desired.
-     * 
+     *
      * @return Returns a brand spanking new LayoutInflater object associated with
      * the given Context.
      */
     public abstract LayoutInflater cloneInContext(Context newContext);
-    
+
     /**
      * Return the context we are running in, for access to resources, class
      * loader, etc.
@@ -285,7 +285,7 @@
      * called on each element name as the xml is parsed. If the factory returns
      * a View, that is added to the hierarchy. If it returns null, the next
      * factory default {@link #onCreateView} method is called.
-     * 
+     *
      * <p>If you have an existing
      * LayoutInflater and want to add your own factory to it, use
      * {@link #cloneInContext} to clone the existing instance and then you
@@ -345,13 +345,13 @@
     public Filter getFilter() {
         return mFilter;
     }
-    
+
     /**
      * Sets the {@link Filter} to by this LayoutInflater. If a view is attempted to be inflated
      * which is not allowed by the {@link Filter}, the {@link #inflate(int, ViewGroup)} call will
      * throw an {@link InflateException}. This filter will replace any previous filter set on this
      * LayoutInflater.
-     * 
+     *
      * @param filter The Filter which restricts the set of Views that are allowed to be inflated.
      *        This filter will replace any previous filter set on this LayoutInflater.
      */
@@ -365,7 +365,7 @@
     /**
      * Inflate a new view hierarchy from the specified xml resource. Throws
      * {@link InflateException} if there is an error.
-     * 
+     *
      * @param resource ID for an XML layout resource to load (e.g.,
      *        <code>R.layout.main_page</code>)
      * @param root Optional view to be the parent of the generated hierarchy.
@@ -385,7 +385,7 @@
      * reasons, view inflation relies heavily on pre-processing of XML files
      * that is done at build time. Therefore, it is not currently possible to
      * use LayoutInflater with an XmlPullParser over a plain XML file at runtime.
-     * 
+     *
      * @param parser XML dom node containing the description of the view
      *        hierarchy.
      * @param root Optional view to be the parent of the generated hierarchy.
@@ -400,7 +400,7 @@
     /**
      * Inflate a new view hierarchy from the specified xml resource. Throws
      * {@link InflateException} if there is an error.
-     * 
+     *
      * @param resource ID for an XML layout resource to load (e.g.,
      *        <code>R.layout.main_page</code>)
      * @param root Optional view to be the parent of the generated hierarchy (if
@@ -437,7 +437,7 @@
      * reasons, view inflation relies heavily on pre-processing of XML files
      * that is done at build time. Therefore, it is not currently possible to
      * use LayoutInflater with an XmlPullParser over a plain XML file at runtime.
-     * 
+     *
      * @param parser XML dom node containing the description of the view
      *        hierarchy.
      * @param root Optional view to be the parent of the generated hierarchy (if
@@ -475,7 +475,7 @@
                 }
 
                 final String name = parser.getName();
-                
+
                 if (DEBUG) {
                     System.out.println("**************************");
                     System.out.println("Creating root view: "
@@ -579,17 +579,17 @@
      * Low-level function for instantiating a view by name. This attempts to
      * instantiate a view class of the given <var>name</var> found in this
      * LayoutInflater's ClassLoader.
-     * 
+     *
      * <p>
      * There are two things that can happen in an error case: either the
      * exception describing the error will be thrown, or a null will be
      * returned. You must deal with both possibilities -- the former will happen
      * the first time createView() is called for a class of a particular name,
      * the latter every time there-after for that class name.
-     * 
+     *
      * @param name The full name of the class to be instantiated.
      * @param attrs The XML attributes supplied for this instance.
-     * 
+     *
      * @return View The newly instantiated view, or null.
      */
     public final View createView(String name, String prefix, AttributeSet attrs)
@@ -608,7 +608,7 @@
                 // Class not found in the cache, see if it's real, and try to add it
                 clazz = mContext.getClassLoader().loadClass(
                         prefix != null ? (prefix + name) : name).asSubclass(View.class);
-                
+
                 if (mFilter != null && clazz != null) {
                     boolean allowed = mFilter.onLoadClass(clazz);
                     if (!allowed) {
@@ -627,7 +627,7 @@
                         // New class -- remember whether it is allowed
                         clazz = mContext.getClassLoader().loadClass(
                                 prefix != null ? (prefix + name) : name).asSubclass(View.class);
-                        
+
                         boolean allowed = clazz != null && mFilter.onLoadClass(clazz);
                         mFilterMap.put(name, allowed);
                         if (!allowed) {
@@ -689,10 +689,10 @@
      * given the xml element name. Override it to handle custom view objects. If
      * you override this in your subclass be sure to call through to
      * super.onCreateView(name) for names you do not recognize.
-     * 
+     *
      * @param name The fully qualified class name of the View to be create.
      * @param attrs An AttributeSet of attributes to apply to the View.
-     * 
+     *
      * @return View The View created.
      */
     protected View onCreateView(String name, AttributeSet attrs)
@@ -842,7 +842,7 @@
             }
 
             final String name = parser.getName();
-            
+
             if (TAG_REQUEST_FOCUS.equals(name)) {
                 parseRequestFocus(parser, parent);
             } else if (TAG_TAG.equals(name)) {
diff --git a/core/java/android/view/MenuInflater.java b/core/java/android/view/MenuInflater.java
index 1c67ba7..73ea9ee 100644
--- a/core/java/android/view/MenuInflater.java
+++ b/core/java/android/view/MenuInflater.java
@@ -16,11 +16,6 @@
 
 package android.view;
 
-import com.android.internal.view.menu.MenuItemImpl;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
 import android.annotation.MenuRes;
 import android.app.Activity;
 import android.content.Context;
@@ -31,6 +26,11 @@
 import android.util.Log;
 import android.util.Xml;
 
+import com.android.internal.view.menu.MenuItemImpl;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
 import java.io.IOException;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Method;
@@ -49,15 +49,15 @@
 
     /** Menu tag name in XML. */
     private static final String XML_MENU = "menu";
-    
+
     /** Group tag name in XML. */
     private static final String XML_GROUP = "group";
-    
+
     /** Item tag name in XML. */
     private static final String XML_ITEM = "item";
 
     private static final int NO_ID = 0;
-    
+
     private static final Class<?>[] ACTION_VIEW_CONSTRUCTOR_SIGNATURE = new Class[] {Context.class};
 
     private static final Class<?>[] ACTION_PROVIDER_CONSTRUCTOR_SIGNATURE = ACTION_VIEW_CONSTRUCTOR_SIGNATURE;
@@ -71,7 +71,7 @@
 
     /**
      * Constructs a menu inflater.
-     * 
+     *
      * @see Activity#getMenuInflater()
      */
     public MenuInflater(Context context) {
@@ -96,7 +96,7 @@
     /**
      * Inflate a menu hierarchy from the specified XML resource. Throws
      * {@link InflateException} if there is an error.
-     * 
+     *
      * @param menuRes Resource ID for an XML layout resource to load (e.g.,
      *            <code>R.menu.main_activity</code>)
      * @param menu The Menu to inflate into. The items and submenus will be
@@ -107,7 +107,7 @@
         try {
             parser = mContext.getResources().getLayout(menuRes);
             AttributeSet attrs = Xml.asAttributeSet(parser);
-            
+
             parseMenu(parser, attrs, menu);
         } catch (XmlPullParserException e) {
             throw new InflateException("Error inflating menu XML", e);
@@ -140,12 +140,12 @@
                     eventType = parser.next();
                     break;
                 }
-                
+
                 throw new RuntimeException("Expecting menu, got " + tagName);
             }
             eventType = parser.next();
         } while (eventType != XmlPullParser.END_DOCUMENT);
-        
+
         boolean reachedEndOfMenu = false;
         while (!reachedEndOfMenu) {
             switch (eventType) {
@@ -153,7 +153,7 @@
                     if (lookingForEndOfUnknownTag) {
                         break;
                     }
-                    
+
                     tagName = parser.getName();
                     if (tagName.equals(XML_GROUP)) {
                         menuState.readGroup(attrs);
@@ -171,7 +171,7 @@
                         unknownTagName = tagName;
                     }
                     break;
-                    
+
                 case XmlPullParser.END_TAG:
                     tagName = parser.getName();
                     if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) {
@@ -194,11 +194,11 @@
                         reachedEndOfMenu = true;
                     }
                     break;
-                    
+
                 case XmlPullParser.END_DOCUMENT:
                     throw new RuntimeException("Unexpected end of document");
             }
-            
+
             eventType = parser.next();
         }
     }
@@ -229,10 +229,10 @@
     private static class InflatedOnMenuItemClickListener
             implements MenuItem.OnMenuItemClickListener {
         private static final Class<?>[] PARAM_TYPES = new Class[] { MenuItem.class };
-        
+
         private Object mRealOwner;
         private Method mMethod;
-        
+
         public InflatedOnMenuItemClickListener(Object realOwner, String methodName) {
             mRealOwner = realOwner;
             Class<?> c = realOwner.getClass();
@@ -246,7 +246,7 @@
                 throw ex;
             }
         }
-        
+
         public boolean onMenuItemClick(MenuItem item) {
             try {
                 if (mMethod.getReturnType() == Boolean.TYPE) {
@@ -277,7 +277,7 @@
         }
         return owner;
     }
-    
+
     /**
      * State for the current menu.
      * <p>
@@ -316,7 +316,7 @@
         private boolean itemChecked;
         private boolean itemVisible;
         private boolean itemEnabled;
-        
+
         /**
          * Sync to attrs.xml enum, values in MenuItem:
          * - 0: never
@@ -331,7 +331,7 @@
         private String itemActionProviderClassName;
 
         private String itemListenerMethodName;
-        
+
         private ActionProvider itemActionProvider;
 
         private static final int defaultGroupId = NO_ID;
@@ -342,13 +342,13 @@
         private static final boolean defaultItemChecked = false;
         private static final boolean defaultItemVisible = true;
         private static final boolean defaultItemEnabled = true;
-        
+
         public MenuState(final Menu menu) {
             this.menu = menu;
-            
+
             resetGroup();
         }
-        
+
         public void resetGroup() {
             groupId = defaultGroupId;
             groupCategory = defaultItemCategory;
@@ -364,7 +364,7 @@
         public void readGroup(AttributeSet attrs) {
             TypedArray a = mContext.obtainStyledAttributes(attrs,
                     com.android.internal.R.styleable.MenuGroup);
-            
+
             groupId = a.getResourceId(com.android.internal.R.styleable.MenuGroup_id, defaultGroupId);
             groupCategory = a.getInt(com.android.internal.R.styleable.MenuGroup_menuCategory, defaultItemCategory);
             groupOrder = a.getInt(com.android.internal.R.styleable.MenuGroup_orderInCategory, defaultItemOrder);
@@ -374,7 +374,7 @@
 
             a.recycle();
         }
-        
+
         /**
          * Called when the parser is pointing to an item tag.
          */
@@ -436,7 +436,7 @@
                 return shortcutString.charAt(0);
             }
         }
-        
+
         private void setItem(MenuItem item) {
             item.setChecked(itemChecked)
                 .setVisible(itemVisible)
@@ -446,11 +446,11 @@
                 .setIcon(itemIconResId)
                 .setAlphabeticShortcut(itemAlphabeticShortcut)
                 .setNumericShortcut(itemNumericShortcut);
-            
+
             if (itemShowAsAction >= 0) {
                 item.setShowAsAction(itemShowAsAction);
             }
-            
+
             if (itemListenerMethodName != null) {
                 if (mContext.isRestricted()) {
                     throw new IllegalStateException("The android:onClick attribute cannot "
@@ -494,14 +494,14 @@
             setItem(item);
             return item;
         }
-        
+
         public SubMenu addSubMenuItem() {
             itemAdded = true;
             SubMenu subMenu = menu.addSubMenu(groupId, itemId, itemCategoryOrder, itemTitle);
             setItem(subMenu.getItem());
             return subMenu;
         }
-        
+
         public boolean hasAddedItem() {
             return itemAdded;
         }
diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java
index 3e8d577..2316b38 100644
--- a/core/java/android/view/MotionEvent.java
+++ b/core/java/android/view/MotionEvent.java
@@ -436,6 +436,14 @@
     public static final int FLAG_WINDOW_IS_PARTIALLY_OBSCURED = 0x2;
 
     /**
+     * This private flag is only set on {@link #ACTION_HOVER_MOVE} events and indicates that
+     * this event will be immediately followed by a {@link #ACTION_HOVER_EXIT}. It is used to
+     * prevent generating redundant {@link #ACTION_HOVER_ENTER} events.
+     * @hide
+     */
+    public static final int FLAG_HOVER_EXIT_PENDING = 0x4;
+
+    /**
      * Private flag that indicates when the system has detected that this motion event
      * may be inconsistent with respect to the sequence of previously delivered motion events,
      * such as when a pointer move event is sent but the pointer is not down.
@@ -1947,6 +1955,20 @@
                 : flags & ~FLAG_TARGET_ACCESSIBILITY_FOCUS);
     }
 
+    /** @hide */
+    public final boolean isHoverExitPending() {
+        final int flags = getFlags();
+        return (flags & FLAG_HOVER_EXIT_PENDING) != 0;
+    }
+
+    /** @hide */
+    public void setHoverExitPending(boolean hoverExitPending) {
+        final int flags = getFlags();
+        nativeSetFlags(mNativePtr, hoverExitPending
+                ? flags | FLAG_HOVER_EXIT_PENDING
+                : flags & ~FLAG_HOVER_EXIT_PENDING);
+    }
+
     /**
      * Returns the time (in ms) when the user originally pressed down to start
      * a stream of position events.
diff --git a/core/java/android/view/PointerIcon.java b/core/java/android/view/PointerIcon.java
index fc79f53..998fd01 100644
--- a/core/java/android/view/PointerIcon.java
+++ b/core/java/android/view/PointerIcon.java
@@ -17,9 +17,6 @@
 package android.view;
 
 import android.annotation.NonNull;
-import android.util.SparseArray;
-import com.android.internal.util.XmlUtils;
-
 import android.annotation.XmlRes;
 import android.content.Context;
 import android.content.res.Resources;
@@ -32,6 +29,9 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.util.Log;
+import android.util.SparseArray;
+
+import com.android.internal.util.XmlUtils;
 
 /**
  * Represents an icon that can be used as a mouse pointer.
diff --git a/core/java/android/view/RemotableViewMethod.java b/core/java/android/view/RemotableViewMethod.java
index e5cae84..03aed9a 100644
--- a/core/java/android/view/RemotableViewMethod.java
+++ b/core/java/android/view/RemotableViewMethod.java
@@ -36,6 +36,3 @@
      */
     String asyncImpl() default "";
 }
-
-
-
diff --git a/core/java/android/view/RenderNodeAnimatorSetHelper.java b/core/java/android/view/RenderNodeAnimatorSetHelper.java
index ba592d29..e1ef059 100644
--- a/core/java/android/view/RenderNodeAnimatorSetHelper.java
+++ b/core/java/android/view/RenderNodeAnimatorSetHelper.java
@@ -16,6 +16,7 @@
 package android.view;
 
 import android.animation.TimeInterpolator;
+
 import com.android.internal.view.animation.FallbackLUTInterpolator;
 import com.android.internal.view.animation.NativeInterpolatorFactory;
 import com.android.internal.view.animation.NativeInterpolatorFactoryHelper;
diff --git a/core/java/android/view/RoundScrollbarRenderer.java b/core/java/android/view/RoundScrollbarRenderer.java
index b77be8c..4c555ae 100644
--- a/core/java/android/view/RoundScrollbarRenderer.java
+++ b/core/java/android/view/RoundScrollbarRenderer.java
@@ -19,8 +19,8 @@
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
-import android.graphics.RectF;
 import android.graphics.Rect;
+import android.graphics.RectF;
 
 /**
  * Helper class for drawing round scroll bars on round Wear devices.
diff --git a/core/java/android/view/ScaleGestureDetector.java b/core/java/android/view/ScaleGestureDetector.java
index 7cd161c..9787494 100644
--- a/core/java/android/view/ScaleGestureDetector.java
+++ b/core/java/android/view/ScaleGestureDetector.java
@@ -20,7 +20,6 @@
 import android.content.res.Resources;
 import android.os.Build;
 import android.os.Handler;
-import android.os.SystemClock;
 
 /**
  * Detects scaling transformation gestures using the supplied {@link MotionEvent}s.
diff --git a/core/java/android/view/SearchEvent.java b/core/java/android/view/SearchEvent.java
index 643cc3e..72b5e4b 100644
--- a/core/java/android/view/SearchEvent.java
+++ b/core/java/android/view/SearchEvent.java
@@ -16,8 +16,6 @@
 
 package android.view;
 
-import android.view.InputDevice;
-
 /**
  * Class that contains information about an event that triggers a search.
  */
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index 22e68a3..ecd5e3b 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -26,11 +26,11 @@
 import android.os.Parcelable;
 import android.util.Log;
 
+import dalvik.system.CloseGuard;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
-import dalvik.system.CloseGuard;
-
 /**
  * Handle onto a raw buffer that is being managed by the screen compositor.
  *
diff --git a/core/java/android/view/SurfaceControl.java b/core/java/android/view/SurfaceControl.java
index 6456826..b87250e 100644
--- a/core/java/android/view/SurfaceControl.java
+++ b/core/java/android/view/SurfaceControl.java
@@ -16,7 +16,6 @@
 
 package android.view;
 
-import dalvik.system.CloseGuard;
 import android.graphics.Bitmap;
 import android.graphics.Rect;
 import android.graphics.Region;
@@ -24,6 +23,8 @@
 import android.util.Log;
 import android.view.Surface.OutOfResourcesException;
 
+import dalvik.system.CloseGuard;
+
 /**
  * SurfaceControl
  *  @hide
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index 816bcf0..80f447e 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -16,11 +16,9 @@
 
 package android.view;
 
-import com.android.internal.view.BaseIWindow;
-
 import android.content.Context;
-import android.content.res.Configuration;
 import android.content.res.CompatibilityInfo.Translator;
+import android.content.res.Configuration;
 import android.graphics.Canvas;
 import android.graphics.PixelFormat;
 import android.graphics.PorterDuff;
@@ -28,12 +26,14 @@
 import android.graphics.Region;
 import android.os.Handler;
 import android.os.Message;
+import android.os.ParcelFileDescriptor;
 import android.os.RemoteException;
 import android.os.SystemClock;
-import android.os.ParcelFileDescriptor;
 import android.util.AttributeSet;
 import android.util.Log;
 
+import com.android.internal.view.BaseIWindow;
+
 import java.lang.ref.WeakReference;
 import java.util.ArrayList;
 import java.util.concurrent.locks.ReentrantLock;
diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java
index ce390a2..0bb84cc 100644
--- a/core/java/android/view/ThreadedRenderer.java
+++ b/core/java/android/view/ThreadedRenderer.java
@@ -16,9 +16,9 @@
 
 package android.view;
 
-import android.app.ActivityManagerNative;
 import android.annotation.IntDef;
 import android.annotation.NonNull;
+import android.app.ActivityManagerNative;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
@@ -916,7 +916,6 @@
             mInitialized = true;
             initSched(context, renderProxy);
             initGraphicsStats(context, renderProxy);
-            initAssetAtlas(context, renderProxy);
         }
 
         private static void initSched(Context context, long renderProxy) {
@@ -944,32 +943,6 @@
                 Log.w(LOG_TAG, "Could not acquire gfx stats buffer", t);
             }
         }
-
-        private static void initAssetAtlas(Context context, long renderProxy) {
-            IBinder binder = ServiceManager.getService("assetatlas");
-            if (binder == null) return;
-
-            IAssetAtlas atlas = IAssetAtlas.Stub.asInterface(binder);
-            try {
-                if (atlas.isCompatible(android.os.Process.myPpid())) {
-                    GraphicBuffer buffer = atlas.getBuffer();
-                    if (buffer != null) {
-                        long[] map = atlas.getMap();
-                        if (map != null) {
-                            nSetAtlas(renderProxy, buffer, map);
-                        }
-                        // If IAssetAtlas is not the same class as the IBinder
-                        // we are using a remote service and we can safely
-                        // destroy the graphic buffer
-                        if (atlas.getClass() != binder.getClass()) {
-                            buffer.destroy();
-                        }
-                    }
-                }
-            } catch (RemoteException e) {
-                Log.w(LOG_TAG, "Could not acquire atlas", e);
-            }
-        }
     }
 
     void addFrameMetricsObserver(FrameMetricsObserver observer) {
@@ -984,7 +957,6 @@
 
     static native void setupShadersDiskCache(String cacheFile);
 
-    private static native void nSetAtlas(long nativeProxy, GraphicBuffer buffer, long[] map);
     private static native void nSetProcessStatsBuffer(long nativeProxy, int fd);
     private static native int nGetRenderThreadTid(long nativeProxy);
 
diff --git a/core/java/android/view/TouchDelegate.java b/core/java/android/view/TouchDelegate.java
index 27b49db..cf36f43 100644
--- a/core/java/android/view/TouchDelegate.java
+++ b/core/java/android/view/TouchDelegate.java
@@ -17,9 +17,6 @@
 package android.view;
 
 import android.graphics.Rect;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewConfiguration;
 
 /**
  * Helper class to handle situations where you want a view to have a larger touch area than its
@@ -33,24 +30,24 @@
  * </p>
  */
 public class TouchDelegate {
-    
+
     /**
-     * View that should receive forwarded touch events 
+     * View that should receive forwarded touch events
      */
     private View mDelegateView;
-    
+
     /**
      * Bounds in local coordinates of the containing view that should be mapped to the delegate
      * view. This rect is used for initial hit testing.
      */
     private Rect mBounds;
-    
+
     /**
      * mBounds inflated to include some slop. This rect is to track whether the motion events
      * should be considered to be be within the delegate view.
      */
     private Rect mSlopBounds;
-    
+
     /**
      * True if the delegate had been targeted on a down event (intersected mBounds).
      */
@@ -82,7 +79,7 @@
 
     /**
      * Constructor
-     * 
+     *
      * @param bounds Bounds in local coordinates of the containing view that should be mapped to
      *        the delegate view
      * @param delegateView The view that should receive motion events
@@ -99,7 +96,7 @@
     /**
      * Will forward touch events to the delegate view if the event is within the bounds
      * specified in the constructor.
-     * 
+     *
      * @param event The touch event to forward
      * @return True if the event was forwarded to the delegate, false otherwise.
      */
@@ -136,7 +133,7 @@
         }
         if (sendToDelegate) {
             final View delegateView = mDelegateView;
-            
+
             if (hit) {
                 // Offset event coordinates to be inside the target view
                 event.setLocation(delegateView.getWidth() / 2, delegateView.getHeight() / 2);
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index bdf93e4..20876a9 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -16,6 +16,14 @@
 
 package android.view;
 
+import static android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH;
+import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
+import static android.os.Build.VERSION_CODES.KITKAT;
+import static android.os.Build.VERSION_CODES.M;
+import static android.os.Build.VERSION_CODES.N;
+
+import static java.lang.Math.max;
+
 import android.animation.AnimatorInflater;
 import android.animation.StateListAnimator;
 import android.annotation.CallSuper;
@@ -40,6 +48,7 @@
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.Insets;
 import android.graphics.Interpolator;
 import android.graphics.LinearGradient;
@@ -79,11 +88,11 @@
 import android.util.StateSet;
 import android.util.SuperNotCalledException;
 import android.util.TypedValue;
-import android.view.ContextMenu.ContextMenuInfo;
 import android.view.AccessibilityIterators.CharacterTextSegmentIterator;
 import android.view.AccessibilityIterators.ParagraphTextSegmentIterator;
 import android.view.AccessibilityIterators.TextSegmentIterator;
 import android.view.AccessibilityIterators.WordTextSegmentIterator;
+import android.view.ContextMenu.ContextMenuInfo;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityEventSource;
 import android.view.accessibility.AccessibilityManager;
@@ -99,17 +108,15 @@
 import android.widget.Checkable;
 import android.widget.FrameLayout;
 import android.widget.ScrollBarDrawable;
-import static android.os.Build.VERSION_CODES.*;
-import static java.lang.Math.max;
 
 import com.android.internal.R;
 import com.android.internal.util.Predicate;
 import com.android.internal.view.menu.MenuBuilder;
 import com.android.internal.widget.ScrollBarUtils;
+
 import com.google.android.collect.Lists;
 import com.google.android.collect.Maps;
 
-import java.lang.NullPointerException;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.ref.WeakReference;
@@ -757,6 +764,9 @@
         AccessibilityEventSource {
     private static final boolean DBG = false;
 
+    /** @hide */
+    public static boolean DEBUG_DRAW = false;
+
     /**
      * The logging tag used by this class with android.util.Log.
      */
@@ -1184,6 +1194,8 @@
      */
     static final int PARENT_SAVE_DISABLED_MASK = 0x20000000;
 
+    private static Paint sDebugPaint;
+
     /** @hide */
     @IntDef(flag = true,
             value = {
@@ -1655,6 +1667,10 @@
             | AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED
             | AccessibilityEvent.TYPE_VIEW_TEXT_TRAVERSED_AT_MOVEMENT_GRANULARITY;
 
+    static final int DEBUG_CORNERS_COLOR = Color.rgb(63, 127, 255);
+
+    static final int DEBUG_CORNERS_SIZE_DIP = 8;
+
     /**
      * Temporary Rect currently for use in setBackground().  This will probably
      * be extended in the future to hold our own class with more than just
@@ -4743,6 +4759,10 @@
         mRenderNode = RenderNode.create(getClass().getName(), this);
     }
 
+    final boolean debugDraw() {
+        return DEBUG_DRAW || mAttachInfo != null && mAttachInfo.mDebugLayout;
+    }
+
     private static SparseArray<String> getAttributeMap() {
         if (mAttributeMap == null) {
             mAttributeMap = new SparseArray<>();
@@ -16137,6 +16157,9 @@
                         if (mOverlay != null && !mOverlay.isEmpty()) {
                             mOverlay.getOverlayView().draw(canvas);
                         }
+                        if (debugDraw()) {
+                            debugDrawFocus(canvas);
+                        }
                     } else {
                         draw(canvas);
                     }
@@ -17115,6 +17138,44 @@
         return more;
     }
 
+    static Paint getDebugPaint() {
+        if (sDebugPaint == null) {
+            sDebugPaint = new Paint();
+            sDebugPaint.setAntiAlias(false);
+        }
+        return sDebugPaint;
+    }
+
+    final int dipsToPixels(int dips) {
+        float scale = getContext().getResources().getDisplayMetrics().density;
+        return (int) (dips * scale + 0.5f);
+    }
+
+    final private void debugDrawFocus(Canvas canvas) {
+        if (isFocused()) {
+            final int cornerSquareSize = dipsToPixels(DEBUG_CORNERS_SIZE_DIP);
+            final int l = mScrollX;
+            final int r = l + mRight - mLeft;
+            final int t = mScrollY;
+            final int b = t + mBottom - mTop;
+
+            final Paint paint = getDebugPaint();
+            paint.setColor(DEBUG_CORNERS_COLOR);
+
+            // Draw squares in corners.
+            paint.setStyle(Paint.Style.FILL);
+            canvas.drawRect(l, t, l + cornerSquareSize, t + cornerSquareSize, paint);
+            canvas.drawRect(r - cornerSquareSize, t, r, t + cornerSquareSize, paint);
+            canvas.drawRect(l, b - cornerSquareSize, l + cornerSquareSize, b, paint);
+            canvas.drawRect(r - cornerSquareSize, b - cornerSquareSize, r, b, paint);
+
+            // Draw big X across the view.
+            paint.setStyle(Paint.Style.STROKE);
+            canvas.drawLine(l, t, r, b, paint);
+            canvas.drawLine(l, b, r, t, paint);
+        }
+    }
+
     /**
      * Manually render this view (and all of its children) to the given Canvas.
      * The view must have already done a full layout before this function is
@@ -17169,6 +17230,10 @@
             // Step 6, draw decorations (foreground, scrollbars)
             onDrawForeground(canvas);
 
+            if (debugDraw()) {
+                debugDrawFocus(canvas);
+            }
+
             // we're done...
             return;
         }
@@ -17317,6 +17382,10 @@
 
         // Step 6, draw decorations (foreground, scrollbars)
         onDrawForeground(canvas);
+
+        if (debugDraw()) {
+            debugDrawFocus(canvas);
+        }
     }
 
     /**
diff --git a/core/java/android/view/ViewDebug.java b/core/java/android/view/ViewDebug.java
index e1ff0d6..047a515 100644
--- a/core/java/android/view/ViewDebug.java
+++ b/core/java/android/view/ViewDebug.java
@@ -51,8 +51,8 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.FutureTask;
-import java.util.concurrent.TimeoutException;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
 import java.util.concurrent.atomic.AtomicReference;
 
 /**
diff --git a/core/java/android/view/ViewGroup.java b/core/java/android/view/ViewGroup.java
index 2e428a7..e39cb96 100644
--- a/core/java/android/view/ViewGroup.java
+++ b/core/java/android/view/ViewGroup.java
@@ -16,6 +16,8 @@
 
 package android.view;
 
+import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
+
 import android.animation.LayoutTransition;
 import android.annotation.IdRes;
 import android.annotation.NonNull;
@@ -62,8 +64,6 @@
 import java.util.List;
 import java.util.Map;
 
-import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
-
 /**
  * <p>
  * A <code>ViewGroup</code> is a special view that can contain other views
@@ -116,8 +116,6 @@
     private static final String TAG = "ViewGroup";
 
     private static final boolean DBG = false;
-    /** @hide */
-    public static boolean DEBUG_DRAW = false;
 
     /**
      * Views which have been hidden or removed which need to be animated on
@@ -476,7 +474,6 @@
     private static final int ARRAY_INITIAL_CAPACITY = 12;
     private static final int ARRAY_CAPACITY_INCREMENT = 12;
 
-    private static Paint sDebugPaint;
     private static float[] sDebugLines;
 
     // Used to draw cached views
@@ -586,10 +583,6 @@
         initFromAttributes(context, attrs, defStyleAttr, defStyleRes);
     }
 
-    private boolean debugDraw() {
-        return DEBUG_DRAW || mAttachInfo != null && mAttachInfo.mDebugLayout;
-    }
-
     private void initViewGroup() {
         // ViewGroup doesn't draw by default
         if (!debugDraw()) {
@@ -1865,8 +1858,11 @@
                 // Synthesize an exit from a move or enter.
                 // Ignore the result because hover focus has moved to a different view.
                 if (action == MotionEvent.ACTION_HOVER_MOVE) {
+                    final boolean hoverExitPending = event.isHoverExitPending();
+                    event.setHoverExitPending(true);
                     dispatchTransformedGenericPointerEvent(
                             event, child); // move
+                    event.setHoverExitPending(hoverExitPending);
                 }
                 eventNoHistory = obtainMotionEventNoHistoryOrSelf(eventNoHistory);
                 eventNoHistory.setAction(MotionEvent.ACTION_HOVER_EXIT);
@@ -1880,8 +1876,10 @@
             firstOldHoverTarget = nextOldHoverTarget;
         }
 
-        // Send events to the view group itself if no children have handled it.
-        boolean newHoveredSelf = !handled;
+        // Send events to the view group itself if no children have handled it and the view group
+        // itself is not currently being hover-exited.
+        boolean newHoveredSelf = !handled &&
+                (action != MotionEvent.ACTION_HOVER_EXIT) && !event.isHoverExitPending();
         if (newHoveredSelf == mHoveredSelf) {
             if (newHoveredSelf) {
                 // Send event to the view group as before.
@@ -3375,11 +3373,6 @@
         fillRect(c, paint, x1, y1, x1 + lw * sign(dx), y1 + dy);
     }
 
-    private int dipsToPixels(int dips) {
-        float scale = getContext().getResources().getDisplayMetrics().density;
-        return (int) (dips * scale + 0.5f);
-    }
-
     private static void drawRectCorners(Canvas canvas, int x1, int y1, int x2, int y2, Paint paint,
             int lineLength, int lineWidth) {
         drawCorner(canvas, paint, x1, y1, lineLength, lineLength, lineWidth);
@@ -3448,10 +3441,10 @@
 
         // Draw clip bounds
         {
-            paint.setColor(Color.rgb(63, 127, 255));
+            paint.setColor(DEBUG_CORNERS_COLOR);
             paint.setStyle(Paint.Style.FILL);
 
-            int lineLength = dipsToPixels(8);
+            int lineLength = dipsToPixels(DEBUG_CORNERS_SIZE_DIP);
             int lineWidth = dipsToPixels(1);
             for (int i = 0; i < getChildCount(); i++) {
                 View c = getChildAt(i);
@@ -7926,14 +7919,6 @@
         }
     }
 
-    private static Paint getDebugPaint() {
-        if (sDebugPaint == null) {
-            sDebugPaint = new Paint();
-            sDebugPaint.setAntiAlias(false);
-        }
-        return sDebugPaint;
-    }
-
     private static void drawRect(Canvas canvas, Paint paint, int x1, int y1, int x2, int y2) {
         if (sDebugLines== null) {
             // TODO: This won't work with multiple UI threads in a single process
diff --git a/core/java/android/view/ViewPropertyAnimator.java b/core/java/android/view/ViewPropertyAnimator.java
index c604234..6c84b63 100644
--- a/core/java/android/view/ViewPropertyAnimator.java
+++ b/core/java/android/view/ViewPropertyAnimator.java
@@ -17,8 +17,9 @@
 package android.view;
 
 import android.animation.Animator;
-import android.animation.ValueAnimator;
 import android.animation.TimeInterpolator;
+import android.animation.ValueAnimator;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Set;
@@ -42,7 +43,7 @@
  * <p>This class is not constructed by the caller, but rather by the View whose properties
  * it will animate. Calls to {@link android.view.View#animate()} will return a reference
  * to the appropriate ViewPropertyAnimator object for that View.</p>
- * 
+ *
  */
 public class ViewPropertyAnimator {
 
@@ -332,7 +333,7 @@
      * Sets the interpolator for the underlying animator that animates the requested properties.
      * By default, the animator uses the default interpolator for ValueAnimator. Calling this method
      * will cause the declared object to be used instead.
-     * 
+     *
      * @param interpolator The TimeInterpolator to be used for ensuing property animations. A value
      * of <code>null</code> will result in linear interpolation.
      * @return This object, allowing calls to methods in this class to be chained.
diff --git a/core/java/android/view/Window.java b/core/java/android/view/Window.java
index b046e2d..2c13831 100644
--- a/core/java/android/view/Window.java
+++ b/core/java/android/view/Window.java
@@ -16,6 +16,8 @@
 
 package android.view;
 
+import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
+
 import android.annotation.ColorInt;
 import android.annotation.DrawableRes;
 import android.annotation.IdRes;
@@ -24,7 +26,6 @@
 import android.annotation.Nullable;
 import android.annotation.StyleRes;
 import android.annotation.SystemApi;
-import android.app.ActivityManagerNative;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.content.res.Resources;
@@ -44,8 +45,6 @@
 import android.transition.TransitionManager;
 import android.view.accessibility.AccessibilityEvent;
 
-import static android.view.WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
-
 import java.util.List;
 
 /**
diff --git a/core/java/android/view/WindowManager.java b/core/java/android/view/WindowManager.java
index 395f738..abb3051 100644
--- a/core/java/android/view/WindowManager.java
+++ b/core/java/android/view/WindowManager.java
@@ -64,6 +64,13 @@
     /** @hide */
     int DOCKED_BOTTOM = 4;
 
+    /** @hide */
+    final static String INPUT_CONSUMER_PIP = "pip_input_consumer";
+    /** @hide */
+    final static String INPUT_CONSUMER_NAVIGATION = "nav_input_consumer";
+    /** @hide */
+    final static String INPUT_CONSUMER_WALLPAPER = "wallpaper_input_consumer";
+
     /**
      * Exception that is thrown when trying to add view whose
      * {@link LayoutParams} {@link LayoutParams#token}
diff --git a/core/java/android/view/WindowManagerImpl.java b/core/java/android/view/WindowManagerImpl.java
index dd4e096..c1b8f04 100644
--- a/core/java/android/view/WindowManagerImpl.java
+++ b/core/java/android/view/WindowManagerImpl.java
@@ -23,7 +23,6 @@
 import android.os.RemoteException;
 
 import com.android.internal.os.IResultReceiver;
-import com.android.internal.R;
 
 import java.util.List;
 
@@ -38,11 +37,11 @@
  * Additional window manager specific layout parameters are defined for
  * control over how windows are displayed.  It also implements the {@link WindowManager}
  * interface, allowing you to control the displays attached to the device.
- * 
+ *
  * <p>Applications will not normally use WindowManager directly, instead relying
  * on the higher-level facilities in {@link android.app.Activity} and
  * {@link android.app.Dialog}.
- * 
+ *
  * <p>Even for low-level window manager access, it is almost never correct to use
  * this class.  For example, {@link android.app.Activity#getWindowManager}
  * provides a window manager for adding windows that are associated with that
diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java
index da361c1..a6be493 100644
--- a/core/java/android/view/WindowManagerPolicy.java
+++ b/core/java/android/view/WindowManagerPolicy.java
@@ -25,12 +25,12 @@
 import android.content.res.Configuration;
 import android.graphics.Point;
 import android.graphics.Rect;
-import android.graphics.RectF;
 import android.os.Bundle;
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.RemoteException;
 import android.view.animation.Animation;
+
 import com.android.internal.policy.IShortcutService;
 
 import java.io.PrintWriter;
@@ -458,7 +458,7 @@
         /**
          * Add a input consumer which will consume all input events going to any window below it.
          */
-        public InputConsumer addInputConsumer(Looper looper,
+        public InputConsumer createInputConsumer(Looper looper, String name,
                 InputEventReceiver.Factory inputEventReceiverFactory);
 
         /**
diff --git a/core/java/android/view/accessibility/AccessibilityManager.java b/core/java/android/view/accessibility/AccessibilityManager.java
index c125b32..8084195 100644
--- a/core/java/android/view/accessibility/AccessibilityManager.java
+++ b/core/java/android/view/accessibility/AccessibilityManager.java
@@ -21,7 +21,6 @@
 import android.annotation.NonNull;
 import android.content.Context;
 import android.content.pm.PackageManager;
-import android.content.pm.ParceledListSlice;
 import android.content.pm.ServiceInfo;
 import android.os.Binder;
 import android.os.Handler;
diff --git a/core/java/android/view/animation/Animation.java b/core/java/android/view/animation/Animation.java
index d89c172..474db12 100644
--- a/core/java/android/view/animation/Animation.java
+++ b/core/java/android/view/animation/Animation.java
@@ -26,6 +26,7 @@
 import android.os.SystemProperties;
 import android.util.AttributeSet;
 import android.util.TypedValue;
+
 import dalvik.system.CloseGuard;
 
 /**
@@ -80,13 +81,13 @@
      * order.
      */
     public static final int ZORDER_NORMAL = 0;
-    
+
     /**
      * Requests that the content being animated be forced on top of all other
      * content for the duration of the animation.
      */
     public static final int ZORDER_TOP = 1;
-    
+
     /**
      * Requests that the content being animated be forced under all other
      * content for the duration of the animation.
@@ -138,7 +139,7 @@
     /**
      * Indicates whether fillBefore should be taken into account.
      */
-    boolean mFillEnabled = false;    
+    boolean mFillEnabled = false;
 
     /**
      * The time in milliseconds at which the animation must start;
@@ -240,7 +241,7 @@
 
         setDuration((long) a.getInt(com.android.internal.R.styleable.Animation_duration, 0));
         setStartOffset((long) a.getInt(com.android.internal.R.styleable.Animation_startOffset, 0));
-        
+
         setFillEnabled(a.getBoolean(com.android.internal.R.styleable.Animation_fillEnabled, mFillEnabled));
         setFillBefore(a.getBoolean(com.android.internal.R.styleable.Animation_fillBefore, mFillBefore));
         setFillAfter(a.getBoolean(com.android.internal.R.styleable.Animation_fillAfter, mFillAfter));
@@ -249,7 +250,7 @@
         setRepeatMode(a.getInt(com.android.internal.R.styleable.Animation_repeatMode, RESTART));
 
         setZAdjustment(a.getInt(com.android.internal.R.styleable.Animation_zAdjustment, ZORDER_NORMAL));
-        
+
         setBackgroundColor(a.getInt(com.android.internal.R.styleable.Animation_background, 0));
 
         setDetachWallpaper(a.getBoolean(com.android.internal.R.styleable.Animation_detachWallpaper, false));
@@ -294,13 +295,13 @@
     /**
      * Cancel the animation. Cancelling an animation invokes the animation
      * listener, if set, to notify the end of the animation.
-     * 
+     *
      * If you cancel an animation manually, you must call {@link #reset()}
      * before starting the animation again.
-     * 
-     * @see #reset() 
-     * @see #start() 
-     * @see #startNow() 
+     *
+     * @see #reset()
+     * @see #start()
+     * @see #startNow()
      */
     public void cancel() {
         if (mStarted && !mEnded) {
@@ -356,7 +357,7 @@
 
     /**
      * Sets the handler used to invoke listeners.
-     * 
+     *
      * @hide
      */
     public void setListenerHandler(Handler handler) {
@@ -424,7 +425,7 @@
 
     /**
      * How long this animation should last. The duration cannot be negative.
-     * 
+     *
      * @param durationMillis Duration in milliseconds
      *
      * @throws java.lang.IllegalArgumentException if the duration is < 0
@@ -443,7 +444,7 @@
      * than <var>durationMillis</var>.  In addition to adjusting the duration
      * itself, this ensures that the repeat count also will not make it run
      * longer than the given time.
-     * 
+     *
      * @param durationMillis The maximum duration the animation is allowed
      * to run.
      */
@@ -455,7 +456,7 @@
             mRepeatCount = 0;
             return;
         }
-        
+
         long dur = mDuration + mStartOffset;
         if (dur > durationMillis) {
             mDuration = durationMillis-mStartOffset;
@@ -480,7 +481,7 @@
             }
         }
     }
-    
+
     /**
      * How much to scale the duration by.
      *
@@ -528,7 +529,7 @@
     /**
      * Defines what this animation should do when it reaches the end. This
      * setting is applied only when the repeat count is either greater than
-     * 0 or {@link #INFINITE}. Defaults to {@link #RESTART}. 
+     * 0 or {@link #INFINITE}. Defaults to {@link #RESTART}.
      *
      * @param repeatMode {@link #RESTART} or {@link #REVERSE}
      * @attr ref android.R.styleable#Animation_repeatMode
@@ -606,7 +607,7 @@
      * @param fillAfter true if the animation should apply its transformation after it ends
      * @attr ref android.R.styleable#Animation_fillAfter
      *
-     * @see #setFillEnabled(boolean) 
+     * @see #setFillEnabled(boolean)
      */
     public void setFillAfter(boolean fillAfter) {
         mFillAfter = fillAfter;
@@ -614,7 +615,7 @@
 
     /**
      * Set the Z ordering mode to use while running the animation.
-     * 
+     *
      * @param zAdjustment The desired mode, one of {@link #ZORDER_NORMAL},
      * {@link #ZORDER_TOP}, or {@link #ZORDER_BOTTOM}.
      * @attr ref android.R.styleable#Animation_zAdjustment
@@ -622,7 +623,7 @@
     public void setZAdjustment(int zAdjustment) {
         mZAdjustment = zAdjustment;
     }
-    
+
     /**
      * Set background behind animation.
      *
@@ -634,11 +635,11 @@
     }
 
     /**
-     * The scale factor is set by the call to <code>getTransformation</code>. Overrides of 
+     * The scale factor is set by the call to <code>getTransformation</code>. Overrides of
      * {@link #getTransformation(long, Transformation, float)} will get this value
      * directly. Overrides of {@link #applyTransformation(float, Transformation)} can
      * call this method to get the value.
-     * 
+     *
      * @return float The scale factor that should be applied to pre-scaled values in
      * an Animation such as the pivot points in {@link ScaleAnimation} and {@link RotateAnimation}.
      */
@@ -748,7 +749,7 @@
     /**
      * Returns the Z ordering mode to use while running the animation as
      * previously set by {@link #setZAdjustment}.
-     * 
+     *
      * @return Returns one of {@link #ZORDER_NORMAL},
      * {@link #ZORDER_TOP}, or {@link #ZORDER_BOTTOM}.
      * @attr ref android.R.styleable#Animation_zAdjustment
@@ -827,7 +828,7 @@
     public long computeDurationHint() {
         return (getStartOffset() + getDuration()) * (getRepeatCount() + 1);
     }
-    
+
     /**
      * Gets the transformation to apply at a specified point in time. Implementations of this
      * method should always replace the specified Transformation or document they are doing
@@ -975,7 +976,7 @@
      * their transforms given an interpolation value.  Implementations of this
      * method should always replace the specified Transformation or document
      * they are doing otherwise.
-     * 
+     *
      * @param interpolatedTime The value of the normalized time (0.0 to 1.0)
      *        after it has been run through the interpolation function.
      * @param t The Transformation object to fill in with the current
@@ -1015,7 +1016,7 @@
      * @param bottom
      * @param invalidate
      * @param transformation
-     * 
+     *
      * @hide
      */
     public void getInvalidateRegion(int left, int top, int right, int bottom,
@@ -1072,7 +1073,7 @@
 
     /**
      * Return true if this animation changes the view's alpha property.
-     * 
+     *
      * @hide
      */
     public boolean hasAlpha() {
diff --git a/core/java/android/view/animation/AnimationSet.java b/core/java/android/view/animation/AnimationSet.java
index 71c7450..09d4dfc 100644
--- a/core/java/android/view/animation/AnimationSet.java
+++ b/core/java/android/view/animation/AnimationSet.java
@@ -18,17 +18,17 @@
 
 import android.content.Context;
 import android.content.res.TypedArray;
+import android.graphics.RectF;
 import android.os.Build;
 import android.util.AttributeSet;
-import android.graphics.RectF;
 
 import java.util.ArrayList;
 import java.util.List;
 
 /**
  * Represents a group of Animations that should be played together.
- * The transformation of each individual animation are composed 
- * together into a single transform. 
+ * The transformation of each individual animation are composed
+ * together into a single transform.
  * If AnimationSet sets any properties that its children also set
  * (for example, duration or fillBefore), the values of AnimationSet
  * override the child values.
@@ -72,17 +72,17 @@
     private long[] mStoredOffsets;
 
     /**
-     * Constructor used when an AnimationSet is loaded from a resource. 
-     * 
+     * Constructor used when an AnimationSet is loaded from a resource.
+     *
      * @param context Application context to use
      * @param attrs Attribute set from which to read values
      */
     public AnimationSet(Context context, AttributeSet attrs) {
         super(context, attrs);
-        
+
         TypedArray a =
             context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.AnimationSet);
-        
+
         setFlag(PROPERTY_SHARE_INTERPOLATOR_MASK,
                 a.getBoolean(com.android.internal.R.styleable.AnimationSet_shareInterpolator, true));
         init();
@@ -108,11 +108,11 @@
 
         a.recycle();
     }
-    
-    
+
+
     /**
      * Constructor to use when building an AnimationSet from code
-     * 
+     *
      * @param shareInterpolator Pass true if all of the animations in this set
      *        should use the interpolator associated with this AnimationSet.
      *        Pass false if each animation should use its own interpolator.
@@ -244,10 +244,10 @@
 
         mDirty = true;
     }
-    
+
     /**
      * Sets the start time of this animation and all child animations
-     * 
+     *
      * @see android.view.animation.Animation#setStartTime(long)
      */
     @Override
@@ -289,11 +289,11 @@
             animations.get(i).restrictDuration(durationMillis);
         }
     }
-    
+
     /**
-     * The duration of an AnimationSet is defined to be the 
+     * The duration of an AnimationSet is defined to be the
      * duration of the longest child animation.
-     * 
+     *
      * @see android.view.animation.Animation#getDuration()
      */
     @Override
@@ -317,7 +317,7 @@
     /**
      * The duration hint of an animation set is the maximum of the duration
      * hints of all of its component animations.
-     * 
+     *
      * @see android.view.animation.Animation#computeDurationHint
      */
     public long computeDurationHint() {
@@ -362,7 +362,7 @@
     /**
      * The transformation of an animation set is the concatenation of all of its
      * component animations.
-     * 
+     *
      * @see android.view.animation.Animation#getTransformation
      */
     @Override
@@ -404,7 +404,7 @@
 
         return more;
     }
-    
+
     /**
      * @see android.view.animation.Animation#scaleCurrentDuration(float)
      */
diff --git a/core/java/android/view/animation/AnimationUtils.java b/core/java/android/view/animation/AnimationUtils.java
index 351b6db..f5c3613 100644
--- a/core/java/android/view/animation/AnimationUtils.java
+++ b/core/java/android/view/animation/AnimationUtils.java
@@ -16,19 +16,19 @@
 
 package android.view.animation;
 
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
 import android.annotation.AnimRes;
 import android.annotation.InterpolatorRes;
 import android.content.Context;
 import android.content.res.Resources;
+import android.content.res.Resources.NotFoundException;
 import android.content.res.Resources.Theme;
 import android.content.res.XmlResourceParser;
-import android.content.res.Resources.NotFoundException;
+import android.os.SystemClock;
 import android.util.AttributeSet;
 import android.util.Xml;
-import android.os.SystemClock;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.IOException;
 
diff --git a/core/java/android/view/animation/AnticipateInterpolator.java b/core/java/android/view/animation/AnticipateInterpolator.java
index fb66c31..7a837c3 100644
--- a/core/java/android/view/animation/AnticipateInterpolator.java
+++ b/core/java/android/view/animation/AnticipateInterpolator.java
@@ -18,8 +18,8 @@
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.content.res.TypedArray;
 import android.content.res.Resources.Theme;
+import android.content.res.TypedArray;
 import android.util.AttributeSet;
 
 import com.android.internal.R;
diff --git a/core/java/android/view/animation/AnticipateOvershootInterpolator.java b/core/java/android/view/animation/AnticipateOvershootInterpolator.java
index 1af72da..9a75134 100644
--- a/core/java/android/view/animation/AnticipateOvershootInterpolator.java
+++ b/core/java/android/view/animation/AnticipateOvershootInterpolator.java
@@ -16,6 +16,10 @@
 
 package android.view.animation;
 
+import static com.android.internal.R.styleable.AnticipateOvershootInterpolator;
+import static com.android.internal.R.styleable.AnticipateOvershootInterpolator_extraTension;
+import static com.android.internal.R.styleable.AnticipateOvershootInterpolator_tension;
+
 import android.content.Context;
 import android.content.res.Resources;
 import android.content.res.Resources.Theme;
@@ -26,10 +30,6 @@
 import com.android.internal.view.animation.NativeInterpolatorFactory;
 import com.android.internal.view.animation.NativeInterpolatorFactoryHelper;
 
-import static com.android.internal.R.styleable.AnticipateOvershootInterpolator_extraTension;
-import static com.android.internal.R.styleable.AnticipateOvershootInterpolator_tension;
-import static com.android.internal.R.styleable.AnticipateOvershootInterpolator;
-
 /**
  * An interpolator where the change starts backward then flings forward and overshoots
  * the target value and finally goes back to the final value.
diff --git a/core/java/android/view/animation/CycleInterpolator.java b/core/java/android/view/animation/CycleInterpolator.java
index 663c109..72d64a1 100644
--- a/core/java/android/view/animation/CycleInterpolator.java
+++ b/core/java/android/view/animation/CycleInterpolator.java
@@ -18,8 +18,8 @@
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.content.res.TypedArray;
 import android.content.res.Resources.Theme;
+import android.content.res.TypedArray;
 import android.util.AttributeSet;
 
 import com.android.internal.R;
diff --git a/core/java/android/view/animation/DecelerateInterpolator.java b/core/java/android/view/animation/DecelerateInterpolator.java
index f426f60..f89743c 100644
--- a/core/java/android/view/animation/DecelerateInterpolator.java
+++ b/core/java/android/view/animation/DecelerateInterpolator.java
@@ -18,8 +18,8 @@
 
 import android.content.Context;
 import android.content.res.Resources;
-import android.content.res.TypedArray;
 import android.content.res.Resources.Theme;
+import android.content.res.TypedArray;
 import android.util.AttributeSet;
 
 import com.android.internal.R;
diff --git a/core/java/android/view/animation/GridLayoutAnimationController.java b/core/java/android/view/animation/GridLayoutAnimationController.java
index 9161d8b..0f189ae 100644
--- a/core/java/android/view/animation/GridLayoutAnimationController.java
+++ b/core/java/android/view/animation/GridLayoutAnimationController.java
@@ -16,11 +16,11 @@
 
 package android.view.animation;
 
-import android.view.View;
-import android.view.ViewGroup;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
 
 import java.util.Random;
 
@@ -43,7 +43,7 @@
  *
  * @see LayoutAnimationController
  * @see android.widget.GridView
- * 
+ *
  * @attr ref android.R.styleable#GridLayoutAnimation_columnDelay
  * @attr ref android.R.styleable#GridLayoutAnimation_rowDelay
  * @attr ref android.R.styleable#GridLayoutAnimation_direction
@@ -206,7 +206,7 @@
      *
      * @see #getRowDelay()
      * @see #getColumnDelay()
-     * @see #setColumnDelay(float) 
+     * @see #setColumnDelay(float)
      */
     public void setRowDelay(float rowDelay) {
         mRowDelay = rowDelay;
diff --git a/core/java/android/view/inputmethod/BaseInputConnection.java b/core/java/android/view/inputmethod/BaseInputConnection.java
index 38962a3..5f7a0f7 100644
--- a/core/java/android/view/inputmethod/BaseInputConnection.java
+++ b/core/java/android/view/inputmethod/BaseInputConnection.java
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 2008 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
@@ -35,7 +35,6 @@
 import android.view.KeyCharacterMap;
 import android.view.KeyEvent;
 import android.view.View;
-import android.view.ViewRootImpl;
 
 class ComposingText implements NoCopySpan {
 }
@@ -56,25 +55,25 @@
     protected final InputMethodManager mIMM;
     final View mTargetView;
     final boolean mDummyMode;
-    
+
     private Object[] mDefaultComposingSpans;
-    
+
     Editable mEditable;
     KeyCharacterMap mKeyCharacterMap;
-    
+
     BaseInputConnection(InputMethodManager mgr, boolean fullEditor) {
         mIMM = mgr;
         mTargetView = null;
         mDummyMode = !fullEditor;
     }
-    
+
     public BaseInputConnection(View targetView, boolean fullEditor) {
         mIMM = (InputMethodManager)targetView.getContext().getSystemService(
                 Context.INPUT_METHOD_SERVICE);
         mTargetView = targetView;
         mDummyMode = !fullEditor;
     }
-    
+
     public static final void removeComposingSpans(Spannable text) {
         text.removeSpan(COMPOSING);
         Object[] sps = text.getSpans(0, text.length(), Object.class);
@@ -104,8 +103,8 @@
                 }
 
                 final int fl = text.getSpanFlags(o);
-                if ((fl&(Spanned.SPAN_COMPOSING|Spanned.SPAN_POINT_MARK_MASK)) 
-                        != (Spanned.SPAN_COMPOSING|Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)) {
+                if ((fl & (Spanned.SPAN_COMPOSING | Spanned.SPAN_POINT_MARK_MASK))
+                        != (Spanned.SPAN_COMPOSING | Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)) {
                     text.setSpan(o, text.getSpanStart(o), text.getSpanEnd(o),
                             (fl & ~Spanned.SPAN_POINT_MARK_MASK)
                                     | Spanned.SPAN_COMPOSING
@@ -117,15 +116,15 @@
         text.setSpan(COMPOSING, start, end,
                 Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
     }
-    
+
     public static int getComposingSpanStart(Spannable text) {
         return text.getSpanStart(COMPOSING);
     }
-    
+
     public static int getComposingSpanEnd(Spannable text) {
         return text.getSpanEnd(COMPOSING);
     }
-    
+
     /**
      * Return the target of edit operations.  The default implementation
      * returns its own fake editable that is just used for composing text;
@@ -139,7 +138,7 @@
         }
         return mEditable;
     }
-    
+
     /**
      * Default implementation does nothing.
      */
@@ -452,10 +451,10 @@
      */
     public int getCursorCapsMode(int reqModes) {
         if (mDummyMode) return 0;
-        
+
         final Editable content = getEditable();
         if (content == null) return 0;
-        
+
         int a = Selection.getSelectionStart(content);
         int b = Selection.getSelectionEnd(content);
 
@@ -495,7 +494,7 @@
         if (a <= 0) {
             return "";
         }
-        
+
         if (length > a) {
             length = a;
         }
@@ -702,7 +701,7 @@
         if (!mDummyMode) {
             return;
         }
-        
+
         Editable content = getEditable();
         if (content != null) {
             final int N = content.length();
@@ -727,7 +726,7 @@
                     return;
                 }
             }
-            
+
             // Otherwise, revert to the special key event containing
             // the actual characters.
             KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(),
@@ -768,7 +767,7 @@
         if (content == null) {
             return;
         }
-        
+
         beginBatchEdit();
 
         // delete composing text set previously.
@@ -776,7 +775,7 @@
         int b = getComposingSpanEnd(content);
 
         if (DEBUG) Log.v(TAG, "Composing span: " + a + " to " + b);
-        
+
         if (b < a) {
             int tmp = a;
             a = b;
@@ -814,11 +813,11 @@
             }
             setComposingSpans(sp);
         }
-        
+
         if (DEBUG) Log.v(TAG, "Replacing from " + a + " to " + b + " with \""
                 + text + "\", composing=" + composing
                 + ", type=" + text.getClass().getCanonicalName());
-        
+
         if (DEBUG) {
             LogPrinter lp = new LogPrinter(Log.VERBOSE, TAG);
             lp.println("Current text:");
@@ -842,13 +841,13 @@
         Selection.setSelection(content, newCursorPosition);
 
         content.replace(a, b, text);
-        
+
         if (DEBUG) {
             LogPrinter lp = new LogPrinter(Log.VERBOSE, TAG);
             lp.println("Final text:");
             TextUtils.dumpSpans(content, lp, "  ");
         }
-        
+
         endBatchEdit();
     }
 
diff --git a/core/java/android/view/inputmethod/InputConnectionInspector.java b/core/java/android/view/inputmethod/InputConnectionInspector.java
index 2b292bb..5f25bf5 100644
--- a/core/java/android/view/inputmethod/InputConnectionInspector.java
+++ b/core/java/android/view/inputmethod/InputConnectionInspector.java
@@ -16,6 +16,8 @@
 
 package android.view.inputmethod;
 
+import static java.lang.annotation.RetentionPolicy.SOURCE;
+
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -28,8 +30,6 @@
 import java.util.Map;
 import java.util.WeakHashMap;
 
-import static java.lang.annotation.RetentionPolicy.SOURCE;
-
 /**
  * @hide
  */
diff --git a/core/java/android/view/inputmethod/InputMethodInfo.java b/core/java/android/view/inputmethod/InputMethodInfo.java
index 661b52f..5c8e6dc 100644
--- a/core/java/android/view/inputmethod/InputMethodInfo.java
+++ b/core/java/android/view/inputmethod/InputMethodInfo.java
@@ -16,9 +16,6 @@
 
 package android.view.inputmethod;
 
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
@@ -39,6 +36,9 @@
 import android.util.Xml;
 import android.view.inputmethod.InputMethodSubtype.InputMethodSubtypeBuilder;
 
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index ca370dc..2e99092 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 2007-2008 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
@@ -16,15 +16,7 @@
 
 package android.view.inputmethod;
 
-import com.android.internal.inputmethod.IInputContentUriToken;
-import com.android.internal.os.SomeArgs;
-import com.android.internal.view.IInputConnectionWrapper;
-import com.android.internal.view.IInputContext;
-import com.android.internal.view.IInputMethodClient;
-import com.android.internal.view.IInputMethodManager;
-import com.android.internal.view.IInputMethodSession;
-import com.android.internal.view.InputBindResult;
-import com.android.internal.view.InputMethodClient;
+import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -40,8 +32,8 @@
 import android.os.RemoteException;
 import android.os.ResultReceiver;
 import android.os.ServiceManager;
-import android.os.Trace;
 import android.os.ServiceManager.ServiceNotFoundException;
+import android.os.Trace;
 import android.text.TextUtils;
 import android.text.style.SuggestionSpan;
 import android.util.Log;
@@ -56,11 +48,19 @@
 import android.view.KeyEvent;
 import android.view.View;
 import android.view.ViewRootImpl;
-import android.view.textservice.TextServicesManager;
+
+import com.android.internal.inputmethod.IInputContentUriToken;
+import com.android.internal.os.SomeArgs;
+import com.android.internal.view.IInputConnectionWrapper;
+import com.android.internal.view.IInputContext;
+import com.android.internal.view.IInputMethodClient;
+import com.android.internal.view.IInputMethodManager;
+import com.android.internal.view.IInputMethodSession;
+import com.android.internal.view.InputBindResult;
+import com.android.internal.view.InputMethodClient;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
-import java.security.InvalidParameterException;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -70,14 +70,12 @@
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import static android.Manifest.permission.WRITE_SECURE_SETTINGS;
-
 /**
  * Central system API to the overall input method framework (IMF) architecture,
  * which arbitrates interaction between applications and the current input method.
  * You can retrieve an instance of this interface with
  * {@link Context#getSystemService(String) Context.getSystemService()}.
- * 
+ *
  * <p>Topics covered here:
  * <ol>
  * <li><a href="#ArchitectureOverview">Architecture Overview</a>
@@ -85,13 +83,13 @@
  * <li><a href="#InputMethods">Input Methods</a>
  * <li><a href="#Security">Security</a>
  * </ol>
- * 
+ *
  * <a name="ArchitectureOverview"></a>
  * <h3>Architecture Overview</h3>
- * 
+ *
  * <p>There are three primary parties involved in the input method
  * framework (IMF) architecture:</p>
- * 
+ *
  * <ul>
  * <li> The <strong>input method manager</strong> as expressed by this class
  * is the central point of the system that manages interaction between all
@@ -106,16 +104,16 @@
  * method manager for input focus and control over the state of the IME.  Only
  * one such client is ever active (working with the IME) at a time.
  * </ul>
- * 
- * 
+ *
+ *
  * <a name="Applications"></a>
  * <h3>Applications</h3>
- * 
+ *
  * <p>In most cases, applications that are using the standard
  * {@link android.widget.TextView} or its subclasses will have little they need
  * to do to work well with soft input methods.  The main things you need to
  * be aware of are:</p>
- * 
+ *
  * <ul>
  * <li> Properly set the {@link android.R.attr#inputType} in your editable
  * text views, so that the input method will have enough context to help the
@@ -131,43 +129,43 @@
  * for your window using the same {@link android.R.attr#windowSoftInputMode}
  * attribute.
  * </ul>
- * 
+ *
  * <p>More finer-grained control is available through the APIs here to directly
  * interact with the IMF and its IME -- either showing or hiding the input
  * area, letting the user pick an input method, etc.</p>
- * 
+ *
  * <p>For the rare people amongst us writing their own text editors, you
  * will need to implement {@link android.view.View#onCreateInputConnection}
  * to return a new instance of your own {@link InputConnection} interface
  * allowing the IME to interact with your editor.</p>
- * 
- * 
+ *
+ *
  * <a name="InputMethods"></a>
  * <h3>Input Methods</h3>
- * 
+ *
  * <p>An input method (IME) is implemented
  * as a {@link android.app.Service}, typically deriving from
  * {@link android.inputmethodservice.InputMethodService}.  It must provide
  * the core {@link InputMethod} interface, though this is normally handled by
  * {@link android.inputmethodservice.InputMethodService} and implementors will
  * only need to deal with the higher-level API there.</p>
- * 
+ *
  * See the {@link android.inputmethodservice.InputMethodService} class for
  * more information on implementing IMEs.
- * 
- * 
+ *
+ *
  * <a name="Security"></a>
  * <h3>Security</h3>
- * 
+ *
  * <p>There are a lot of security issues associated with input methods,
  * since they essentially have freedom to completely drive the UI and monitor
  * everything the user enters.  The Android input method framework also allows
  * arbitrary third party IMEs, so care must be taken to restrict their
  * selection and interactions.</p>
- * 
+ *
  * <p>Here are some key points about the security architecture behind the
  * IMF:</p>
- * 
+ *
  * <ul>
  * <li> <p>Only the system is allowed to directly access an IME's
  * {@link InputMethod} interface, via the
@@ -175,11 +173,11 @@
  * enforced in the system by not binding to an input method service that does
  * not require this permission, so the system can guarantee no other untrusted
  * clients are accessing the current input method outside of its control.</p>
- * 
+ *
  * <li> <p>There may be many client processes of the IMF, but only one may
  * be active at a time.  The inactive clients can not interact with key
  * parts of the IMF through the mechanisms described below.</p>
- * 
+ *
  * <li> <p>Clients of an input method are only given access to its
  * {@link InputMethodSession} interface.  One instance of this interface is
  * created for each client, and only calls from the session associated with
@@ -187,19 +185,19 @@
  * by {@link android.inputmethodservice.AbstractInputMethodService} for normal
  * IMEs, but must be explicitly handled by an IME that is customizing the
  * raw {@link InputMethodSession} implementation.</p>
- * 
+ *
  * <li> <p>Only the active client's {@link InputConnection} will accept
  * operations.  The IMF tells each client process whether it is active, and
  * the framework enforces that in inactive processes calls on to the current
  * InputConnection will be ignored.  This ensures that the current IME can
  * only deliver events and text edits to the UI that the user sees as
  * being in focus.</p>
- * 
+ *
  * <li> <p>An IME can never interact with an {@link InputConnection} while
  * the screen is off.  This is enforced by making all clients inactive while
  * the screen is off, and prevents bad IMEs from driving the UI when the user
  * can not be aware of its behavior.</p>
- * 
+ *
  * <li> <p>A client application can ask that the system let the user pick a
  * new IME, but can not programmatically switch to one itself.  This avoids
  * malicious applications from switching the user to their own IME, which
@@ -207,7 +205,7 @@
  * IME, on the other hand, <em>is</em> allowed to programmatically switch
  * the system to another IME, since it already has full control of user
  * input.</p>
- * 
+ *
  * <li> <p>The user must explicitly enable a new IME in settings before
  * they can switch to it, to confirm with the system that they know about it
  * and want to make it available for use.</p>
@@ -268,11 +266,11 @@
 
     final IInputMethodManager mService;
     final Looper mMainLooper;
-    
+
     // For scheduling work on the main thread.  This also serves as our
     // global lock.
     final H mH;
-    
+
     // Our generic input connection if the current target does not have its own.
     final IInputContext mIInputContext;
 
@@ -280,20 +278,20 @@
      * True if this input method client is active, initially false.
      */
     boolean mActive = false;
-    
+
     /**
      * Set whenever this client becomes inactive, to know we need to reset
      * state with the IME the next time we receive focus.
      */
     boolean mHasBeenInactive = true;
-    
+
     /**
      * As reported by IME through InputConnection.
      */
     boolean mFullscreenMode;
-    
+
     // -----------------------------------------------------------
-    
+
     /**
      * This is the root view of the overall window that currently has input
      * method focus.
@@ -328,7 +326,7 @@
      * The completions that were last provided by the served view.
      */
     CompletionInfo[] mCompletions;
-    
+
     // Cursor position on the screen.
     Rect mTmpCursorRect = new Rect();
     Rect mCursorRect = new Rect();
@@ -389,7 +387,7 @@
     final SparseArray<PendingEvent> mPendingEvents = new SparseArray<>(20);
 
     // -----------------------------------------------------------
-    
+
     static final int MSG_DUMP = 1;
     static final int MSG_BIND = 2;
     static final int MSG_UNBIND = 3;
@@ -403,7 +401,7 @@
         H(Looper looper) {
             super(looper, null, true);
         }
-        
+
         @Override
         public void handleMessage(Message msg) {
             switch (msg.what) {
@@ -654,7 +652,7 @@
             return sInstance;
         }
     }
-    
+
     /**
      * Private optimization: retrieve the global InputMethodManager instance,
      * if it exists.
@@ -663,17 +661,17 @@
     public static InputMethodManager peekInstance() {
         return sInstance;
     }
-    
+
     /** @hide */
     public IInputMethodClient getClient() {
         return mClient;
     }
-    
+
     /** @hide */
     public IInputContext getInputContext() {
         return mIInputContext;
     }
-    
+
     public List<InputMethodInfo> getInputMethodList() {
         try {
             return mService.getInputMethodList();
@@ -784,7 +782,7 @@
                     && mCurrentTextBoxAttribute != null;
         }
     }
-    
+
     /**
      * Return true if any view is currently active in the input method.
      */
@@ -794,7 +792,7 @@
             return mServedView != null && mCurrentTextBoxAttribute != null;
         }
     }
-    
+
     /**
      * Return true if the currently served view is accepting full text edits.
      * If false, it has no input connection, so can only handle raw key events.
@@ -871,7 +869,7 @@
                             || !mServedView.checkInputConnectionProxy(view))) {
                 return;
             }
-            
+
             mCompletions = completions;
             if (mCurMethod != null) {
                 try {
@@ -881,7 +879,7 @@
             }
         }
     }
-    
+
     public void updateExtractedText(View view, int token, ExtractedText text) {
         checkFocus();
         synchronized (mH) {
@@ -889,7 +887,7 @@
                     || !mServedView.checkInputConnectionProxy(view))) {
                 return;
             }
-            
+
             if (mCurMethod != null) {
                 try {
                     mCurMethod.updateExtractedText(token, text);
@@ -898,26 +896,26 @@
             }
         }
     }
-    
+
     /**
      * Flag for {@link #showSoftInput} to indicate that this is an implicit
      * request to show the input window, not as the result of a direct request
      * by the user.  The window may not be shown in this case.
      */
     public static final int SHOW_IMPLICIT = 0x0001;
-    
+
     /**
      * Flag for {@link #showSoftInput} to indicate that the user has forced
      * the input method open (such as by long-pressing menu) so it should
      * not be closed until they explicitly do so.
      */
     public static final int SHOW_FORCED = 0x0002;
-    
+
     /**
      * Synonym for {@link #showSoftInput(View, int, ResultReceiver)} without
      * a result receiver: explicitly request that the current input method's
      * soft input area be shown to the user, if needed.
-     * 
+     *
      * @param view The currently focused view, which would like to receive
      * soft keyboard input.
      * @param flags Provides additional operating flags.  Currently may be
@@ -926,7 +924,7 @@
     public boolean showSoftInput(View view, int flags) {
         return showSoftInput(view, flags, null);
     }
-    
+
     /**
      * Flag for the {@link ResultReceiver} result code from
      * {@link #showSoftInput(View, int, ResultReceiver)} and
@@ -934,7 +932,7 @@
      * state of the soft input window was unchanged and remains shown.
      */
     public static final int RESULT_UNCHANGED_SHOWN = 0;
-    
+
     /**
      * Flag for the {@link ResultReceiver} result code from
      * {@link #showSoftInput(View, int, ResultReceiver)} and
@@ -942,7 +940,7 @@
      * state of the soft input window was unchanged and remains hidden.
      */
     public static final int RESULT_UNCHANGED_HIDDEN = 1;
-    
+
     /**
      * Flag for the {@link ResultReceiver} result code from
      * {@link #showSoftInput(View, int, ResultReceiver)} and
@@ -950,7 +948,7 @@
      * state of the soft input window changed from hidden to shown.
      */
     public static final int RESULT_SHOWN = 2;
-    
+
     /**
      * Flag for the {@link ResultReceiver} result code from
      * {@link #showSoftInput(View, int, ResultReceiver)} and
@@ -958,7 +956,7 @@
      * state of the soft input window changed from shown to hidden.
      */
     public static final int RESULT_HIDDEN = 3;
-    
+
     /**
      * Explicitly request that the current input method's soft input area be
      * shown to the user, if needed.  Call this if the user interacts with
@@ -1000,7 +998,7 @@
             }
         }
     }
-    
+
     /** @hide */
     public void showSoftInputUnchecked(int flags, ResultReceiver resultReceiver) {
         try {
@@ -1009,14 +1007,14 @@
             throw e.rethrowFromSystemServer();
         }
     }
-    
+
     /**
      * Flag for {@link #hideSoftInputFromWindow} to indicate that the soft
      * input window should only be hidden if it was not explicitly shown
      * by the user.
      */
     public static final int HIDE_IMPLICIT_ONLY = 0x0001;
-    
+
     /**
      * Flag for {@link #hideSoftInputFromWindow} to indicate that the soft
      * input window should normally be hidden, unless it was originally
@@ -1028,7 +1026,7 @@
      * Synonym for {@link #hideSoftInputFromWindow(IBinder, int, ResultReceiver)}
      * without a result: request to hide the soft input window from the
      * context of the window that is currently accepting input.
-     * 
+     *
      * @param windowToken The token of the window that is making the request,
      * as returned by {@link View#getWindowToken() View.getWindowToken()}.
      * @param flags Provides additional operating flags.  Currently may be
@@ -1037,7 +1035,7 @@
     public boolean hideSoftInputFromWindow(IBinder windowToken, int flags) {
         return hideSoftInputFromWindow(windowToken, flags, null);
     }
-    
+
     /**
      * Request to hide the soft input window from the context of the window
      * that is currently accepting input.  This should be called as a result
@@ -1079,11 +1077,11 @@
             }
         }
     }
-    
+
 
     /**
      * This method toggles the input method window display.
-     * If the input window is already displayed, it gets hidden. 
+     * If the input window is already displayed, it gets hidden.
      * If not the input window will be displayed.
      * @param windowToken The token of the window that is making the request,
      * as returned by {@link View#getWindowToken() View.getWindowToken()}.
@@ -1110,7 +1108,7 @@
 
     /*
      * This method toggles the input method window display.
-     * If the input window is already displayed, it gets hidden. 
+     * If the input window is already displayed, it gets hidden.
      * If not the input window will be displayed.
      * @param showFlags Provides additional operating flags.  May be
      * 0 or have the {@link #SHOW_IMPLICIT},
@@ -1134,7 +1132,7 @@
      * restart it with its new contents.  You should call this when the text
      * within your view changes outside of the normal input method or key
      * input flow, such as when an application calls TextView.setText().
-     * 
+     *
      * @param view The view whose text has changed.
      */
     public void restartInput(View view) {
@@ -1144,7 +1142,7 @@
                     || !mServedView.checkInputConnectionProxy(view))) {
                 return;
             }
-            
+
             mServedConnecting = true;
         }
 
@@ -1196,7 +1194,7 @@
             });
             return false;
         }
-        
+
         // Okay we are now ready to call into the served view and have it
         // do its stuff.
         // Life is good: let's hook everything up!
@@ -1465,7 +1463,7 @@
 
         return true;
     }
-    
+
     void closeCurrentInput() {
         try {
             mService.hideSoftInput(mClient, HIDE_NOT_ALWAYS, null);
@@ -1504,7 +1502,7 @@
         if (first) {
             controlFlags |= CONTROL_WINDOW_FIRST;
         }
-        
+
         if (checkFocusNoStartInput(forceNewFocus)) {
             // We need to restart input on the current focus view.  This
             // should be done in conjunction with telling the system service
@@ -1792,7 +1790,7 @@
      * Close/hide the input method's soft input area, so the user no longer
      * sees it or can interact with it.  This can only be called
      * from the currently active input method, as validated by the given token.
-     * 
+     *
      * @param token Supplies the identifying token given to an input method
      * when it was started, which allows it to perform this operation on
      * itself.
@@ -1807,13 +1805,13 @@
             throw e.rethrowFromSystemServer();
         }
     }
-    
+
     /**
-     * Show the input method's soft input area, so the user 
+     * Show the input method's soft input area, so the user
      * sees the input method window and can interact with it.
      * This can only be called from the currently active input method,
      * as validated by the given token.
-     * 
+     *
      * @param token Supplies the identifying token given to an input method
      * when it was started, which allows it to perform this operation on
      * itself.
@@ -2335,7 +2333,7 @@
     void doDump(FileDescriptor fd, PrintWriter fout, String[] args) {
         final Printer p = new PrintWriterPrinter(fout);
         p.println("Input method client state for " + this + ":");
-        
+
         p.println("  mService=" + mService);
         p.println("  mMainLooper=" + mMainLooper);
         p.println("  mIInputContext=" + mIInputContext);
diff --git a/core/java/android/view/textservice/SpellCheckerInfo.java b/core/java/android/view/textservice/SpellCheckerInfo.java
index fc17f7a..7aa2c23 100644
--- a/core/java/android/view/textservice/SpellCheckerInfo.java
+++ b/core/java/android/view/textservice/SpellCheckerInfo.java
@@ -16,9 +16,6 @@
 
 package android.view.textservice;
 
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.PackageManager;
@@ -35,6 +32,9 @@
 import android.util.Slog;
 import android.util.Xml;
 
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
diff --git a/core/java/android/view/textservice/SpellCheckerSession.java b/core/java/android/view/textservice/SpellCheckerSession.java
index e77dc0d..729eb8d 100644
--- a/core/java/android/view/textservice/SpellCheckerSession.java
+++ b/core/java/android/view/textservice/SpellCheckerSession.java
@@ -16,11 +16,6 @@
 
 package android.view.textservice;
 
-import com.android.internal.textservice.ISpellCheckerSession;
-import com.android.internal.textservice.ISpellCheckerSessionListener;
-import com.android.internal.textservice.ITextServicesManager;
-import com.android.internal.textservice.ITextServicesSessionListener;
-
 import android.os.Binder;
 import android.os.Handler;
 import android.os.HandlerThread;
@@ -29,6 +24,11 @@
 import android.os.RemoteException;
 import android.util.Log;
 
+import com.android.internal.textservice.ISpellCheckerSession;
+import com.android.internal.textservice.ISpellCheckerSessionListener;
+import com.android.internal.textservice.ITextServicesManager;
+import com.android.internal.textservice.ITextServicesSessionListener;
+
 import java.util.LinkedList;
 import java.util.Queue;
 
diff --git a/core/java/android/view/textservice/SpellCheckerSubtype.java b/core/java/android/view/textservice/SpellCheckerSubtype.java
index 8dff0c6..026610e 100644
--- a/core/java/android/view/textservice/SpellCheckerSubtype.java
+++ b/core/java/android/view/textservice/SpellCheckerSubtype.java
@@ -16,8 +16,6 @@
 
 package android.view.textservice;
 
-import com.android.internal.inputmethod.InputMethodUtils;
-
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
@@ -27,6 +25,8 @@
 import android.text.TextUtils;
 import android.util.Slog;
 
+import com.android.internal.inputmethod.InputMethodUtils;
+
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
diff --git a/core/java/android/view/textservice/SuggestionsInfo.java b/core/java/android/view/textservice/SuggestionsInfo.java
index 78bc1a9..dc2051c 100644
--- a/core/java/android/view/textservice/SuggestionsInfo.java
+++ b/core/java/android/view/textservice/SuggestionsInfo.java
@@ -16,11 +16,11 @@
 
 package android.view.textservice;
 
-import com.android.internal.util.ArrayUtils;
-
 import android.os.Parcel;
 import android.os.Parcelable;
 
+import com.android.internal.util.ArrayUtils;
+
 /**
  * This class contains a metadata of suggestions from the text service
  */
diff --git a/core/java/android/webkit/IWebViewUpdateService.aidl b/core/java/android/webkit/IWebViewUpdateService.aidl
index 9434f0c..894f080 100644
--- a/core/java/android/webkit/IWebViewUpdateService.aidl
+++ b/core/java/android/webkit/IWebViewUpdateService.aidl
@@ -64,6 +64,11 @@
     String getCurrentWebViewPackageName();
 
     /**
+     * Used by public API for debugging purposes.
+     */
+    PackageInfo getCurrentWebViewPackage();
+
+    /**
      * Used by Settings to determine whether a certain package can be enabled/disabled by the user -
      * the package should not be modifiable in this way if it is a fallback package.
      */
diff --git a/core/java/android/webkit/WebView.java b/core/java/android/webkit/WebView.java
index 8c725cf..939f45f 100644
--- a/core/java/android/webkit/WebView.java
+++ b/core/java/android/webkit/WebView.java
@@ -21,6 +21,7 @@
 import android.annotation.Widget;
 import android.content.Context;
 import android.content.Intent;
+import android.content.pm.PackageInfo;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
@@ -36,6 +37,7 @@
 import android.os.Looper;
 import android.os.Message;
 import android.os.StrictMode;
+import android.os.RemoteException;
 import android.print.PrintDocumentAdapter;
 import android.security.KeyChain;
 import android.util.AttributeSet;
@@ -2674,6 +2676,26 @@
     }
 
     /**
+     * If WebView has already been loaded into the current process this method will return the
+     * package that was used to load it. Otherwise, the package that would be used if the WebView
+     * was loaded right now will be returned; this does not cause WebView to be loaded, so this
+     * information may become outdated at any time.
+     * @return the current WebView package, or null if there is none.
+     */
+    public static PackageInfo getCurrentWebViewPackage() {
+        PackageInfo webviewPackage = WebViewFactory.getLoadedPackageInfo();
+        if (webviewPackage != null) {
+            return webviewPackage;
+        }
+
+        try {
+            return WebViewFactory.getUpdateService().getCurrentWebViewPackage();
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
      * Receive the result from a previous call to {@link #startActivityForResult(Intent, int)}.
      *
      * @param requestCode The integer request code originally supplied to
diff --git a/core/java/android/webkit/WebViewFactory.java b/core/java/android/webkit/WebViewFactory.java
index 4bfc718..884a86c 100644
--- a/core/java/android/webkit/WebViewFactory.java
+++ b/core/java/android/webkit/WebViewFactory.java
@@ -135,7 +135,9 @@
     }
 
     public static PackageInfo getLoadedPackageInfo() {
-        return sPackageInfo;
+        synchronized (sProviderLock) {
+            return sPackageInfo;
+        }
     }
 
     /**
@@ -170,9 +172,8 @@
             Log.e(LOGTAG, "Couldn't find package " + packageName);
             return LIBLOAD_WRONG_PACKAGE_NAME;
         }
-        sPackageInfo = packageInfo;
 
-        int loadNativeRet = loadNativeLibrary(clazzLoader);
+        int loadNativeRet = loadNativeLibrary(clazzLoader, packageInfo);
         // If we failed waiting for relro we want to return that fact even if we successfully load
         // the relro file.
         if (loadNativeRet == LIBLOAD_SUCCESS) return response.status;
@@ -358,7 +359,7 @@
                 ClassLoader clazzLoader = webViewContext.getClassLoader();
 
                 Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "WebViewFactory.loadNativeLibrary()");
-                loadNativeLibrary(clazzLoader);
+                loadNativeLibrary(clazzLoader, sPackageInfo);
                 Trace.traceEnd(Trace.TRACE_TAG_WEBVIEW);
 
                 Trace.traceBegin(Trace.TRACE_TAG_WEBVIEW, "Class.forName()");
@@ -637,14 +638,14 @@
         }
     }
 
-    // Assumes that we have waited for relro creation and set sPackageInfo
-    private static int loadNativeLibrary(ClassLoader clazzLoader) {
+    // Assumes that we have waited for relro creation
+    private static int loadNativeLibrary(ClassLoader clazzLoader, PackageInfo packageInfo) {
         if (!sAddressSpaceReserved) {
             Log.e(LOGTAG, "can't load with relro file; address space not reserved");
             return LIBLOAD_ADDRESS_SPACE_NOT_RESERVED;
         }
 
-        String[] args = getWebViewNativeLibraryPaths(sPackageInfo);
+        String[] args = getWebViewNativeLibraryPaths(packageInfo);
         int result = nativeLoadWithRelroFile(args[0] /* path32 */,
                                              args[1] /* path64 */,
                                              CHROMIUM_WEBVIEW_NATIVE_RELRO_32,
diff --git a/core/java/android/widget/AbsSeekBar.java b/core/java/android/widget/AbsSeekBar.java
index 01a95a4..5d136dc 100644
--- a/core/java/android/widget/AbsSeekBar.java
+++ b/core/java/android/widget/AbsSeekBar.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
@@ -36,6 +34,8 @@
 import android.view.ViewConfiguration;
 import android.view.accessibility.AccessibilityNodeInfo;
 
+import com.android.internal.R;
+
 
 /**
  * AbsSeekBar extends the capabilities of ProgressBar by adding a draggable thumb.
@@ -469,7 +469,7 @@
     /**
      * Returns the amount of progress changed via the arrow keys.
      * <p>
-     * By default, this will be a value that is derived from the max progress.
+     * By default, this will be a value that is derived from the progress range.
      *
      * @return The amount to increment or decrement when the user presses the
      *         arrow keys. This will be positive.
@@ -479,13 +479,27 @@
     }
 
     @Override
-    public synchronized void setMax(int max) {
-        super.setMax(max);
+    public synchronized void setMin(int min) {
+        super.setMin(min);
+        int range = getMax() - getMin();
 
-        if ((mKeyProgressIncrement == 0) || (getMax() / mKeyProgressIncrement > 20)) {
+        if ((mKeyProgressIncrement == 0) || (range / mKeyProgressIncrement > 20)) {
+
             // It will take the user too long to change this via keys, change it
             // to something more reasonable
-            setKeyProgressIncrement(Math.max(1, Math.round((float) getMax() / 20)));
+            setKeyProgressIncrement(Math.max(1, Math.round((float) range / 20)));
+        }
+    }
+
+    @Override
+    public synchronized void setMax(int max) {
+        super.setMax(max);
+        int range = getMax() - getMin();
+
+        if ((mKeyProgressIncrement == 0) || (range / mKeyProgressIncrement > 20)) {
+            // It will take the user too long to change this via keys, change it
+            // to something more reasonable
+            setKeyProgressIncrement(Math.max(1, Math.round((float) range / 20)));
         }
     }
 
@@ -596,8 +610,10 @@
     }
 
     private float getScale() {
-        final int max = getMax();
-        return max > 0 ? getProgress() / (float) max : 0;
+        int min = getMin();
+        int max = getMax();
+        int range = max - min;
+        return range > 0 ? (getProgress() - min) / (float) range : 0;
     }
 
     /**
@@ -691,7 +707,7 @@
      */
     void drawTickMarks(Canvas canvas) {
         if (mTickMark != null) {
-            final int count = getMax();
+            final int count = getMax() - getMin();
             if (count > 1) {
                 final int w = mTickMark.getIntrinsicWidth();
                 final int h = mTickMark.getIntrinsicHeight();
@@ -847,8 +863,8 @@
             }
         }
 
-        final int max = getMax();
-        progress += scale * max;
+        final int range = getMax() - getMin();
+        progress += scale * range;
 
         setHotspot(x, y);
         setProgressInternal(Math.round(progress), true, false);
@@ -922,7 +938,7 @@
 
         if (isEnabled()) {
             final int progress = getProgress();
-            if (progress > 0) {
+            if (progress > getMin()) {
                 info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
             }
             if (progress < getMax()) {
@@ -960,7 +976,8 @@
                 if (!canUserSetProgress()) {
                     return false;
                 }
-                int increment = Math.max(1, Math.round((float) getMax() / 20));
+                int range = getMax() - getMin();
+                int increment = Math.max(1, Math.round((float) range / 20));
                 if (action == AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD) {
                     increment = -increment;
                 }
diff --git a/core/java/android/widget/AbsSpinner.java b/core/java/android/widget/AbsSpinner.java
index 18db54e..bc3dfff 100644
--- a/core/java/android/widget/AbsSpinner.java
+++ b/core/java/android/widget/AbsSpinner.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.database.DataSetObserver;
@@ -29,10 +27,12 @@
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.android.internal.R;
+
 /**
  * An abstract base class for spinner widgets. SDK users will probably not
  * need to use this class.
- * 
+ *
  * @attr ref android.R.styleable#AbsSpinner_entries
  */
 public abstract class AbsSpinner extends AdapterView<SpinnerAdapter> {
@@ -104,12 +104,12 @@
             mAdapter.unregisterDataSetObserver(mDataSetObserver);
             resetList();
         }
-        
+
         mAdapter = adapter;
-        
+
         mOldSelectedPosition = INVALID_POSITION;
         mOldSelectedRowId = INVALID_ROW_ID;
-        
+
         if (mAdapter != null) {
             mOldItemCount = mItemCount;
             mItemCount = mAdapter.getCount();
@@ -122,14 +122,14 @@
 
             setSelectedPositionInt(position);
             setNextSelectedPositionInt(position);
-            
+
             if (mItemCount == 0) {
                 // Nothing selected
                 checkSelectionChanged();
             }
-            
+
         } else {
-            checkFocus();            
+            checkFocus();
             resetList();
             // Nothing selected
             checkSelectionChanged();
@@ -144,23 +144,23 @@
     void resetList() {
         mDataChanged = false;
         mNeedSync = false;
-        
+
         removeAllViewsInLayout();
         mOldSelectedPosition = INVALID_POSITION;
         mOldSelectedRowId = INVALID_ROW_ID;
-        
+
         setSelectedPositionInt(INVALID_POSITION);
         setNextSelectedPositionInt(INVALID_POSITION);
         invalidate();
     }
 
-    /** 
+    /**
      * @see android.view.View#measure(int, int)
-     * 
+     *
      * Figure out the dimensions of this Spinner. The width comes from
      * the widthMeasureSpec as Spinnners can't have their width set to
      * UNSPECIFIED. The height is based on the height of the selected item
-     * plus padding. 
+     * plus padding.
      */
     @Override
     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
@@ -180,11 +180,11 @@
         if (mDataChanged) {
             handleDataChanged();
         }
-        
+
         int preferredHeight = 0;
         int preferredWidth = 0;
         boolean needsMeasuring = true;
-        
+
         int selectedPosition = getSelectedItemPosition();
         if (selectedPosition >= 0 && mAdapter != null && selectedPosition < mAdapter.getCount()) {
             // Try looking in the recycler. (Maybe we were measured once already)
@@ -208,14 +208,14 @@
                     mBlockLayoutRequests = false;
                 }
                 measureChild(view, widthMeasureSpec, heightMeasureSpec);
-                
+
                 preferredHeight = getChildHeight(view) + mSpinnerPadding.top + mSpinnerPadding.bottom;
                 preferredWidth = getChildWidth(view) + mSpinnerPadding.left + mSpinnerPadding.right;
-                
+
                 needsMeasuring = false;
             }
         }
-        
+
         if (needsMeasuring) {
             // No views -- just use padding
             preferredHeight = mSpinnerPadding.top + mSpinnerPadding.bottom;
@@ -238,18 +238,18 @@
     int getChildHeight(View child) {
         return child.getMeasuredHeight();
     }
-    
+
     int getChildWidth(View child) {
         return child.getMeasuredWidth();
     }
-    
+
     @Override
     protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
         return new ViewGroup.LayoutParams(
                 ViewGroup.LayoutParams.MATCH_PARENT,
                 ViewGroup.LayoutParams.WRAP_CONTENT);
     }
-    
+
     void recycleAllViews() {
         final int childCount = getChildCount();
         final AbsSpinner.RecycleBin recycleBin = mRecycler;
@@ -260,7 +260,7 @@
             View v = getChildAt(i);
             int index = position + i;
             recycleBin.put(index, v);
-        }  
+        }
     }
 
     /**
@@ -279,14 +279,14 @@
         requestLayout();
         invalidate();
     }
-    
+
 
     /**
      * Makes the item at the supplied position selected.
-     * 
+     *
      * @param position Position to select
      * @param animate Should the transition be animated
-     * 
+     *
      */
     void setSelectionInt(int position, boolean animate) {
         if (position != mOldSelectedPosition) {
@@ -308,11 +308,11 @@
             return null;
         }
     }
-   
+
     /**
      * Override to prevent spamming ourselves with layout requests
      * as we place views
-     * 
+     *
      * @see android.view.View#requestLayout()
      */
     @Override
@@ -334,7 +334,7 @@
 
     /**
      * Maps a point to a position in the list.
-     * 
+     *
      * @param x X in local coordinate
      * @param y Y in local coordinate
      * @return The position of the item which contains the specified point, or
@@ -378,7 +378,7 @@
         SavedState(Parcelable superState) {
             super(superState);
         }
-        
+
         /**
          * Constructor called from {@link #CREATOR}
          */
@@ -431,7 +431,7 @@
     @Override
     public void onRestoreInstanceState(Parcelable state) {
         SavedState ss = (SavedState) state;
-  
+
         super.onRestoreInstanceState(ss.getSuperState());
 
         if (ss.selectedId >= 0) {
@@ -450,7 +450,7 @@
         public void put(int position, View v) {
             mScrapHeap.put(position, v);
         }
-        
+
         View get(int position) {
             // System.out.print("Looking for " + position);
             View result = mScrapHeap.get(position);
diff --git a/core/java/android/widget/ActionMenuPresenter.java b/core/java/android/widget/ActionMenuPresenter.java
index ac8d578..46269c6 100644
--- a/core/java/android/widget/ActionMenuPresenter.java
+++ b/core/java/android/widget/ActionMenuPresenter.java
@@ -39,6 +39,7 @@
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
 import android.view.accessibility.AccessibilityNodeInfo;
+
 import com.android.internal.view.ActionBarPolicy;
 import com.android.internal.view.menu.ActionMenuItemView;
 import com.android.internal.view.menu.BaseMenuPresenter;
diff --git a/core/java/android/widget/ActionMenuView.java b/core/java/android/widget/ActionMenuView.java
index 4d0a1c8..c4bbdb0 100644
--- a/core/java/android/widget/ActionMenuView.java
+++ b/core/java/android/widget/ActionMenuView.java
@@ -31,6 +31,7 @@
 import android.view.ViewGroup;
 import android.view.ViewHierarchyEncoder;
 import android.view.accessibility.AccessibilityEvent;
+
 import com.android.internal.view.menu.ActionMenuItemView;
 import com.android.internal.view.menu.MenuBuilder;
 import com.android.internal.view.menu.MenuItemImpl;
@@ -45,7 +46,7 @@
  */
 public class ActionMenuView extends LinearLayout implements MenuBuilder.ItemInvoker, MenuView {
     private static final String TAG = "ActionMenuView";
-    
+
     static final int MIN_CELL_SIZE = 56; // dips
     static final int GENERATED_ITEM_PADDING = 4; // dips
 
@@ -71,7 +72,7 @@
     public ActionMenuView(Context context) {
         this(context, null);
     }
-    
+
     public ActionMenuView(Context context, AttributeSet attrs) {
         super(context, attrs);
         setBaselineAligned(false);
@@ -579,7 +580,7 @@
         params.gravity = Gravity.CENTER_VERTICAL;
         return params;
     }
-    
+
     @Override
     public LayoutParams generateLayoutParams(AttributeSet attrs) {
         return new LayoutParams(getContext(), attrs);
diff --git a/core/java/android/widget/ActivityChooserView.java b/core/java/android/widget/ActivityChooserView.java
index f5c46db..51587a7 100644
--- a/core/java/android/widget/ActivityChooserView.java
+++ b/core/java/android/widget/ActivityChooserView.java
@@ -16,9 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-import com.android.internal.view.menu.ShowableListMenu;
-
 import android.annotation.StringRes;
 import android.content.Context;
 import android.content.Intent;
@@ -39,6 +36,9 @@
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.widget.ActivityChooserModel.ActivityChooserModelClient;
 
+import com.android.internal.R;
+import com.android.internal.view.menu.ShowableListMenu;
+
 /**
  * This class is a view for choosing an activity for handling a given {@link Intent}.
  * <p>
diff --git a/core/java/android/widget/AnalogClock.java b/core/java/android/widget/AnalogClock.java
index 7f5e2133..bde5f7f 100644
--- a/core/java/android/widget/AnalogClock.java
+++ b/core/java/android/widget/AnalogClock.java
@@ -16,15 +16,14 @@
 
 package android.widget;
 
+import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.BroadcastReceiver;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
 import android.graphics.drawable.Drawable;
-import android.os.Handler;
 import android.text.format.DateUtils;
 import android.text.format.Time;
 import android.util.AttributeSet;
@@ -258,7 +257,7 @@
             }
 
             onTimeChanged();
-            
+
             invalidate();
         }
     };
diff --git a/core/java/android/widget/AppSecurityPermissions.java b/core/java/android/widget/AppSecurityPermissions.java
index 1a1680a..68e6809 100644
--- a/core/java/android/widget/AppSecurityPermissions.java
+++ b/core/java/android/widget/AppSecurityPermissions.java
@@ -16,10 +16,6 @@
 */
 package android.widget;
 
-import android.annotation.SystemApi;
-import android.os.UserHandle;
-import com.android.internal.R;
-
 import android.app.AlertDialog;
 import android.content.Context;
 import android.content.DialogInterface;
@@ -31,6 +27,7 @@
 import android.content.pm.PermissionInfo;
 import android.graphics.drawable.Drawable;
 import android.os.Parcel;
+import android.os.UserHandle;
 import android.text.SpannableStringBuilder;
 import android.text.TextUtils;
 import android.util.AttributeSet;
@@ -39,6 +36,8 @@
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.android.internal.R;
+
 import java.text.Collator;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -57,7 +56,7 @@
  * extended information consisting of all groups and permissions.
  * To use this view define a LinearLayout or any ViewGroup and add this
  * view by instantiating AppSecurityPermissions and invoking getPermissionsView.
- * 
+ *
  * {@hide}
  */
 public class AppSecurityPermissions {
@@ -324,7 +323,7 @@
         return getPermissionItemViewOld(context, inflater, grpName,
                 description, dangerous, icon);
     }
-    
+
     private void getAllUsedPermissions(int sharedUid, Set<MyPermissionInfo> permSet) {
         String sharedPkgList[] = mPm.getPackagesForUid(sharedUid);
         if(sharedPkgList == null || (sharedPkgList.length == 0)) {
@@ -334,7 +333,7 @@
             getPermissionsForPackage(sharedPkg, permSet);
         }
     }
-    
+
     private void getPermissionsForPackage(String packageName, Set<MyPermissionInfo> permSet) {
         try {
             PackageInfo pkgInfo = mPm.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS);
@@ -417,7 +416,7 @@
             }
         }
     }
-    
+
     public int getPermissionCount() {
         return getPermissionCount(WHICH_ALL);
     }
@@ -570,7 +569,7 @@
         }
         return false;
     }
-    
+
     private static class PermissionGroupInfoComparator implements Comparator<MyPermissionGroupInfo> {
         private final Collator sCollator = Collator.getInstance();
         @Override
@@ -578,7 +577,7 @@
             return sCollator.compare(a.mLabel, b.mLabel);
         }
     }
-    
+
     private static class PermissionInfoComparator implements Comparator<MyPermissionInfo> {
         private final Collator sCollator = Collator.getInstance();
         PermissionInfoComparator() {
diff --git a/core/java/android/widget/AutoCompleteTextView.java b/core/java/android/widget/AutoCompleteTextView.java
index 6a4e36a..49741d4 100644
--- a/core/java/android/widget/AutoCompleteTextView.java
+++ b/core/java/android/widget/AutoCompleteTextView.java
@@ -39,7 +39,9 @@
 import android.view.inputmethod.CompletionInfo;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
+
 import com.android.internal.R;
+
 import java.lang.ref.WeakReference;
 
 /**
@@ -362,22 +364,22 @@
      * <p>Returns the current width for the auto-complete drop down list. This can
      * be a fixed width, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill the screen, or
      * {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the width of its anchor view.</p>
-     * 
+     *
      * @return the width for the drop down list
-     * 
+     *
      * @attr ref android.R.styleable#AutoCompleteTextView_dropDownWidth
      */
     public int getDropDownWidth() {
         return mPopup.getWidth();
     }
-    
+
     /**
      * <p>Sets the current width for the auto-complete drop down list. This can
      * be a fixed width, or {@link ViewGroup.LayoutParams#MATCH_PARENT} to fill the screen, or
      * {@link ViewGroup.LayoutParams#WRAP_CONTENT} to fit the width of its anchor view.</p>
-     * 
+     *
      * @param width the width to use
-     * 
+     *
      * @attr ref android.R.styleable#AutoCompleteTextView_dropDownWidth
      */
     public void setDropDownWidth(int width) {
@@ -411,68 +413,68 @@
     public void setDropDownHeight(int height) {
         mPopup.setHeight(height);
     }
-    
+
     /**
      * <p>Returns the id for the view that the auto-complete drop down list is anchored to.</p>
-     *  
+     *
      * @return the view's id, or {@link View#NO_ID} if none specified
-     * 
+     *
      * @attr ref android.R.styleable#AutoCompleteTextView_dropDownAnchor
      */
     public int getDropDownAnchor() {
         return mDropDownAnchorId;
     }
-    
+
     /**
      * <p>Sets the view to which the auto-complete drop down list should anchor. The view
      * corresponding to this id will not be loaded until the next time it is needed to avoid
      * loading a view which is not yet instantiated.</p>
-     * 
+     *
      * @param id the id to anchor the drop down list view to
-     * 
-     * @attr ref android.R.styleable#AutoCompleteTextView_dropDownAnchor 
+     *
+     * @attr ref android.R.styleable#AutoCompleteTextView_dropDownAnchor
      */
     public void setDropDownAnchor(int id) {
         mDropDownAnchorId = id;
         mPopup.setAnchorView(null);
     }
-    
+
     /**
      * <p>Gets the background of the auto-complete drop-down list.</p>
-     * 
+     *
      * @return the background drawable
-     * 
+     *
      * @attr ref android.R.styleable#PopupWindow_popupBackground
      */
     public Drawable getDropDownBackground() {
         return mPopup.getBackground();
     }
-    
+
     /**
      * <p>Sets the background of the auto-complete drop-down list.</p>
-     * 
+     *
      * @param d the drawable to set as the background
-     * 
+     *
      * @attr ref android.R.styleable#PopupWindow_popupBackground
      */
     public void setDropDownBackgroundDrawable(Drawable d) {
         mPopup.setBackgroundDrawable(d);
     }
-    
+
     /**
      * <p>Sets the background of the auto-complete drop-down list.</p>
-     * 
+     *
      * @param id the id of the drawable to set as the background
-     * 
+     *
      * @attr ref android.R.styleable#PopupWindow_popupBackground
      */
     public void setDropDownBackgroundResource(@DrawableRes int id) {
         mPopup.setBackgroundDrawable(getContext().getDrawable(id));
     }
-    
+
     /**
      * <p>Sets the vertical offset used for the auto-complete drop-down list.</p>
-     * 
+     *
      * @param offset the vertical offset
      *
      * @attr ref android.R.styleable#ListPopupWindow_dropDownVerticalOffset
@@ -480,10 +482,10 @@
     public void setDropDownVerticalOffset(int offset) {
         mPopup.setVerticalOffset(offset);
     }
-    
+
     /**
      * <p>Gets the vertical offset used for the auto-complete drop-down list.</p>
-     * 
+     *
      * @return the vertical offset
      *
      * @attr ref android.R.styleable#ListPopupWindow_dropDownVerticalOffset
@@ -491,10 +493,10 @@
     public int getDropDownVerticalOffset() {
         return mPopup.getVerticalOffset();
     }
-    
+
     /**
      * <p>Sets the horizontal offset used for the auto-complete drop-down list.</p>
-     * 
+     *
      * @param offset the horizontal offset
      *
      * @attr ref android.R.styleable#ListPopupWindow_dropDownHorizontalOffset
@@ -502,10 +504,10 @@
     public void setDropDownHorizontalOffset(int offset) {
         mPopup.setHorizontalOffset(offset);
     }
-    
+
     /**
      * <p>Gets the horizontal offset used for the auto-complete drop-down list.</p>
-     * 
+     *
      * @return the horizontal offset
      *
      * @attr ref android.R.styleable#ListPopupWindow_dropDownHorizontalOffset
@@ -567,10 +569,10 @@
     public void setDropDownAlwaysVisible(boolean dropDownAlwaysVisible) {
         mPopup.setDropDownAlwaysVisible(dropDownAlwaysVisible);
     }
-   
+
     /**
      * Checks whether the drop-down is dismissed when a suggestion is clicked.
-     * 
+     *
      * @hide Pending API council approval
      */
     public boolean isDropDownDismissedOnCompletion() {
@@ -578,17 +580,17 @@
     }
 
     /**
-     * Sets whether the drop-down is dismissed when a suggestion is clicked. This is 
+     * Sets whether the drop-down is dismissed when a suggestion is clicked. This is
      * true by default.
-     * 
+     *
      * @param dropDownDismissedOnCompletion Whether to dismiss the drop-down.
-     * 
+     *
      * @hide Pending API council approval
      */
     public void setDropDownDismissedOnCompletion(boolean dropDownDismissedOnCompletion) {
         mDropDownDismissedOnCompletion = dropDownDismissedOnCompletion;
     }
- 
+
     /**
      * <p>Returns the number of characters the user must type before the drop
      * down list is shown.</p>
@@ -720,13 +722,13 @@
     /**
      * <p>Changes the list of data used for auto completion. The provided list
      * must be a filterable list adapter.</p>
-     * 
+     *
      * <p>The caller is still responsible for managing any resources used by the adapter.
      * Notably, when the AutoCompleteTextView is closed or released, the adapter is not notified.
      * A common case is the use of {@link android.widget.CursorAdapter}, which
      * contains a {@link android.database.Cursor} that must be closed.  This can be done
-     * automatically (see 
-     * {@link android.app.Activity#startManagingCursor(android.database.Cursor) 
+     * automatically (see
+     * {@link android.app.Activity#startManagingCursor(android.database.Cursor)
      * startManagingCursor()}),
      * or by manually closing the cursor when the AutoCompleteTextView is dismissed.</p>
      *
@@ -811,7 +813,7 @@
         if (mPopup.onKeyDown(keyCode, event)) {
             return true;
         }
-        
+
         if (!isPopupShowing()) {
             switch(keyCode) {
             case KeyEvent.KEYCODE_DPAD_DOWN:
@@ -924,18 +926,18 @@
     protected CharSequence convertSelectionToString(Object selectedItem) {
         return mFilter.convertResultToString(selectedItem);
     }
-    
+
     /**
-     * <p>Clear the list selection.  This may only be temporary, as user input will often bring 
+     * <p>Clear the list selection.  This may only be temporary, as user input will often bring
      * it back.
      */
     public void clearListSelection() {
         mPopup.clearListSelection();
     }
-    
+
     /**
      * Set the position of the dropdown view selection.
-     * 
+     *
      * @param position The position to move the selector to.
      */
     public void setListSelection(int position) {
@@ -943,13 +945,13 @@
     }
 
     /**
-     * Get the position of the dropdown view selection, if there is one.  Returns 
+     * Get the position of the dropdown view selection, if there is one.  Returns
      * {@link ListView#INVALID_POSITION ListView.INVALID_POSITION} if there is no dropdown or if
      * there is no selection.
-     * 
-     * @return the position of the current selection, if there is one, or 
+     *
+     * @return the position of the current selection, if there is one, or
      * {@link ListView#INVALID_POSITION ListView.INVALID_POSITION} if not.
-     * 
+     *
      * @see ListView#getSelectedItemPosition()
      */
     public int getListSelection() {
@@ -1020,7 +1022,7 @@
             dismissDropDown();
         }
     }
-    
+
     /**
      * Identifies whether the view is currently performing a text completion, so subclasses
      * can decide whether to respond to text changed events.
@@ -1172,7 +1174,7 @@
     public void showDropDownAfterLayout() {
         mPopup.postShow();
     }
-    
+
     /**
      * Ensures that the drop down is not obscuring the IME.
      * @param visible whether the ime should be in front. If false, the ime is pushed to
@@ -1220,7 +1222,7 @@
      * Forces outside touches to be ignored. Normally if {@link #isDropDownAlwaysVisible()} is
      * false, we allow outside touch to dismiss the dropdown. If this is set to true, then we
      * ignore outside touch even when the drop down is not set to always visible.
-     * 
+     *
      * @hide used only by SearchDialog
      */
     public void setForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch) {
@@ -1245,7 +1247,7 @@
                         realCount++;
                     }
                 }
-                
+
                 if (realCount != count) {
                     CompletionInfo[] tmp = new CompletionInfo[realCount];
                     System.arraycopy(completions, 0, tmp, 0, realCount);
@@ -1340,7 +1342,7 @@
          */
         CharSequence fixText(CharSequence invalidText);
     }
-    
+
     /**
      * Listener to respond to the AutoCompleteTextView's completion list being dismissed.
      * @see AutoCompleteTextView#setOnDismissListener(OnDismissListener)
diff --git a/core/java/android/widget/CalendarView.java b/core/java/android/widget/CalendarView.java
index 6ef1576..db50e34 100644
--- a/core/java/android/widget/CalendarView.java
+++ b/core/java/android/widget/CalendarView.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.AttrRes;
 import android.annotation.ColorInt;
 import android.annotation.DrawableRes;
@@ -36,6 +34,8 @@
 import android.util.AttributeSet;
 import android.util.Log;
 
+import com.android.internal.R;
+
 import java.text.DateFormat;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
diff --git a/core/java/android/widget/CalendarViewLegacyDelegate.java b/core/java/android/widget/CalendarViewLegacyDelegate.java
index bcda83f..557d411 100644
--- a/core/java/android/widget/CalendarViewLegacyDelegate.java
+++ b/core/java/android/widget/CalendarViewLegacyDelegate.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.app.Service;
 import android.content.Context;
 import android.content.res.Configuration;
@@ -38,10 +36,12 @@
 import android.view.View;
 import android.view.ViewGroup;
 
-import java.util.Locale;
+import com.android.internal.R;
 
 import libcore.icu.LocaleData;
 
+import java.util.Locale;
+
 /**
  * A delegate implementing the legacy CalendarView
  */
diff --git a/core/java/android/widget/CheckBox.java b/core/java/android/widget/CheckBox.java
index 15bbdd2..046f75f 100644
--- a/core/java/android/widget/CheckBox.java
+++ b/core/java/android/widget/CheckBox.java
@@ -19,7 +19,6 @@
 import android.content.Context;
 import android.util.AttributeSet;
 
-
 /**
  * <p>
  * A checkbox is a specific type of two-states button that can be either
@@ -44,12 +43,12 @@
  *
  * <p>See the <a href="{@docRoot}guide/topics/ui/controls/checkbox.html">Checkboxes</a>
  * guide.</p>
- *  
- * <p><strong>XML attributes</strong></p> 
+ *
+ * <p><strong>XML attributes</strong></p>
  * <p>
- * See {@link android.R.styleable#CompoundButton CompoundButton Attributes}, 
- * {@link android.R.styleable#Button Button Attributes}, 
- * {@link android.R.styleable#TextView TextView Attributes}, 
+ * See {@link android.R.styleable#CompoundButton CompoundButton Attributes},
+ * {@link android.R.styleable#Button Button Attributes},
+ * {@link android.R.styleable#TextView TextView Attributes},
  * {@link android.R.styleable#View View Attributes}
  * </p>
  */
@@ -57,7 +56,7 @@
     public CheckBox(Context context) {
         this(context, null);
     }
-    
+
     public CheckBox(Context context, AttributeSet attrs) {
         this(context, attrs, com.android.internal.R.attr.checkboxStyle);
     }
diff --git a/core/java/android/widget/CheckedTextView.java b/core/java/android/widget/CheckedTextView.java
index 21595d15..92bfd56 100644
--- a/core/java/android/widget/CheckedTextView.java
+++ b/core/java/android/widget/CheckedTextView.java
@@ -16,11 +16,8 @@
 
 package android.widget;
 
-import android.annotation.NonNull;
-import android.view.ViewHierarchyEncoder;
-import com.android.internal.R;
-
 import android.annotation.DrawableRes;
+import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.ColorStateList;
@@ -34,9 +31,12 @@
 import android.view.Gravity;
 import android.view.RemotableViewMethod;
 import android.view.ViewDebug;
+import android.view.ViewHierarchyEncoder;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
 
+import com.android.internal.R;
+
 /**
  * An extension to {@link TextView} that supports the {@link Checkable}
  * interface and displays.
@@ -394,7 +394,7 @@
                     y = (getHeight() - height) / 2;
                     break;
             }
-            
+
             final boolean checkMarkAtStart = isCheckMarkAtStart();
             final int width = getWidth();
             final int top = y;
@@ -417,7 +417,7 @@
             }
         }
     }
-    
+
     @Override
     protected int[] onCreateDrawableState(int extraSpace) {
         final int[] drawableState = super.onCreateDrawableState(extraSpace + 1);
diff --git a/core/java/android/widget/Chronometer.java b/core/java/android/widget/Chronometer.java
index adcb012..b9224f3 100644
--- a/core/java/android/widget/Chronometer.java
+++ b/core/java/android/widget/Chronometer.java
@@ -24,7 +24,6 @@
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.View;
-import android.view.accessibility.AccessibilityEvent;
 import android.widget.RemoteViews.RemoteView;
 
 import com.android.internal.R;
@@ -80,7 +79,7 @@
     private OnChronometerTickListener mOnChronometerTickListener;
     private StringBuilder mRecycle = new StringBuilder(8);
     private boolean mCountDown;
-    
+
     /**
      * Initialize this Chronometer object.
      * Sets the base to the current time.
@@ -191,7 +190,7 @@
 
     /**
      * Sets the listener to be called when the chronometer changes.
-     * 
+     *
      * @param listener The listener.
      */
     public void setOnChronometerTickListener(OnChronometerTickListener listener) {
@@ -209,10 +208,10 @@
     /**
      * Start counting up.  This does not affect the base as set from {@link #setBase}, just
      * the view display.
-     * 
-     * Chronometer works by regularly scheduling messages to the handler, even when the 
-     * Widget is not visible.  To make sure resource leaks do not occur, the user should 
-     * make sure that each start() call has a reciprocal call to {@link #stop}. 
+     *
+     * Chronometer works by regularly scheduling messages to the handler, even when the
+     * Widget is not visible.  To make sure resource leaks do not occur, the user should
+     * make sure that each start() call has a reciprocal call to {@link #stop}.
      */
     public void start() {
         mStarted = true;
@@ -222,9 +221,9 @@
     /**
      * Stop counting up.  This does not affect the base as set from {@link #setBase}, just
      * the view display.
-     * 
+     *
      * This stops the messages to the handler, effectively releasing resources that would
-     * be held as the chronometer is running, via {@link #start}. 
+     * be held as the chronometer is running, via {@link #start}.
      */
     public void stop() {
         mStarted = false;
diff --git a/core/java/android/widget/CompoundButton.java b/core/java/android/widget/CompoundButton.java
index 0357834..dd63fef 100644
--- a/core/java/android/widget/CompoundButton.java
+++ b/core/java/android/widget/CompoundButton.java
@@ -19,14 +19,11 @@
 import android.annotation.DrawableRes;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.graphics.PorterDuff;
-import android.view.ViewHierarchyEncoder;
-import com.android.internal.R;
-
 import android.content.Context;
 import android.content.res.ColorStateList;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
+import android.graphics.PorterDuff;
 import android.graphics.drawable.Drawable;
 import android.os.Parcel;
 import android.os.Parcelable;
@@ -34,9 +31,12 @@
 import android.view.Gravity;
 import android.view.SoundEffectConstants;
 import android.view.ViewDebug;
+import android.view.ViewHierarchyEncoder;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
 
+import com.android.internal.R;
+
 /**
  * <p>
  * A button with two states, checked and unchecked. When the button is pressed
@@ -159,7 +159,7 @@
                 mOnCheckedChangeWidgetListener.onCheckedChanged(this, mChecked);
             }
 
-            mBroadcasting = false;            
+            mBroadcasting = false;
         }
     }
 
@@ -492,7 +492,7 @@
         SavedState(Parcelable superState) {
             super(superState);
         }
-        
+
         /**
          * Constructor called from {@link #CREATOR}
          */
diff --git a/core/java/android/widget/DatePicker.java b/core/java/android/widget/DatePicker.java
index 80f25d4..517e20cd 100644
--- a/core/java/android/widget/DatePicker.java
+++ b/core/java/android/widget/DatePicker.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.IntDef;
 import android.annotation.Nullable;
 import android.annotation.TestApi;
@@ -35,6 +33,8 @@
 import android.view.View;
 import android.view.accessibility.AccessibilityEvent;
 
+import com.android.internal.R;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.Locale;
diff --git a/core/java/android/widget/DatePickerCalendarDelegate.java b/core/java/android/widget/DatePickerCalendarDelegate.java
index 1bf0c87..f712685 100755
--- a/core/java/android/widget/DatePickerCalendarDelegate.java
+++ b/core/java/android/widget/DatePickerCalendarDelegate.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.ColorStateList;
@@ -40,6 +38,8 @@
 import android.widget.DayPickerView.OnDaySelectedListener;
 import android.widget.YearPickerView.OnYearSelectedListener;
 
+import com.android.internal.R;
+
 import java.util.Locale;
 
 /**
diff --git a/core/java/android/widget/DatePickerSpinnerDelegate.java b/core/java/android/widget/DatePickerSpinnerDelegate.java
index 9ecf8a5..702b2a5 100644
--- a/core/java/android/widget/DatePickerSpinnerDelegate.java
+++ b/core/java/android/widget/DatePickerSpinnerDelegate.java
@@ -33,14 +33,14 @@
 import android.widget.DatePicker.AbstractDatePickerDelegate;
 import android.widget.NumberPicker.OnValueChangeListener;
 
+import libcore.icu.ICU;
+
 import java.text.DateFormatSymbols;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Arrays;
 import java.util.Locale;
 
-import libcore.icu.ICU;
-
 /**
  * A delegate implementing the basic DatePicker
  */
diff --git a/core/java/android/widget/DayPickerPagerAdapter.java b/core/java/android/widget/DayPickerPagerAdapter.java
index f748d3a..8d5bf8f 100644
--- a/core/java/android/widget/DayPickerPagerAdapter.java
+++ b/core/java/android/widget/DayPickerPagerAdapter.java
@@ -16,9 +16,6 @@
 
 package android.widget;
 
-import android.graphics.Rect;
-import com.android.internal.widget.PagerAdapter;
-
 import android.annotation.IdRes;
 import android.annotation.LayoutRes;
 import android.annotation.NonNull;
@@ -26,6 +23,7 @@
 import android.content.Context;
 import android.content.res.ColorStateList;
 import android.content.res.TypedArray;
+import android.graphics.Rect;
 import android.icu.util.Calendar;
 import android.util.SparseArray;
 import android.view.LayoutInflater;
@@ -33,6 +31,8 @@
 import android.view.ViewGroup;
 import android.widget.SimpleMonthView.OnDayClickListener;
 
+import com.android.internal.widget.PagerAdapter;
+
 /**
  * An adapter for a list of {@link android.widget.SimpleMonthView} items.
  */
diff --git a/core/java/android/widget/DayPickerView.java b/core/java/android/widget/DayPickerView.java
index 0c02a2b..919c1e2 100644
--- a/core/java/android/widget/DayPickerView.java
+++ b/core/java/android/widget/DayPickerView.java
@@ -18,15 +18,11 @@
 
 import static android.os.Build.VERSION_CODES.N_MR1;
 
-import android.graphics.Rect;
-import com.android.internal.R;
-import com.android.internal.widget.ViewPager;
-import com.android.internal.widget.ViewPager.OnPageChangeListener;
-
 import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.ColorStateList;
 import android.content.res.TypedArray;
+import android.graphics.Rect;
 import android.icu.util.Calendar;
 import android.util.AttributeSet;
 import android.util.MathUtils;
@@ -35,10 +31,14 @@
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityManager;
 
-import java.util.Locale;
+import com.android.internal.R;
+import com.android.internal.widget.ViewPager;
+import com.android.internal.widget.ViewPager.OnPageChangeListener;
 
 import libcore.icu.LocaleData;
 
+import java.util.Locale;
+
 class DayPickerView extends ViewGroup {
     private static final int DEFAULT_LAYOUT = R.layout.day_picker_content_material;
     private static final int DEFAULT_START_YEAR = 1900;
diff --git a/core/java/android/widget/DayPickerViewPager.java b/core/java/android/widget/DayPickerViewPager.java
index 5f0ae29..94022ae 100644
--- a/core/java/android/widget/DayPickerViewPager.java
+++ b/core/java/android/widget/DayPickerViewPager.java
@@ -16,17 +16,12 @@
 
 package android.widget;
 
-import android.annotation.Nullable;
 import android.content.Context;
-import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewGroup.LayoutParams;
 
 import com.android.internal.util.Predicate;
-import com.android.internal.widget.PagerAdapter;
 import com.android.internal.widget.ViewPager;
 
 import java.util.ArrayList;
diff --git a/core/java/android/widget/DialerFilter.java b/core/java/android/widget/DialerFilter.java
index e37e3ba7..8f9c96c 100644
--- a/core/java/android/widget/DialerFilter.java
+++ b/core/java/android/widget/DialerFilter.java
@@ -17,7 +17,7 @@
 package android.widget;
 
 import android.content.Context;
-import android.view.KeyEvent;
+import android.graphics.Rect;
 import android.text.Editable;
 import android.text.InputFilter;
 import android.text.Selection;
@@ -28,8 +28,8 @@
 import android.text.method.KeyListener;
 import android.text.method.TextKeyListener;
 import android.util.AttributeSet;
+import android.view.KeyEvent;
 import android.view.View;
-import android.graphics.Rect;
 
 /**
  * This widget is a layout that contains several specifically-named child views that
@@ -169,7 +169,7 @@
                         // Only check to see if the digit is valid if the key is a printing key
                         // in the TextKeyListener. This prevents us from hiding the digits
                         // line when keys like UP and DOWN are hit.
-                        // XXX note that KEYCODE_TAB is special-cased here for 
+                        // XXX note that KEYCODE_TAB is special-cased here for
                         // devices that share tab and 0 on a single key.
                         boolean isPrint = event.isPrintingKey();
                         if (isPrint || keyCode == KeyEvent.KEYCODE_SPACE
diff --git a/core/java/android/widget/DigitalClock.java b/core/java/android/widget/DigitalClock.java
index 1df1643..c503ef2 100644
--- a/core/java/android/widget/DigitalClock.java
+++ b/core/java/android/widget/DigitalClock.java
@@ -23,6 +23,7 @@
 import android.provider.Settings;
 import android.text.format.DateFormat;
 import android.util.AttributeSet;
+
 import java.util.Calendar;
 
 /**
diff --git a/core/java/android/widget/DropDownListView.java b/core/java/android/widget/DropDownListView.java
index 69e4218..e9c4728 100644
--- a/core/java/android/widget/DropDownListView.java
+++ b/core/java/android/widget/DropDownListView.java
@@ -17,13 +17,13 @@
 package android.widget;
 
 
-import com.android.internal.widget.AutoScrollHelper.AbsListViewAutoScroller;
-
 import android.annotation.NonNull;
 import android.content.Context;
 import android.view.MotionEvent;
 import android.view.View;
 
+import com.android.internal.widget.AutoScrollHelper.AbsListViewAutoScroller;
+
 /**
  * Wrapper class for a ListView. This wrapper can hijack the focus to
  * make sure the list uses the appropriate drawables and states when
diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java
index 9019f31..98d8a13 100644
--- a/core/java/android/widget/EdgeEffect.java
+++ b/core/java/android/widget/EdgeEffect.java
@@ -17,14 +17,13 @@
 package android.widget;
 
 import android.annotation.ColorInt;
+import android.content.Context;
 import android.content.res.TypedArray;
+import android.graphics.Canvas;
 import android.graphics.Paint;
 import android.graphics.PorterDuff;
 import android.graphics.PorterDuffXfermode;
 import android.graphics.Rect;
-
-import android.content.Context;
-import android.graphics.Canvas;
 import android.view.animation.AnimationUtils;
 import android.view.animation.DecelerateInterpolator;
 import android.view.animation.Interpolator;
@@ -103,7 +102,7 @@
     private int mState = STATE_IDLE;
 
     private float mPullDistance;
-    
+
     private final Rect mBounds = new Rect();
     private final Paint mPaint = new Paint();
     private float mRadius;
diff --git a/core/java/android/widget/EditText.java b/core/java/android/widget/EditText.java
index 24d8618..a8d3984 100644
--- a/core/java/android/widget/EditText.java
+++ b/core/java/android/widget/EditText.java
@@ -17,7 +17,6 @@
 package android.widget;
 
 import android.content.Context;
-import android.os.Bundle;
 import android.text.Editable;
 import android.text.Selection;
 import android.text.Spannable;
diff --git a/core/java/android/widget/ExpandableListView.java b/core/java/android/widget/ExpandableListView.java
index fac36c5..8d9848d 100644
--- a/core/java/android/widget/ExpandableListView.java
+++ b/core/java/android/widget/ExpandableListView.java
@@ -16,7 +16,7 @@
 
 package android.widget;
 
-import com.android.internal.R;
+import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
 
 import android.content.Context;
 import android.content.res.TypedArray;
@@ -27,14 +27,14 @@
 import android.os.Parcelable;
 import android.util.AttributeSet;
 import android.view.ContextMenu;
+import android.view.ContextMenu.ContextMenuInfo;
 import android.view.SoundEffectConstants;
 import android.view.View;
-import android.view.ContextMenu.ContextMenuInfo;
 import android.widget.ExpandableListConnector.PositionMetadata;
 
-import java.util.ArrayList;
+import com.android.internal.R;
 
-import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
+import java.util.ArrayList;
 
 /**
  * A view that shows items in a vertically scrolling two-level list. This
@@ -68,7 +68,7 @@
  * wrap_content since it also can be any length. However, you can use
  * wrap_content if the ExpandableListView parent has a specific size, such as
  * 100 pixels.
- * 
+ *
  * @attr ref android.R.styleable#ExpandableListView_groupIndicator
  * @attr ref android.R.styleable#ExpandableListView_indicatorLeft
  * @attr ref android.R.styleable#ExpandableListView_indicatorRight
@@ -87,7 +87,7 @@
      * The packed position represents a group.
      */
     public static final int PACKED_POSITION_TYPE_GROUP = 0;
-    
+
     /**
      * The packed position represents a child.
      */
@@ -97,14 +97,14 @@
      * The packed position represents a neither/null/no preference.
      */
     public static final int PACKED_POSITION_TYPE_NULL = 2;
-    
+
     /**
      * The value for a packed position that represents neither/null/no
      * preference. This value is not otherwise possible since a group type
      * (first bit 0) should not have a child position filled.
      */
     public static final long PACKED_POSITION_VALUE_NULL = 0x00000000FFFFFFFFL;
-    
+
     /** The mask (in packed position representation) for the child */
     private static final long PACKED_POSITION_MASK_CHILD = 0x00000000FFFFFFFFL;
 
@@ -125,13 +125,13 @@
 
     /** The mask (in integer group position representation) for the group */
     private static final long PACKED_POSITION_INT_MASK_GROUP = 0x7FFFFFFF;
-    
+
     /** Serves as the glue/translator between a ListView and an ExpandableListView */
     private ExpandableListConnector mConnector;
-    
-    /** Gives us Views through group+child positions */ 
+
+    /** Gives us Views through group+child positions */
     private ExpandableListAdapter mAdapter;
-    
+
     /** Left bound for drawing the indicator. */
     private int mIndicatorLeft;
 
@@ -210,7 +210,7 @@
     /** State indicating the child is the last within its group. */
     private static final int[] CHILD_LAST_STATE_SET =
             {R.attr.state_last};
-    
+
     /** Drawable to be used as a divider when it is adjacent to any children */
     private Drawable mChildDivider;
 
@@ -367,16 +367,16 @@
         }
 
         final int headerViewsCount = getHeaderViewsCount();
-        
+
         final int lastChildFlPos = mItemCount - getFooterViewsCount() - headerViewsCount - 1;
 
-        final int myB = mBottom; 
-        
+        final int myB = mBottom;
+
         PositionMetadata pos;
         View item;
-        Drawable indicator; 
+        Drawable indicator;
         int t, b;
-        
+
         // Start at a value that is neither child nor group
         int lastItemType = ~(ExpandableListPosition.CHILD | ExpandableListPosition.GROUP);
 
@@ -385,7 +385,7 @@
         // The "child" mentioned in the following two lines is this
         // View's child, not referring to an expandable list's
         // notion of a child (as opposed to a group)
-        final int childCount = getChildCount(); 
+        final int childCount = getChildCount();
         for (int i = 0, childFlPos = mFirstPosition - headerViewsCount; i < childCount;
              i++, childFlPos++) {
 
@@ -396,11 +396,11 @@
                 // This child is footer, so are all subsequent children
                 break;
             }
-            
+
             item = getChildAt(i);
             t = item.getTop();
             b = item.getBottom();
-            
+
             // This item isn't on the screen
             if ((b < 0) || (t > myB)) continue;
 
@@ -435,7 +435,7 @@
                     indicatorRect.right += mPaddingLeft;
                 }
 
-                lastItemType = pos.position.type; 
+                lastItemType = pos.position.type;
             }
 
             if (indicatorRect.left != indicatorRect.right) {
@@ -448,7 +448,7 @@
                     indicatorRect.top = t;
                     indicatorRect.bottom = b;// + mDividerHeight;
                 }
-                
+
                 // Get the indicator (with its state set to the item's state)
                 indicator = getIndicator(pos);
                 if (indicator != null) {
@@ -468,24 +468,24 @@
     /**
      * Gets the indicator for the item at the given position. If the indicator
      * is stateful, the state will be given to the indicator.
-     * 
+     *
      * @param pos The flat list position of the item whose indicator
      *            should be returned.
      * @return The indicator in the proper state.
      */
     private Drawable getIndicator(PositionMetadata pos) {
         Drawable indicator;
-        
+
         if (pos.position.type == ExpandableListPosition.GROUP) {
             indicator = mGroupIndicator;
-            
+
             if (indicator != null && indicator.isStateful()) {
                 // Empty check based on availability of data.  If the groupMetadata isn't null,
                 // we do a check on it. Otherwise, the group is collapsed so we consider it
                 // empty for performance reasons.
                 boolean isEmpty = (pos.groupMetadata == null) ||
                         (pos.groupMetadata.lastChildFlPos == pos.groupMetadata.flPos);
-                
+
                 final int stateSetIndex =
                     (pos.isExpanded() ? 1 : 0) | // Expanded?
                     (isEmpty ? 2 : 0); // Empty?
@@ -493,7 +493,7 @@
             }
         } else {
             indicator = mChildIndicator;
-            
+
             if (indicator != null && indicator.isStateful()) {
                 // No need for a state sets array for the child since it only has two states
                 final int stateSet[] = pos.position.flatListPos == pos.groupMetadata.lastChildFlPos
@@ -502,15 +502,15 @@
                 indicator.setState(stateSet);
             }
         }
-        
+
         return indicator;
     }
-    
+
     /**
      * Sets the drawable that will be drawn adjacent to every child in the list. This will
      * be drawn using the same height as the normal divider ({@link #setDivider(Drawable)}) or
      * if it does not have an intrinsic height, the height set by {@link #setDividerHeight(int)}.
-     * 
+     *
      * @param childDivider The drawable to use.
      */
     public void setChildDivider(Drawable childDivider) {
@@ -520,7 +520,7 @@
     @Override
     void drawDivider(Canvas canvas, Rect bounds, int childIndex) {
         int flatListPosition = childIndex + mFirstPosition;
-        
+
         // Only proceed as possible child if the divider isn't above all items (if it is above
         // all items, then the item below it has to be a group)
         if (flatListPosition >= 0) {
@@ -538,7 +538,7 @@
             }
             pos.recycle();
         }
-        
+
         // Otherwise draw the default divider
         super.drawDivider(canvas, bounds, flatListPosition);
     }
@@ -589,18 +589,18 @@
     public void setAdapter(ExpandableListAdapter adapter) {
         // Set member variable
         mAdapter = adapter;
-        
+
         if (adapter != null) {
             // Create the connector
             mConnector = new ExpandableListConnector(adapter);
         } else {
             mConnector = null;
         }
-        
+
         // Link the ListView (superclass) to the expandable list data through the connector
         super.setAdapter(mConnector);
     }
-    
+
     /**
      * Gets the adapter that provides data to this view.
      * @return The adapter that provides data to this view.
@@ -608,7 +608,7 @@
     public ExpandableListAdapter getExpandableListAdapter() {
         return mAdapter;
     }
-    
+
     /**
      * @param position An absolute (including header and footer) flat list position.
      * @return true if the position corresponds to a header or a footer item.
@@ -621,7 +621,7 @@
     /**
      * Converts an absolute item flat position into a group/child flat position, shifting according
      * to the number of header items.
-     * 
+     *
      * @param flatListPosition The absolute flat position
      * @return A group/child flat position as expected by the connector.
      */
@@ -632,7 +632,7 @@
     /**
      * Converts a group/child flat position into an absolute flat position, that takes into account
      * the possible headers.
-     * 
+     *
      * @param flatListPosition The child/group flat position
      * @return An absolute flat position.
      */
@@ -647,25 +647,25 @@
             // Clicked on a header/footer, so ignore pass it on to super
             return super.performItemClick(v, position, id);
         }
-        
+
         // Internally handle the item click
         final int adjustedPosition = getFlatPositionForConnector(position);
         return handleItemClick(v, adjustedPosition, id);
     }
-    
+
     /**
      * This will either expand/collapse groups (if a group was clicked) or pass
      * on the click to the proper child (if a child was clicked)
-     * 
+     *
      * @param position The flat list position. This has already been factored to
      *            remove the header/footer.
      * @param id The ListAdapter ID, not the group or child ID.
      */
     boolean handleItemClick(View v, int position, long id) {
         final PositionMetadata posMetadata = mConnector.getUnflattenedPos(position);
-        
+
         id = getChildOrGroupId(posMetadata.position);
-        
+
         boolean returnValue;
         if (posMetadata.position.type == ExpandableListPosition.GROUP) {
             /* It's a group, so handle collapsing/expanding */
@@ -697,11 +697,11 @@
                 if (mOnGroupExpandListener != null) {
                     mOnGroupExpandListener.onGroupExpand(posMetadata.position.groupPos);
                 }
-                
+
                 final int groupPos = posMetadata.position.groupPos;
                 final int groupFlatPos = posMetadata.position.flatListPos;
 
-                final int shiftedGroupPosition = groupFlatPos + getHeaderViewsCount(); 
+                final int shiftedGroupPosition = groupFlatPos + getHeaderViewsCount();
                 smoothScrollToPosition(shiftedGroupPosition + mAdapter.getChildrenCount(groupPos),
                         shiftedGroupPosition);
             }
@@ -764,17 +764,17 @@
 
         return retValue;
     }
-    
+
     /**
      * Collapse a group in the grouped list view
-     * 
+     *
      * @param groupPos position of the group to collapse
      * @return True if the group was collapsed, false otherwise (if the group
      *         was already collapsed, this will return false)
      */
     public boolean collapseGroup(int groupPos) {
         boolean retValue = mConnector.collapseGroup(groupPos);
-        
+
         if (mOnGroupCollapseListener != null) {
             mOnGroupCollapseListener.onGroupCollapse(groupPos);
         }
@@ -787,14 +787,14 @@
         /**
          * Callback method to be invoked when a group in this expandable list has
          * been collapsed.
-         * 
+         *
          * @param groupPosition The group position that was collapsed
          */
         void onGroupCollapse(int groupPosition);
     }
-    
+
     private OnGroupCollapseListener mOnGroupCollapseListener;
-    
+
     public void setOnGroupCollapseListener(
             OnGroupCollapseListener onGroupCollapseListener) {
         mOnGroupCollapseListener = onGroupCollapseListener;
@@ -805,14 +805,14 @@
         /**
          * Callback method to be invoked when a group in this expandable list has
          * been expanded.
-         * 
+         *
          * @param groupPosition The group position that was expanded
          */
         void onGroupExpand(int groupPosition);
     }
-    
+
     private OnGroupExpandListener mOnGroupExpandListener;
-    
+
     public void setOnGroupExpandListener(
             OnGroupExpandListener onGroupExpandListener) {
         mOnGroupExpandListener = onGroupExpandListener;
@@ -826,7 +826,7 @@
         /**
          * Callback method to be invoked when a group in this expandable list has
          * been clicked.
-         * 
+         *
          * @param parent The ExpandableListConnector where the click happened
          * @param v The view within the expandable list/ListView that was clicked
          * @param groupPosition The group position that was clicked
@@ -836,13 +836,13 @@
         boolean onGroupClick(ExpandableListView parent, View v, int groupPosition,
                 long id);
     }
-    
+
     private OnGroupClickListener mOnGroupClickListener;
 
     public void setOnGroupClickListener(OnGroupClickListener onGroupClickListener) {
         mOnGroupClickListener = onGroupClickListener;
     }
-    
+
     /**
      * Interface definition for a callback to be invoked when a child in this
      * expandable list has been clicked.
@@ -851,7 +851,7 @@
         /**
          * Callback method to be invoked when a child in this expandable list has
          * been clicked.
-         * 
+         *
          * @param parent The ExpandableListView where the click happened
          * @param v The view within the expandable list/ListView that was clicked
          * @param groupPosition The group position that contains the child that
@@ -863,13 +863,13 @@
         boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
                 int childPosition, long id);
     }
-    
+
     private OnChildClickListener mOnChildClickListener;
 
     public void setOnChildClickListener(OnChildClickListener onChildClickListener) {
         mOnChildClickListener = onChildClickListener;
     }
-    
+
     /**
      * Converts a flat list position (the raw position of an item (child or group)
      * in the list) to a group and/or child position (represented in a
@@ -878,7 +878,7 @@
      * {@link ExpandableListView#getPackedPositionType} ,
      * {@link ExpandableListView#getPackedPositionChild},
      * {@link ExpandableListView#getPackedPositionGroup} to unpack.
-     * 
+     *
      * @param flatListPosition The flat list position to be converted.
      * @return The group and/or child position for the given flat list position
      *         in packed position representation. #PACKED_POSITION_VALUE_NULL if
@@ -895,12 +895,12 @@
         pm.recycle();
         return packedPos;
     }
-    
+
     /**
      * Converts a group and/or child position to a flat list position. This is
      * useful in situations where the caller needs to use the underlying
      * {@link ListView}'s methods.
-     * 
+     *
      * @param packedPosition The group and/or child positions to be converted in
      *            packed position representation. Use
      *            {@link #getPackedPositionForChild(int, int)} or
@@ -920,7 +920,7 @@
     /**
      * Gets the position of the currently selected group or child (along with
      * its type). Can return {@link #PACKED_POSITION_VALUE_NULL} if no selection.
-     * 
+     *
      * @return A packed position containing the currently selected group or
      *         child's position and type. #PACKED_POSITION_VALUE_NULL if no selection
      *         or if selection is on a header or a footer item.
@@ -931,11 +931,11 @@
         // The case where there is no selection (selectedPos == -1) is also handled here.
         return getExpandableListPosition(selectedPos);
     }
-    
+
     /**
      * Gets the ID of the currently selected group or child. Can return -1 if no
      * selection.
-     * 
+     *
      * @return The ID of the currently selected group or child. -1 if no
      *         selection.
      */
@@ -944,7 +944,7 @@
         if (packedPos == PACKED_POSITION_VALUE_NULL) return -1;
 
         int groupPos = getPackedPositionGroup(packedPos);
-        
+
         if (getPackedPositionType(packedPos) == PACKED_POSITION_TYPE_GROUP) {
             // It's a group
             return mAdapter.getGroupId(groupPos);
@@ -953,7 +953,7 @@
             return mAdapter.getChildId(groupPos, getPackedPositionChild(packedPos));
         }
     }
-    
+
     /**
      * Sets the selection to the specified group.
      * @param groupPosition The position of the group that should be selected.
@@ -967,12 +967,12 @@
         super.setSelection(absoluteFlatPosition);
         pm.recycle();
     }
-    
+
     /**
      * Sets the selection to the specified child. If the child is in a collapsed
      * group, the group will only be expanded and child subsequently selected if
      * shouldExpandGroup is set to true, otherwise the method will return false.
-     * 
+     *
      * @param groupPosition The position of the group that contains the child.
      * @param childPosition The position of the child within the group.
      * @param shouldExpandGroup Whether the child's group should be expanded if
@@ -981,48 +981,48 @@
      */
     public boolean setSelectedChild(int groupPosition, int childPosition, boolean shouldExpandGroup) {
         ExpandableListPosition elChildPos = ExpandableListPosition.obtainChildPosition(
-                groupPosition, childPosition); 
+                groupPosition, childPosition);
         PositionMetadata flatChildPos = mConnector.getFlattenedPos(elChildPos);
-        
+
         if (flatChildPos == null) {
             // The child's group isn't expanded
-            
+
             // Shouldn't expand the group, so return false for we didn't set the selection
-            if (!shouldExpandGroup) return false; 
+            if (!shouldExpandGroup) return false;
 
             expandGroup(groupPosition);
-            
+
             flatChildPos = mConnector.getFlattenedPos(elChildPos);
-            
+
             // Sanity check
             if (flatChildPos == null) {
                 throw new IllegalStateException("Could not find child");
             }
         }
-        
+
         int absoluteFlatPosition = getAbsoluteFlatPosition(flatChildPos.position.flatListPos);
         super.setSelection(absoluteFlatPosition);
-        
+
         elChildPos.recycle();
         flatChildPos.recycle();
-        
+
         return true;
     }
 
     /**
      * Whether the given group is currently expanded.
-     * 
+     *
      * @param groupPosition The group to check.
      * @return Whether the group is currently expanded.
      */
     public boolean isGroupExpanded(int groupPosition) {
         return mConnector.isGroupExpanded(groupPosition);
     }
-    
+
     /**
      * Gets the type of a packed position. See
      * {@link #getPackedPositionForChild(int, int)}.
-     * 
+     *
      * @param packedPosition The packed position for which to return the type.
      * @return The type of the position contained within the packed position,
      *         either {@link #PACKED_POSITION_TYPE_CHILD}, {@link #PACKED_POSITION_TYPE_GROUP}, or
@@ -1032,7 +1032,7 @@
         if (packedPosition == PACKED_POSITION_VALUE_NULL) {
             return PACKED_POSITION_TYPE_NULL;
         }
-        
+
         return (packedPosition & PACKED_POSITION_MASK_TYPE) == PACKED_POSITION_MASK_TYPE
                 ? PACKED_POSITION_TYPE_CHILD
                 : PACKED_POSITION_TYPE_GROUP;
@@ -1041,7 +1041,7 @@
     /**
      * Gets the group position from a packed position. See
      * {@link #getPackedPositionForChild(int, int)}.
-     * 
+     *
      * @param packedPosition The packed position from which the group position
      *            will be returned.
      * @return The group position portion of the packed position. If this does
@@ -1050,7 +1050,7 @@
     public static int getPackedPositionGroup(long packedPosition) {
         // Null
         if (packedPosition == PACKED_POSITION_VALUE_NULL) return -1;
-        
+
         return (int) ((packedPosition & PACKED_POSITION_MASK_GROUP) >> PACKED_POSITION_SHIFT_GROUP);
     }
 
@@ -1060,7 +1060,7 @@
      * To get the group that this child belongs to, use
      * {@link #getPackedPositionGroup(long)}. See
      * {@link #getPackedPositionForChild(int, int)}.
-     * 
+     *
      * @param packedPosition The packed position from which the child position
      *            will be returned.
      * @return The child position portion of the packed position. If this does
@@ -1069,7 +1069,7 @@
     public static int getPackedPositionChild(long packedPosition) {
         // Null
         if (packedPosition == PACKED_POSITION_VALUE_NULL) return -1;
-        
+
         // Group since a group type clears this bit
         if ((packedPosition & PACKED_POSITION_MASK_TYPE) != PACKED_POSITION_MASK_TYPE) return -1;
 
@@ -1087,7 +1087,7 @@
      * {@link #getPackedPositionChild(long)},
      * {@link #getPackedPositionGroup(long)}, and
      * {@link #getPackedPositionType(long)}.
-     * 
+     *
      * @param groupPosition The child's parent group's position.
      * @param childPosition The child position within the group.
      * @return The packed position representation of the child (and parent group).
@@ -1096,20 +1096,20 @@
         return (((long)PACKED_POSITION_TYPE_CHILD) << PACKED_POSITION_SHIFT_TYPE)
                 | ((((long)groupPosition) & PACKED_POSITION_INT_MASK_GROUP)
                         << PACKED_POSITION_SHIFT_GROUP)
-                | (childPosition & PACKED_POSITION_INT_MASK_CHILD);  
+                | (childPosition & PACKED_POSITION_INT_MASK_CHILD);
     }
 
     /**
      * Returns the packed position representation of a group's position. See
      * {@link #getPackedPositionForChild(int, int)}.
-     * 
+     *
      * @param groupPosition The child's parent group's position.
      * @return The packed position representation of the group.
      */
     public static long getPackedPositionForGroup(int groupPosition) {
         // No need to OR a type in because PACKED_POSITION_GROUP == 0
         return ((((long)groupPosition) & PACKED_POSITION_INT_MASK_GROUP)
-                        << PACKED_POSITION_SHIFT_GROUP); 
+                        << PACKED_POSITION_SHIFT_GROUP);
     }
 
     @Override
@@ -1122,12 +1122,12 @@
         final int adjustedPosition = getFlatPositionForConnector(flatListPosition);
         PositionMetadata pm = mConnector.getUnflattenedPos(adjustedPosition);
         ExpandableListPosition pos = pm.position;
-        
+
         id = getChildOrGroupId(pos);
         long packedPosition = pos.getPackedPosition();
 
         pm.recycle();
-        
+
         return new ExpandableListContextMenuInfo(view, packedPosition, id);
     }
 
@@ -1135,7 +1135,7 @@
      * Gets the ID of the group or child at the given <code>position</code>.
      * This is useful since there is no ListAdapter ID -> ExpandableListAdapter
      * ID conversion mechanism (in some cases, it isn't possible).
-     * 
+     *
      * @param position The position of the child or group whose ID should be
      *            returned.
      */
@@ -1146,10 +1146,10 @@
             return mAdapter.getGroupId(position.groupPos);
         }
     }
-    
+
     /**
      * Sets the indicator to be drawn next to a child.
-     * 
+     *
      * @param childIndicator The drawable to be used as an indicator. If the
      *            child is the last child for a group, the state
      *            {@link android.R.attr#state_last} will be set.
@@ -1157,7 +1157,7 @@
     public void setChildIndicator(Drawable childIndicator) {
         mChildIndicator = childIndicator;
     }
-    
+
     /**
      * Sets the drawing bounds for the child indicator. For either, you can
      * specify {@link #CHILD_INDICATOR_INHERIT} to use inherit from the general
@@ -1194,7 +1194,7 @@
 
     /**
      * Sets the indicator to be drawn next to a group.
-     * 
+     *
      * @param groupIndicator The drawable to be used as an indicator. If the
      *            group is empty, the state {@link android.R.attr#state_empty} will be
      *            set. If the group is expanded, the state
@@ -1211,8 +1211,8 @@
      * Sets the drawing bounds for the indicators (at minimum, the group indicator
      * is affected by this; the child indicator is affected by this if the
      * child indicator bounds are set to inherit).
-     * 
-     * @see #setChildIndicatorBounds(int, int) 
+     *
+     * @see #setChildIndicatorBounds(int, int)
      * @param left The left position (relative to the left bounds of this View)
      *            to start drawing the indicator.
      * @param right The right position (relative to the left bounds of this
@@ -1248,13 +1248,13 @@
      * callback when a context menu is brought up for this AdapterView.
      */
     public static class ExpandableListContextMenuInfo implements ContextMenu.ContextMenuInfo {
-        
+
         public ExpandableListContextMenuInfo(View targetView, long packedPosition, long id) {
             this.targetView = targetView;
             this.packedPosition = packedPosition;
             this.id = id;
         }
-        
+
         /**
          * The view for which the context menu is being displayed. This
          * will be one of the children Views of this {@link ExpandableListView}.
@@ -1276,10 +1276,10 @@
          */
         public long id;
     }
-    
+
     static class SavedState extends BaseSavedState {
         ArrayList<ExpandableListConnector.GroupMetadata> expandedGroupMetadataList;
-        
+
         /**
          * Constructor called from {@link ExpandableListView#onSaveInstanceState()}
          */
@@ -1333,7 +1333,7 @@
 
         SavedState ss = (SavedState) state;
         super.onRestoreInstanceState(ss.getSuperState());
-        
+
         if (mConnector != null && ss.expandedGroupMetadataList != null) {
             mConnector.setExpandedGroupMetadataList(ss.expandedGroupMetadataList);
         }
diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java
index b8c74d8..dc8ee01 100644
--- a/core/java/android/widget/FrameLayout.java
+++ b/core/java/android/widget/FrameLayout.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.AttrRes;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -34,6 +32,8 @@
 import android.view.ViewHierarchyEncoder;
 import android.widget.RemoteViews.RemoteView;
 
+import com.android.internal.R;
+
 import java.util.ArrayList;
 
 /**
diff --git a/core/java/android/widget/GridLayout.java b/core/java/android/widget/GridLayout.java
index af2852c..1c15c7a 100644
--- a/core/java/android/widget/GridLayout.java
+++ b/core/java/android/widget/GridLayout.java
@@ -16,6 +16,20 @@
 
 package android.widget;
 
+import static android.view.Gravity.AXIS_PULL_AFTER;
+import static android.view.Gravity.AXIS_PULL_BEFORE;
+import static android.view.Gravity.AXIS_SPECIFIED;
+import static android.view.Gravity.AXIS_X_SHIFT;
+import static android.view.Gravity.AXIS_Y_SHIFT;
+import static android.view.Gravity.HORIZONTAL_GRAVITY_MASK;
+import static android.view.Gravity.RELATIVE_LAYOUT_DIRECTION;
+import static android.view.Gravity.VERTICAL_GRAVITY_MASK;
+import static android.view.View.MeasureSpec.EXACTLY;
+import static android.view.View.MeasureSpec.makeMeasureSpec;
+
+import static java.lang.Math.max;
+import static java.lang.Math.min;
+
 import android.annotation.IntDef;
 import android.content.Context;
 import android.content.res.TypedArray;
@@ -32,6 +46,7 @@
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.RemoteViews.RemoteView;
+
 import com.android.internal.R;
 
 import java.lang.annotation.Retention;
@@ -43,12 +58,6 @@
 import java.util.List;
 import java.util.Map;
 
-import static android.view.Gravity.*;
-import static android.view.View.MeasureSpec.EXACTLY;
-import static android.view.View.MeasureSpec.makeMeasureSpec;
-import static java.lang.Math.max;
-import static java.lang.Math.min;
-
 /**
  * A layout that places its children in a rectangular <em>grid</em>.
  * <p>
diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java
index b95aa52..20543fb 100644
--- a/core/java/android/widget/GridView.java
+++ b/core/java/android/widget/GridView.java
@@ -36,9 +36,9 @@
 import android.view.ViewRootImpl;
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
-import android.view.accessibility.AccessibilityNodeProvider;
 import android.view.accessibility.AccessibilityNodeInfo.CollectionInfo;
 import android.view.accessibility.AccessibilityNodeInfo.CollectionItemInfo;
+import android.view.accessibility.AccessibilityNodeProvider;
 import android.view.animation.GridLayoutAnimationController;
 import android.widget.RemoteViews.RemoteView;
 
@@ -54,7 +54,7 @@
  *
  * <p>See the <a href="{@docRoot}guide/topics/ui/layout/gridview.html">Grid
  * View</a> guide.</p>
- * 
+ *
  * @attr ref android.R.styleable#GridView_horizontalSpacing
  * @attr ref android.R.styleable#GridView_verticalSpacing
  * @attr ref android.R.styleable#GridView_stretchMode
@@ -71,33 +71,33 @@
 
     /**
      * Disables stretching.
-     * 
-     * @see #setStretchMode(int) 
+     *
+     * @see #setStretchMode(int)
      */
     public static final int NO_STRETCH = 0;
     /**
      * Stretches the spacing between columns.
-     * 
-     * @see #setStretchMode(int) 
+     *
+     * @see #setStretchMode(int)
      */
     public static final int STRETCH_SPACING = 1;
     /**
      * Stretches columns.
-     * 
-     * @see #setStretchMode(int) 
+     *
+     * @see #setStretchMode(int)
      */
     public static final int STRETCH_COLUMN_WIDTH = 2;
     /**
      * Stretches the spacing between columns. The spacing is uniform.
-     * 
-     * @see #setStretchMode(int) 
+     *
+     * @see #setStretchMode(int)
      */
     public static final int STRETCH_SPACING_UNIFORM = 3;
 
     /**
      * Creates as many columns as can fit on screen.
-     * 
-     * @see #setNumColumns(int) 
+     *
+     * @see #setNumColumns(int)
      */
     public static final int AUTO_FIT = -1;
 
@@ -161,7 +161,7 @@
         if (index >= 0) {
             setGravity(index);
         }
-        
+
         a.recycle();
     }
 
@@ -192,7 +192,7 @@
         }
 
         resetList();
-        mRecycler.clear();        
+        mRecycler.clear();
         mAdapter = adapter;
 
         mOldSelectedPosition = INVALID_POSITION;
@@ -222,7 +222,7 @@
             setNextSelectedPositionInt(position);
             checkSelectionChanged();
         } else {
-            checkFocus();            
+            checkFocus();
             // Nothing selected
             checkSelectionChanged();
         }
@@ -376,7 +376,7 @@
         }
 
         mReferenceView = child;
-        
+
         if (selectedView != null) {
             mReferenceViewInSelectedRow = mReferenceView;
         }
@@ -515,7 +515,7 @@
                 offsetChildrenTopAndBottom(offset);
             }
         }
-    }    
+    }
 
     @Override
     int findMotionRow(int y) {
@@ -624,7 +624,7 @@
 
             // This is how far the bottom edge of the last view is from the bottom of the
             // drawable area
-            int bottomOffset = end - lastBottom;        
+            int bottomOffset = end - lastBottom;
 
             final View firstChild = getChildAt(0);
             final int firstTop = firstChild.getTop();
@@ -636,7 +636,7 @@
                     // Don't pull the top too far down
                     bottomOffset = Math.min(bottomOffset, mListPadding.top - firstTop);
                 }
-                
+
                 // Move everything down
                 offsetChildrenTopAndBottom(bottomOffset);
                 if (mFirstPosition > 0) {
@@ -679,7 +679,7 @@
                     // Don't pull the bottom too far up
                     topOffset = Math.min(topOffset, lastBottom - end);
                 }
-                
+
                 // Move everything up
                 offsetChildrenTopAndBottom(-topOffset);
                 if (lastPosition < mItemCount - 1) {
@@ -965,7 +965,7 @@
         final int stretchMode = mStretchMode;
         final int requestedColumnWidth = mRequestedColumnWidth;
         boolean didNotInitiallyFit = false;
-        
+
         if (mRequestedNumColumns == AUTO_FIT) {
             if (requestedColumnWidth > 0) {
                 // Client told us to pick the number of columns
@@ -979,57 +979,57 @@
             // We picked the columns
             mNumColumns = mRequestedNumColumns;
         }
-        
+
         if (mNumColumns <= 0) {
             mNumColumns = 1;
         }
 
         switch (stretchMode) {
-        case NO_STRETCH:
-            // Nobody stretches
-            mColumnWidth = requestedColumnWidth;
-            mHorizontalSpacing = requestedHorizontalSpacing;
-            break;
-
-        default:
-            int spaceLeftOver = availableSpace - (mNumColumns * requestedColumnWidth) -
-                    ((mNumColumns - 1) * requestedHorizontalSpacing);
-
-            if (spaceLeftOver < 0) {
-                didNotInitiallyFit = true;
-            }
-
-            switch (stretchMode) {
-            case STRETCH_COLUMN_WIDTH:
-                // Stretch the columns
-                mColumnWidth = requestedColumnWidth + spaceLeftOver / mNumColumns;
+            case NO_STRETCH:
+                // Nobody stretches
+                mColumnWidth = requestedColumnWidth;
                 mHorizontalSpacing = requestedHorizontalSpacing;
                 break;
 
-            case STRETCH_SPACING:
-                // Stretch the spacing between columns
-                mColumnWidth = requestedColumnWidth;
-                if (mNumColumns > 1) {
-                    mHorizontalSpacing = requestedHorizontalSpacing + 
-                        spaceLeftOver / (mNumColumns - 1);
-                } else {
-                    mHorizontalSpacing = requestedHorizontalSpacing + spaceLeftOver;
-                }
-                break;
+            default:
+                int spaceLeftOver = availableSpace - (mNumColumns * requestedColumnWidth)
+                        - ((mNumColumns - 1) * requestedHorizontalSpacing);
 
-            case STRETCH_SPACING_UNIFORM:
-                // Stretch the spacing between columns
-                mColumnWidth = requestedColumnWidth;
-                if (mNumColumns > 1) {
-                    mHorizontalSpacing = requestedHorizontalSpacing + 
-                        spaceLeftOver / (mNumColumns + 1);
-                } else {
-                    mHorizontalSpacing = requestedHorizontalSpacing + spaceLeftOver;
+                if (spaceLeftOver < 0) {
+                    didNotInitiallyFit = true;
                 }
-                break;
-            }
 
-            break;
+                switch (stretchMode) {
+                    case STRETCH_COLUMN_WIDTH:
+                        // Stretch the columns
+                        mColumnWidth = requestedColumnWidth + spaceLeftOver / mNumColumns;
+                        mHorizontalSpacing = requestedHorizontalSpacing;
+                        break;
+
+                    case STRETCH_SPACING:
+                        // Stretch the spacing between columns
+                        mColumnWidth = requestedColumnWidth;
+                        if (mNumColumns > 1) {
+                            mHorizontalSpacing = requestedHorizontalSpacing
+                                    + spaceLeftOver / (mNumColumns - 1);
+                        } else {
+                            mHorizontalSpacing = requestedHorizontalSpacing + spaceLeftOver;
+                        }
+                        break;
+
+                    case STRETCH_SPACING_UNIFORM:
+                        // Stretch the spacing between columns
+                        mColumnWidth = requestedColumnWidth;
+                        if (mNumColumns > 1) {
+                            mHorizontalSpacing = requestedHorizontalSpacing
+                                    + spaceLeftOver / (mNumColumns + 1);
+                        } else {
+                            mHorizontalSpacing = requestedHorizontalSpacing + spaceLeftOver;
+                        }
+                        break;
+                }
+
+                break;
         }
         return didNotInitiallyFit;
     }
@@ -1052,7 +1052,7 @@
             }
             widthSize += getVerticalScrollbarWidth();
         }
-        
+
         int childWidth = widthSize - mListPadding.left - mListPadding.right;
         boolean didNotInitiallyFit = determineColumns(childWidth);
 
@@ -1087,7 +1087,7 @@
                 mRecycler.addScrapView(child, -1);
             }
         }
-        
+
         if (heightMode == MeasureSpec.UNSPECIFIED) {
             heightSize = mListPadding.top + mListPadding.bottom + childHeight +
                     getVerticalFadingEdgeLength() * 2;
@@ -1095,7 +1095,7 @@
 
         if (heightMode == MeasureSpec.AT_MOST) {
             int ourSize =  mListPadding.top + mListPadding.bottom;
-           
+
             final int numColumns = mNumColumns;
             for (int i = 0; i < count; i += numColumns) {
                 ourSize += childHeight;
@@ -1574,9 +1574,9 @@
 
     /**
      * Sets the currently selected item
-     * 
+     *
      * @param position Index (starting at 0) of the data item to be selected.
-     * 
+     *
      * If in touch mode, the item will not be selected but it will still be positioned
      * appropriately.
      */
@@ -1609,8 +1609,8 @@
 
         setNextSelectedPositionInt(position);
         layoutChildren();
-        
-        final int next = mStackFromBottom ? mItemCount - 1  - mNextSelectedPosition : 
+
+        final int next = mStackFromBottom ? mItemCount - 1  - mNextSelectedPosition :
             mNextSelectedPosition;
         final int previous = mStackFromBottom ? mItemCount - 1
                 - previousSelectedPosition : previousSelectedPosition;
@@ -1802,7 +1802,7 @@
             invokeOnItemScrollListener();
             moved = true;
         }
-        
+
         if (moved) {
             awakenScrollBars();
         }
@@ -1874,7 +1874,7 @@
         if (moved) {
             awakenScrollBars();
         }
-        
+
         return moved;
     }
 
@@ -2216,17 +2216,17 @@
             requestLayoutIfNecessary();
         }
     }
-    
+
     /**
-     * Get the number of columns in the grid. 
+     * Get the number of columns in the grid.
      * Returns {@link #AUTO_FIT} if the Grid has never been laid out.
      *
      * @attr ref android.R.styleable#GridView_numColumns
-     * 
+     *
      * @see #setNumColumns(int)
      */
     @ViewDebug.ExportedProperty
-    public int getNumColumns() {  
+    public int getNumColumns() {
         return mNumColumns;
     }
 
@@ -2259,13 +2259,13 @@
                 // we are too high, slide all views down to align with bottom
                 child = getChildAt(childCount - 1);
                 delta = child.getBottom() - (getHeight() - mListPadding.bottom);
-                
+
                 if (mFirstPosition + childCount < mItemCount) {
                     // It's OK to have some space below the last item if it is
                     // part of the vertical spacing
                     delta += mVerticalSpacing;
                 }
-                
+
                 if (delta > 0) {
                     // We only are looking to see if we are too high, not too low
                     delta = 0;
@@ -2277,14 +2277,14 @@
             }
         }
     }
-    
+
     @Override
     protected int computeVerticalScrollExtent() {
         final int count = getChildCount();
         if (count > 0) {
             final int numColumns = mNumColumns;
             final int rowCount = (count + numColumns - 1) / numColumns;
-            
+
             int extent = rowCount * 100;
 
             View view = getChildAt(0);
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index d9cb269..4d405c5 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -467,6 +467,14 @@
      * {@link #setImageBitmap(android.graphics.Bitmap)} and
      * {@link android.graphics.BitmapFactory} instead.</p>
      *
+     * <p class="note">On devices running SDK < 24, this method will fail to
+     * apply correct density scaling to images loaded from
+     * {@link ContentResolver#SCHEME_CONTENT content} and
+     * {@link ContentResolver#SCHEME_FILE file} schemes. Applications running
+     * on devices with SDK >= 24 <strong>MUST</strong> specify the
+     * {@code targetSdkVersion} in their manifest as 24 or above for density
+     * scaling to be applied to images loaded from these schemes.</p>
+     *
      * @param uri the Uri of an image, or {@code null} to clear the content
      */
     @android.view.RemotableViewMethod(asyncImpl="setImageURIAsync")
diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java
index 6511de8..544e591 100644
--- a/core/java/android/widget/LinearLayout.java
+++ b/core/java/android/widget/LinearLayout.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -34,15 +32,17 @@
 import android.view.ViewHierarchyEncoder;
 import android.widget.RemoteViews.RemoteView;
 
+import com.android.internal.R;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
 
 /**
- * A Layout that arranges its children in a single column or a single row. The direction of 
- * the row can be set by calling {@link #setOrientation(int) setOrientation()}. 
+ * A Layout that arranges its children in a single column or a single row. The direction of
+ * the row can be set by calling {@link #setOrientation(int) setOrientation()}.
  * You can also specify gravity, which specifies the alignment of all the child elements by
- * calling {@link #setGravity(int) setGravity()} or specify that specific children 
+ * calling {@link #setGravity(int) setGravity()} or specify that specific children
  * grow to fill up any remaining space in the layout by setting the <em>weight</em> member of
  * {@link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams}.
  * The default orientation is horizontal.
@@ -202,7 +202,7 @@
     public LinearLayout(Context context, @Nullable AttributeSet attrs) {
         this(context, attrs, 0);
     }
-    
+
     public LinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
         this(context, attrs, defStyleAttr, 0);
     }
@@ -497,7 +497,7 @@
      * When true, all children with a weight will be considered having
      * the minimum size of the largest child. If false, all children are
      * measured normally.
-     * 
+     *
      * @return True to measure children with a weight using the minimum
      *         size of the largest child, false otherwise.
      *
@@ -511,9 +511,9 @@
      * When set to true, all children with a weight will be considered having
      * the minimum size of the largest child. If false, all children are
      * measured normally.
-     * 
+     *
      * Disabled by default.
-     * 
+     *
      * @param enabled True to measure children with a weight using the
      *        minimum size of the largest child, false otherwise.
      *
@@ -589,7 +589,7 @@
     /**
      * @param i The index of the child that will be used if this layout is
      *          part of a larger layout that is baseline aligned.
-     * 
+     *
      * @attr ref android.R.styleable#LinearLayout_baselineAlignedChildIndex
      */
     @android.view.RemotableViewMethod
@@ -720,14 +720,14 @@
         float totalWeight = 0;
 
         final int count = getVirtualChildCount();
-        
+
         final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
         final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
 
         boolean matchWidth = false;
         boolean skippedMeasure = false;
 
-        final int baselineChildIndex = mBaselineAlignedChildIndex;        
+        final int baselineChildIndex = mBaselineAlignedChildIndex;
         final boolean useLargestChild = mUseLargestChild;
 
         int largestChildHeight = Integer.MIN_VALUE;
@@ -886,7 +886,7 @@
 
         // Check against our minimum height
         heightSize = Math.max(heightSize, getSuggestedMinimumHeight());
-        
+
         // Reconcile our calculated size with the heightMeasureSpec
         int heightSizeAndState = resolveSizeAndState(heightSize, heightMeasureSpec, 0);
         heightSize = heightSizeAndState & MEASURED_SIZE_MASK;
@@ -991,12 +991,12 @@
         if (!allFillParent && widthMode != MeasureSpec.EXACTLY) {
             maxWidth = alternativeMaxWidth;
         }
-        
+
         maxWidth += mPaddingLeft + mPaddingRight;
 
         // Check against our minimum width
         maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
-        
+
         setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
                 heightSizeAndState);
 
@@ -1013,13 +1013,13 @@
            final View child = getVirtualChildAt(i);
            if (child != null && child.getVisibility() != GONE) {
                LinearLayout.LayoutParams lp = ((LinearLayout.LayoutParams)child.getLayoutParams());
-               
+
                if (lp.width == LayoutParams.MATCH_PARENT) {
                    // Temporarily force children to reuse their old measured height
                    // FIXME: this may not be right for something like wrapping text?
                    int oldHeight = lp.height;
                    lp.height = child.getMeasuredHeight();
-                   
+
                    // Remeasue with new dimensions
                    measureChildWithMargins(child, uniformMeasureSpec, 0, heightMeasureSpec, 0);
                    lp.height = oldHeight;
@@ -1037,7 +1037,7 @@
      *
      * @see #getOrientation()
      * @see #setOrientation(int)
-     * @see #onMeasure(int, int) 
+     * @see #onMeasure(int, int)
      */
     void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) {
         mTotalLength = 0;
@@ -1049,7 +1049,7 @@
         float totalWeight = 0;
 
         final int count = getVirtualChildCount();
-        
+
         final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
         final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
 
@@ -1069,7 +1069,7 @@
 
         final boolean baselineAligned = mBaselineAligned;
         final boolean useLargestChild = mUseLargestChild;
-        
+
         final boolean isExactly = widthMode == MeasureSpec.EXACTLY;
 
         int largestChildWidth = Integer.MIN_VALUE;
@@ -1084,7 +1084,7 @@
                 mTotalLength += measureNullChild(i);
                 continue;
             }
-           
+
             if (child.getVisibility() == GONE) {
                 i += getChildrenSkipCount(child, i);
                 continue;
@@ -1263,16 +1263,16 @@
 
         // Add in our padding
         mTotalLength += mPaddingLeft + mPaddingRight;
-        
+
         int widthSize = mTotalLength;
-        
+
         // Check against our minimum width
         widthSize = Math.max(widthSize, getSuggestedMinimumWidth());
-        
+
         // Reconcile our calculated size with the widthMeasureSpec
         int widthSizeAndState = resolveSizeAndState(widthSize, widthMeasureSpec, 0);
         widthSize = widthSizeAndState & MEASURED_SIZE_MASK;
-        
+
         // Either expand children with weight to take up available space or
         // shrink them if they extend beyond our current bounds. If we skipped
         // measurement on any children, we need to measure them now.
@@ -1409,12 +1409,12 @@
         if (!allFillParent && heightMode != MeasureSpec.EXACTLY) {
             maxHeight = alternativeMaxHeight;
         }
-        
+
         maxHeight += mPaddingTop + mPaddingBottom;
 
         // Check against our minimum height
         maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
-        
+
         setMeasuredDimension(widthSizeAndState | (childState&MEASURED_STATE_MASK),
                 resolveSizeAndState(maxHeight, heightMeasureSpec,
                         (childState<<MEASURED_HEIGHT_STATE_SHIFT)));
@@ -1434,13 +1434,13 @@
            final View child = getVirtualChildAt(i);
            if (child != null && child.getVisibility() != GONE) {
                LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams();
-               
+
                if (lp.height == LayoutParams.MATCH_PARENT) {
                    // Temporarily force children to reuse their old measured width
                    // FIXME: this may not be right for something like wrapping text?
                    int oldWidth = lp.width;
                    lp.width = child.getMeasuredWidth();
-                   
+
                    // Remeasure with new dimensions
                    measureChildWithMargins(child, widthMeasureSpec, 0, uniformMeasureSpec, 0);
                    lp.width = oldWidth;
@@ -1541,14 +1541,14 @@
 
         int childTop;
         int childLeft;
-        
+
         // Where right end of child should go
         final int width = right - left;
         int childRight = width - mPaddingRight;
-        
+
         // Space available for child
         int childSpace = width - paddingLeft - mPaddingRight;
-        
+
         final int count = getVirtualChildCount();
 
         final int majorGravity = mGravity & Gravity.VERTICAL_GRAVITY_MASK;
@@ -1578,10 +1578,10 @@
             } else if (child.getVisibility() != GONE) {
                 final int childWidth = child.getMeasuredWidth();
                 final int childHeight = child.getMeasuredHeight();
-                
+
                 final LinearLayout.LayoutParams lp =
                         (LinearLayout.LayoutParams) child.getLayoutParams();
-                
+
                 int gravity = lp.gravity;
                 if (gravity < 0) {
                     gravity = minorGravity;
@@ -1647,11 +1647,11 @@
 
         int childTop;
         int childLeft;
-        
+
         // Where bottom of child should go
         final int height = bottom - top;
-        int childBottom = height - mPaddingBottom; 
-        
+        int childBottom = height - mPaddingBottom;
+
         // Space available for child
         int childSpace = height - paddingTop - mPaddingBottom;
 
@@ -1707,12 +1707,12 @@
                 if (baselineAligned && lp.height != LayoutParams.MATCH_PARENT) {
                     childBaseline = child.getBaseline();
                 }
-                
+
                 int gravity = lp.gravity;
                 if (gravity < 0) {
                     gravity = minorGravity;
                 }
-                
+
                 switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
                     case Gravity.TOP:
                         childTop = paddingTop + lp.topMargin;
@@ -1764,15 +1764,15 @@
         }
     }
 
-    private void setChildFrame(View child, int left, int top, int width, int height) {        
+    private void setChildFrame(View child, int left, int top, int width, int height) {
         child.layout(left, top, left + width, top + height);
     }
-    
+
     /**
      * Should the layout be a column or a row.
      * @param orientation Pass {@link #HORIZONTAL} or {@link #VERTICAL}. Default
      * value is {@link #HORIZONTAL}.
-     * 
+     *
      * @attr ref android.R.styleable#LinearLayout_orientation
      */
     public void setOrientation(@OrientationMode int orientation) {
@@ -1784,7 +1784,7 @@
 
     /**
      * Returns the current orientation.
-     * 
+     *
      * @return either {@link #HORIZONTAL} or {@link #VERTICAL}
      */
     @OrientationMode
@@ -1797,9 +1797,9 @@
      * this layout has a VERTICAL orientation, this controls where all the child
      * views are placed if there is extra vertical space. If this layout has a
      * HORIZONTAL orientation, this controls the alignment of the children.
-     * 
+     *
      * @param gravity See {@link android.view.Gravity}
-     * 
+     *
      * @attr ref android.R.styleable#LinearLayout_gravity
      */
     @android.view.RemotableViewMethod
@@ -1845,7 +1845,7 @@
             requestLayout();
         }
     }
-    
+
     @Override
     public LayoutParams generateLayoutParams(AttributeSet attrs) {
         return new LinearLayout.LayoutParams(getContext(), attrs);
@@ -1909,7 +1909,7 @@
 
     /**
      * Per-child layout information associated with ViewLinearLayout.
-     * 
+     *
      * @attr ref android.R.styleable#LinearLayout_Layout_layout_weight
      * @attr ref android.R.styleable#LinearLayout_Layout_layout_gravity
      */
diff --git a/core/java/android/widget/ListPopupWindow.java b/core/java/android/widget/ListPopupWindow.java
index 6a10743..0bde983 100644
--- a/core/java/android/widget/ListPopupWindow.java
+++ b/core/java/android/widget/ListPopupWindow.java
@@ -16,9 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-import com.android.internal.view.menu.ShowableListMenu;
-
 import android.annotation.AttrRes;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -42,14 +39,17 @@
 import android.view.WindowManager;
 import android.widget.AdapterView.OnItemSelectedListener;
 
+import com.android.internal.R;
+import com.android.internal.view.menu.ShowableListMenu;
+
 /**
  * A ListPopupWindow anchors itself to a host view and displays a
  * list of choices.
- * 
+ *
  * <p>ListPopupWindow contains a number of tricky behaviors surrounding
  * positioning, scrolling parents to fit the dropdown, interacting
  * sanely with the IME if present, and others.
- * 
+ *
  * @see android.widget.AutoCompleteTextView
  * @see android.widget.Spinner
  */
@@ -116,7 +116,7 @@
 
     /**
      * The provided prompt view should appear above list content.
-     * 
+     *
      * @see #setPromptPosition(int)
      * @see #getPromptPosition()
      * @see #setPromptView(View)
@@ -125,7 +125,7 @@
 
     /**
      * The provided prompt view should appear below list content.
-     * 
+     *
      * @see #setPromptPosition(int)
      * @see #getPromptPosition()
      * @see #setPromptView(View)
@@ -138,13 +138,13 @@
      * If used to specify a popup height, the popup will fill available space.
      */
     public static final int MATCH_PARENT = ViewGroup.LayoutParams.MATCH_PARENT;
-    
+
     /**
      * Alias for {@link ViewGroup.LayoutParams#WRAP_CONTENT}.
      * If used to specify a popup width, the popup will use the width of its content.
      */
     public static final int WRAP_CONTENT = ViewGroup.LayoutParams.WRAP_CONTENT;
-    
+
     /**
      * Mode for {@link #setInputMethodMode(int)}: the requirements for the
      * input method should be based on the focusability of the popup.  That is
@@ -152,7 +152,7 @@
      * it doesn't.
      */
     public static final int INPUT_METHOD_FROM_FOCUSABLE = PopupWindow.INPUT_METHOD_FROM_FOCUSABLE;
-    
+
     /**
      * Mode for {@link #setInputMethodMode(int)}: this popup always needs to
      * work with an input method, regardless of whether it is focusable.  This
@@ -160,7 +160,7 @@
      * the input method while it is shown.
      */
     public static final int INPUT_METHOD_NEEDED = PopupWindow.INPUT_METHOD_NEEDED;
-    
+
     /**
      * Mode for {@link #setInputMethodMode(int)}: this popup never needs to
      * work with an input method, regardless of whether it is focusable.  This
@@ -172,7 +172,7 @@
     /**
      * Create a new, empty popup window capable of displaying items from a ListAdapter.
      * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
-     * 
+     *
      * @param context Context used for contained views.
      */
     public ListPopupWindow(@NonNull Context context) {
@@ -182,7 +182,7 @@
     /**
      * Create a new, empty popup window capable of displaying items from a ListAdapter.
      * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
-     * 
+     *
      * @param context Context used for contained views.
      * @param attrs Attributes from inflating parent views used to style the popup.
      */
@@ -193,7 +193,7 @@
     /**
      * Create a new, empty popup window capable of displaying items from a ListAdapter.
      * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
-     * 
+     *
      * @param context Context used for contained views.
      * @param attrs Attributes from inflating parent views used to style the popup.
      * @param defStyleAttr Default style attribute to use for popup content.
@@ -206,7 +206,7 @@
     /**
      * Create a new, empty popup window capable of displaying items from a ListAdapter.
      * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
-     * 
+     *
      * @param context Context used for contained views.
      * @param attrs Attributes from inflating parent views used to style the popup.
      * @param defStyleAttr Style attribute to read for default styling of popup content.
@@ -248,7 +248,7 @@
         if (mAdapter != null) {
             adapter.registerDataSetObserver(mObserver);
         }
-        
+
         if (mDropDownList != null) {
             mDropDownList.setAdapter(mAdapter);
         }
@@ -257,9 +257,9 @@
     /**
      * Set where the optional prompt view should appear. The default is
      * {@link #POSITION_PROMPT_ABOVE}.
-     * 
+     *
      * @param position A position constant declaring where the prompt should be displayed.
-     * 
+     *
      * @see #POSITION_PROMPT_ABOVE
      * @see #POSITION_PROMPT_BELOW
      */
@@ -269,7 +269,7 @@
 
     /**
      * @return Where the optional prompt view should appear.
-     * 
+     *
      * @see #POSITION_PROMPT_ABOVE
      * @see #POSITION_PROMPT_BELOW
      */
@@ -279,11 +279,11 @@
 
     /**
      * Set whether this window should be modal when shown.
-     * 
+     *
      * <p>If a popup window is modal, it will receive all touch and key input.
      * If the user touches outside the popup window's content area the popup window
      * will be dismissed.
-     * 
+     *
      * @param modal {@code true} if the popup window should be modal, {@code false} otherwise.
      */
     public void setModal(boolean modal) {
@@ -293,7 +293,7 @@
 
     /**
      * Returns whether the popup window will be modal when shown.
-     * 
+     *
      * @return {@code true} if the popup window will be modal, {@code false} otherwise.
      */
     public boolean isModal() {
@@ -304,7 +304,7 @@
      * Forces outside touches to be ignored. Normally if {@link #isDropDownAlwaysVisible()} is
      * false, we allow outside touch to dismiss the dropdown. If this is set to true, then we
      * ignore outside touch even when the drop down is not set to always visible.
-     * 
+     *
      * @hide Used only by AutoCompleteTextView to handle some internal special cases.
      */
     public void setForceIgnoreOutsideTouch(boolean forceIgnoreOutsideTouch) {
@@ -361,7 +361,7 @@
 
     /**
      * Sets a drawable to use as the list item selector.
-     * 
+     *
      * @param selector List selector drawable to use in the popup.
      */
     public void setListSelector(Drawable selector) {
@@ -377,7 +377,7 @@
 
     /**
      * Sets a drawable to be the background for the popup window.
-     * 
+     *
      * @param d A drawable to set as the background.
      */
     public void setBackgroundDrawable(@Nullable Drawable d) {
@@ -386,7 +386,7 @@
 
     /**
      * Set an animation style to use when the popup window is shown or dismissed.
-     * 
+     *
      * @param animationStyle Animation style to use.
      */
     public void setAnimationStyle(@StyleRes int animationStyle) {
@@ -396,7 +396,7 @@
     /**
      * Returns the animation style that will be used when the popup window is
      * shown or dismissed.
-     * 
+     *
      * @return Animation style that will be used.
      */
     public @StyleRes int getAnimationStyle() {
@@ -405,7 +405,7 @@
 
     /**
      * Returns the view that will be used to anchor this popup.
-     * 
+     *
      * @return The popup's anchor view
      */
     public @Nullable View getAnchorView() {
@@ -415,7 +415,7 @@
     /**
      * Sets the popup's anchor view. This popup will always be positioned relative to
      * the anchor view when shown.
-     * 
+     *
      * @param anchor The view to use as an anchor.
      */
     public void setAnchorView(@Nullable View anchor) {
@@ -431,7 +431,7 @@
 
     /**
      * Set the horizontal offset of this popup from its anchor view in pixels.
-     * 
+     *
      * @param offset The horizontal offset of the popup from its anchor.
      */
     public void setHorizontalOffset(int offset) {
@@ -450,7 +450,7 @@
 
     /**
      * Set the vertical offset of this popup from its anchor view in pixels.
-     * 
+     *
      * @param offset The vertical offset of the popup from its anchor.
      */
     public void setVerticalOffset(int offset) {
@@ -489,7 +489,7 @@
     /**
      * Sets the width of the popup window in pixels. Can also be {@link #MATCH_PARENT}
      * or {@link #WRAP_CONTENT}.
-     * 
+     *
      * @param width Width of the popup window.
      */
     public void setWidth(int width) {
@@ -521,7 +521,7 @@
 
     /**
      * Sets the height of the popup window in pixels. Can also be {@link #MATCH_PARENT}.
-     * 
+     *
      * @param height Height of the popup window.
      */
     public void setHeight(int height) {
@@ -543,9 +543,9 @@
 
     /**
      * Sets a listener to receive events when a list item is clicked.
-     * 
+     *
      * @param clickListener Listener to register
-     * 
+     *
      * @see ListView#setOnItemClickListener(android.widget.AdapterView.OnItemClickListener)
      */
     public void setOnItemClickListener(@Nullable AdapterView.OnItemClickListener clickListener) {
@@ -554,9 +554,9 @@
 
     /**
      * Sets a listener to receive events when a list item is selected.
-     * 
+     *
      * @param selectedListener Listener to register.
-     * 
+     *
      * @see ListView#setOnItemSelectedListener(OnItemSelectedListener)
      */
     public void setOnItemSelectedListener(@Nullable OnItemSelectedListener selectedListener) {
@@ -566,7 +566,7 @@
     /**
      * Set a view to act as a user prompt for this popup window. Where the prompt view will appear
      * is controlled by {@link #setPromptPosition(int)}.
-     * 
+     *
      * @param prompt View to use as an informational prompt.
      */
     public void setPromptView(@Nullable View prompt) {
@@ -662,7 +662,7 @@
             mPopup.setWidth(widthSpec);
             mPopup.setHeight(heightSpec);
             mPopup.setClipToScreenEnabled(true);
-            
+
             // use outside touchable to dismiss drop down when touching outside of it, so
             // only set this if the dropdown is not always visible
             mPopup.setOutsideTouchable(!mForceIgnoreOutsideTouch && !mDropDownAlwaysVisible);
@@ -671,7 +671,7 @@
             mPopup.showAsDropDown(getAnchorView(), mDropDownHorizontalOffset,
                     mDropDownVerticalOffset, mDropDownGravity);
             mDropDownList.setSelection(ListView.INVALID_POSITION);
-            
+
             if (!mModal || mDropDownList.isInTouchMode()) {
                 clearListSelection();
             }
@@ -716,11 +716,11 @@
      * Control how the popup operates with an input method: one of
      * {@link #INPUT_METHOD_FROM_FOCUSABLE}, {@link #INPUT_METHOD_NEEDED},
      * or {@link #INPUT_METHOD_NOT_NEEDED}.
-     * 
+     *
      * <p>If the popup is showing, calling this method will take effect only
      * the next time the popup is shown or through a manual call to the {@link #show()}
      * method.</p>
-     * 
+     *
      * @see #getInputMethodMode()
      * @see #show()
      */
@@ -730,7 +730,7 @@
 
     /**
      * Return the current value in {@link #setInputMethodMode(int)}.
-     * 
+     *
      * @see #setInputMethodMode(int)
      */
     public int getInputMethodMode() {
@@ -740,7 +740,7 @@
     /**
      * Set the selected position of the list.
      * Only valid when {@link #isShowing()} == {@code true}.
-     * 
+     *
      * @param position List position to set as selected.
      */
     public void setSelection(int position) {
@@ -786,7 +786,7 @@
 
     /**
      * Perform an item click operation on the specified list adapter position.
-     * 
+     *
      * @param position Adapter position for performing the click
      * @return true if the click action could be performed, false if not.
      *         (e.g. if the popup was not showing, this method would return false.)
@@ -817,7 +817,7 @@
     /**
      * @return The position of the currently selected item or {@link ListView#INVALID_POSITION}
      * if {@link #isShowing()} == {@code false}.
-     * 
+     *
      * @see ListView#getSelectedItemPosition()
      */
     public int getSelectedItemPosition() {
@@ -830,7 +830,7 @@
     /**
      * @return The ID of the currently selected item or {@link ListView#INVALID_ROW_ID}
      * if {@link #isShowing()} == {@code false}.
-     * 
+     *
      * @see ListView#getSelectedItemId()
      */
     public long getSelectedItemId() {
@@ -843,7 +843,7 @@
     /**
      * @return The View for the currently selected item or null if
      * {@link #isShowing()} == {@code false}.
-     * 
+     *
      * @see ListView#getSelectedView()
      */
     public @Nullable View getSelectedView() {
@@ -904,7 +904,7 @@
                 final boolean below = !mPopup.isAboveAnchor();
 
                 final ListAdapter adapter = mAdapter;
-                
+
                 boolean allEnabled;
                 int firstItem = Integer.MAX_VALUE;
                 int lastItem = Integer.MIN_VALUE;
@@ -914,9 +914,9 @@
                     firstItem = allEnabled ? 0 :
                             mDropDownList.lookForSelectablePosition(0, true);
                     lastItem = allEnabled ? adapter.getCount() - 1 :
-                            mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);                    
+                            mDropDownList.lookForSelectablePosition(adapter.getCount() - 1, false);
                 }
-                
+
                 if ((below && keyCode == KeyEvent.KEYCODE_DPAD_UP && curIndex <= firstItem) ||
                         (!below && keyCode == KeyEvent.KEYCODE_DPAD_DOWN && curIndex >= lastItem)) {
                     // When the selection is at the top, we block the key
@@ -1132,18 +1132,18 @@
                 LinearLayout.LayoutParams hintParams = new LinearLayout.LayoutParams(
                         ViewGroup.LayoutParams.MATCH_PARENT, 0, 1.0f
                 );
-                
+
                 switch (mPromptPosition) {
                 case POSITION_PROMPT_BELOW:
                     hintContainer.addView(dropDownView, hintParams);
                     hintContainer.addView(hintView);
                     break;
-                    
+
                 case POSITION_PROMPT_ABOVE:
                     hintContainer.addView(hintView);
                     hintContainer.addView(dropDownView, hintParams);
                     break;
-                    
+
                 default:
                     Log.e(TAG, "Invalid hint position " + mPromptPosition);
                     break;
@@ -1249,7 +1249,7 @@
                 show();
             }
         }
-        
+
         @Override
         public void onInvalidated() {
             dismiss();
@@ -1278,7 +1278,7 @@
             final int action = event.getAction();
             final int x = (int) event.getX();
             final int y = (int) event.getY();
-            
+
             if (action == MotionEvent.ACTION_DOWN &&
                     mPopup != null && mPopup.isShowing() &&
                     (x >= 0 && x < mPopup.getWidth() && y >= 0 && y < mPopup.getHeight())) {
diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java
index b0f19d7..e88c7ef 100644
--- a/core/java/android/widget/ListView.java
+++ b/core/java/android/widget/ListView.java
@@ -16,11 +16,6 @@
 
 package android.widget;
 
-import com.google.android.collect.Lists;
-
-import com.android.internal.R;
-import com.android.internal.util.Predicate;
-
 import android.annotation.IdRes;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -53,6 +48,11 @@
 import android.view.accessibility.AccessibilityNodeProvider;
 import android.widget.RemoteViews.RemoteView;
 
+import com.android.internal.R;
+import com.android.internal.util.Predicate;
+
+import com.google.android.collect.Lists;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -464,7 +464,7 @@
      *        data backing this list and for producing a view to represent an
      *        item in that data set.
      *
-     * @see #getAdapter() 
+     * @see #getAdapter()
      */
     @Override
     public void setAdapter(ListAdapter adapter) {
@@ -1532,7 +1532,7 @@
                         adjustViewsUpOrDown();
                     }
                 } else if (lastPosition == mItemCount - 1) {
-                    adjustViewsUpOrDown();                    
+                    adjustViewsUpOrDown();
                 }
             }
         }
@@ -1857,7 +1857,7 @@
                     && focusLayoutRestoreView.getWindowToken() != null) {
                 focusLayoutRestoreView.dispatchFinishTemporaryDetach();
             }
-            
+
             mLayoutMode = LAYOUT_NORMAL;
             mDataChanged = false;
             if (mPositionScrollAfterLayout != null) {
@@ -2109,7 +2109,7 @@
 
     /**
      * Makes the item at the supplied position selected.
-     * 
+     *
      * @param position the position of the item to select
      */
     @Override
@@ -2960,7 +2960,7 @@
             if (startPos < firstPosition) {
                 startPos = firstPosition;
             }
-            
+
             final int lastVisiblePos = getLastVisiblePosition();
             final ListAdapter adapter = getAdapter();
             for (int pos = startPos; pos <= lastVisiblePos; pos++) {
@@ -3129,7 +3129,7 @@
     /**
      * Determine the distance to the nearest edge of a view in a particular
      * direction.
-     * 
+     *
      * @param descendant A descendant of this list.
      * @return The distance, or 0 if the nearest edge is already on screen.
      */
@@ -3386,7 +3386,7 @@
             final int listBottom = mBottom - mTop - effectivePaddingBottom + mScrollY;
             if (!mStackFromBottom) {
                 int bottom = 0;
-                
+
                 // Draw top divider or header for overscroll
                 final int scrollY = mScrollY;
                 if (count > 0 && scrollY < 0) {
@@ -3483,7 +3483,7 @@
                         }
                     }
                 }
-                
+
                 if (count > 0 && scrollY > 0) {
                     if (drawOverscrollFooter) {
                         final int absListBottom = mBottom;
@@ -3567,7 +3567,7 @@
     public int getDividerHeight() {
         return mDividerHeight;
     }
-    
+
     /**
      * Sets the height of the divider that will be drawn between each item in the list. Calling
      * this will override the intrinsic height as set by {@link #setDivider(Drawable)}
@@ -3625,7 +3625,7 @@
     public boolean areFooterDividersEnabled() {
         return mFooterDividersEnabled;
     }
-    
+
     /**
      * Sets the drawable that will be drawn above all other list content.
      * This area can become visible when the user overscrolls the list.
@@ -3878,10 +3878,10 @@
     /**
      * Returns the set of checked items ids. The result is only valid if the
      * choice mode has not been set to {@link #CHOICE_MODE_NONE}.
-     * 
+     *
      * @return A new array which contains the id of each checked item in the
      *         list.
-     *         
+     *
      * @deprecated Use {@link #getCheckedItemIds()} instead.
      */
     @Deprecated
diff --git a/core/java/android/widget/MenuItemHoverListener.java b/core/java/android/widget/MenuItemHoverListener.java
index 13f0e6a..835e4cd 100644
--- a/core/java/android/widget/MenuItemHoverListener.java
+++ b/core/java/android/widget/MenuItemHoverListener.java
@@ -1,10 +1,10 @@
 package android.widget;
 
-import com.android.internal.view.menu.MenuBuilder;
-
 import android.annotation.NonNull;
 import android.view.MenuItem;
 
+import com.android.internal.view.menu.MenuBuilder;
+
 /**
  * An interface notified when a menu item is hovered. Useful for cases when hover should trigger
  * some behavior at a higher level, like managing the opening and closing of submenus.
diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java
index 72b2e31..662e640 100644
--- a/core/java/android/widget/NumberPicker.java
+++ b/core/java/android/widget/NumberPicker.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.CallSuper;
 import android.annotation.IntDef;
 import android.annotation.TestApi;
@@ -32,12 +30,10 @@
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 import android.os.Bundle;
-import android.text.Editable;
 import android.text.InputFilter;
 import android.text.InputType;
 import android.text.Spanned;
 import android.text.TextUtils;
-import android.text.TextWatcher;
 import android.text.method.NumberKeyListener;
 import android.util.AttributeSet;
 import android.util.SparseArray;
@@ -57,6 +53,10 @@
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
 
+import com.android.internal.R;
+
+import libcore.icu.LocaleData;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.ArrayList;
@@ -64,8 +64,6 @@
 import java.util.List;
 import java.util.Locale;
 
-import libcore.icu.LocaleData;
-
 /**
  * A widget that enables the user to select a number from a predefined range.
  * There are two flavors of this widget and which one is presented to the user
diff --git a/core/java/android/widget/PopupMenu.java b/core/java/android/widget/PopupMenu.java
index 027f874..eb27533 100644
--- a/core/java/android/widget/PopupMenu.java
+++ b/core/java/android/widget/PopupMenu.java
@@ -16,11 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-import com.android.internal.view.menu.MenuBuilder;
-import com.android.internal.view.menu.MenuPopupHelper;
-import com.android.internal.view.menu.ShowableListMenu;
-
 import android.annotation.MenuRes;
 import android.content.Context;
 import android.view.Gravity;
@@ -30,6 +25,11 @@
 import android.view.View;
 import android.view.View.OnTouchListener;
 
+import com.android.internal.R;
+import com.android.internal.view.menu.MenuBuilder;
+import com.android.internal.view.menu.MenuPopupHelper;
+import com.android.internal.view.menu.ShowableListMenu;
+
 /**
  * A PopupMenu displays a {@link Menu} in a modal popup window anchored to a
  * {@link View}. The popup will appear below the anchor view if there is room,
diff --git a/core/java/android/widget/PopupWindow.java b/core/java/android/widget/PopupWindow.java
index 5e73a63..fc1520b 100644
--- a/core/java/android/widget/PopupWindow.java
+++ b/core/java/android/widget/PopupWindow.java
@@ -16,7 +16,11 @@
 
 package android.widget;
 
-import com.android.internal.R;
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
+import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+import static android.view.WindowManager.LayoutParams
+        .PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
+import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -50,12 +54,9 @@
 import android.view.WindowManager;
 import android.view.WindowManager.LayoutParams;
 
-import java.lang.ref.WeakReference;
+import com.android.internal.R;
 
-import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_LAYOUT_CHILD_WINDOW_IN_PARENT_FRAME;
-import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_WILL_NOT_REPLACE_ON_RELAUNCH;
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
-import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
+import java.lang.ref.WeakReference;
 
 /**
  * <p>
diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java
index 1f379c9..266ff75 100644
--- a/core/java/android/widget/ProgressBar.java
+++ b/core/java/android/widget/ProgressBar.java
@@ -22,9 +22,7 @@
 import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.ColorStateList;
-import android.content.res.Resources;
 import android.content.res.TypedArray;
-import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.PorterDuff;
 import android.graphics.Rect;
@@ -60,6 +58,7 @@
 import android.view.animation.LinearInterpolator;
 import android.view.animation.Transformation;
 import android.widget.RemoteViews.RemoteView;
+
 import com.android.internal.R;
 
 import java.util.ArrayList;
@@ -186,6 +185,7 @@
  * @attr ref android.R.styleable#ProgressBar_indeterminateDuration
  * @attr ref android.R.styleable#ProgressBar_indeterminateOnly
  * @attr ref android.R.styleable#ProgressBar_interpolator
+ * @attr ref android.R.styleable#ProgressBar_min
  * @attr ref android.R.styleable#ProgressBar_max
  * @attr ref android.R.styleable#ProgressBar_maxHeight
  * @attr ref android.R.styleable#ProgressBar_maxWidth
@@ -216,7 +216,10 @@
 
     private int mProgress;
     private int mSecondaryProgress;
+    private int mMin;
+    private boolean mMinInitialized;
     private int mMax;
+    private boolean mMaxInitialized;
 
     private int mBehavior;
     private int mDuration;
@@ -309,6 +312,7 @@
             setInterpolator(context, resID);
         }
 
+        setMin(a.getInt(R.styleable.ProgressBar_min, mMin));
         setMax(a.getInt(R.styleable.ProgressBar_max, mMax));
 
         setProgress(a.getInt(R.styleable.ProgressBar_progress, mProgress));
@@ -565,6 +569,7 @@
      * </ul>
      */
     private void initProgressBar() {
+        mMin = 0;
         mMax = 100;
         mProgress = 0;
         mSecondaryProgress = 0;
@@ -1310,7 +1315,8 @@
 
     private synchronized void doRefreshProgress(int id, int progress, boolean fromUser,
             boolean callBackToApp, boolean animate) {
-        final float scale = mMax > 0 ? progress / (float) mMax : 0;
+        int range = mMax - mMin;
+        final float scale = range > 0 ? (progress - mMin) / (float) range : 0;
         final boolean isPrimary = id == R.id.progress;
 
         if (isPrimary && animate) {
@@ -1436,7 +1442,7 @@
             return false;
         }
 
-        progress = MathUtils.constrain(progress, 0, mMax);
+        progress = MathUtils.constrain(progress, mMin, mMax);
 
         if (progress == mProgress) {
             // No change from current.
@@ -1466,8 +1472,8 @@
             return;
         }
 
-        if (secondaryProgress < 0) {
-            secondaryProgress = 0;
+        if (secondaryProgress < mMin) {
+            secondaryProgress = mMin;
         }
 
         if (secondaryProgress > mMax) {
@@ -1515,6 +1521,20 @@
     }
 
     /**
+     * <p>Return the lower limit of this progress bar's range.</p>
+     *
+     * @return a positive integer
+     *
+     * @see #setMin(int)
+     * @see #getProgress()
+     * @see #getSecondaryProgress()
+     */
+    @ViewDebug.ExportedProperty(category = "progress")
+    public synchronized int getMin() {
+        return mMin;
+    }
+
+    /**
      * <p>Return the upper limit of this progress bar's range.</p>
      *
      * @return a positive integer
@@ -1529,7 +1549,37 @@
     }
 
     /**
-     * <p>Set the range of the progress bar to 0...<tt>max</tt>.</p>
+     * <p>Set the lower range of the progress bar to <tt>min</tt>.</p>
+     *
+     * @param min the lower range of this progress bar
+     *
+     * @see #getMin()
+     * @see #setProgress(int)
+     * @see #setSecondaryProgress(int)
+     */
+    @android.view.RemotableViewMethod
+    public synchronized void setMin(int min) {
+        if (mMaxInitialized) {
+            if (min > mMax) {
+                min = mMax;
+            }
+        }
+        mMinInitialized = true;
+        if (mMaxInitialized && min != mMin) {
+            mMin = min;
+            postInvalidate();
+
+            if (mProgress < min) {
+                mProgress = min;
+            }
+            refreshProgress(R.id.progress, mProgress, false, false);
+        } else {
+            mMin = min;
+        }
+    }
+
+    /**
+     * <p>Set the upper range of the progress bar <tt>max</tt>.</p>
      *
      * @param max the upper range of this progress bar
      *
@@ -1539,10 +1589,13 @@
      */
     @android.view.RemotableViewMethod
     public synchronized void setMax(int max) {
-        if (max < 0) {
-            max = 0;
+        if (mMinInitialized) {
+            if (max < mMin) {
+                max = mMin;
+            }
         }
-        if (max != mMax) {
+        mMaxInitialized = true;
+        if (mMinInitialized && max != mMax) {
             mMax = max;
             postInvalidate();
 
@@ -1550,6 +1603,8 @@
                 mProgress = max;
             }
             refreshProgress(R.id.progress, mProgress, false, false);
+        } else {
+            mMax = max;
         }
     }
 
@@ -1959,7 +2014,7 @@
     @Override
     public void onInitializeAccessibilityEventInternal(AccessibilityEvent event) {
         super.onInitializeAccessibilityEventInternal(event);
-        event.setItemCount(mMax);
+        event.setItemCount(mMax - mMin);
         event.setCurrentItemIndex(mProgress);
     }
 
diff --git a/core/java/android/widget/QuickContactBadge.java b/core/java/android/widget/QuickContactBadge.java
index 8c15cde..8f6b0d5 100644
--- a/core/java/android/widget/QuickContactBadge.java
+++ b/core/java/android/widget/QuickContactBadge.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.content.AsyncQueryHandler;
 import android.content.ContentResolver;
 import android.content.Context;
@@ -38,6 +36,8 @@
 import android.view.View;
 import android.view.View.OnClickListener;
 
+import com.android.internal.R;
+
 /**
  * Widget used to show an image with the standard QuickContact badge
  * and on-click behavior.
diff --git a/core/java/android/widget/RadialTimePickerView.java b/core/java/android/widget/RadialTimePickerView.java
index 5a0e1f9..757a4ca 100644
--- a/core/java/android/widget/RadialTimePickerView.java
+++ b/core/java/android/widget/RadialTimePickerView.java
@@ -16,10 +16,6 @@
 
 package android.widget;
 
-import android.view.PointerIcon;
-import com.android.internal.R;
-import com.android.internal.widget.ExploreByTouchHelper;
-
 import android.animation.ObjectAnimator;
 import android.annotation.IntDef;
 import android.content.Context;
@@ -43,11 +39,15 @@
 import android.util.TypedValue;
 import android.view.HapticFeedbackConstants;
 import android.view.MotionEvent;
+import android.view.PointerIcon;
 import android.view.View;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
 
+import com.android.internal.R;
+import com.android.internal.widget.ExploreByTouchHelper;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.Calendar;
diff --git a/core/java/android/widget/RadioGroup.java b/core/java/android/widget/RadioGroup.java
index 065feb8..54b5763 100644
--- a/core/java/android/widget/RadioGroup.java
+++ b/core/java/android/widget/RadioGroup.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.IdRes;
 import android.content.Context;
 import android.content.res.TypedArray;
@@ -25,6 +23,8 @@
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.android.internal.R;
+
 
 /**
  * <p>This class is used to create a multiple-exclusion scope for a set of radio
@@ -39,14 +39,14 @@
  * in the XML layout file.</p>
  *
  * <p><strong>XML Attributes</strong></p>
- * <p>See {@link android.R.styleable#RadioGroup RadioGroup Attributes}, 
+ * <p>See {@link android.R.styleable#RadioGroup RadioGroup Attributes},
  * {@link android.R.styleable#LinearLayout LinearLayout Attributes},
  * {@link android.R.styleable#ViewGroup ViewGroup Attributes},
  * {@link android.R.styleable#View View Attributes}</p>
  * <p>Also see
  * {@link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams}
  * for layout attributes.</p>
- * 
+ *
  * @see RadioButton
  *
  */
@@ -310,7 +310,7 @@
             } else {
                 width = WRAP_CONTENT;
             }
-            
+
             if (a.hasValue(heightAttr)) {
                 height = a.getLayoutDimension(heightAttr, "layout_height");
             } else {
diff --git a/core/java/android/widget/RatingBar.java b/core/java/android/widget/RatingBar.java
index 62dd90f..3b7fe86 100644
--- a/core/java/android/widget/RatingBar.java
+++ b/core/java/android/widget/RatingBar.java
@@ -22,6 +22,7 @@
 import android.graphics.drawable.shapes.Shape;
 import android.util.AttributeSet;
 import android.view.accessibility.AccessibilityNodeInfo;
+
 import com.android.internal.R;
 
 /**
diff --git a/core/java/android/widget/RelativeLayout.java b/core/java/android/widget/RelativeLayout.java
index a189d3c..b424101 100644
--- a/core/java/android/widget/RelativeLayout.java
+++ b/core/java/android/widget/RelativeLayout.java
@@ -16,20 +16,14 @@
 
 package android.widget;
 
+import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
+
 import android.annotation.NonNull;
-import android.util.ArrayMap;
-import com.android.internal.R;
-
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Rect;
 import android.os.Build;
+import android.util.ArrayMap;
 import android.util.AttributeSet;
 import android.util.Pools.SynchronizedPool;
 import android.util.SparseArray;
@@ -41,7 +35,13 @@
 import android.view.accessibility.AccessibilityEvent;
 import android.widget.RemoteViews.RemoteView;
 
-import static android.os.Build.VERSION_CODES.JELLY_BEAN_MR1;
+import com.android.internal.R;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.SortedSet;
+import java.util.TreeSet;
 
 /**
  * A Layout where the positions of the children can be described in relation to each other or to the
@@ -209,7 +209,7 @@
     private int mIgnoreGravity;
 
     private SortedSet<View> mTopToBottomLeftToRightSet = null;
-    
+
     private boolean mDirtyHierarchy;
     private View[] mSortedHorizontalChildren;
     private View[] mSortedVerticalChildren;
diff --git a/core/java/android/widget/RemoteViews.java b/core/java/android/widget/RemoteViews.java
index 2a6e01f..6543d0c 100644
--- a/core/java/android/widget/RemoteViews.java
+++ b/core/java/android/widget/RemoteViews.java
@@ -59,11 +59,12 @@
 import android.view.View.OnClickListener;
 import android.view.ViewGroup;
 import android.widget.AdapterView.OnItemClickListener;
-import libcore.util.Objects;
 
 import com.android.internal.R;
 import com.android.internal.util.Preconditions;
 
+import libcore.util.Objects;
+
 import java.lang.annotation.ElementType;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
diff --git a/core/java/android/widget/RemoteViewsAdapter.java b/core/java/android/widget/RemoteViewsAdapter.java
index 10abbab..e0f94fd 100644
--- a/core/java/android/widget/RemoteViewsAdapter.java
+++ b/core/java/android/widget/RemoteViewsAdapter.java
@@ -16,13 +16,6 @@
 
 package android.widget;
 
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-
 import android.Manifest;
 import android.appwidget.AppWidgetHostView;
 import android.appwidget.AppWidgetManager;
@@ -48,6 +41,11 @@
 import com.android.internal.widget.IRemoteViewsAdapterConnection;
 import com.android.internal.widget.IRemoteViewsFactory;
 
+import java.lang.ref.WeakReference;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.LinkedList;
+
 /**
  * An adapter to a RemoteViewsService which fetches and caches RemoteViews
  * to be later inflated as child views.
diff --git a/core/java/android/widget/RemoteViewsService.java b/core/java/android/widget/RemoteViewsService.java
index 07bd918..2827f63 100644
--- a/core/java/android/widget/RemoteViewsService.java
+++ b/core/java/android/widget/RemoteViewsService.java
@@ -16,14 +16,14 @@
 
 package android.widget;
 
-import java.util.HashMap;
-
 import android.app.Service;
 import android.content.Intent;
 import android.os.IBinder;
 
 import com.android.internal.widget.IRemoteViewsFactory;
 
+import java.util.HashMap;
+
 /**
  * The service to be connected to for a remote adapter to request RemoteViews.  Users should
  * extend the RemoteViewsService to provide the appropriate RemoteViewsFactory's used to
@@ -46,7 +46,7 @@
      * An interface for an adapter between a remote collection view (ListView, GridView, etc) and
      * the underlying data for that view.  The implementor is responsible for making a RemoteView
      * for each item in the data set. This interface is a thin wrapper around {@link Adapter}.
-     * 
+     *
      * @see android.widget.Adapter
      * @see android.appwidget.AppWidgetManager
      */
diff --git a/core/java/android/widget/ResourceCursorAdapter.java b/core/java/android/widget/ResourceCursorAdapter.java
index 100f919..9732bb1 100644
--- a/core/java/android/widget/ResourceCursorAdapter.java
+++ b/core/java/android/widget/ResourceCursorAdapter.java
@@ -20,9 +20,9 @@
 import android.content.res.Resources;
 import android.database.Cursor;
 import android.view.ContextThemeWrapper;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.LayoutInflater;
 
 
 /**
@@ -148,7 +148,7 @@
     public void setViewResource(int layout) {
         mLayout = layout;
     }
-    
+
     /**
      * <p>Sets the layout resource of the drop down views.</p>
      *
diff --git a/core/java/android/widget/ResourceCursorTreeAdapter.java b/core/java/android/widget/ResourceCursorTreeAdapter.java
index ddce515..0894dba 100644
--- a/core/java/android/widget/ResourceCursorTreeAdapter.java
+++ b/core/java/android/widget/ResourceCursorTreeAdapter.java
@@ -18,9 +18,9 @@
 
 import android.content.Context;
 import android.database.Cursor;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.LayoutInflater;
 
 /**
  * A fairly simple ExpandableListAdapter that creates views defined in an XML
@@ -32,10 +32,10 @@
     private int mChildLayout;
     private int mLastChildLayout;
     private LayoutInflater mInflater;
-    
+
     /**
      * Constructor.
-     * 
+     *
      * @param context The context where the ListView associated with this
      *            SimpleListItemFactory is running
      * @param cursor The database cursor
@@ -51,18 +51,18 @@
     public ResourceCursorTreeAdapter(Context context, Cursor cursor, int collapsedGroupLayout,
             int expandedGroupLayout, int childLayout, int lastChildLayout) {
         super(cursor, context);
-        
+
         mCollapsedGroupLayout = collapsedGroupLayout;
         mExpandedGroupLayout = expandedGroupLayout;
         mChildLayout = childLayout;
         mLastChildLayout = lastChildLayout;
-        
+
         mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     }
 
     /**
      * Constructor.
-     * 
+     *
      * @param context The context where the ListView associated with this
      *            SimpleListItemFactory is running
      * @param cursor The database cursor
@@ -80,7 +80,7 @@
 
     /**
      * Constructor.
-     * 
+     *
      * @param context The context where the ListView associated with this
      *            SimpleListItemFactory is running
      * @param cursor The database cursor
@@ -93,7 +93,7 @@
             int childLayout) {
         this(context, cursor, groupLayout, groupLayout, childLayout, childLayout);
     }
-    
+
     @Override
     public View newChildView(Context context, Cursor cursor, boolean isLastChild,
             ViewGroup parent) {
diff --git a/core/java/android/widget/ScrollBarDrawable.java b/core/java/android/widget/ScrollBarDrawable.java
index 11eab2a..2ae38c9 100644
--- a/core/java/android/widget/ScrollBarDrawable.java
+++ b/core/java/android/widget/ScrollBarDrawable.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.widget.ScrollBarUtils;
-
 import android.annotation.NonNull;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
@@ -25,6 +23,8 @@
 import android.graphics.Rect;
 import android.graphics.drawable.Drawable;
 
+import com.android.internal.widget.ScrollBarUtils;
+
 /**
  * This is only used by View for displaying its scroll bars. It should probably
  * be moved in to the view package since it is used in that lower-level layer.
diff --git a/core/java/android/widget/ScrollView.java b/core/java/android/widget/ScrollView.java
index e696ff7..d8f3379 100644
--- a/core/java/android/widget/ScrollView.java
+++ b/core/java/android/widget/ScrollView.java
@@ -17,18 +17,16 @@
 package android.widget;
 
 import android.annotation.NonNull;
-import android.content.res.Configuration;
-import android.os.Build;
-import android.os.Build.VERSION_CODES;
-import android.os.Parcel;
-import android.os.Parcelable;
-import com.android.internal.R;
-
 import android.content.Context;
+import android.content.res.Configuration;
 import android.content.res.TypedArray;
 import android.graphics.Canvas;
 import android.graphics.Rect;
+import android.os.Build;
+import android.os.Build.VERSION_CODES;
 import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
 import android.os.StrictMode;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -47,6 +45,8 @@
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.animation.AnimationUtils;
 
+import com.android.internal.R;
+
 import java.util.List;
 
 /**
diff --git a/core/java/android/widget/SeekBar.java b/core/java/android/widget/SeekBar.java
index 5d01d8d..f9aced0 100644
--- a/core/java/android/widget/SeekBar.java
+++ b/core/java/android/widget/SeekBar.java
@@ -46,8 +46,10 @@
          * to distinguish user-initiated changes from those that occurred programmatically.
          *
          * @param seekBar The SeekBar whose progress has changed
-         * @param progress The current progress level. This will be in the range 0..max where max
-         *        was set by {@link ProgressBar#setMax(int)}. (The default value for max is 100.)
+         * @param progress The current progress level. This will be in the range min..max where min
+         *                 and max were set by {@link ProgressBar#setMin(int)} and
+         *                 {@link ProgressBar#setMax(int)}, respectively. (The default values for
+         *                 min is 0 and max is 100.)
          * @param fromUser True if the progress change was initiated by the user.
          */
         void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser);
diff --git a/core/java/android/widget/SimpleAdapter.java b/core/java/android/widget/SimpleAdapter.java
index 3bf9485..9190117 100644
--- a/core/java/android/widget/SimpleAdapter.java
+++ b/core/java/android/widget/SimpleAdapter.java
@@ -20,11 +20,11 @@
 import android.annotation.LayoutRes;
 import android.content.Context;
 import android.content.res.Resources;
+import android.net.Uri;
 import android.view.ContextThemeWrapper;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.LayoutInflater;
-import android.net.Uri;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -40,7 +40,7 @@
  * Binding data to views occurs in two phases. First, if a
  * {@link android.widget.SimpleAdapter.ViewBinder} is available,
  * {@link ViewBinder#setViewValue(android.view.View, Object, String)}
- * is invoked. If the returned value is true, binding has occurred. 
+ * is invoked. If the returned value is true, binding has occurred.
  * If the returned value is false, the following views are then tried in order:
  * <ul>
  * <li> A view that implements Checkable (e.g. CheckBox).  The expected bind value is a boolean.
@@ -223,7 +223,7 @@
                         setViewText((TextView) v, text);
                     } else if (v instanceof ImageView) {
                         if (data instanceof Integer) {
-                            setViewImage((ImageView) v, (Integer) data);                            
+                            setViewImage((ImageView) v, (Integer) data);
                         } else {
                             setViewImage((ImageView) v, text);
                         }
@@ -291,7 +291,7 @@
      * @param v ImageView to receive an image
      * @param value the value retrieved from the data set
      *
-     * @see #setViewImage(ImageView, int) 
+     * @see #setViewImage(ImageView, int)
      */
     public void setViewImage(ImageView v, String value) {
         try {
@@ -381,18 +381,18 @@
                 for (int i = 0; i < count; i++) {
                     Map<String, ?> h = unfilteredValues.get(i);
                     if (h != null) {
-                        
+
                         int len = mTo.length;
 
                         for (int j=0; j<len; j++) {
                             String str =  (String)h.get(mFrom[j]);
-                            
+
                             String[] words = str.split(" ");
                             int wordCount = words.length;
-                            
+
                             for (int k = 0; k < wordCount; k++) {
                                 String word = words[k];
-                                
+
                                 if (word.toLowerCase().startsWith(prefixString)) {
                                     newValues.add(h);
                                     break;
diff --git a/core/java/android/widget/SimpleExpandableListAdapter.java b/core/java/android/widget/SimpleExpandableListAdapter.java
index 015c169..597502b 100644
--- a/core/java/android/widget/SimpleExpandableListAdapter.java
+++ b/core/java/android/widget/SimpleExpandableListAdapter.java
@@ -17,9 +17,9 @@
 package android.widget;
 
 import android.content.Context;
+import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.LayoutInflater;
 
 import java.util.List;
 import java.util.Map;
@@ -42,18 +42,18 @@
     private int mCollapsedGroupLayout;
     private String[] mGroupFrom;
     private int[] mGroupTo;
-    
+
     private List<? extends List<? extends Map<String, ?>>> mChildData;
     private int mChildLayout;
     private int mLastChildLayout;
     private String[] mChildFrom;
     private int[] mChildTo;
-    
+
     private LayoutInflater mInflater;
-    
+
     /**
      * Constructor
-     * 
+     *
      * @param context The context where the {@link ExpandableListView}
      *            associated with this {@link SimpleExpandableListAdapter} is
      *            running
@@ -98,7 +98,7 @@
 
     /**
      * Constructor
-     * 
+     *
      * @param context The context where the {@link ExpandableListView}
      *            associated with this {@link SimpleExpandableListAdapter} is
      *            running
@@ -147,7 +147,7 @@
 
     /**
      * Constructor
-     * 
+     *
      * @param context The context where the {@link ExpandableListView}
      *            associated with this {@link SimpleExpandableListAdapter} is
      *            running
@@ -200,16 +200,16 @@
         mCollapsedGroupLayout = collapsedGroupLayout;
         mGroupFrom = groupFrom;
         mGroupTo = groupTo;
-        
+
         mChildData = childData;
         mChildLayout = childLayout;
         mLastChildLayout = lastChildLayout;
         mChildFrom = childFrom;
         mChildTo = childTo;
-        
+
         mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     }
-    
+
     public Object getChild(int groupPosition, int childPosition) {
         return mChildData.get(groupPosition).get(childPosition);
     }
@@ -239,7 +239,7 @@
     public View newChildView(boolean isLastChild, ViewGroup parent) {
         return mInflater.inflate((isLastChild) ? mLastChildLayout : mChildLayout, parent, false);
     }
-    
+
     private void bindView(View view, Map<String, ?> data, String[] from, int[] to) {
         int len = to.length;
 
diff --git a/core/java/android/widget/SimpleMonthView.java b/core/java/android/widget/SimpleMonthView.java
index 8c43782..855d1d2 100644
--- a/core/java/android/widget/SimpleMonthView.java
+++ b/core/java/android/widget/SimpleMonthView.java
@@ -16,10 +16,6 @@
 
 package android.widget;
 
-import android.view.PointerIcon;
-import com.android.internal.R;
-import com.android.internal.widget.ExploreByTouchHelper;
-
 import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.ColorStateList;
@@ -43,17 +39,21 @@
 import android.util.StateSet;
 import android.view.KeyEvent;
 import android.view.MotionEvent;
+import android.view.PointerIcon;
 import android.view.View;
 import android.view.ViewParent;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
 
-import java.text.NumberFormat;
-import java.util.Locale;
+import com.android.internal.R;
+import com.android.internal.widget.ExploreByTouchHelper;
 
 import libcore.icu.LocaleData;
 
+import java.text.NumberFormat;
+import java.util.Locale;
+
 /**
  * A calendar-like view displaying a specified month and the appropriate selectable day numbers
  * within the specified month.
diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java
index dc5e5a2..28cc693 100644
--- a/core/java/android/widget/Spinner.java
+++ b/core/java/android/widget/Spinner.java
@@ -16,13 +16,9 @@
 
 package android.widget;
 
-import android.annotation.TestApi;
-import android.view.PointerIcon;
-import com.android.internal.R;
-import com.android.internal.view.menu.ShowableListMenu;
-
 import android.annotation.DrawableRes;
 import android.annotation.Nullable;
+import android.annotation.TestApi;
 import android.annotation.Widget;
 import android.app.AlertDialog;
 import android.content.Context;
@@ -42,6 +38,7 @@
 import android.view.ContextThemeWrapper;
 import android.view.Gravity;
 import android.view.MotionEvent;
+import android.view.PointerIcon;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
@@ -49,6 +46,9 @@
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.widget.PopupWindow.OnDismissListener;
 
+import com.android.internal.R;
+import com.android.internal.view.menu.ShowableListMenu;
+
 /**
  * A view that displays one child at a time and lets the user pick among them.
  * The items in the Spinner come from the {@link Adapter} associated with
@@ -123,7 +123,7 @@
      *                access the current theme, resources, etc.
      * @param mode Constant describing how the user will select choices from
      *             the spinner.
-     * 
+     *
      * @see #MODE_DIALOG
      * @see #MODE_DROPDOWN
      */
@@ -563,7 +563,7 @@
     @Override
     protected void onDetachedFromWindow() {
         super.onDetachedFromWindow();
-        
+
         if (mPopup != null && mPopup.isShowing()) {
             mPopup.dismiss();
         }
@@ -772,7 +772,7 @@
     @Override
     public boolean performClick() {
         boolean handled = super.performClick();
-        
+
         if (!handled) {
             handled = true;
 
@@ -1011,7 +1011,7 @@
 
         /**
          * If the wrapped SpinnerAdapter is also a ListAdapter, delegate this call.
-         * Otherwise, return true. 
+         * Otherwise, return true.
          */
         public boolean areAllItemsEnabled() {
             final ListAdapter adapter = mListAdapter;
@@ -1042,19 +1042,19 @@
         public int getViewTypeCount() {
             return 1;
         }
-        
+
         public boolean isEmpty() {
             return getCount() == 0;
         }
     }
-    
+
     /**
      * Implements some sort of popup selection interface for selecting a spinner option.
      * Allows for different spinner modes.
      */
     private interface SpinnerPopup {
         public void setAdapter(ListAdapter adapter);
-        
+
         /**
          * Show the popup
          */
@@ -1064,12 +1064,12 @@
          * Dismiss the popup
          */
         public void dismiss();
-        
+
         /**
          * @return true if the popup is showing, false otherwise.
          */
         public boolean isShowing();
-        
+
         /**
          * Set hint text to be displayed to the user. This should provide
          * a description of the choice being made.
@@ -1129,7 +1129,7 @@
             listView.setTextAlignment(textAlignment);
             mPopup.show();
         }
-        
+
         public void onClick(DialogInterface dialog, int which) {
             setSelection(which);
             if (mOnItemClickListener != null) {
@@ -1168,7 +1168,7 @@
             return 0;
         }
     }
-    
+
     private class DropdownPopup extends ListPopupWindow implements SpinnerPopup {
         private CharSequence mHintText;
         private ListAdapter mAdapter;
@@ -1190,7 +1190,7 @@
                 }
             });
         }
-        
+
         @Override
         public void setAdapter(ListAdapter adapter) {
             super.setAdapter(adapter);
@@ -1200,7 +1200,7 @@
         public CharSequence getHintText() {
             return mHintText;
         }
-        
+
         public void setPromptText(CharSequence hintText) {
             // Hint text is ignored for dropdowns, but maintain it here.
             mHintText = hintText;
diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java
index 2bd3143..0e99c02 100644
--- a/core/java/android/widget/StackView.java
+++ b/core/java/android/widget/StackView.java
@@ -15,8 +15,6 @@
 
 package android.widget;
 
-import java.lang.ref.WeakReference;
-
 import android.animation.ObjectAnimator;
 import android.animation.PropertyValuesHolder;
 import android.content.Context;
@@ -45,6 +43,8 @@
 import android.view.animation.LinearInterpolator;
 import android.widget.RemoteViews.RemoteView;
 
+import java.lang.ref.WeakReference;
+
 @RemoteView
 /**
  * A view that displays its children in a stack and allows users to discretely swipe
@@ -670,12 +670,12 @@
                 activeIndex = (swipeGestureType == GESTURE_SLIDE_DOWN) ? 1 : 0;
             }
 
-            boolean endOfStack = mLoopViews && adapterCount == 1 && 
-                ((mStackMode == ITEMS_SLIDE_UP && swipeGestureType == GESTURE_SLIDE_UP) ||
-                 (mStackMode == ITEMS_SLIDE_DOWN && swipeGestureType == GESTURE_SLIDE_DOWN));
-            boolean beginningOfStack = mLoopViews && adapterCount == 1 && 
-                ((mStackMode == ITEMS_SLIDE_DOWN && swipeGestureType == GESTURE_SLIDE_UP) ||
-                 (mStackMode == ITEMS_SLIDE_UP && swipeGestureType == GESTURE_SLIDE_DOWN));
+            boolean endOfStack = mLoopViews && adapterCount == 1
+                    && ((mStackMode == ITEMS_SLIDE_UP && swipeGestureType == GESTURE_SLIDE_UP)
+                    || (mStackMode == ITEMS_SLIDE_DOWN && swipeGestureType == GESTURE_SLIDE_DOWN));
+            boolean beginningOfStack = mLoopViews && adapterCount == 1
+                    && ((mStackMode == ITEMS_SLIDE_DOWN && swipeGestureType == GESTURE_SLIDE_UP)
+                    || (mStackMode == ITEMS_SLIDE_UP && swipeGestureType == GESTURE_SLIDE_DOWN));
 
             int stackMode;
             if (mLoopViews && !beginningOfStack && !endOfStack) {
diff --git a/core/java/android/widget/SuggestionsAdapter.java b/core/java/android/widget/SuggestionsAdapter.java
index aad0625..f833d1b 100644
--- a/core/java/android/widget/SuggestionsAdapter.java
+++ b/core/java/android/widget/SuggestionsAdapter.java
@@ -21,8 +21,8 @@
 import android.app.SearchableInfo;
 import android.content.ComponentName;
 import android.content.ContentResolver;
-import android.content.Context;
 import android.content.ContentResolver.OpenResourceIdResult;
+import android.content.Context;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageManager.NameNotFoundException;
@@ -39,8 +39,8 @@
 import android.util.Log;
 import android.util.TypedValue;
 import android.view.View;
-import android.view.ViewGroup;
 import android.view.View.OnClickListener;
+import android.view.ViewGroup;
 
 import com.android.internal.R;
 
@@ -111,7 +111,7 @@
         mProviderContext = mSearchable.getProviderContext(mContext, activityContext);
 
         mOutsideDrawablesCache = outsideDrawablesCache;
-        
+
         // mStartSpinnerRunnable = new Runnable() {
         // public void run() {
         // // mSearchView.setWorking(true); // TODO:
diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java
index d51c5be..fcc1667 100644
--- a/core/java/android/widget/Switch.java
+++ b/core/java/android/widget/Switch.java
@@ -30,8 +30,8 @@
 import android.graphics.Paint;
 import android.graphics.PorterDuff;
 import android.graphics.Rect;
-import android.graphics.Typeface;
 import android.graphics.Region.Op;
+import android.graphics.Typeface;
 import android.graphics.drawable.Drawable;
 import android.text.Layout;
 import android.text.StaticLayout;
@@ -46,8 +46,8 @@
 import android.view.MotionEvent;
 import android.view.SoundEffectConstants;
 import android.view.VelocityTracker;
-import android.view.ViewStructure;
 import android.view.ViewConfiguration;
+import android.view.ViewStructure;
 import android.view.accessibility.AccessibilityEvent;
 import android.view.accessibility.AccessibilityNodeInfo;
 
diff --git a/core/java/android/widget/TabHost.java b/core/java/android/widget/TabHost.java
index 583f037..32418cd 100644
--- a/core/java/android/widget/TabHost.java
+++ b/core/java/android/widget/TabHost.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.app.LocalActivityManager;
@@ -35,6 +33,9 @@
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
 import android.view.Window;
+
+import com.android.internal.R;
+
 import java.util.ArrayList;
 import java.util.List;
 
diff --git a/core/java/android/widget/TabWidget.java b/core/java/android/widget/TabWidget.java
index 1f0cb7c..05f7c0a 100644
--- a/core/java/android/widget/TabWidget.java
+++ b/core/java/android/widget/TabWidget.java
@@ -16,10 +16,6 @@
 
 package android.widget;
 
-import android.view.MotionEvent;
-import android.view.PointerIcon;
-import com.android.internal.R;
-
 import android.annotation.DrawableRes;
 import android.annotation.Nullable;
 import android.content.Context;
@@ -29,11 +25,15 @@
 import android.graphics.drawable.Drawable;
 import android.os.Build;
 import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.PointerIcon;
 import android.view.View;
 import android.view.View.OnFocusChangeListener;
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
 
+import com.android.internal.R;
+
 /**
  *
  * Displays a list of tab labels representing each page in the parent's tab
diff --git a/core/java/android/widget/TableLayout.java b/core/java/android/widget/TableLayout.java
index eed3c2d..8bb4d16 100644
--- a/core/java/android/widget/TableLayout.java
+++ b/core/java/android/widget/TableLayout.java
@@ -16,14 +16,15 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.util.AttributeSet;
 import android.util.SparseBooleanArray;
 import android.view.View;
 import android.view.ViewGroup;
+
+import com.android.internal.R;
+
 import java.util.regex.Pattern;
 
 /**
diff --git a/core/java/android/widget/TextClock.java b/core/java/android/widget/TextClock.java
index 5003c61..a6a9db4 100644
--- a/core/java/android/widget/TextClock.java
+++ b/core/java/android/widget/TextClock.java
@@ -16,6 +16,9 @@
 
 package android.widget;
 
+import static android.view.ViewDebug.ExportedProperty;
+import static android.widget.RemoteViews.RemoteView;
+
 import android.annotation.NonNull;
 import android.app.ActivityManager;
 import android.content.BroadcastReceiver;
@@ -37,13 +40,10 @@
 
 import com.android.internal.R;
 
-import java.util.Calendar;
-import java.util.TimeZone;
-
 import libcore.icu.LocaleData;
 
-import static android.view.ViewDebug.ExportedProperty;
-import static android.widget.RemoteViews.*;
+import java.util.Calendar;
+import java.util.TimeZone;
 
 /**
  * <p><code>TextClock</code> can display the current date and/or time as
diff --git a/core/java/android/widget/TimePicker.java b/core/java/android/widget/TimePicker.java
index 6a76c5b..e6cd798 100644
--- a/core/java/android/widget/TimePicker.java
+++ b/core/java/android/widget/TimePicker.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.annotation.IntDef;
 import android.annotation.IntRange;
 import android.annotation.NonNull;
@@ -32,12 +30,14 @@
 import android.view.View;
 import android.view.accessibility.AccessibilityEvent;
 
+import com.android.internal.R;
+
+import libcore.icu.LocaleData;
+
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.Locale;
 
-import libcore.icu.LocaleData;
-
 /**
  * A widget for selecting the time of day, in either 24-hour or AM/PM mode.
  * <p>
diff --git a/core/java/android/widget/TimePickerSpinnerDelegate.java b/core/java/android/widget/TimePickerSpinnerDelegate.java
index 26e1564..6a68f60 100644
--- a/core/java/android/widget/TimePickerSpinnerDelegate.java
+++ b/core/java/android/widget/TimePickerSpinnerDelegate.java
@@ -16,6 +16,9 @@
 
 package android.widget;
 
+import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
+import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_YES;
+
 import android.annotation.TestApi;
 import android.content.Context;
 import android.content.res.TypedArray;
@@ -29,14 +32,12 @@
 import android.view.accessibility.AccessibilityEvent;
 import android.view.inputmethod.EditorInfo;
 import android.view.inputmethod.InputMethodManager;
-import com.android.internal.R;
 
-import java.util.Calendar;
+import com.android.internal.R;
 
 import libcore.icu.LocaleData;
 
-import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_AUTO;
-import static android.view.View.IMPORTANT_FOR_ACCESSIBILITY_YES;
+import java.util.Calendar;
 
 /**
  * A delegate implementing the basic spinner-based TimePicker.
diff --git a/core/java/android/widget/TwoLineListItem.java b/core/java/android/widget/TwoLineListItem.java
index 69ff488..0445ebd 100644
--- a/core/java/android/widget/TwoLineListItem.java
+++ b/core/java/android/widget/TwoLineListItem.java
@@ -20,22 +20,21 @@
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.util.AttributeSet;
-import android.widget.RelativeLayout;
 
 /**
- * <p>A view group with two children, intended for use in ListViews. This item has two 
- * {@link android.widget.TextView TextViews} elements (or subclasses) with the ID values 
+ * <p>A view group with two children, intended for use in ListViews. This item has two
+ * {@link android.widget.TextView TextViews} elements (or subclasses) with the ID values
  * {@link android.R.id#text1 text1}
- * and {@link android.R.id#text2 text2}. There is an optional third View element with the 
- * ID {@link android.R.id#selectedIcon selectedIcon}, which can be any View subclass 
+ * and {@link android.R.id#text2 text2}. There is an optional third View element with the
+ * ID {@link android.R.id#selectedIcon selectedIcon}, which can be any View subclass
  * (though it is typically a graphic View, such as {@link android.widget.ImageView ImageView})
- * that can be displayed when a TwoLineListItem has focus. Android supplies a 
- * {@link android.R.layout#two_line_list_item standard layout resource for TwoLineListView} 
+ * that can be displayed when a TwoLineListItem has focus. Android supplies a
+ * {@link android.R.layout#two_line_list_item standard layout resource for TwoLineListView}
  * (which does not include a selected item icon), but you can design your own custom XML
  * layout for this object.
- * 
+ *
  * @attr ref android.R.styleable#TwoLineListItem_mode
- * 
+ *
  * @deprecated This class can be implemented easily by apps using a {@link RelativeLayout}
  * or a {@link LinearLayout}.
  */
@@ -51,7 +50,7 @@
     }
 
     public TwoLineListItem(Context context, AttributeSet attrs) {
-        this(context, attrs, 0); 
+        this(context, attrs, 0);
     }
 
     public TwoLineListItem(Context context, AttributeSet attrs, int defStyleAttr) {
@@ -70,11 +69,11 @@
     @Override
     protected void onFinishInflate() {
         super.onFinishInflate();
-        
+
         mText1 = (TextView) findViewById(com.android.internal.R.id.text1);
         mText2 = (TextView) findViewById(com.android.internal.R.id.text2);
     }
-    
+
     /**
      * Returns a handle to the item with ID text1.
      * @return A handle to the item with ID text1.
@@ -82,7 +81,7 @@
     public TextView getText1() {
         return mText1;
     }
-    
+
     /**
      * Returns a handle to the item with ID text2.
      * @return A handle to the item with ID text2.
diff --git a/core/java/android/widget/ViewFlipper.java b/core/java/android/widget/ViewFlipper.java
index 65af7aa..e769d71 100644
--- a/core/java/android/widget/ViewFlipper.java
+++ b/core/java/android/widget/ViewFlipper.java
@@ -21,7 +21,7 @@
 import android.content.Intent;
 import android.content.IntentFilter;
 import android.content.res.TypedArray;
-import android.os.*;
+import android.os.Message;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.widget.RemoteViews.RemoteView;
diff --git a/core/java/android/widget/YearPickerView.java b/core/java/android/widget/YearPickerView.java
index a3f5a67..824fec8 100644
--- a/core/java/android/widget/YearPickerView.java
+++ b/core/java/android/widget/YearPickerView.java
@@ -16,8 +16,6 @@
 
 package android.widget;
 
-import com.android.internal.R;
-
 import android.content.Context;
 import android.content.res.Resources;
 import android.icu.util.Calendar;
@@ -27,6 +25,8 @@
 import android.view.ViewGroup;
 import android.view.accessibility.AccessibilityEvent;
 
+import com.android.internal.R;
+
 /**
  * Displays a selectable list of years.
  */
diff --git a/core/java/android/widget/ZoomButtonsController.java b/core/java/android/widget/ZoomButtonsController.java
index fb912a4..69b79971 100644
--- a/core/java/android/widget/ZoomButtonsController.java
+++ b/core/java/android/widget/ZoomButtonsController.java
@@ -30,11 +30,11 @@
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
+import android.view.View.OnClickListener;
 import android.view.ViewConfiguration;
 import android.view.ViewGroup;
 import android.view.ViewRootImpl;
 import android.view.WindowManager;
-import android.view.View.OnClickListener;
 import android.view.WindowManager.LayoutParams;
 
 /*
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java
index a5b2a91..3b6073a 100644
--- a/core/java/com/android/internal/app/ChooserActivity.java
+++ b/core/java/com/android/internal/app/ChooserActivity.java
@@ -68,6 +68,7 @@
 import android.widget.BaseAdapter;
 import android.widget.ListView;
 import com.android.internal.R;
+import com.android.internal.app.ResolverActivity.TargetInfo;
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.MetricsProto.MetricsEvent;
 import com.google.android.collect.Lists;
@@ -345,6 +346,12 @@
     }
 
     @Override
+    public boolean shouldAutoLaunchSingleChoice(TargetInfo target) {
+        return getIntent().getBooleanExtra(Intent.EXTRA_AUTO_LAUNCH_SINGLE_CHOICE,
+                super.shouldAutoLaunchSingleChoice(target));
+    }
+
+    @Override
     public void showTargetDetails(ResolveInfo ri) {
         ComponentName name = ri.activityInfo.getComponentName();
         boolean pinned = mPinnedSharedPrefs.getBoolean(name.flattenToString(), false);
diff --git a/core/java/com/android/internal/app/procstats/ProcessState.java b/core/java/com/android/internal/app/procstats/ProcessState.java
index 8c5df08..8c2c236 100644
--- a/core/java/com/android/internal/app/procstats/ProcessState.java
+++ b/core/java/com/android/internal/app/procstats/ProcessState.java
@@ -379,7 +379,7 @@
 
     public void setState(int state, long now) {
         ensureNotDead();
-        if (mCurState != state) {
+        if (!mDead && (mCurState != state)) {
             //Slog.i(TAG, "Setting state in " + mName + "/" + mPackage + ": " + state);
             commitStateTime(now);
             mCurState = state;
diff --git a/core/java/com/android/internal/view/IInputConnectionWrapper.java b/core/java/com/android/internal/view/IInputConnectionWrapper.java
index 644c7e9..4f7b106 100644
--- a/core/java/com/android/internal/view/IInputConnectionWrapper.java
+++ b/core/java/com/android/internal/view/IInputConnectionWrapper.java
@@ -580,7 +580,13 @@
                         return;
                     }
                     if (grantUriPermission) {
-                        inputContentInfo.requestPermission();
+                        try {
+                            inputContentInfo.requestPermission();
+                        } catch (Exception e) {
+                            Log.e(TAG, "InputConnectionInfo.requestPermission() failed", e);
+                            args.callback.setCommitContentResult(false, args.seq);
+                            return;
+                        }
                     }
                     final boolean result =
                             ic.commitContent(inputContentInfo, flags, (Bundle) args.arg2);
diff --git a/core/jni/Android.mk b/core/jni/Android.mk
index 4c6350b..7950685 100644
--- a/core/jni/Android.mk
+++ b/core/jni/Android.mk
@@ -19,6 +19,14 @@
     LOCAL_CFLAGS += -DENABLE_CPUSETS
 endif
 
+# TODO: Linear blending should be enabled by default, but we are
+# TODO: making it an opt-in while it's a work in progress
+# TODO: The final test should be:
+# TODO: ifneq ($(TARGET_ENABLE_LINEAR_BLENDING),false)
+ifeq ($(TARGET_ENABLE_LINEAR_BLENDING),true)
+    LOCAL_CFLAGS += -DANDROID_ENABLE_LINEAR_BLENDING
+endif
+
 LOCAL_CFLAGS += -DGL_GLEXT_PROTOTYPES -DEGL_EGLEXT_PROTOTYPES
 
 LOCAL_CFLAGS += -DU_USING_ICU_NAMESPACE=0
@@ -214,6 +222,7 @@
 LOCAL_SHARED_LIBRARIES := \
     libmemtrack \
     libandroidfw \
+    libbase \
     libexpat \
     libnativehelper \
     liblog \
diff --git a/core/jni/android/graphics/Bitmap.cpp b/core/jni/android/graphics/Bitmap.cpp
index 2111a57..9ed1588 100755
--- a/core/jni/android/graphics/Bitmap.cpp
+++ b/core/jni/android/graphics/Bitmap.cpp
@@ -545,7 +545,8 @@
     }
 
     SkBitmap bitmap;
-    bitmap.setInfo(SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType));
+    bitmap.setInfo(SkImageInfo::Make(width, height, colorType, kPremul_SkAlphaType,
+            GraphicsJNI::defaultColorSpace()));
 
     PixelRef* nativeBitmap = GraphicsJNI::allocateHeapPixelRef(&bitmap, NULL);
     if (!nativeBitmap) {
@@ -646,7 +647,8 @@
         // Otherwise respect the premultiplied request.
         alphaType = requestPremul ? kPremul_SkAlphaType : kUnpremul_SkAlphaType;
     }
-    bitmap->pixelRef()->reconfigure(SkImageInfo::Make(width, height, colorType, alphaType));
+    bitmap->pixelRef()->reconfigure(SkImageInfo::Make(width, height, colorType, alphaType,
+            sk_sp<SkColorSpace>(bitmap->info().colorSpace())));
 }
 
 // These must match the int values in Bitmap.java
@@ -779,6 +781,7 @@
     const bool        isMutable = p->readInt32() != 0;
     const SkColorType colorType = (SkColorType)p->readInt32();
     const SkAlphaType alphaType = (SkAlphaType)p->readInt32();
+    const bool        isSRGB = p->readInt32() != 0;
     const int         width = p->readInt32();
     const int         height = p->readInt32();
     const int         rowBytes = p->readInt32();
@@ -795,7 +798,8 @@
 
     std::unique_ptr<SkBitmap> bitmap(new SkBitmap);
 
-    if (!bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType), rowBytes)) {
+    if (!bitmap->setInfo(SkImageInfo::Make(width, height, colorType, alphaType,
+            isSRGB ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named) : nullptr), rowBytes)) {
         return NULL;
     }
 
@@ -910,9 +914,13 @@
     auto androidBitmap = reinterpret_cast<Bitmap*>(bitmapHandle);
     androidBitmap->getSkBitmap(&bitmap);
 
+    sk_sp<SkColorSpace> sRGB = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+    bool isSRGB = bitmap.colorSpace() == sRGB.get();
+
     p->writeInt32(isMutable);
     p->writeInt32(bitmap.colorType());
     p->writeInt32(bitmap.alphaType());
+    p->writeInt32(isSRGB); // TODO: We should write the color space (b/32072280)
     p->writeInt32(bitmap.width());
     p->writeInt32(bitmap.height());
     p->writeInt32(bitmap.rowBytes());
@@ -1125,7 +1133,9 @@
     reinterpret_cast<Bitmap*>(bm1Handle)->getSkBitmap(&bm1);
     if (bm0.width() != bm1.width() ||
         bm0.height() != bm1.height() ||
-        bm0.colorType() != bm1.colorType()) {
+        bm0.colorType() != bm1.colorType() ||
+        bm0.alphaType() != bm1.alphaType() ||
+        bm0.colorSpace() != bm1.colorSpace()) {
         return JNI_FALSE;
     }
 
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 5bb0274..5c24585 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -385,11 +385,8 @@
     // Set the alpha type for the decode.
     SkAlphaType alphaType = codec->computeOutputAlphaType(requireUnpremultiplied);
 
-    // Enable legacy behavior to avoid any gamma correction.  Android's assets are
-    // adjusted to expect a non-gamma correct premultiply.
-    sk_sp<SkColorSpace> colorSpace = nullptr;
-    const SkImageInfo decodeInfo = SkImageInfo::Make(size.width(), size.height(), decodeColorType,
-                                                     alphaType, colorSpace);
+    const SkImageInfo decodeInfo = SkImageInfo::Make(size.width(), size.height(),
+            decodeColorType, alphaType, GraphicsJNI::defaultColorSpace());
 
     SkImageInfo bitmapInfo = decodeInfo;
     if (decodeColorType == kGray_8_SkColorType) {
@@ -413,7 +410,7 @@
 
     // Use SkAndroidCodec to perform the decode.
     SkAndroidCodec::AndroidOptions codecOptions;
-    codecOptions.fZeroInitialized =  decodeAllocator == &defaultAllocator ?
+    codecOptions.fZeroInitialized = decodeAllocator == &defaultAllocator ?
             SkCodec::kYes_ZeroInitialized : SkCodec::kNo_ZeroInitialized;
     codecOptions.fColorPtr = colorPtr;
     codecOptions.fColorCount = colorCount;
@@ -452,8 +449,10 @@
     jobject ninePatchInsets = NULL;
     if (peeker.mHasInsets) {
         ninePatchInsets = env->NewObject(gInsetStruct_class, gInsetStruct_constructorMethodID,
-                peeker.mOpticalInsets[0], peeker.mOpticalInsets[1], peeker.mOpticalInsets[2], peeker.mOpticalInsets[3],
-                peeker.mOutlineInsets[0], peeker.mOutlineInsets[1], peeker.mOutlineInsets[2], peeker.mOutlineInsets[3],
+                peeker.mOpticalInsets[0], peeker.mOpticalInsets[1],
+                peeker.mOpticalInsets[2], peeker.mOpticalInsets[3],
+                peeker.mOutlineInsets[0], peeker.mOutlineInsets[1],
+                peeker.mOutlineInsets[2], peeker.mOutlineInsets[3],
                 peeker.mOutlineRadius, peeker.mOutlineAlpha, scale);
         if (ninePatchInsets == NULL) {
             return nullObjectReturn("nine patch insets == null");
@@ -495,11 +494,11 @@
         }
 
         SkPaint paint;
-        // kSrc_Mode instructs us to overwrite the unininitialized pixels in
+        // kSrc_Mode instructs us to overwrite the uninitialized pixels in
         // outputBitmap.  Otherwise we would blend by default, which is not
         // what we want.
         paint.setXfermodeMode(SkXfermode::kSrc_Mode);
-        paint.setFilterQuality(kLow_SkFilterQuality);
+        paint.setFilterQuality(kLow_SkFilterQuality); // bilinear filtering
 
         SkCanvas canvas(outputBitmap);
         canvas.scale(sx, sy);
diff --git a/core/jni/android/graphics/Graphics.cpp b/core/jni/android/graphics/Graphics.cpp
index 8a55052..82b70fc 100644
--- a/core/jni/android/graphics/Graphics.cpp
+++ b/core/jni/android/graphics/Graphics.cpp
@@ -587,6 +587,14 @@
     return wrapper;
 }
 
+sk_sp<SkColorSpace> GraphicsJNI::defaultColorSpace() {
+#ifdef ANDROID_ENABLE_LINEAR_BLENDING
+    return SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+#else
+    return nullptr;
+#endif
+}
+
 ///////////////////////////////////////////////////////////////////////////////
 bool HeapAllocator::allocPixelRef(SkBitmap* bitmap, SkColorTable* ctable) {
     mStorage.reset(GraphicsJNI::allocateHeapPixelRef(bitmap, ctable));
diff --git a/core/jni/android/graphics/GraphicsJNI.h b/core/jni/android/graphics/GraphicsJNI.h
index 4c6a384..e5af525 100644
--- a/core/jni/android/graphics/GraphicsJNI.h
+++ b/core/jni/android/graphics/GraphicsJNI.h
@@ -10,6 +10,7 @@
 #include "SkMallocPixelRef.h"
 #include "SkPoint.h"
 #include "SkRect.h"
+#include "SkColorSpace.h"
 #include <jni.h>
 #include <hwui/Canvas.h>
 #include <hwui/PixelRef.h>
@@ -94,6 +95,8 @@
     static bool SetPixels(JNIEnv* env, jintArray colors, int srcOffset,
             int srcStride, int x, int y, int width, int height,
             const SkBitmap& dstBitmap);
+
+    static sk_sp<SkColorSpace> defaultColorSpace();
 };
 
 class HeapAllocator : public SkBRDAllocator {
diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp
index 87f754d..43f7ca5 100644
--- a/core/jni/android_graphics_Canvas.cpp
+++ b/core/jni/android_graphics_Canvas.cpp
@@ -442,9 +442,8 @@
                             jboolean hasAlpha, jlong paintHandle) {
     // Note: If hasAlpha is false, kRGB_565_SkColorType will be used, which will
     // correct the alphaType to kOpaque_SkAlphaType.
-    SkImageInfo info = SkImageInfo::Make(width, height,
-                           hasAlpha ? kN32_SkColorType : kRGB_565_SkColorType,
-                           kPremul_SkAlphaType);
+    SkImageInfo info = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType,
+            GraphicsJNI::defaultColorSpace());
     SkBitmap bitmap;
     bitmap.setInfo(info);
     if (!GraphicsJNI::allocatePixels(env, &bitmap, NULL)) {
diff --git a/core/jni/android_os_Debug.cpp b/core/jni/android_os_Debug.cpp
index 2b1353c..06f22dd 100644
--- a/core/jni/android_os_Debug.cpp
+++ b/core/jni/android_os_Debug.cpp
@@ -15,15 +15,7 @@
  */
 
 #define LOG_TAG "android.os.Debug"
-#include "JNIHelp.h"
-#include "jni.h"
-#include <utils/String8.h>
-#include "utils/misc.h"
-#include "cutils/debugger.h"
-#include <memtrack/memtrack.h>
-#include <memunreachable/memunreachable.h>
 
-#include <cutils/log.h>
 #include <fcntl.h>
 #include <inttypes.h>
 #include <stdio.h>
@@ -40,9 +32,26 @@
 #include <iomanip>
 #include <string>
 
+#include "jni.h"
+
+#include "android-base/stringprintf.h"
+#include "cutils/debugger.h"
+#include "cutils/log.h"
+#include "JNIHelp.h"
+#include "memtrack/memtrack.h"
+#include "memunreachable/memunreachable.h"
+#include "utils/misc.h"
+#include "utils/String8.h"
+
 namespace android
 {
 
+using UniqueFile = std::unique_ptr<FILE, decltype(&fclose)>;
+
+static inline UniqueFile MakeUniqueFile(const char* path, const char* mode) {
+    return UniqueFile(fopen(path, mode), fclose);
+}
+
 enum {
     HEAP_UNKNOWN,
     HEAP_DALVIK,
@@ -421,17 +430,13 @@
 
 static void load_maps(int pid, stats_t* stats, bool* foundSwapPss)
 {
-    char tmp[128];
-    FILE *fp;
-
     *foundSwapPss = false;
 
-    sprintf(tmp, "/proc/%d/smaps", pid);
-    fp = fopen(tmp, "r");
-    if (fp == 0) return;
+    std::string smaps_path = base::StringPrintf("/proc/%d/smaps", pid);
+    UniqueFile fp = MakeUniqueFile(smaps_path.c_str(), "re");
+    if (fp == nullptr) return;
 
-    read_mapinfo(fp, stats, foundSwapPss);
-    fclose(fp);
+    read_mapinfo(fp.get(), stats, foundSwapPss);
 }
 
 static void android_os_Debug_getDirtyPagesPid(JNIEnv *env, jobject clazz,
@@ -513,51 +518,48 @@
     jlong uss = 0;
     jlong memtrack = 0;
 
-    char tmp[128];
-    FILE *fp;
-
     struct graphics_memory_pss graphics_mem;
     if (read_memtrack_memory(pid, &graphics_mem) == 0) {
         pss = uss = memtrack = graphics_mem.graphics + graphics_mem.gl + graphics_mem.other;
     }
 
-    sprintf(tmp, "/proc/%d/smaps", pid);
-    fp = fopen(tmp, "r");
+    {
+        std::string smaps_path = base::StringPrintf("/proc/%d/smaps", pid);
+        UniqueFile fp = MakeUniqueFile(smaps_path.c_str(), "re");
 
-    if (fp != 0) {
-        while (true) {
-            if (fgets(line, 1024, fp) == NULL) {
-                break;
-            }
+        if (fp != nullptr) {
+            while (true) {
+                if (fgets(line, 1024, fp.get()) == NULL) {
+                    break;
+                }
 
-            if (line[0] == 'P') {
-                if (strncmp(line, "Pss:", 4) == 0) {
-                    char* c = line + 4;
+                if (line[0] == 'P') {
+                    if (strncmp(line, "Pss:", 4) == 0) {
+                        char* c = line + 4;
+                        while (*c != 0 && (*c < '0' || *c > '9')) {
+                            c++;
+                        }
+                        pss += atoi(c);
+                    } else if (strncmp(line, "Private_Clean:", 14) == 0
+                                || strncmp(line, "Private_Dirty:", 14) == 0) {
+                        char* c = line + 14;
+                        while (*c != 0 && (*c < '0' || *c > '9')) {
+                            c++;
+                        }
+                        uss += atoi(c);
+                    }
+                } else if (line[0] == 'S' && strncmp(line, "SwapPss:", 8) == 0) {
+                    char* c = line + 8;
+                    jlong lSwapPss;
                     while (*c != 0 && (*c < '0' || *c > '9')) {
                         c++;
                     }
-                    pss += atoi(c);
-                } else if (strncmp(line, "Private_Clean:", 14) == 0
-                        || strncmp(line, "Private_Dirty:", 14) == 0) {
-                    char* c = line + 14;
-                    while (*c != 0 && (*c < '0' || *c > '9')) {
-                        c++;
-                    }
-                    uss += atoi(c);
+                    lSwapPss = atoi(c);
+                    swapPss += lSwapPss;
+                    pss += lSwapPss; // Also in swap, those pages would be accounted as Pss without SWAP
                 }
-            } else if (line[0] == 'S' && strncmp(line, "SwapPss:", 8) == 0) {
-                char* c = line + 8;
-                jlong lSwapPss;
-                while (*c != 0 && (*c < '0' || *c > '9')) {
-                    c++;
-                }
-                lSwapPss = atoi(c);
-                swapPss += lSwapPss;
-                pss += lSwapPss; // Also in swap, those pages would be accounted as Pss without SWAP
             }
         }
-
-        fclose(fp);
     }
 
     if (outUssSwapPss != NULL) {
@@ -601,12 +603,14 @@
             NULL
     };
     long size, vmalloc_allocated_size = 0;
-    FILE* fp = fopen("/proc/vmallocinfo", "r");
-    if (fp == NULL) {
+
+    UniqueFile fp = MakeUniqueFile("/proc/vmallocinfo", "re");
+    if (fp == nullptr) {
         return 0;
     }
+
     while (true) {
-        if (fgets(line, 1024, fp) == NULL) {
+        if (fgets(line, 1024, fp.get()) == NULL) {
             break;
         }
         bool valid_line = true;
@@ -622,7 +626,6 @@
             vmalloc_allocated_size += size;
         }
     }
-    fclose(fp);
     return vmalloc_allocated_size;
 }
 
@@ -646,27 +649,25 @@
 static long long get_zram_mem_used()
 {
 #define ZRAM_SYSFS "/sys/block/zram0/"
-    FILE *f = fopen(ZRAM_SYSFS "mm_stat", "r");
-    if (f) {
+    UniqueFile mm_stat_file = MakeUniqueFile(ZRAM_SYSFS "mm_stat", "re");
+    if (mm_stat_file) {
         long long mem_used_total = 0;
 
-        int matched = fscanf(f, "%*d %*d %lld %*d %*d %*d %*d", &mem_used_total);
+        int matched = fscanf(mm_stat_file.get(), "%*d %*d %lld %*d %*d %*d %*d", &mem_used_total);
         if (matched != 1)
             ALOGW("failed to parse " ZRAM_SYSFS "mm_stat");
 
-        fclose(f);
         return mem_used_total;
     }
 
-    f = fopen(ZRAM_SYSFS "mem_used_total", "r");
-    if (f) {
+    UniqueFile mem_used_total_file = MakeUniqueFile(ZRAM_SYSFS "mem_used_total", "re");
+    if (mem_used_total_file) {
         long long mem_used_total = 0;
 
-        int matched = fscanf(f, "%lld", &mem_used_total);
+        int matched = fscanf(mem_used_total_file.get(), "%lld", &mem_used_total);
         if (matched != 1)
             ALOGW("failed to parse " ZRAM_SYSFS "mem_used_total");
 
-        fclose(f);
         return mem_used_total;
     }
 
@@ -779,8 +780,8 @@
 
 static jint read_binder_stat(const char* stat)
 {
-    FILE* fp = fopen(BINDER_STATS, "r");
-    if (fp == NULL) {
+    UniqueFile fp = MakeUniqueFile(BINDER_STATS, "re");
+    if (fp == nullptr) {
         return -1;
     }
 
@@ -791,8 +792,7 @@
 
     // loop until we have the block that represents this process
     do {
-        if (fgets(line, 1024, fp) == 0) {
-            fclose(fp);
+        if (fgets(line, 1024, fp.get()) == 0) {
             return -1;
         }
     } while (strncmp(compare, line, len));
@@ -801,8 +801,7 @@
     len = snprintf(compare, 128, "  %s: ", stat);
 
     do {
-        if (fgets(line, 1024, fp) == 0) {
-            fclose(fp);
+        if (fgets(line, 1024, fp.get()) == 0) {
             return -1;
         }
     } while (strncmp(compare, line, len));
@@ -810,7 +809,6 @@
     // we have the line, now increment the line ptr to the value
     char* ptr = line + len;
     jint result = atoi(ptr);
-    fclose(fp);
     return result;
 }
 
@@ -956,16 +954,15 @@
 
     fprintf(fp, "MAPS\n");
     const char* maps = "/proc/self/maps";
-    FILE* in = fopen(maps, "r");
-    if (in == NULL) {
+    UniqueFile in = MakeUniqueFile(maps, "re");
+    if (in == nullptr) {
         fprintf(fp, "Could not open %s\n", maps);
         return;
     }
     char buf[BUFSIZ];
-    while (size_t n = fread(buf, sizeof(char), BUFSIZ, in)) {
+    while (size_t n = fread(buf, sizeof(char), BUFSIZ, in.get())) {
         fwrite(buf, sizeof(char), n, fp);
     }
-    fclose(in);
 
     fprintf(fp, "END\n");
 }
@@ -995,8 +992,8 @@
         return;
     }
 
-    FILE* fp = fdopen(fd, "w");
-    if (fp == NULL) {
+    UniqueFile fp(fdopen(fd, "w"), fclose);
+    if (fp == nullptr) {
         ALOGW("fdopen(%d) failed: %s\n", fd, strerror(errno));
         close(fd);
         jniThrowRuntimeException(env, "fdopen() failed");
@@ -1004,10 +1001,8 @@
     }
 
     ALOGD("Native heap dump starting...\n");
-    dumpNativeHeap(fp);
+    dumpNativeHeap(fp.get());
     ALOGD("Native heap dump complete.\n");
-
-    fclose(fp);
 }
 
 
diff --git a/core/jni/android_util_AssetManager.cpp b/core/jni/android_util_AssetManager.cpp
index ef32afee..5a4348e 100644
--- a/core/jni/android_util_AssetManager.cpp
+++ b/core/jni/android_util_AssetManager.cpp
@@ -31,7 +31,7 @@
 
 #include "androidfw/Asset.h"
 #include "androidfw/AssetManager.h"
-#include "androidfw/AttributeFinder.h"
+#include "androidfw/AttributeResolution.h"
 #include "androidfw/ResourceTypes.h"
 #include "android_runtime/AndroidRuntime.h"
 #include "android_util_Binder.h"
@@ -51,7 +51,6 @@
 namespace android {
 
 static const bool kThrowOnBadId = false;
-static const bool kDebugStyles = false;
 
 // ----------------------------------------------------------------------------
 
@@ -1121,30 +1120,6 @@
     theme->dumpToLog();
 }
 
-class XmlAttributeFinder : public BackTrackingAttributeFinder<XmlAttributeFinder, jsize> {
-public:
-    explicit XmlAttributeFinder(const ResXMLParser* parser)
-        : BackTrackingAttributeFinder(0, parser != NULL ? parser->getAttributeCount() : 0)
-        , mParser(parser) {}
-
-    inline uint32_t getAttribute(jsize index) const {
-        return mParser->getAttributeNameResID(index);
-    }
-
-private:
-    const ResXMLParser* mParser;
-};
-
-class BagAttributeFinder : public BackTrackingAttributeFinder<BagAttributeFinder, const ResTable::bag_entry*> {
-public:
-    BagAttributeFinder(const ResTable::bag_entry* start, const ResTable::bag_entry* end)
-        : BackTrackingAttributeFinder(start, end) {}
-
-    inline uint32_t getAttribute(const ResTable::bag_entry* entry) const {
-        return entry->map.name.ident;
-    }
-};
-
 static jboolean android_content_AssetManager_resolveAttrs(JNIEnv* env, jobject clazz,
                                                           jlong themeToken,
                                                           jint defStyleAttr,
@@ -1167,16 +1142,6 @@
         return JNI_FALSE;
     }
 
-    if (kDebugStyles) {
-        ALOGI("APPLY STYLE: theme=0x%" PRIx64 " defStyleAttr=0x%x "
-              "defStyleRes=0x%x", themeToken, defStyleAttr, defStyleRes);
-    }
-
-    ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken);
-    const ResTable& res = theme->getResTable();
-    ResTable_config config;
-    Res_value value;
-
     const jsize NI = env->GetArrayLength(attrs);
     const jsize NV = env->GetArrayLength(outValues);
     if (NV < (NI*STYLE_NUM_ENTRIES)) {
@@ -1193,159 +1158,32 @@
     const jsize NSV = srcValues == NULL ? 0 : env->GetArrayLength(inValues);
 
     jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0);
-    jint* dest = baseDest;
-    if (dest == NULL) {
+    if (baseDest == NULL) {
         env->ReleasePrimitiveArrayCritical(attrs, src, 0);
         return JNI_FALSE;
     }
 
     jint* indices = NULL;
-    int indicesIdx = 0;
     if (outIndices != NULL) {
         if (env->GetArrayLength(outIndices) > NI) {
             indices = (jint*)env->GetPrimitiveArrayCritical(outIndices, 0);
         }
     }
 
-    // Load default style from attribute, if specified...
-    uint32_t defStyleBagTypeSetFlags = 0;
-    if (defStyleAttr != 0) {
-        Res_value value;
-        if (theme->getAttribute(defStyleAttr, &value, &defStyleBagTypeSetFlags) >= 0) {
-            if (value.dataType == Res_value::TYPE_REFERENCE) {
-                defStyleRes = value.data;
-            }
-        }
-    }
-
-    // Now lock down the resource object and start pulling stuff from it.
-    res.lock();
-
-    // Retrieve the default style bag, if requested.
-    const ResTable::bag_entry* defStyleStart = NULL;
-    uint32_t defStyleTypeSetFlags = 0;
-    ssize_t bagOff = defStyleRes != 0
-            ? res.getBagLocked(defStyleRes, &defStyleStart, &defStyleTypeSetFlags) : -1;
-    defStyleTypeSetFlags |= defStyleBagTypeSetFlags;
-    const ResTable::bag_entry* const defStyleEnd = defStyleStart + (bagOff >= 0 ? bagOff : 0);
-    BagAttributeFinder defStyleAttrFinder(defStyleStart, defStyleEnd);
-
-    // Now iterate through all of the attributes that the client has requested,
-    // filling in each with whatever data we can find.
-    ssize_t block = 0;
-    uint32_t typeSetFlags;
-    for (jsize ii=0; ii<NI; ii++) {
-        const uint32_t curIdent = (uint32_t)src[ii];
-
-        if (kDebugStyles) {
-            ALOGI("RETRIEVING ATTR 0x%08x...", curIdent);
-        }
-
-        // Try to find a value for this attribute...  we prioritize values
-        // coming from, first XML attributes, then XML style, then default
-        // style, and finally the theme.
-        value.dataType = Res_value::TYPE_NULL;
-        value.data = Res_value::DATA_NULL_UNDEFINED;
-        typeSetFlags = 0;
-        config.density = 0;
-
-        // Retrieve the current input value if available.
-        if (NSV > 0 && srcValues[ii] != 0) {
-            block = -1;
-            value.dataType = Res_value::TYPE_ATTRIBUTE;
-            value.data = srcValues[ii];
-            if (kDebugStyles) {
-                ALOGI("-> From values: type=0x%x, data=0x%08x", value.dataType, value.data);
-            }
-        }
-
-        if (value.dataType == Res_value::TYPE_NULL) {
-            const ResTable::bag_entry* const defStyleEntry = defStyleAttrFinder.find(curIdent);
-            if (defStyleEntry != defStyleEnd) {
-                block = defStyleEntry->stringBlock;
-                typeSetFlags = defStyleTypeSetFlags;
-                value = defStyleEntry->map.value;
-                if (kDebugStyles) {
-                    ALOGI("-> From def style: type=0x%x, data=0x%08x", value.dataType, value.data);
-                }
-            }
-        }
-
-        uint32_t resid = 0;
-        if (value.dataType != Res_value::TYPE_NULL) {
-            // Take care of resolving the found resource to its final value.
-            ssize_t newBlock = theme->resolveAttributeReference(&value, block,
-                    &resid, &typeSetFlags, &config);
-            if (newBlock >= 0) block = newBlock;
-            if (kDebugStyles) {
-                ALOGI("-> Resolved attr: type=0x%x, data=0x%08x", value.dataType, value.data);
-            }
-        } else {
-            // If we still don't have a value for this attribute, try to find
-            // it in the theme!
-            ssize_t newBlock = theme->getAttribute(curIdent, &value, &typeSetFlags);
-            if (newBlock >= 0) {
-                if (kDebugStyles) {
-                    ALOGI("-> From theme: type=0x%x, data=0x%08x", value.dataType, value.data);
-                }
-                newBlock = res.resolveReference(&value, block, &resid,
-                        &typeSetFlags, &config);
-                if (kThrowOnBadId) {
-                    if (newBlock == BAD_INDEX) {
-                        jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!");
-                        return JNI_FALSE;
-                    }
-                }
-                if (newBlock >= 0) block = newBlock;
-                if (kDebugStyles) {
-                    ALOGI("-> Resolved theme: type=0x%x, data=0x%08x", value.dataType, value.data);
-                }
-            }
-        }
-
-        // Deal with the special @null value -- it turns back to TYPE_NULL.
-        if (value.dataType == Res_value::TYPE_REFERENCE && value.data == 0) {
-            if (kDebugStyles) {
-                ALOGI("-> Setting to @null!");
-            }
-            value.dataType = Res_value::TYPE_NULL;
-            value.data = Res_value::DATA_NULL_UNDEFINED;
-            block = -1;
-        }
-
-        if (kDebugStyles) {
-            ALOGI("Attribute 0x%08x: type=0x%x, data=0x%08x", curIdent, value.dataType,
-                  value.data);
-        }
-
-        // Write the final value back to Java.
-        dest[STYLE_TYPE] = value.dataType;
-        dest[STYLE_DATA] = value.data;
-        dest[STYLE_ASSET_COOKIE] =
-            block != -1 ? reinterpret_cast<jint>(res.getTableCookie(block)) : (jint)-1;
-        dest[STYLE_RESOURCE_ID] = resid;
-        dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags;
-        dest[STYLE_DENSITY] = config.density;
-
-        if (indices != NULL && value.dataType != Res_value::TYPE_NULL) {
-            indicesIdx++;
-            indices[indicesIdx] = ii;
-        }
-
-        dest += STYLE_NUM_ENTRIES;
-    }
-
-    res.unlock();
+    ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken);
+    bool result = resolveAttrs(theme, defStyleAttr, defStyleRes,
+                               (uint32_t*) srcValues, NSV,
+                               (uint32_t*) src, NI,
+                               (uint32_t*) baseDest,
+                               (uint32_t*) indices);
 
     if (indices != NULL) {
-        indices[0] = indicesIdx;
         env->ReleasePrimitiveArrayCritical(outIndices, indices, 0);
     }
     env->ReleasePrimitiveArrayCritical(outValues, baseDest, 0);
     env->ReleasePrimitiveArrayCritical(inValues, srcValues, 0);
     env->ReleasePrimitiveArrayCritical(attrs, src, 0);
-
-    return JNI_TRUE;
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
 static jboolean android_content_AssetManager_applyStyle(JNIEnv* env, jobject clazz,
@@ -1370,18 +1208,6 @@
         return JNI_FALSE;
     }
 
-    if (kDebugStyles) {
-    ALOGI("APPLY STYLE: theme=0x%" PRIx64 " defStyleAttr=0x%x defStyleRes=0x%x "
-          "xml=0x%" PRIx64, themeToken, defStyleAttr, defStyleRes,
-          xmlParserToken);
-    }
-
-    ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken);
-    const ResTable& res = theme->getResTable();
-    ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken);
-    ResTable_config config;
-    Res_value value;
-
     const jsize NI = env->GetArrayLength(attrs);
     const jsize NV = env->GetArrayLength(outValues);
     if (NV < (NI*STYLE_NUM_ENTRIES)) {
@@ -1395,211 +1221,32 @@
     }
 
     jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0);
-    jint* dest = baseDest;
-    if (dest == NULL) {
+    if (baseDest == NULL) {
         env->ReleasePrimitiveArrayCritical(attrs, src, 0);
         return JNI_FALSE;
     }
 
     jint* indices = NULL;
-    int indicesIdx = 0;
     if (outIndices != NULL) {
         if (env->GetArrayLength(outIndices) > NI) {
             indices = (jint*)env->GetPrimitiveArrayCritical(outIndices, 0);
         }
     }
 
-    // Load default style from attribute, if specified...
-    uint32_t defStyleBagTypeSetFlags = 0;
-    if (defStyleAttr != 0) {
-        Res_value value;
-        if (theme->getAttribute(defStyleAttr, &value, &defStyleBagTypeSetFlags) >= 0) {
-            if (value.dataType == Res_value::TYPE_REFERENCE) {
-                defStyleRes = value.data;
-            }
-        }
-    }
-
-    // Retrieve the style class associated with the current XML tag.
-    int style = 0;
-    uint32_t styleBagTypeSetFlags = 0;
-    if (xmlParser != NULL) {
-        ssize_t idx = xmlParser->indexOfStyle();
-        if (idx >= 0 && xmlParser->getAttributeValue(idx, &value) >= 0) {
-            if (value.dataType == value.TYPE_ATTRIBUTE) {
-                if (theme->getAttribute(value.data, &value, &styleBagTypeSetFlags) < 0) {
-                    value.dataType = Res_value::TYPE_NULL;
-                }
-            }
-            if (value.dataType == value.TYPE_REFERENCE) {
-                style = value.data;
-            }
-        }
-    }
-
-    // Now lock down the resource object and start pulling stuff from it.
-    res.lock();
-
-    // Retrieve the default style bag, if requested.
-    const ResTable::bag_entry* defStyleAttrStart = NULL;
-    uint32_t defStyleTypeSetFlags = 0;
-    ssize_t bagOff = defStyleRes != 0
-            ? res.getBagLocked(defStyleRes, &defStyleAttrStart, &defStyleTypeSetFlags) : -1;
-    defStyleTypeSetFlags |= defStyleBagTypeSetFlags;
-    const ResTable::bag_entry* const defStyleAttrEnd = defStyleAttrStart + (bagOff >= 0 ? bagOff : 0);
-    BagAttributeFinder defStyleAttrFinder(defStyleAttrStart, defStyleAttrEnd);
-
-    // Retrieve the style class bag, if requested.
-    const ResTable::bag_entry* styleAttrStart = NULL;
-    uint32_t styleTypeSetFlags = 0;
-    bagOff = style != 0 ? res.getBagLocked(style, &styleAttrStart, &styleTypeSetFlags) : -1;
-    styleTypeSetFlags |= styleBagTypeSetFlags;
-    const ResTable::bag_entry* const styleAttrEnd = styleAttrStart + (bagOff >= 0 ? bagOff : 0);
-    BagAttributeFinder styleAttrFinder(styleAttrStart, styleAttrEnd);
-
-    // Retrieve the XML attributes, if requested.
-    static const ssize_t kXmlBlock = 0x10000000;
-    XmlAttributeFinder xmlAttrFinder(xmlParser);
-    const jsize xmlAttrEnd = xmlParser != NULL ? xmlParser->getAttributeCount() : 0;
-
-    // Now iterate through all of the attributes that the client has requested,
-    // filling in each with whatever data we can find.
-    ssize_t block = 0;
-    uint32_t typeSetFlags;
-    for (jsize ii = 0; ii < NI; ii++) {
-        const uint32_t curIdent = (uint32_t)src[ii];
-
-        if (kDebugStyles) {
-            ALOGI("RETRIEVING ATTR 0x%08x...", curIdent);
-        }
-
-        // Try to find a value for this attribute...  we prioritize values
-        // coming from, first XML attributes, then XML style, then default
-        // style, and finally the theme.
-        value.dataType = Res_value::TYPE_NULL;
-        value.data = Res_value::DATA_NULL_UNDEFINED;
-        typeSetFlags = 0;
-        config.density = 0;
-
-        // Walk through the xml attributes looking for the requested attribute.
-        const jsize xmlAttrIdx = xmlAttrFinder.find(curIdent);
-        if (xmlAttrIdx != xmlAttrEnd) {
-            // We found the attribute we were looking for.
-            block = kXmlBlock;
-            xmlParser->getAttributeValue(xmlAttrIdx, &value);
-            if (kDebugStyles) {
-                ALOGI("-> From XML: type=0x%x, data=0x%08x", value.dataType, value.data);
-            }
-        }
-
-        if (value.dataType == Res_value::TYPE_NULL) {
-            // Walk through the style class values looking for the requested attribute.
-            const ResTable::bag_entry* const styleAttrEntry = styleAttrFinder.find(curIdent);
-            if (styleAttrEntry != styleAttrEnd) {
-                // We found the attribute we were looking for.
-                block = styleAttrEntry->stringBlock;
-                typeSetFlags = styleTypeSetFlags;
-                value = styleAttrEntry->map.value;
-                if (kDebugStyles) {
-                    ALOGI("-> From style: type=0x%x, data=0x%08x", value.dataType, value.data);
-                }
-            }
-        }
-
-        if (value.dataType == Res_value::TYPE_NULL) {
-            // Walk through the default style values looking for the requested attribute.
-            const ResTable::bag_entry* const defStyleAttrEntry = defStyleAttrFinder.find(curIdent);
-            if (defStyleAttrEntry != defStyleAttrEnd) {
-                // We found the attribute we were looking for.
-                block = defStyleAttrEntry->stringBlock;
-                typeSetFlags = styleTypeSetFlags;
-                value = defStyleAttrEntry->map.value;
-                if (kDebugStyles) {
-                    ALOGI("-> From def style: type=0x%x, data=0x%08x", value.dataType, value.data);
-                }
-            }
-        }
-
-        uint32_t resid = 0;
-        if (value.dataType != Res_value::TYPE_NULL) {
-            // Take care of resolving the found resource to its final value.
-            ssize_t newBlock = theme->resolveAttributeReference(&value, block,
-                    &resid, &typeSetFlags, &config);
-            if (newBlock >= 0) {
-                block = newBlock;
-            }
-
-            if (kDebugStyles) {
-                ALOGI("-> Resolved attr: type=0x%x, data=0x%08x", value.dataType, value.data);
-            }
-        } else {
-            // If we still don't have a value for this attribute, try to find
-            // it in the theme!
-            ssize_t newBlock = theme->getAttribute(curIdent, &value, &typeSetFlags);
-            if (newBlock >= 0) {
-                if (kDebugStyles) {
-                    ALOGI("-> From theme: type=0x%x, data=0x%08x", value.dataType, value.data);
-                }
-                newBlock = res.resolveReference(&value, block, &resid,
-                        &typeSetFlags, &config);
-                if (kThrowOnBadId) {
-                    if (newBlock == BAD_INDEX) {
-                        jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!");
-                        return JNI_FALSE;
-                    }
-                }
-
-                if (newBlock >= 0) {
-                    block = newBlock;
-                }
-
-                if (kDebugStyles) {
-                    ALOGI("-> Resolved theme: type=0x%x, data=0x%08x", value.dataType, value.data);
-                }
-            }
-        }
-
-        // Deal with the special @null value -- it turns back to TYPE_NULL.
-        if (value.dataType == Res_value::TYPE_REFERENCE && value.data == 0) {
-            if (kDebugStyles) {
-                ALOGI("-> Setting to @null!");
-            }
-            value.dataType = Res_value::TYPE_NULL;
-            value.data = Res_value::DATA_NULL_UNDEFINED;
-            block = kXmlBlock;
-        }
-
-        if (kDebugStyles) {
-            ALOGI("Attribute 0x%08x: type=0x%x, data=0x%08x", curIdent, value.dataType, value.data);
-        }
-
-        // Write the final value back to Java.
-        dest[STYLE_TYPE] = value.dataType;
-        dest[STYLE_DATA] = value.data;
-        dest[STYLE_ASSET_COOKIE] = block != kXmlBlock ?
-            static_cast<jint>(res.getTableCookie(block)) : -1;
-        dest[STYLE_RESOURCE_ID] = resid;
-        dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags;
-        dest[STYLE_DENSITY] = config.density;
-
-        if (indices != NULL && value.dataType != Res_value::TYPE_NULL) {
-            indicesIdx++;
-            indices[indicesIdx] = ii;
-        }
-
-        dest += STYLE_NUM_ENTRIES;
-    }
-
-    res.unlock();
+    ResTable::Theme* theme = reinterpret_cast<ResTable::Theme*>(themeToken);
+    ResXMLParser* xmlParser = reinterpret_cast<ResXMLParser*>(xmlParserToken);
+    bool result = applyStyle(theme, xmlParser,
+                             defStyleAttr, defStyleRes,
+                             (uint32_t*) src, NI,
+                             (uint32_t*) baseDest,
+                             (uint32_t*) indices);
 
     if (indices != NULL) {
-        indices[0] = indicesIdx;
         env->ReleasePrimitiveArrayCritical(outIndices, indices, 0);
     }
     env->ReleasePrimitiveArrayCritical(outValues, baseDest, 0);
     env->ReleasePrimitiveArrayCritical(attrs, src, 0);
-
-    return JNI_TRUE;
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
 static jboolean android_content_AssetManager_retrieveAttributes(JNIEnv* env, jobject clazz,
@@ -1627,8 +1274,6 @@
     }
     const ResTable& res(am->getResources());
     ResXMLParser* xmlParser = (ResXMLParser*)xmlParserToken;
-    ResTable_config config;
-    Res_value value;
 
     const jsize NI = env->GetArrayLength(attrs);
     const jsize NV = env->GetArrayLength(outValues);
@@ -1643,108 +1288,29 @@
     }
 
     jint* baseDest = (jint*)env->GetPrimitiveArrayCritical(outValues, 0);
-    jint* dest = baseDest;
-    if (dest == NULL) {
+    if (baseDest == NULL) {
         env->ReleasePrimitiveArrayCritical(attrs, src, 0);
         return JNI_FALSE;
     }
 
     jint* indices = NULL;
-    int indicesIdx = 0;
     if (outIndices != NULL) {
         if (env->GetArrayLength(outIndices) > NI) {
             indices = (jint*)env->GetPrimitiveArrayCritical(outIndices, 0);
         }
     }
 
-    // Now lock down the resource object and start pulling stuff from it.
-    res.lock();
-
-    // Retrieve the XML attributes, if requested.
-    const jsize NX = xmlParser->getAttributeCount();
-    jsize ix=0;
-    uint32_t curXmlAttr = xmlParser->getAttributeNameResID(ix);
-
-    static const ssize_t kXmlBlock = 0x10000000;
-
-    // Now iterate through all of the attributes that the client has requested,
-    // filling in each with whatever data we can find.
-    ssize_t block = 0;
-    uint32_t typeSetFlags;
-    for (jsize ii=0; ii<NI; ii++) {
-        const uint32_t curIdent = (uint32_t)src[ii];
-
-        // Try to find a value for this attribute...
-        value.dataType = Res_value::TYPE_NULL;
-        value.data = Res_value::DATA_NULL_UNDEFINED;
-        typeSetFlags = 0;
-        config.density = 0;
-
-        // Skip through XML attributes until the end or the next possible match.
-        while (ix < NX && curIdent > curXmlAttr) {
-            ix++;
-            curXmlAttr = xmlParser->getAttributeNameResID(ix);
-        }
-        // Retrieve the current XML attribute if it matches, and step to next.
-        if (ix < NX && curIdent == curXmlAttr) {
-            block = kXmlBlock;
-            xmlParser->getAttributeValue(ix, &value);
-            ix++;
-            curXmlAttr = xmlParser->getAttributeNameResID(ix);
-        }
-
-        //printf("Attribute 0x%08x: type=0x%x, data=0x%08x\n", curIdent, value.dataType, value.data);
-        uint32_t resid = 0;
-        if (value.dataType != Res_value::TYPE_NULL) {
-            // Take care of resolving the found resource to its final value.
-            //printf("Resolving attribute reference\n");
-            ssize_t newBlock = res.resolveReference(&value, block, &resid,
-                    &typeSetFlags, &config);
-            if (kThrowOnBadId) {
-                if (newBlock == BAD_INDEX) {
-                    jniThrowException(env, "java/lang/IllegalStateException", "Bad resource!");
-                    return JNI_FALSE;
-                }
-            }
-            if (newBlock >= 0) block = newBlock;
-        }
-
-        // Deal with the special @null value -- it turns back to TYPE_NULL.
-        if (value.dataType == Res_value::TYPE_REFERENCE && value.data == 0) {
-            value.dataType = Res_value::TYPE_NULL;
-            value.data = Res_value::DATA_NULL_UNDEFINED;
-        }
-
-        //printf("Attribute 0x%08x: final type=0x%x, data=0x%08x\n", curIdent, value.dataType, value.data);
-
-        // Write the final value back to Java.
-        dest[STYLE_TYPE] = value.dataType;
-        dest[STYLE_DATA] = value.data;
-        dest[STYLE_ASSET_COOKIE] =
-            block != kXmlBlock ? reinterpret_cast<jint>(res.getTableCookie(block)) : (jint)-1;
-        dest[STYLE_RESOURCE_ID] = resid;
-        dest[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags;
-        dest[STYLE_DENSITY] = config.density;
-
-        if (indices != NULL && value.dataType != Res_value::TYPE_NULL) {
-            indicesIdx++;
-            indices[indicesIdx] = ii;
-        }
-
-        dest += STYLE_NUM_ENTRIES;
-    }
-
-    res.unlock();
+    bool result = retrieveAttributes(&res, xmlParser,
+                                     (uint32_t*) src, NI,
+                                     (uint32_t*) baseDest,
+                                     (uint32_t*) indices);
 
     if (indices != NULL) {
-        indices[0] = indicesIdx;
         env->ReleasePrimitiveArrayCritical(outIndices, indices, 0);
     }
-
     env->ReleasePrimitiveArrayCritical(outValues, baseDest, 0);
     env->ReleasePrimitiveArrayCritical(attrs, src, 0);
-
-    return JNI_TRUE;
+    return result ? JNI_TRUE : JNI_FALSE;
 }
 
 static jint android_content_AssetManager_getArraySize(JNIEnv* env, jobject clazz,
diff --git a/core/jni/android_view_GraphicBuffer.cpp b/core/jni/android_view_GraphicBuffer.cpp
index 59c337b..1743731 100644
--- a/core/jni/android_view_GraphicBuffer.cpp
+++ b/core/jni/android_view_GraphicBuffer.cpp
@@ -182,7 +182,8 @@
     SkBitmap bitmap;
     bitmap.setInfo(SkImageInfo::Make(buffer->getWidth(), buffer->getHeight(),
                                      convertPixelFormat(buffer->getPixelFormat()),
-                                     kPremul_SkAlphaType),
+                                     kPremul_SkAlphaType,
+                                     GraphicsJNI::defaultColorSpace()),
                    bytesCount);
 
     if (buffer->getWidth() > 0 && buffer->getHeight() > 0) {
diff --git a/core/jni/android_view_Surface.cpp b/core/jni/android_view_Surface.cpp
index 3f2b924..b6c81cf8 100644
--- a/core/jni/android_view_Surface.cpp
+++ b/core/jni/android_view_Surface.cpp
@@ -318,11 +318,11 @@
         return 0;
     }
 
-
     SkImageInfo info = SkImageInfo::Make(outBuffer.width, outBuffer.height,
                                          convertPixelFormat(outBuffer.format),
-                                         outBuffer.format == PIXEL_FORMAT_RGBX_8888 ?
-                                         kOpaque_SkAlphaType : kPremul_SkAlphaType);
+                                         outBuffer.format == PIXEL_FORMAT_RGBX_8888
+                                                 ? kOpaque_SkAlphaType : kPremul_SkAlphaType,
+                                         GraphicsJNI::defaultColorSpace());
 
     SkBitmap bitmap;
     ssize_t bpr = outBuffer.stride * bytesPerPixel(outBuffer.format);
diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp
index 5d53b3f..65f12ac 100644
--- a/core/jni/android_view_SurfaceControl.cpp
+++ b/core/jni/android_view_SurfaceControl.cpp
@@ -175,7 +175,9 @@
     }
     SkImageInfo screenshotInfo = SkImageInfo::Make(screenshot->getWidth(),
                                                    screenshot->getHeight(),
-                                                   colorType, alphaType);
+                                                   colorType,
+                                                   alphaType,
+                                                   GraphicsJNI::defaultColorSpace());
 
     const size_t rowBytes =
             screenshot->getStride() * android::bytesPerPixel(screenshot->getFormat());
diff --git a/core/jni/android_view_TextureView.cpp b/core/jni/android_view_TextureView.cpp
index e185281..268aec5 100644
--- a/core/jni/android_view_TextureView.cpp
+++ b/core/jni/android_view_TextureView.cpp
@@ -90,7 +90,8 @@
         default:
             break;
     }
-    return SkImageInfo::Make(buffer.width, buffer.height, colorType, alphaType);
+    return SkImageInfo::Make(buffer.width, buffer.height, colorType, alphaType,
+            GraphicsJNI::defaultColorSpace());
 }
 
 /**
diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp
index 309bb2f..14dcb3f 100644
--- a/core/jni/android_view_ThreadedRenderer.cpp
+++ b/core/jni/android_view_ThreadedRenderer.cpp
@@ -613,21 +613,6 @@
     return atoi(prop) > 0 ? JNI_TRUE : JNI_FALSE;
 }
 
-static void android_view_ThreadedRenderer_setAtlas(JNIEnv* env, jobject clazz,
-        jlong proxyPtr, jobject graphicBuffer, jlongArray atlasMapArray) {
-    sp<GraphicBuffer> buffer = graphicBufferForJavaObject(env, graphicBuffer);
-    jsize len = env->GetArrayLength(atlasMapArray);
-    if (len <= 0) {
-        ALOGW("Failed to initialize atlas, invalid map length: %d", len);
-        return;
-    }
-    int64_t* map = new int64_t[len];
-    env->GetLongArrayRegion(atlasMapArray, 0, len, map);
-
-    RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
-    proxy->setTextureAtlas(buffer, map, len);
-}
-
 static void android_view_ThreadedRenderer_setProcessStatsBuffer(JNIEnv* env, jobject clazz,
         jlong proxyPtr, jint fd) {
     RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
@@ -955,7 +940,6 @@
 
 static const JNINativeMethod gMethods[] = {
     { "nSupportsOpenGL", "()Z", (void*) android_view_ThreadedRenderer_supportsOpenGL },
-    { "nSetAtlas", "(JLandroid/view/GraphicBuffer;[J)V",   (void*) android_view_ThreadedRenderer_setAtlas },
     { "nSetProcessStatsBuffer", "(JI)V", (void*) android_view_ThreadedRenderer_setProcessStatsBuffer },
     { "nGetRenderThreadTid", "(J)I", (void*) android_view_ThreadedRenderer_getRenderThreadTid },
     { "nCreateRootRenderNode", "()J", (void*) android_view_ThreadedRenderer_createRootRenderNode },
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 0942a24..c346849 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -436,6 +436,7 @@
 
     <protected-broadcast android:name="ScheduleConditionProvider.EVALUATE" />
     <protected-broadcast android:name="EventConditionProvider.EVALUATE" />
+    <protected-broadcast android:name="SnoozeHelper.EVALUATE" />
     <protected-broadcast android:name="wifi_scan_available" />
 
     <protected-broadcast android:name="action.cne.started" />
@@ -3044,7 +3045,7 @@
     <!-- @SystemApi Allows access to MAC addresses of WiFi and Bluetooth peer devices.
         @hide -->
     <permission android:name="android.permission.PEERS_MAC_ADDRESS"
-                android:protectionLevel="signature" />
+                android:protectionLevel="signature|setup" />
 
     <!-- Allows the Nfc stack to dispatch Nfc messages to applications. Applications
         can use this permission to ensure incoming Nfc messages are from the Nfc stack
diff --git a/core/res/res/color/background_cache_hint_selector_device_default.xml b/core/res/res/color/background_cache_hint_selector_device_default.xml
new file mode 100644
index 0000000..4470754
--- /dev/null
+++ b/core/res/res/color/background_cache_hint_selector_device_default.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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_accelerated="false" android:color="?attr/colorBackground" />
+    <item android:color="@android:color/transparent" />
+</selector>
+
diff --git a/core/res/res/layout-round-watch/alert_dialog_title_material.xml b/core/res/res/layout-round-watch/alert_dialog_title_material.xml
index 0279911..7e71e41 100644
--- a/core/res/res/layout-round-watch/alert_dialog_title_material.xml
+++ b/core/res/res/layout-round-watch/alert_dialog_title_material.xml
@@ -24,6 +24,7 @@
             android:maxHeight="24dp"
             android:maxWidth="24dp"
             android:layout_marginTop="12dp"
+            android:layout_gravity="center_horizontal"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:src="@null" />
diff --git a/core/res/res/values-b+sr+Latn/strings.xml b/core/res/res/values-b+sr+Latn/strings.xml
index 3469f97..2509eae 100644
--- a/core/res/res/values-b+sr+Latn/strings.xml
+++ b/core/res/res/values-b+sr+Latn/strings.xml
@@ -152,7 +152,7 @@
     <string name="httpErrorAuth" msgid="1435065629438044534">"Nije moguće potvrditi autentičnost."</string>
     <string name="httpErrorProxyAuth" msgid="1788207010559081331">"Potvrda identiteta preko proksi servera nije uspela."</string>
     <string name="httpErrorConnect" msgid="8714273236364640549">"Nije moguće povezati se sa serverom."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"Nije moguće komunicirati sa serverom. Pokušajte ponovo kasnije."</string>
+    <string name="httpErrorIO" msgid="2340558197489302188">"Nije moguće komunicirati sa serverom. Probajte ponovo kasnije."</string>
     <string name="httpErrorTimeout" msgid="4743403703762883954">"Veza sa serverom je istekla."</string>
     <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"Stranica sadrži previše veza za preusmeravanje sa servera."</string>
     <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"Protokol nije podržan."</string>
@@ -160,7 +160,7 @@
     <string name="httpErrorBadUrl" msgid="3636929722728881972">"Stranicu nije moguće otvoriti zato što je URL adresa nevažeća."</string>
     <string name="httpErrorFile" msgid="2170788515052558676">"Nije moguće pristupiti datoteci."</string>
     <string name="httpErrorFileNotFound" msgid="6203856612042655084">"Nije moguće pronaći traženu datoteku."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"Previše zahteva se obrađuje. Pokušajte ponovo kasnije."</string>
+    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"Previše zahteva se obrađuje. Probajte ponovo kasnije."</string>
     <string name="notification_title" msgid="8967710025036163822">"Greška pri prijavljivanju za <xliff:g id="ACCOUNT">%1$s</xliff:g>"</string>
     <string name="contentServiceSync" msgid="8353523060269335667">"Sinhronizacija"</string>
     <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"Sinhronizacija"</string>
@@ -440,19 +440,19 @@
     <string name="permdesc_manageFingerprint" msgid="178208705828055464">"Dozvoljava aplikaciji da aktivira metode za dodavanje i brisanje šablona otisaka prstiju koji će se koristiti."</string>
     <string name="permlab_useFingerprint" msgid="3150478619915124905">"koristi hardver za otiske prstiju"</string>
     <string name="permdesc_useFingerprint" msgid="9165097460730684114">"Dozvoljava aplikaciji da koristi hardver za otiske prstiju radi potvrde autentičnosti"</string>
-    <string name="fingerprint_acquired_partial" msgid="735082772341716043">"Otkriven je delimični otisak prsta. Pokušajte ponovo."</string>
-    <string name="fingerprint_acquired_insufficient" msgid="4596546021310923214">"Nije uspela obrada otiska prsta. Pokušajte ponovo."</string>
+    <string name="fingerprint_acquired_partial" msgid="735082772341716043">"Otkriven je delimični otisak prsta. Probajte ponovo."</string>
+    <string name="fingerprint_acquired_insufficient" msgid="4596546021310923214">"Nije uspela obrada otiska prsta. Probajte ponovo."</string>
     <string name="fingerprint_acquired_imager_dirty" msgid="1087209702421076105">"Senzor za otiske prstiju je prljav. Očistite ga i pokušajte ponovo."</string>
-    <string name="fingerprint_acquired_too_fast" msgid="6470642383109155969">"Prebrzo ste pomerili prst. Pokušajte ponovo."</string>
-    <string name="fingerprint_acquired_too_slow" msgid="59250885689661653">"Previše sporo ste pomerili prst. Pokušajte ponovo."</string>
+    <string name="fingerprint_acquired_too_fast" msgid="6470642383109155969">"Prebrzo ste pomerili prst. Probajte ponovo."</string>
+    <string name="fingerprint_acquired_too_slow" msgid="59250885689661653">"Previše sporo ste pomerili prst. Probajte ponovo."</string>
   <string-array name="fingerprint_acquired_vendor">
   </string-array>
     <string name="fingerprint_error_hw_not_available" msgid="7955921658939936596">"Hardver za otiske prstiju nije dostupan."</string>
     <string name="fingerprint_error_no_space" msgid="1055819001126053318">"Nije moguće sačuvati otisak prsta. Uklonite neki od postojećih otisaka prstiju."</string>
-    <string name="fingerprint_error_timeout" msgid="3927186043737732875">"Vremensko ograničenje za otisak prsta je isteklo. Pokušajte ponovo."</string>
+    <string name="fingerprint_error_timeout" msgid="3927186043737732875">"Vremensko ograničenje za otisak prsta je isteklo. Probajte ponovo."</string>
     <string name="fingerprint_error_canceled" msgid="4402024612660774395">"Radnja sa otiskom prsta je otkazana."</string>
-    <string name="fingerprint_error_lockout" msgid="5536934748136933450">"Previše pokušaja. Pokušajte ponovo kasnije."</string>
-    <string name="fingerprint_error_unable_to_process" msgid="6107816084103552441">"Pokušajte ponovo."</string>
+    <string name="fingerprint_error_lockout" msgid="5536934748136933450">"Previše pokušaja. Probajte ponovo kasnije."</string>
+    <string name="fingerprint_error_unable_to_process" msgid="6107816084103552441">"Probajte ponovo."</string>
     <string name="fingerprint_name_template" msgid="5870957565512716938">"Prst <xliff:g id="FINGERID">%d</xliff:g>"</string>
   <string-array name="fingerprint_error_vendor">
   </string-array>
@@ -680,8 +680,8 @@
     <string name="lockscreen_emergency_call" msgid="5298642613417801888">"Hitne službe"</string>
     <string name="lockscreen_return_to_call" msgid="5244259785500040021">"Nazad na poziv"</string>
     <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"Tačno!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Pokušajte ponovo"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Pokušajte ponovo"</string>
+    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Probajte ponovo"</string>
+    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Probajte ponovo"</string>
     <string name="lockscreen_storage_locked" msgid="9167551160010625200">"Otključaj za sve funkcije i podatke"</string>
     <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Premašen je najveći dozvoljeni broj pokušaja Otključavanja licem"</string>
     <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"Nema SIM kartice"</string>
@@ -705,19 +705,19 @@
     <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"Pogledajte Korisnički vodič ili kontaktirajte Korisničku podršku."</string>
     <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM kartica je zaključana."</string>
     <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"Otključavanje SIM kartice…"</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste nepravilno nacrtali šablon za otključavanje. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste pogrešno uneli lozinku. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste pogrešno uneli PIN. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste netačno uneli šablon za otključavanje. Nakon još <xliff:g id="NUMBER_1">%2$d</xliff:g> nesupešna(ih) pokušaja, od vas će biti zatraženo da otključate tablet pomoću podataka za prijavljivanje na Google.\n\n Pokušajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tv" msgid="5316664559603394684">"Neispravno ste nacrtali šablon za otključavanje <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja od vas će biti zatraženo da otključate TV pomoću podataka za prijavljivanje na Google.\n\n Pokušajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sek."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste netačno uneli šablon za otključavanje. Nakon još <xliff:g id="NUMBER_1">%2$d</xliff:g> nesupešna(ih) pokušaja, od vas će biti zatraženo da otključate telefon pomoću podataka za prijavljivanje na Google.\n\n Pokušajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
+    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste nepravilno nacrtali šablon za otključavanje. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste pogrešno uneli lozinku. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste pogrešno uneli PIN. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste netačno uneli šablon za otključavanje. Nakon još <xliff:g id="NUMBER_1">%2$d</xliff:g> nesupešna(ih) pokušaja, od vas će biti zatraženo da otključate tablet pomoću podataka za prijavljivanje na Google.\n\n Probajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
+    <string name="lockscreen_failed_attempts_almost_glogin" product="tv" msgid="5316664559603394684">"Neispravno ste nacrtali šablon za otključavanje <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja od vas će biti zatraženo da otključate TV pomoću podataka za prijavljivanje na Google.\n\n Probajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sek."</string>
+    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"<xliff:g id="NUMBER_0">%1$d</xliff:g> puta ste netačno uneli šablon za otključavanje. Nakon još <xliff:g id="NUMBER_1">%2$d</xliff:g> nesupešna(ih) pokušaja, od vas će biti zatraženo da otključate telefon pomoću podataka za prijavljivanje na Google.\n\n Probajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
     <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"Nepravilno ste pokušali da otključate tablet <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Nakon još neuspešnih pokušaja (<xliff:g id="NUMBER_1">%2$d</xliff:g>) tablet će biti resetovan na fabrička podešavanja i svi korisnički podaci će biti izgubljeni."</string>
     <string name="lockscreen_failed_attempts_almost_at_wipe" product="tv" msgid="950408382418270260">"Pokušali ste da otključate TV netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja TV će biti resetovan na podrazumevana fabrička podešavanja i svi korisnički podaci će biti izgubljeni."</string>
     <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"Neispravno ste pokušali da otključate telefon <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Nakon još neuspešnih pokušaja (<xliff:g id="NUMBER_1">%2$d</xliff:g>) telefon će biti resetovan na fabrička podešavanja i svi korisnički podaci će biti izgubljeni."</string>
     <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"Neispravno ste pokušali da otključate tablet <xliff:g id="NUMBER">%d</xliff:g> puta. Tablet će sada biti vraćen na podrazumevana fabrička podešavanja."</string>
     <string name="lockscreen_failed_attempts_now_wiping" product="tv" msgid="3195755534096192191">"Pokušali ste da otključate TV netačno <xliff:g id="NUMBER">%d</xliff:g> puta. TV će sada biti resetovan na podrazumevana fabrička podešavanja."</string>
     <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"Neispravno ste pokušali da otključate telefon <xliff:g id="NUMBER">%d</xliff:g> puta. Telefon će sada biti vraćen na podrazumevana fabrička podešavanja."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"Pokušajte ponovo za <xliff:g id="NUMBER">%d</xliff:g> sekunde(i)."</string>
+    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"Probajte ponovo za <xliff:g id="NUMBER">%d</xliff:g> sekunde(i)."</string>
     <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"Zaboravili ste šablon?"</string>
     <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"Otključavanje naloga"</string>
     <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"Previše pokušaja unosa šablona"</string>
@@ -1421,7 +1421,7 @@
     <string name="kg_wrong_pattern" msgid="1850806070801358830">"Pogrešan šablon"</string>
     <string name="kg_wrong_password" msgid="2333281762128113157">"Pogrešna lozinka"</string>
     <string name="kg_wrong_pin" msgid="1131306510833563801">"Pogrešan PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Pokušajte ponovo za <xliff:g id="NUMBER">%1$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Probajte ponovo za <xliff:g id="NUMBER">%1$d</xliff:g> sekunde(i)."</string>
     <string name="kg_pattern_instructions" msgid="398978611683075868">"Nacrtajte šablon"</string>
     <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Unesite PIN SIM kartice"</string>
     <string name="kg_pin_instructions" msgid="2377242233495111557">"Unesite PIN"</string>
@@ -1443,18 +1443,18 @@
     <string name="kg_login_invalid_input" msgid="5754664119319872197">"Nevažeće korisničko ime ili lozinka."</string>
     <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Zaboravili ste korisničko ime ili lozinku?\nPosetite adresu "<b>"google.com/accounts/recovery"</b>"."</string>
     <string name="kg_login_checking_password" msgid="1052685197710252395">"Provera naloga…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Uneli ste netačni PIN <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Uneli ste netačnu lozinku <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Uneli ste netačni PIN <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Uneli ste netačnu lozinku <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Pokušali ste da otključate tablet netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Nakon još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja tablet će biti resetovan na fabrička podešavanja i svi korisnički podaci će biti izgubljeni."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="tv" msgid="5621231220154419413">"Pokušali ste da otključate TV netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja TV će biti resetovan na podrazumevana fabrička podešavanja i svi korisnički podaci će biti izgubljeni."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Pokušali ste da otključate telefon netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja telefon će biti resetovan na fabrička podešavanja i svi korisnički podaci će biti izgubljeni."</string>
     <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Pokušali ste da otključate tablet netačno <xliff:g id="NUMBER">%d</xliff:g> puta. Tablet će sada biti vraćen na podrazumevana fabrička podešavanja."</string>
     <string name="kg_failed_attempts_now_wiping" product="tv" msgid="4987878286750741463">"Pokušali ste da otključate TV netačno <xliff:g id="NUMBER">%d</xliff:g> puta. TV će sada biti resetovan na podrazumevana fabrička podešavanja."</string>
     <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Pokušali ste da otključate telefon netačno <xliff:g id="NUMBER">%d</xliff:g> puta. Telefon će sada biti vraćen na podrazumevana fabrička podešavanja."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate tablet pomoću naloga e-pošte.\n\nPokušajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tv" msgid="4224651132862313471">"Neispravno ste nacrtali šablon za otključavanje <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate TV pomoću naloga e-pošte.\n\n Pokušajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sek."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate telefon pomoću naloga e-pošte.\n\nPokušajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate tablet pomoću naloga e-pošte.\n\nProbajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="tv" msgid="4224651132862313471">"Neispravno ste nacrtali šablon za otključavanje <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate TV pomoću naloga e-pošte.\n\n Probajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sek."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate telefon pomoću naloga e-pošte.\n\nProbajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
     <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" – "</string>
     <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Ukloni"</string>
     <string name="safe_media_volume_warning" product="default" msgid="2276318909314492312">"Želite da pojačate zvuk iznad preporučenog nivoa?\n\nSlušanje glasne muzike duže vreme može da vam ošteti sluh."</string>
@@ -1565,14 +1565,14 @@
     <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"Novi PIN"</string>
     <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"Potvrdite novi PIN"</string>
     <string name="restr_pin_create_pin" msgid="8017600000263450337">"Napravite PIN za izmenu ograničenja"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN-ovi se ne podudaraju. Pokušajte ponovo."</string>
+    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN-ovi se ne podudaraju. Probajte ponovo."</string>
     <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN je prekratak. Mora da sadrži najmanje 4 cifre."</string>
     <plurals name="restr_pin_countdown" formatted="false" msgid="9061246974881224688">
-      <item quantity="one">Pokušajte ponovo za <xliff:g id="COUNT">%d</xliff:g> sekundu</item>
-      <item quantity="few">Pokušajte ponovo za <xliff:g id="COUNT">%d</xliff:g> sekunde</item>
-      <item quantity="other">Pokušajte ponovo za <xliff:g id="COUNT">%d</xliff:g> sekundi</item>
+      <item quantity="one">Probajte ponovo za <xliff:g id="COUNT">%d</xliff:g> sekundu</item>
+      <item quantity="few">Probajte ponovo za <xliff:g id="COUNT">%d</xliff:g> sekunde</item>
+      <item quantity="other">Probajte ponovo za <xliff:g id="COUNT">%d</xliff:g> sekundi</item>
     </plurals>
-    <string name="restr_pin_try_later" msgid="973144472490532377">"Pokušajte ponovo kasnije"</string>
+    <string name="restr_pin_try_later" msgid="973144472490532377">"Probajte ponovo kasnije"</string>
     <string name="immersive_cling_title" msgid="8394201622932303336">"Prikazuje se ceo ekran"</string>
     <string name="immersive_cling_description" msgid="3482371193207536040">"Da biste izašli, prevucite nadole odozgo."</string>
     <string name="immersive_cling_positive" msgid="5016839404568297683">"Važi"</string>
diff --git a/core/res/res/values-de/strings.xml b/core/res/res/values-de/strings.xml
index f453024..05155ca 100644
--- a/core/res/res/values-de/strings.xml
+++ b/core/res/res/values-de/strings.xml
@@ -417,7 +417,7 @@
     <string name="permdesc_changeWifiMulticastState" product="default" msgid="6851949706025349926">"Ermöglicht der App, Pakete zu empfangen, die mithilfe von Multicast-Adressen an sämtliche Geräte in einem WLAN versendet wurden, nicht nur an dein Telefon. Dies nimmt mehr Leistung in Anspruch als der Nicht-Multicast-Modus."</string>
     <string name="permlab_bluetoothAdmin" msgid="6006967373935926659">"Auf Bluetooth-Einstellungen zugreifen"</string>
     <string name="permdesc_bluetoothAdmin" product="tablet" msgid="6921177471748882137">"Ermöglicht der App, das lokale Bluetooth-Tablet zu konfigurieren, Remote-Geräte zu erkennen und eine Verbindung zu diesen herzustellen"</string>
-    <string name="permdesc_bluetoothAdmin" product="tv" msgid="3373125682645601429">"Ermöglicht der App, den lokalen Bluetooth-Fernseher zu konfigurieren, Remote-Geräte zu erkennen und ein Pairing mit diesen durchzuführen"</string>
+    <string name="permdesc_bluetoothAdmin" product="tv" msgid="3373125682645601429">"Ermöglicht der App, den lokalen Bluetooth-Fernseher zu konfigurieren, Remote-Geräte zu erkennen und eine Kopplung mit ihnen durchzuführen"</string>
     <string name="permdesc_bluetoothAdmin" product="default" msgid="8931682159331542137">"Ermöglicht der App, das lokale Bluetooth-Telefon zu konfigurieren, Remote-Geräte zu erkennen und eine Verbindung zu diesen herzustellen"</string>
     <string name="permlab_accessWimaxState" msgid="4195907010610205703">"WiMAX-Verbindungen herstellen und trennen"</string>
     <string name="permdesc_accessWimaxState" msgid="6360102877261978887">"Ermöglicht der App festzustellen, ob WiMAX aktiviert ist. Zudem kann sie Informationen zu verbundenen WiMAX-Netzwerken abrufen."</string>
@@ -425,9 +425,9 @@
     <string name="permdesc_changeWimaxState" product="tablet" msgid="3156456504084201805">"Ermöglicht der App, eine Verbindung zwischen dem Tablet und WiMAX-Netzwerken herzustellen und solche zu trennen."</string>
     <string name="permdesc_changeWimaxState" product="tv" msgid="6022307083934827718">"Ermöglicht der App, eine Verbindung zwischen dem Fernseher und WiMAX-Netzwerken herzustellen und diese zu trennen"</string>
     <string name="permdesc_changeWimaxState" product="default" msgid="697025043004923798">"Ermöglicht der App, eine Verbindung zwischen dem Telefon und WiMAX-Netzwerken herzustellen und solche zu trennen."</string>
-    <string name="permlab_bluetooth" msgid="6127769336339276828">"Pairing mit Bluetooth-Geräten durchführen"</string>
+    <string name="permlab_bluetooth" msgid="6127769336339276828">"Kopplung mit Bluetooth-Geräten durchführen"</string>
     <string name="permdesc_bluetooth" product="tablet" msgid="3480722181852438628">"Ermöglicht der App, die Bluetooth-Konfiguration eines Tablets einzusehen und Verbindungen zu gekoppelten Geräten herzustellen und zu akzeptieren."</string>
-    <string name="permdesc_bluetooth" product="tv" msgid="3974124940101104206">"Ermöglicht der App, die Bluetooth-Konfiguration des Fernsehers einzusehen und Verbindungen zu Pairing-Geräten herzustellen und zu akzeptieren"</string>
+    <string name="permdesc_bluetooth" product="tv" msgid="3974124940101104206">"Ermöglicht der App, die Bluetooth-Konfiguration des Fernsehers abzurufen und Verbindungen zu gekoppelten Geräten herzustellen und zu akzeptieren"</string>
     <string name="permdesc_bluetooth" product="default" msgid="3207106324452312739">"Ermöglicht der App, die Bluetooth-Konfiguration des Telefons einzusehen und Verbindungen mit gekoppelten Geräten herzustellen und zu akzeptieren."</string>
     <string name="permlab_nfc" msgid="4423351274757876953">"Nahfeldkommunikation steuern"</string>
     <string name="permdesc_nfc" msgid="7120611819401789907">"Ermöglicht der App die Kommunikation mit Tags für die Nahfeldkommunikation, Karten und Readern"</string>
diff --git a/core/res/res/values-es/strings.xml b/core/res/res/values-es/strings.xml
index 7cd4ad5..77b43b1 100644
--- a/core/res/res/values-es/strings.xml
+++ b/core/res/res/values-es/strings.xml
@@ -1569,7 +1569,7 @@
     <string name="package_updated_device_owner" msgid="8856631322440187071">"Actualizado por tu administrador"</string>
     <string name="package_deleted_device_owner" msgid="7650577387493101353">"Eliminado por tu administrador"</string>
     <string name="battery_saver_description" msgid="1960431123816253034">"Para ayudar a mejorar la duración de la batería, la función de ahorro de energía reduce el rendimiento del dispositivo y limita la vibración, los servicios de ubicación y la mayor parte de la transmisión de datos en segundo plano. Es posible que las aplicaciones que se sincronizan, como las de correo y mensajes, no se actualicen a menos que las abras.\n\nLa función de ahorro de energía se desactiva automáticamente cuando el dispositivo se está cargando."</string>
-    <string name="data_saver_description" msgid="6015391409098303235">"El Economizador de Datos evita que algunas aplicaciones envíen o reciban datos en segundo plano, lo que permite reducir el uso de datos. Una aplicación activa podrá acceder a los datos, aunque con menos frecuencia. Esto significa que, por ejemplo, algunas imágenes no se muestren hasta que no las toques."</string>
+    <string name="data_saver_description" msgid="6015391409098303235">"El ahorro de datos evita que algunas aplicaciones envíen o reciban datos en segundo plano, lo que permite reducir el uso de datos. Una aplicación activa podrá acceder a los datos, aunque con menos frecuencia. Esto significa que, por ejemplo, algunas imágenes no se muestren hasta que no las toques."</string>
     <string name="data_saver_enable_title" msgid="4674073932722787417">"¿Activar ahorro de datos?"</string>
     <string name="data_saver_enable_button" msgid="7147735965247211818">"Activar"</string>
     <plurals name="zen_mode_duration_minutes_summary" formatted="false" msgid="4367877408072000848">
diff --git a/core/res/res/values-kn-rIN/strings.xml b/core/res/res/values-kn-rIN/strings.xml
index 0a9a511..b8c90d7 100644
--- a/core/res/res/values-kn-rIN/strings.xml
+++ b/core/res/res/values-kn-rIN/strings.xml
@@ -815,9 +815,9 @@
     <string name="menu_space_shortcut_label" msgid="2410328639272162537">"space"</string>
     <string name="menu_enter_shortcut_label" msgid="2743362785111309668">"enter"</string>
     <string name="menu_delete_shortcut_label" msgid="3658178007202748164">"ಅಳಿಸು"</string>
-    <string name="search_go" msgid="8298016669822141719">"ಹುಡುಕು"</string>
+    <string name="search_go" msgid="8298016669822141719">"ಹುಡುಕಿ"</string>
     <string name="search_hint" msgid="1733947260773056054">"ಹುಡುಕಿ…"</string>
-    <string name="searchview_description_search" msgid="6749826639098512120">"ಹುಡುಕು"</string>
+    <string name="searchview_description_search" msgid="6749826639098512120">"ಹುಡುಕಿ"</string>
     <string name="searchview_description_query" msgid="5911778593125355124">"ಪ್ರಶ್ನೆಯನ್ನು ಹುಡುಕಿ"</string>
     <string name="searchview_description_clear" msgid="1330281990951833033">"ಪ್ರಶ್ನೆಯನ್ನು ತೆರವುಗೊಳಿಸು"</string>
     <string name="searchview_description_submit" msgid="2688450133297983542">"ಪ್ರಶ್ನೆಯನ್ನು ಸಲ್ಲಿಸು"</string>
@@ -1211,7 +1211,7 @@
     <string name="tutorial_double_tap_to_zoom_message_short" msgid="1311810005957319690">"ಝೂಮ್‌ ನಿಯಂತ್ರಿಸಲು ಎರಡು ಬಾರಿ ಟ್ಯಾಪ್ ಮಾಡಿ"</string>
     <string name="gadget_host_error_inflating" msgid="4882004314906466162">"ವಿಜೆಟ್ ಸೇರಿಸಲು ಸಾಧ್ಯವಾಗುತ್ತಿಲ್ಲ."</string>
     <string name="ime_action_go" msgid="8320845651737369027">"ಹೋಗು"</string>
-    <string name="ime_action_search" msgid="658110271822807811">"ಹುಡುಕು"</string>
+    <string name="ime_action_search" msgid="658110271822807811">"ಹುಡುಕಿ"</string>
     <string name="ime_action_send" msgid="2316166556349314424">"ಕಳುಹಿಸು"</string>
     <string name="ime_action_next" msgid="3138843904009813834">"ಮುಂದೆ"</string>
     <string name="ime_action_done" msgid="8971516117910934605">"ಮುಗಿದಿದೆ"</string>
@@ -1269,8 +1269,8 @@
     <string name="share" msgid="1778686618230011964">"ಹಂಚು"</string>
     <string name="find" msgid="4808270900322985960">"ಹುಡುಕಿ"</string>
     <string name="websearch" msgid="4337157977400211589">"ವೆಬ್ ಹುಡುಕಾಟ"</string>
-    <string name="find_next" msgid="5742124618942193978">"ಮುಂದಿನದನ್ನು ಹುಡುಕು"</string>
-    <string name="find_previous" msgid="2196723669388360506">"ಹಿಂದಿನದನ್ನು ಹುಡುಕು"</string>
+    <string name="find_next" msgid="5742124618942193978">"ಮುಂದಿನದನ್ನು ಹುಡುಕಿ"</string>
+    <string name="find_previous" msgid="2196723669388360506">"ಹಿಂದಿನದನ್ನು ಹುಡುಕಿ"</string>
     <string name="gpsNotifTicker" msgid="5622683912616496172">"<xliff:g id="NAME">%s</xliff:g> ಅವರಿಂದ ಸ್ಥಾನ ವಿನಂತಿ"</string>
     <string name="gpsNotifTitle" msgid="5446858717157416839">"ಸ್ಥಾನ ವಿನಂತಿ"</string>
     <string name="gpsNotifMessage" msgid="1374718023224000702">"<xliff:g id="NAME">%1$s</xliff:g> (<xliff:g id="SERVICE">%2$s</xliff:g>) ಅವರಿಂದ ವಿನಂತಿಸಲಾಗಿದೆ"</string>
@@ -1650,7 +1650,7 @@
     <string name="language_picker_section_suggested" msgid="8414489646861640885">"ಸೂಚಿತ ಭಾಷೆ"</string>
     <string name="language_picker_section_all" msgid="3097279199511617537">"ಎಲ್ಲಾ ಭಾಷೆಗಳು"</string>
     <string name="region_picker_section_all" msgid="8966316787153001779">"ಎಲ್ಲಾ ಪ್ರದೇಶಗಳು"</string>
-    <string name="locale_search_menu" msgid="2560710726687249178">"ಹುಡುಕು"</string>
+    <string name="locale_search_menu" msgid="2560710726687249178">"ಹುಡುಕಿ"</string>
     <string name="work_mode_off_title" msgid="8954725060677558855">"ಕೆಲಸದ ಮೋಡ್ ಆಫ್ ಆಗಿದೆ"</string>
     <string name="work_mode_off_message" msgid="3286169091278094476">"ಅಪ್ಲಿಕೇಶನ್‌ಗಳು, ಹಿನ್ನೆಲೆ ಸಿಂಕ್ ಮತ್ತು ಇತರ ಸಂಬಂಧಿತ ವೈಶಿಷ್ಟ್ಯಗಳು ಸೇರಿದಂತೆ ನಿಮ್ಮ ಕೆಲಸದ ಪ್ರೊಫೈಲ್‌‌ ಕಾರ್ಯನಿರ್ವಹಿಸಲು ಅನುಮತಿಸಿ."</string>
     <string name="work_mode_turn_on" msgid="2062544985670564875">"ಆನ್ ಮಾಡು"</string>
diff --git a/core/res/res/values-sr/strings.xml b/core/res/res/values-sr/strings.xml
index 6e99a9b..fdf8a6d 100644
--- a/core/res/res/values-sr/strings.xml
+++ b/core/res/res/values-sr/strings.xml
@@ -152,7 +152,7 @@
     <string name="httpErrorAuth" msgid="1435065629438044534">"Није могуће потврдити аутентичност."</string>
     <string name="httpErrorProxyAuth" msgid="1788207010559081331">"Потврда идентитета преко прокси сервера није успела."</string>
     <string name="httpErrorConnect" msgid="8714273236364640549">"Није могуће повезати се са сервером."</string>
-    <string name="httpErrorIO" msgid="2340558197489302188">"Није могуће комуницирати са сервером. Покушајте поново касније."</string>
+    <string name="httpErrorIO" msgid="2340558197489302188">"Није могуће комуницирати са сервером. Пробајте поново касније."</string>
     <string name="httpErrorTimeout" msgid="4743403703762883954">"Веза са сервером је истекла."</string>
     <string name="httpErrorRedirectLoop" msgid="8679596090392779516">"Страница садржи превише веза за преусмеравање са сервера."</string>
     <string name="httpErrorUnsupportedScheme" msgid="5015730812906192208">"Протокол није подржан."</string>
@@ -160,7 +160,7 @@
     <string name="httpErrorBadUrl" msgid="3636929722728881972">"Страницу није могуће отворити зато што је URL адреса неважећа."</string>
     <string name="httpErrorFile" msgid="2170788515052558676">"Није могуће приступити датотеци."</string>
     <string name="httpErrorFileNotFound" msgid="6203856612042655084">"Није могуће пронаћи тражену датотеку."</string>
-    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"Превише захтева се обрађује. Покушајте поново касније."</string>
+    <string name="httpErrorTooManyRequests" msgid="1235396927087188253">"Превише захтева се обрађује. Пробајте поново касније."</string>
     <string name="notification_title" msgid="8967710025036163822">"Грешка при пријављивању за <xliff:g id="ACCOUNT">%1$s</xliff:g>"</string>
     <string name="contentServiceSync" msgid="8353523060269335667">"Синхронизација"</string>
     <string name="contentServiceSyncNotificationTitle" msgid="397743349191901458">"Синхронизација"</string>
@@ -440,19 +440,19 @@
     <string name="permdesc_manageFingerprint" msgid="178208705828055464">"Дозвољава апликацији да активира методе за додавање и брисање шаблона отисака прстију који ће се користити."</string>
     <string name="permlab_useFingerprint" msgid="3150478619915124905">"користи хардвер за отиске прстију"</string>
     <string name="permdesc_useFingerprint" msgid="9165097460730684114">"Дозвољава апликацији да користи хардвер за отиске прстију ради потврде аутентичности"</string>
-    <string name="fingerprint_acquired_partial" msgid="735082772341716043">"Откривен је делимични отисак прста. Покушајте поново."</string>
-    <string name="fingerprint_acquired_insufficient" msgid="4596546021310923214">"Није успела обрада отиска прста. Покушајте поново."</string>
+    <string name="fingerprint_acquired_partial" msgid="735082772341716043">"Откривен је делимични отисак прста. Пробајте поново."</string>
+    <string name="fingerprint_acquired_insufficient" msgid="4596546021310923214">"Није успела обрада отиска прста. Пробајте поново."</string>
     <string name="fingerprint_acquired_imager_dirty" msgid="1087209702421076105">"Сензор за отиске прстију је прљав. Очистите га и покушајте поново."</string>
-    <string name="fingerprint_acquired_too_fast" msgid="6470642383109155969">"Пребрзо сте померили прст. Покушајте поново."</string>
-    <string name="fingerprint_acquired_too_slow" msgid="59250885689661653">"Превише споро сте померили прст. Покушајте поново."</string>
+    <string name="fingerprint_acquired_too_fast" msgid="6470642383109155969">"Пребрзо сте померили прст. Пробајте поново."</string>
+    <string name="fingerprint_acquired_too_slow" msgid="59250885689661653">"Превише споро сте померили прст. Пробајте поново."</string>
   <string-array name="fingerprint_acquired_vendor">
   </string-array>
     <string name="fingerprint_error_hw_not_available" msgid="7955921658939936596">"Хардвер за отиске прстију није доступан."</string>
     <string name="fingerprint_error_no_space" msgid="1055819001126053318">"Није могуће сачувати отисак прста. Уклоните неки од постојећих отисака прстију."</string>
-    <string name="fingerprint_error_timeout" msgid="3927186043737732875">"Временско ограничење за отисак прста је истекло. Покушајте поново."</string>
+    <string name="fingerprint_error_timeout" msgid="3927186043737732875">"Временско ограничење за отисак прста је истекло. Пробајте поново."</string>
     <string name="fingerprint_error_canceled" msgid="4402024612660774395">"Радња са отиском прста је отказана."</string>
-    <string name="fingerprint_error_lockout" msgid="5536934748136933450">"Превише покушаја. Покушајте поново касније."</string>
-    <string name="fingerprint_error_unable_to_process" msgid="6107816084103552441">"Покушајте поново."</string>
+    <string name="fingerprint_error_lockout" msgid="5536934748136933450">"Превише покушаја. Пробајте поново касније."</string>
+    <string name="fingerprint_error_unable_to_process" msgid="6107816084103552441">"Пробајте поново."</string>
     <string name="fingerprint_name_template" msgid="5870957565512716938">"Прст <xliff:g id="FINGERID">%d</xliff:g>"</string>
   <string-array name="fingerprint_error_vendor">
   </string-array>
@@ -680,8 +680,8 @@
     <string name="lockscreen_emergency_call" msgid="5298642613417801888">"Хитне службе"</string>
     <string name="lockscreen_return_to_call" msgid="5244259785500040021">"Назад на позив"</string>
     <string name="lockscreen_pattern_correct" msgid="9039008650362261237">"Тачно!"</string>
-    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Покушајте поново"</string>
-    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Покушајте поново"</string>
+    <string name="lockscreen_pattern_wrong" msgid="4317955014948108794">"Пробајте поново"</string>
+    <string name="lockscreen_password_wrong" msgid="5737815393253165301">"Пробајте поново"</string>
     <string name="lockscreen_storage_locked" msgid="9167551160010625200">"Откључај за све функције и податке"</string>
     <string name="faceunlock_multiple_failures" msgid="754137583022792429">"Премашен је највећи дозвољени број покушаја Откључавања лицем"</string>
     <string name="lockscreen_missing_sim_message_short" msgid="5099439277819215399">"Нема SIM картице"</string>
@@ -705,19 +705,19 @@
     <string name="lockscreen_sim_puk_locked_instructions" msgid="8127916255245181063">"Погледајте Кориснички водич или контактирајте Корисничку подршку."</string>
     <string name="lockscreen_sim_locked_message" msgid="8066660129206001039">"SIM картица је закључана."</string>
     <string name="lockscreen_sim_unlock_progress_dialog_message" msgid="595323214052881264">"Откључавање SIM картице…"</string>
-    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте неправилно нацртали шаблон за откључавање. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
-    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте погрешно унели лозинку. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
-    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте погрешно унели PIN. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте нетачно унели шаблон за откључавање. Након још <xliff:g id="NUMBER_1">%2$d</xliff:g> несупешна(их) покушаја, од вас ће бити затражено да откључате таблет помоћу података за пријављивање на Google.\n\n Покушајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="tv" msgid="5316664559603394684">"Неисправно сте нацртали шаблон за откључавање <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја од вас ће бити затражено да откључате ТВ помоћу података за пријављивање на Google.\n\n Покушајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> сек."</string>
-    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте нетачно унели шаблон за откључавање. Након још <xliff:g id="NUMBER_1">%2$d</xliff:g> несупешна(их) покушаја, од вас ће бити затражено да откључате телефон помоћу података за пријављивање на Google.\n\n Покушајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
+    <string name="lockscreen_too_many_failed_attempts_dialog_message" msgid="6481623830344107222">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте неправилно нацртали шаблон за откључавање. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="lockscreen_too_many_failed_password_attempts_dialog_message" msgid="2725973286239344555">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте погрешно унели лозинку. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="lockscreen_too_many_failed_pin_attempts_dialog_message" msgid="6216672706545696955">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте погрешно унели PIN. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="lockscreen_failed_attempts_almost_glogin" product="tablet" msgid="9191611984625460820">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте нетачно унели шаблон за откључавање. Након још <xliff:g id="NUMBER_1">%2$d</xliff:g> несупешна(их) покушаја, од вас ће бити затражено да откључате таблет помоћу података за пријављивање на Google.\n\n Пробајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
+    <string name="lockscreen_failed_attempts_almost_glogin" product="tv" msgid="5316664559603394684">"Неисправно сте нацртали шаблон за откључавање <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја од вас ће бити затражено да откључате ТВ помоћу података за пријављивање на Google.\n\n Пробајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> сек."</string>
+    <string name="lockscreen_failed_attempts_almost_glogin" product="default" msgid="2590227559763762751">"<xliff:g id="NUMBER_0">%1$d</xliff:g> пута сте нетачно унели шаблон за откључавање. Након још <xliff:g id="NUMBER_1">%2$d</xliff:g> несупешна(их) покушаја, од вас ће бити затражено да откључате телефон помоћу података за пријављивање на Google.\n\n Пробајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
     <string name="lockscreen_failed_attempts_almost_at_wipe" product="tablet" msgid="6128106399745755604">"Неправилно сте покушали да откључате таблет <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. Након још неуспешних покушаја (<xliff:g id="NUMBER_1">%2$d</xliff:g>) таблет ће бити ресетован на фабричка подешавања и сви кориснички подаци ће бити изгубљени."</string>
     <string name="lockscreen_failed_attempts_almost_at_wipe" product="tv" msgid="950408382418270260">"Покушали сте да откључате ТВ нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја ТВ ће бити ресетован на подразумевана фабричка подешавања и сви кориснички подаци ће бити изгубљени."</string>
     <string name="lockscreen_failed_attempts_almost_at_wipe" product="default" msgid="8603565142156826565">"Неисправно сте покушали да откључате телефон <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. Након још неуспешних покушаја (<xliff:g id="NUMBER_1">%2$d</xliff:g>) телефон ће бити ресетован на фабричка подешавања и сви кориснички подаци ће бити изгубљени."</string>
     <string name="lockscreen_failed_attempts_now_wiping" product="tablet" msgid="280873516493934365">"Неисправно сте покушали да откључате таблет <xliff:g id="NUMBER">%d</xliff:g> пута. Таблет ће сада бити враћен на подразумевана фабричка подешавања."</string>
     <string name="lockscreen_failed_attempts_now_wiping" product="tv" msgid="3195755534096192191">"Покушали сте да откључате ТВ нетачно <xliff:g id="NUMBER">%d</xliff:g> пута. ТВ ће сада бити ресетован на подразумевана фабричка подешавања."</string>
     <string name="lockscreen_failed_attempts_now_wiping" product="default" msgid="3025504721764922246">"Неисправно сте покушали да откључате телефон <xliff:g id="NUMBER">%d</xliff:g> пута. Телефон ће сада бити враћен на подразумевана фабричка подешавања."</string>
-    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"Покушајте поново за <xliff:g id="NUMBER">%d</xliff:g> секунде(и)."</string>
+    <string name="lockscreen_too_many_failed_attempts_countdown" msgid="6251480343394389665">"Пробајте поново за <xliff:g id="NUMBER">%d</xliff:g> секунде(и)."</string>
     <string name="lockscreen_forgot_pattern_button_text" msgid="2626999449610695930">"Заборавили сте шаблон?"</string>
     <string name="lockscreen_glogin_forgot_pattern" msgid="2588521501166032747">"Откључавање налога"</string>
     <string name="lockscreen_glogin_too_many_attempts" msgid="2751368605287288808">"Превише покушаја уноса шаблона"</string>
@@ -1421,7 +1421,7 @@
     <string name="kg_wrong_pattern" msgid="1850806070801358830">"Погрешан шаблон"</string>
     <string name="kg_wrong_password" msgid="2333281762128113157">"Погрешна лозинка"</string>
     <string name="kg_wrong_pin" msgid="1131306510833563801">"Погрешан PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Покушајте поново за <xliff:g id="NUMBER">%1$d</xliff:g> секунде(и)."</string>
+    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Пробајте поново за <xliff:g id="NUMBER">%1$d</xliff:g> секунде(и)."</string>
     <string name="kg_pattern_instructions" msgid="398978611683075868">"Нацртајте шаблон"</string>
     <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Унесите PIN SIM картице"</string>
     <string name="kg_pin_instructions" msgid="2377242233495111557">"Унесите PIN"</string>
@@ -1443,18 +1443,18 @@
     <string name="kg_login_invalid_input" msgid="5754664119319872197">"Неважеће корисничко име или лозинка."</string>
     <string name="kg_login_account_recovery_hint" msgid="5690709132841752974">"Заборавили сте корисничко име или лозинку?\nПосетите адресу "<b>"google.com/accounts/recovery"</b>"."</string>
     <string name="kg_login_checking_password" msgid="1052685197710252395">"Провера налога…"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Унели сте нетачни PIN <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Унели сте нетачну лозинку <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Унели сте нетачни PIN <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Унели сте нетачну лозинку <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="1575557200627128949">"Покушали сте да откључате таблет нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. Након још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја таблет ће бити ресетован на фабричка подешавања и сви кориснички подаци ће бити изгубљени."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="tv" msgid="5621231220154419413">"Покушали сте да откључате ТВ нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја ТВ ће бити ресетован на подразумевана фабричка подешавања и сви кориснички подаци ће бити изгубљени."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="4051015943038199910">"Покушали сте да откључате телефон нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја телефон ће бити ресетован на фабричка подешавања и сви кориснички подаци ће бити изгубљени."</string>
     <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="2072996269148483637">"Покушали сте да откључате таблет нетачно <xliff:g id="NUMBER">%d</xliff:g> пута. Таблет ће сада бити враћен на подразумевана фабричка подешавања."</string>
     <string name="kg_failed_attempts_now_wiping" product="tv" msgid="4987878286750741463">"Покушали сте да откључате ТВ нетачно <xliff:g id="NUMBER">%d</xliff:g> пута. ТВ ће сада бити ресетован на подразумевана фабричка подешавања."</string>
     <string name="kg_failed_attempts_now_wiping" product="default" msgid="4817627474419471518">"Покушали сте да откључате телефон нетачно <xliff:g id="NUMBER">%d</xliff:g> пута. Телефон ће сада бити враћен на подразумевана фабричка подешавања."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате таблет помоћу налога е-поште.\n\nПокушајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tv" msgid="4224651132862313471">"Неисправно сте нацртали шаблон за откључавање <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате ТВ помоћу налога е-поште.\n\n Покушајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> сек."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате телефон помоћу налога е-поште.\n\nПокушајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате таблет помоћу налога е-поште.\n\nПробајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="tv" msgid="4224651132862313471">"Неисправно сте нацртали шаблон за откључавање <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате ТВ помоћу налога е-поште.\n\n Пробајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> сек."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате телефон помоћу налога е-поште.\n\nПробајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
     <string name="kg_text_message_separator" product="default" msgid="4160700433287233771">" – "</string>
     <string name="kg_reordering_delete_drop_target_text" msgid="7899202978204438708">"Уклони"</string>
     <string name="safe_media_volume_warning" product="default" msgid="2276318909314492312">"Желите да појачате звук изнад препорученог нивоа?\n\nСлушање гласне музике дуже време може да вам оштети слух."</string>
@@ -1565,14 +1565,14 @@
     <string name="restr_pin_enter_new_pin" msgid="5959606691619959184">"Нови PIN"</string>
     <string name="restr_pin_confirm_pin" msgid="8501523829633146239">"Потврдите нови PIN"</string>
     <string name="restr_pin_create_pin" msgid="8017600000263450337">"Направите PIN за измену ограничења"</string>
-    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN-ови се не подударају. Покушајте поново."</string>
+    <string name="restr_pin_error_doesnt_match" msgid="2224214190906994548">"PIN-ови се не подударају. Пробајте поново."</string>
     <string name="restr_pin_error_too_short" msgid="8173982756265777792">"PIN је прекратак. Мора да садржи најмање 4 цифре."</string>
     <plurals name="restr_pin_countdown" formatted="false" msgid="9061246974881224688">
-      <item quantity="one">Покушајте поново за <xliff:g id="COUNT">%d</xliff:g> секунду</item>
-      <item quantity="few">Покушајте поново за <xliff:g id="COUNT">%d</xliff:g> секунде</item>
-      <item quantity="other">Покушајте поново за <xliff:g id="COUNT">%d</xliff:g> секунди</item>
+      <item quantity="one">Пробајте поново за <xliff:g id="COUNT">%d</xliff:g> секунду</item>
+      <item quantity="few">Пробајте поново за <xliff:g id="COUNT">%d</xliff:g> секунде</item>
+      <item quantity="other">Пробајте поново за <xliff:g id="COUNT">%d</xliff:g> секунди</item>
     </plurals>
-    <string name="restr_pin_try_later" msgid="973144472490532377">"Покушајте поново касније"</string>
+    <string name="restr_pin_try_later" msgid="973144472490532377">"Пробајте поново касније"</string>
     <string name="immersive_cling_title" msgid="8394201622932303336">"Приказује се цео екран"</string>
     <string name="immersive_cling_description" msgid="3482371193207536040">"Да бисте изашли, превуците надоле одозго."</string>
     <string name="immersive_cling_positive" msgid="5016839404568297683">"Важи"</string>
diff --git a/core/res/res/values-watch/colors_device_defaults.xml b/core/res/res/values-watch/colors_device_defaults.xml
new file mode 100644
index 0000000..9150cc4
--- /dev/null
+++ b/core/res/res/values-watch/colors_device_defaults.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2016 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.
+-->
+
+<!-- Colors specific to DeviceDefault themes. These are mostly pass-throughs to enable
+     overlaying new theme colors. -->
+<resources>
+    <color name="button_normal_device_default_dark">@color/btn_default_material_dark</color>
+</resources>
diff --git a/core/res/res/values-watch/colors_material.xml b/core/res/res/values-watch/colors_material.xml
index 54eece4..18bfd4d 100644
--- a/core/res/res/values-watch/colors_material.xml
+++ b/core/res/res/values-watch/colors_material.xml
@@ -17,8 +17,10 @@
     <color name="background_material_dark">#ff232e33</color>
     <color name="background_floating_material_dark">#ff3e5059</color>
 
-    <color name="accent_material_dark">#ff5e97f6</color>
+    <color name="accent_material_700">#ff2e4978</color>
     <color name="accent_material_light">#ff4285f4</color>
+    <color name="accent_material_dark">#ff5e97f6</color>
+    <color name="accent_material_50">#ffd0def7</color>
 
     <color name="primary_material_dark">#4D4D4D</color>
 
diff --git a/core/res/res/values-watch/themes_device_defaults.xml b/core/res/res/values-watch/themes_device_defaults.xml
index 2313b26..aa1594d 100644
--- a/core/res/res/values-watch/themes_device_defaults.xml
+++ b/core/res/res/values-watch/themes_device_defaults.xml
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Copyright (C) 2014 The Android Open Source Project
+<!-- Copyright (C) 2011 The Android Open Source Project
 
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
@@ -18,26 +18,328 @@
 ===============================================================
                         PLEASE READ
 ===============================================================
-This file contains the themes that are the Device Defaults.
-If you want to edit themes to skin your device, do it here.
-We recommend that you do not edit themes.xml and instead edit
-this file.
-
-Editing this file instead of themes.xml will greatly simplify
+This file contains the themes that are the Device Defaults on
+Watch. If you want to edit themes to skin your device, do it
+here. Editing this file instead of themes.xml will greatly simplify
 merges for future platform versions and CTS compliance will be
 easier.
+
+You should also have a look at themes.xml, to
+understand why we define Dialogs and Settings with color
+palette Dark. It's because themes.xml modify Material in
+a similar way.
 ===============================================================
                         PLEASE READ
 ===============================================================
  -->
 <resources>
+    <style name="Theme.DeviceDefault" parent="Theme.DeviceDefaultBase">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- Variant of {@link #Theme_DeviceDefault} with no action bar -->
+    <style name="Theme.DeviceDefault.NoActionBar" parent="Theme.Material.NoActionBar">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- Variant of {@link #Theme_DeviceDefault} with no action bar and no status bar.  This theme
+         sets {@link android.R.attr#windowFullscreen} to true.  -->
+    <style name="Theme.DeviceDefault.NoActionBar.Fullscreen" parent="Theme.Material.NoActionBar.Fullscreen">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- Variant of {@link #Theme_DeviceDefault} with no action bar and no status bar and
+    extending in to overscan region.  This theme
+    sets {@link android.R.attr#windowFullscreen} and {@link android.R.attr#windowOverscan}
+    to true. -->
+    <style name="Theme.DeviceDefault.NoActionBar.Overscan" parent="Theme.Material.NoActionBar.Overscan">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- Variant of {@link #Theme_DeviceDefault} that has no title bar and translucent
+         system decor.  This theme sets {@link android.R.attr#windowTranslucentStatus} and
+         {@link android.R.attr#windowTranslucentNavigation} to true. -->
+    <style name="Theme.DeviceDefault.NoActionBar.TranslucentDecor" parent="Theme.Material.NoActionBar.TranslucentDecor">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
     <!-- Theme used for the intent picker activity. -->
-    <style name="Theme.DeviceDefault.Resolver" parent="Theme.Material">
+    <style name="Theme.DeviceDefault.Resolver">
         <item name="colorControlActivated">?attr/colorControlHighlight</item>
         <item name="listPreferredItemPaddingStart">?attr/dialogPreferredPadding</item>
         <item name="listPreferredItemPaddingEnd">?attr/dialogPreferredPadding</item>
     </style>
 
     <!-- Use a dark theme for watches. -->
-    <style name="Theme.DeviceDefault.System" parent="Theme.Material" />
+    <style name="Theme.DeviceDefault.System" />
+
+    <!-- DeviceDefault style for input methods, which is used by the
+         {@link android.inputmethodservice.InputMethodService} class.-->
+    <style name="Theme.DeviceDefault.InputMethod" parent="Theme.DeviceDefault.Panel">
+        <item name="windowAnimationStyle">@style/Animation.InputMethod</item>
+        <item name="imeFullscreenBackground">?colorBackground</item>
+        <item name="imeExtractEnterAnimation">@anim/input_method_extract_enter</item>
+    </style>
+
+    <!-- DeviceDefault theme for dialog windows and activities. In contrast to Material, the
+    watch theme is not floating. You can set this theme on an activity if you would like to make
+    an activity that looks like a Dialog.-->
+    <style name="Theme.DeviceDefault.Dialog" parent="Theme.Material.Dialog" >
+        <item name="windowIsFloating">false</item>
+        <item name="windowTitleStyle">@style/DialogWindowTitle.DeviceDefault</item>
+        <item name="windowAnimationStyle">@style/Animation.DeviceDefault.Dialog</item>
+
+        <item name="buttonBarStyle">@style/DeviceDefault.ButtonBar.AlertDialog</item>
+        <item name="borderlessButtonStyle">@style/Widget.DeviceDefault.Button.Borderless.Small</item>
+
+        <item name="textAppearance">@style/TextAppearance.DeviceDefault</item>
+        <item name="textAppearanceInverse">@style/TextAppearance.DeviceDefault.Inverse</item>
+
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- DeviceDefault theme for a window that should look like the Settings app.  -->
+    <style name="Theme.DeviceDefault.Settings" parent="Theme.DeviceDefault"/>
+    <style name="Theme.DeviceDefault.Settings.NoActionBar" parent="Theme.DeviceDefault"/>
+    <style name="Theme.DeviceDefault.Settings.BaseDialog" parent="Theme.DeviceDefault.Dialog"/>
+    <style name="Theme.DeviceDefault.Settings.Dialog" parent="Theme.DeviceDefault.Settings.BaseDialog"/>
+    <style name="Theme.DeviceDefault.Settings.DialogWhenLarge" parent="Theme.DeviceDefault.DialogWhenLarge"/>
+    <style name="Theme.DeviceDefault.Settings.DialogWhenLarge.NoActionBar" parent="Theme.DeviceDefault.DialogWhenLarge.NoActionBar"/>
+    <style name="Theme.DeviceDefault.Settings.Dialog.Presentation" parent="Theme.DeviceDefault.Dialog.Presentation"/>
+    <style name="Theme.DeviceDefault.Settings.SearchBar" parent="Theme.DeviceDefault.SearchBar"/>
+
+    <style name="Theme.DeviceDefault.Settings.Dialog.Alert" parent="Theme.Material.Dialog.Alert">
+        <item name="windowIsFloating">false</item>
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <style name="Theme.DeviceDefault.Settings.CompactMenu" parent="Theme.Material.CompactMenu">
+        <item name="windowIsFloating">false</item>
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- Variant of {@link #Theme_DeviceDefault_Dialog} that has a nice minimum width for a
+    regular dialog. -->
+    <style name="Theme.DeviceDefault.Dialog.MinWidth" parent="Theme.Material.Dialog.MinWidth">
+        <item name="windowIsFloating">false</item>
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- Variant of {@link #Theme_DeviceDefault_Dialog} without an action bar -->
+    <style name="Theme.DeviceDefault.Dialog.NoActionBar" parent="Theme.Material.Dialog.NoActionBar">
+        <item name="windowIsFloating">false</item>
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- Variant of {@link #Theme_DeviceDefault_Dialog_NoActionBar} that has a nice minimum width
+    for a regular dialog. -->
+    <style name="Theme.DeviceDefault.Dialog.NoActionBar.MinWidth" parent="Theme.Material.Dialog.NoActionBar.MinWidth">
+        <item name="windowIsFloating">false</item>
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+   <!-- DeviceDefault theme for a window that will be displayed either full-screen on smaller
+    screens (small, normal) or as a dialog on larger screens (large, xlarge). -->
+    <style name="Theme.DeviceDefault.DialogWhenLarge" parent="Theme.Material.DialogWhenLarge">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- DeviceDefault theme for a window without an action bar that will be displayed either
+    full-screen on smaller screens (small, normal) or as a dialog on larger screens (large,
+    xlarge). -->
+    <style name="Theme.DeviceDefault.DialogWhenLarge.NoActionBar" parent="Theme.Material.DialogWhenLarge.NoActionBar">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- DeviceDefault theme for a presentation window on a secondary display. -->
+    <style name="Theme.DeviceDefault.Dialog.Presentation" parent="Theme.Material.Dialog.Presentation">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- DeviceDefault theme for panel windows. This removes all extraneous window
+    decorations, so you basically have an empty rectangle in which to place your content. It makes
+    the window floating, with a transparent background, and turns off dimming behind the window. -->
+    <style name="Theme.DeviceDefault.Panel" parent="Theme.Material.Panel">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- DeviceDefault theme for windows that want to have the user's selected wallpaper appear
+    behind them. -->
+    <style name="Theme.DeviceDefault.Wallpaper" parent="Theme.Material.Wallpaper">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- DeviceDefault theme for windows that want to have the user's selected wallpaper appear
+    behind them and without an action bar. -->
+    <style name="Theme.DeviceDefault.Wallpaper.NoTitleBar" parent="Theme.Material.Wallpaper.NoTitleBar">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <!-- DeviceDefault style for input methods, which is used by the
+         {@link android.service.voice.VoiceInteractionSession} class.-->
+    <style name="Theme.DeviceDefault.VoiceInteractionSession" parent="Theme.Material.VoiceInteractionSession">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <style name="Theme.DeviceDefault.Dialog.Alert" parent="Theme.Material.Dialog.Alert">
+        <item name="windowTitleStyle">@style/DialogWindowTitle.DeviceDefault</item>
+
+        <!-- Color palette Dialog -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">?attr/colorBackgroundFloating</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <style name="Theme.DeviceDefault.SearchBar" parent="Theme.Material.SearchBar">
+        <!-- Color palette Dark -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">@color/background_device_default_dark</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
+
+    <style name="Theme.DeviceDefault.Dialog.NoFrame" parent="Theme.Material.Dialog.NoFrame">
+        <item name="windowIsFloating">false</item>
+        <!-- Color palette Dialog -->
+        <item name="colorPrimary">@color/primary_device_default_dark</item>
+        <item name="colorPrimaryDark">@color/primary_dark_device_default_dark</item>
+        <item name="colorAccent">@color/accent_device_default_dark</item>
+        <item name="colorBackground">?attr/colorBackgroundFloating</item>
+        <item name="colorBackgroundFloating">@color/background_floating_device_default_dark</item>
+        <item name="colorBackgroundCacheHint">@color/background_cache_hint_selector_device_default</item>
+        <item name="colorButtonNormal">@color/button_normal_device_default_dark</item>
+    </style>
 </resources>
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index f0a25aa..c3967e4 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -3965,6 +3965,7 @@
     </declare-styleable>
 
     <declare-styleable name="ProgressBar">
+        <attr name="min" format="integer" />
         <!-- Defines the maximum value the progress can take. -->
         <attr name="max" format="integer" />
         <!-- Defines the default progress value, between 0 and max. -->
@@ -7941,6 +7942,14 @@
 
     <declare-styleable name="SeekBarPreference">
         <attr name="layout" />
+        <!-- Attribute indicating whether the slider within this preference can be adjusted, that is
+        pressing left/right keys when this preference is focused will move the slider accordingly (e.g.
+        inline adjustable preferences). False, if the slider within the preference is read-only and
+        cannot be adjusted. By default, the seekbar is adjustable. -->
+        <attr name="adjustable" format="boolean" />
+        <!-- Flag indicating whether the TextView next to the seekbar that shows the current seekbar value will be
+        displayed. If true, the view is VISIBLE; if false, the view will be GONE. By default, this view is VISIBLE. -->
+        <attr name="showSeekBarValue" format="boolean" />
     </declare-styleable>
 
     <!-- Base attributes available to PreferenceFragment. -->
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index dbad4b4..c40436a 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -2258,6 +2258,21 @@
     <!-- Sprint need a 70 ms delay for 3way call -->
     <integer name="config_cdma_3waycall_flash_delay">0</integer>
 
+    <!-- If there is no preload VM number in the sim card, carriers such as
+         Verizon require to load a default vm number from the configurantion.
+         Define config_default_vm_number for this purpose. And there are two
+         optional formats for this configuration as below:
+         (1)<item>voicemail number</item>
+         (2)<item>voicemail number;gid</item>
+         The logic to pick up the correct voicemail number:
+         (1) If the config_default_vm_number array has no gid special item, the last one will be
+         picked
+         (2) If the config_default_vm_number array has gid special item and  it matches the current
+         sim's gid, it will be picked.
+         (3) If the config_default_vm_number array has gid special item but it doesn't match the
+         current sim's gid, the last one without gid will be picked -->
+    <string-array translatable="false" name="config_default_vm_number" />
+
     <!--SIM does not save, but the voice mail number to be changed. -->
     <bool name="editable_voicemailnumber">false</bool>
 
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index 7bce379..7999e7e 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2764,4 +2764,5 @@
     <public-group type="id" first-id="0x01020041">
     </public-group>
 
+    <public type="attr" name="min" />
 </resources>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 69db023..97a679e 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2264,6 +2264,7 @@
   <java-symbol type="attr" name="closeItemLayout" />
   <java-symbol type="layout" name="resolver_different_item_header" />
   <java-symbol type="integer" name="config_cdma_3waycall_flash_delay"/>
+  <java-symbol type="array" name="config_default_vm_number" />
   <java-symbol type="attr" name="windowBackgroundFallback" />
   <java-symbol type="id" name="textSpacerNoButtons" />
   <java-symbol type="array" name="dial_string_replace" />
diff --git a/core/res/res/values/themes_device_defaults.xml b/core/res/res/values/themes_device_defaults.xml
index 0e98ade..b19858e 100644
--- a/core/res/res/values/themes_device_defaults.xml
+++ b/core/res/res/values/themes_device_defaults.xml
@@ -49,7 +49,7 @@
          Type.DeviceDefault.Etc (for example, {@code Widget.DeviceDefault.Button} and
          {@code TextAppearance.DeviceDefault.Widget.PopupMenu.Large}).</p>
           -->
-    <style name="Theme.DeviceDefault" parent="Theme.Material" >
+    <style name="Theme.DeviceDefaultBase" parent="Theme.Material" >
         <!-- Text styles -->
         <item name="textAppearance">@style/TextAppearance.DeviceDefault</item>
         <item name="textAppearanceInverse">@style/TextAppearance.DeviceDefault.Inverse</item>
@@ -206,6 +206,8 @@
 
     </style>
 
+    <style name="Theme.DeviceDefault" parent="Theme.DeviceDefaultBase" />
+
     <!-- Variant of {@link #Theme_DeviceDefault} with no action bar -->
     <style name="Theme.DeviceDefault.NoActionBar" parent="Theme.Material.NoActionBar">
         <!-- Color palette -->
diff --git a/core/res/res/xml/preferred_time_zones.xml b/core/res/res/xml/preferred_time_zones.xml
deleted file mode 100644
index da8553f..0000000
--- a/core/res/res/xml/preferred_time_zones.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
-/* //device/apps/common/assets/default/default/data/preferred_time_zones.xml
-**
-** Copyright 2006, 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.
-*/
--->
-<timezones>
-	<timezone offset="-18000000">America/New_York</timezone>
-	<timezone offset="-21600000">America/Chicago</timezone>
-	<timezone offset="-25200000">America/Denver</timezone>
-	<timezone offset="-28800000">America/Los_Angeles</timezone>
-</timezones>
diff --git a/core/res/res/xml/sms_short_codes.xml b/core/res/res/xml/sms_short_codes.xml
index a9fa5e0..29c6b79 100644
--- a/core/res/res/xml/sms_short_codes.xml
+++ b/core/res/res/xml/sms_short_codes.xml
@@ -57,6 +57,12 @@
     <!-- Bulgaria: 4-5 digits, plus EU -->
     <shortcode country="bg" pattern="\\d{4,5}" premium="18(?:16|423)|19(?:1[56]|35)" free="116\\d{3}" />
 
+    <!-- Bahrain: 1-5 digits (standard system default, not country specific) -->
+    <shortcode country="bh" pattern="\\d{1,5}" free="81181" />
+
+    <!-- Brazil: 1-5 digits (standard system default, not country specific) -->
+    <shortcode country="br" pattern="\\d{1,5}" free="6000[012]\\d" />
+
     <!-- Belarus: 4 digits -->
     <shortcode country="by" pattern="\\d{4}" premium="3336|4161|444[4689]|501[34]|7781" />
 
@@ -129,7 +135,7 @@
 
     <!-- Italy: 5 digits (premium=4xxxx), plus EU:
          http://clients.txtnation.com/attachments/token/di5kfblvubttvlw/?name=Italy_CASP_EN.pdf -->
-    <shortcode country="it" pattern="\\d{5}" premium="4\\d{4}" free="116\\d{3}|4112503" />
+    <shortcode country="it" pattern="\\d{5}" premium="4\\d{4}" free="116\\d{3}|4112503" standard="43\\d{3}" />
 
     <!-- Japan: 8083 used by SOFTBANK_DCB_2 -->
     <shortcode country="jp" free="8083" />
@@ -204,7 +210,7 @@
     <shortcode country="si" pattern="\\d{4}" premium="[368]\\d{3}" free="116\\d{3}" />
 
     <!-- Slovakia: 4 digits (premium), plus EU: http://www.cmtelecom.com/premium-sms/slovakia -->
-    <shortcode country="sk" premium="\\d{4}" free="116\\d{3}" />
+    <shortcode country="sk" premium="\\d{4}" free="116\\d{3}|8000" />
 
     <!-- Thailand: 4186001 used by AIS_TH_DCB -->
     <shortcode country="th" free="4186001" />
@@ -220,9 +226,9 @@
 
     <!-- USA: 5-6 digits (premium codes from https://www.premiumsmsrefunds.com/ShortCodes.htm),
          visual voicemail code for T-Mobile: 122 -->
-    <shortcode country="us" pattern="\\d{5,6}" premium="20433|21(?:344|472)|22715|23(?:333|847)|24(?:15|28)0|25209|27(?:449|606|663)|28498|305(?:00|83)|32(?:340|941)|33(?:166|786|849)|34746|35(?:182|564)|37975|38(?:135|146|254)|41(?:366|463)|42335|43(?:355|500)|44(?:578|711|811)|45814|46(?:157|173|327)|46666|47553|48(?:221|277|669)|50(?:844|920)|51(?:062|368)|52944|54(?:723|892)|55928|56483|57370|59(?:182|187|252|342)|60339|61(?:266|982)|62478|64(?:219|898)|65(?:108|500)|69(?:208|388)|70877|71851|72(?:078|087|465)|73(?:288|588|882|909|997)|74(?:034|332|815)|76426|79213|81946|83177|84(?:103|685)|85797|86(?:234|236|666)|89616|90(?:715|842|938)|91(?:362|958)|94719|95297|96(?:040|666|835|969)|97(?:142|294|688)|99(?:689|796|807)" standard="44567" free="122|87902" />
+    <shortcode country="us" pattern="\\d{5,6}" premium="20433|21(?:344|472)|22715|23(?:333|847)|24(?:15|28)0|25209|27(?:449|606|663)|28498|305(?:00|83)|32(?:340|941)|33(?:166|786|849)|34746|35(?:182|564)|37975|38(?:135|146|254)|41(?:366|463)|42335|43(?:355|500)|44(?:578|711|811)|45814|46(?:157|173|327)|46666|47553|48(?:221|277|669)|50(?:844|920)|51(?:062|368)|52944|54(?:723|892)|55928|56483|57370|59(?:182|187|252|342)|60339|61(?:266|982)|62478|64(?:219|898)|65(?:108|500)|69(?:208|388)|70877|71851|72(?:078|087|465)|73(?:288|588|882|909|997)|74(?:034|332|815)|76426|79213|81946|83177|84(?:103|685)|85797|86(?:234|236|666)|89616|90(?:715|842|938)|91(?:362|958)|94719|95297|96(?:040|666|835|969)|97(?:142|294|688)|99(?:689|796|807)" standard="44567" free="122|87902|21696|24614|28003|30356|33669|40196|41064|41270|43753|44034|46645|52413|56139|57969|61785|66975|75136|76227|81398|83952|85140|86566|86799|95737|96684|99245" />
 
     <!-- Vietnam: 1-5 digits (standard system default, not country specific) -->
-    <shortcode country="vn" pattern="\\d{1,5}" free="5001" />
+    <shortcode country="vn" pattern="\\d{1,5}" free="5001|9055" />
 
 </shortcodes>
diff --git a/core/res/res/xml/time_zones_by_country.xml b/core/res/res/xml/time_zones_by_country.xml
index 9b2bd50..a685e2b 100644
--- a/core/res/res/xml/time_zones_by_country.xml
+++ b/core/res/res/xml/time_zones_by_country.xml
@@ -31,11 +31,11 @@
 
     <!-- ANTIGUA AND BARBUDA, -4:00 -->
 
-    <timezone code="ag">America/Antigua</timezone>
+    <timezone code="ag">America/Port_of_Spain</timezone>
 
     <!-- ANGUILLA, -4:00 -->
 
-    <timezone code="ai">America/Anguilla</timezone>
+    <timezone code="ai">America/Port_of_Spain</timezone>
 
     <!-- ALBANIA, 1:00 -->
 
@@ -45,18 +45,13 @@
 
     <timezone code="am">Asia/Yerevan</timezone>
 
-    <!-- NETHERLANDS ANTILLES, -4:00 -->
-
-    <timezone code="an">America/Curacao</timezone>
-
     <!-- ANGOLA, 1:00 -->
 
-    <timezone code="ao">Africa/Luanda</timezone>
+    <timezone code="ao">Africa/Lagos</timezone>
 
     <!-- ANTARCTICA, 12:00 -->
 
-    <timezone code="aq">Antarctica/McMurdo</timezone>
-    <timezone code="aq">Antarctica/South_Pole</timezone>
+    <timezone code="aq">Pacific/Auckland</timezone>
 
     <!-- ANTARCTICA, 10:00 -->
 
@@ -70,15 +65,22 @@
 
     <timezone code="aq">Antarctica/Davis</timezone>
 
-    <!-- ANTARCTICA, 6:00 -->
+    <!-- ANTARCTICA, 5:00 -->
 
     <timezone code="aq">Antarctica/Mawson</timezone>
+
+    <!-- ANTARCTICA, 6:00 -->
+
     <timezone code="aq">Antarctica/Vostok</timezone>
 
     <!-- ANTARCTICA, 3:00 -->
 
     <timezone code="aq">Antarctica/Syowa</timezone>
 
+    <!-- ANTARCTICA, 0:00 -->
+
+    <timezone code="aq">Antarctica/Troll</timezone>
+
     <!-- ANTARCTICA, -3:00 -->
 
     <timezone code="aq">Antarctica/Rothera</timezone>
@@ -91,12 +93,14 @@
 
     <timezone code="ar">America/Argentina/Buenos_Aires</timezone>
     <timezone code="ar">America/Argentina/Cordoba</timezone>
+    <timezone code="ar">America/Argentina/Salta</timezone>
     <timezone code="ar">America/Argentina/Jujuy</timezone>
     <timezone code="ar">America/Argentina/Tucuman</timezone>
     <timezone code="ar">America/Argentina/Catamarca</timezone>
     <timezone code="ar">America/Argentina/La_Rioja</timezone>
     <timezone code="ar">America/Argentina/San_Juan</timezone>
     <timezone code="ar">America/Argentina/Mendoza</timezone>
+    <timezone code="ar">America/Argentina/San_Luis</timezone>
     <timezone code="ar">America/Argentina/Rio_Gallegos</timezone>
     <timezone code="ar">America/Argentina/Ushuaia</timezone>
 
@@ -117,6 +121,9 @@
     <timezone code="au">Australia/Currie</timezone>
     <timezone code="au">Australia/Lindeman</timezone>
 
+    <!-- AUSTRALIA, 11:00 -->
+    <timezone code="au">Antarctica/Macquarie</timezone>
+
     <!-- AUSTRALIA, 10:30 -->
 
     <timezone code="au">Australia/Lord_Howe</timezone>
@@ -137,11 +144,11 @@
 
     <!-- ARUBA, -4:00 -->
 
-    <timezone code="aw">America/Aruba</timezone>
+    <timezone code="aw">America/Curacao</timezone>
 
     <!-- ALAND ISLANDS, 2:00 -->
 
-    <timezone code="ax">Europe/Mariehamn</timezone>
+    <timezone code="ax">Europe/Helsinki</timezone>
 
     <!-- AZERBAIJAN, 4:00 -->
 
@@ -149,7 +156,7 @@
 
     <!-- BOSNIA AND HERZEGOVINA, 1:00 -->
 
-    <timezone code="ba">Europe/Sarajevo</timezone>
+    <timezone code="ba">Europe/Belgrade</timezone>
 
     <!-- BARBADOS, -4:00 -->
 
@@ -165,7 +172,7 @@
 
     <!-- BURKINA FASO, 0:00 -->
 
-    <timezone code="bf">Africa/Ouagadougou</timezone>
+    <timezone code="bf">Africa/Abidjan</timezone>
 
     <!-- BULGARIA, 2:00 -->
 
@@ -173,15 +180,19 @@
 
     <!-- BAHRAIN, 3:00 -->
 
-    <timezone code="bh">Asia/Bahrain</timezone>
+    <timezone code="bh">Asia/Qatar</timezone>
 
     <!-- BURUNDI, 2:00 -->
 
-    <timezone code="bi">Africa/Bujumbura</timezone>
+    <timezone code="bi">Africa/Maputo</timezone>
 
     <!-- BENIN, 1:00 -->
 
-    <timezone code="bj">Africa/Porto-Novo</timezone>
+    <timezone code="bj">Africa/Lagos</timezone>
+
+    <!-- Saint Barthélemy, -4:00 -->
+
+    <timezone code="bl">America/Port_of_Spain</timezone>
 
     <!-- BERMUDA, -4:00 -->
 
@@ -195,6 +206,10 @@
 
     <timezone code="bo">America/La_Paz</timezone>
 
+    <!-- Caribbean Netherlands, -4:00 -->
+
+    <timezone code="bq">America/Curacao</timezone>
+
     <!-- BRAZIL, -2:00 -->
 
     <timezone code="br">America/Noronha</timezone>
@@ -208,6 +223,7 @@
     <timezone code="br">America/Araguaina</timezone>
     <timezone code="br">America/Maceio</timezone>
     <timezone code="br">America/Bahia</timezone>
+    <timezone code="br">America/Santarem</timezone>
 
     <!-- BRAZIL, -4:00 -->
 
@@ -216,6 +232,9 @@
     <timezone code="br">America/Cuiaba</timezone>
     <timezone code="br">America/Porto_Velho</timezone>
     <timezone code="br">America/Boa_Vista</timezone>
+
+    <!-- BRAZIL, -5:00 -->
+
     <timezone code="br">America/Eirunepe</timezone>
     <timezone code="br">America/Rio_Branco</timezone>
 
@@ -229,9 +248,9 @@
 
     <!-- BOTSWANA, 2:00 -->
 
-    <timezone code="bw">Africa/Gaborone</timezone>
+    <timezone code="bw">Africa/Maputo</timezone>
 
-    <!-- BELARUS, 2:00 -->
+    <!-- BELARUS, 3:00 -->
 
     <timezone code="by">Europe/Minsk</timezone>
 
@@ -254,12 +273,10 @@
     <!-- CANADA, -5:00 -->
 
     <timezone code="ca">America/Toronto</timezone>
-    <timezone code="ca">America/Montreal</timezone>
     <timezone code="ca">America/Nipigon</timezone>
     <timezone code="ca">America/Thunder_Bay</timezone>
     <timezone code="ca">America/Iqaluit</timezone>
     <timezone code="ca">America/Pangnirtung</timezone>
-    <timezone code="ca">America/Resolute</timezone>
     <timezone code="ca">America/Atikokan</timezone>
 
     <!-- CANADA, -6:00 -->
@@ -269,6 +286,7 @@
     <timezone code="ca">America/Rankin_Inlet</timezone>
     <timezone code="ca">America/Rainy_River</timezone>
     <timezone code="ca">America/Swift_Current</timezone>
+    <timezone code="ca">America/Resolute</timezone>
 
     <!-- CANADA, -7:00 -->
 
@@ -277,6 +295,8 @@
     <timezone code="ca">America/Yellowknife</timezone>
     <timezone code="ca">America/Inuvik</timezone>
     <timezone code="ca">America/Dawson_Creek</timezone>
+    <timezone code="ca">America/Creston</timezone>
+    <timezone code="ca">America/Fort_Nelson</timezone>
 
     <!-- CANADA, -8:00 -->
 
@@ -290,19 +310,19 @@
 
     <!-- CONGO, THE DEMOCRATIC REPUBLIC OF THE, 2:00 -->
 
-    <timezone code="cd">Africa/Lubumbashi</timezone>
+    <timezone code="cd">Africa/Maputo</timezone>
 
     <!-- CONGO, THE DEMOCRATIC REPUBLIC OF THE, 1:00 -->
 
-    <timezone code="cd">Africa/Kinshasa</timezone>
+    <timezone code="cd">Africa/Lagos</timezone>
 
     <!-- CENTRAL AFRICAN REPUBLIC, 1:00 -->
 
-    <timezone code="cf">Africa/Bangui</timezone>
+    <timezone code="cf">Africa/Lagos</timezone>
 
     <!-- CONGO, 1:00 -->
 
-    <timezone code="cg">Africa/Brazzaville</timezone>
+    <timezone code="cg">Africa/Lagos</timezone>
 
     <!-- SWITZERLAND, 1:00 -->
 
@@ -326,15 +346,15 @@
 
     <!-- CAMEROON, 1:00 -->
 
-    <timezone code="cm">Africa/Douala</timezone>
+    <timezone code="cm">Africa/Lagos</timezone>
 
     <!-- CHINA, 8:00 -->
 
     <timezone code="cn">Asia/Shanghai</timezone>
-    <timezone code="cn">Asia/Harbin</timezone>
-    <timezone code="cn">Asia/Chongqing</timezone>
+
+    <!-- CHINA, 6:00 -->
+
     <timezone code="cn">Asia/Urumqi</timezone>
-    <timezone code="cn">Asia/Kashgar</timezone>
 
     <!-- COLOMBIA, -5:00 -->
 
@@ -352,6 +372,10 @@
 
     <timezone code="cv">Atlantic/Cape_Verde</timezone>
 
+    <!-- Curaçao, -4:00 -->
+
+    <timezone code="cw">America/Curacao</timezone>
+
     <!-- CHRISTMAS ISLAND, 7:00 -->
 
     <timezone code="cx">Indian/Christmas</timezone>
@@ -367,10 +391,11 @@
     <!-- GERMANY, 1:00 -->
 
     <timezone code="de">Europe/Berlin</timezone>
+    <timezone code="de">Europe/Zurich</timezone>
 
     <!-- DJIBOUTI, 3:00 -->
 
-    <timezone code="dj">Africa/Djibouti</timezone>
+    <timezone code="dj">Africa/Nairobi</timezone>
 
     <!-- DENMARK, 1:00 -->
 
@@ -378,7 +403,7 @@
 
     <!-- DOMINICA, -4:00 -->
 
-    <timezone code="dm">America/Dominica</timezone>
+    <timezone code="dm">America/Port_of_Spain</timezone>
 
     <!-- DOMINICAN REPUBLIC, -4:00 -->
 
@@ -410,7 +435,7 @@
 
     <!-- ERITREA, 3:00 -->
 
-    <timezone code="er">Africa/Asmara</timezone>
+    <timezone code="er">Africa/Nairobi</timezone>
 
     <!-- SPAIN, 1:00 -->
 
@@ -423,7 +448,7 @@
 
     <!-- ETHIOPIA, 3:00 -->
 
-    <timezone code="et">Africa/Addis_Ababa</timezone>
+    <timezone code="et">Africa/Nairobi</timezone>
 
     <!-- FINLAND, 2:00 -->
 
@@ -433,7 +458,7 @@
 
     <timezone code="fj">Pacific/Fiji</timezone>
 
-    <!-- FALKLAND ISLANDS (MALVINAS), -4:00 -->
+    <!-- FALKLAND ISLANDS (MALVINAS), -3:00 -->
 
     <timezone code="fk">Atlantic/Stanley</timezone>
 
@@ -444,7 +469,7 @@
 
     <!-- MICRONESIA, FEDERATED STATES OF, 10:00 -->
 
-    <timezone code="fm">Pacific/Truk</timezone>
+    <timezone code="fm">Pacific/Chuuk</timezone>
 
     <!-- FAROE ISLANDS, 0:00 -->
 
@@ -456,7 +481,7 @@
 
     <!-- GABON, 1:00 -->
 
-    <timezone code="ga">Africa/Libreville</timezone>
+    <timezone code="ga">Africa/Lagos</timezone>
 
     <!-- UNITED KINGDOM, 0:00 -->
 
@@ -464,7 +489,7 @@
 
     <!-- GRENADA, -4:00 -->
 
-    <timezone code="gd">America/Grenada</timezone>
+    <timezone code="gd">America/Port_of_Spain</timezone>
 
     <!-- GEORGIA, 4:00 -->
 
@@ -476,7 +501,7 @@
 
     <!-- GUERNSEY, 0:00 -->
 
-    <timezone code="gg">Europe/Guernsey</timezone>
+    <timezone code="gg">Europe/London</timezone>
 
     <!-- GHANA, 0:00 -->
 
@@ -504,19 +529,19 @@
 
     <!-- GAMBIA, 0:00 -->
 
-    <timezone code="gm">Africa/Banjul</timezone>
+    <timezone code="gm">Africa/Abidjan</timezone>
 
     <!-- GUINEA, 0:00 -->
 
-    <timezone code="gn">Africa/Conakry</timezone>
+    <timezone code="gn">Africa/Abidjan</timezone>
 
     <!-- GUADELOUPE, -4:00 -->
 
-    <timezone code="gp">America/Guadeloupe</timezone>
+    <timezone code="gp">America/Port_of_Spain</timezone>
 
     <!-- EQUATORIAL GUINEA, 1:00 -->
 
-    <timezone code="gq">Africa/Malabo</timezone>
+    <timezone code="gq">Africa/Lagos</timezone>
 
     <!-- GREECE, 2:00 -->
 
@@ -552,7 +577,7 @@
 
     <!-- CROATIA, 1:00 -->
 
-    <timezone code="hr">Europe/Zagreb</timezone>
+    <timezone code="hr">Europe/Belgrade</timezone>
 
     <!-- HAITI, -5:00 -->
 
@@ -585,11 +610,11 @@
 
     <!-- ISLE OF MAN, 0:00 -->
 
-    <timezone code="im">Europe/Isle_of_Man</timezone>
+    <timezone code="im">Europe/London</timezone>
 
     <!-- INDIA, 5:30 -->
 
-    <timezone code="in">Asia/Calcutta</timezone>
+    <timezone code="in">Asia/Kolkata</timezone>
 
     <!-- BRITISH INDIAN OCEAN TERRITORY, 6:00 -->
 
@@ -613,7 +638,7 @@
 
     <!-- JERSEY, 0:00 -->
 
-    <timezone code="je">Europe/Jersey</timezone>
+    <timezone code="je">Europe/London</timezone>
 
     <!-- JAMAICA, -5:00 -->
 
@@ -637,7 +662,7 @@
 
     <!-- CAMBODIA, 7:00 -->
 
-    <timezone code="kh">Asia/Phnom_Penh</timezone>
+    <timezone code="kh">Asia/Bangkok</timezone>
 
     <!-- KIRIBATI, 14:00 -->
 
@@ -653,13 +678,13 @@
 
     <!-- COMOROS, 3:00 -->
 
-    <timezone code="km">Indian/Comoro</timezone>
+    <timezone code="km">Africa/Nairobi</timezone>
 
     <!-- SAINT KITTS AND NEVIS, -4:00 -->
 
-    <timezone code="kn">America/St_Kitts</timezone>
+    <timezone code="kn">America/Port_of_Spain</timezone>
 
-    <!-- KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF, 9:00 -->
+    <!-- KOREA, DEMOCRATIC PEOPLE'S REPUBLIC OF, 8:30 -->
 
     <timezone code="kp">Asia/Pyongyang</timezone>
 
@@ -669,11 +694,11 @@
 
     <!-- KUWAIT, 3:00 -->
 
-    <timezone code="kw">Asia/Kuwait</timezone>
+    <timezone code="kw">Asia/Riyadh</timezone>
 
     <!-- CAYMAN ISLANDS, -5:00 -->
 
-    <timezone code="ky">America/Cayman</timezone>
+    <timezone code="ky">America/Panama</timezone>
 
     <!-- KAZAKHSTAN, 6:00 -->
 
@@ -688,7 +713,7 @@
 
     <!-- LAO PEOPLE'S DEMOCRATIC REPUBLIC, 7:00 -->
 
-    <timezone code="la">Asia/Vientiane</timezone>
+    <timezone code="la">Asia/Bangkok</timezone>
 
     <!-- LEBANON, 2:00 -->
 
@@ -696,11 +721,11 @@
 
     <!-- SAINT LUCIA, -4:00 -->
 
-    <timezone code="lc">America/St_Lucia</timezone>
+    <timezone code="lc">America/Port_of_Spain</timezone>
 
     <!-- LIECHTENSTEIN, 1:00 -->
 
-    <timezone code="li">Europe/Vaduz</timezone>
+    <timezone code="li">Europe/Zurich</timezone>
 
     <!-- SRI LANKA, 5:30 -->
 
@@ -712,7 +737,7 @@
 
     <!-- LESOTHO, 2:00 -->
 
-    <timezone code="ls">Africa/Maseru</timezone>
+    <timezone code="ls">Africa/Johannesburg</timezone>
 
     <!-- LITHUANIA, 2:00 -->
 
@@ -744,11 +769,15 @@
 
     <!-- MONTENEGRO, 1:00 -->
 
-    <timezone code="me">Europe/Podgorica</timezone>
+    <timezone code="me">Europe/Belgrade</timezone>
+
+    <!-- Collectivity of Saint Martin, -4:00 -->
+
+    <timezone code="mf">America/Port_of_Spain</timezone>
 
     <!-- MADAGASCAR, 3:00 -->
 
-    <timezone code="mg">Indian/Antananarivo</timezone>
+    <timezone code="mg">Africa/Nairobi</timezone>
 
     <!-- MARSHALL ISLANDS, 12:00 -->
 
@@ -757,15 +786,15 @@
 
     <!-- MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF, 1:00 -->
 
-    <timezone code="mk">Europe/Skopje</timezone>
+    <timezone code="mk">Europe/Belgrade</timezone>
 
     <!-- MALI, 0:00 -->
 
-    <timezone code="ml">Africa/Bamako</timezone>
+    <timezone code="ml">Africa/Abidjan</timezone>
 
     <!-- MYANMAR, 6:30 -->
 
-    <timezone code="mm">Asia/Rangoon</timezone>
+    <timezone code="mm">Asia/Yangon</timezone>
 
     <!-- MONGOLIA, 8:00 -->
 
@@ -782,7 +811,7 @@
 
     <!-- NORTHERN MARIANA ISLANDS, 10:00 -->
 
-    <timezone code="mp">Pacific/Saipan</timezone>
+    <timezone code="mp">Pacific/Guam</timezone>
 
     <!-- MARTINIQUE, -4:00 -->
 
@@ -790,11 +819,11 @@
 
     <!-- MAURITANIA, 0:00 -->
 
-    <timezone code="mr">Africa/Nouakchott</timezone>
+    <timezone code="mr">Africa/Abidjan</timezone>
 
     <!-- MONTSERRAT, -4:00 -->
 
-    <timezone code="ms">America/Montserrat</timezone>
+    <timezone code="ms">America/Port_of_Spain</timezone>
 
     <!-- MALTA, 1:00 -->
 
@@ -810,20 +839,26 @@
 
     <!-- MALAWI, 2:00 -->
 
-    <timezone code="mw">Africa/Blantyre</timezone>
+    <timezone code="mw">Africa/Maputo</timezone>
 
     <!-- MEXICO, -6:00 -->
 
     <timezone code="mx">America/Mexico_City</timezone>
-    <timezone code="mx">America/Cancun</timezone>
     <timezone code="mx">America/Merida</timezone>
     <timezone code="mx">America/Monterrey</timezone>
+    <timezone code="mx">America/Matamoros</timezone>
+    <timezone code="mx">America/Bahia_Banderas</timezone>
+
+    <!-- MEXICO, -5:00 -->
+
+    <timezone code="mx">America/Cancun</timezone>
 
     <!-- MEXICO, -7:00 -->
 
     <timezone code="mx">America/Chihuahua</timezone>
     <timezone code="mx">America/Hermosillo</timezone>
     <timezone code="mx">America/Mazatlan</timezone>
+    <timezone code="mx">America/Ojinaga</timezone>
 
     <!-- MEXICO, -8:00 -->
 
@@ -848,7 +883,7 @@
 
     <!-- NIGER, 1:00 -->
 
-    <timezone code="ne">Africa/Niamey</timezone>
+    <timezone code="ne">Africa/Lagos</timezone>
 
     <!-- NORFOLK ISLAND, 11:30 -->
 
@@ -892,7 +927,7 @@
 
     <!-- OMAN, 4:00 -->
 
-    <timezone code="om">Asia/Muscat</timezone>
+    <timezone code="om">Asia/Dubai</timezone>
 
     <!-- PANAMA, -5:00 -->
 
@@ -918,6 +953,10 @@
 
     <timezone code="pg">Pacific/Port_Moresby</timezone>
 
+    <!-- PAPUA NEW GUINEA, 11:00 -->
+
+    <timezone code="pg">Pacific/Bougainville</timezone>
+
     <!-- PHILIPPINES, 8:00 -->
 
     <timezone code="ph">Asia/Manila</timezone>
@@ -945,6 +984,7 @@
     <!-- PALESTINE, 2:00 -->
 
     <timezone code="ps">Asia/Gaza</timezone>
+    <timezone code="ps">Asia/Hebron</timezone>
 
     <!-- PORTUGAL, 0:00 -->
 
@@ -987,15 +1027,19 @@
     <!-- RUSSIAN FEDERATION, 11:00 -->
 
     <timezone code="ru">Asia/Magadan</timezone>
+    <timezone code="ru">Asia/Sakhalin</timezone>
+    <timezone code="ru">Asia/Srednekolymsk</timezone>
 
     <!-- RUSSIAN FEDERATION, 10:00 -->
 
     <timezone code="ru">Asia/Vladivostok</timezone>
-    <timezone code="ru">Asia/Sakhalin</timezone>
+    <timezone code="ru">Asia/Ust-Nera</timezone>
 
     <!-- RUSSIAN FEDERATION, 9:00 -->
 
     <timezone code="ru">Asia/Yakutsk</timezone>
+    <timezone code="ru">Asia/Chita</timezone>
+    <timezone code="ru">Asia/Khandyga</timezone>
 
     <!-- RUSSIAN FEDERATION, 8:00 -->
 
@@ -1004,10 +1048,13 @@
     <!-- RUSSIAN FEDERATION, 7:00 -->
 
     <timezone code="ru">Asia/Krasnoyarsk</timezone>
+    <timezone code="ru">Asia/Novosibirsk</timezone>
+    <timezone code="ru">Asia/Barnaul</timezone>
+    <timezone code="ru">Asia/Novokuznetsk</timezone>
+    <timezone code="ru">Asia/Tomsk</timezone>
 
     <!-- RUSSIAN FEDERATION, 6:00 -->
 
-    <timezone code="ru">Asia/Novosibirsk</timezone>
     <timezone code="ru">Asia/Omsk</timezone>
 
     <!-- RUSSIAN FEDERATION, 5:00 -->
@@ -1017,11 +1064,15 @@
     <!-- RUSSIAN FEDERATION, 4:00 -->
 
     <timezone code="ru">Europe/Samara</timezone>
+    <timezone code="ru">Europe/Astrakhan</timezone>
+    <timezone code="ru">Europe/Ulyanovsk</timezone>
 
     <!-- RUSSIAN FEDERATION, 3:00 -->
 
     <timezone code="ru">Europe/Moscow</timezone>
     <timezone code="ru">Europe/Volgograd</timezone>
+    <timezone code="ru">Europe/Kirov</timezone>
+    <timezone code="ru">Europe/Simferopol</timezone>
 
     <!-- RUSSIAN FEDERATION, 2:00 -->
 
@@ -1029,7 +1080,7 @@
 
     <!-- RWANDA, 2:00 -->
 
-    <timezone code="rw">Africa/Kigali</timezone>
+    <timezone code="rw">Africa/Maputo</timezone>
 
     <!-- SAUDI ARABIA, 3:00 -->
 
@@ -1057,57 +1108,65 @@
 
     <!-- SAINT HELENA, 0:00 -->
 
-    <timezone code="sh">Atlantic/St_Helena</timezone>
+    <timezone code="sh">Africa/Abidjan</timezone>
 
     <!-- SLOVENIA, 1:00 -->
 
-    <timezone code="si">Europe/Ljubljana</timezone>
+    <timezone code="si">Europe/Belgrade</timezone>
 
     <!-- SVALBARD AND JAN MAYEN, 1:00 -->
 
-    <timezone code="sj">Arctic/Longyearbyen</timezone>
+    <timezone code="sj">Europe/Oslo</timezone>
 
     <!-- SLOVAKIA, 1:00 -->
 
-    <timezone code="sk">Europe/Bratislava</timezone>
+    <timezone code="sk">Europe/Prague</timezone>
 
     <!-- SIERRA LEONE, 0:00 -->
 
-    <timezone code="sl">Africa/Freetown</timezone>
+    <timezone code="sl">Africa/Abidjan</timezone>
 
     <!-- SAN MARINO, 1:00 -->
 
-    <timezone code="sm">Europe/San_Marino</timezone>
+    <timezone code="sm">Europe/Rome</timezone>
 
     <!-- SENEGAL, 0:00 -->
 
-    <timezone code="sn">Africa/Dakar</timezone>
+    <timezone code="sn">Africa/Abidjan</timezone>
 
     <!-- SOMALIA, 3:00 -->
 
-    <timezone code="so">Africa/Mogadishu</timezone>
+    <timezone code="so">Africa/Nairobi</timezone>
 
     <!-- SURINAME, -3:00 -->
 
     <timezone code="sr">America/Paramaribo</timezone>
 
+    <!-- South Sudan, 3:00 -->
+
+    <timezone code="ss">Africa/Khartoum</timezone>
+
     <!-- SAO TOME AND PRINCIPE, 0:00 -->
 
-    <timezone code="st">Africa/Sao_Tome</timezone>
+    <timezone code="st">Africa/Abidjan</timezone>
 
     <!-- EL SALVADOR, -6:00 -->
 
     <timezone code="sv">America/El_Salvador</timezone>
 
+    <!-- Sint Maarten, -4:00 -->
+
+    <timezone code="sx">America/Curacao</timezone>
+
     <!-- SYRIAN ARAB REPUBLIC, 2:00 -->
 
     <timezone code="sy">Asia/Damascus</timezone>
 
     <!-- SWAZILAND, 2:00 -->
 
-    <timezone code="sz">Africa/Mbabane</timezone>
+    <timezone code="sz">Africa/Johannesburg</timezone>
 
-    <!-- TURKS AND CAICOS ISLANDS, -5:00 -->
+    <!-- TURKS AND CAICOS ISLANDS, -4:00 -->
 
     <timezone code="tc">America/Grand_Turk</timezone>
 
@@ -1119,9 +1178,13 @@
 
     <timezone code="tf">Indian/Kerguelen</timezone>
 
+    <!-- FRENCH SOUTHERN TERRITORIES, 4:00 -->
+
+    <timezone code="tf">Indian/Reunion</timezone>
+
     <!-- TOGO, 0:00 -->
 
-    <timezone code="tg">Africa/Lome</timezone>
+    <timezone code="tg">Africa/Abidjan</timezone>
 
     <!-- THAILAND, 7:00 -->
 
@@ -1131,7 +1194,7 @@
 
     <timezone code="tj">Asia/Dushanbe</timezone>
 
-    <!-- TOKELAU, -10:00 -->
+    <!-- TOKELAU, +13:00 -->
 
     <timezone code="tk">Pacific/Fakaofo</timezone>
 
@@ -1151,7 +1214,7 @@
 
     <timezone code="to">Pacific/Tongatapu</timezone>
 
-    <!-- TURKEY, 2:00 -->
+    <!-- TURKEY, 3:00 -->
 
     <timezone code="tr">Europe/Istanbul</timezone>
 
@@ -1169,18 +1232,17 @@
 
     <!-- TANZANIA, UNITED REPUBLIC OF, 3:00 -->
 
-    <timezone code="tz">Africa/Dar_es_Salaam</timezone>
+    <timezone code="tz">Africa/Nairobi</timezone>
 
     <!-- UKRAINE, 2:00 -->
 
     <timezone code="ua">Europe/Kiev</timezone>
     <timezone code="ua">Europe/Uzhgorod</timezone>
     <timezone code="ua">Europe/Zaporozhye</timezone>
-    <timezone code="ua">Europe/Simferopol</timezone>
 
     <!-- UGANDA, 3:00 -->
 
-    <timezone code="ug">Africa/Kampala</timezone>
+    <timezone code="ug">Africa/Nairobi</timezone>
 
     <!-- UNITED STATES MINOR OUTLYING ISLANDS, 12:00 -->
 
@@ -1188,11 +1250,11 @@
 
     <!-- UNITED STATES MINOR OUTLYING ISLANDS, -10:00 -->
 
-    <timezone code="um">Pacific/Johnston</timezone>
+    <timezone code="um">Pacific/Honolulu</timezone>
 
     <!-- UNITED STATES MINOR OUTLYING ISLANDS, -11:00 -->
 
-    <timezone code="um">Pacific/Midway</timezone>
+    <timezone code="um">Pacific/Pago_Pago</timezone>
 
     <!-- UNITED STATES, -5:00 -->
 
@@ -1214,12 +1276,13 @@
     <timezone code="us">America/Menominee</timezone>
     <timezone code="us">America/North_Dakota/Center</timezone>
     <timezone code="us">America/North_Dakota/New_Salem</timezone>
+    <timezone code="us">America/Indiana/Tell_City</timezone>
+    <timezone code="us">America/North_Dakota/Beulah</timezone>
 
     <!-- UNITED STATES, -7:00 -->
 
     <timezone code="us">America/Denver</timezone>
     <timezone code="us">America/Boise</timezone>
-    <timezone code="us">America/Shiprock</timezone>
     <timezone code="us">America/Phoenix</timezone>
 
     <!-- UNITED STATES, -8:00 -->
@@ -1232,6 +1295,8 @@
     <timezone code="us">America/Juneau</timezone>
     <timezone code="us">America/Yakutat</timezone>
     <timezone code="us">America/Nome</timezone>
+    <timezone code="us">America/Metlakatla</timezone>
+    <timezone code="us">America/Sitka</timezone>
 
     <!-- UNITED STATES, -10:00 -->
 
@@ -1249,27 +1314,28 @@
 
     <!-- HOLY SEE (VATICAN CITY STATE), 1:00 -->
 
-    <timezone code="va">Europe/Vatican</timezone>
+    <timezone code="va">Europe/Rome</timezone>
 
     <!-- SAINT VINCENT AND THE GRENADINES, -4:00 -->
 
-    <timezone code="vc">America/St_Vincent</timezone>
+    <timezone code="vc">America/Port_of_Spain</timezone>
 
-    <!-- VENEZUELA, -4:30 -->
+    <!-- VENEZUELA, -4:00 -->
 
     <timezone code="ve">America/Caracas</timezone>
 
     <!-- VIRGIN ISLANDS, BRITISH, -4:00 -->
 
-    <timezone code="vg">America/Tortola</timezone>
+    <timezone code="vg">America/Port_of_Spain</timezone>
 
     <!-- VIRGIN ISLANDS, U.S., -4:00 -->
 
-    <timezone code="vi">America/St_Thomas</timezone>
+    <timezone code="vi">America/Port_of_Spain</timezone>
 
     <!-- VIET NAM, 7:00 -->
 
-    <timezone code="vn">Asia/Saigon</timezone>
+    <timezone code="vn">Asia/Ho_Chi_Minh</timezone>
+    <timezone code="vn">Asia/Bangkok</timezone>
 
     <!-- VANUATU, 11:00 -->
 
@@ -1279,17 +1345,17 @@
 
     <timezone code="wf">Pacific/Wallis</timezone>
 
-    <!-- SAMOA, -11:00 -->
+    <!-- SAMOA, 13:00 -->
 
     <timezone code="ws">Pacific/Apia</timezone>
 
     <!-- YEMEN, 3:00 -->
 
-    <timezone code="ye">Asia/Aden</timezone>
+    <timezone code="ye">Asia/Riyadh</timezone>
 
     <!-- MAYOTTE, 3:00 -->
 
-    <timezone code="yt">Indian/Mayotte</timezone>
+    <timezone code="yt">Africa/Nairobi</timezone>
 
     <!-- SOUTH AFRICA, 2:00 -->
 
@@ -1297,9 +1363,9 @@
 
     <!-- ZAMBIA, 2:00 -->
 
-    <timezone code="zm">Africa/Lusaka</timezone>
+    <timezone code="zm">Africa/Maputo</timezone>
 
     <!-- ZIMBABWE, 2:00 -->
 
-    <timezone code="zw">Africa/Harare</timezone>
+    <timezone code="zw">Africa/Maputo</timezone>
 </timezones>
diff --git a/core/tests/coretests/src/android/util/TimeUtilsTest.java b/core/tests/coretests/src/android/util/TimeUtilsTest.java
deleted file mode 100644
index 2370627..0000000
--- a/core/tests/coretests/src/android/util/TimeUtilsTest.java
+++ /dev/null
@@ -1,457 +0,0 @@
-/*
- * Copyright (C) 2008 Google Inc.
- *
- * 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.util;
-
-import junit.framework.TestCase;
-
-import java.util.Calendar;
-import java.util.TimeZone;
-
-/**
- * TimeUtilsTest tests the time zone guesser.
- */
-public class TimeUtilsTest extends TestCase {
-    public void testMainstream() throws Exception {
-        String[] mainstream = new String[] {
-            "America/New_York", // Eastern
-            "America/Chicago", // Central
-            "America/Denver", // Mountain
-            "America/Los_Angeles", // Pacific
-            "America/Anchorage", // Alaska
-            "Pacific/Honolulu", // Hawaii, no DST
-        };
-
-        for (String name : mainstream) {
-            TimeZone tz = TimeZone.getTimeZone(name);
-            Calendar c = Calendar.getInstance(tz);
-            TimeZone guess;
-
-            c.set(2008, Calendar.OCTOBER, 20, 12, 00, 00);
-            guess = guess(c, "us");
-            assertEquals(name, guess.getID());
-
-            c.set(2009, Calendar.JANUARY, 20, 12, 00, 00);
-            guess = guess(c, "us");
-            assertEquals(name, guess.getID());
-        }
-    }
-
-    public void testWeird() throws Exception {
-        String[] weird = new String[] {
-            "America/Phoenix", // Mountain, no DST
-            "America/Adak", // Same as Hawaii, but with DST
-        };
-
-        for (String name : weird) {
-            TimeZone tz = TimeZone.getTimeZone(name);
-            Calendar c = Calendar.getInstance(tz);
-            TimeZone guess;
-
-            c.set(2008, Calendar.OCTOBER, 20, 12, 00, 00);
-            guess = guess(c, "us");
-            assertEquals(name, guess.getID());
-        }
-    }
-
-    public void testOld() throws Exception {
-        String[] old = new String[] {
-            "America/Indiana/Indianapolis", // Eastern, formerly no DST
-        };
-
-        for (String name : old) {
-            TimeZone tz = TimeZone.getTimeZone(name);
-            Calendar c = Calendar.getInstance(tz);
-            TimeZone guess;
-
-            c.set(2005, Calendar.OCTOBER, 20, 12, 00, 00);
-            guess = guess(c, "us");
-            assertEquals(name, guess.getID());
-        }
-    }
-
-    public void testWorld() throws Exception {
-        String[] world = new String[] {
-            "ad", "Europe/Andorra",
-            "ae", "Asia/Dubai",
-            "af", "Asia/Kabul",
-            "ag", "America/Antigua",
-            "ai", "America/Anguilla",
-            "al", "Europe/Tirane",
-            "am", "Asia/Yerevan",
-            "an", "America/Curacao",
-            "ao", "Africa/Luanda",
-            "aq", "Antarctica/McMurdo",
-            "aq", "Antarctica/DumontDUrville",
-            "aq", "Antarctica/Casey",
-            "aq", "Antarctica/Davis",
-            "aq", "Antarctica/Mawson",
-            "aq", "Antarctica/Syowa",
-            "aq", "Antarctica/Rothera",
-            "aq", "Antarctica/Palmer",
-            "ar", "America/Argentina/Buenos_Aires",
-            "as", "Pacific/Pago_Pago",
-            "at", "Europe/Vienna",
-            "au", "Australia/Sydney",
-            "au", "Australia/Adelaide",
-            "au", "Australia/Perth",
-            "au", "Australia/Eucla",
-            "aw", "America/Aruba",
-            "ax", "Europe/Mariehamn",
-            "az", "Asia/Baku",
-            "ba", "Europe/Sarajevo",
-            "bb", "America/Barbados",
-            "bd", "Asia/Dhaka",
-            "be", "Europe/Brussels",
-            "bf", "Africa/Ouagadougou",
-            "bg", "Europe/Sofia",
-            "bh", "Asia/Bahrain",
-            "bi", "Africa/Bujumbura",
-            "bj", "Africa/Porto-Novo",
-            "bm", "Atlantic/Bermuda",
-            "bn", "Asia/Brunei",
-            "bo", "America/La_Paz",
-            "br", "America/Noronha",
-            "br", "America/Sao_Paulo",
-            "br", "America/Manaus",
-            "bs", "America/Nassau",
-            "bt", "Asia/Thimphu",
-            "bw", "Africa/Gaborone",
-            "by", "Europe/Minsk",
-            "bz", "America/Belize",
-            "ca", "America/St_Johns",
-            "ca", "America/Halifax",
-            "ca", "America/Toronto",
-            "ca", "America/Winnipeg",
-            "ca", "America/Edmonton",
-            "ca", "America/Vancouver",
-            "cc", "Indian/Cocos",
-            "cd", "Africa/Lubumbashi",
-            "cd", "Africa/Kinshasa",
-            "cf", "Africa/Bangui",
-            "cg", "Africa/Brazzaville",
-            "ch", "Europe/Zurich",
-            "ci", "Africa/Abidjan",
-            "ck", "Pacific/Rarotonga",
-            "cl", "America/Santiago",
-            "cl", "Pacific/Easter",
-            "cm", "Africa/Douala",
-            "cn", "Asia/Shanghai",
-            "co", "America/Bogota",
-            "cr", "America/Costa_Rica",
-            "cu", "America/Havana",
-            "cv", "Atlantic/Cape_Verde",
-            "cx", "Indian/Christmas",
-            "cy", "Asia/Nicosia",
-            "cz", "Europe/Prague",
-            "de", "Europe/Berlin",
-            "dj", "Africa/Djibouti",
-            "dk", "Europe/Copenhagen",
-            "dm", "America/Dominica",
-            "do", "America/Santo_Domingo",
-            "dz", "Africa/Algiers",
-            "ec", "America/Guayaquil",
-            "ec", "Pacific/Galapagos",
-            "ee", "Europe/Tallinn",
-            "eg", "Africa/Cairo",
-            "eh", "Africa/El_Aaiun",
-            "er", "Africa/Asmara",
-            "es", "Europe/Madrid",
-            "es", "Atlantic/Canary",
-            "et", "Africa/Addis_Ababa",
-            "fi", "Europe/Helsinki",
-            "fj", "Pacific/Fiji",
-            "fk", "Atlantic/Stanley",
-            "fm", "Pacific/Ponape",
-            "fm", "Pacific/Truk",
-            "fo", "Atlantic/Faroe",
-            "fr", "Europe/Paris",
-            "ga", "Africa/Libreville",
-            "gb", "Europe/London",
-            "gd", "America/Grenada",
-            "ge", "Asia/Tbilisi",
-            "gf", "America/Cayenne",
-            "gg", "Europe/Guernsey",
-            "gh", "Africa/Accra",
-            "gi", "Europe/Gibraltar",
-            "gl", "America/Danmarkshavn",
-            "gl", "America/Scoresbysund",
-            "gl", "America/Godthab",
-            "gl", "America/Thule",
-            "gm", "Africa/Banjul",
-            "gn", "Africa/Conakry",
-            "gp", "America/Guadeloupe",
-            "gq", "Africa/Malabo",
-            "gr", "Europe/Athens",
-            "gs", "Atlantic/South_Georgia",
-            "gt", "America/Guatemala",
-            "gu", "Pacific/Guam",
-            "gw", "Africa/Bissau",
-            "gy", "America/Guyana",
-            "hk", "Asia/Hong_Kong",
-            "hn", "America/Tegucigalpa",
-            "hr", "Europe/Zagreb",
-            "ht", "America/Port-au-Prince",
-            "hu", "Europe/Budapest",
-            "id", "Asia/Jayapura",
-            "id", "Asia/Makassar",
-            "id", "Asia/Jakarta",
-            "ie", "Europe/Dublin",
-            "il", "Asia/Jerusalem",
-            "im", "Europe/Isle_of_Man",
-            "in", "Asia/Calcutta",
-            "io", "Indian/Chagos",
-            "iq", "Asia/Baghdad",
-            "ir", "Asia/Tehran",
-            "is", "Atlantic/Reykjavik",
-            "it", "Europe/Rome",
-            "je", "Europe/Jersey",
-            "jm", "America/Jamaica",
-            "jo", "Asia/Amman",
-            "jp", "Asia/Tokyo",
-            "ke", "Africa/Nairobi",
-            "kg", "Asia/Bishkek",
-            "kh", "Asia/Phnom_Penh",
-            "ki", "Pacific/Kiritimati",
-            "ki", "Pacific/Enderbury",
-            "ki", "Pacific/Tarawa",
-            "km", "Indian/Comoro",
-            "kn", "America/St_Kitts",
-            "kp", "Asia/Pyongyang",
-            "kr", "Asia/Seoul",
-            "kw", "Asia/Kuwait",
-            "ky", "America/Cayman",
-            "kz", "Asia/Almaty",
-            "kz", "Asia/Aqtau",
-            "la", "Asia/Vientiane",
-            "lb", "Asia/Beirut",
-            "lc", "America/St_Lucia",
-            "li", "Europe/Vaduz",
-            "lk", "Asia/Colombo",
-            "lr", "Africa/Monrovia",
-            "ls", "Africa/Maseru",
-            "lt", "Europe/Vilnius",
-            "lu", "Europe/Luxembourg",
-            "lv", "Europe/Riga",
-            "ly", "Africa/Tripoli",
-            "ma", "Africa/Casablanca",
-            "mc", "Europe/Monaco",
-            "md", "Europe/Chisinau",
-            "me", "Europe/Podgorica",
-            "mg", "Indian/Antananarivo",
-            "mh", "Pacific/Majuro",
-            "mk", "Europe/Skopje",
-            "ml", "Africa/Bamako",
-            "mm", "Asia/Rangoon",
-            "mn", "Asia/Choibalsan",
-            "mn", "Asia/Hovd",
-            "mo", "Asia/Macau",
-            "mp", "Pacific/Saipan",
-            "mq", "America/Martinique",
-            "mr", "Africa/Nouakchott",
-            "ms", "America/Montserrat",
-            "mt", "Europe/Malta",
-            "mu", "Indian/Mauritius",
-            "mv", "Indian/Maldives",
-            "mw", "Africa/Blantyre",
-            "mx", "America/Mexico_City",
-            "mx", "America/Chihuahua",
-            "mx", "America/Tijuana",
-            "my", "Asia/Kuala_Lumpur",
-            "mz", "Africa/Maputo",
-            "na", "Africa/Windhoek",
-            "nc", "Pacific/Noumea",
-            "ne", "Africa/Niamey",
-            "nf", "Pacific/Norfolk",
-            "ng", "Africa/Lagos",
-            "ni", "America/Managua",
-            "nl", "Europe/Amsterdam",
-            "no", "Europe/Oslo",
-            "np", "Asia/Katmandu",
-            "nr", "Pacific/Nauru",
-            "nu", "Pacific/Niue",
-            "nz", "Pacific/Auckland",
-            "nz", "Pacific/Chatham",
-            "om", "Asia/Muscat",
-            "pa", "America/Panama",
-            "pe", "America/Lima",
-            "pf", "Pacific/Gambier",
-            "pf", "Pacific/Marquesas",
-            "pf", "Pacific/Tahiti",
-            "pg", "Pacific/Port_Moresby",
-            "ph", "Asia/Manila",
-            "pk", "Asia/Karachi",
-            "pl", "Europe/Warsaw",
-            "pm", "America/Miquelon",
-            "pn", "Pacific/Pitcairn",
-            "pr", "America/Puerto_Rico",
-            "ps", "Asia/Gaza",
-            "pt", "Europe/Lisbon",
-            "pt", "Atlantic/Azores",
-            "pw", "Pacific/Palau",
-            "py", "America/Asuncion",
-            "qa", "Asia/Qatar",
-            "re", "Indian/Reunion",
-            "ro", "Europe/Bucharest",
-            "rs", "Europe/Belgrade",
-            "ru", "Asia/Kamchatka",
-            "ru", "Asia/Magadan",
-            "ru", "Asia/Vladivostok",
-            "ru", "Asia/Yakutsk",
-            "ru", "Asia/Irkutsk",
-            "ru", "Asia/Krasnoyarsk",
-            "ru", "Asia/Novosibirsk",
-            "ru", "Asia/Yekaterinburg",
-            "ru", "Europe/Samara",
-            "ru", "Europe/Moscow",
-            "ru", "Europe/Kaliningrad",
-            "rw", "Africa/Kigali",
-            "sa", "Asia/Riyadh",
-            "sb", "Pacific/Guadalcanal",
-            "sc", "Indian/Mahe",
-            "sd", "Africa/Khartoum",
-            "se", "Europe/Stockholm",
-            "sg", "Asia/Singapore",
-            "sh", "Atlantic/St_Helena",
-            "si", "Europe/Ljubljana",
-            "sj", "Arctic/Longyearbyen",
-            "sk", "Europe/Bratislava",
-            "sl", "Africa/Freetown",
-            "sm", "Europe/San_Marino",
-            "sn", "Africa/Dakar",
-            "so", "Africa/Mogadishu",
-            "sr", "America/Paramaribo",
-            "st", "Africa/Sao_Tome",
-            "sv", "America/El_Salvador",
-            "sy", "Asia/Damascus",
-            "sz", "Africa/Mbabane",
-            "tc", "America/Grand_Turk",
-            "td", "Africa/Ndjamena",
-            "tf", "Indian/Kerguelen",
-            "tg", "Africa/Lome",
-            "th", "Asia/Bangkok",
-            "tj", "Asia/Dushanbe",
-            "tk", "Pacific/Fakaofo",
-            "tl", "Asia/Dili",
-            "tm", "Asia/Ashgabat",
-            "tn", "Africa/Tunis",
-            "to", "Pacific/Tongatapu",
-            "tr", "Europe/Istanbul",
-            "tt", "America/Port_of_Spain",
-            "tv", "Pacific/Funafuti",
-            "tw", "Asia/Taipei",
-            "tz", "Africa/Dar_es_Salaam",
-            "ua", "Europe/Kiev",
-            "ug", "Africa/Kampala",
-            "um", "Pacific/Wake",
-            "um", "Pacific/Johnston",
-            "um", "Pacific/Midway",
-            "us", "America/New_York",
-            "us", "America/Chicago",
-            "us", "America/Denver",
-            "us", "America/Los_Angeles",
-            "us", "America/Anchorage",
-            "us", "Pacific/Honolulu",
-            "uy", "America/Montevideo",
-            "uz", "Asia/Tashkent",
-            "va", "Europe/Vatican",
-            "vc", "America/St_Vincent",
-            "ve", "America/Caracas",
-            "vg", "America/Tortola",
-            "vi", "America/St_Thomas",
-            "vn", "Asia/Saigon",
-            "vu", "Pacific/Efate",
-            "wf", "Pacific/Wallis",
-            "ws", "Pacific/Apia",
-            "ye", "Asia/Aden",
-            "yt", "Indian/Mayotte",
-            "za", "Africa/Johannesburg",
-            "zm", "Africa/Lusaka",
-            "zw", "Africa/Harare",
-        };
-
-        for (int i = 0; i < world.length; i += 2) {
-            String country = world[i];
-            String name = world[i + 1];
-
-            TimeZone tz = TimeZone.getTimeZone(name);
-            Calendar c = Calendar.getInstance(tz);
-            TimeZone guess;
-
-            c.set(2009, Calendar.JULY, 20, 12, 00, 00);
-            guess = guess(c, country);
-            assertEquals(name, guess.getID());
-
-            c.set(2009, Calendar.JANUARY, 20, 12, 00, 00);
-            guess = guess(c, country);
-            assertEquals(name, guess.getID());
-        }
-    }
-
-    public void testWorldWeird() throws Exception {
-        String[] world = new String[] {
-            // Distinguisable from Sydney only when DST not in effect
-            "au", "Australia/Lord_Howe",
-        };
-
-        for (int i = 0; i < world.length; i += 2) {
-            String country = world[i];
-            String name = world[i + 1];
-
-            TimeZone tz = TimeZone.getTimeZone(name);
-            Calendar c = Calendar.getInstance(tz);
-            TimeZone guess;
-
-            c.set(2009, Calendar.JULY, 20, 12, 00, 00);
-            guess = guess(c, country);
-            assertEquals(name, guess.getID());
-        }
-    }
-
-    private static TimeZone guess(Calendar c, String country) {
-        return TimeUtils.getTimeZone(c.get(c.ZONE_OFFSET) + c.get(c.DST_OFFSET),
-                                     c.get(c.DST_OFFSET) != 0,
-                                     c.getTimeInMillis(),
-                                     country);
-    }
-
-    public void testFormatDuration() {
-        assertFormatDuration("0", 0);
-        assertFormatDuration("-1ms", -1);
-        assertFormatDuration("+1ms", 1);
-        assertFormatDuration("+10ms", 10);
-        assertFormatDuration("+100ms", 100);
-        assertFormatDuration("+101ms", 101);
-        assertFormatDuration("+330ms", 330);
-        assertFormatDuration("+1s0ms", 1000);
-        assertFormatDuration("+1s330ms", 1330);
-        assertFormatDuration("+10s24ms", 10024);
-        assertFormatDuration("+1m0s30ms", 60030);
-        assertFormatDuration("+1h0m0s30ms", 3600030);
-        assertFormatDuration("+1d0h0m0s30ms", 86400030);
-    }
-
-    public void testFormatHugeDuration() {
-        assertFormatDuration("+15542d1h11m11s555ms", 1342833071555L);
-        assertFormatDuration("-15542d1h11m11s555ms", -1342833071555L);
-    }
-
-    private void assertFormatDuration(String expected, long duration) {
-        StringBuilder sb = new StringBuilder();
-        TimeUtils.formatDuration(duration, sb);
-        assertEquals("formatDuration(" + duration + ")", expected, sb.toString());
-    }
-}
diff --git a/docs/html/_redirects.yaml b/docs/html/_redirects.yaml
index 7200d47..6185dab 100644
--- a/docs/html/_redirects.yaml
+++ b/docs/html/_redirects.yaml
@@ -289,6 +289,8 @@
   to: /design/patterns/app-structure.html
 - from: /guide/practices/ui_guidelines/menu_design.html
   to: /design/patterns/actionbar.html
+- from: /design/patterns/accessibility.html
+  to: https://material.google.com/usability/accessibility.html
 - from: /design/get-started/ui-overview.html
   to: /design/handhelds/index.html
 - from: /design/building-blocks/buttons.html
diff --git a/docs/html/about/versions/nougat/android-7.0-samples.jd b/docs/html/about/versions/nougat/android-7.0-samples.jd
index e283a7a..ff63bef 100644
--- a/docs/html/about/versions/nougat/android-7.0-samples.jd
+++ b/docs/html/about/versions/nougat/android-7.0-samples.jd
@@ -6,7 +6,7 @@
 
 <p>
   Use the code samples below to learn about Android 7.0 capabilities and APIs. To
-  download the samples in Android Studio, select the <b>File &gt; Import
+  download the samples in Android Studio, select the <b>File &gt; New &gt; Import
   Samples</b> menu option.
 </p>
 
diff --git a/docs/html/design/_book.yaml b/docs/html/design/_book.yaml
index 18b4719..8ffa9a4 100644
--- a/docs/html/design/_book.yaml
+++ b/docs/html/design/_book.yaml
@@ -117,8 +117,6 @@
     path: /design/patterns/pure-android.html
   - title: Compatibility
     path: /design/patterns/compatibility.html
-  - title: Accessibility
-    path: /design/patterns/accessibility.html
   - title: Help
     path: /design/patterns/help.html
 
diff --git a/docs/html/design/patterns/accessibility.jd b/docs/html/design/patterns/accessibility.jd
deleted file mode 100644
index b910294..0000000
--- a/docs/html/design/patterns/accessibility.jd
+++ /dev/null
@@ -1,98 +0,0 @@
-page.title=Accessibility
-page.tags="accessibility","navigation","input"
-page.metaDescription=Design an app that's universally accessible to people with visual impairment, color deficiency, hearing loss, and limited dexterity.
-@jd:body
-
-<a class="notice-designers-material"
-  href="http://www.google.com/design/spec/usability/accessibility.html">
-  <div>
-    <h3>Material Design</h3>
-    <p>Accessibility<p>
-  </div>
-</a>
-
-<a class="notice-developers" href="{@docRoot}training/accessibility/index.html">
-  <div>
-    <h3>Developer Docs</h3>
-    <p>Implementing Accessibility</p>
-  </div>
-</a>
-
-<p>One of Android's missions is to organize the world's information and make it universally accessible and useful. Accessibility is the measure of how successfully a product can be used by people with varying abilities. Our mission applies to all users-including people with disabilities such as visual impairment, color deficiency, hearing loss, and limited dexterity.</p>
-<p><a href="https://www.google.com/#hl=en&q=universal+design&fp=1">Universal design</a> is the practice of making products that are inherently accessible to all users, regardless of ability. The Android design patterns were created in accordance with universal design principles, and following them will help your app meet basic usability standards. Adhering to universal design and enabling Android's accessibility tools will make your app as accessible as possible.</p>
-<p>Robust support for accessibility will increase your app's user base. It may also be required for adoption by some organizations.</p>
-<p><a href="http://www.google.com/accessibility/">Learn more about Google and accessibility.</a></p>
-
-<h2 id="tools">Android's Accessibility Tools</h2>
-<p>Android includes several features that support access for users with visual impairments; they don't require drastic visual changes to your app.</p>
-
-<ul>
-  <li><strong><a href="https://play.google.com/store/apps/details?id=com.google.android.marvin.talkback">TalkBack</a></strong> is a pre-installed screen reader service provided by Google. It uses spoken feedback to describe the results of actions such as launching an app, and events such as notifications.</li>
-  <li><strong>Explore by Touch</strong> is a system feature that works with TalkBack, allowing you to touch your device's screen and hear what's under your finger via spoken feedback. This feature is helpful to users with low vision.</li>
-  <li><strong>Accessibility settings</strong> let you modify your device's display and sound options, such as increasing the text size, changing the speed at which text is spoken, and more.</li>
-</ul>
-
-<p>Some users use hardware or software directional controllers (such as a D-pad, trackball, keyboard) to jump from selection to selection on a screen. They interact with the structure of your app in a linear fashion, similar to 4-way remote control navigation on a television.</p>
-
-<h2 id="tools">Guidelines</h2>
-<p>The Android design principle "I should always know where I am" is key for accessibility concerns. As a user navigates through an application, they need feedback and a mental model of where they are. All users benefit from a strong sense of information hierarchy and an architecture that makes sense. Most users benefit from visual and haptic feedback during their navigation (such as labels, colors, icons, touch feedback) Low vision users benefit from explicit verbal descriptions and large visuals with high contrast.</p>
-<p>As you design your app, think about the labels and notations needed to navigate your app by sound. When using Explore by Touch, the user enables an invisible but audible layer of structure in your application. Like any other aspect of app design, this structure can be simple, elegant, and robust. The following are Android's recommended guidelines to enable effective navigation for all users.</p>
-
-<h4>Make navigation intuitive</h4>
-<p>Design well-defined, clear task flows with minimal navigation steps, especially for major user tasks. Make sure those tasks are navigable via focus controls. </p>
-
-<h4>Use recommended touch target sizes</h4>
-<p>48 dp is the recommended touch target size for on screen elements. Read about <a href="{@docRoot}design/style/metrics-grids.html">Android Metrics and Grids</a> to learn about implementation strategies to help most of your users. For certain users, it may be appropriate to use larger touch targets. An example of this is educational apps, where buttons larger than the minimum recommendations are appropriate for children with developing motor skills and people with manual dexterity challenges.</p>
-
-
-<h4>Label visual UI elements meaningfully</h4>
-<p>In your wireframes, <a href="{@docRoot}guide/topics/ui/accessibility/apps.html#label-ui">label functional UI components</a> that have no visible text. Those components might be buttons, icons, tabs with icons, and icons with state (like stars). Developers can use the <code><a href="{@docRoot}guide/topics/ui/accessibility/apps.html#label-ui">contentDescription</a></code> attribute to set the label.</p>
-
-<div class ="cols">
-    <div class="col-8">
-      <img src="{@docRoot}design/media/accessibility_contentdesc.png">
-    </div>
-    <div class="col-5 with-callouts">
-      <ol>
-        <li class="value-1">group</li>
-        <li class="value-2">all contacts</li>
-        <li class="value-3">favorites</li>
-        <li class="value-4">search</li>
-        <li class="value-5">action overflow button</li>
-        <li class="value-6">
-          <em>when starred:</em> remove from favorites </br>
-          <em>when not starred:</em> add to favorties</li>
-        <li class="value-7">action overflow button</li>
-        <li class="value-8">text message</li>
-      </ol>
-  </div>
-</div>
-
-<h4>Provide alternatives to affordances that time out</h4>
-<p>Your app may have icons or controls that disappear after a certain amount of time. For example, five seconds after starting a video, playback controls may fade from the screen.</p>
-
-<p>Due to the way that TalkBack works, those controls are not read out loud unless they are focused on. If they fade out from the screen quickly, your user may not even be aware that they are available. Therefore, make sure that you are not relying on timed out controls for high priority task flows. (This is a good universal design guideline too.) If the controls enable an important function, make sure that the user can turn on the controls again and/or their function is duplicated elsewhere. You can also change the behavior of your app when accessibility services are turned on. Your developer may be able to make sure that timed-out controls won't disappear.</p>
-
-<h4>Use standard framework controls or enable TalkBack for custom controls</h4>
-<p>Standard Android framework controls work automatically with accessibility services and have ContentDescriptions built in by default.</p>
-
-<p>An oft-overlooked system control is font size. Users can turn on a system-wide large font size in Settings; using the default system font size in your application will enable the user's preferences in your app as well. To enable system font size in your app, mark text and their associated containers to be measured in <a href="{@docRoot}guide/practices/screens_support.html#screen-independence">scale pixels</a>.</p>
-
-<p>Also, keep in mind that when users have large fonts enabled or speak a different language than you, their type might be larger than the space you've allotted for it. Read <a href="{@docRoot}design/style/devices-displays.html">Devices and Displays</a> and <a href="http://developer.android.com/guide/practices/screens_support.html">Supporting Multiple Screens</a> for design strategies.</p>
-
-<p>If you use custom controls, Android has the developer tools in place to allow adherence to the above guidelines and provide meaningful descriptions about the UI. Provide adequate notation on your wireframes and direct your developer to the <a href="{@docRoot}guide/topics/ui/accessibility/apps.html#custom-views">Custom Views</a> documentation.</p>
-
-<h4>Try it out yourself</h4>
-<p>Turn on the TalkBack service in <strong>Settings > Accessibility</strong> and navigate your application using directional controls or eyes-free navigation.</p>
-
-
-
-<h2>Checklist</h2>
-<ul>
-  <li>Make navigation intuitive</li>
-  <li>Use recommended touch target sizes</li>
-  <li>Label visual UI elements meaningfully</li>
-  <li>Provide alternatives to affordances that time out</li>
-  <li>Use standard framework controls or enable TalkBack for custom controls</li>
-  <li>Try it out yourself</li>
-</ul>
diff --git a/docs/html/wear/preview/downloads.jd b/docs/html/wear/preview/downloads.jd
index da6a06d..bfa384b 100644
--- a/docs/html/wear/preview/downloads.jd
+++ b/docs/html/wear/preview/downloads.jd
@@ -346,7 +346,8 @@
     </p>
 
     <p class="warning">
-      <strong>Warning:</strong> Installing a system image on a watch removes all data from the
+      <strong>Warning:</strong> Installing a system image on a watch
+      removes all data from the
       watch, so you should back up your data first.
     </p>
 
@@ -355,8 +356,7 @@
     </h4>
 
     <p>
-      From the phone, unpair ("Forget") the watch.
-      Then on the watch, enable the Developer Options menu and ADB debugging as
+      On the watch, enable the Developer Options menu and ADB debugging as
       follows:
     </p>
 
@@ -365,14 +365,14 @@
       </li>
 
       <li>Scroll to the bottom of the menu. If no <strong>Developer
-      Options</strong> item is provided, tap <strong>About</strong>.
+      Options</strong> item is provided, tap <strong>System</strong>
+      and then <strong>About</strong>.
       </li>
 
       <li>Tap the build number 7 times.
       </li>
 
-      <li>From the Settings menu, tap the <strong>Developer Options</strong>
-      item.
+      <li>From the Settings menu, tap <strong>Developer Options</strong>.
       </li>
 
       <li>Enable ADB debugging.
@@ -418,7 +418,9 @@
       </li>
 
       <li>Use the following <a href="{@docRoot}tools/help/adb.html">adb
-      command</a> to confirm that the watch is available for flashing:
+      command</a> to confirm that the watch is recognized.
+      You may need to turn ADB debugging off and then on for the watch to
+      be recognized:
       <code>adb devices</code>
       </li>
 
@@ -432,11 +434,11 @@
       devices, <code>fastboot oem unlock</code>
       </li>
 
-      <li>On the watch, select the <strong>Unlock</strong> option.
+      <li>On the watch, select the option to unlock the bootloader.
       </li>
 
-      <li>Navigate to the directory where you unzipped the system image in Step
-      1. At the top level of that directory,
+      <li>On your computer, navigate to the directory where you unzipped the
+      system image in Step 1. At the top level of that directory,
       execute the <code>flash-all</code> script by typing
       <code>flash-all.sh</code> or, in the case of Windows,
       <code>flash-all.bat</code>. The following may need to
@@ -449,16 +451,16 @@
       Set up the watch
     </h4>
 
-      <p>
-        After the <code>flash-all</code> script finishes, your watch reboots.
-        Only pair the watch with a phone (so you can begin testing the preview)
-        by using the instructions in <a href="#set_up_a_phone">Set Up a Phone</a>.
-        Additionally, before installing an app, perform the
-        following steps on the watch to re-secure the watch's bootloader:
+    <p>
+      After the <code>flash-all</code> script finishes, the watch reboots.
+      Only pair the watch with a phone (so you can begin testing the preview)
+      by using the instructions in <a href="#set_up_a_phone">Set Up a Phone</a>.
+      Additionally, before installing an app, perform the
+      following steps on the watch to re-secure the watch's bootloader:
     </p>
 
     <ol>
-      <li>Open the Settings menu (on the watch).
+      <li>Open the Settings menu by long-pressing the physical button.
       </li>
 
       <li>Scroll to the bottom of the menu and tap <strong>About</strong>.
@@ -467,15 +469,16 @@
       <li>Tap the build number 7 times.
       </li>
 
-      <li>From the Settings menu, tap the <strong>Developer Options</strong>
-      item.
+      <li>From the Settings menu, tap <strong>Developer Options</strong>.
       </li>
 
       <li>Enable ADB debugging.
       </li>
 
       <li>Connect the watch to your computer and tap <strong>Always allow from
-      this computer</strong>.
+      this computer</strong>. (You may need to turn ADB debugging off
+      and then on, to be prompted to always allow ADB debugging from
+      the connected computer.)
       </li>
 
       <li>Use the following adb command to start the device in fastboot mode:
@@ -487,8 +490,11 @@
       devices, <code>fastboot oem lock</code>
       </li>
 
-      <li>On the watch, continue the boot by choosing
-      <strong>Start</strong> and touching <strong>'0'</strong>.
+      <li>On the watch, continue the boot as follows:
+      On an LGE Watch Urbane 2nd Edition, choose
+      <strong>Start</strong> and touch <strong>'0'</strong>.
+      On a Huawei Watch, confirm that <strong>Reboot</strong> is chosen and
+      long-press the physical button.
       </li>
     </ol>
 
@@ -610,7 +616,8 @@
 
     <p>
       After you install the beta version of the companion app on a phone,
-      you can pair the phone to the watch:
+      unpair ("Forget") any obsolete watch pairings, if necessary.
+      Then you can pair the phone to a newly-imaged watch:
     </p>
 
     <ol>
diff --git a/graphics/java/android/graphics/Atlas.java b/graphics/java/android/graphics/Atlas.java
deleted file mode 100644
index e0a5345..0000000
--- a/graphics/java/android/graphics/Atlas.java
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * Copyright (C) 2013 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.graphics;
-
-/**
- * @hide
- */
-public class Atlas {
-    /**
-     * WARNING: These flag values are part of the on-disk configuration information,
-     * do not change their values.
-     */
-
-    /** DELETED: FLAG_ROTATION = 0x01 */
-
-    /**
-     * This flag indicates whether the packing algorithm should leave
-     * an empty 1 pixel wide border around each bitmap. This border can
-     * be useful if the content of the atlas will be used in OpenGL using
-     * bilinear filtering.
-     */
-    public static final int FLAG_ADD_PADDING = 0x2;
-    /**
-     * Default flags: allow rotations and add padding.
-     */
-    public static final int FLAG_DEFAULTS = FLAG_ADD_PADDING;
-
-    /**
-     * Each type defines a different packing algorithm that can
-     * be used by an {@link Atlas}. The best algorithm to use
-     * will depend on the source dataset and the dimensions of
-     * the atlas.
-     */
-    public enum Type {
-        SliceMinArea,
-        SliceMaxArea,
-        SliceShortAxis,
-        SliceLongAxis
-    }
-
-    /**
-     * Represents a bitmap packed in the atlas. Each entry has a location in
-     * pixels in the atlas and a rotation flag.
-     */
-    public static class Entry {
-        /**
-         * Location, in pixels, of the bitmap on the X axis in the atlas.
-         */
-        public int x;
-        /**
-         * Location, in pixels, of the bitmap on the Y axis in the atlas.
-         */
-        public int y;
-    }
-
-    private final Policy mPolicy;
-
-    /**
-     * Creates a new atlas with the specified algorithm and dimensions
-     * in pixels. Calling this constructor is equivalent to calling
-     * {@link #Atlas(Atlas.Type, int, int, int)} with {@link #FLAG_DEFAULTS}.
-     *
-     * @param type The algorithm to use to pack rectangles in the atlas
-     * @param width The width of the atlas in pixels
-     * @param height The height of the atlas in pixels
-     *
-     * @see #Atlas(Atlas.Type, int, int, int)
-     */
-    public Atlas(Type type, int width, int height) {
-        this(type, width, height, FLAG_DEFAULTS);
-    }
-
-    /**
-     * Creates a new atlas with the specified algorithm and dimensions
-     * in pixels. A set of flags can also be specified to control the
-     * behavior of the atlas.
-     *
-     * @param type The algorithm to use to pack rectangles in the atlas
-     * @param width The width of the atlas in pixels
-     * @param height The height of the atlas in pixels
-     * @param flags Optional flags to control the behavior of the atlas:
-     *              {@link #FLAG_ADD_PADDING}, {@link #FLAG_ALLOW_ROTATIONS}
-     *
-     * @see #Atlas(Atlas.Type, int, int)
-     */
-    public Atlas(Type type, int width, int height, int flags) {
-        mPolicy = findPolicy(type, width, height, flags);
-    }
-
-    /**
-     * Packs a rectangle of the specified dimensions in this atlas.
-     *
-     * @param width The width of the rectangle to pack in the atlas
-     * @param height The height of the rectangle to pack in the atlas
-     *
-     * @return An {@link Entry} instance if the rectangle was packed in
-     *         the atlas, or null if the rectangle could not fit
-     *
-     * @see #pack(int, int, Atlas.Entry)
-     */
-    public Entry pack(int width, int height) {
-        return pack(width, height, null);
-    }
-
-    /**
-     * Packs a rectangle of the specified dimensions in this atlas.
-     *
-     * @param width The width of the rectangle to pack in the atlas
-     * @param height The height of the rectangle to pack in the atlas
-     * @param entry Out parameter that will be filled in with the location
-     *              and attributes of the packed rectangle, can be null
-     *
-     * @return An {@link Entry} instance if the rectangle was packed in
-     *         the atlas, or null if the rectangle could not fit
-     *
-     * @see #pack(int, int)
-     */
-    public Entry pack(int width, int height, Entry entry) {
-        if (entry == null) entry = new Entry();
-        return mPolicy.pack(width, height, entry);
-    }
-
-    private static Policy findPolicy(Type type, int width, int height, int flags) {
-        switch (type) {
-            case SliceMinArea:
-                return new SlicePolicy(width, height, flags,
-                        new SlicePolicy.MinAreaSplitDecision());
-            case SliceMaxArea:
-                return new SlicePolicy(width, height, flags,
-                        new SlicePolicy.MaxAreaSplitDecision());
-            case SliceShortAxis:
-                return new SlicePolicy(width, height, flags,
-                        new SlicePolicy.ShorterFreeAxisSplitDecision());
-            case SliceLongAxis:
-                return new SlicePolicy(width, height, flags,
-                        new SlicePolicy.LongerFreeAxisSplitDecision());
-        }
-        return null;
-    }
-
-    /**
-     * A policy defines how the atlas performs the packing operation.
-     */
-    private static abstract class Policy {
-        abstract Entry pack(int width, int height, Entry entry);
-    }
-
-    /**
-     * The Slice algorightm divides the remaining empty space either
-     * horizontally or vertically after a bitmap is placed in the atlas.
-     *
-     * NOTE: the algorithm is explained below using a tree but is
-     * implemented using a linked list instead for performance reasons.
-     *
-     * The algorithm starts with a single empty cell covering the entire
-     * atlas:
-     *
-     *  -----------------------
-     * |                       |
-     * |                       |
-     * |                       |
-     * |      Empty space      |
-     * |          (C0)         |
-     * |                       |
-     * |                       |
-     * |                       |
-     *  -----------------------
-     *
-     * The tree of cells looks like this:
-     *
-     * N0(free)
-     *
-     * The algorithm then places a bitmap B1, if possible:
-     *
-     *  -----------------------
-     * |        |              |
-     * |   B1   |              |
-     * |        |              |
-     * |--------               |
-     * |                       |
-     * |                       |
-     * |                       |
-     * |                       |
-     *  -----------------------
-     *
-     *  After placing a bitmap in an empty cell, the algorithm splits
-     *  the remaining space in two new empty cells. The split can occur
-     *  vertically or horizontally (this is controlled by the "split
-     *  decision" parameter of the algorithm.)
-     *
-     *  Here is for the instance the result of a vertical split:
-     *
-     *  -----------------------
-     * |        |              |
-     * |   B1   |              |
-     * |        |              |
-     * |--------|      C2      |
-     * |        |              |
-     * |        |              |
-     * |   C1   |              |
-     * |        |              |
-     *  -----------------------
-     *
-     * The cells tree now looks like this:
-     *
-     *       C0(occupied)
-     *           / \
-     *          /   \
-     *         /     \
-     *        /       \
-     *    C1(free)  C2(free)
-     *
-     * For each bitmap to place in the atlas, the Slice algorithm
-     * will visit the free cells until it finds one where a bitmap can
-     * fit. It will then split the now occupied cell and proceed onto
-     * the next bitmap.
-     */
-    private static class SlicePolicy extends Policy {
-        private final Cell mRoot = new Cell();
-
-        private final SplitDecision mSplitDecision;
-
-        private final int mPadding;
-
-        /**
-         * A cell represents a sub-rectangle of the atlas. A cell is
-         * a node in a linked list representing the available free
-         * space in the atlas.
-         */
-        private static class Cell {
-            int x;
-            int y;
-
-            int width;
-            int height;
-
-            Cell next;
-
-            @Override
-            public String toString() {
-                return String.format("cell[x=%d y=%d width=%d height=%d", x, y, width, height);
-            }
-        }
-
-        SlicePolicy(int width, int height, int flags, SplitDecision splitDecision) {
-            mPadding = (flags & FLAG_ADD_PADDING) != 0 ? 1 : 0;
-
-            // The entire atlas is empty at first, minus padding
-            Cell first = new Cell();
-            first.x = first.y = mPadding;
-            first.width = width - 2 * mPadding;
-            first.height = height - 2 * mPadding;
-
-            mRoot.next = first;
-            mSplitDecision = splitDecision;
-        }
-
-        @Override
-        Entry pack(int width, int height, Entry entry) {
-            Cell cell = mRoot.next;
-            Cell prev = mRoot;
-
-            while (cell != null) {
-                if (insert(cell, prev, width, height, entry)) {
-                    return entry;
-                }
-
-                prev = cell;
-                cell = cell.next;
-            }
-
-            return null;
-        }
-
-        /**
-         * Defines how the remaining empty space should be split up:
-         * vertically or horizontally.
-         */
-        private static interface SplitDecision {
-            /**
-             * Returns true if the remaining space defined by
-             * <code>freeWidth</code> and <code>freeHeight</code>
-             * should be split horizontally.
-             *
-             * @param freeWidth The rectWidth of the free space after packing a rectangle
-             * @param freeHeight The rectHeight of the free space after packing a rectangle
-             * @param rectWidth The rectWidth of the rectangle that was packed in a cell
-             * @param rectHeight The rectHeight of the rectangle that was packed in a cell
-             */
-            boolean splitHorizontal(int freeWidth, int freeHeight,
-                    int rectWidth, int rectHeight);
-        }
-
-        // Splits the free area horizontally to minimize the horizontal section area
-        private static class MinAreaSplitDecision implements SplitDecision {
-            @Override
-            public boolean splitHorizontal(int freeWidth, int freeHeight,
-                    int rectWidth, int rectHeight) {
-                return rectWidth * freeHeight > freeWidth * rectHeight;
-            }
-        }
-
-        // Splits the free area horizontally to maximize the horizontal section area
-        private static class MaxAreaSplitDecision implements SplitDecision {
-            @Override
-            public boolean splitHorizontal(int freeWidth, int freeHeight,
-                    int rectWidth, int rectHeight) {
-                return rectWidth * freeHeight <= freeWidth * rectHeight;
-            }
-        }
-
-        // Splits the free area horizontally if the horizontal axis is shorter
-        private static class ShorterFreeAxisSplitDecision implements SplitDecision {
-            @Override
-            public boolean splitHorizontal(int freeWidth, int freeHeight,
-                    int rectWidth, int rectHeight) {
-                return freeWidth <= freeHeight;
-            }
-        }
-
-        // Splits the free area horizontally if the vertical axis is shorter
-        private static class LongerFreeAxisSplitDecision implements SplitDecision {
-            @Override
-            public boolean splitHorizontal(int freeWidth, int freeHeight,
-                    int rectWidth, int rectHeight) {
-                return freeWidth > freeHeight;
-            }
-        }
-
-        /**
-         * Attempts to pack a rectangle of specified dimensions in the available
-         * empty space.
-         *
-         * @param cell The cell representing free space in which to pack the rectangle
-         * @param prev The previous cell in the free space linked list
-         * @param width The width of the rectangle to pack
-         * @param height The height of the rectangle to pack
-         * @param entry Stores the location of the packged rectangle, if it fits
-         *
-         * @return True if the rectangle was packed in the atlas, false otherwise
-         */
-        private boolean insert(Cell cell, Cell prev, int width, int height, Entry entry) {
-            if (cell.width < width || cell.height < height) {
-                return false;
-            }
-
-            // Remaining free space after packing the rectangle
-            int deltaWidth = cell.width - width;
-            int deltaHeight = cell.height - height;
-
-            // Split the remaining free space into two new cells
-            Cell first = new Cell();
-            Cell second = new Cell();
-
-            first.x = cell.x + width + mPadding;
-            first.y = cell.y;
-            first.width = deltaWidth - mPadding;
-
-            second.x = cell.x;
-            second.y = cell.y + height + mPadding;
-            second.height = deltaHeight - mPadding;
-
-            if (mSplitDecision.splitHorizontal(deltaWidth, deltaHeight,
-                    width, height)) {
-                first.height = height;
-                second.width = cell.width;
-            } else {
-                first.height = cell.height;
-                second.width = width;
-
-                // The order of the cells matters for efficient packing
-                // We want to give priority to the cell chosen by the
-                // split decision heuristic
-                Cell temp = first;
-                first = second;
-                second = temp;
-            }
-
-            // Remove degenerate cases to keep the free list as small as possible
-            if (first.width > 0 && first.height > 0) {
-                prev.next = first;
-                prev = first;
-            }
-
-            if (second.width > 0 && second.height > 0) {
-                prev.next = second;
-                second.next = cell.next;
-            } else {
-                prev.next = cell.next;
-            }
-
-            // The cell is now completely removed from the free list
-            cell.next = null;
-
-            // Return the location and rotation of the packed rectangle
-            entry.x = cell.x;
-            entry.y = cell.y;
-
-            return true;
-        }
-    }
-}
diff --git a/graphics/java/android/graphics/drawable/BitmapDrawable.java b/graphics/java/android/graphics/drawable/BitmapDrawable.java
index df107f5..6deeb0d 100644
--- a/graphics/java/android/graphics/drawable/BitmapDrawable.java
+++ b/graphics/java/android/graphics/drawable/BitmapDrawable.java
@@ -49,7 +49,6 @@
 import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.IOException;
-import java.util.Collection;
 
 /**
  * A Drawable that wraps a bitmap and can be tiled, stretched, or aligned. You can create a
@@ -957,14 +956,6 @@
         }
 
         @Override
-        public int addAtlasableBitmaps(Collection<Bitmap> atlasList) {
-            if (isAtlasable(mBitmap) && atlasList.add(mBitmap)) {
-                return mBitmap.getWidth() * mBitmap.getHeight();
-            }
-            return 0;
-        }
-
-        @Override
         public Drawable newDrawable() {
             return new BitmapDrawable(this, null);
         }
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index 10f0dda..6ddc2d7 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -58,7 +58,6 @@
 import java.io.InputStream;
 import java.lang.ref.WeakReference;
 import java.util.Arrays;
-import java.util.Collection;
 
 /**
  * A Drawable is a general abstraction for "something that can be drawn."  Most
@@ -1367,19 +1366,6 @@
         public abstract @Config int getChangingConfigurations();
 
         /**
-         * @return Total pixel count
-         * @hide
-         */
-        public int addAtlasableBitmaps(@NonNull Collection<Bitmap> atlasList) {
-            return 0;
-        }
-
-        /** @hide */
-        protected final boolean isAtlasable(@Nullable Bitmap bitmap) {
-            return bitmap != null && bitmap.getConfig() == Bitmap.Config.ARGB_8888;
-        }
-
-        /**
          * Return whether this constant state can have a theme applied.
          */
         public boolean canApplyTheme() {
diff --git a/graphics/java/android/graphics/drawable/DrawableContainer.java b/graphics/java/android/graphics/drawable/DrawableContainer.java
index c7a3c75..abdc2b9 100644
--- a/graphics/java/android/graphics/drawable/DrawableContainer.java
+++ b/graphics/java/android/graphics/drawable/DrawableContainer.java
@@ -21,7 +21,6 @@
 import android.content.res.ColorStateList;
 import android.content.res.Resources;
 import android.content.res.Resources.Theme;
-import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
 import android.graphics.Insets;
@@ -35,8 +34,6 @@
 import android.util.SparseArray;
 import android.view.View;
 
-import java.util.Collection;
-
 /**
  * A helper class that contains several {@link Drawable}s and selects which one to use.
  *
@@ -1194,19 +1191,6 @@
             return true;
         }
 
-        /** @hide */
-        @Override
-        public int addAtlasableBitmaps(Collection<Bitmap> atlasList) {
-            final int N = mNumChildren;
-            int pixelCount = 0;
-            for (int i = 0; i < N; i++) {
-                final ConstantState state = getChild(i).getConstantState();
-                if (state != null) {
-                    pixelCount += state.addAtlasableBitmaps(atlasList);
-                }
-            }
-            return pixelCount;
-        }
     }
 
     protected void setConstantState(DrawableContainerState state) {
diff --git a/graphics/java/android/graphics/drawable/DrawableWrapper.java b/graphics/java/android/graphics/drawable/DrawableWrapper.java
index 5abfc54..5887939 100644
--- a/graphics/java/android/graphics/drawable/DrawableWrapper.java
+++ b/graphics/java/android/graphics/drawable/DrawableWrapper.java
@@ -28,7 +28,6 @@
 import android.content.res.Resources;
 import android.content.res.Resources.Theme;
 import android.content.res.TypedArray;
-import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
 import android.graphics.Insets;
@@ -41,7 +40,6 @@
 import android.view.View;
 
 import java.io.IOException;
-import java.util.Collection;
 
 /**
  * Drawable container with only one child element.
@@ -508,15 +506,6 @@
         }
 
         @Override
-        public int addAtlasableBitmaps(Collection<Bitmap> atlasList) {
-            final Drawable.ConstantState state = mDrawableState;
-            if (state != null) {
-                return state.addAtlasableBitmaps(atlasList);
-            }
-            return 0;
-        }
-
-        @Override
         public Drawable newDrawable() {
             return newDrawable(null);
         }
diff --git a/graphics/java/android/graphics/drawable/LayerDrawable.java b/graphics/java/android/graphics/drawable/LayerDrawable.java
index c30c4c2..e09fea5 100644
--- a/graphics/java/android/graphics/drawable/LayerDrawable.java
+++ b/graphics/java/android/graphics/drawable/LayerDrawable.java
@@ -23,7 +23,6 @@
 import android.content.res.Resources;
 import android.content.res.Resources.Theme;
 import android.content.res.TypedArray;
-import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.ColorFilter;
 import android.graphics.Outline;
@@ -42,7 +41,6 @@
 import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.IOException;
-import java.util.Collection;
 
 /**
  * A Drawable that manages an array of other Drawables. These are drawn in array
@@ -2128,22 +2126,6 @@
             mHaveIsStateful = false;
         }
 
-        @Override
-        public int addAtlasableBitmaps(Collection<Bitmap> atlasList) {
-            final ChildDrawable[] array = mChildren;
-            final int N = mNum;
-            int pixelCount = 0;
-            for (int i = 0; i < N; i++) {
-                final Drawable dr = array[i].mDrawable;
-                if (dr != null) {
-                    final ConstantState state = dr.getConstantState();
-                    if (state != null) {
-                        pixelCount += state.addAtlasableBitmaps(atlasList);
-                    }
-                }
-            }
-            return pixelCount;
-        }
     }
 }
 
diff --git a/graphics/java/android/graphics/drawable/NinePatchDrawable.java b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
index d962385..c7183d9 100644
--- a/graphics/java/android/graphics/drawable/NinePatchDrawable.java
+++ b/graphics/java/android/graphics/drawable/NinePatchDrawable.java
@@ -49,7 +49,6 @@
 
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Collection;
 
 /**
  *
@@ -633,15 +632,6 @@
         }
 
         @Override
-        public int addAtlasableBitmaps(Collection<Bitmap> atlasList) {
-            final Bitmap bitmap = mNinePatch.getBitmap();
-            if (isAtlasable(bitmap) && atlasList.add(bitmap)) {
-                return bitmap.getWidth() * bitmap.getHeight();
-            }
-            return 0;
-        }
-
-        @Override
         public Drawable newDrawable() {
             return new NinePatchDrawable(this, null);
         }
diff --git a/include/androidfw/AttributeResolution.h b/include/androidfw/AttributeResolution.h
new file mode 100644
index 0000000..2f60a1d
--- /dev/null
+++ b/include/androidfw/AttributeResolution.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROIDFW_ATTRIBUTERESOLUTION_H
+#define ANDROIDFW_ATTRIBUTERESOLUTION_H
+
+#include <androidfw/ResourceTypes.h>
+
+namespace android {
+
+// These are all variations of the same method. They each perform the exact same operation,
+// but on various data sources. I *think* they are re-written to avoid an extra branch
+// in the inner loop, but after one branch miss (some pointer != null), the branch predictor should
+// predict the rest of the iterations' branch correctly.
+// TODO(adamlesinski): Run performance tests against these methods and a new, single method
+// that uses all the sources and branches to the right ones within the inner loop.
+
+bool resolveAttrs(ResTable::Theme* theme,
+                  uint32_t defStyleAttr,
+                  uint32_t defStyleRes,
+                  uint32_t* srcValues, size_t srcValuesLength,
+                  uint32_t* attrs, size_t attrsLength,
+                  uint32_t* outValues,
+                  uint32_t* outIndices);
+
+bool applyStyle(ResTable::Theme* theme, ResXMLParser* xmlParser,
+                uint32_t defStyleAttr,
+                uint32_t defStyleRes,
+                uint32_t* attrs, size_t attrsLength,
+                uint32_t* outValues,
+                uint32_t* outIndices);
+
+bool retrieveAttributes(const ResTable* res, ResXMLParser* xmlParser,
+                        uint32_t* attrs, size_t attrsLength,
+                        uint32_t* outValues,
+                        uint32_t* outIndices);
+
+} // namespace android
+
+#endif /* ANDROIDFW_ATTRIBUTERESOLUTION_H */
diff --git a/libs/androidfw/Android.mk b/libs/androidfw/Android.mk
index 6bbfcd2..7d7d42c7 100644
--- a/libs/androidfw/Android.mk
+++ b/libs/androidfw/Android.mk
@@ -21,6 +21,7 @@
     Asset.cpp \
     AssetDir.cpp \
     AssetManager.cpp \
+    AttributeResolution.cpp \
     LocaleData.cpp \
     misc.cpp \
     ObbFile.cpp \
diff --git a/libs/androidfw/AssetManager.cpp b/libs/androidfw/AssetManager.cpp
index 796cb36..371bc9a 100644
--- a/libs/androidfw/AssetManager.cpp
+++ b/libs/androidfw/AssetManager.cpp
@@ -35,6 +35,9 @@
 #include <utils/threads.h>
 #include <utils/Timers.h>
 #include <utils/Trace.h>
+#ifndef _WIN32
+#include <sys/file.h>
+#endif
 
 #include <assert.h>
 #include <dirent.h>
@@ -647,6 +650,12 @@
         return;
     }
 
+#ifndef _WIN32
+    if (TEMP_FAILURE_RETRY(flock(fileno(fin), LOCK_SH)) != 0) {
+        fclose(fin);
+        return;
+    }
+#endif
     char buf[1024];
     while (fgets(buf, sizeof(buf), fin)) {
         // format of each line:
@@ -677,6 +686,10 @@
             const_cast<AssetManager*>(this)->mZipSet.addOverlay(targetPackagePath, oap);
         }
     }
+
+#ifndef _WIN32
+    TEMP_FAILURE_RETRY(flock(fileno(fin), LOCK_UN));
+#endif
     fclose(fin);
 }
 
diff --git a/libs/androidfw/AttributeResolution.cpp b/libs/androidfw/AttributeResolution.cpp
new file mode 100644
index 0000000..ad428a4
--- /dev/null
+++ b/libs/androidfw/AttributeResolution.cpp
@@ -0,0 +1,500 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "androidfw/AttributeFinder.h"
+#include "androidfw/AttributeResolution.h"
+#include "androidfw/ResourceTypes.h"
+
+#include <android/log.h>
+#include <cstdint>
+
+constexpr bool kDebugStyles = false;
+
+namespace android {
+
+enum {
+    STYLE_NUM_ENTRIES = 6,
+    STYLE_TYPE = 0,
+    STYLE_DATA = 1,
+    STYLE_ASSET_COOKIE = 2,
+    STYLE_RESOURCE_ID = 3,
+    STYLE_CHANGING_CONFIGURATIONS = 4,
+    STYLE_DENSITY = 5
+};
+
+class XmlAttributeFinder : public BackTrackingAttributeFinder<XmlAttributeFinder, size_t> {
+public:
+    explicit XmlAttributeFinder(const ResXMLParser* parser) :
+        BackTrackingAttributeFinder(0, parser != NULL ? parser->getAttributeCount() : 0),
+        mParser(parser) {
+    }
+
+    inline uint32_t getAttribute(size_t index) const {
+        return mParser->getAttributeNameResID(index);
+    }
+
+private:
+    const ResXMLParser* mParser;
+};
+
+class BagAttributeFinder :
+        public BackTrackingAttributeFinder<BagAttributeFinder, const ResTable::bag_entry*> {
+public:
+    BagAttributeFinder(const ResTable::bag_entry* start, const ResTable::bag_entry* end) :
+        BackTrackingAttributeFinder(start, end) {}
+
+    inline uint32_t getAttribute(const ResTable::bag_entry* entry) const {
+        return entry->map.name.ident;
+    }
+};
+
+bool resolveAttrs(ResTable::Theme* theme,
+                  uint32_t defStyleAttr,
+                  uint32_t defStyleRes,
+                  uint32_t* srcValues, size_t srcValuesLength,
+                  uint32_t* attrs, size_t attrsLength,
+                  uint32_t* outValues,
+                  uint32_t* outIndices) {
+    if (kDebugStyles) {
+        ALOGI("APPLY STYLE: theme=0x%p defStyleAttr=0x%x "
+              "defStyleRes=0x%x", theme, defStyleAttr, defStyleRes);
+    }
+
+    const ResTable& res = theme->getResTable();
+    ResTable_config config;
+    Res_value value;
+
+    int indicesIdx = 0;
+
+    // Load default style from attribute, if specified...
+    uint32_t defStyleBagTypeSetFlags = 0;
+    if (defStyleAttr != 0) {
+        Res_value value;
+        if (theme->getAttribute(defStyleAttr, &value, &defStyleBagTypeSetFlags) >= 0) {
+            if (value.dataType == Res_value::TYPE_REFERENCE) {
+                defStyleRes = value.data;
+            }
+        }
+    }
+
+    // Now lock down the resource object and start pulling stuff from it.
+    res.lock();
+
+    // Retrieve the default style bag, if requested.
+    const ResTable::bag_entry* defStyleStart = NULL;
+    uint32_t defStyleTypeSetFlags = 0;
+    ssize_t bagOff = defStyleRes != 0
+            ? res.getBagLocked(defStyleRes, &defStyleStart, &defStyleTypeSetFlags) : -1;
+    defStyleTypeSetFlags |= defStyleBagTypeSetFlags;
+    const ResTable::bag_entry* const defStyleEnd = defStyleStart + (bagOff >= 0 ? bagOff : 0);
+    BagAttributeFinder defStyleAttrFinder(defStyleStart, defStyleEnd);
+
+    // Now iterate through all of the attributes that the client has requested,
+    // filling in each with whatever data we can find.
+    ssize_t block = 0;
+    uint32_t typeSetFlags;
+    for (size_t ii=0; ii<attrsLength; ii++) {
+        const uint32_t curIdent = attrs[ii];
+
+        if (kDebugStyles) {
+            ALOGI("RETRIEVING ATTR 0x%08x...", curIdent);
+        }
+
+        // Try to find a value for this attribute...  we prioritize values
+        // coming from, first XML attributes, then XML style, then default
+        // style, and finally the theme.
+        value.dataType = Res_value::TYPE_NULL;
+        value.data = Res_value::DATA_NULL_UNDEFINED;
+        typeSetFlags = 0;
+        config.density = 0;
+
+        // Retrieve the current input value if available.
+        if (srcValuesLength > 0 && srcValues[ii] != 0) {
+            block = -1;
+            value.dataType = Res_value::TYPE_ATTRIBUTE;
+            value.data = srcValues[ii];
+            if (kDebugStyles) {
+                ALOGI("-> From values: type=0x%x, data=0x%08x", value.dataType, value.data);
+            }
+        }
+
+        if (value.dataType == Res_value::TYPE_NULL) {
+            const ResTable::bag_entry* const defStyleEntry = defStyleAttrFinder.find(curIdent);
+            if (defStyleEntry != defStyleEnd) {
+                block = defStyleEntry->stringBlock;
+                typeSetFlags = defStyleTypeSetFlags;
+                value = defStyleEntry->map.value;
+                if (kDebugStyles) {
+                    ALOGI("-> From def style: type=0x%x, data=0x%08x", value.dataType, value.data);
+                }
+            }
+        }
+
+        uint32_t resid = 0;
+        if (value.dataType != Res_value::TYPE_NULL) {
+            // Take care of resolving the found resource to its final value.
+            ssize_t newBlock = theme->resolveAttributeReference(&value, block,
+                    &resid, &typeSetFlags, &config);
+            if (newBlock >= 0) block = newBlock;
+            if (kDebugStyles) {
+                ALOGI("-> Resolved attr: type=0x%x, data=0x%08x", value.dataType, value.data);
+            }
+        } else {
+            // If we still don't have a value for this attribute, try to find
+            // it in the theme!
+            ssize_t newBlock = theme->getAttribute(curIdent, &value, &typeSetFlags);
+            if (newBlock >= 0) {
+                if (kDebugStyles) {
+                    ALOGI("-> From theme: type=0x%x, data=0x%08x", value.dataType, value.data);
+                }
+                newBlock = res.resolveReference(&value, block, &resid,
+                        &typeSetFlags, &config);
+                if (newBlock >= 0) block = newBlock;
+                if (kDebugStyles) {
+                    ALOGI("-> Resolved theme: type=0x%x, data=0x%08x", value.dataType, value.data);
+                }
+            }
+        }
+
+        // Deal with the special @null value -- it turns back to TYPE_NULL.
+        if (value.dataType == Res_value::TYPE_REFERENCE && value.data == 0) {
+            if (kDebugStyles) {
+                ALOGI("-> Setting to @null!");
+            }
+            value.dataType = Res_value::TYPE_NULL;
+            value.data = Res_value::DATA_NULL_UNDEFINED;
+            block = -1;
+        }
+
+        if (kDebugStyles) {
+            ALOGI("Attribute 0x%08x: type=0x%x, data=0x%08x", curIdent, value.dataType,
+                  value.data);
+        }
+
+        // Write the final value back to Java.
+        outValues[STYLE_TYPE] = value.dataType;
+        outValues[STYLE_DATA] = value.data;
+        outValues[STYLE_ASSET_COOKIE] = block != -1
+                ? static_cast<uint32_t>(res.getTableCookie(block)) : static_cast<uint32_t>(-1);
+        outValues[STYLE_RESOURCE_ID] = resid;
+        outValues[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags;
+        outValues[STYLE_DENSITY] = config.density;
+
+        if (outIndices != NULL && value.dataType != Res_value::TYPE_NULL) {
+            indicesIdx++;
+            outIndices[indicesIdx] = ii;
+        }
+
+        outValues += STYLE_NUM_ENTRIES;
+    }
+
+    res.unlock();
+
+    if (outIndices != NULL) {
+        outIndices[0] = indicesIdx;
+    }
+    return true;
+}
+
+bool applyStyle(ResTable::Theme* theme, ResXMLParser* xmlParser,
+                uint32_t defStyleAttr,
+                uint32_t defStyleRes,
+                uint32_t* attrs, size_t attrsLength,
+                uint32_t* outValues,
+                uint32_t* outIndices) {
+    if (kDebugStyles) {
+        ALOGI("APPLY STYLE: theme=0x%p defStyleAttr=0x%x defStyleRes=0x%x xml=0x%p",
+              theme, defStyleAttr, defStyleRes, xmlParser);
+    }
+
+    const ResTable& res = theme->getResTable();
+    ResTable_config config;
+    Res_value value;
+
+    int indicesIdx = 0;
+
+    // Load default style from attribute, if specified...
+    uint32_t defStyleBagTypeSetFlags = 0;
+    if (defStyleAttr != 0) {
+        Res_value value;
+        if (theme->getAttribute(defStyleAttr, &value, &defStyleBagTypeSetFlags) >= 0) {
+            if (value.dataType == Res_value::TYPE_REFERENCE) {
+                defStyleRes = value.data;
+            }
+        }
+    }
+
+    // Retrieve the style class associated with the current XML tag.
+    int style = 0;
+    uint32_t styleBagTypeSetFlags = 0;
+    if (xmlParser != NULL) {
+        ssize_t idx = xmlParser->indexOfStyle();
+        if (idx >= 0 && xmlParser->getAttributeValue(idx, &value) >= 0) {
+            if (value.dataType == value.TYPE_ATTRIBUTE) {
+                if (theme->getAttribute(value.data, &value, &styleBagTypeSetFlags) < 0) {
+                    value.dataType = Res_value::TYPE_NULL;
+                }
+            }
+            if (value.dataType == value.TYPE_REFERENCE) {
+                style = value.data;
+            }
+        }
+    }
+
+    // Now lock down the resource object and start pulling stuff from it.
+    res.lock();
+
+    // Retrieve the default style bag, if requested.
+    const ResTable::bag_entry* defStyleAttrStart = NULL;
+    uint32_t defStyleTypeSetFlags = 0;
+    ssize_t bagOff = defStyleRes != 0
+            ? res.getBagLocked(defStyleRes, &defStyleAttrStart, &defStyleTypeSetFlags) : -1;
+    defStyleTypeSetFlags |= defStyleBagTypeSetFlags;
+    const ResTable::bag_entry* const defStyleAttrEnd = defStyleAttrStart + (bagOff >= 0 ? bagOff : 0);
+    BagAttributeFinder defStyleAttrFinder(defStyleAttrStart, defStyleAttrEnd);
+
+    // Retrieve the style class bag, if requested.
+    const ResTable::bag_entry* styleAttrStart = NULL;
+    uint32_t styleTypeSetFlags = 0;
+    bagOff = style != 0 ? res.getBagLocked(style, &styleAttrStart, &styleTypeSetFlags) : -1;
+    styleTypeSetFlags |= styleBagTypeSetFlags;
+    const ResTable::bag_entry* const styleAttrEnd = styleAttrStart + (bagOff >= 0 ? bagOff : 0);
+    BagAttributeFinder styleAttrFinder(styleAttrStart, styleAttrEnd);
+
+    // Retrieve the XML attributes, if requested.
+    static const ssize_t kXmlBlock = 0x10000000;
+    XmlAttributeFinder xmlAttrFinder(xmlParser);
+    const size_t xmlAttrEnd = xmlParser != NULL ? xmlParser->getAttributeCount() : 0;
+
+    // Now iterate through all of the attributes that the client has requested,
+    // filling in each with whatever data we can find.
+    ssize_t block = 0;
+    uint32_t typeSetFlags;
+    for (size_t ii = 0; ii < attrsLength; ii++) {
+        const uint32_t curIdent = attrs[ii];
+
+        if (kDebugStyles) {
+            ALOGI("RETRIEVING ATTR 0x%08x...", curIdent);
+        }
+
+        // Try to find a value for this attribute...  we prioritize values
+        // coming from, first XML attributes, then XML style, then default
+        // style, and finally the theme.
+        value.dataType = Res_value::TYPE_NULL;
+        value.data = Res_value::DATA_NULL_UNDEFINED;
+        typeSetFlags = 0;
+        config.density = 0;
+
+        // Walk through the xml attributes looking for the requested attribute.
+        const size_t xmlAttrIdx = xmlAttrFinder.find(curIdent);
+        if (xmlAttrIdx != xmlAttrEnd) {
+            // We found the attribute we were looking for.
+            block = kXmlBlock;
+            xmlParser->getAttributeValue(xmlAttrIdx, &value);
+            if (kDebugStyles) {
+                ALOGI("-> From XML: type=0x%x, data=0x%08x", value.dataType, value.data);
+            }
+        }
+
+        if (value.dataType == Res_value::TYPE_NULL) {
+            // Walk through the style class values looking for the requested attribute.
+            const ResTable::bag_entry* const styleAttrEntry = styleAttrFinder.find(curIdent);
+            if (styleAttrEntry != styleAttrEnd) {
+                // We found the attribute we were looking for.
+                block = styleAttrEntry->stringBlock;
+                typeSetFlags = styleTypeSetFlags;
+                value = styleAttrEntry->map.value;
+                if (kDebugStyles) {
+                    ALOGI("-> From style: type=0x%x, data=0x%08x", value.dataType, value.data);
+                }
+            }
+        }
+
+        if (value.dataType == Res_value::TYPE_NULL) {
+            // Walk through the default style values looking for the requested attribute.
+            const ResTable::bag_entry* const defStyleAttrEntry = defStyleAttrFinder.find(curIdent);
+            if (defStyleAttrEntry != defStyleAttrEnd) {
+                // We found the attribute we were looking for.
+                block = defStyleAttrEntry->stringBlock;
+                typeSetFlags = styleTypeSetFlags;
+                value = defStyleAttrEntry->map.value;
+                if (kDebugStyles) {
+                    ALOGI("-> From def style: type=0x%x, data=0x%08x", value.dataType, value.data);
+                }
+            }
+        }
+
+        uint32_t resid = 0;
+        if (value.dataType != Res_value::TYPE_NULL) {
+            // Take care of resolving the found resource to its final value.
+            ssize_t newBlock = theme->resolveAttributeReference(&value, block,
+                    &resid, &typeSetFlags, &config);
+            if (newBlock >= 0) {
+                block = newBlock;
+            }
+
+            if (kDebugStyles) {
+                ALOGI("-> Resolved attr: type=0x%x, data=0x%08x", value.dataType, value.data);
+            }
+        } else {
+            // If we still don't have a value for this attribute, try to find
+            // it in the theme!
+            ssize_t newBlock = theme->getAttribute(curIdent, &value, &typeSetFlags);
+            if (newBlock >= 0) {
+                if (kDebugStyles) {
+                    ALOGI("-> From theme: type=0x%x, data=0x%08x", value.dataType, value.data);
+                }
+                newBlock = res.resolveReference(&value, block, &resid,
+                        &typeSetFlags, &config);
+
+                if (newBlock >= 0) {
+                    block = newBlock;
+                }
+
+                if (kDebugStyles) {
+                    ALOGI("-> Resolved theme: type=0x%x, data=0x%08x", value.dataType, value.data);
+                }
+            }
+        }
+
+        // Deal with the special @null value -- it turns back to TYPE_NULL.
+        if (value.dataType == Res_value::TYPE_REFERENCE && value.data == 0) {
+            if (kDebugStyles) {
+                ALOGI("-> Setting to @null!");
+            }
+            value.dataType = Res_value::TYPE_NULL;
+            value.data = Res_value::DATA_NULL_UNDEFINED;
+            block = kXmlBlock;
+        }
+
+        if (kDebugStyles) {
+            ALOGI("Attribute 0x%08x: type=0x%x, data=0x%08x", curIdent, value.dataType, value.data);
+        }
+
+        // Write the final value back to Java.
+        outValues[STYLE_TYPE] = value.dataType;
+        outValues[STYLE_DATA] = value.data;
+        outValues[STYLE_ASSET_COOKIE] = block != kXmlBlock ?
+            static_cast<uint32_t>(res.getTableCookie(block)) : static_cast<uint32_t>(-1);
+        outValues[STYLE_RESOURCE_ID] = resid;
+        outValues[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags;
+        outValues[STYLE_DENSITY] = config.density;
+
+        if (outIndices != NULL && value.dataType != Res_value::TYPE_NULL) {
+            indicesIdx++;
+            outIndices[indicesIdx] = ii;
+        }
+
+        outValues += STYLE_NUM_ENTRIES;
+    }
+
+    res.unlock();
+
+    if (outIndices != NULL) {
+        outIndices[0] = indicesIdx;
+    }
+    return true;
+}
+
+bool retrieveAttributes(const ResTable* res, ResXMLParser* xmlParser,
+                        uint32_t* attrs, size_t attrsLength,
+                        uint32_t* outValues,
+                        uint32_t* outIndices) {
+    ResTable_config config;
+    Res_value value;
+
+    int indicesIdx = 0;
+
+    // Now lock down the resource object and start pulling stuff from it.
+    res->lock();
+
+    // Retrieve the XML attributes, if requested.
+    const size_t NX = xmlParser->getAttributeCount();
+    size_t ix=0;
+    uint32_t curXmlAttr = xmlParser->getAttributeNameResID(ix);
+
+    static const ssize_t kXmlBlock = 0x10000000;
+
+    // Now iterate through all of the attributes that the client has requested,
+    // filling in each with whatever data we can find.
+    ssize_t block = 0;
+    uint32_t typeSetFlags;
+    for (size_t ii=0; ii<attrsLength; ii++) {
+        const uint32_t curIdent = attrs[ii];
+
+        // Try to find a value for this attribute...
+        value.dataType = Res_value::TYPE_NULL;
+        value.data = Res_value::DATA_NULL_UNDEFINED;
+        typeSetFlags = 0;
+        config.density = 0;
+
+        // Skip through XML attributes until the end or the next possible match.
+        while (ix < NX && curIdent > curXmlAttr) {
+            ix++;
+            curXmlAttr = xmlParser->getAttributeNameResID(ix);
+        }
+        // Retrieve the current XML attribute if it matches, and step to next.
+        if (ix < NX && curIdent == curXmlAttr) {
+            block = kXmlBlock;
+            xmlParser->getAttributeValue(ix, &value);
+            ix++;
+            curXmlAttr = xmlParser->getAttributeNameResID(ix);
+        }
+
+        //printf("Attribute 0x%08x: type=0x%x, data=0x%08x\n", curIdent, value.dataType, value.data);
+        uint32_t resid = 0;
+        if (value.dataType != Res_value::TYPE_NULL) {
+            // Take care of resolving the found resource to its final value.
+            //printf("Resolving attribute reference\n");
+            ssize_t newBlock = res->resolveReference(&value, block, &resid,
+                    &typeSetFlags, &config);
+            if (newBlock >= 0) block = newBlock;
+        }
+
+        // Deal with the special @null value -- it turns back to TYPE_NULL.
+        if (value.dataType == Res_value::TYPE_REFERENCE && value.data == 0) {
+            value.dataType = Res_value::TYPE_NULL;
+            value.data = Res_value::DATA_NULL_UNDEFINED;
+        }
+
+        //printf("Attribute 0x%08x: final type=0x%x, data=0x%08x\n", curIdent, value.dataType, value.data);
+
+        // Write the final value back to Java.
+        outValues[STYLE_TYPE] = value.dataType;
+        outValues[STYLE_DATA] = value.data;
+        outValues[STYLE_ASSET_COOKIE] = block != kXmlBlock
+                ? static_cast<uint32_t>(res->getTableCookie(block)) : static_cast<uint32_t>(-1);
+        outValues[STYLE_RESOURCE_ID] = resid;
+        outValues[STYLE_CHANGING_CONFIGURATIONS] = typeSetFlags;
+        outValues[STYLE_DENSITY] = config.density;
+
+        if (outIndices != NULL && value.dataType != Res_value::TYPE_NULL) {
+            indicesIdx++;
+            outIndices[indicesIdx] = ii;
+        }
+
+        outValues += STYLE_NUM_ENTRIES;
+    }
+
+    res->unlock();
+
+    if (outIndices != NULL) {
+        outIndices[0] = indicesIdx;
+    }
+    return true;
+}
+
+} // namespace android
diff --git a/libs/hwui/Android.mk b/libs/hwui/Android.mk
index ac7b597..1282846 100644
--- a/libs/hwui/Android.mk
+++ b/libs/hwui/Android.mk
@@ -46,7 +46,6 @@
     AnimationContext.cpp \
     Animator.cpp \
     AnimatorManager.cpp \
-    AssetAtlas.cpp \
     BakedOpDispatcher.cpp \
     BakedOpRenderer.cpp \
     BakedOpState.cpp \
@@ -57,7 +56,6 @@
     DeferredLayerUpdater.cpp \
     DeviceInfo.cpp \
     DisplayList.cpp \
-    Dither.cpp \
     Extensions.cpp \
     FboCache.cpp \
     FontRenderer.cpp \
@@ -96,6 +94,7 @@
     ShadowTessellator.cpp \
     SkiaCanvas.cpp \
     SkiaCanvasProxy.cpp \
+    SkiaDisplayList.cpp \
     SkiaShader.cpp \
     Snapshot.cpp \
     SpotShadow.cpp \
@@ -131,6 +130,14 @@
     hwui_cflags += -DUSE_HWC2
 endif
 
+# TODO: Linear blending should be enabled by default, but we are
+# TODO: making it an opt-in while it's a work in progress
+# TODO: The final test should be:
+# TODO: ifneq ($(TARGET_ENABLE_LINEAR_BLENDING),false)
+ifeq ($(TARGET_ENABLE_LINEAR_BLENDING),true)
+    hwui_cflags += -DANDROID_ENABLE_LINEAR_BLENDING
+endif
+
 # GCC false-positives on this warning, and since we -Werror that's
 # a problem
 hwui_cflags += -Wno-free-nonheap-object
@@ -144,7 +151,6 @@
     hwui_cflags += -DBUGREPORT_FONT_CACHE_USAGE
 endif
 
-
 ifndef HWUI_COMPILE_SYMBOLS
     hwui_cflags += -fvisibility=hidden
 endif
@@ -281,6 +287,7 @@
     tests/unit/RenderNodeTests.cpp \
     tests/unit/RenderPropertiesTests.cpp \
     tests/unit/SkiaBehaviorTests.cpp \
+    tests/unit/SkiaDisplayListTests.cpp \
     tests/unit/SkiaCanvasTests.cpp \
     tests/unit/SnapshotTests.cpp \
     tests/unit/StringUtilsTests.cpp \
diff --git a/libs/hwui/AssetAtlas.cpp b/libs/hwui/AssetAtlas.cpp
deleted file mode 100644
index e2e70372..0000000
--- a/libs/hwui/AssetAtlas.cpp
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "AssetAtlas.h"
-#include "Caches.h"
-#include "Image.h"
-
-#include <GLES2/gl2ext.h>
-
-namespace android {
-namespace uirenderer {
-
-///////////////////////////////////////////////////////////////////////////////
-// Lifecycle
-///////////////////////////////////////////////////////////////////////////////
-
-void AssetAtlas::init(const sp<GraphicBuffer>& buffer, int64_t* map, int count) {
-    if (mImage) {
-        return;
-    }
-
-    ATRACE_NAME("AssetAtlas::init");
-
-    mImage = new Image(buffer);
-    if (mImage->getTexture()) {
-        if (!mTexture) {
-            Caches& caches = Caches::getInstance();
-            mTexture = new Texture(caches);
-            mTexture->wrap(mImage->getTexture(),
-                    buffer->getWidth(), buffer->getHeight(), GL_RGBA);
-            createEntries(caches, map, count);
-        }
-    } else {
-        ALOGW("Could not create atlas image");
-        terminate();
-    }
-}
-
-void AssetAtlas::terminate() {
-    delete mImage;
-    mImage = nullptr;
-    delete mTexture;
-    mTexture = nullptr;
-    mEntries.clear();
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Entries
-///////////////////////////////////////////////////////////////////////////////
-
-AssetAtlas::Entry* AssetAtlas::getEntry(const SkPixelRef* pixelRef) const {
-    auto result = mEntries.find(pixelRef);
-    return result != mEntries.end() ? result->second.get() : nullptr;
-}
-
-Texture* AssetAtlas::getEntryTexture(const SkPixelRef* pixelRef) const {
-    auto result = mEntries.find(pixelRef);
-    return result != mEntries.end() ? result->second->texture : nullptr;
-}
-
-/**
- * Delegates changes to wrapping and filtering to the base atlas texture
- * instead of applying the changes to the virtual textures.
- */
-struct DelegateTexture: public Texture {
-    DelegateTexture(Caches& caches, Texture* delegate)
-            : Texture(caches), mDelegate(delegate) { }
-
-    virtual void setWrapST(GLenum wrapS, GLenum wrapT, bool bindTexture = false,
-            bool force = false, GLenum renderTarget = GL_TEXTURE_2D) override {
-        mDelegate->setWrapST(wrapS, wrapT, bindTexture, force, renderTarget);
-    }
-
-    virtual void setFilterMinMag(GLenum min, GLenum mag, bool bindTexture = false,
-            bool force = false, GLenum renderTarget = GL_TEXTURE_2D) override {
-        mDelegate->setFilterMinMag(min, mag, bindTexture, force, renderTarget);
-    }
-
-private:
-    Texture* const mDelegate;
-}; // struct DelegateTexture
-
-void AssetAtlas::createEntries(Caches& caches, int64_t* map, int count) {
-    const float width = float(mTexture->width());
-    const float height = float(mTexture->height());
-
-    for (int i = 0; i < count; ) {
-        SkPixelRef* pixelRef = reinterpret_cast<SkPixelRef*>(map[i++]);
-        // NOTE: We're converting from 64 bit signed values to 32 bit
-        // signed values. This is guaranteed to be safe because the "x"
-        // and "y" coordinate values are guaranteed to be representable
-        // with 32 bits. The array is 64 bits wide so that it can carry
-        // pointers on 64 bit architectures.
-        const int x = static_cast<int>(map[i++]);
-        const int y = static_cast<int>(map[i++]);
-
-        // Bitmaps should never be null, we're just extra paranoid
-        if (!pixelRef) continue;
-
-        const UvMapper mapper(
-                x / width, (x + pixelRef->info().width()) / width,
-                y / height, (y + pixelRef->info().height()) / height);
-
-        Texture* texture = new DelegateTexture(caches, mTexture);
-        texture->blend = !SkAlphaTypeIsOpaque(pixelRef->info().alphaType());
-        texture->wrap(mTexture->id(), pixelRef->info().width(),
-                pixelRef->info().height(), mTexture->format());
-
-        std::unique_ptr<Entry> entry(new Entry(pixelRef, texture, mapper, *this));
-        texture->uvMapper = &entry->uvMapper;
-
-        mEntries.emplace(entry->pixelRef, std::move(entry));
-    }
-}
-
-}; // namespace uirenderer
-}; // namespace android
diff --git a/libs/hwui/AssetAtlas.h b/libs/hwui/AssetAtlas.h
deleted file mode 100644
index b32e518..0000000
--- a/libs/hwui/AssetAtlas.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_HWUI_ASSET_ATLAS_H
-#define ANDROID_HWUI_ASSET_ATLAS_H
-
-#include "Texture.h"
-#include "UvMapper.h"
-
-#include <cutils/compiler.h>
-#include <GLES2/gl2.h>
-#include <ui/GraphicBuffer.h>
-#include <SkBitmap.h>
-
-#include <memory>
-#include <unordered_map>
-
-namespace android {
-namespace uirenderer {
-
-class Caches;
-class Image;
-
-/**
- * An asset atlas holds a collection of framework bitmaps in a single OpenGL
- * texture. Each bitmap is associated with a location, defined in pixels,
- * inside the atlas. The atlas is generated by the framework and bound as
- * an external texture using the EGLImageKHR extension.
- */
-class AssetAtlas {
-public:
-    /**
-     * Entry representing the texture and uvMapper of a PixelRef in the
-     * atlas
-     */
-    class Entry {
-    public:
-        /*
-         * A "virtual texture" object that represents the texture
-         * this entry belongs to. This texture should never be
-         * modified.
-         */
-        Texture* texture;
-
-        /**
-         * Maps texture coordinates in the [0..1] range into the
-         * correct range to sample this entry from the atlas.
-         */
-        const UvMapper uvMapper;
-
-        /**
-         * Unique identifier used to merge bitmaps and 9-patches stored
-         * in the atlas.
-         */
-        const void* getMergeId() const {
-            return texture->blend ? &atlas.mBlendKey : &atlas.mOpaqueKey;
-        }
-
-        ~Entry() {
-            delete texture;
-        }
-
-    private:
-        /**
-         * The pixel ref that generated this atlas entry.
-         */
-        SkPixelRef* pixelRef;
-
-        /**
-         * Atlas this entry belongs to.
-         */
-        const AssetAtlas& atlas;
-
-        Entry(SkPixelRef* pixelRef, Texture* texture, const UvMapper& mapper,
-                    const AssetAtlas& atlas)
-                : texture(texture)
-                , uvMapper(mapper)
-                , pixelRef(pixelRef)
-                , atlas(atlas) {
-        }
-
-        friend class AssetAtlas;
-    };
-
-    AssetAtlas(): mTexture(nullptr), mImage(nullptr),
-            mBlendKey(true), mOpaqueKey(false) { }
-    ~AssetAtlas() { terminate(); }
-
-    /**
-     * Initializes the atlas with the specified buffer and
-     * map. The buffer is a gralloc'd texture that will be
-     * used as an EGLImage. The map is a list of SkBitmap*
-     * and their (x, y) positions
-     *
-     * This method returns immediately if the atlas is already
-     * initialized. To re-initialize the atlas, you must
-     * first call terminate().
-     */
-    ANDROID_API void init(const sp<GraphicBuffer>& buffer, int64_t* map, int count);
-
-    /**
-     * Destroys the atlas texture. This object can be
-     * re-initialized after calling this method.
-     *
-     * After calling this method, the width, height
-     * and texture are set to 0.
-     */
-    void terminate();
-
-    /**
-     * Returns the width of this atlas in pixels.
-     * Can return 0 if the atlas is not initialized.
-     */
-    uint32_t getWidth() const {
-        return mTexture ? mTexture->width() : 0;
-    }
-
-    /**
-     * Returns the height of this atlas in pixels.
-     * Can return 0 if the atlas is not initialized.
-     */
-    uint32_t getHeight() const {
-        return mTexture ? mTexture->height() : 0;
-    }
-
-    /**
-     * Returns the OpenGL name of the texture backing this atlas.
-     * Can return 0 if the atlas is not initialized.
-     */
-    GLuint getTexture() const {
-        return mTexture ? mTexture->id() : 0;
-    }
-
-    /**
-     * Returns the entry in the atlas associated with the specified
-     * pixelRef. If the pixelRef is not in the atlas, return NULL.
-     */
-    Entry* getEntry(const SkPixelRef* pixelRef) const;
-
-    /**
-     * Returns the texture for the atlas entry associated with the
-     * specified pixelRef. If the pixelRef is not in the atlas, return NULL.
-     */
-    Texture* getEntryTexture(const SkPixelRef* pixelRef) const;
-
-private:
-    void createEntries(Caches& caches, int64_t* map, int count);
-
-    Texture* mTexture;
-    Image* mImage;
-
-    const bool mBlendKey;
-    const bool mOpaqueKey;
-
-    std::unordered_map<const SkPixelRef*, std::unique_ptr<Entry>> mEntries;
-}; // class AssetAtlas
-
-}; // namespace uirenderer
-}; // namespace android
-
-#endif // ANDROID_HWUI_ASSET_ATLAS_H
diff --git a/libs/hwui/BakedOpDispatcher.cpp b/libs/hwui/BakedOpDispatcher.cpp
index 8b3f172..6995039 100644
--- a/libs/hwui/BakedOpDispatcher.cpp
+++ b/libs/hwui/BakedOpDispatcher.cpp
@@ -35,11 +35,11 @@
 namespace android {
 namespace uirenderer {
 
-static void storeTexturedRect(TextureVertex* vertices, const Rect& bounds, const Rect& texCoord) {
-    vertices[0] = { bounds.left, bounds.top, texCoord.left, texCoord.top };
-    vertices[1] = { bounds.right, bounds.top, texCoord.right, texCoord.top };
-    vertices[2] = { bounds.left, bounds.bottom, texCoord.left, texCoord.bottom };
-    vertices[3] = { bounds.right, bounds.bottom, texCoord.right, texCoord.bottom };
+static void storeTexturedRect(TextureVertex* vertices, const Rect& bounds) {
+    vertices[0] = { bounds.left,  bounds.top,    0, 0 };
+    vertices[1] = { bounds.right, bounds.top,    1, 0 };
+    vertices[2] = { bounds.left,  bounds.bottom, 0, 1 };
+    vertices[3] = { bounds.right, bounds.bottom, 1, 1 };
 }
 
 void BakedOpDispatcher::onMergedBitmapOps(BakedOpRenderer& renderer,
@@ -48,16 +48,11 @@
     const BakedOpState& firstState = *(opList.states[0]);
     const SkBitmap* bitmap = (static_cast<const BitmapOp*>(opList.states[0]->op))->bitmap;
 
-    AssetAtlas::Entry* entry = renderer.renderState().assetAtlas().getEntry(bitmap->pixelRef());
-    Texture* texture = entry ? entry->texture : renderer.caches().textureCache.get(bitmap);
+    Texture* texture = renderer.caches().textureCache.get(bitmap);
     if (!texture) return;
     const AutoTexture autoCleanup(texture);
 
     TextureVertex vertices[opList.count * 4];
-    Rect texCoords(0, 0, 1, 1);
-    if (entry) {
-        entry->uvMapper.map(texCoords);
-    }
     for (size_t i = 0; i < opList.count; i++) {
         const BakedOpState& state = *(opList.states[i]);
         TextureVertex* rectVerts = &vertices[i * 4];
@@ -69,7 +64,7 @@
             // pure translate, so snap (same behavior as onBitmapOp)
             opBounds.snapToPixelBoundaries();
         }
-        storeTexturedRect(rectVerts, opBounds, texCoords);
+        storeTexturedRect(rectVerts, opBounds);
         renderer.dirtyRenderTarget(opBounds);
     }
 
@@ -92,8 +87,6 @@
         const MergedBakedOpList& opList) {
     const PatchOp& firstOp = *(static_cast<const PatchOp*>(opList.states[0]->op));
     const BakedOpState& firstState = *(opList.states[0]);
-    AssetAtlas::Entry* entry = renderer.renderState().assetAtlas().getEntry(
-            firstOp.bitmap->pixelRef());
 
     // Batches will usually contain a small number of items so it's
     // worth performing a first iteration to count the exact number
@@ -105,7 +98,7 @@
 
         // TODO: cache mesh lookups
         const Patch* opMesh = renderer.caches().patchCache.get(
-                entry, op.bitmap->width(), op.bitmap->height(),
+                op.bitmap->width(), op.bitmap->height(),
                 op.unmappedBounds.getWidth(), op.unmappedBounds.getHeight(), op.patch);
         totalVertices += opMesh->verticesCount;
     }
@@ -126,7 +119,7 @@
 
         // TODO: cache mesh lookups
         const Patch* opMesh = renderer.caches().patchCache.get(
-                entry, op.bitmap->width(), op.bitmap->height(),
+                op.bitmap->width(), op.bitmap->height(),
                 op.unmappedBounds.getWidth(), op.unmappedBounds.getHeight(), op.patch);
 
 
@@ -172,7 +165,7 @@
     }
 
 
-    Texture* texture = entry ? entry->texture : renderer.caches().textureCache.get(firstOp.bitmap);
+    Texture* texture = renderer.caches().textureCache.get(firstOp.bitmap);
     if (!texture) return;
     const AutoTexture autoCleanup(texture);
 
@@ -442,7 +435,12 @@
 }
 
 void BakedOpDispatcher::onBitmapMeshOp(BakedOpRenderer& renderer, const BitmapMeshOp& op, const BakedOpState& state) {
-    const static UvMapper defaultUvMapper;
+    Texture* texture = renderer.caches().textureCache.get(op.bitmap);
+    if (!texture) {
+        return;
+    }
+    const AutoTexture autoCleanup(texture);
+
     const uint32_t elementCount = op.meshWidth * op.meshHeight * 6;
 
     std::unique_ptr<ColorTextureVertex[]> mesh(new ColorTextureVertex[elementCount]);
@@ -457,9 +455,6 @@
         colors = tempColors.get();
     }
 
-    Texture* texture = renderer.renderState().assetAtlas().getEntryTexture(op.bitmap->pixelRef());
-    const UvMapper& mapper(texture && texture->uvMapper ? *texture->uvMapper : defaultUvMapper);
-
     for (int32_t y = 0; y < op.meshHeight; y++) {
         for (int32_t x = 0; x < op.meshWidth; x++) {
             uint32_t i = (y * (op.meshWidth + 1) + x) * 2;
@@ -469,8 +464,6 @@
             float v1 = float(y) / op.meshHeight;
             float v2 = float(y + 1) / op.meshHeight;
 
-            mapper.map(u1, v1, u2, v2);
-
             int ax = i + (op.meshWidth + 1) * 2;
             int ay = ax + 1;
             int bx = i;
@@ -491,14 +484,6 @@
         }
     }
 
-    if (!texture) {
-        texture = renderer.caches().textureCache.get(op.bitmap);
-        if (!texture) {
-            return;
-        }
-    }
-    const AutoTexture autoCleanup(texture);
-
     /*
      * TODO: handle alpha_8 textures correctly by applying paint color, but *not*
      * shader in that case to mimic the behavior in SkiaCanvas::drawBitmapMesh.
@@ -599,12 +584,11 @@
     }
 
     // TODO: avoid redoing the below work each frame:
-    AssetAtlas::Entry* entry = renderer.renderState().assetAtlas().getEntry(op.bitmap->pixelRef());
     const Patch* mesh = renderer.caches().patchCache.get(
-            entry, op.bitmap->width(), op.bitmap->height(),
+            op.bitmap->width(), op.bitmap->height(),
             op.unmappedBounds.getWidth(), op.unmappedBounds.getHeight(), op.patch);
 
-    Texture* texture = entry ? entry->texture : renderer.caches().textureCache.get(op.bitmap);
+    Texture* texture = renderer.caches().textureCache.get(op.bitmap);
     if (CC_LIKELY(texture)) {
         const AutoTexture autoCleanup(texture);
         Glop glop;
diff --git a/libs/hwui/BakedOpRenderer.cpp b/libs/hwui/BakedOpRenderer.cpp
index 6db345a..ac7a600 100644
--- a/libs/hwui/BakedOpRenderer.cpp
+++ b/libs/hwui/BakedOpRenderer.cpp
@@ -182,11 +182,7 @@
 }
 
 Texture* BakedOpRenderer::getTexture(const SkBitmap* bitmap) {
-    Texture* texture = mRenderState.assetAtlas().getEntryTexture(bitmap->pixelRef());
-    if (!texture) {
-        return mCaches.textureCache.get(bitmap);
-    }
-    return texture;
+    return mCaches.textureCache.get(bitmap);
 }
 
 void BakedOpRenderer::drawRects(const float* rects, int count, const SkPaint* paint) {
diff --git a/libs/hwui/Caches.cpp b/libs/hwui/Caches.cpp
index 741cdcc..b463e45 100644
--- a/libs/hwui/Caches.cpp
+++ b/libs/hwui/Caches.cpp
@@ -53,7 +53,6 @@
         : gradientCache(mExtensions)
         , patchCache(renderState)
         , programCache(mExtensions)
-        , dither(*this)
         , mRenderState(&renderState)
         , mInitialized(false) {
     INIT_LOGD("Creating OpenGL renderer caches");
@@ -238,7 +237,6 @@
             gradientCache.clear();
             fontRenderer.clear();
             fboCache.clear();
-            dither.clear();
             // fall through
         case FlushMode::Moderate:
             fontRenderer.flush();
diff --git a/libs/hwui/Caches.h b/libs/hwui/Caches.h
index 344ee71..7c2e78c 100644
--- a/libs/hwui/Caches.h
+++ b/libs/hwui/Caches.h
@@ -16,8 +16,6 @@
 
 #pragma once
 
-#include "AssetAtlas.h"
-#include "Dither.h"
 #include "Extensions.h"
 #include "FboCache.h"
 #include "GammaFontRenderer.h"
@@ -130,6 +128,15 @@
     TextureVertex* getRegionMesh();
 
     /**
+     * Returns the GL RGBA internal format to use for the current device
+     * If the device supports linear blending and needSRGB is true,
+     * this function returns GL_SRGB8_ALPHA8, otherwise it returns GL_RGBA
+     */
+    constexpr GLint rgbaInternalFormat(bool needSRGB = true) const {
+        return extensions().hasSRGB() && needSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA;
+    }
+
+    /**
      * Displays the memory usage of each cache and the total sum.
      */
     void dumpMemoryUsage();
@@ -157,8 +164,6 @@
 
     TaskManager tasks;
 
-    Dither dither;
-
     bool gpuPixelBuffersEnabled;
 
     // Debug methods
@@ -169,7 +174,7 @@
     void setProgram(const ProgramDescription& description);
     void setProgram(Program* program);
 
-    Extensions& extensions() { return mExtensions; }
+    const Extensions& extensions() const { return mExtensions; }
     Program& program() { return *mProgram; }
     PixelBufferState& pixelBufferState() { return *mPixelBufferState; }
     TextureState& textureState() { return *mTextureState; }
diff --git a/libs/hwui/DisplayList.cpp b/libs/hwui/DisplayList.cpp
index ca9e2bd..6e7d11f 100644
--- a/libs/hwui/DisplayList.cpp
+++ b/libs/hwui/DisplayList.cpp
@@ -19,10 +19,12 @@
 
 #include <utils/Trace.h>
 
+#include "DamageAccumulator.h"
 #include "Debug.h"
 #include "DisplayList.h"
 #include "RecordedOp.h"
 #include "RenderNode.h"
+#include "VectorDrawable.h"
 
 namespace android {
 namespace uirenderer {
@@ -86,5 +88,46 @@
     return index;
 }
 
+void DisplayList::syncContents() {
+    for (auto& iter : functors) {
+        (*iter.functor)(DrawGlInfo::kModeSync, nullptr);
+    }
+    for (auto& vectorDrawable : vectorDrawables) {
+        vectorDrawable->syncProperties();
+    }
+}
+
+void DisplayList::updateChildren(std::function<void(RenderNode*)> updateFn) {
+    for (auto&& child : children) {
+        updateFn(child->renderNode);
+    }
+}
+
+bool DisplayList::prepareListAndChildren(TreeInfo& info, bool functorsNeedLayer,
+        std::function<void(RenderNode*, TreeInfo&, bool)> childFn) {
+    TextureCache& cache = Caches::getInstance().textureCache;
+    for (auto&& bitmapResource : bitmapResources) {
+        void* ownerToken = &info.canvasContext;
+        info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource);
+    }
+    for (auto&& op : children) {
+        RenderNode* childNode = op->renderNode;
+        info.damageAccumulator->pushTransform(&op->localMatrix);
+        bool childFunctorsNeedLayer = functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip;
+        childFn(childNode, info, childFunctorsNeedLayer);
+        info.damageAccumulator->popTransform();
+    }
+
+    bool isDirty = false;
+    for (auto& vectorDrawable : vectorDrawables) {
+        // If any vector drawable in the display list needs update, damage the node.
+        if (vectorDrawable->isDirty()) {
+            isDirty = true;
+        }
+        vectorDrawable->setPropertyChangeWillBeConsumed(true);
+    }
+    return isDirty;
+}
+
 }; // namespace uirenderer
 }; // namespace android
diff --git a/libs/hwui/DisplayList.h b/libs/hwui/DisplayList.h
index c5d8767..06b0891 100644
--- a/libs/hwui/DisplayList.h
+++ b/libs/hwui/DisplayList.h
@@ -17,6 +17,7 @@
 #pragma once
 
 #include <SkCamera.h>
+#include <SkDrawable.h>
 #include <SkMatrix.h>
 
 #include <private/hwui/DrawGlInfo.h>
@@ -36,6 +37,7 @@
 #include "GlFunctorLifecycleListener.h"
 #include "Matrix.h"
 #include "RenderProperties.h"
+#include "TreeInfo.h"
 
 #include <vector>
 
@@ -89,7 +91,7 @@
     };
 
     DisplayList();
-    ~DisplayList();
+    virtual ~DisplayList();
 
     // index of DisplayListOp restore, after which projected descendants should be drawn
     int projectionReceiveIndex;
@@ -100,8 +102,6 @@
     const LsaVector<NodeOpType*>& getChildren() const { return children; }
 
     const LsaVector<const SkBitmap*>& getBitmapResources() const { return bitmapResources; }
-    const LsaVector<FunctorContainer>& getFunctors() const { return functors; }
-    const LsaVector<VectorDrawableRoot*>& getVectorDrawables() const { return vectorDrawables; }
 
     size_t addChild(NodeOpType* childOp);
 
@@ -113,15 +113,26 @@
     size_t getUsedSize() {
         return allocator.usedSize();
     }
-    bool isEmpty() {
-        return ops.empty();
+
+    virtual bool isEmpty() const { return ops.empty(); }
+    virtual bool hasFunctor() const { return !functors.empty(); }
+    virtual bool hasVectorDrawables() const { return !vectorDrawables.empty(); }
+    virtual bool isSkiaDL() const { return false; }
+    virtual bool reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) {
+        return false;
     }
 
-private:
+    virtual void syncContents();
+    virtual void updateChildren(std::function<void(RenderNode*)> updateFn);
+    virtual bool prepareListAndChildren(TreeInfo& info, bool functorsNeedLayer,
+            std::function<void(RenderNode*, TreeInfo&, bool)> childFn);
+
+protected:
     // allocator into which all ops and LsaVector arrays allocated
     LinearAllocator allocator;
     LinearStdAllocator<void*> stdAllocator;
 
+private:
     LsaVector<Chunk> chunks;
     LsaVector<BaseOpType*> ops;
 
diff --git a/libs/hwui/Dither.cpp b/libs/hwui/Dither.cpp
deleted file mode 100644
index ec2013e..0000000
--- a/libs/hwui/Dither.cpp
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "Caches.h"
-#include "Dither.h"
-
-namespace android {
-namespace uirenderer {
-
-///////////////////////////////////////////////////////////////////////////////
-// Lifecycle
-///////////////////////////////////////////////////////////////////////////////
-
-Dither::Dither(Caches& caches)
-        : mCaches(caches)
-        , mInitialized(false)
-        , mDitherTexture(0) {
-}
-
-void Dither::bindDitherTexture() {
-    if (!mInitialized) {
-        glGenTextures(1, &mDitherTexture);
-        mCaches.textureState().bindTexture(mDitherTexture);
-
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-
-        if (mCaches.extensions().hasFloatTextures()) {
-            // We use a R16F texture, let's remap the alpha channel to the
-            // red channel to avoid changing the shader sampling code on GL ES 3.0+
-            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_A, GL_RED);
-
-            float dither = 1.0f / (255.0f * DITHER_KERNEL_SIZE * DITHER_KERNEL_SIZE);
-            const GLfloat pattern[] = {
-                 0 * dither,  8 * dither,  2 * dither, 10 * dither,
-                12 * dither,  4 * dither, 14 * dither,  6 * dither,
-                 3 * dither, 11 * dither,  1 * dither,  9 * dither,
-                15 * dither,  7 * dither, 13 * dither,  5 * dither
-            };
-
-            glTexImage2D(GL_TEXTURE_2D, 0, GL_R16F, DITHER_KERNEL_SIZE, DITHER_KERNEL_SIZE, 0,
-                    GL_RED, GL_FLOAT, &pattern);
-        } else {
-            const uint8_t pattern[] = {
-                 0,  8,  2, 10,
-                12,  4, 14,  6,
-                 3, 11,  1,  9,
-                15,  7, 13,  5
-            };
-
-            glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, DITHER_KERNEL_SIZE, DITHER_KERNEL_SIZE, 0,
-                    GL_ALPHA, GL_UNSIGNED_BYTE, &pattern);
-        }
-
-        mInitialized = true;
-    } else {
-        mCaches.textureState().bindTexture(mDitherTexture);
-    }
-}
-
-void Dither::clear() {
-    if (mInitialized) {
-        mCaches.textureState().deleteTexture(mDitherTexture);
-        mInitialized = false;
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////
-// Program management
-///////////////////////////////////////////////////////////////////////////////
-
-void Dither::setupProgram(Program& program, GLuint* textureUnit) {
-    GLuint textureSlot = (*textureUnit)++;
-    mCaches.textureState().activateTexture(textureSlot);
-
-    bindDitherTexture();
-
-    glUniform1i(program.getUniform("ditherSampler"), textureSlot);
-}
-
-}; // namespace uirenderer
-}; // namespace android
diff --git a/libs/hwui/Dither.h b/libs/hwui/Dither.h
deleted file mode 100644
index 6af3e83..0000000
--- a/libs/hwui/Dither.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_HWUI_DITHER_H
-#define ANDROID_HWUI_DITHER_H
-
-#include <GLES3/gl3.h>
-
-namespace android {
-namespace uirenderer {
-
-class Caches;
-class Extensions;
-class Program;
-
-// Must be a power of two
-#define DITHER_KERNEL_SIZE 4
-// These must not use the .0f notation as they are used from GLSL
-#define DITHER_KERNEL_SIZE_INV (1.0 / 4.0)
-#define DITHER_KERNEL_SIZE_INV_SQUARE (1.0 / 16.0)
-
-/**
- * Handles dithering for programs.
- */
-class Dither {
-public:
-    explicit Dither(Caches& caches);
-
-    void clear();
-    void setupProgram(Program& program, GLuint* textureUnit);
-
-private:
-    void bindDitherTexture();
-
-    Caches& mCaches;
-    bool mInitialized;
-    GLuint mDitherTexture;
-};
-
-}; // namespace uirenderer
-}; // namespace android
-
-#endif // ANDROID_HWUI_DITHER_H
diff --git a/libs/hwui/Extensions.cpp b/libs/hwui/Extensions.cpp
index 02caaa4..1d67579 100644
--- a/libs/hwui/Extensions.cpp
+++ b/libs/hwui/Extensions.cpp
@@ -22,6 +22,7 @@
 
 #include <GLES2/gl2.h>
 #include <GLES2/gl2ext.h>
+
 #include <utils/Log.h>
 
 namespace android {
@@ -45,6 +46,19 @@
     mHas4BitStencil = extensions.has("GL_OES_stencil4");
     mHasUnpackSubImage = extensions.has("GL_EXT_unpack_subimage");
 
+#ifdef ANDROID_ENABLE_LINEAR_BLENDING
+    mHasSRGB = mVersionMajor >= 3 || extensions.has("GL_EXT_sRGB");
+    mHasSRGBWriteControl = extensions.has("GL_EXT_sRGB_write_control");
+
+    // If linear blending is enabled, the device must have (ES3.0 or EXT_sRGB)
+    // and EXT_sRGB_write_control
+    LOG_ALWAYS_FATAL_IF(!mHasSRGB, "Linear blending requires ES 3.0 or EXT_sRGB");
+    LOG_ALWAYS_FATAL_IF(!mHasSRGBWriteControl, "Linear blending requires EXT_sRGB_write_control");
+#else
+    mHasSRGB = false;
+    mHasSRGBWriteControl = false;
+#endif
+
     const char* version = (const char*) glGetString(GL_VERSION);
 
     // Section 6.1.5 of the OpenGL ES specification indicates the GL version
diff --git a/libs/hwui/Extensions.h b/libs/hwui/Extensions.h
index 67cc747..2c38507 100644
--- a/libs/hwui/Extensions.h
+++ b/libs/hwui/Extensions.h
@@ -43,6 +43,8 @@
     inline bool hasPixelBufferObjects() const { return mVersionMajor >= 3; }
     inline bool hasOcclusionQueries() const { return mVersionMajor >= 3; }
     inline bool hasFloatTextures() const { return mVersionMajor >= 3; }
+    inline bool hasSRGB() const { return mHasSRGB; }
+    inline bool hasSRGBWriteControl() const { return hasSRGB() && mHasSRGBWriteControl; }
 
     inline int getMajorGlVersion() const { return mVersionMajor; }
     inline int getMinorGlVersion() const { return mVersionMinor; }
@@ -55,6 +57,8 @@
     bool mHas1BitStencil;
     bool mHas4BitStencil;
     bool mHasUnpackSubImage;
+    bool mHasSRGB;
+    bool mHasSRGBWriteControl;
 
     int mVersionMajor;
     int mVersionMinor;
diff --git a/libs/hwui/FloatColor.h b/libs/hwui/FloatColor.h
index 9a39ec2..9df7338 100644
--- a/libs/hwui/FloatColor.h
+++ b/libs/hwui/FloatColor.h
@@ -16,6 +16,7 @@
 #ifndef FLOATCOLOR_H
 #define FLOATCOLOR_H
 
+#include "utils/Color.h"
 #include "utils/Macros.h"
 #include "utils/MathUtils.h"
 
@@ -25,11 +26,25 @@
 namespace uirenderer {
 
 struct FloatColor {
+    // "color" is a gamma-encoded sRGB color
+    // After calling this method, the color is stored as a pre-multiplied linear color
+    // if linear blending is enabled. Otherwise, the color is stored as a pre-multiplied
+    // gamma-encoded sRGB color
     void set(uint32_t color) {
         a = ((color >> 24) & 0xff) / 255.0f;
-        r = a * ((color >> 16) & 0xff) / 255.0f;
-        g = a * ((color >>  8) & 0xff) / 255.0f;
-        b = a * ((color      ) & 0xff) / 255.0f;
+        r = a * EOCF(((color >> 16) & 0xff) / 255.0f);
+        g = a * EOCF(((color >>  8) & 0xff) / 255.0f);
+        b = a * EOCF(((color      ) & 0xff) / 255.0f);
+    }
+
+    // "color" is a gamma-encoded sRGB color
+    // After calling this method, the color is stored as a pre-multiplied linear color
+    // if linear blending is enabled.
+    void setSRGB(uint32_t color) {
+        a = ((color >> 24) & 0xff) / 255.0f;
+        r = a * EOCF_sRGB(((color >> 16) & 0xff) / 255.0f);
+        g = a * EOCF_sRGB(((color >>  8) & 0xff) / 255.0f);
+        b = a * EOCF_sRGB(((color      ) & 0xff) / 255.0f);
     }
 
     bool isNotBlack() {
diff --git a/libs/hwui/FontRenderer.cpp b/libs/hwui/FontRenderer.cpp
index 9b60dfc..effc65e 100644
--- a/libs/hwui/FontRenderer.cpp
+++ b/libs/hwui/FontRenderer.cpp
@@ -60,11 +60,17 @@
     }
     int transformFlags = pureTranslate
             ? TransformFlags::MeshIgnoresCanvasTransform : TransformFlags::None;
+#ifdef ANDROID_ENABLE_LINEAR_BLENDING
+    bool gammaCorrection = true;
+#else
+    bool gammaCorrection = false;
+#endif
     Glop glop;
     GlopBuilder(renderer->renderState(), renderer->caches(), &glop)
             .setRoundRectClipState(bakedState->roundRectClipState)
             .setMeshTexturedIndexedQuads(texture.mesh(), texture.meshElementCount())
             .setFillTexturePaint(texture.getTexture(), textureFillFlags, paint, bakedState->alpha)
+            .setGammaCorrection(gammaCorrection)
             .setTransform(bakedState->computedState.transform, transformFlags)
             .setModelViewIdentityEmptyBounds()
             .build();
@@ -287,24 +293,23 @@
     // Copy the glyph image, taking the mask format into account
     switch (format) {
         case SkMask::kA8_Format: {
-            uint32_t cacheX = 0, bX = 0, cacheY = 0, bY = 0;
             uint32_t row = (startY - TEXTURE_BORDER_SIZE) * cacheWidth + startX
                     - TEXTURE_BORDER_SIZE;
             // write leading border line
             memset(&cacheBuffer[row], 0, glyph.fWidth + 2 * TEXTURE_BORDER_SIZE);
             // write glyph data
             if (mGammaTable) {
-                for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += srcStride) {
+                for (uint32_t cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += srcStride) {
                     row = cacheY * cacheWidth;
                     cacheBuffer[row + startX - TEXTURE_BORDER_SIZE] = 0;
-                    for (cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) {
+                    for (uint32_t cacheX = startX, bX = 0; cacheX < endX; cacheX++, bX++) {
                         uint8_t tempCol = bitmapBuffer[bY + bX];
                         cacheBuffer[row + cacheX] = mGammaTable[tempCol];
                     }
                     cacheBuffer[row + endX + TEXTURE_BORDER_SIZE - 1] = 0;
                 }
             } else {
-                for (cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += srcStride) {
+                for (uint32_t cacheY = startY, bY = 0; cacheY < endY; cacheY++, bY += srcStride) {
                     row = cacheY * cacheWidth;
                     memcpy(&cacheBuffer[row + startX], &bitmapBuffer[bY], glyph.fWidth);
                     cacheBuffer[row + startX - TEXTURE_BORDER_SIZE] = 0;
diff --git a/libs/hwui/FrameBuilder.cpp b/libs/hwui/FrameBuilder.cpp
index be4fdac..17ad0e3 100644
--- a/libs/hwui/FrameBuilder.cpp
+++ b/libs/hwui/FrameBuilder.cpp
@@ -612,7 +612,6 @@
             && op.bitmap->colorType() != kAlpha_8_SkColorType
             && hasMergeableClip(*bakedState)) {
         mergeid_t mergeId = reinterpret_cast<mergeid_t>(op.bitmap->getGenerationID());
-        // TODO: AssetAtlas in mergeId
         currentLayer().deferMergeableOp(mAllocator, bakedState, OpBatchType::Bitmap, mergeId);
     } else {
         currentLayer().deferUnmergeableOp(mAllocator, bakedState, OpBatchType::Bitmap);
@@ -687,7 +686,6 @@
             && PaintUtils::getXfermodeDirect(op.paint) == SkXfermode::kSrcOver_Mode
             && hasMergeableClip(*bakedState)) {
         mergeid_t mergeId = reinterpret_cast<mergeid_t>(op.bitmap->getGenerationID());
-        // TODO: AssetAtlas in mergeId
 
         // Only use the MergedPatch batchId when merged, so Bitmap+Patch don't try to merge together
         currentLayer().deferMergeableOp(mAllocator, bakedState, OpBatchType::MergedPatch, mergeId);
diff --git a/libs/hwui/GammaFontRenderer.cpp b/libs/hwui/GammaFontRenderer.cpp
index 96cac86..8aff0a2 100644
--- a/libs/hwui/GammaFontRenderer.cpp
+++ b/libs/hwui/GammaFontRenderer.cpp
@@ -24,12 +24,13 @@
 GammaFontRenderer::GammaFontRenderer() {
     INIT_LOGD("Creating lookup gamma font renderer");
 
+#ifndef ANDROID_ENABLE_LINEAR_BLENDING
     // Compute the gamma tables
     const float gamma = 1.0f / Properties::textGamma;
-
     for (uint32_t i = 0; i <= 255; i++) {
         mGammaTable[i] = uint8_t((float)::floor(pow(i / 255.0f, gamma) * 255.0f + 0.5f));
     }
+#endif
 }
 
 void GammaFontRenderer::endPrecaching() {
diff --git a/libs/hwui/GammaFontRenderer.h b/libs/hwui/GammaFontRenderer.h
index bd27a1a..c9cf69b 100644
--- a/libs/hwui/GammaFontRenderer.h
+++ b/libs/hwui/GammaFontRenderer.h
@@ -18,11 +18,6 @@
 #define ANDROID_HWUI_GAMMA_FONT_RENDERER_H
 
 #include "FontRenderer.h"
-#include "Program.h"
-
-#include <SkPaint.h>
-
-#include <utils/String8.h>
 
 namespace android {
 namespace uirenderer {
@@ -43,7 +38,11 @@
 
     FontRenderer& getFontRenderer() {
         if (!mRenderer) {
-            mRenderer.reset(new FontRenderer(&mGammaTable[0]));
+            const uint8_t* table = nullptr;
+#ifndef ANDROID_ENABLE_LINEAR_BLENDING
+            table = &mGammaTable[0];
+#endif
+            mRenderer.reset(new FontRenderer(table));
         }
         return *mRenderer;
     }
@@ -64,7 +63,9 @@
 
 private:
     std::unique_ptr<FontRenderer> mRenderer;
+#ifndef ANDROID_ENABLE_LINEAR_BLENDING
     uint8_t mGammaTable[256];
+#endif
 };
 
 }; // namespace uirenderer
diff --git a/libs/hwui/GlopBuilder.cpp b/libs/hwui/GlopBuilder.cpp
index 1091736..65922f6 100644
--- a/libs/hwui/GlopBuilder.cpp
+++ b/libs/hwui/GlopBuilder.cpp
@@ -223,16 +223,16 @@
         SkXfermode::Mode mode, Blend::ModeOrderSwap modeUsage,
         const SkShader* shader, const SkColorFilter* colorFilter) {
     if (mode != SkXfermode::kClear_Mode) {
-        float alpha = (SkColorGetA(color) / 255.0f) * alphaScale;
         if (!shader) {
-            float colorScale = alpha / 255.0f;
-            mOutGlop->fill.color = {
-                    colorScale * SkColorGetR(color),
-                    colorScale * SkColorGetG(color),
-                    colorScale * SkColorGetB(color),
-                    alpha
-            };
+            FloatColor c;
+            c.set(color);
+            c.r *= alphaScale;
+            c.g *= alphaScale;
+            c.b *= alphaScale;
+            c.a *= alphaScale;
+            mOutGlop->fill.color = c;
         } else {
+            float alpha = (SkColorGetA(color) / 255.0f) * alphaScale;
             mOutGlop->fill.color = { 1, 1, 1, alpha };
         }
     } else {
@@ -276,15 +276,7 @@
         if (colorFilter->asColorMode(&color, &mode)) {
             mOutGlop->fill.filterMode = mDescription.colorOp = ProgramDescription::ColorFilterMode::Blend;
             mDescription.colorMode = mode;
-
-            const float alpha = SkColorGetA(color) / 255.0f;
-            float colorScale = alpha / 255.0f;
-            mOutGlop->fill.filter.color = {
-                    colorScale * SkColorGetR(color),
-                    colorScale * SkColorGetG(color),
-                    colorScale * SkColorGetB(color),
-                    alpha,
-            };
+            mOutGlop->fill.filter.color.set(color);
         } else if (colorFilter->asColorMatrix(srcColorMatrix)) {
             mOutGlop->fill.filterMode = mDescription.colorOp = ProgramDescription::ColorFilterMode::Matrix;
 
@@ -297,10 +289,10 @@
             // Skia uses the range [0..255] for the addition vector, but we need
             // the [0..1] range to apply the vector in GLSL
             float* colorVector = mOutGlop->fill.filter.matrix.vector;
-            colorVector[0] = srcColorMatrix[4] / 255.0f;
-            colorVector[1] = srcColorMatrix[9] / 255.0f;
-            colorVector[2] = srcColorMatrix[14] / 255.0f;
-            colorVector[3] = srcColorMatrix[19] / 255.0f;
+            colorVector[0] = EOCF(srcColorMatrix[4]  / 255.0f);
+            colorVector[1] = EOCF(srcColorMatrix[9]  / 255.0f);
+            colorVector[2] = EOCF(srcColorMatrix[14] / 255.0f);
+            colorVector[3] =      srcColorMatrix[19] / 255.0f;  // alpha is linear
         } else {
             LOG_ALWAYS_FATAL("unsupported ColorFilter");
         }
@@ -481,6 +473,13 @@
     return *this;
 }
 
+GlopBuilder& GlopBuilder::setGammaCorrection(bool enabled) {
+    REQUIRE_STAGES(kFillStage);
+
+    mDescription.hasGammaCorrection = enabled;
+    return *this;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 // Transform
 ////////////////////////////////////////////////////////////////////////////////
diff --git a/libs/hwui/GlopBuilder.h b/libs/hwui/GlopBuilder.h
index 1152461..1f3b53a 100644
--- a/libs/hwui/GlopBuilder.h
+++ b/libs/hwui/GlopBuilder.h
@@ -105,6 +105,8 @@
 
     GlopBuilder& setRoundRectClipState(const RoundRectClipState* roundRectClipState);
 
+    GlopBuilder& setGammaCorrection(bool enabled);
+
     void build();
 
     static void dump(const Glop& glop);
diff --git a/libs/hwui/GradientCache.cpp b/libs/hwui/GradientCache.cpp
index c8f5e94..0972ac1 100644
--- a/libs/hwui/GradientCache.cpp
+++ b/libs/hwui/GradientCache.cpp
@@ -67,7 +67,8 @@
         , mSize(0)
         , mMaxSize(Properties::gradientCacheSize)
         , mUseFloatTexture(extensions.hasFloatTextures())
-        , mHasNpot(extensions.hasNPot()){
+        , mHasNpot(extensions.hasNPot())
+        , mHasSRGB(extensions.hasSRGB()) {
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
 
     mCache.setOnEntryRemovedListener(this);
@@ -176,71 +177,56 @@
 
 size_t GradientCache::bytesPerPixel() const {
     // We use 4 channels (RGBA)
+    return 4 * (mUseFloatTexture ? /* fp16 */ 2 : sizeof(uint8_t));
+}
+
+size_t GradientCache::sourceBytesPerPixel() const {
+    // We use 4 channels (RGBA) and upload from floats (not half floats)
     return 4 * (mUseFloatTexture ? sizeof(float) : sizeof(uint8_t));
 }
 
-void GradientCache::splitToBytes(uint32_t inColor, GradientColor& outColor) const {
-    outColor.r = (inColor >> 16) & 0xff;
-    outColor.g = (inColor >>  8) & 0xff;
-    outColor.b = (inColor >>  0) & 0xff;
-    outColor.a = (inColor >> 24) & 0xff;
-}
-
-void GradientCache::splitToFloats(uint32_t inColor, GradientColor& outColor) const {
-    outColor.r = ((inColor >> 16) & 0xff) / 255.0f;
-    outColor.g = ((inColor >>  8) & 0xff) / 255.0f;
-    outColor.b = ((inColor >>  0) & 0xff) / 255.0f;
-    outColor.a = ((inColor >> 24) & 0xff) / 255.0f;
-}
-
-void GradientCache::mixBytes(GradientColor& start, GradientColor& end, float amount,
-        uint8_t*& dst) const {
+void GradientCache::mixBytes(const FloatColor& start, const FloatColor& end,
+        float amount, uint8_t*& dst) const {
     float oppAmount = 1.0f - amount;
-    const float alpha = start.a * oppAmount + end.a * amount;
-    const float a = alpha / 255.0f;
-
-    *dst++ = uint8_t(a * (start.r * oppAmount + end.r * amount));
-    *dst++ = uint8_t(a * (start.g * oppAmount + end.g * amount));
-    *dst++ = uint8_t(a * (start.b * oppAmount + end.b * amount));
-    *dst++ = uint8_t(alpha);
+    *dst++ = uint8_t(OECF_sRGB(start.r * oppAmount + end.r * amount) * 255.0f);
+    *dst++ = uint8_t(OECF_sRGB(start.g * oppAmount + end.g * amount) * 255.0f);
+    *dst++ = uint8_t(OECF_sRGB(start.b * oppAmount + end.b * amount) * 255.0f);
+    *dst++ = uint8_t(         (start.a * oppAmount + end.a * amount) * 255.0f);
 }
 
-void GradientCache::mixFloats(GradientColor& start, GradientColor& end, float amount,
-        uint8_t*& dst) const {
+void GradientCache::mixFloats(const FloatColor& start, const FloatColor& end,
+        float amount, uint8_t*& dst) const {
     float oppAmount = 1.0f - amount;
-    const float a = start.a * oppAmount + end.a * amount;
-
     float* d = (float*) dst;
-    *d++ = a * (start.r * oppAmount + end.r * amount);
-    *d++ = a * (start.g * oppAmount + end.g * amount);
-    *d++ = a * (start.b * oppAmount + end.b * amount);
-    *d++ = a;
-
+#ifdef ANDROID_ENABLE_LINEAR_BLENDING
+    *d++ = start.r * oppAmount + end.r * amount;
+    *d++ = start.g * oppAmount + end.g * amount;
+    *d++ = start.b * oppAmount + end.b * amount;
+#else
+    *d++ = OECF_sRGB(start.r * oppAmount + end.r * amount);
+    *d++ = OECF_sRGB(start.g * oppAmount + end.g * amount);
+    *d++ = OECF_sRGB(start.b * oppAmount + end.b * amount);
+#endif
+    *d++ = start.a * oppAmount + end.a * amount;
     dst += 4 * sizeof(float);
 }
 
 void GradientCache::generateTexture(uint32_t* colors, float* positions,
         const uint32_t width, const uint32_t height, Texture* texture) {
-    const GLsizei rowBytes = width * bytesPerPixel();
+    const GLsizei rowBytes = width * sourceBytesPerPixel();
     uint8_t pixels[rowBytes * height];
 
-    static ChannelSplitter gSplitters[] = {
-            &android::uirenderer::GradientCache::splitToBytes,
-            &android::uirenderer::GradientCache::splitToFloats,
-    };
-    ChannelSplitter split = gSplitters[mUseFloatTexture];
-
     static ChannelMixer gMixers[] = {
-            &android::uirenderer::GradientCache::mixBytes,
-            &android::uirenderer::GradientCache::mixFloats,
+            &android::uirenderer::GradientCache::mixBytes,  // colors are stored gamma-encoded
+            &android::uirenderer::GradientCache::mixFloats, // colors are stored in linear
     };
     ChannelMixer mix = gMixers[mUseFloatTexture];
 
-    GradientColor start;
-    (this->*split)(colors[0], start);
+    FloatColor start;
+    start.setSRGB(colors[0]);
 
-    GradientColor end;
-    (this->*split)(colors[1], end);
+    FloatColor end;
+    end.setSRGB(colors[1]);
 
     int currentPos = 1;
     float startPos = positions[0];
@@ -255,7 +241,7 @@
 
             currentPos++;
 
-            (this->*split)(colors[currentPos], end);
+            end.setSRGB(colors[currentPos]);
             distance = positions[currentPos] - startPos;
         }
 
@@ -266,10 +252,10 @@
     memcpy(pixels + rowBytes, pixels, rowBytes);
 
     if (mUseFloatTexture) {
-        // We have to use GL_RGBA16F because GL_RGBA32F does not support filtering
         texture->upload(GL_RGBA16F, width, height, GL_RGBA, GL_FLOAT, pixels);
     } else {
-        texture->upload(GL_RGBA, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
+        GLint internalFormat = mHasSRGB ? GL_SRGB8_ALPHA8 : GL_RGBA;
+        texture->upload(internalFormat, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
     }
 
     texture->setFilter(GL_LINEAR);
diff --git a/libs/hwui/GradientCache.h b/libs/hwui/GradientCache.h
index 49be19a..5e35435 100644
--- a/libs/hwui/GradientCache.h
+++ b/libs/hwui/GradientCache.h
@@ -26,6 +26,8 @@
 #include <utils/LruCache.h>
 #include <utils/Mutex.h>
 
+#include "FloatColor.h"
+
 namespace android {
 namespace uirenderer {
 
@@ -150,25 +152,15 @@
     void getGradientInfo(const uint32_t* colors, const int count, GradientInfo& info);
 
     size_t bytesPerPixel() const;
+    size_t sourceBytesPerPixel() const;
 
-    struct GradientColor {
-        float r;
-        float g;
-        float b;
-        float a;
-    };
-
-    typedef void (GradientCache::*ChannelSplitter)(uint32_t inColor,
-            GradientColor& outColor) const;
-
-    void splitToBytes(uint32_t inColor, GradientColor& outColor) const;
-    void splitToFloats(uint32_t inColor, GradientColor& outColor) const;
-
-    typedef void (GradientCache::*ChannelMixer)(GradientColor& start, GradientColor& end,
+    typedef void (GradientCache::*ChannelMixer)(const FloatColor& start, const FloatColor& end,
             float amount, uint8_t*& dst) const;
 
-    void mixBytes(GradientColor& start, GradientColor& end, float amount, uint8_t*& dst) const;
-    void mixFloats(GradientColor& start, GradientColor& end, float amount, uint8_t*& dst) const;
+    void mixBytes(const FloatColor& start, const FloatColor& end,
+            float amount, uint8_t*& dst) const;
+    void mixFloats(const FloatColor& start, const FloatColor& end,
+            float amount, uint8_t*& dst) const;
 
     LruCache<GradientCacheEntry, Texture*> mCache;
 
@@ -178,6 +170,7 @@
     GLint mMaxTextureSize;
     bool mUseFloatTexture;
     bool mHasNpot;
+    bool mHasSRGB;
 
     mutable Mutex mLock;
 }; // class GradientCache
diff --git a/libs/hwui/Layer.h b/libs/hwui/Layer.h
index c688a96..01650ef 100644
--- a/libs/hwui/Layer.h
+++ b/libs/hwui/Layer.h
@@ -75,7 +75,7 @@
     }
 
     void setSize(uint32_t width, uint32_t height) {
-        texture.updateSize(width, height, texture.format());
+        texture.updateSize(width, height, texture.internalFormat(), texture.format());
     }
 
     inline void setBlend(bool blend) {
diff --git a/libs/hwui/PatchCache.cpp b/libs/hwui/PatchCache.cpp
index a6c281d..52c62cc 100644
--- a/libs/hwui/PatchCache.cpp
+++ b/libs/hwui/PatchCache.cpp
@@ -225,17 +225,15 @@
 
 static const UvMapper sIdentity;
 
-const Patch* PatchCache::get(const AssetAtlas::Entry* entry,
-        const uint32_t bitmapWidth, const uint32_t bitmapHeight,
+const Patch* PatchCache::get( const uint32_t bitmapWidth, const uint32_t bitmapHeight,
         const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch) {
 
     const PatchDescription description(bitmapWidth, bitmapHeight, pixelWidth, pixelHeight, patch);
     const Patch* mesh = mCache.get(description);
 
     if (!mesh) {
-        const UvMapper& mapper = entry ? entry->uvMapper : sIdentity;
         Patch* newMesh = new Patch(bitmapWidth, bitmapHeight,
-                pixelWidth, pixelHeight, mapper, patch);
+                pixelWidth, pixelHeight, sIdentity, patch);
 
         if (newMesh->vertices) {
             setupMesh(newMesh);
diff --git a/libs/hwui/PatchCache.h b/libs/hwui/PatchCache.h
index 6e6a730..0624c35 100644
--- a/libs/hwui/PatchCache.h
+++ b/libs/hwui/PatchCache.h
@@ -22,7 +22,6 @@
 
 #include <androidfw/ResourceTypes.h>
 
-#include "AssetAtlas.h"
 #include "Debug.h"
 #include "utils/Pair.h"
 
@@ -54,8 +53,7 @@
     explicit PatchCache(RenderState& renderState);
     ~PatchCache();
 
-    const Patch* get(const AssetAtlas::Entry* entry,
-            const uint32_t bitmapWidth, const uint32_t bitmapHeight,
+    const Patch* get(const uint32_t bitmapWidth, const uint32_t bitmapHeight,
             const float pixelWidth, const float pixelHeight, const Res_png_9patch* patch);
     void clear();
 
diff --git a/libs/hwui/PathCache.cpp b/libs/hwui/PathCache.cpp
index eb606cb..e69ea79 100644
--- a/libs/hwui/PathCache.cpp
+++ b/libs/hwui/PathCache.cpp
@@ -182,8 +182,7 @@
 PathCache::PathCache()
         : mCache(LruCache<PathDescription, PathTexture*>::kUnlimitedCapacity)
         , mSize(0)
-        , mMaxSize(Properties::pathCacheSize)
-        , mTexNum(0) {
+        , mMaxSize(Properties::pathCacheSize) {
     mCache.setOnEntryRemovedListener(this);
 
     GLint maxTextureSize;
@@ -239,7 +238,6 @@
                         "the cache in an inconsistent state", size);
             }
             mSize -= size;
-            mTexNum--;
         }
 
         PATH_LOGD("PathCache::delete name, size, mSize = %d, %d, %d",
@@ -264,7 +262,14 @@
 }
 
 void PathCache::trim() {
-    while (mSize > mMaxSize || mTexNum > DEFAULT_PATH_TEXTURE_CAP) {
+    // 25 is just an arbitrary lower bound to ensure we aren't in weird edge cases
+    // of things like a cap of 0 or 1 as that's going to break things.
+    // It does not represent a reasonable minimum value
+    static_assert(DEFAULT_PATH_TEXTURE_CAP > 25, "Path cache texture cap is too small");
+
+    while (mSize > mMaxSize || mCache.size() > DEFAULT_PATH_TEXTURE_CAP) {
+        LOG_ALWAYS_FATAL_IF(!mCache.size(), "Inconsistent mSize! Ran out of items to remove!"
+                " mSize = %u, mMaxSize = %u", mSize, mMaxSize);
         mCache.removeOldest();
     }
 }
@@ -312,7 +317,6 @@
     ATRACE_NAME("Upload Path Texture");
     texture->upload(bitmap);
     texture->setFilter(GL_LINEAR);
-    mTexNum++;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
diff --git a/libs/hwui/PathCache.h b/libs/hwui/PathCache.h
index b45a2c5..18bcc56 100644
--- a/libs/hwui/PathCache.h
+++ b/libs/hwui/PathCache.h
@@ -281,12 +281,6 @@
 
     bool mDebugEnabled;
 
-    /**
-     * Driver allocated 4k/8k/16k memory for small path cache,
-     * limit the number of PathTexture in case occupy too much memory in hardware.
-     */
-    uint32_t mTexNum;
-
     sp<PathProcessor> mProcessor;
 
     std::vector<uint32_t> mGarbage;
diff --git a/libs/hwui/Program.h b/libs/hwui/Program.h
index e5200a5..f5beb62 100644
--- a/libs/hwui/Program.h
+++ b/libs/hwui/Program.h
@@ -85,6 +85,8 @@
 #define PROGRAM_HAS_DEBUG_HIGHLIGHT 42
 #define PROGRAM_HAS_ROUND_RECT_CLIP 43
 
+#define PROGRAM_HAS_GAMMA_CORRECTION 44
+
 ///////////////////////////////////////////////////////////////////////////////
 // Types
 ///////////////////////////////////////////////////////////////////////////////
@@ -158,6 +160,8 @@
     bool hasDebugHighlight;
     bool hasRoundRectClip;
 
+    bool hasGammaCorrection;
+
     /**
      * Resets this description. All fields are reset back to the default
      * values they hold after building a new instance.
@@ -196,6 +200,8 @@
 
         hasDebugHighlight = false;
         hasRoundRectClip = false;
+
+        hasGammaCorrection = false;
     }
 
     /**
@@ -262,6 +268,7 @@
         if (hasColors) key |= programid(0x1) << PROGRAM_HAS_COLORS;
         if (hasDebugHighlight) key |= programid(0x1) << PROGRAM_HAS_DEBUG_HIGHLIGHT;
         if (hasRoundRectClip) key |= programid(0x1) << PROGRAM_HAS_ROUND_RECT_CLIP;
+        if (hasGammaCorrection) key |= programid(0x1) << PROGRAM_HAS_GAMMA_CORRECTION;
         return key;
     }
 
diff --git a/libs/hwui/ProgramCache.cpp b/libs/hwui/ProgramCache.cpp
index 59225e1..4ef6b85 100644
--- a/libs/hwui/ProgramCache.cpp
+++ b/libs/hwui/ProgramCache.cpp
@@ -17,8 +17,8 @@
 #include <utils/String8.h>
 
 #include "Caches.h"
-#include "Dither.h"
 #include "ProgramCache.h"
+#include "Properties.h"
 
 namespace android {
 namespace uirenderer {
@@ -69,22 +69,16 @@
         "varying highp vec2 outBitmapTexCoords;\n";
 const char* gVS_Header_Varyings_HasGradient[6] = {
         // Linear
-        "varying highp vec2 linear;\n"
-        "varying vec2 ditherTexCoords;\n",
-        "varying float linear;\n"
-        "varying vec2 ditherTexCoords;\n",
+        "varying highp vec2 linear;\n",
+        "varying float linear;\n",
 
         // Circular
-        "varying highp vec2 circular;\n"
-        "varying vec2 ditherTexCoords;\n",
-        "varying highp vec2 circular;\n"
-        "varying vec2 ditherTexCoords;\n",
+        "varying highp vec2 circular;\n",
+        "varying highp vec2 circular;\n",
 
         // Sweep
-        "varying highp vec2 sweep;\n"
-        "varying vec2 ditherTexCoords;\n",
-        "varying highp vec2 sweep;\n"
-        "varying vec2 ditherTexCoords;\n",
+        "varying highp vec2 sweep;\n",
+        "varying highp vec2 sweep;\n",
 };
 const char* gVS_Header_Varyings_HasRoundRectClip =
         "varying highp vec2 roundRectPos;\n";
@@ -98,22 +92,16 @@
         "    outTexCoords = (mainTextureTransform * vec4(texCoords, 0.0, 1.0)).xy;\n";
 const char* gVS_Main_OutGradient[6] = {
         // Linear
-        "    linear = vec2((screenSpace * position).x, 0.5);\n"
-        "    ditherTexCoords = (transform * position).xy * " STR(DITHER_KERNEL_SIZE_INV) ";\n",
-        "    linear = (screenSpace * position).x;\n"
-        "    ditherTexCoords = (transform * position).xy * " STR(DITHER_KERNEL_SIZE_INV) ";\n",
+        "    linear = vec2((screenSpace * position).x, 0.5);\n",
+        "    linear = (screenSpace * position).x;\n",
 
         // Circular
-        "    circular = (screenSpace * position).xy;\n"
-        "    ditherTexCoords = (transform * position).xy * " STR(DITHER_KERNEL_SIZE_INV) ";\n",
-        "    circular = (screenSpace * position).xy;\n"
-        "    ditherTexCoords = (transform * position).xy * " STR(DITHER_KERNEL_SIZE_INV) ";\n",
+        "    circular = (screenSpace * position).xy;\n",
+        "    circular = (screenSpace * position).xy;\n",
 
         // Sweep
+        "    sweep = (screenSpace * position).xy;\n",
         "    sweep = (screenSpace * position).xy;\n"
-        "    ditherTexCoords = (transform * position).xy * " STR(DITHER_KERNEL_SIZE_INV) ";\n",
-        "    sweep = (screenSpace * position).xy;\n"
-        "    ditherTexCoords = (transform * position).xy * " STR(DITHER_KERNEL_SIZE_INV) ";\n",
 };
 const char* gVS_Main_OutBitmapTexCoords =
         "    outBitmapTexCoords = (textureTransform * position).xy * textureDimension;\n";
@@ -147,12 +135,11 @@
         "uniform sampler2D baseSampler;\n";
 const char* gFS_Uniforms_ExternalTextureSampler =
         "uniform samplerExternalOES baseSampler;\n";
-const char* gFS_Uniforms_Dither =
-        "uniform sampler2D ditherSampler;";
 const char* gFS_Uniforms_GradientSampler[2] = {
-        "%s\n"
+        "uniform vec2 screenSize;\n"
         "uniform sampler2D gradientSampler;\n",
-        "%s\n"
+
+        "uniform vec2 screenSize;\n"
         "uniform vec4 startColor;\n"
         "uniform vec4 endColor;\n"
 };
@@ -172,18 +159,57 @@
         "uniform vec4 roundRectInnerRectLTRB;\n"
         "uniform float roundRectRadius;\n";
 
+// Dithering must be done in the quantization space
+// When we are writing to an sRGB framebuffer, we must do the following:
+//     EOCF(OECF(color) + dither)
+// We approximate the transfer functions with gamma 2.0 to avoid branches and pow()
+// The dithering pattern is generated with a triangle noise generator in the range [-0.0,1.0]
+// TODO: Handle linear fp16 render targets
+const char* gFS_Gradient_Functions =
+        "\nfloat triangleNoise(const highp vec2 n) {\n"
+        "    highp vec2 p = fract(n * vec2(5.3987, 5.4421));\n"
+        "    p += dot(p.yx, p.xy + vec2(21.5351, 14.3137));\n"
+        "    highp float xy = p.x * p.y;\n"
+        "    return fract(xy * 95.4307) + fract(xy * 75.04961) - 1.0;\n"
+        "}\n";
+const char* gFS_Gradient_Preamble[2] = {
+        // Linear framebuffer
+        "\nvec4 dither(const vec4 color) {\n"
+        "    return vec4(color.rgb + (triangleNoise(gl_FragCoord.xy * screenSize.xy) / 255.0), color.a);"
+        "}\n"
+        "\nvec4 gammaMix(const vec4 a, const vec4 b, float v) {\n"
+        "    return pow(mix(a, b, v), vec4(vec3(1.0 / 2.2), 1.0));"
+        "}\n",
+        // sRGB framebuffer
+        "\nvec4 dither(const vec4 color) {\n"
+        "    vec3 dithered = sqrt(color.rgb) + (triangleNoise(gl_FragCoord.xy * screenSize.xy) / 255.0);\n"
+        "    return vec4(dithered * dithered, color.a);\n"
+        "}\n"
+        "\nvec4 gammaMix(const vec4 a, const vec4 b, float v) {\n"
+        "    return mix(a, b, v);"
+        "}\n"
+};
+
+// Uses luminance coefficients from Rec.709 to choose the appropriate gamma
+// The gamma() function assumes that bright text will be displayed on a dark
+// background and that dark text will be displayed on bright background
+// The gamma coefficient is chosen to thicken or thin the text accordingly
+// The dot product used to compute the luminance could be approximated with
+// a simple max(color.r, color.g, color.b)
+const char* gFS_Gamma_Preamble =
+        "\n#define GAMMA (%.2f)\n"
+        "#define GAMMA_INV (%.2f)\n"
+        "\nfloat gamma(float a, const vec3 color) {\n"
+        "    float luminance = dot(color, vec3(0.2126, 0.7152, 0.0722));\n"
+        "    return pow(a, luminance < 0.5 ? GAMMA_INV : GAMMA);\n"
+        "}\n";
+
 const char* gFS_Main =
         "\nvoid main(void) {\n"
-        "    lowp vec4 fragColor;\n";
+        "    vec4 fragColor;\n";
 
-const char* gFS_Main_Dither[2] = {
-        // ES 2.0
-        "texture2D(ditherSampler, ditherTexCoords).a * " STR(DITHER_KERNEL_SIZE_INV_SQUARE),
-        // ES 3.0
-        "texture2D(ditherSampler, ditherTexCoords).a"
-};
-const char* gFS_Main_AddDitherToGradient =
-        "    gradientColor += %s;\n";
+const char* gFS_Main_AddDither =
+        "    fragColor = dither(fragColor);\n";
 
 // Fast cases
 const char* gFS_Fast_SingleColor =
@@ -202,24 +228,32 @@
         "\nvoid main(void) {\n"
         "    gl_FragColor = texture2D(baseSampler, outTexCoords);\n"
         "}\n\n";
+const char* gFS_Fast_SingleA8Texture_ApplyGamma =
+        "\nvoid main(void) {\n"
+        "    gl_FragColor = vec4(0.0, 0.0, 0.0, pow(texture2D(baseSampler, outTexCoords).a, GAMMA));\n"
+        "}\n\n";
 const char* gFS_Fast_SingleModulateA8Texture =
         "\nvoid main(void) {\n"
         "    gl_FragColor = color * texture2D(baseSampler, outTexCoords).a;\n"
         "}\n\n";
+const char* gFS_Fast_SingleModulateA8Texture_ApplyGamma =
+        "\nvoid main(void) {\n"
+        "    gl_FragColor = color * gamma(texture2D(baseSampler, outTexCoords).a, color.rgb);\n"
+        "}\n\n";
 const char* gFS_Fast_SingleGradient[2] = {
         "\nvoid main(void) {\n"
-        "    gl_FragColor = %s + texture2D(gradientSampler, linear);\n"
+        "    gl_FragColor = dither(texture2D(gradientSampler, linear));\n"
         "}\n\n",
         "\nvoid main(void) {\n"
-        "    gl_FragColor = %s + mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n"
+        "    gl_FragColor = dither(gammaMix(startColor, endColor, clamp(linear, 0.0, 1.0)));\n"
         "}\n\n",
 };
 const char* gFS_Fast_SingleModulateGradient[2] = {
         "\nvoid main(void) {\n"
-        "    gl_FragColor = %s + color.a * texture2D(gradientSampler, linear);\n"
+        "    gl_FragColor = dither(color.a * texture2D(gradientSampler, linear));\n"
         "}\n\n",
         "\nvoid main(void) {\n"
-        "    gl_FragColor = %s + color.a * mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n"
+        "    gl_FragColor = dither(color.a * gammaMix(startColor, endColor, clamp(linear, 0.0, 1.0)));\n"
         "}\n\n"
 };
 
@@ -239,29 +273,31 @@
         // Modulate
         "    fragColor = color * texture2D(baseSampler, outTexCoords);\n"
 };
-const char* gFS_Main_FetchA8Texture[2] = {
+const char* gFS_Main_FetchA8Texture[4] = {
         // Don't modulate
         "    fragColor = texture2D(baseSampler, outTexCoords);\n",
+        "    fragColor = texture2D(baseSampler, outTexCoords);\n",
         // Modulate
         "    fragColor = color * texture2D(baseSampler, outTexCoords).a;\n",
+        "    fragColor = color * gamma(texture2D(baseSampler, outTexCoords).a, color.rgb);\n",
 };
 const char* gFS_Main_FetchGradient[6] = {
         // Linear
         "    vec4 gradientColor = texture2D(gradientSampler, linear);\n",
 
-        "    vec4 gradientColor = mix(startColor, endColor, clamp(linear, 0.0, 1.0));\n",
+        "    vec4 gradientColor = gammaMix(startColor, endColor, clamp(linear, 0.0, 1.0));\n",
 
         // Circular
         "    vec4 gradientColor = texture2D(gradientSampler, vec2(length(circular), 0.5));\n",
 
-        "    vec4 gradientColor = mix(startColor, endColor, clamp(length(circular), 0.0, 1.0));\n",
+        "    vec4 gradientColor = gammaMix(startColor, endColor, clamp(length(circular), 0.0, 1.0));\n",
 
         // Sweep
         "    highp float index = atan(sweep.y, sweep.x) * 0.15915494309; // inv(2 * PI)\n"
         "    vec4 gradientColor = texture2D(gradientSampler, vec2(index - floor(index), 0.5));\n",
 
         "    highp float index = atan(sweep.y, sweep.x) * 0.15915494309; // inv(2 * PI)\n"
-        "    vec4 gradientColor = mix(startColor, endColor, clamp(index - floor(index), 0.0, 1.0));\n"
+        "    vec4 gradientColor = gammaMix(startColor, endColor, clamp(index - floor(index), 0.0, 1.0));\n"
 };
 const char* gFS_Main_FetchBitmap =
         "    vec4 bitmapColor = texture2D(bitmapSampler, outBitmapTexCoords);\n";
@@ -271,29 +307,38 @@
         "    fragColor = blendShaders(gradientColor, bitmapColor)";
 const char* gFS_Main_BlendShadersGB =
         "    fragColor = blendShaders(bitmapColor, gradientColor)";
-const char* gFS_Main_BlendShaders_Modulate[3] = {
+const char* gFS_Main_BlendShaders_Modulate[6] = {
         // Don't modulate
         ";\n",
+        ";\n",
         // Modulate
         " * color.a;\n",
+        " * color.a;\n",
         // Modulate with alpha 8 texture
         " * texture2D(baseSampler, outTexCoords).a;\n",
+        " * gamma(texture2D(baseSampler, outTexCoords).a, color.rgb);\n",
 };
-const char* gFS_Main_GradientShader_Modulate[3] = {
+const char* gFS_Main_GradientShader_Modulate[6] = {
         // Don't modulate
         "    fragColor = gradientColor;\n",
+        "    fragColor = gradientColor;\n",
         // Modulate
         "    fragColor = gradientColor * color.a;\n",
+        "    fragColor = gradientColor * color.a;\n",
         // Modulate with alpha 8 texture
         "    fragColor = gradientColor * texture2D(baseSampler, outTexCoords).a;\n",
+        "    fragColor = gradientColor * gamma(texture2D(baseSampler, outTexCoords).a, gradientColor.rgb);\n",
     };
-const char* gFS_Main_BitmapShader_Modulate[3] = {
+const char* gFS_Main_BitmapShader_Modulate[6] = {
         // Don't modulate
         "    fragColor = bitmapColor;\n",
+        "    fragColor = bitmapColor;\n",
         // Modulate
         "    fragColor = bitmapColor * color.a;\n",
+        "    fragColor = bitmapColor * color.a;\n",
         // Modulate with alpha 8 texture
         "    fragColor = bitmapColor * texture2D(baseSampler, outTexCoords).a;\n",
+        "    fragColor = bitmapColor * gamma(texture2D(baseSampler, outTexCoords).a, bitmapColor.rgb);\n",
     };
 const char* gFS_Main_FragColor =
         "    gl_FragColor = fragColor;\n";
@@ -385,7 +430,8 @@
 ///////////////////////////////////////////////////////////////////////////////
 
 ProgramCache::ProgramCache(Extensions& extensions)
-        : mHasES3(extensions.getMajorGlVersion() >= 3) {
+        : mHasES3(extensions.getMajorGlVersion() >= 3)
+        , mHasSRGB(extensions.hasSRGB()) {
 }
 
 ProgramCache::~ProgramCache() {
@@ -518,6 +564,7 @@
 static bool shaderOp(const ProgramDescription& description, String8& shader,
         const int modulateOp, const char** snippets) {
     int op = description.hasAlpha8Texture ? MODULATE_OP_MODULATE_A8 : modulateOp;
+    op = op * 2 + description.hasGammaCorrection;
     shader.append(snippets[op]);
     return description.hasAlpha8Texture;
 }
@@ -570,13 +617,16 @@
         shader.append(gFS_Uniforms_ExternalTextureSampler);
     }
     if (description.hasGradient) {
-        shader.appendFormat(gFS_Uniforms_GradientSampler[description.isSimpleGradient],
-                gFS_Uniforms_Dither);
+        shader.append(gFS_Uniforms_GradientSampler[description.isSimpleGradient]);
     }
     if (description.hasRoundRectClip) {
         shader.append(gFS_Uniforms_HasRoundRectClip);
     }
 
+    if (description.hasGammaCorrection) {
+        shader.appendFormat(gFS_Gamma_Preamble, Properties::textGamma, 1.0f / Properties::textGamma);
+    }
+
     // Optimization for common cases
     if (!description.hasVertexAlpha
             && !blendFramebuffer
@@ -607,18 +657,26 @@
             fast = true;
         } else if (singleA8Texture) {
             if (!description.modulate) {
-                shader.append(gFS_Fast_SingleA8Texture);
+                if (description.hasGammaCorrection) {
+                    shader.append(gFS_Fast_SingleA8Texture_ApplyGamma);
+                } else {
+                    shader.append(gFS_Fast_SingleA8Texture);
+                }
             } else {
-                shader.append(gFS_Fast_SingleModulateA8Texture);
+                if (description.hasGammaCorrection) {
+                    shader.append(gFS_Fast_SingleModulateA8Texture_ApplyGamma);
+                } else {
+                    shader.append(gFS_Fast_SingleModulateA8Texture);
+                }
             }
             fast = true;
         } else if (singleGradient) {
+            shader.append(gFS_Gradient_Functions);
+            shader.append(gFS_Gradient_Preamble[mHasSRGB]);
             if (!description.modulate) {
-                shader.appendFormat(gFS_Fast_SingleGradient[description.isSimpleGradient],
-                        gFS_Main_Dither[mHasES3]);
+                shader.append(gFS_Fast_SingleGradient[description.isSimpleGradient]);
             } else {
-                shader.appendFormat(gFS_Fast_SingleModulateGradient[description.isSimpleGradient],
-                        gFS_Main_Dither[mHasES3]);
+                shader.append(gFS_Fast_SingleModulateGradient[description.isSimpleGradient]);
             }
             fast = true;
         }
@@ -652,6 +710,10 @@
     if (description.isBitmapNpot) {
         generateTextureWrap(shader, description.bitmapWrapS, description.bitmapWrapT);
     }
+    if (description.hasGradient) {
+        shader.append(gFS_Gradient_Functions);
+        shader.append(gFS_Gradient_Preamble[mHasSRGB]);
+    }
 
     // Begin the shader
     shader.append(gFS_Main); {
@@ -659,7 +721,8 @@
         if (description.hasTexture || description.hasExternalTexture) {
             if (description.hasAlpha8Texture) {
                 if (!description.hasGradient && !description.hasBitmap) {
-                    shader.append(gFS_Main_FetchA8Texture[modulateOp]);
+                    shader.append(
+                            gFS_Main_FetchA8Texture[modulateOp * 2 + description.hasGammaCorrection]);
                 }
             } else {
                 shader.append(gFS_Main_FetchTexture[modulateOp]);
@@ -671,7 +734,6 @@
         }
         if (description.hasGradient) {
             shader.append(gFS_Main_FetchGradient[gradientIndex(description)]);
-            shader.appendFormat(gFS_Main_AddDitherToGradient, gFS_Main_Dither[mHasES3]);
         }
         if (description.hasBitmap) {
             if (!description.isBitmapNpot) {
@@ -715,6 +777,10 @@
             }
         }
 
+        if (description.hasGradient) {
+            shader.append(gFS_Main_AddDither);
+        }
+
         // Output the fragment
         if (!blendFramebuffer) {
             shader.append(gFS_Main_FragColor);
diff --git a/libs/hwui/ProgramCache.h b/libs/hwui/ProgramCache.h
index 9ac885b..292ecdf 100644
--- a/libs/hwui/ProgramCache.h
+++ b/libs/hwui/ProgramCache.h
@@ -59,6 +59,7 @@
     std::map<programid, std::unique_ptr<Program>> mCache;
 
     const bool mHasES3;
+    const bool mHasSRGB;
 }; // class ProgramCache
 
 }; // namespace uirenderer
diff --git a/libs/hwui/Properties.cpp b/libs/hwui/Properties.cpp
index 93b2e15..848161e 100644
--- a/libs/hwui/Properties.cpp
+++ b/libs/hwui/Properties.cpp
@@ -214,7 +214,7 @@
     property_get(PROPERTY_DEFAULT_RENDERER, prop, "opengl");
     if (!strcmp(prop, "skiagl") ) {
         sRenderPipelineType = RenderPipelineType::SkiaGL;
-    } else if (!strcmp(prop, "skiavulkan") ) {
+    } else if (!strcmp(prop, "skiavk") ) {
         sRenderPipelineType = RenderPipelineType::SkiaVulkan;
     } else { //"opengl"
         sRenderPipelineType = RenderPipelineType::OpenGL;
@@ -222,5 +222,11 @@
     return sRenderPipelineType;
 }
 
+bool Properties::isSkiaEnabled() {
+    auto renderType = getRenderPipelineType();
+    return RenderPipelineType::SkiaGL == renderType
+            || RenderPipelineType::SkiaVulkan == renderType;
+}
+
 }; // namespace uirenderer
 }; // namespace android
diff --git a/libs/hwui/Properties.h b/libs/hwui/Properties.h
index eedc9e7..b4a3118 100644
--- a/libs/hwui/Properties.h
+++ b/libs/hwui/Properties.h
@@ -203,7 +203,7 @@
 #define PROPERTY_TEXT_LARGE_CACHE_WIDTH "ro.hwui.text_large_cache_width"
 #define PROPERTY_TEXT_LARGE_CACHE_HEIGHT "ro.hwui.text_large_cache_height"
 
-// Gamma (>= 1.0, <= 10.0)
+// Gamma (>= 1.0, <= 3.0)
 #define PROPERTY_TEXT_GAMMA "hwui.text_gamma"
 
 ///////////////////////////////////////////////////////////////////////////////
@@ -222,7 +222,7 @@
 
 #define DEFAULT_TEXTURE_CACHE_FLUSH_RATE 0.6f
 
-#define DEFAULT_TEXT_GAMMA 1.4f
+#define DEFAULT_TEXT_GAMMA 1.45f // Match design tools
 
 // cap to 256 to limite paths in the path cache
 #define DEFAULT_PATH_TEXTURE_CAP 256
@@ -308,6 +308,7 @@
 
     static ProfileType getProfileType();
     static RenderPipelineType getRenderPipelineType();
+    static bool isSkiaEnabled();
 
     // Should be used only by test apps
     static bool waitForGpuCompletion;
diff --git a/libs/hwui/PropertyValuesHolder.cpp b/libs/hwui/PropertyValuesHolder.cpp
index 6ba0ab5..2a03e6a 100644
--- a/libs/hwui/PropertyValuesHolder.cpp
+++ b/libs/hwui/PropertyValuesHolder.cpp
@@ -16,6 +16,7 @@
 
 #include "PropertyValuesHolder.h"
 
+#include "utils/Color.h"
 #include "utils/VectorDrawableUtils.h"
 
 #include <utils/Log.h>
@@ -25,18 +26,26 @@
 
 using namespace VectorDrawable;
 
-inline U8CPU lerp(U8CPU fromValue, U8CPU toValue, float fraction) {
-    return (U8CPU) (fromValue * (1 - fraction) + toValue * fraction);
+inline constexpr float lerp(float fromValue, float toValue, float fraction) {
+    return float (fromValue * (1 - fraction) + toValue * fraction);
+}
+
+inline constexpr float linearize(U8CPU component) {
+    return EOCF_sRGB(component / 255.0f);
 }
 
 // TODO: Add a test for this
 void ColorEvaluator::evaluate(SkColor* outColor,
         const SkColor& fromColor, const SkColor& toColor, float fraction) const {
-    U8CPU alpha = lerp(SkColorGetA(fromColor), SkColorGetA(toColor), fraction);
-    U8CPU red = lerp(SkColorGetR(fromColor), SkColorGetR(toColor), fraction);
-    U8CPU green = lerp(SkColorGetG(fromColor), SkColorGetG(toColor), fraction);
-    U8CPU blue = lerp(SkColorGetB(fromColor), SkColorGetB(toColor), fraction);
-    *outColor = SkColorSetARGB(alpha, red, green, blue);
+    float a = lerp(SkColorGetA(fromColor) / 255.0f, SkColorGetA(toColor) / 255.0f, fraction);
+    float r = lerp(linearize(SkColorGetR(fromColor)), linearize(SkColorGetR(toColor)), fraction);
+    float g = lerp(linearize(SkColorGetG(fromColor)), linearize(SkColorGetG(toColor)), fraction);
+    float b = lerp(linearize(SkColorGetB(fromColor)), linearize(SkColorGetB(toColor)), fraction);
+    *outColor = SkColorSetARGB(
+            (U8CPU) roundf(a * 255.0f),
+            (U8CPU) roundf(OECF_sRGB(r) * 255.0f),
+            (U8CPU) roundf(OECF_sRGB(g) * 255.0f),
+            (U8CPU) roundf(OECF_sRGB(b) * 255.0f));
 }
 
 void PathEvaluator::evaluate(PathData* out,
diff --git a/libs/hwui/Readback.cpp b/libs/hwui/Readback.cpp
index ddca122..22c6dfc 100644
--- a/libs/hwui/Readback.cpp
+++ b/libs/hwui/Readback.cpp
@@ -197,7 +197,7 @@
 
     Texture sourceTexture(caches);
     sourceTexture.wrap(sourceTexId,
-            sourceBuffer->getWidth(), sourceBuffer->getHeight(), 0 /* total lie */);
+            sourceBuffer->getWidth(), sourceBuffer->getHeight(), 0, 0 /* total lie */);
 
     CopyResult copyResult = copyTextureInto(caches, renderThread.renderState(),
             sourceTexture, texTransform, srcRect, bitmap);
diff --git a/libs/hwui/RecordedOp.h b/libs/hwui/RecordedOp.h
index a65c22c..ebc41b1 100644
--- a/libs/hwui/RecordedOp.h
+++ b/libs/hwui/RecordedOp.h
@@ -216,7 +216,6 @@
             : SUPER(BitmapOp)
             , bitmap(bitmap) {}
     const SkBitmap* bitmap;
-    // TODO: asset atlas/texture id lookup?
 };
 
 struct BitmapMeshOp : RecordedOp {
diff --git a/libs/hwui/RenderNode.cpp b/libs/hwui/RenderNode.cpp
index 8c36ab5..a03ded6 100644
--- a/libs/hwui/RenderNode.cpp
+++ b/libs/hwui/RenderNode.cpp
@@ -51,7 +51,7 @@
 RenderNode::~RenderNode() {
     deleteDisplayList(nullptr);
     delete mStagingDisplayList;
-    LOG_ALWAYS_FATAL_IF(mLayer, "layer missed detachment!");
+    LOG_ALWAYS_FATAL_IF(hasLayer(), "layer missed detachment!");
 }
 
 void RenderNode::setStagingDisplayList(DisplayList* displayList, TreeObserver* observer) {
@@ -81,7 +81,7 @@
             << (properties().hasShadow() ? ", casting shadow" : "")
             << (isRenderable() ? "" : ", empty")
             << (properties().getProjectBackwards() ? ", projected" : "")
-            << (mLayer != nullptr ? ", on HW Layer" : "")
+            << (hasLayer() ? ", on HW Layer" : "")
             << ")" << std::endl;
 
     properties().debugOutputProperties(output, level + 1);
@@ -237,7 +237,7 @@
             || CC_UNLIKELY(!isRenderable())
             || CC_UNLIKELY(properties().getWidth() == 0)
             || CC_UNLIKELY(properties().getHeight() == 0)) {
-        if (CC_UNLIKELY(mLayer)) {
+        if (CC_UNLIKELY(hasLayer())) {
             renderthread::CanvasContext::destroyLayer(this);
         }
         return;
@@ -247,7 +247,7 @@
         damageSelf(info);
     }
 
-    if (!mLayer) {
+    if (!hasLayer()) {
         Caches::getInstance().dumpMemoryUsage();
         if (info.errorHandler) {
             std::ostringstream err;
@@ -295,9 +295,9 @@
 
     bool willHaveFunctor = false;
     if (info.mode == TreeInfo::MODE_FULL && mStagingDisplayList) {
-        willHaveFunctor = !mStagingDisplayList->getFunctors().empty();
+        willHaveFunctor = mStagingDisplayList->hasFunctor();
     } else if (mDisplayList) {
-        willHaveFunctor = !mDisplayList->getFunctors().empty();
+        willHaveFunctor = mDisplayList->hasFunctor();
     }
     bool childFunctorsNeedLayer = mProperties.prepareForFunctorPresence(
             willHaveFunctor, functorsNeedLayer);
@@ -310,15 +310,15 @@
     if (info.mode == TreeInfo::MODE_FULL) {
         pushStagingDisplayListChanges(info);
     }
-    prepareSubTree(info, childFunctorsNeedLayer, mDisplayList);
 
     if (mDisplayList) {
-        for (auto& vectorDrawable : mDisplayList->getVectorDrawables()) {
-            // If any vector drawable in the display list needs update, damage the node.
-            if (vectorDrawable->isDirty()) {
-                damageSelf(info);
-            }
-            vectorDrawable->setPropertyChangeWillBeConsumed(true);
+        info.out.hasFunctors |= mDisplayList->hasFunctor();
+        bool isDirty = mDisplayList->prepareListAndChildren(info, childFunctorsNeedLayer,
+                [](RenderNode* child, TreeInfo& info, bool functorsNeedLayer) {
+            child->prepareTreeImpl(info, functorsNeedLayer);
+        });
+        if (isDirty) {
+            damageSelf(info);
         }
     }
     pushLayerUpdate(info);
@@ -356,20 +356,15 @@
     // Make sure we inc first so that we don't fluctuate between 0 and 1,
     // which would thrash the layer cache
     if (mStagingDisplayList) {
-        for (auto&& child : mStagingDisplayList->getChildren()) {
-            child->renderNode->incParentRefCount();
-        }
+        mStagingDisplayList->updateChildren([](RenderNode* child) {
+            child->incParentRefCount();
+        });
     }
     deleteDisplayList(info ? info->observer : nullptr, info);
     mDisplayList = mStagingDisplayList;
     mStagingDisplayList = nullptr;
     if (mDisplayList) {
-        for (auto& iter : mDisplayList->getFunctors()) {
-            (*iter.functor)(DrawGlInfo::kModeSync, nullptr);
-        }
-        for (auto& vectorDrawable : mDisplayList->getVectorDrawables()) {
-            vectorDrawable->syncProperties();
-        }
+        mDisplayList->syncContents();
     }
 }
 
@@ -386,40 +381,24 @@
 
 void RenderNode::deleteDisplayList(TreeObserver* observer, TreeInfo* info) {
     if (mDisplayList) {
-        for (auto&& child : mDisplayList->getChildren()) {
-            child->renderNode->decParentRefCount(observer, info);
+        mDisplayList->updateChildren([observer, info](RenderNode* child) {
+            child->decParentRefCount(observer, info);
+        });
+        if (!mDisplayList->reuseDisplayList(this, info ? &info->canvasContext : nullptr)) {
+            delete mDisplayList;
         }
     }
-    delete mDisplayList;
     mDisplayList = nullptr;
 }
 
-void RenderNode::prepareSubTree(TreeInfo& info, bool functorsNeedLayer, DisplayList* subtree) {
-    if (subtree) {
-        TextureCache& cache = Caches::getInstance().textureCache;
-        info.out.hasFunctors |= subtree->getFunctors().size();
-        for (auto&& bitmapResource : subtree->getBitmapResources()) {
-            void* ownerToken = &info.canvasContext;
-            info.prepareTextures = cache.prefetchAndMarkInUse(ownerToken, bitmapResource);
-        }
-        for (auto&& op : subtree->getChildren()) {
-            RenderNode* childNode = op->renderNode;
-            info.damageAccumulator->pushTransform(&op->localMatrix);
-            bool childFunctorsNeedLayer = functorsNeedLayer; // TODO! || op->mRecordedWithPotentialStencilClip;
-            childNode->prepareTreeImpl(info, childFunctorsNeedLayer);
-            info.damageAccumulator->popTransform();
-        }
-    }
-}
-
 void RenderNode::destroyHardwareResources(TreeObserver* observer, TreeInfo* info) {
-    if (mLayer) {
+    if (hasLayer()) {
         renderthread::CanvasContext::destroyLayer(this);
     }
     if (mDisplayList) {
-        for (auto&& child : mDisplayList->getChildren()) {
-            child->renderNode->destroyHardwareResources(observer, info);
-        }
+        mDisplayList->updateChildren([observer, info](RenderNode* child) {
+            child->destroyHardwareResources(observer, info);
+        });
         if (mNeedsDisplayListSync) {
             // Next prepare tree we are going to push a new display list, so we can
             // drop our current one now
diff --git a/libs/hwui/RenderNode.h b/libs/hwui/RenderNode.h
index da93c13..a05c744 100644
--- a/libs/hwui/RenderNode.h
+++ b/libs/hwui/RenderNode.h
@@ -32,6 +32,7 @@
 #include "DisplayList.h"
 #include "Matrix.h"
 #include "RenderProperties.h"
+#include "SkiaDisplayList.h"
 
 #include <vector>
 
@@ -39,6 +40,7 @@
 class SkPaint;
 class SkPath;
 class SkRegion;
+class SkSurface;
 
 namespace android {
 namespace uirenderer {
@@ -48,6 +50,7 @@
 class FrameBuilder;
 class OffscreenBuffer;
 class Rect;
+class SkiaDisplayList;
 class SkiaShader;
 struct RenderNodeOp;
 
@@ -240,7 +243,6 @@
     void prepareTreeImpl(TreeInfo& info, bool functorsNeedLayer);
     void pushStagingPropertiesChanges(TreeInfo& info);
     void pushStagingDisplayListChanges(TreeInfo& info);
-    void prepareSubTree(TreeInfo& info, bool functorsNeedLayer, DisplayList* subtree);
     void prepareLayer(TreeInfo& info, uint32_t dirtyMask);
     void pushLayerUpdate(TreeInfo& info);
     void deleteDisplayList(TreeObserver* observer, TreeInfo* info = nullptr);
@@ -285,6 +287,63 @@
     uint32_t mParentCount;
 
     sp<PositionListener> mPositionListener;
+
+// METHODS & FIELDS ONLY USED BY THE SKIA RENDERER
+public:
+    /**
+     * Detach and transfer ownership of an already allocated displayList for use
+     * in recording updated content for this renderNode
+     */
+    std::unique_ptr<SkiaDisplayList> detachAvailableList() {
+        return std::move(mAvailableDisplayList);
+    }
+
+    /**
+     * Attach unused displayList to this node for potential future reuse.
+     */
+    void attachAvailableList(SkiaDisplayList* skiaDisplayList) {
+        mAvailableDisplayList.reset(skiaDisplayList);
+    }
+
+    /**
+     * Returns true if an offscreen layer from any renderPipeline is attached
+     * to this node.
+     */
+    bool hasLayer() const { return mLayer || mLayerSurface.get(); }
+
+    /**
+     * Used by the RenderPipeline to attach an offscreen surface to the RenderNode.
+     * The surface is then will be used to store the contents of a layer.
+     */
+    void setLayerSurface(sk_sp<SkSurface> layer) { mLayerSurface = layer; }
+
+
+    /**
+     * If the RenderNode is of type LayerType::RenderLayer then this method will
+     * return the an offscreen rendering surface that is used to both render into
+     * the layer and composite the layer into its parent.  If the type is not
+     * LayerType::RenderLayer then it will return a nullptr.
+     *
+     * NOTE: this function is only guaranteed to return accurate results after
+     *       prepareTree has been run for this RenderNode
+     */
+    SkSurface* getLayerSurface() const { return mLayerSurface.get(); }
+
+private:
+    /**
+     * If this RenderNode has been used in a previous frame then the SkiaDisplayList
+     * from that frame is cached here until one of the following conditions is met:
+     *  1) The RenderNode is deleted (causing this to be deleted)
+     *  2) It is replaced with the displayList from the next completed frame
+     *  3) It is detached and used to to record a new displayList for a later frame
+     */
+    std::unique_ptr<SkiaDisplayList> mAvailableDisplayList;
+
+    /**
+     * An offscreen rendering target used to contain the contents this RenderNode
+     * when it has been set to draw as a LayerType::RenderLayer.
+     */
+    sk_sp<SkSurface> mLayerSurface;
 }; // class RenderNode
 
 } /* namespace uirenderer */
diff --git a/libs/hwui/SkiaDisplayList.cpp b/libs/hwui/SkiaDisplayList.cpp
new file mode 100644
index 0000000..d10f306
--- /dev/null
+++ b/libs/hwui/SkiaDisplayList.cpp
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "SkiaDisplayList.h"
+
+#include "renderthread/CanvasContext.h"
+#include "VectorDrawable.h"
+
+#include <SkImagePriv.h>
+#include <SkMutex.h>
+
+namespace android {
+namespace uirenderer {
+
+SkiaDisplayList::SkiaDisplayList(SkRect bounds) : mDrawable(SkLiteDL::New(bounds)) {
+    SkASSERT(projectionReceiveIndex == -1);
+}
+
+void SkiaDisplayList::syncContents() {
+    for (auto& functor : mChildFunctors) {
+        functor.syncFunctor();
+    }
+    for (auto& vectorDrawable : mVectorDrawables) {
+        vectorDrawable->syncProperties();
+    }
+}
+
+bool SkiaDisplayList::reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) {
+    reset(context ? context->getGrContext() : nullptr, SkRect::MakeEmpty());
+    node->attachAvailableList(this);
+    return true;
+}
+
+void SkiaDisplayList::updateChildren(std::function<void(RenderNode*)> updateFn) {
+    for (auto& child : mChildNodes) {
+        updateFn(child.getRenderNode());
+    }
+}
+
+bool SkiaDisplayList::prepareListAndChildren(TreeInfo& info, bool functorsNeedLayer,
+        std::function<void(RenderNode*, TreeInfo&, bool)> childFn) {
+    // force all mutable images to be pinned in the GPU cache for the duration
+    // of this frame
+    pinImages(info.canvasContext.getGrContext());
+
+    for (auto& child : mChildNodes) {
+        RenderNode* childNode = child.getRenderNode();
+        Matrix4 mat4(child.getRecordedMatrix());
+        info.damageAccumulator->pushTransform(&mat4);
+        // TODO: a layer is needed if the canvas is rotated or has a non-rect clip
+        bool childFunctorsNeedLayer = functorsNeedLayer;
+        childFn(childNode, info, childFunctorsNeedLayer);
+        info.damageAccumulator->popTransform();
+    }
+
+    bool isDirty = false;
+    for (auto& vectorDrawable : mVectorDrawables) {
+        // If any vector drawable in the display list needs update, damage the node.
+        if (vectorDrawable->isDirty()) {
+            isDirty = true;
+        }
+        vectorDrawable->setPropertyChangeWillBeConsumed(true);
+    }
+    return isDirty;
+}
+
+static std::vector<sk_sp<SkImage>> gPinnedImages;
+static SkBaseMutex gLock;
+
+void SkiaDisplayList::pinImages(GrContext* context) {
+    if (mPinnedImages) return;
+    for (SkImage* image : mMutableImages) {
+        SkImage_pinAsTexture(image, context);
+    }
+    mPinnedImages = true;
+}
+
+void SkiaDisplayList::unpinImages(GrContext* context) {
+    if (!mPinnedImages) return;
+    if (context) {
+        for (SkImage* image : mMutableImages) {
+            SkImage_unpinAsTexture(image, context);
+        }
+    } else {
+        gLock.acquire();
+        for (SkImage* image : mMutableImages) {
+            gPinnedImages.emplace_back(sk_ref_sp(image));
+        }
+        gLock.release();
+    }
+    mPinnedImages = false;
+}
+
+void SkiaDisplayList::cleanupImages(GrContext* context) {
+    gLock.acquire();
+    for (auto& image : gPinnedImages) {
+        SkImage_unpinAsTexture(image.get(), context);
+    }
+    gPinnedImages.clear();
+    gLock.release();
+}
+
+void SkiaDisplayList::reset(GrContext* context, SkRect bounds) {
+    unpinImages(context);
+    SkASSERT(!mPinnedImages);
+    mIsProjectionReceiver = false;
+
+    mDrawable->reset(bounds);
+
+    mMutableImages.clear();
+    mVectorDrawables.clear();
+    mChildFunctors.clear();
+    mChildNodes.clear();
+
+    projectionReceiveIndex = -1;
+    allocator.~LinearAllocator();
+    new (&allocator) LinearAllocator();
+}
+
+}; // namespace uirenderer
+}; // namespace android
diff --git a/libs/hwui/SkiaDisplayList.h b/libs/hwui/SkiaDisplayList.h
new file mode 100644
index 0000000..c8a82bd
--- /dev/null
+++ b/libs/hwui/SkiaDisplayList.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include "DisplayList.h"
+#include "SkiaDrawables.h"
+
+#include <deque>
+#include <SkLiteDL.h>
+#include <SkPictureRecorder.h>
+
+namespace android {
+namespace uirenderer {
+
+/**
+ * This class is intended to be self contained, but still subclasses from
+ * DisplayList to make it easier to support switching between the two at
+ * runtime.  The downside of this inheritance is that we pay for the overhead
+ * of the parent class construction/destruction without any real benefit.
+ */
+class SkiaDisplayList : public DisplayList {
+public:
+    SkiaDisplayList(SkRect bounds);
+    virtual ~SkiaDisplayList() {
+        /* Given that we are using a LinearStdAllocator to store some of the
+         * SkDrawable contents we must ensure that any other object that is
+         * holding a reference to those drawables is destroyed prior to their
+         * deletion.
+         */
+        mDrawable.reset();
+    }
+
+    /**
+     * This resets the DisplayList so that it behaves as if the object were newly
+     * constructed with the provided bounds.  The reuse avoids any overhead
+     * associated with destroying the SkLiteDL as well as the deques and vectors.
+     */
+    void reset(GrContext* context, SkRect bounds);
+
+    /**
+     * Use the linear allocator to create any SkDrawables needed by the display
+     * list. This could be dangerous as these objects are ref-counted, so we
+     * need to monitor that they don't extend beyond the lifetime of the class
+     * that creates them.
+     */
+    template<class T, typename... Params>
+    SkDrawable* allocateDrawable(Params&&... params) {
+        return allocator.create<T>(std::forward<Params>(params)...);
+    }
+
+    bool isSkiaDL() const override { return true; }
+
+    /**
+     * Returns true if the DisplayList does not have any recorded content
+     */
+    bool isEmpty() const override { return mDrawable->empty(); }
+
+    /**
+     * Returns true if this list directly contains a GLFunctor drawing command.
+     */
+    bool hasFunctor() const override { return !mChildFunctors.empty(); }
+
+    /**
+     * Returns true if this list directly contains a VectorDrawable drawing command.
+     */
+    bool hasVectorDrawables() const override { return !mVectorDrawables.empty(); }
+
+    /**
+     * Attempts to reset and reuse this DisplayList.
+     *
+     * @return true if the displayList will be reused and therefore should not be deleted
+     */
+    bool reuseDisplayList(RenderNode* node, renderthread::CanvasContext* context) override;
+
+    /**
+     * ONLY to be called by RenderNode::syncDisplayList so that we can notify any
+     * contained VectorDrawables or GLFunctors to sync their state.
+     *
+     * NOTE: This function can be folded into RenderNode when we no longer need
+     *       to subclass from DisplayList
+     */
+    void syncContents() override;
+
+    /**
+     * ONLY to be called by RenderNode::prepareTree in order to prepare this
+     * list while the UI thread is blocked.  Here we can upload mutable bitmaps
+     * and notify our parent if any of our content has been invalidated and in
+     * need of a redraw.  If the renderNode has any children then they are also
+     * call in order to prepare them.
+     *
+     * @return true if any content change requires the node to be invalidated
+     *
+     * NOTE: This function can be folded into RenderNode when we no longer need
+     *       to subclass from DisplayList
+     */
+
+    bool prepareListAndChildren(TreeInfo& info, bool functorsNeedLayer,
+            std::function<void(RenderNode*, TreeInfo&, bool)> childFn) override;
+
+    /**
+     *  Calls the provided function once for each child of this DisplayList
+     */
+    void updateChildren(std::function<void(RenderNode*)> updateFn) override;
+
+    /**
+     * Pin/Unpin any mutable images to the GPU cache. A pinned images is
+     * guaranteed to be remain in the cache until it has been unpinned which
+     * we leverage to avoid making a CPU copy of the pixels.
+     */
+    void pinImages(GrContext* context);
+    void unpinImages(GrContext* context);
+
+    /**
+     * If a SkiaDisplayList is deleted on the UI thread we cache a list of any
+     * images that need unpinned from the GPU cache and call this function on
+     * a subsequent frame to perform that cleanup.
+     */
+    static void cleanupImages(GrContext* context);
+
+    /**
+     * We use std::deque here because (1) we need to iterate through these
+     * elements and (2) mDrawable holds pointers to the elements, so they cannot
+     * relocate.
+     */
+    std::deque<RenderNodeDrawable> mChildNodes;
+    std::deque<GLFunctorDrawable> mChildFunctors;
+    std::vector<SkImage*> mMutableImages;
+    std::vector<VectorDrawableRoot*> mVectorDrawables;
+    sk_sp<SkLiteDL> mDrawable;
+
+    bool mIsProjectionReceiver = false;
+
+private:
+    bool mPinnedImages = false;
+};
+
+}; // namespace uirenderer
+}; // namespace android
diff --git a/libs/hwui/SkiaDrawables.h b/libs/hwui/SkiaDrawables.h
new file mode 100644
index 0000000..a1ceeaa
--- /dev/null
+++ b/libs/hwui/SkiaDrawables.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+#pragma once
+
+#include "Layer.h"
+#include "RenderNode.h"
+
+#include <SkCanvas.h>
+#include <SkDrawable.h>
+#include <SkMatrix.h>
+
+#include <utils/RefBase.h>
+#include <utils/FatVector.h>
+#include <utils/Functor.h>
+
+namespace android {
+
+class Functor;
+
+namespace uirenderer {
+
+
+class RenderProperties;
+class OffscreenBuffer;
+class GlFunctorLifecycleListener;
+class SkiaDisplayList;
+
+/**
+ * This drawable wraps a RenderNode and enables it to be recorded into a list
+ * of Skia drawing commands.
+ */
+class RenderNodeDrawable : public SkDrawable {
+public:
+    explicit RenderNodeDrawable(RenderNode* node, SkCanvas* canvas)
+            : mRenderNode(node)
+            , mRecordedTransform(canvas->getTotalMatrix()) {}
+
+    /**
+     * The renderNode (and its properties) that is to be drawn
+     */
+    RenderNode* getRenderNode() const { return mRenderNode.get(); }
+
+    /**
+     * Returns the transform on the canvas at time of recording and is used for
+     * computing total transform without rerunning DL contents.
+     */
+    const SkMatrix& getRecordedMatrix() const { return mRecordedTransform; }
+
+protected:
+    virtual SkRect onGetBounds() override {
+        // We don't want to enable a record time quick reject because the properties
+        // of the RenderNode may be updated on subsequent frames.
+        return SkRect::MakeLargest();
+    }
+    virtual void onDraw(SkCanvas* canvas) override { /* TODO */ }
+
+private:
+    sp<RenderNode> mRenderNode;
+    const SkMatrix mRecordedTransform;
+};
+
+/**
+ * This drawable wraps a OpenGL functor enabling it to be recorded into a list
+ * of Skia drawing commands.
+ */
+class GLFunctorDrawable : public SkDrawable {
+public:
+    GLFunctorDrawable(Functor* functor, GlFunctorLifecycleListener* listener, SkCanvas* canvas)
+            : mFunctor(functor)
+            , mListener(listener) {
+        canvas->getClipBounds(&mBounds);
+    }
+    virtual ~GLFunctorDrawable() {}
+
+    void syncFunctor() const { (*mFunctor)(DrawGlInfo::kModeSync, nullptr); }
+
+ protected:
+    virtual SkRect onGetBounds() override { return mBounds; }
+    virtual void onDraw(SkCanvas* canvas) override { /* TODO */ }
+
+ private:
+     Functor* mFunctor;
+     sp<GlFunctorLifecycleListener> mListener;
+     SkRect mBounds;
+};
+
+}; // namespace uirenderer
+}; // namespace android
diff --git a/libs/hwui/SkiaShader.cpp b/libs/hwui/SkiaShader.cpp
index 6f4a683..5d9e5c0 100644
--- a/libs/hwui/SkiaShader.cpp
+++ b/libs/hwui/SkiaShader.cpp
@@ -173,15 +173,16 @@
         outData->gradientSampler = 0;
         outData->gradientTexture = nullptr;
 
-        outData->startColor.set(gradInfo.fColors[0]);
-        outData->endColor.set(gradInfo.fColors[1]);
+        outData->startColor.setSRGB(gradInfo.fColors[0]);
+        outData->endColor.setSRGB(gradInfo.fColors[1]);
     }
 
-    outData->ditherSampler = (*textureUnit)++;
     return true;
 }
 
-void applyGradient(Caches& caches, const SkiaShaderData::GradientShaderData& data) {
+void applyGradient(Caches& caches, const SkiaShaderData::GradientShaderData& data,
+        const GLsizei width, const GLsizei height) {
+
     if (CC_UNLIKELY(data.gradientTexture)) {
         caches.textureState().activateTexture(data.gradientSampler);
         bindTexture(&caches, data.gradientTexture, data.wrapST, data.wrapST);
@@ -191,10 +192,7 @@
         bindUniformColor(caches.program().getUniform("endColor"), data.endColor);
     }
 
-    // TODO: remove sampler slot incrementing from dither.setupProgram,
-    // since this assignment of slots is done at store, not apply time
-    GLuint ditherSampler = data.ditherSampler;
-    caches.dither.setupProgram(caches.program(), &ditherSampler);
+    glUniform2f(caches.program().getUniform("screenSize"), 1.0f / width, 1.0f / height);
     glUniformMatrix4fv(caches.program().getUniform("screenSpace"), 1,
             GL_FALSE, &data.screenSpace.data[0]);
 }
@@ -208,13 +206,7 @@
         return false;
     }
 
-    /*
-     * Bypass the AssetAtlas, since those textures:
-     * 1) require UV mapping, which isn't implemented in matrix computation below
-     * 2) can't handle REPEAT simply
-     * 3) are safe to upload here (outside of sync stage), since they're static
-     */
-    outData->bitmapTexture = caches.textureCache.getAndBypassAtlas(&bitmap);
+    outData->bitmapTexture = caches.textureCache.get(&bitmap);
     if (!outData->bitmapTexture) return false;
 
     outData->bitmapSampler = (*textureUnit)++;
@@ -388,11 +380,12 @@
     outData->skiaShaderType = kNone_SkiaShaderType;
 }
 
-void SkiaShader::apply(Caches& caches, const SkiaShaderData& data) {
+void SkiaShader::apply(Caches& caches, const SkiaShaderData& data,
+        const GLsizei width, const GLsizei height) {
     if (!data.skiaShaderType) return;
 
     if (data.skiaShaderType & kGradient_SkiaShaderType) {
-        applyGradient(caches, data.gradientData);
+        applyGradient(caches, data.gradientData, width, height);
     }
     if (data.skiaShaderType & kBitmap_SkiaShaderType) {
         applyBitmap(caches, data.bitmapData);
diff --git a/libs/hwui/SkiaShader.h b/libs/hwui/SkiaShader.h
index 884196d..5854289 100644
--- a/libs/hwui/SkiaShader.h
+++ b/libs/hwui/SkiaShader.h
@@ -62,7 +62,6 @@
     } bitmapData;
     struct GradientShaderData {
         Matrix4 screenSpace;
-        GLuint ditherSampler;
 
         // simple gradient
         FloatColor startColor;
@@ -72,7 +71,6 @@
         Texture* gradientTexture;
         GLuint gradientSampler;
         GLenum wrapST;
-
     } gradientData;
     struct LayerShaderData {
         Layer* layer;
@@ -90,7 +88,8 @@
     static void store(Caches& caches, const SkShader& shader, const Matrix4& modelViewMatrix,
             GLuint* textureUnit, ProgramDescription* description,
             SkiaShaderData* outData);
-    static void apply(Caches& caches, const SkiaShaderData& data);
+    static void apply(Caches& caches, const SkiaShaderData& data,
+            const GLsizei width, const GLsizei height);
 };
 
 }; // namespace uirenderer
diff --git a/libs/hwui/Texture.cpp b/libs/hwui/Texture.cpp
index 4f49a35..908f572 100644
--- a/libs/hwui/Texture.cpp
+++ b/libs/hwui/Texture.cpp
@@ -26,19 +26,23 @@
 namespace android {
 namespace uirenderer {
 
+// Number of bytes used by a texture in the given format
 static int bytesPerPixel(GLint glFormat) {
     switch (glFormat) {
     // The wrapped-texture case, usually means a SurfaceTexture
     case 0:
         return 0;
+    case GL_LUMINANCE:
     case GL_ALPHA:
         return 1;
+    case GL_SRGB8:
     case GL_RGB:
         return 3;
+    case GL_SRGB8_ALPHA8:
     case GL_RGBA:
         return 4;
     case GL_RGBA16F:
-        return 16;
+        return 8;
     default:
         LOG_ALWAYS_FATAL("UNKNOWN FORMAT %d", glFormat);
     }
@@ -83,14 +87,16 @@
     mId = 0;
 }
 
-bool Texture::updateSize(uint32_t width, uint32_t height, GLint format) {
-    if (mWidth == width && mHeight == height && mFormat == format) {
+bool Texture::updateSize(uint32_t width, uint32_t height, GLint internalFormat, GLint format) {
+    if (mWidth == width && mHeight == height &&
+            mFormat == format && mInternalFormat == internalFormat) {
         return false;
     }
     mWidth = width;
     mHeight = height;
     mFormat = format;
-    notifySizeChanged(mWidth * mHeight * bytesPerPixel(mFormat));
+    mInternalFormat = internalFormat;
+    notifySizeChanged(mWidth * mHeight * bytesPerPixel(internalFormat));
     return true;
 }
 
@@ -101,10 +107,10 @@
     mMagFilter = GL_LINEAR;
 }
 
-void Texture::upload(GLint internalformat, uint32_t width, uint32_t height,
+void Texture::upload(GLint internalFormat, uint32_t width, uint32_t height,
         GLenum format, GLenum type, const void* pixels) {
     GL_CHECKPOINT(MODERATE);
-    bool needsAlloc = updateSize(width, height, internalformat);
+    bool needsAlloc = updateSize(width, height, internalFormat, format);
     if (!mId) {
         glGenTextures(1, &mId);
         needsAlloc = true;
@@ -112,17 +118,17 @@
     }
     mCaches.textureState().bindTexture(GL_TEXTURE_2D, mId);
     if (needsAlloc) {
-        glTexImage2D(GL_TEXTURE_2D, 0, mFormat, mWidth, mHeight, 0,
+        glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0,
                 format, type, pixels);
     } else if (pixels) {
-        glTexSubImage2D(GL_TEXTURE_2D, 0, mFormat, mWidth, mHeight, 0,
+        glTexSubImage2D(GL_TEXTURE_2D, 0, internalFormat, mWidth, mHeight, 0,
                 format, type, pixels);
     }
     GL_CHECKPOINT(MODERATE);
 }
 
-static void uploadToTexture(bool resize, GLenum format, GLenum type, GLsizei stride, GLsizei bpp,
-        GLsizei width, GLsizei height, const GLvoid * data) {
+static void uploadToTexture(bool resize, GLint internalFormat, GLenum format, GLenum type,
+        GLsizei stride, GLsizei bpp, GLsizei width, GLsizei height, const GLvoid * data) {
 
     const bool useStride = stride != width
             && Caches::getInstance().extensions().hasUnpackRowLength();
@@ -132,7 +138,7 @@
         }
 
         if (resize) {
-            glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, data);
+            glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, data);
         } else {
             glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, data);
         }
@@ -156,7 +162,7 @@
         }
 
         if (resize) {
-            glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, type, temp);
+            glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, type, temp);
         } else {
             glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height, format, type, temp);
         }
@@ -166,31 +172,44 @@
 }
 
 static void uploadSkBitmapToTexture(const SkBitmap& bitmap,
-        bool resize, GLenum format, GLenum type) {
-    uploadToTexture(resize, format, type, bitmap.rowBytesAsPixels(), bitmap.bytesPerPixel(),
-            bitmap.width(), bitmap.height(), bitmap.getPixels());
+        bool resize, GLint internalFormat, GLenum format, GLenum type) {
+    uploadToTexture(resize, internalFormat, format, type, bitmap.rowBytesAsPixels(),
+            bitmap.bytesPerPixel(), bitmap.width(), bitmap.height(), bitmap.getPixels());
 }
 
-static void colorTypeToGlFormatAndType(SkColorType colorType,
-        GLint* outFormat, GLint* outType) {
+static void colorTypeToGlFormatAndType(const Caches& caches, SkColorType colorType,
+        bool needSRGB, GLint* outInternalFormat, GLint* outFormat, GLint* outType) {
     switch (colorType) {
     case kAlpha_8_SkColorType:
         *outFormat = GL_ALPHA;
+        *outInternalFormat = GL_ALPHA;
         *outType = GL_UNSIGNED_BYTE;
         break;
     case kRGB_565_SkColorType:
-        *outFormat = GL_RGB;
-        *outType = GL_UNSIGNED_SHORT_5_6_5;
+        if (needSRGB) {
+            // We would ideally use a GL_RGB/GL_SRGB8 texture but the
+            // intermediate Skia bitmap needs to be ARGB_8888
+            *outFormat = GL_RGBA;
+            *outInternalFormat = caches.rgbaInternalFormat();
+            *outType = GL_UNSIGNED_BYTE;
+        } else {
+            *outFormat = GL_RGB;
+            *outInternalFormat = GL_RGB;
+            *outType = GL_UNSIGNED_SHORT_5_6_5;
+        }
         break;
     // ARGB_4444 and Index_8 are both upconverted to RGBA_8888
     case kARGB_4444_SkColorType:
     case kIndex_8_SkColorType:
     case kN32_SkColorType:
         *outFormat = GL_RGBA;
+        *outInternalFormat = caches.rgbaInternalFormat(needSRGB);
         *outType = GL_UNSIGNED_BYTE;
         break;
     case kGray_8_SkColorType:
+        // TODO: Handle sRGB
         *outFormat = GL_LUMINANCE;
+        *outInternalFormat = GL_LUMINANCE;
         *outType = GL_UNSIGNED_BYTE;
         break;
     default:
@@ -224,29 +243,36 @@
         setDefaultParams = true;
     }
 
-    GLint format, type;
-    colorTypeToGlFormatAndType(bitmap.colorType(), &format, &type);
+    sk_sp<SkColorSpace> sRGB = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+    bool needSRGB = bitmap.colorSpace() == sRGB.get();
 
-    if (updateSize(bitmap.width(), bitmap.height(), format)) {
+    GLint internalFormat, format, type;
+    colorTypeToGlFormatAndType(mCaches, bitmap.colorType(), needSRGB, &internalFormat, &format, &type);
+
+    if (updateSize(bitmap.width(), bitmap.height(), internalFormat, format)) {
         needsAlloc = true;
     }
 
     blend = !bitmap.isOpaque();
     mCaches.textureState().bindTexture(mId);
 
+    // TODO: Handle sRGB gray bitmaps
+    bool hasSRGB = mCaches.extensions().hasSRGB();
     if (CC_UNLIKELY(bitmap.colorType() == kARGB_4444_SkColorType
-            || bitmap.colorType() == kIndex_8_SkColorType)) {
+            || bitmap.colorType() == kIndex_8_SkColorType
+            || (bitmap.colorType() == kRGB_565_SkColorType && hasSRGB && needSRGB))) {
+
         SkBitmap rgbaBitmap;
-        rgbaBitmap.allocPixels(SkImageInfo::MakeN32(mWidth, mHeight,
-                bitmap.alphaType()));
+        rgbaBitmap.allocPixels(SkImageInfo::MakeN32(
+                mWidth, mHeight, bitmap.alphaType(), hasSRGB ? sRGB : nullptr));
         rgbaBitmap.eraseColor(0);
 
         SkCanvas canvas(rgbaBitmap);
         canvas.drawBitmap(bitmap, 0.0f, 0.0f, nullptr);
 
-        uploadSkBitmapToTexture(rgbaBitmap, needsAlloc, format, type);
+        uploadSkBitmapToTexture(rgbaBitmap, needsAlloc, internalFormat, format, type);
     } else {
-        uploadSkBitmapToTexture(bitmap, needsAlloc, format, type);
+        uploadSkBitmapToTexture(bitmap, needsAlloc, internalFormat, format, type);
     }
 
     if (canMipMap) {
@@ -262,11 +288,12 @@
     }
 }
 
-void Texture::wrap(GLuint id, uint32_t width, uint32_t height, GLint format) {
+void Texture::wrap(GLuint id, uint32_t width, uint32_t height, GLint internalFormat, GLint format) {
     mId = id;
     mWidth = width;
     mHeight = height;
     mFormat = format;
+    mInternalFormat = internalFormat;
     // We're wrapping an existing texture, so don't double count this memory
     notifySizeChanged(0);
 }
diff --git a/libs/hwui/Texture.h b/libs/hwui/Texture.h
index b72742f..aa8a6d3 100644
--- a/libs/hwui/Texture.h
+++ b/libs/hwui/Texture.h
@@ -69,8 +69,8 @@
      *
      * The image data is undefined after calling this.
      */
-    void resize(uint32_t width, uint32_t height, GLint format) {
-        upload(format, width, height, format, GL_UNSIGNED_BYTE, nullptr);
+    void resize(uint32_t width, uint32_t height, GLint internalFormat, GLint format) {
+        upload(internalFormat, width, height, format, GL_UNSIGNED_BYTE, nullptr);
     }
 
     /**
@@ -85,13 +85,13 @@
     /**
      * Basically glTexImage2D/glTexSubImage2D.
      */
-    void upload(GLint internalformat, uint32_t width, uint32_t height,
+    void upload(GLint internalFormat, uint32_t width, uint32_t height,
             GLenum format, GLenum type, const void* pixels);
 
     /**
      * Wraps an existing texture.
      */
-    void wrap(GLuint id, uint32_t width, uint32_t height, GLint format);
+    void wrap(GLuint id, uint32_t width, uint32_t height, GLint internalFormat, GLint format);
 
     GLuint id() const {
         return mId;
@@ -109,6 +109,10 @@
         return mFormat;
     }
 
+    GLint internalFormat() const {
+        return mInternalFormat;
+    }
+
     /**
      * Generation of the backing bitmap,
      */
@@ -148,13 +152,14 @@
     friend class Layer;
 
     // Returns true if the size changed, false if it was the same
-    bool updateSize(uint32_t width, uint32_t height, GLint format);
+    bool updateSize(uint32_t width, uint32_t height, GLint internalFormat, GLint format);
     void resetCachedParams();
 
     GLuint mId = 0;
     uint32_t mWidth = 0;
     uint32_t mHeight = 0;
     GLint mFormat = 0;
+    GLint mInternalFormat = 0;
 
     /* See GLES spec section 3.8.14
      * "In the initial state, the value assigned to TEXTURE_MIN_FILTER is
diff --git a/libs/hwui/TextureCache.cpp b/libs/hwui/TextureCache.cpp
index 523924a..5ccdbda 100644
--- a/libs/hwui/TextureCache.cpp
+++ b/libs/hwui/TextureCache.cpp
@@ -18,7 +18,6 @@
 
 #include <utils/Mutex.h>
 
-#include "AssetAtlas.h"
 #include "Caches.h"
 #include "Texture.h"
 #include "TextureCache.h"
@@ -36,8 +35,7 @@
         : mCache(LruCache<uint32_t, Texture*>::kUnlimitedCapacity)
         , mSize(0)
         , mMaxSize(Properties::textureCacheSize)
-        , mFlushRate(Properties::textureCacheFlushRate)
-        , mAssetAtlas(nullptr) {
+        , mFlushRate(Properties::textureCacheFlushRate) {
     mCache.setOnEntryRemovedListener(this);
 
     glGetIntegerv(GL_MAX_TEXTURE_SIZE, &mMaxTextureSize);
@@ -84,10 +82,6 @@
 // Caching
 ///////////////////////////////////////////////////////////////////////////////
 
-void TextureCache::setAssetAtlas(AssetAtlas* assetAtlas) {
-    mAssetAtlas = assetAtlas;
-}
-
 void TextureCache::resetMarkInUse(void* ownerToken) {
     LruCache<uint32_t, Texture*>::Iterator iter(mCache);
     while (iter.next()) {
@@ -108,14 +102,7 @@
 
 // Returns a prepared Texture* that either is already in the cache or can fit
 // in the cache (and is thus added to the cache)
-Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap, AtlasUsageType atlasUsageType) {
-    if (CC_LIKELY(mAssetAtlas != nullptr) && atlasUsageType == AtlasUsageType::Use) {
-        AssetAtlas::Entry* entry = mAssetAtlas->getEntry(bitmap->pixelRef());
-        if (CC_UNLIKELY(entry)) {
-            return entry->texture;
-        }
-    }
-
+Texture* TextureCache::getCachedTexture(const SkBitmap* bitmap) {
     Texture* texture = mCache.get(bitmap->pixelRef()->getStableID());
 
     if (!texture) {
@@ -160,7 +147,7 @@
 }
 
 bool TextureCache::prefetchAndMarkInUse(void* ownerToken, const SkBitmap* bitmap) {
-    Texture* texture = getCachedTexture(bitmap, AtlasUsageType::Use);
+    Texture* texture = getCachedTexture(bitmap);
     if (texture) {
         texture->isInUse = ownerToken;
     }
@@ -168,11 +155,11 @@
 }
 
 bool TextureCache::prefetch(const SkBitmap* bitmap) {
-    return getCachedTexture(bitmap, AtlasUsageType::Use);
+    return getCachedTexture(bitmap);
 }
 
-Texture* TextureCache::get(const SkBitmap* bitmap, AtlasUsageType atlasUsageType) {
-    Texture* texture = getCachedTexture(bitmap, atlasUsageType);
+Texture* TextureCache::get(const SkBitmap* bitmap) {
+    Texture* texture = getCachedTexture(bitmap);
 
     if (!texture) {
         if (!canMakeTextureFromBitmap(bitmap)) {
diff --git a/libs/hwui/TextureCache.h b/libs/hwui/TextureCache.h
index 0a61b6b..88ef771 100644
--- a/libs/hwui/TextureCache.h
+++ b/libs/hwui/TextureCache.h
@@ -47,8 +47,6 @@
 // Classes
 ///////////////////////////////////////////////////////////////////////////////
 
-class AssetAtlas;
-
 /**
  * A simple LRU texture cache. The cache has a maximum size expressed in bytes.
  * Any texture added to the cache causing the cache to grow beyond the maximum
@@ -85,20 +83,10 @@
     bool prefetch(const SkBitmap* bitmap);
 
     /**
-     * Returns the texture associated with the specified bitmap from either within the cache, or
-     * the AssetAtlas. If the texture cannot be found in the cache, a new texture is generated.
+     * Returns the texture associated with the specified bitmap from within the cache.
+     * If the texture cannot be found in the cache, a new texture is generated.
      */
-    Texture* get(const SkBitmap* bitmap) {
-        return get(bitmap, AtlasUsageType::Use);
-    }
-
-    /**
-     * Returns the texture associated with the specified bitmap. If the texture cannot be found in
-     * the cache, a new texture is generated, even if it resides in the AssetAtlas.
-     */
-    Texture* getAndBypassAtlas(const SkBitmap* bitmap) {
-        return get(bitmap, AtlasUsageType::Bypass);
-    }
+    Texture* get(const SkBitmap* bitmap);
 
     /**
      * Removes the texture associated with the specified pixelRef. This is meant
@@ -130,18 +118,10 @@
      */
     void flush();
 
-    void setAssetAtlas(AssetAtlas* assetAtlas);
-
 private:
-    enum class AtlasUsageType {
-        Use,
-        Bypass,
-    };
-
     bool canMakeTextureFromBitmap(const SkBitmap* bitmap);
 
-    Texture* get(const SkBitmap* bitmap, AtlasUsageType atlasUsageType);
-    Texture* getCachedTexture(const SkBitmap* bitmap, AtlasUsageType atlasUsageType);
+    Texture* getCachedTexture(const SkBitmap* bitmap);
 
     LruCache<uint32_t, Texture*> mCache;
 
@@ -155,8 +135,6 @@
 
     std::vector<uint32_t> mGarbage;
     mutable Mutex mLock;
-
-    AssetAtlas* mAssetAtlas;
 }; // class TextureCache
 
 }; // namespace uirenderer
diff --git a/libs/hwui/VectorDrawable.cpp b/libs/hwui/VectorDrawable.cpp
index 2b79941..a2f3cb6 100644
--- a/libs/hwui/VectorDrawable.cpp
+++ b/libs/hwui/VectorDrawable.cpp
@@ -202,7 +202,9 @@
     if (properties.getFillGradient() != nullptr) {
         paint.setColor(applyAlpha(SK_ColorBLACK, properties.getFillAlpha()));
         SkShader* newShader = properties.getFillGradient()->newWithLocalMatrix(matrix);
-        paint.setShader(newShader);
+        // newWithLocalMatrix(...) creates a new SkShader and returns a bare pointer. We need to
+        // remove the extra ref so that the ref count is correctly managed.
+        paint.setShader(newShader)->unref();
         needsFill = true;
     } else if (properties.getFillColor() != SK_ColorTRANSPARENT) {
         paint.setColor(applyAlpha(properties.getFillColor(), properties.getFillAlpha()));
@@ -222,7 +224,9 @@
     if (properties.getStrokeGradient() != nullptr) {
         paint.setColor(applyAlpha(SK_ColorBLACK, properties.getStrokeAlpha()));
         SkShader* newShader = properties.getStrokeGradient()->newWithLocalMatrix(matrix);
-        paint.setShader(newShader);
+        // newWithLocalMatrix(...) creates a new SkShader and returns a bare pointer. We need to
+        // remove the extra ref so that the ref count is correctly managed.
+        paint.setShader(newShader)->unref();
         needsStroke = true;
     } else if (properties.getStrokeColor() != SK_ColorTRANSPARENT) {
         paint.setColor(applyAlpha(properties.getStrokeColor(), properties.getStrokeAlpha()));
@@ -561,8 +565,12 @@
 
 bool Tree::allocateBitmapIfNeeded(SkBitmap* outCache, int width, int height) {
     if (!canReuseBitmap(*outCache, width, height)) {
-        SkImageInfo info = SkImageInfo::Make(width, height,
-                kN32_SkColorType, kPremul_SkAlphaType);
+#ifndef ANDROID_ENABLE_LINEAR_BLENDING
+        sk_sp<SkColorSpace> colorSpace = nullptr;
+#else
+        sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+#endif
+        SkImageInfo info = SkImageInfo::MakeN32(width, height, kPremul_SkAlphaType, colorSpace);
         outCache->setInfo(info);
         // TODO: Count the bitmap cache against app's java heap
         outCache->allocPixels(info);
diff --git a/libs/hwui/Vertex.h b/libs/hwui/Vertex.h
index c1bf980..db982ad 100644
--- a/libs/hwui/Vertex.h
+++ b/libs/hwui/Vertex.h
@@ -19,6 +19,7 @@
 
 #include "Vector.h"
 
+#include "FloatColor.h"
 #include "utils/Macros.h"
 
 namespace android {
@@ -76,21 +77,19 @@
 REQUIRE_COMPATIBLE_LAYOUT(TextureVertex);
 
 /**
- * Simple structure to describe a vertex with a position, texture UV and ARGB color.
+ * Simple structure to describe a vertex with a position, texture UV and an
+ * sRGB color with alpha. The color is stored pre-multiplied in linear space.
  */
 struct ColorTextureVertex {
     float x, y;
     float u, v;
-    float r, g, b, a;
+    float r, g, b, a; // pre-multiplied linear
 
     static inline void set(ColorTextureVertex* vertex, float x, float y,
-            float u, float v, int color) {
-
-        float a =     ((color >> 24) & 0xff) / 255.0f;
-        float r = a * ((color >> 16) & 0xff) / 255.0f;
-        float g = a * ((color >>  8) & 0xff) / 255.0f;
-        float b = a * ((color) & 0xff) / 255.0f;
-        *vertex = { x, y, u, v, r, g, b, a };
+            float u, float v, uint32_t color) {
+        FloatColor c;
+        c.set(color);
+        *vertex = { x, y, u, v, c.r, c.g, c.b, c.a };
     }
 }; // struct ColorTextureVertex
 
diff --git a/libs/hwui/font/CacheTexture.cpp b/libs/hwui/font/CacheTexture.cpp
index 49e9f65..e2844ad 100644
--- a/libs/hwui/font/CacheTexture.cpp
+++ b/libs/hwui/font/CacheTexture.cpp
@@ -180,7 +180,12 @@
         mPixelBuffer = PixelBuffer::create(mFormat, getWidth(), getHeight());
     }
 
-    mTexture.resize(mWidth, mHeight, mFormat);
+    GLint internalFormat = mFormat;
+    if (mFormat == GL_RGBA) {
+        internalFormat = mCaches.rgbaInternalFormat();
+    }
+
+    mTexture.resize(mWidth, mHeight, internalFormat, mFormat);
     mTexture.setFilter(getLinearFiltering() ? GL_LINEAR : GL_NEAREST);
     mTexture.setWrap(GL_CLAMP_TO_EDGE);
 }
diff --git a/libs/hwui/renderstate/OffscreenBufferPool.cpp b/libs/hwui/renderstate/OffscreenBufferPool.cpp
index 10a26e0..a9bbb27 100644
--- a/libs/hwui/renderstate/OffscreenBufferPool.cpp
+++ b/libs/hwui/renderstate/OffscreenBufferPool.cpp
@@ -22,6 +22,7 @@
 #include "utils/FatVector.h"
 #include "utils/TraceUtils.h"
 
+#include <utils/Color.h>
 #include <utils/Log.h>
 
 #include <GLES2/gl2.h>
@@ -44,7 +45,7 @@
     uint32_t height = computeIdealDimension(viewportHeight);
     ATRACE_FORMAT("Allocate %ux%u HW Layer", width, height);
     caches.textureState().activateTexture(0);
-    texture.resize(width, height, GL_RGBA);
+    texture.resize(width, height, caches.rgbaInternalFormat(), GL_RGBA);
     texture.blend = true;
     texture.setWrap(GL_CLAMP_TO_EDGE);
     // not setting filter on texture, since it's set when drawing, based on transform
diff --git a/libs/hwui/renderstate/RenderState.cpp b/libs/hwui/renderstate/RenderState.cpp
index ee4619d..84ab3f3 100644
--- a/libs/hwui/renderstate/RenderState.cpp
+++ b/libs/hwui/renderstate/RenderState.cpp
@@ -52,7 +52,6 @@
         mCaches = &Caches::createInstance(*this);
     }
     mCaches->init();
-    mCaches->textureCache.setAssetAtlas(&mAssetAtlas);
 }
 
 static void layerLostGlContext(Layer* layer) {
@@ -64,7 +63,6 @@
 
     // TODO: reset all cached state in state objects
     std::for_each(mActiveLayers.begin(), mActiveLayers.end(), layerLostGlContext);
-    mAssetAtlas.terminate();
 
     mCaches->terminate();
 
@@ -147,9 +145,17 @@
     meshState().resetVertexPointers();
     meshState().disableTexCoordsVertexArray();
     debugOverdraw(false, false);
+    // TODO: We need a way to know whether the functor is sRGB aware (b/32072673)
+    if (mCaches->extensions().hasSRGBWriteControl()) {
+        glDisable(GL_FRAMEBUFFER_SRGB_EXT);
+    }
 }
 
 void RenderState::resumeFromFunctorInvoke() {
+    if (mCaches->extensions().hasSRGBWriteControl()) {
+        glEnable(GL_FRAMEBUFFER_SRGB_EXT);
+    }
+
     glViewport(0, 0, mViewportWidth, mViewportHeight);
     glBindFramebuffer(GL_FRAMEBUFFER, mFramebuffer);
     debugOverdraw(false, false);
@@ -308,7 +314,7 @@
         glVertexAttribPointer(alphaLocation, 1, GL_FLOAT, GL_FALSE, vertices.stride, alphaCoords);
     }
     // Shader uniforms
-    SkiaShader::apply(*mCaches, fill.skiaShaderData);
+    SkiaShader::apply(*mCaches, fill.skiaShaderData, mViewportWidth, mViewportHeight);
 
     GL_CHECKPOINT(MODERATE);
     Texture* texture = (fill.skiaShaderData.skiaShaderType & kBitmap_SkiaShaderType) ?
diff --git a/libs/hwui/renderstate/RenderState.h b/libs/hwui/renderstate/RenderState.h
index 9e0fb12..3d119dc 100644
--- a/libs/hwui/renderstate/RenderState.h
+++ b/libs/hwui/renderstate/RenderState.h
@@ -16,7 +16,6 @@
 #ifndef RENDERSTATE_H
 #define RENDERSTATE_H
 
-#include "AssetAtlas.h"
 #include "Caches.h"
 #include "Glop.h"
 #include "renderstate/Blend.h"
@@ -92,7 +91,6 @@
 
     void render(const Glop& glop, const Matrix4& orthoMatrix);
 
-    AssetAtlas& assetAtlas() { return mAssetAtlas; }
     Blend& blend() { return *mBlend; }
     MeshState& meshState() { return *mMeshState; }
     Scissor& scissor() { return *mScissor; }
@@ -120,7 +118,6 @@
 
     OffscreenBufferPool mLayerPool;
 
-    AssetAtlas mAssetAtlas;
     std::set<Layer*> mActiveLayers;
     std::set<renderthread::CanvasContext*> mRegisteredContexts;
 
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 0f2d55b..fe0f56a 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -545,11 +545,6 @@
     return mRenderPipeline->createTextureLayer();
 }
 
-void CanvasContext::setTextureAtlas(RenderThread& thread,
-        const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize) {
-    thread.eglManager().setTextureAtlas(buffer, map, mapSize);
-}
-
 void CanvasContext::dumpFrames(int fd) {
     FILE* file = fdopen(fd, "a");
     fprintf(file, "\n\n---PROFILEDATA---\n");
diff --git a/libs/hwui/renderthread/CanvasContext.h b/libs/hwui/renderthread/CanvasContext.h
index 652cddd..559ac87 100644
--- a/libs/hwui/renderthread/CanvasContext.h
+++ b/libs/hwui/renderthread/CanvasContext.h
@@ -85,6 +85,12 @@
      */
     static void destroyLayer(RenderNode* node);
 
+    /*
+     * If Properties::isSkiaEnabled() is true then this will return the Skia
+     * grContext associated with the current RenderPipeline.
+     */
+    GrContext* getGrContext() const { return mRenderPipeline->getGrContext(); }
+
     // Won't take effect until next EGLSurface creation
     void setSwapBehavior(SwapBehavior swapBehavior);
 
@@ -119,9 +125,6 @@
 
     DeferredLayerUpdater* createTextureLayer();
 
-    ANDROID_API static void setTextureAtlas(RenderThread& thread,
-            const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize);
-
     void stopDrawing();
     void notifyFramePending();
 
diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp
index 86731c9..beda045 100644
--- a/libs/hwui/renderthread/EglManager.cpp
+++ b/libs/hwui/renderthread/EglManager.cpp
@@ -91,9 +91,7 @@
         , mEglConfig(nullptr)
         , mEglContext(EGL_NO_CONTEXT)
         , mPBufferSurface(EGL_NO_SURFACE)
-        , mCurrentSurface(EGL_NO_SURFACE)
-        , mAtlasMap(nullptr)
-        , mAtlasMapSize(0) {
+        , mCurrentSurface(EGL_NO_SURFACE) {
 }
 
 void EglManager::initialize() {
@@ -128,7 +126,6 @@
     makeCurrent(mPBufferSurface);
     DeviceInfo::initialize();
     mRenderThread.renderState().onGLContextCreated();
-    initAtlas();
 }
 
 void EglManager::initExtensions() {
@@ -191,32 +188,6 @@
         "Failed to create context, error = %s", egl_error_str());
 }
 
-void EglManager::setTextureAtlas(const sp<GraphicBuffer>& buffer,
-        int64_t* map, size_t mapSize) {
-
-    // Already initialized
-    if (mAtlasBuffer.get()) {
-        ALOGW("Multiple calls to setTextureAtlas!");
-        delete map;
-        return;
-    }
-
-    mAtlasBuffer = buffer;
-    mAtlasMap = map;
-    mAtlasMapSize = mapSize;
-
-    if (hasEglContext()) {
-        initAtlas();
-    }
-}
-
-void EglManager::initAtlas() {
-    if (mAtlasBuffer.get()) {
-        mRenderThread.renderState().assetAtlas().init(mAtlasBuffer,
-                mAtlasMap, mAtlasMapSize);
-    }
-}
-
 void EglManager::createPBufferSurface() {
     LOG_ALWAYS_FATAL_IF(mEglDisplay == EGL_NO_DISPLAY,
             "usePBufferSurface() called on uninitialized GlobalContext!");
@@ -229,7 +200,16 @@
 
 EGLSurface EglManager::createSurface(EGLNativeWindowType window) {
     initialize();
-    EGLSurface surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, window, nullptr);
+
+    EGLint attribs[] = {
+#ifdef ANDROID_ENABLE_LINEAR_BLENDING
+            EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_SRGB_KHR,
+            EGL_COLORSPACE, EGL_COLORSPACE_sRGB,
+#endif
+            EGL_NONE
+    };
+
+    EGLSurface surface = eglCreateWindowSurface(mEglDisplay, mEglConfig, window, attribs);
     LOG_ALWAYS_FATAL_IF(surface == EGL_NO_SURFACE,
             "Failed to create EGLSurface for window %p, eglErr = %s",
             (void*) window, egl_error_str());
diff --git a/libs/hwui/renderthread/EglManager.h b/libs/hwui/renderthread/EglManager.h
index 41047fe..ba4a3e1 100644
--- a/libs/hwui/renderthread/EglManager.h
+++ b/libs/hwui/renderthread/EglManager.h
@@ -79,8 +79,6 @@
     // Returns true iff the surface is now preserving buffers.
     bool setPreserveBuffer(EGLSurface surface, bool preserve);
 
-    void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t mapSize);
-
     void fence();
 
 private:
@@ -94,7 +92,6 @@
     void createPBufferSurface();
     void loadConfig();
     void createContext();
-    void initAtlas();
     EGLint queryBufferAge(EGLSurface surface);
 
     RenderThread& mRenderThread;
@@ -106,10 +103,6 @@
 
     EGLSurface mCurrentSurface;
 
-    sp<GraphicBuffer> mAtlasBuffer;
-    int64_t* mAtlasMap;
-    size_t mAtlasMapSize;
-
     enum class SwapBehavior {
         Discard,
         Preserved,
diff --git a/libs/hwui/renderthread/IRenderPipeline.h b/libs/hwui/renderthread/IRenderPipeline.h
index 97cdf7f..f96c2fd 100644
--- a/libs/hwui/renderthread/IRenderPipeline.h
+++ b/libs/hwui/renderthread/IRenderPipeline.h
@@ -22,6 +22,8 @@
 #include <SkRect.h>
 #include <utils/RefBase.h>
 
+class GrContext;
+
 namespace android {
 
 class Surface;
@@ -43,6 +45,8 @@
     Succeeded
 };
 
+class Frame;
+
 class IRenderPipeline {
 public:
     virtual MakeCurrentResult makeCurrent() = 0;
@@ -69,6 +73,7 @@
     virtual TaskManager* getTaskManager() = 0;
     virtual bool createOrUpdateLayer(RenderNode* node,
             const DamageAccumulator& damageAccumulator) = 0;
+    virtual GrContext* getGrContext() = 0;
 
     virtual ~IRenderPipeline() {}
 };
diff --git a/libs/hwui/renderthread/OpenGLPipeline.h b/libs/hwui/renderthread/OpenGLPipeline.h
index 34d9bc0..d024aec 100644
--- a/libs/hwui/renderthread/OpenGLPipeline.h
+++ b/libs/hwui/renderthread/OpenGLPipeline.h
@@ -26,9 +26,6 @@
 namespace uirenderer {
 namespace renderthread {
 
-class Frame;
-
-
 class OpenGLPipeline : public IRenderPipeline {
 public:
     OpenGLPipeline(RenderThread& thread);
@@ -59,6 +56,7 @@
     bool createOrUpdateLayer(RenderNode* node,
             const DamageAccumulator& damageAccumulator) override;
     static void destroyLayer(RenderNode* node);
+    GrContext* getGrContext() override { return nullptr; }
 
 private:
     EglManager& mEglManager;
diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp
index dcbc980..c2ed864 100644
--- a/libs/hwui/renderthread/RenderProxy.cpp
+++ b/libs/hwui/renderthread/RenderProxy.cpp
@@ -480,23 +480,6 @@
     staticPostAndWait(task);
 }
 
-CREATE_BRIDGE4(setTextureAtlas, RenderThread* thread, GraphicBuffer* buffer, int64_t* map,
-               size_t size) {
-    CanvasContext::setTextureAtlas(*args->thread, args->buffer, args->map, args->size);
-    args->buffer->decStrong(nullptr);
-    return nullptr;
-}
-
-void RenderProxy::setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size) {
-    SETUP_TASK(setTextureAtlas);
-    args->thread = &mRenderThread;
-    args->buffer = buffer.get();
-    args->buffer->incStrong(nullptr);
-    args->map = map;
-    args->size = size;
-    post(task);
-}
-
 CREATE_BRIDGE2(setProcessStatsBuffer, RenderThread* thread, int fd) {
     args->thread->jankTracker().switchStorageToAshmem(args->fd);
     close(args->fd);
diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h
index d4aaea6..50a6f64 100644
--- a/libs/hwui/renderthread/RenderProxy.h
+++ b/libs/hwui/renderthread/RenderProxy.h
@@ -112,7 +112,6 @@
     uint32_t frameTimePercentile(int p);
     ANDROID_API static void dumpGraphicsMemory(int fd);
 
-    ANDROID_API void setTextureAtlas(const sp<GraphicBuffer>& buffer, int64_t* map, size_t size);
     ANDROID_API void setProcessStatsBuffer(int fd);
     ANDROID_API int getRenderThreadTid();
 
diff --git a/libs/hwui/tests/common/TestUtils.h b/libs/hwui/tests/common/TestUtils.h
index 78e9bc4..51c0a05 100644
--- a/libs/hwui/tests/common/TestUtils.h
+++ b/libs/hwui/tests/common/TestUtils.h
@@ -124,8 +124,9 @@
     static SkBitmap createSkBitmap(int width, int height,
             SkColorType colorType = kN32_SkColorType) {
         SkBitmap bitmap;
+        sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
         SkImageInfo info = SkImageInfo::Make(width, height,
-                colorType, kPremul_SkAlphaType);
+                colorType, kPremul_SkAlphaType, colorSpace);
         bitmap.setInfo(info);
         bitmap.allocPixels(info);
         return bitmap;
diff --git a/libs/hwui/tests/unit/RenderNodeTests.cpp b/libs/hwui/tests/unit/RenderNodeTests.cpp
index 0d90afa..39c7f32 100644
--- a/libs/hwui/tests/unit/RenderNodeTests.cpp
+++ b/libs/hwui/tests/unit/RenderNodeTests.cpp
@@ -160,7 +160,7 @@
 
     // Check that the VD is in the dislay list, and the layer update queue contains the correct
     // damage rect.
-    EXPECT_FALSE(rootNode->getDisplayList()->getVectorDrawables().empty());
+    EXPECT_TRUE(rootNode->getDisplayList()->hasVectorDrawables());
     EXPECT_FALSE(info.layerUpdateQueue->entries().empty());
     EXPECT_EQ(rootNode.get(), info.layerUpdateQueue->entries().at(0).renderNode);
     EXPECT_EQ(uirenderer::Rect(0, 0, 200, 400), info.layerUpdateQueue->entries().at(0).damage);
diff --git a/libs/hwui/tests/unit/SkiaBehaviorTests.cpp b/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
index a30ada0..5cab04d 100644
--- a/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
+++ b/libs/hwui/tests/unit/SkiaBehaviorTests.cpp
@@ -18,6 +18,7 @@
 
 #include <gtest/gtest.h>
 #include <SkColorMatrixFilter.h>
+#include <SkColorSpace.h>
 #include <SkImagePriv.h>
 #include <SkShader.h>
 
@@ -82,3 +83,9 @@
     paint.setXfermodeMode(SkXfermode::kOverlay_Mode);
     ASSERT_EQ(expected, paint.getXfermode());
 }
+
+TEST(SkiaBehavior, srgbColorSpaceIsSingleton) {
+    sk_sp<SkColorSpace> sRGB1 = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+    sk_sp<SkColorSpace> sRGB2 = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+    ASSERT_EQ(sRGB1.get(), sRGB2.get());
+}
diff --git a/libs/hwui/tests/unit/SkiaDisplayListTests.cpp b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
new file mode 100644
index 0000000..7f622eb
--- /dev/null
+++ b/libs/hwui/tests/unit/SkiaDisplayListTests.cpp
@@ -0,0 +1,189 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <gtest/gtest.h>
+#include <VectorDrawable.h>
+
+#include "AnimationContext.h"
+#include "DamageAccumulator.h"
+#include "IContextFactory.h"
+#include "SkiaDisplayList.h"
+#include "renderthread/CanvasContext.h"
+#include "tests/common/TestUtils.h"
+
+
+using namespace android;
+using namespace android::uirenderer;
+using namespace android::uirenderer::renderthread;
+
+TEST(SkiaDisplayList, create) {
+    SkRect bounds = SkRect::MakeWH(200, 200);
+    SkiaDisplayList skiaDL(bounds);
+    ASSERT_TRUE(skiaDL.isEmpty());
+    ASSERT_FALSE(skiaDL.mIsProjectionReceiver);
+    ASSERT_EQ(skiaDL.mDrawable->getBounds(), bounds);
+}
+
+TEST(SkiaDisplayList, reset) {
+    SkRect bounds = SkRect::MakeWH(200, 200);
+    SkiaDisplayList skiaDL(bounds);
+
+    SkCanvas dummyCanvas;
+    skiaDL.mChildNodes.emplace_back(nullptr, &dummyCanvas);
+    skiaDL.mChildFunctors.emplace_back(nullptr, nullptr, &dummyCanvas);
+    skiaDL.mMutableImages.push_back(nullptr);
+    skiaDL.mVectorDrawables.push_back(nullptr);
+    skiaDL.mDrawable->drawAnnotation(bounds, "testAnnotation", nullptr);
+    skiaDL.mIsProjectionReceiver = true;
+
+    ASSERT_EQ(skiaDL.mDrawable->getBounds(), bounds);
+    ASSERT_FALSE(skiaDL.mChildNodes.empty());
+    ASSERT_FALSE(skiaDL.mChildFunctors.empty());
+    ASSERT_FALSE(skiaDL.mMutableImages.empty());
+    ASSERT_FALSE(skiaDL.mVectorDrawables.empty());
+    ASSERT_FALSE(skiaDL.isEmpty());
+    ASSERT_TRUE(skiaDL.mIsProjectionReceiver);
+
+    bounds = SkRect::MakeWH(100, 100);
+    skiaDL.reset(nullptr, bounds);
+
+    ASSERT_EQ(skiaDL.mDrawable->getBounds(), bounds);
+    ASSERT_TRUE(skiaDL.mChildNodes.empty());
+    ASSERT_TRUE(skiaDL.mChildFunctors.empty());
+    ASSERT_TRUE(skiaDL.mMutableImages.empty());
+    ASSERT_TRUE(skiaDL.mVectorDrawables.empty());
+    ASSERT_TRUE(skiaDL.isEmpty());
+    ASSERT_FALSE(skiaDL.mIsProjectionReceiver);
+}
+
+TEST(SkiaDisplayList, reuseDisplayList) {
+    sp<RenderNode> renderNode = new RenderNode();
+    std::unique_ptr<SkiaDisplayList> availableList;
+
+    // no list has been attached so it should return a nullptr
+    availableList = renderNode->detachAvailableList();
+    ASSERT_EQ(availableList.get(), nullptr);
+
+    // attach a displayList for reuse
+    SkiaDisplayList skiaDL(SkRect::MakeWH(200, 200));
+    ASSERT_TRUE(skiaDL.reuseDisplayList(renderNode.get(), nullptr));
+
+    // detach the list that you just attempted to reuse
+    availableList = renderNode->detachAvailableList();
+    ASSERT_EQ(availableList.get(), &skiaDL);
+    availableList.release(); // prevents an invalid free since our DL is stack allocated
+
+    // after detaching there should return no available list
+    availableList = renderNode->detachAvailableList();
+    ASSERT_EQ(availableList.get(), nullptr);
+}
+
+class TestFunctor : public Functor {
+public:
+    bool didSync = false;
+
+    virtual status_t operator ()(int what, void* data) {
+        if (what == DrawGlInfo::kModeSync) { didSync = true; }
+        return DrawGlInfo::kStatusDone;
+    }
+};
+
+TEST(SkiaDisplayList, syncContexts) {
+    SkRect bounds = SkRect::MakeWH(200, 200);
+    SkiaDisplayList skiaDL(bounds);
+
+    SkCanvas dummyCanvas;
+    TestFunctor functor;
+    skiaDL.mChildFunctors.emplace_back(&functor, nullptr, &dummyCanvas);
+
+    VectorDrawableRoot vectorDrawable(new VectorDrawable::Group());
+    vectorDrawable.mutateStagingProperties()->setBounds(bounds);
+    skiaDL.mVectorDrawables.push_back(&vectorDrawable);
+
+    // ensure that the functor and vectorDrawable are properly synced
+    skiaDL.syncContents();
+
+    ASSERT_TRUE(functor.didSync);
+    ASSERT_EQ(vectorDrawable.mutateProperties()->getBounds(), bounds);
+}
+
+class ContextFactory : public IContextFactory {
+public:
+    virtual AnimationContext* createAnimationContext(renderthread::TimeLord& clock) override {
+        return new AnimationContext(clock);
+    }
+};
+
+RENDERTHREAD_TEST(SkiaDisplayList, prepareListAndChildren) {
+    auto rootNode = TestUtils::createNode(0, 0, 200, 400, nullptr);
+    ContextFactory contextFactory;
+    std::unique_ptr<CanvasContext> canvasContext(CanvasContext::create(
+            renderThread, false, rootNode.get(), &contextFactory));
+    TreeInfo info(TreeInfo::MODE_FULL, *canvasContext.get());
+    DamageAccumulator damageAccumulator;
+    info.damageAccumulator = &damageAccumulator;
+    info.observer = nullptr;
+
+    SkiaDisplayList skiaDL(SkRect::MakeWH(200, 200));
+
+    // prepare with a clean VD
+    VectorDrawableRoot cleanVD(new VectorDrawable::Group());
+    skiaDL.mVectorDrawables.push_back(&cleanVD);
+    cleanVD.getBitmapUpdateIfDirty(); // this clears the dirty bit
+
+    ASSERT_FALSE(cleanVD.isDirty());
+    ASSERT_FALSE(cleanVD.getPropertyChangeWillBeConsumed());
+    ASSERT_FALSE(skiaDL.prepareListAndChildren(info, false, [](RenderNode*, TreeInfo&, bool) {}));
+    ASSERT_TRUE(cleanVD.getPropertyChangeWillBeConsumed());
+
+    // prepare again this time adding a dirty VD
+    VectorDrawableRoot dirtyVD(new VectorDrawable::Group());
+    skiaDL.mVectorDrawables.push_back(&dirtyVD);
+
+    ASSERT_TRUE(dirtyVD.isDirty());
+    ASSERT_FALSE(dirtyVD.getPropertyChangeWillBeConsumed());
+    ASSERT_TRUE(skiaDL.prepareListAndChildren(info, false, [](RenderNode*, TreeInfo&, bool) {}));
+    ASSERT_TRUE(dirtyVD.getPropertyChangeWillBeConsumed());
+
+    // prepare again this time adding a RenderNode and a callback
+    sp<RenderNode> renderNode = new RenderNode();
+    TreeInfo* infoPtr = &info;
+    SkCanvas dummyCanvas;
+    skiaDL.mChildNodes.emplace_back(renderNode.get(), &dummyCanvas);
+    bool hasRun = false;
+    ASSERT_TRUE(skiaDL.prepareListAndChildren(info, false,
+            [&hasRun, renderNode, infoPtr](RenderNode* n, TreeInfo& i, bool r) {
+        hasRun = true;
+        ASSERT_EQ(renderNode.get(), n);
+        ASSERT_EQ(infoPtr, &i);
+        ASSERT_FALSE(r);
+    }));
+    ASSERT_TRUE(hasRun);
+
+    canvasContext->destroy(nullptr);
+}
+
+TEST(SkiaDisplayList, updateChildren) {
+    SkRect bounds = SkRect::MakeWH(200, 200);
+    SkiaDisplayList skiaDL(bounds);
+
+    sp<RenderNode> renderNode = new RenderNode();
+    SkCanvas dummyCanvas;
+    skiaDL.mChildNodes.emplace_back(renderNode.get(), &dummyCanvas);
+    skiaDL.updateChildren([renderNode](RenderNode* n) {
+        ASSERT_EQ(renderNode.get(), n);
+    });
+}
diff --git a/libs/hwui/tests/unit/VectorDrawableTests.cpp b/libs/hwui/tests/unit/VectorDrawableTests.cpp
index 83b485f..8e0d3ee 100644
--- a/libs/hwui/tests/unit/VectorDrawableTests.cpp
+++ b/libs/hwui/tests/unit/VectorDrawableTests.cpp
@@ -426,5 +426,49 @@
     EXPECT_EQ(1.0f, properties->getPivotY());
 
 }
+
+static SkShader* createShader(bool* isDestroyed) {
+    class TestShader : public SkShader {
+    public:
+        TestShader(bool* isDestroyed) : SkShader(), mDestroyed(isDestroyed) {
+        }
+        ~TestShader() {
+            *mDestroyed = true;
+        }
+
+        Factory getFactory() const override { return nullptr; }
+    private:
+        bool* mDestroyed;
+    };
+    return new TestShader(isDestroyed);
+}
+
+TEST(VectorDrawable, drawPathWithoutIncrementingShaderRefCount) {
+    VectorDrawable::FullPath path("m1 1", 4);
+    SkBitmap bitmap;
+    SkImageInfo info = SkImageInfo::Make(5, 5, kN32_SkColorType, kPremul_SkAlphaType);
+    bitmap.setInfo(info);
+    bitmap.allocPixels(info);
+    SkCanvas canvas(bitmap);
+
+    bool shaderIsDestroyed = false;
+
+    // Initial ref count is 1
+    SkShader* shader = createShader(&shaderIsDestroyed);
+
+    // Setting the fill gradient increments the ref count of the shader by 1
+    path.mutateStagingProperties()->setFillGradient(shader);
+    path.draw(&canvas, SkMatrix::I(), 1.0f, 1.0f, true);
+    // Resetting the fill gradient decrements the ref count of the shader by 1
+    path.mutateStagingProperties()->setFillGradient(nullptr);
+
+    // Expect ref count to be 1 again, i.e. nothing else to have a ref to the shader now. Unref()
+    // again should bring the ref count to zero and consequently trigger detor.
+    shader->unref();
+
+    // Verify that detor is called.
+    EXPECT_TRUE(shaderIsDestroyed);
+}
+
 }; // namespace uirenderer
 }; // namespace android
diff --git a/libs/hwui/utils/Color.h b/libs/hwui/utils/Color.h
index b5157f4..f9cc46d1 100644
--- a/libs/hwui/utils/Color.h
+++ b/libs/hwui/utils/Color.h
@@ -16,6 +16,8 @@
 #ifndef COLOR_H
 #define COLOR_H
 
+#include <math.h>
+
 #include <SkColor.h>
 
 namespace android {
@@ -80,6 +82,42 @@
     };
     static constexpr int BrightColorsCount = sizeof(BrightColors) / sizeof(Color::Color);
 
+    // Opto-electronic conversion function for the sRGB color space
+    // Takes a gamma-encoded sRGB value and converts it to a linear sRGB value
+    static constexpr float OECF_sRGB(float linear) {
+        // IEC 61966-2-1:1999
+        return linear <= 0.0031308f ?
+                linear * 12.92f : (powf(linear, 1.0f / 2.4f) * 1.055f) - 0.055f;
+    }
+
+    // Opto-electronic conversion function for the sRGB color space
+    // Takes a gamma-encoded sRGB value and converts it to a linear sRGB value
+    // This function returns the input unmodified if linear blending is not enabled
+    static constexpr float OECF(float linear) {
+#ifdef ANDROID_ENABLE_LINEAR_BLENDING
+        return OECF_sRGB(linear);
+#else
+        return linear;
+#endif
+    }
+
+    // Electro-optical conversion function for the sRGB color space
+    // Takes a linear sRGB value and converts it to a gamma-encoded sRGB value
+    static constexpr float EOCF_sRGB(float srgb) {
+        // IEC 61966-2-1:1999
+        return srgb <= 0.04045f ? srgb / 12.92f : powf((srgb + 0.055f) / 1.055f, 2.4f);
+    }
+
+    // Electro-optical conversion function for the sRGB color space
+    // Takes a linear sRGB value and converts it to a gamma-encoded sRGB value
+    // This function returns the input unmodified if linear blending is not enabled
+    static constexpr float EOCF(float srgb) {
+#ifdef ANDROID_ENABLE_LINEAR_BLENDING
+        return EOCF_sRGB(srgb);
+#else
+        return srgb;
+#endif
+    }
 } /* namespace uirenderer */
 } /* namespace android */
 
diff --git a/libs/hwui/utils/TestWindowContext.cpp b/libs/hwui/utils/TestWindowContext.cpp
index b879f78..624d207 100644
--- a/libs/hwui/utils/TestWindowContext.cpp
+++ b/libs/hwui/utils/TestWindowContext.cpp
@@ -110,9 +110,10 @@
     }
 
     bool capturePixels(SkBitmap* bmp) {
+        sk_sp<SkColorSpace> colorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
         SkImageInfo destinationConfig =
             SkImageInfo::Make(mSize.width(), mSize.height(),
-                              kRGBA_8888_SkColorType, kPremul_SkAlphaType);
+                              kRGBA_8888_SkColorType, kPremul_SkAlphaType, colorSpace);
         bmp->allocPixels(destinationConfig);
         android_memset32((uint32_t*) bmp->getPixels(), SK_ColorRED,
                          mSize.width() * mSize.height() * 4);
diff --git a/media/java/android/media/AmrInputStream.java b/media/java/android/media/AmrInputStream.java
index f90f1e2..fb91bbb 100644
--- a/media/java/android/media/AmrInputStream.java
+++ b/media/java/android/media/AmrInputStream.java
@@ -18,45 +18,69 @@
 
 import java.io.InputStream;
 import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import android.media.MediaCodec.BufferInfo;
+import android.util.Log;
 
 
 /**
  * AmrInputStream
  * @hide
  */
-public final class AmrInputStream extends InputStream
-{    
-    static {
-        System.loadLibrary("media_jni");
-    }
-    
+public final class AmrInputStream extends InputStream {
     private final static String TAG = "AmrInputStream";
     
     // frame is 20 msec at 8.000 khz
     private final static int SAMPLES_PER_FRAME = 8000 * 20 / 1000;
-    
+
+    MediaCodec mCodec;
+    BufferInfo mInfo;
+    boolean mSawOutputEOS;
+    boolean mSawInputEOS;
+
     // pcm input stream
     private InputStream mInputStream;
-    
-    // native handle
-    private long mGae;
-    
+
     // result amr stream
     private final byte[] mBuf = new byte[SAMPLES_PER_FRAME * 2];
     private int mBufIn = 0;
     private int mBufOut = 0;
-    
+
     // helper for bytewise read()
     private byte[] mOneByte = new byte[1];
-    
+
     /**
      * Create a new AmrInputStream, which converts 16 bit PCM to AMR
      * @param inputStream InputStream containing 16 bit PCM.
      */
     public AmrInputStream(InputStream inputStream) {
         mInputStream = inputStream;
-        mGae = GsmAmrEncoderNew();
-        GsmAmrEncoderInitialize(mGae);
+
+        MediaFormat format  = new MediaFormat();
+        format.setString(MediaFormat.KEY_MIME, MediaFormat.MIMETYPE_AUDIO_AMR_NB);
+        format.setInteger(MediaFormat.KEY_SAMPLE_RATE, 8000);
+        format.setInteger(MediaFormat.KEY_CHANNEL_COUNT, 1);
+        format.setInteger(MediaFormat.KEY_BIT_RATE, 12200);
+
+        MediaCodecList mcl = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
+        String name = mcl.findEncoderForFormat(format);
+        if (name != null) {
+            try {
+                mCodec = MediaCodec.createByCodecName(name);
+                mCodec.configure(format,
+                        null /* surface */,
+                        null /* crypto */,
+                        MediaCodec.CONFIGURE_FLAG_ENCODE);
+                mCodec.start();
+            } catch (IOException e) {
+                if (mCodec != null) {
+                    mCodec.release();
+                }
+                mCodec = null;
+            }
+        }
+        mInfo = new BufferInfo();
     }
 
     @Override
@@ -64,7 +88,7 @@
         int rtn = read(mOneByte, 0, 1);
         return rtn == 1 ? (0xff & mOneByte[0]) : -1;
     }
-    
+
     @Override
     public int read(byte[] b) throws IOException {
         return read(b, 0, b.length);
@@ -72,67 +96,100 @@
 
     @Override
     public int read(byte[] b, int offset, int length) throws IOException {
-        if (mGae == 0) throw new IllegalStateException("not open");
-        
-        // local buffer of amr encoded audio empty
-        if (mBufOut >= mBufIn) {
-            // reset the buffer
+        if (mCodec == null) {
+            throw new IllegalStateException("not open");
+        }
+
+        if (mBufOut >= mBufIn && !mSawOutputEOS) {
+            // no data left in buffer, refill it
             mBufOut = 0;
             mBufIn = 0;
-            
-            // fetch a 20 msec frame of pcm
-            for (int i = 0; i < SAMPLES_PER_FRAME * 2; ) {
-                int n = mInputStream.read(mBuf, i, SAMPLES_PER_FRAME * 2 - i);
-                if (n == -1) return -1;
-                i += n;
+
+            // first push as much data into the encoder as possible
+            while (!mSawInputEOS) {
+                int index = mCodec.dequeueInputBuffer(0);
+                if (index < 0) {
+                    // no input buffer currently available
+                    break;
+                } else {
+                    int numRead;
+                    for (numRead = 0; numRead < SAMPLES_PER_FRAME * 2; ) {
+                        int n = mInputStream.read(mBuf, numRead, SAMPLES_PER_FRAME * 2 - numRead);
+                        if (n == -1) {
+                            mSawInputEOS = true;
+                            break;
+                        }
+                        numRead += n;
+                    }
+                    ByteBuffer buf = mCodec.getInputBuffer(index);
+                    buf.put(mBuf, 0, numRead);
+                    mCodec.queueInputBuffer(index,
+                            0 /* offset */,
+                            numRead,
+                            0 /* presentationTimeUs */,
+                            mSawInputEOS ? MediaCodec.BUFFER_FLAG_END_OF_STREAM : 0 /* flags */);
+                }
             }
-            
-            // encode it
-            mBufIn = GsmAmrEncoderEncode(mGae, mBuf, 0, mBuf, 0);
+
+            // now read encoded data from the encoder (blocking, since we just filled up the
+            // encoder's input with data it should be able to output at least one buffer)
+            while (true) {
+                int index = mCodec.dequeueOutputBuffer(mInfo, -1);
+                if (index >= 0) {
+                    mBufIn = mInfo.size;
+                    ByteBuffer out = mCodec.getOutputBuffer(index);
+                    out.get(mBuf, 0 /* offset */, mBufIn /* length */);
+                    mCodec.releaseOutputBuffer(index,  false /* render */);
+                    if ((mInfo.flags & MediaCodec.BUFFER_FLAG_END_OF_STREAM) != 0) {
+                        mSawOutputEOS = true;
+                    }
+                    break;
+                }
+            }
         }
-        
-        // return encoded audio to user
-        if (length > mBufIn - mBufOut) length = mBufIn - mBufOut;
-        System.arraycopy(mBuf, mBufOut, b, offset, length);
-        mBufOut += length;
-        
-        return length;
+
+        if (mBufOut < mBufIn) {
+            // there is data in the buffer
+            if (length > mBufIn - mBufOut) {
+                length = mBufIn - mBufOut;
+            }
+            System.arraycopy(mBuf, mBufOut, b, offset, length);
+            mBufOut += length;
+            return length;
+        }
+
+        if (mSawInputEOS && mSawOutputEOS) {
+            // no more data available in buffer, codec or input stream
+            return -1;
+        }
+
+        // caller should try again
+        return 0;
     }
 
     @Override
     public void close() throws IOException {
         try {
-            if (mInputStream != null) mInputStream.close();
+            if (mInputStream != null) {
+                mInputStream.close();
+            }
         } finally {
             mInputStream = null;
             try {
-                if (mGae != 0) GsmAmrEncoderCleanup(mGae);
-            } finally {
-                try {
-                    if (mGae != 0) GsmAmrEncoderDelete(mGae);
-                } finally {
-                    mGae = 0;
+                if (mCodec != null) {
+                    mCodec.release();
                 }
+            } finally {
+                mCodec = null;
             }
         }
     }
 
     @Override
     protected void finalize() throws Throwable {
-        if (mGae != 0) {
-            close();
-            throw new IllegalStateException("someone forgot to close AmrInputStream");
+        if (mCodec != null) {
+            Log.w(TAG, "AmrInputStream wasn't closed");
+            mCodec.release();
         }
     }
-    
-    //
-    // AudioRecord JNI interface
-    //
-    private static native long GsmAmrEncoderNew();
-    private static native void GsmAmrEncoderInitialize(long gae);
-    private static native int GsmAmrEncoderEncode(long gae,
-            byte[] pcm, int pcmOffset, byte[] amr, int amrOffset) throws IOException;
-    private static native void GsmAmrEncoderCleanup(long gae);
-    private static native void GsmAmrEncoderDelete(long gae);
-
 }
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index 33c1c3f..f24bf09 100644
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -312,29 +312,32 @@
      */
     public static final String EXTRA_ENCODINGS = "android.media.extra.ENCODINGS";
 
-    /** The audio stream for phone calls */
+    /** Used to identify the volume of audio streams for phone calls */
     public static final int STREAM_VOICE_CALL = AudioSystem.STREAM_VOICE_CALL;
-    /** The audio stream for system sounds */
+    /** Used to identify the volume of audio streams for system sounds */
     public static final int STREAM_SYSTEM = AudioSystem.STREAM_SYSTEM;
-    /** The audio stream for the phone ring */
+    /** Used to identify the volume of audio streams for the phone ring */
     public static final int STREAM_RING = AudioSystem.STREAM_RING;
-    /** The audio stream for music playback */
+    /** Used to identify the volume of audio streams for music playback */
     public static final int STREAM_MUSIC = AudioSystem.STREAM_MUSIC;
-    /** The audio stream for alarms */
+    /** Used to identify the volume of audio streams for alarms */
     public static final int STREAM_ALARM = AudioSystem.STREAM_ALARM;
-    /** The audio stream for notifications */
+    /** Used to identify the volume of audio streams for notifications */
     public static final int STREAM_NOTIFICATION = AudioSystem.STREAM_NOTIFICATION;
-    /** @hide The audio stream for phone calls when connected to bluetooth */
+    /** @hide Used to identify the volume of audio streams for phone calls when connected
+     *        to bluetooth */
     public static final int STREAM_BLUETOOTH_SCO = AudioSystem.STREAM_BLUETOOTH_SCO;
-    /** @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */
+    /** @hide Used to identify the volume of audio streams for enforced system sounds
+     *        in certain countries (e.g camera in Japan) */
     public static final int STREAM_SYSTEM_ENFORCED = AudioSystem.STREAM_SYSTEM_ENFORCED;
-    /** The audio stream for DTMF Tones */
+    /** Used to identify the volume of audio streams for DTMF Tones */
     public static final int STREAM_DTMF = AudioSystem.STREAM_DTMF;
-    /** @hide The audio stream for text to speech (TTS) */
+    /** @hide Used to identify the volume of audio streams exclusively transmitted through the
+     *        speaker (TTS) of the device */
     public static final int STREAM_TTS = AudioSystem.STREAM_TTS;
     /** Number of audio streams */
     /**
-     * @deprecated Use AudioSystem.getNumStreamTypes() instead
+     * @deprecated Do not iterate on volume stream type values.
      */
     @Deprecated public static final int NUM_STREAMS = AudioSystem.NUM_STREAMS;
 
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index f9bc95c..384be5c 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -39,27 +39,29 @@
      * If these are modified, please also update Settings.System.VOLUME_SETTINGS
      * and attrs.xml and AudioManager.java.
      */
-    /* The default audio stream */
+    /** Used to identify the default audio stream volume */
     public static final int STREAM_DEFAULT = -1;
-    /* The audio stream for phone calls */
+    /** Used to identify the volume of audio streams for phone calls */
     public static final int STREAM_VOICE_CALL = 0;
-    /* The audio stream for system sounds */
+    /** Used to identify the volume of audio streams for system sounds */
     public static final int STREAM_SYSTEM = 1;
-    /* The audio stream for the phone ring and message alerts */
+    /** Used to identify the volume of audio streams for the phone ring and message alerts */
     public static final int STREAM_RING = 2;
-    /* The audio stream for music playback */
+    /** Used to identify the volume of audio streams for music playback */
     public static final int STREAM_MUSIC = 3;
-    /* The audio stream for alarms */
+    /** Used to identify the volume of audio streams for alarms */
     public static final int STREAM_ALARM = 4;
-    /* The audio stream for notifications */
+    /** Used to identify the volume of audio streams for notifications */
     public static final int STREAM_NOTIFICATION = 5;
-    /* @hide The audio stream for phone calls when connected on bluetooth */
+    /** Used to identify the volume of audio streams for phone calls when connected on bluetooth */
     public static final int STREAM_BLUETOOTH_SCO = 6;
-    /* @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */
+    /** Used to identify the volume of audio streams for enforced system sounds in certain
+     * countries (e.g camera in Japan) */
     public static final int STREAM_SYSTEM_ENFORCED = 7;
-    /* @hide The audio stream for DTMF tones */
+    /** Used to identify the volume of audio streams for DTMF tones */
     public static final int STREAM_DTMF = 8;
-    /* @hide The audio stream for text to speech (TTS) */
+    /** Used to identify the volume of audio streams exclusively transmitted through the
+     *  speaker (TTS) of the device */
     public static final int STREAM_TTS = 9;
     /**
      * @deprecated Use {@link #numStreamTypes() instead}
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index 69710d6..d77a082 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -1764,16 +1764,13 @@
      * <p>
      * This method is only supported for JPEG files.
      * </p>
-     *
-     * @throws UnsupportedOperationException If this method is called with unsupported files.
      */
     public void saveAttributes() throws IOException {
         if (!mIsSupportedFile || mMimeType != IMAGE_TYPE_JPEG) {
-            throw new UnsupportedOperationException(
-                    "ExifInterface only supports saving attributes on JPEG formats.");
+            throw new IOException("ExifInterface only supports saving attributes on JPEG formats.");
         }
         if (mIsInputStream || (mSeekableFileDescriptor == null && mFilename == null)) {
-            throw new UnsupportedOperationException(
+            throw new IOException(
                     "ExifInterface does not support saving attributes for the current input.");
         }
 
diff --git a/media/jni/Android.mk b/media/jni/Android.mk
index dcd5057..44f7e56 100644
--- a/media/jni/Android.mk
+++ b/media/jni/Android.mk
@@ -2,7 +2,6 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-    android_media_AmrInputStream.cpp \
     android_media_ImageWriter.cpp \
     android_media_ImageReader.cpp \
     android_media_MediaCrypto.cpp \
@@ -44,11 +43,9 @@
     libmtp \
     libusbhost \
     libexif \
-    libpiex \
-    libstagefright_amrnb_common
+    libpiex
 
 LOCAL_STATIC_LIBRARIES := \
-    libstagefright_amrnbenc
 
 LOCAL_C_INCLUDES += \
     external/libexif/ \
@@ -58,9 +55,6 @@
     frameworks/base/libs/hwui \
     frameworks/av/media/libmedia \
     frameworks/av/media/libstagefright \
-    frameworks/av/media/libstagefright/codecs/amrnb/enc/src \
-    frameworks/av/media/libstagefright/codecs/amrnb/common \
-    frameworks/av/media/libstagefright/codecs/amrnb/common/include \
     frameworks/av/media/mtp \
     frameworks/native/include/media/openmax \
     $(call include-path-for, libhardware)/hardware \
diff --git a/media/jni/android_media_AmrInputStream.cpp b/media/jni/android_media_AmrInputStream.cpp
deleted file mode 100644
index b56a364..0000000
--- a/media/jni/android_media_AmrInputStream.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
-**
-** Copyright 2007, The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-#define LOG_TAG "AmrInputStream"
-#include "utils/Log.h"
-
-#include "jni.h"
-#include "JNIHelp.h"
-#include "android_runtime/AndroidRuntime.h"
-#include "gsmamr_enc.h"
-
-// ----------------------------------------------------------------------------
-
-using namespace android;
-
-// Corresponds to max bit rate of 12.2 kbps.
-static const int MAX_OUTPUT_BUFFER_SIZE = 32;
-static const int FRAME_DURATION_MS = 20;
-static const int SAMPLING_RATE_HZ = 8000;
-static const int SAMPLES_PER_FRAME = ((SAMPLING_RATE_HZ * FRAME_DURATION_MS) / 1000);
-static const int BYTES_PER_SAMPLE = 2;  // Assume 16-bit PCM samples
-static const int BYTES_PER_FRAME = (SAMPLES_PER_FRAME * BYTES_PER_SAMPLE);
-
-struct GsmAmrEncoderState {
-    GsmAmrEncoderState()
-        : mEncState(NULL),
-          mSidState(NULL),
-          mLastModeUsed(0) {
-    }
-
-    ~GsmAmrEncoderState() {}
-
-    void*   mEncState;
-    void*   mSidState;
-    int32_t mLastModeUsed;
-};
-
-static jlong android_media_AmrInputStream_GsmAmrEncoderNew
-        (JNIEnv *env, jclass /* clazz */) {
-    GsmAmrEncoderState* gae = new GsmAmrEncoderState();
-    if (gae == NULL) {
-        jniThrowRuntimeException(env, "Out of memory");
-    }
-    return (jlong)gae;
-}
-
-static void android_media_AmrInputStream_GsmAmrEncoderInitialize
-        (JNIEnv *env, jclass /* clazz */, jlong gae) {
-    GsmAmrEncoderState *state = (GsmAmrEncoderState *) gae;
-    int32_t nResult = AMREncodeInit(&state->mEncState, &state->mSidState, false);
-    if (nResult != OK) {
-        jniThrowExceptionFmt(env, "java/lang/IllegalArgumentException",
-                "GsmAmrEncoder initialization failed %d", nResult);
-    }
-}
-
-static jint android_media_AmrInputStream_GsmAmrEncoderEncode
-        (JNIEnv *env, jclass /* clazz */,
-         jlong gae, jbyteArray pcm, jint pcmOffset, jbyteArray amr, jint amrOffset) {
-
-    jbyte inBuf[BYTES_PER_FRAME];
-    jbyte outBuf[MAX_OUTPUT_BUFFER_SIZE];
-
-    env->GetByteArrayRegion(pcm, pcmOffset, sizeof(inBuf), inBuf);
-    GsmAmrEncoderState *state = (GsmAmrEncoderState *) gae;
-    int32_t length = AMREncode(state->mEncState, state->mSidState,
-                                (Mode) MR122,
-                                (int16_t *) inBuf,
-                                (unsigned char *) outBuf,
-                                (Frame_Type_3GPP*) &state->mLastModeUsed,
-                                AMR_TX_WMF);
-    if (length < 0) {
-        jniThrowExceptionFmt(env, "java/io/IOException",
-                "Failed to encode a frame with error code: %d", length);
-        return (jint)-1;
-    }
-
-    // The 1st byte of PV AMR frames are WMF (Wireless Multimedia Forum)
-    // bitpacked, i.e.;
-    //    [P(4) + FT(4)]. Q=1 for good frame, P=padding bit, 0
-    // Here we are converting the header to be as specified in Section 5.3 of
-    // RFC 3267 (AMR storage format) i.e.
-    //    [P(1) + FT(4) + Q(1) + P(2)].
-    if (length > 0) {
-      outBuf[0] = (outBuf[0] << 3) | 0x4;
-    }
-
-    env->SetByteArrayRegion(amr, amrOffset, length, outBuf);
-
-    return (jint)length;
-}
-
-static void android_media_AmrInputStream_GsmAmrEncoderCleanup
-        (JNIEnv* /* env */, jclass /* clazz */, jlong gae) {
-    GsmAmrEncoderState *state = (GsmAmrEncoderState *) gae;
-    AMREncodeExit(&state->mEncState, &state->mSidState);
-    state->mEncState = NULL;
-    state->mSidState = NULL;
-}
-
-static void android_media_AmrInputStream_GsmAmrEncoderDelete
-        (JNIEnv* /* env */, jclass /* clazz */, jlong gae) {
-    delete (GsmAmrEncoderState*)gae;
-}
-
-// ----------------------------------------------------------------------------
-
-static const JNINativeMethod gMethods[] = {
-    {"GsmAmrEncoderNew",        "()J",        (void*)android_media_AmrInputStream_GsmAmrEncoderNew},
-    {"GsmAmrEncoderInitialize", "(J)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderInitialize},
-    {"GsmAmrEncoderEncode",     "(J[BI[BI)I", (void*)android_media_AmrInputStream_GsmAmrEncoderEncode},
-    {"GsmAmrEncoderCleanup",    "(J)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderCleanup},
-    {"GsmAmrEncoderDelete",     "(J)V",       (void*)android_media_AmrInputStream_GsmAmrEncoderDelete},
-};
-
-
-int register_android_media_AmrInputStream(JNIEnv *env)
-{
-    const char* const kClassPathName = "android/media/AmrInputStream";
-
-    return AndroidRuntime::registerNativeMethods(env,
-            kClassPathName, gMethods, NELEM(gMethods));
-}
diff --git a/media/jni/android_media_MediaPlayer.cpp b/media/jni/android_media_MediaPlayer.cpp
index ecf733f..c825702 100644
--- a/media/jni/android_media_MediaPlayer.cpp
+++ b/media/jni/android_media_MediaPlayer.cpp
@@ -1105,7 +1105,6 @@
 extern int register_android_media_MediaSync(JNIEnv *env);
 extern int register_android_media_ResampleInputStream(JNIEnv *env);
 extern int register_android_media_MediaProfiles(JNIEnv *env);
-extern int register_android_media_AmrInputStream(JNIEnv *env);
 extern int register_android_mtp_MtpDatabase(JNIEnv *env);
 extern int register_android_mtp_MtpDevice(JNIEnv *env);
 extern int register_android_mtp_MtpServer(JNIEnv *env);
@@ -1151,11 +1150,6 @@
         goto bail;
     }
 
-    if (register_android_media_AmrInputStream(env) < 0) {
-        ALOGE("ERROR: AmrInputStream native registration failed\n");
-        goto bail;
-    }
-
     if (register_android_media_ResampleInputStream(env) < 0) {
         ALOGE("ERROR: ResampleInputStream native registration failed\n");
         goto bail;
diff --git a/packages/Keyguard/res/values-b+sr+Latn/strings.xml b/packages/Keyguard/res/values-b+sr+Latn/strings.xml
index 570f4bc..8006125 100644
--- a/packages/Keyguard/res/values-b+sr+Latn/strings.xml
+++ b/packages/Keyguard/res/values-b+sr+Latn/strings.xml
@@ -56,7 +56,7 @@
     <string name="kg_wrong_pattern" msgid="1850806070801358830">"Pogrešan šablon"</string>
     <string name="kg_wrong_password" msgid="2333281762128113157">"Pogrešna lozinka"</string>
     <string name="kg_wrong_pin" msgid="1131306510833563801">"Pogrešan PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Pokušajte ponovo za <xliff:g id="NUMBER">%d</xliff:g> sekunde(i)."</string>
+    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Probajte ponovo za <xliff:g id="NUMBER">%d</xliff:g> sekunde(i)."</string>
     <string name="kg_pattern_instructions" msgid="398978611683075868">"Nacrtajte šablon"</string>
     <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Unesite PIN SIM kartice"</string>
     <string name="kg_sim_pin_instructions_multi" msgid="7818515973197201434">"Unesite PIN za SIM „<xliff:g id="CARRIER">%1$s</xliff:g>“"</string>
@@ -72,9 +72,9 @@
     <string name="kg_invalid_puk" msgid="3638289409676051243">"Ponovo unesite ispravni PUK kôd. Ponovljeni pokušaji će trajno onemogućiti SIM."</string>
     <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN kodovi se ne podudaraju"</string>
     <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Previše pokušaja unosa šablona"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Uneli ste netačni PIN <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Uneli ste netačnu lozinku <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nPokušajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Uneli ste netačni PIN <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Uneli ste netačnu lozinku <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. \n\nProbajte ponovo za <xliff:g id="NUMBER_1">%2$d</xliff:g> sekunde(i)."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="8774056606869646621">"Pogrešno ste pokušali da otključate tablet <xliff:g id="NUMBER_0">%1$d</xliff:g> put(a). Imate još <xliff:g id="NUMBER_1">%2$d</xliff:g> pokušaj(a), nakon čega se tablet resetuje i svi podaci sa njega brišu."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="1843331751334128428">"Pogrešno ste pokušali da otključate telefon <xliff:g id="NUMBER_0">%1$d</xliff:g> put(a). Imate još <xliff:g id="NUMBER_1">%2$d</xliff:g> pokušaj(a), nakon čega se telefon resetuje i svi podaci sa njega brišu."</string>
     <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="258925501999698032">"Pogrešno ste pokušali da otključate tablet <xliff:g id="NUMBER">%d</xliff:g> put(a). Tablet će biti resetovan i svi podaci sa njega će biti izbrisani."</string>
@@ -87,8 +87,8 @@
     <string name="kg_failed_attempts_almost_at_erase_profile" product="default" msgid="6853071165802933545">"Pogrešno ste pokušali da otključate telefon <xliff:g id="NUMBER_0">%1$d</xliff:g> put(a). Imate još <xliff:g id="NUMBER_1">%2$d</xliff:g> pokušaj(a), nakon čega se poslovni profil uklanja i svi podaci sa profila brišu."</string>
     <string name="kg_failed_attempts_now_erasing_profile" product="tablet" msgid="4686386497449912146">"Pogrešno ste pokušali da otključate tablet <xliff:g id="NUMBER">%d</xliff:g> put(a). Poslovni profil će biti uklonjen i svi podaci sa njega će biti izbrisani."</string>
     <string name="kg_failed_attempts_now_erasing_profile" product="default" msgid="4951507352869831265">"Pogrešno ste pokušali da otključate telefon <xliff:g id="NUMBER">%d</xliff:g> put(a). Poslovni profil će biti uklonjen i svi podaci sa njega će biti izbrisani."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate tablet pomoću naloga e-pošte.\n\nPokušajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate telefon pomoću naloga e-pošte.\n\nPokušajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate tablet pomoću naloga e-pošte.\n\nProbajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Nacrtali ste šablon za otključavanje netačno <xliff:g id="NUMBER_0">%1$d</xliff:g> puta. Posle još <xliff:g id="NUMBER_1">%2$d</xliff:g> neuspešna(ih) pokušaja, od vas će biti zatraženo da otključate telefon pomoću naloga e-pošte.\n\nProbajte ponovo za <xliff:g id="NUMBER_2">%3$d</xliff:g> sekunde(i)."</string>
     <string name="kg_password_wrong_pin_code_pukked" msgid="30531039455764924">"Netačan SIM PIN kôd. Sada morate da kontaktirate mobilnog operatera da biste otključali uređaj."</string>
     <plurals name="kg_password_wrong_pin_code" formatted="false" msgid="6721575017538162249">
       <item quantity="one">Netačan SIM PIN kôd. Imate još <xliff:g id="NUMBER_1">%d</xliff:g> pokušaj.</item>
diff --git a/packages/Keyguard/res/values-sr/strings.xml b/packages/Keyguard/res/values-sr/strings.xml
index 840cae7..23c0b50 100644
--- a/packages/Keyguard/res/values-sr/strings.xml
+++ b/packages/Keyguard/res/values-sr/strings.xml
@@ -56,7 +56,7 @@
     <string name="kg_wrong_pattern" msgid="1850806070801358830">"Погрешан шаблон"</string>
     <string name="kg_wrong_password" msgid="2333281762128113157">"Погрешна лозинка"</string>
     <string name="kg_wrong_pin" msgid="1131306510833563801">"Погрешан PIN"</string>
-    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Покушајте поново за <xliff:g id="NUMBER">%d</xliff:g> секунде(и)."</string>
+    <string name="kg_too_many_failed_attempts_countdown" msgid="6358110221603297548">"Пробајте поново за <xliff:g id="NUMBER">%d</xliff:g> секунде(и)."</string>
     <string name="kg_pattern_instructions" msgid="398978611683075868">"Нацртајте шаблон"</string>
     <string name="kg_sim_pin_instructions" msgid="2319508550934557331">"Унесите PIN SIM картице"</string>
     <string name="kg_sim_pin_instructions_multi" msgid="7818515973197201434">"Унесите PIN за SIM „<xliff:g id="CARRIER">%1$s</xliff:g>“"</string>
@@ -72,9 +72,9 @@
     <string name="kg_invalid_puk" msgid="3638289409676051243">"Поново унесите исправни PUK кôд. Поновљени покушаји ће трајно онемогућити SIM."</string>
     <string name="kg_invalid_confirm_pin_hint" product="default" msgid="7003469261464593516">"PIN кодови се не подударају"</string>
     <string name="kg_login_too_many_attempts" msgid="6486842094005698475">"Превише покушаја уноса шаблона"</string>
-    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Унели сте нетачни PIN <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
-    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Унели сте нетачну лозинку <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
-    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПокушајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="kg_too_many_failed_pin_attempts_dialog_message" msgid="8276745642049502550">"Унели сте нетачни PIN <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="kg_too_many_failed_password_attempts_dialog_message" msgid="7813713389422226531">"Унели сте нетачну лозинку <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
+    <string name="kg_too_many_failed_pattern_attempts_dialog_message" msgid="74089475965050805">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. \n\nПробајте поново за <xliff:g id="NUMBER_1">%2$d</xliff:g> секунде(и)."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="tablet" msgid="8774056606869646621">"Погрешно сте покушали да откључате таблет <xliff:g id="NUMBER_0">%1$d</xliff:g> пут(а). Имате још <xliff:g id="NUMBER_1">%2$d</xliff:g> покушај(а), након чега се таблет ресетује и сви подаци са њега бришу."</string>
     <string name="kg_failed_attempts_almost_at_wipe" product="default" msgid="1843331751334128428">"Погрешно сте покушали да откључате телефон <xliff:g id="NUMBER_0">%1$d</xliff:g> пут(а). Имате још <xliff:g id="NUMBER_1">%2$d</xliff:g> покушај(а), након чега се телефон ресетује и сви подаци са њега бришу."</string>
     <string name="kg_failed_attempts_now_wiping" product="tablet" msgid="258925501999698032">"Погрешно сте покушали да откључате таблет <xliff:g id="NUMBER">%d</xliff:g> пут(а). Таблет ће бити ресетован и сви подаци са њега ће бити избрисани."</string>
@@ -87,8 +87,8 @@
     <string name="kg_failed_attempts_almost_at_erase_profile" product="default" msgid="6853071165802933545">"Погрешно сте покушали да откључате телефон <xliff:g id="NUMBER_0">%1$d</xliff:g> пут(а). Имате још <xliff:g id="NUMBER_1">%2$d</xliff:g> покушај(а), након чега се пословни профил уклања и сви подаци са профила бришу."</string>
     <string name="kg_failed_attempts_now_erasing_profile" product="tablet" msgid="4686386497449912146">"Погрешно сте покушали да откључате таблет <xliff:g id="NUMBER">%d</xliff:g> пут(а). Пословни профил ће бити уклоњен и сви подаци са њега ће бити избрисани."</string>
     <string name="kg_failed_attempts_now_erasing_profile" product="default" msgid="4951507352869831265">"Погрешно сте покушали да откључате телефон <xliff:g id="NUMBER">%d</xliff:g> пут(а). Пословни профил ће бити уклоњен и сви подаци са њега ће бити избрисани."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате таблет помоћу налога е-поште.\n\nПокушајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
-    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате телефон помоћу налога е-поште.\n\nПокушајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="tablet" msgid="3253575572118914370">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате таблет помоћу налога е-поште.\n\nПробајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
+    <string name="kg_failed_attempts_almost_at_login" product="default" msgid="1437638152015574839">"Нацртали сте шаблон за откључавање нетачно <xliff:g id="NUMBER_0">%1$d</xliff:g> пута. После још <xliff:g id="NUMBER_1">%2$d</xliff:g> неуспешна(их) покушаја, од вас ће бити затражено да откључате телефон помоћу налога е-поште.\n\nПробајте поново за <xliff:g id="NUMBER_2">%3$d</xliff:g> секунде(и)."</string>
     <string name="kg_password_wrong_pin_code_pukked" msgid="30531039455764924">"Нетачан SIM PIN кôд. Сада морате да контактирате мобилног оператера да бисте откључали уређај."</string>
     <plurals name="kg_password_wrong_pin_code" formatted="false" msgid="6721575017538162249">
       <item quantity="one">Нетачан SIM PIN кôд. Имате још <xliff:g id="NUMBER_1">%d</xliff:g> покушај.</item>
diff --git a/packages/Keyguard/res/values-zh-rCN/strings.xml b/packages/Keyguard/res/values-zh-rCN/strings.xml
index 0723ab1..e15950f 100644
--- a/packages/Keyguard/res/values-zh-rCN/strings.xml
+++ b/packages/Keyguard/res/values-zh-rCN/strings.xml
@@ -36,7 +36,7 @@
     <string name="keyguard_low_battery" msgid="8143808018719173859">"请连接充电器。"</string>
     <string name="keyguard_instructions_when_pattern_disabled" msgid="1332288268600329841">"按“菜单”键解锁。"</string>
     <string name="keyguard_network_locked_message" msgid="9169717779058037168">"网络已锁定"</string>
-    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"无 SIM 卡"</string>
+    <string name="keyguard_missing_sim_message_short" msgid="494980561304211931">"没有 SIM 卡"</string>
     <string name="keyguard_missing_sim_message" product="tablet" msgid="1445849005909260039">"平板电脑中没有SIM卡。"</string>
     <string name="keyguard_missing_sim_message" product="default" msgid="3481110395508637643">"手机中没有SIM卡。"</string>
     <string name="keyguard_missing_sim_instructions" msgid="5210891509995942250">"请插入SIM卡。"</string>
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java
index 4330573..94286ec 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardAbsKeyInputView.java
@@ -200,7 +200,7 @@
                 }
             }
             if (timeoutMs == 0) {
-                mSecurityMessageDisplay.setMessage(getWrongPasswordStringId(), true);
+                mSecurityMessageDisplay.setMessage(getWrongPasswordStringId());
             }
         }
         resetPasswordText(true /* animate */, !matched /* announce deletion if no match */);
@@ -220,13 +220,13 @@
             @Override
             public void onTick(long millisUntilFinished) {
                 int secondsRemaining = (int) (millisUntilFinished / 1000);
-                mSecurityMessageDisplay.setMessage(
-                        R.string.kg_too_many_failed_attempts_countdown, true, secondsRemaining);
+                mSecurityMessageDisplay.formatMessage(
+                        R.string.kg_too_many_failed_attempts_countdown, secondsRemaining);
             }
 
             @Override
             public void onFinish() {
-                mSecurityMessageDisplay.setMessage("", false);
+                mSecurityMessageDisplay.setMessage("");
                 resetState();
             }
         }.start();
@@ -236,7 +236,7 @@
         if (mCallback != null) {
             mCallback.userActivity();
         }
-        mSecurityMessageDisplay.setMessage("", false);
+        mSecurityMessageDisplay.setMessage("");
     }
 
     @Override
@@ -273,8 +273,7 @@
         if (reason != PROMPT_REASON_NONE) {
             int promtReasonStringRes = getPromtReasonStringRes(reason);
             if (promtReasonStringRes != 0) {
-                mSecurityMessageDisplay.setMessage(promtReasonStringRes,
-                        true /* important */);
+                mSecurityMessageDisplay.setMessage(promtReasonStringRes);
             }
         }
     }
@@ -282,7 +281,7 @@
     @Override
     public void showMessage(String message, int color) {
         mSecurityMessageDisplay.setNextMessageColor(color);
-        mSecurityMessageDisplay.setMessage(message, true /* important */);
+        mSecurityMessageDisplay.setMessage(message);
     }
 
     protected abstract int getPromtReasonStringRes(int reason);
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardMessageArea.java b/packages/Keyguard/src/com/android/keyguard/KeyguardMessageArea.java
index c8adf64..caeb74c 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardMessageArea.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardMessageArea.java
@@ -41,14 +41,10 @@
     private static final long ANNOUNCEMENT_DELAY = 250;
     private static final int DEFAULT_COLOR = -1;
 
-    private static final int SECURITY_MESSAGE_DURATION = 5000;
-
     private final KeyguardUpdateMonitor mUpdateMonitor;
     private final Handler mHandler;
     private final int mDefaultColor;
 
-    // Timeout before we reset the message to show charging/owner info
-    long mTimeout = SECURITY_MESSAGE_DURATION;
     CharSequence mMessage;
     private int mNextMessageColor = DEFAULT_COLOR;
 
@@ -91,8 +87,8 @@
     }
 
     @Override
-    public void setMessage(CharSequence msg, boolean important) {
-        if (!TextUtils.isEmpty(msg) && important) {
+    public void setMessage(CharSequence msg) {
+        if (!TextUtils.isEmpty(msg)) {
             securityMessageChanged(msg);
         } else {
             clearMessage();
@@ -100,28 +96,21 @@
     }
 
     @Override
-    public void setMessage(int resId, boolean important) {
-        if (resId != 0 && important) {
-            CharSequence message = getContext().getResources().getText(resId);
-            securityMessageChanged(message);
-        } else {
-            clearMessage();
+    public void setMessage(int resId) {
+        CharSequence message = null;
+        if (resId != 0) {
+            message = getContext().getResources().getText(resId);
         }
+        setMessage(message);
     }
 
     @Override
-    public void setMessage(int resId, boolean important, Object... formatArgs) {
-        if (resId != 0 && important) {
-            String message = getContext().getString(resId, formatArgs);
-            securityMessageChanged(message);
-        } else {
-            clearMessage();
+    public void formatMessage(int resId, Object... formatArgs) {
+        CharSequence message = null;
+        if (resId != 0) {
+            message = getContext().getString(resId, formatArgs);
         }
-    }
-
-    @Override
-    public void setTimeout(int timeoutMs) {
-        mTimeout = timeoutMs;
+        setMessage(message);
     }
 
     public static SecurityMessageDisplay findSecurityMessageDisplay(View v) {
@@ -142,10 +131,6 @@
     private void securityMessageChanged(CharSequence message) {
         mMessage = message;
         update();
-        mHandler.removeCallbacks(mClearMessageRunnable);
-        if (mTimeout > 0) {
-            mHandler.postDelayed(mClearMessageRunnable, mTimeout);
-        }
         mHandler.removeCallbacksAndMessages(ANNOUNCE_TOKEN);
         mHandler.postAtTime(new AnnounceRunnable(this, getText()), ANNOUNCE_TOKEN,
                 (SystemClock.uptimeMillis() + ANNOUNCEMENT_DELAY));
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardPINView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardPINView.java
index 285b1ae..590d8d5 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardPINView.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardPINView.java
@@ -67,7 +67,7 @@
     @Override
     protected void resetState() {
         super.resetState();
-        mSecurityMessageDisplay.setMessage(R.string.kg_pin_instructions, false);
+        mSecurityMessageDisplay.setMessage("");
     }
 
     @Override
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardPasswordView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardPasswordView.java
index ddccc14..d49ff97 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardPasswordView.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardPasswordView.java
@@ -79,7 +79,7 @@
 
     @Override
     protected void resetState() {
-        mSecurityMessageDisplay.setMessage(R.string.kg_password_instructions, false);
+        mSecurityMessageDisplay.setMessage("");
         final boolean wasDisabled = mPasswordEntry.isEnabled();
         setPasswordEntryEnabled(true);
         setPasswordEntryInputEnabled(true);
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java
index a9ce197..330632b 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardPatternView.java
@@ -200,7 +200,7 @@
     }
 
     private void displayDefaultSecurityMessage() {
-        mSecurityMessageDisplay.setMessage(R.string.kg_pattern_instructions, false);
+        mSecurityMessageDisplay.setMessage("");
     }
 
     @Override
@@ -219,7 +219,7 @@
         @Override
         public void onPatternStart() {
             mLockPatternView.removeCallbacks(mCancelPatternRunnable);
-            mSecurityMessageDisplay.setMessage("", false);
+            mSecurityMessageDisplay.setMessage("");
         }
 
         @Override
@@ -314,7 +314,7 @@
                     }
                 }
                 if (timeoutMs == 0) {
-                    mSecurityMessageDisplay.setMessage(R.string.kg_wrong_pattern, true);
+                    mSecurityMessageDisplay.setMessage(R.string.kg_wrong_pattern);
                     mLockPatternView.postDelayed(mCancelPatternRunnable, PATTERN_CLEAR_TIMEOUT_MS);
                 }
             }
@@ -331,8 +331,8 @@
             @Override
             public void onTick(long millisUntilFinished) {
                 final int secondsRemaining = (int) (millisUntilFinished / 1000);
-                mSecurityMessageDisplay.setMessage(
-                        R.string.kg_too_many_failed_attempts_countdown, true, secondsRemaining);
+                mSecurityMessageDisplay.formatMessage(
+                        R.string.kg_too_many_failed_attempts_countdown, secondsRemaining);
             }
 
             @Override
@@ -375,26 +375,21 @@
     public void showPromptReason(int reason) {
         switch (reason) {
             case PROMPT_REASON_RESTART:
-                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_restart_pattern,
-                        true /* important */);
+                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_restart_pattern);
                 break;
             case PROMPT_REASON_TIMEOUT:
-                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_timeout_pattern,
-                        true /* important */);
+                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_timeout_pattern);
                 break;
             case PROMPT_REASON_DEVICE_ADMIN:
-                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_device_admin,
-                        true /* important */);
+                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_device_admin);
                 break;
             case PROMPT_REASON_USER_REQUEST:
-                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_user_request,
-                        true /* important */);
+                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_user_request);
                 break;
             case PROMPT_REASON_NONE:
                 break;
             default:
-                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_timeout_pattern,
-                        true /* important */);
+                mSecurityMessageDisplay.setMessage(R.string.kg_prompt_reason_timeout_pattern);
                 break;
         }
     }
@@ -402,7 +397,7 @@
     @Override
     public void showMessage(String message, int color) {
         mSecurityMessageDisplay.setNextMessageColor(color);
-        mSecurityMessageDisplay.setMessage(message, true /* important */);
+        mSecurityMessageDisplay.setMessage(message);
     }
 
     @Override
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java
index d48cc94..839d3ce 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSimPinView.java
@@ -92,7 +92,7 @@
                     color = info.getIconTint();
                 }
             }
-            mSecurityMessageDisplay.setMessage(msg, true);
+            mSecurityMessageDisplay.setMessage(msg);
             mSimImageView.setImageTintList(ColorStateList.valueOf(color));
         }
     }
@@ -141,7 +141,6 @@
     protected void onFinishInflate() {
         super.onFinishInflate();
 
-        mSecurityMessageDisplay.setTimeout(0); // don't show ownerinfo/charging status by default
         if (mEcaView instanceof EmergencyCarrierArea) {
             ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
         }
@@ -252,7 +251,7 @@
 
         if (entry.length() < 4) {
             // otherwise, display a message to the user, and don't submit.
-            mSecurityMessageDisplay.setMessage(R.string.kg_invalid_sim_pin_hint, true);
+            mSecurityMessageDisplay.setMessage(R.string.kg_invalid_sim_pin_hint);
             resetPasswordText(true /* animate */, true /* announce */);
             mCallback.userActivity();
             return;
@@ -284,13 +283,13 @@
                                     } else {
                                         // show message
                                         mSecurityMessageDisplay.setMessage(
-                                                getPinPasswordErrorMessage(attemptsRemaining), true);
+                                                getPinPasswordErrorMessage(attemptsRemaining));
                                     }
                                 } else {
                                     // "PIN operation failed!" - no idea what this was and no way to
                                     // find out. :/
                                     mSecurityMessageDisplay.setMessage(getContext().getString(
-                                            R.string.kg_password_pin_failed), true);
+                                            R.string.kg_password_pin_failed));
                                 }
                                 if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
                                         + " CheckSimPin.onSimCheckResponse: " + result
diff --git a/packages/Keyguard/src/com/android/keyguard/KeyguardSimPukView.java b/packages/Keyguard/src/com/android/keyguard/KeyguardSimPukView.java
index 249dde8..3871448 100644
--- a/packages/Keyguard/src/com/android/keyguard/KeyguardSimPukView.java
+++ b/packages/Keyguard/src/com/android/keyguard/KeyguardSimPukView.java
@@ -108,7 +108,7 @@
             }
             resetPasswordText(true /* animate */, true /* announce */);
             if (msg != 0) {
-                mSecurityMessageDisplay.setMessage(msg, true);
+                mSecurityMessageDisplay.setMessage(msg);
             }
         }
 
@@ -133,7 +133,7 @@
                         color = info.getIconTint();
                     }
                 }
-                mSecurityMessageDisplay.setMessage(msg, true);
+                mSecurityMessageDisplay.setMessage(msg);
                 mSimImageView.setImageTintList(ColorStateList.valueOf(color));
             }
             mPasswordEntry.requestFocus();
@@ -184,7 +184,6 @@
     protected void onFinishInflate() {
         super.onFinishInflate();
 
-        mSecurityMessageDisplay.setTimeout(0); // don't show ownerinfo/charging status by default
         if (mEcaView instanceof EmergencyCarrierArea) {
             ((EmergencyCarrierArea) mEcaView).setCarrierTextVisible(true);
         }
@@ -341,11 +340,11 @@
                                     } else {
                                         // show message
                                         mSecurityMessageDisplay.setMessage(
-                                                getPukPasswordErrorMessage(attemptsRemaining), true);
+                                                getPukPasswordErrorMessage(attemptsRemaining));
                                     }
                                 } else {
                                     mSecurityMessageDisplay.setMessage(getContext().getString(
-                                            R.string.kg_password_puk_failed), true);
+                                            R.string.kg_password_puk_failed));
                                 }
                                 if (DEBUG) Log.d(LOG_TAG, "verifyPasswordAndUnlock "
                                         + " UpdateSim.onSimCheckResponse: "
diff --git a/packages/Keyguard/src/com/android/keyguard/LatencyTracker.java b/packages/Keyguard/src/com/android/keyguard/LatencyTracker.java
index 4b4cd86..cee0afc 100644
--- a/packages/Keyguard/src/com/android/keyguard/LatencyTracker.java
+++ b/packages/Keyguard/src/com/android/keyguard/LatencyTracker.java
@@ -141,6 +141,7 @@
         if (startRtc == -1) {
             return;
         }
+        mStartRtc.delete(action);
         Trace.asyncTraceEnd(Trace.TRACE_TAG_APP, NAMES[action], 0);
         long duration = endRtc - startRtc;
         Log.i(TAG, "action=" + action + " latency=" + duration);
diff --git a/packages/Keyguard/src/com/android/keyguard/SecurityMessageDisplay.java b/packages/Keyguard/src/com/android/keyguard/SecurityMessageDisplay.java
index ddb1f6e..6977b51 100644
--- a/packages/Keyguard/src/com/android/keyguard/SecurityMessageDisplay.java
+++ b/packages/Keyguard/src/com/android/keyguard/SecurityMessageDisplay.java
@@ -20,11 +20,9 @@
 
     void setNextMessageColor(int color);
 
-    void setMessage(CharSequence msg, boolean important);
+    void setMessage(CharSequence msg);
 
-    void setMessage(int resId, boolean important);
+    void setMessage(int resId);
 
-    void setMessage(int resId, boolean important, Object... formatArgs);
-
-    void setTimeout(int timeout_ms);
+    void formatMessage(int resId, Object... formatArgs);
 }
diff --git a/packages/MtpDocumentsProvider/perf_tests/src/com/android/mtp/AppFuseTest.java b/packages/MtpDocumentsProvider/perf_tests/src/com/android/mtp/AppFusePerfTest.java
similarity index 98%
rename from packages/MtpDocumentsProvider/perf_tests/src/com/android/mtp/AppFuseTest.java
rename to packages/MtpDocumentsProvider/perf_tests/src/com/android/mtp/AppFusePerfTest.java
index a3e2e6b..0762571 100644
--- a/packages/MtpDocumentsProvider/perf_tests/src/com/android/mtp/AppFuseTest.java
+++ b/packages/MtpDocumentsProvider/perf_tests/src/com/android/mtp/AppFusePerfTest.java
@@ -35,10 +35,10 @@
 import org.junit.Test;
 
 @RunWith(JUnit4.class)
-public class AppFuseTest {
+public class AppFusePerfTest {
     @Test
     @LargeTest
-    public void testPerfReadWriteFile() throws IOException {
+    public void testReadWriteFile() throws IOException {
         final Context context = InstrumentationRegistry.getInstrumentation().getTargetContext();
         final StorageManager storageManager = context.getSystemService(StorageManager.class);
         final int INODE = 10;
diff --git a/packages/PrintSpooler/res/values-b+sr+Latn/strings.xml b/packages/PrintSpooler/res/values-b+sr+Latn/strings.xml
index ce8a81e..2b1b8ca 100644
--- a/packages/PrintSpooler/res/values-b+sr+Latn/strings.xml
+++ b/packages/PrintSpooler/res/values-b+sr+Latn/strings.xml
@@ -103,8 +103,8 @@
     <item msgid="3199660090246166812">"Vodoravno"</item>
   </string-array>
     <string name="print_write_error_message" msgid="5787642615179572543">"Upisivanje u datoteku nije moguće"</string>
-    <string name="print_error_default_message" msgid="8602678405502922346">"Žao nam je, ovo nije uspelo. Pokušajte ponovo."</string>
-    <string name="print_error_retry" msgid="1426421728784259538">"Pokušajte ponovo"</string>
+    <string name="print_error_default_message" msgid="8602678405502922346">"Žao nam je, ovo nije uspelo. Probajte ponovo."</string>
+    <string name="print_error_retry" msgid="1426421728784259538">"Probajte ponovo"</string>
     <string name="print_error_printer_unavailable" msgid="8985614415253203381">"Ovaj štampač trenutno nije dostupan."</string>
     <string name="print_cannot_load_page" msgid="6179560924492912009">"Nije uspeo prikaz pregleda"</string>
     <string name="print_preparing_preview" msgid="3939930735671364712">"Priprema pregleda..."</string>
diff --git a/packages/PrintSpooler/res/values-kn-rIN/strings.xml b/packages/PrintSpooler/res/values-kn-rIN/strings.xml
index ef3ea16..c6e36d2 100644
--- a/packages/PrintSpooler/res/values-kn-rIN/strings.xml
+++ b/packages/PrintSpooler/res/values-kn-rIN/strings.xml
@@ -47,7 +47,7 @@
     <string name="savetopdf_button" msgid="2976186791686924743">"PDF ಗೆ ಉಳಿಸು"</string>
     <string name="print_options_expanded" msgid="6944679157471691859">"ಪ್ರಿಂಟ್ ಆಯ್ಕೆಗಳನ್ನು ವಿಸ್ತರಿಸಲಾಗಿದೆ"</string>
     <string name="print_options_collapsed" msgid="7455930445670414332">"ಪ್ರಿಂಟ್ ಆಯ್ಕೆಗಳನ್ನು ಮುಚ್ಚಲಾಗಿದೆ"</string>
-    <string name="search" msgid="5421724265322228497">"ಹುಡುಕು"</string>
+    <string name="search" msgid="5421724265322228497">"ಹುಡುಕಿ"</string>
     <string name="all_printers_label" msgid="3178848870161526399">"ಎಲ್ಲಾ ಪ್ರಿಂಟರ್‌ಗಳು"</string>
     <string name="add_print_service_label" msgid="5356702546188981940">"ಸೇವೆಯನ್ನು ಸೇರಿಸು"</string>
     <string name="print_search_box_shown_utterance" msgid="7967404953901376090">"ಹುಡುಕಾಟ ಪೆಟ್ಟಿಗೆಯನ್ನು ತೋರಿಸಲಾಗಿದೆ"</string>
diff --git a/packages/PrintSpooler/res/values-sr/strings.xml b/packages/PrintSpooler/res/values-sr/strings.xml
index 012bbbc..9283d77 100644
--- a/packages/PrintSpooler/res/values-sr/strings.xml
+++ b/packages/PrintSpooler/res/values-sr/strings.xml
@@ -103,8 +103,8 @@
     <item msgid="3199660090246166812">"Водоравно"</item>
   </string-array>
     <string name="print_write_error_message" msgid="5787642615179572543">"Уписивање у датотеку није могуће"</string>
-    <string name="print_error_default_message" msgid="8602678405502922346">"Жао нам је, ово није успело. Покушајте поново."</string>
-    <string name="print_error_retry" msgid="1426421728784259538">"Покушајте поново"</string>
+    <string name="print_error_default_message" msgid="8602678405502922346">"Жао нам је, ово није успело. Пробајте поново."</string>
+    <string name="print_error_retry" msgid="1426421728784259538">"Пробајте поново"</string>
     <string name="print_error_printer_unavailable" msgid="8985614415253203381">"Овај штампач тренутно није доступан."</string>
     <string name="print_cannot_load_page" msgid="6179560924492912009">"Није успео приказ прегледа"</string>
     <string name="print_preparing_preview" msgid="3939930735671364712">"Припрема прегледа..."</string>
diff --git a/packages/SettingsLib/res/layout/restricted_switch_preference.xml b/packages/SettingsLib/res/layout/restricted_switch_preference.xml
index 89dc10b..bb1d906 100644
--- a/packages/SettingsLib/res/layout/restricted_switch_preference.xml
+++ b/packages/SettingsLib/res/layout/restricted_switch_preference.xml
@@ -20,7 +20,7 @@
     android:gravity="center_vertical"
     android:paddingStart="?android:attr/listPreferredItemPaddingStart"
     android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
-    android:background="?android:attr/activatedBackgroundIndicator"
+    android:background="?android:attr/selectableItemBackground"
     android:clipToPadding="false">
 
     <LinearLayout
diff --git a/packages/SettingsLib/res/values-af/strings.xml b/packages/SettingsLib/res/values-af/strings.xml
index 20e3f6f..295248c 100644
--- a/packages/SettingsLib/res/values-af/strings.xml
+++ b/packages/SettingsLib/res/values-af/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Wys snitgrense, kantlyne, ens."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Dwing RTL-uitlegrigting"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Dwing skermuitlegrigting na RTL vir alle locales"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Wys CPU-verbruik"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Skermlaag wys huidige CPU-gebruik"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forseer GPU-lewering"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Dwing gebruik van GPU vir 2D-tekening"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Dwing 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-am/strings.xml b/packages/SettingsLib/res/values-am/strings.xml
index e4455a4..bb50087 100644
--- a/packages/SettingsLib/res/values-am/strings.xml
+++ b/packages/SettingsLib/res/values-am/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"የቅንጥብ ገደቦች፣ ጠርዞች፣ ወዘተ አሳይ"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"የቀኝ-ወደ-ግራ አቀማመጥ አቅጣጫ አስገድድ"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"ለሁሉም አካባቢዎች የማያ ገጽ አቀማመጥ ከቀኝ-ወደ-ግራ እንዲሆን አስገድድ"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"የCPU አጠቃቀም አሳይ"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"የማያ ተደራቢ የአሁኑን የCPU አጠቃቀም  እያሳየ ነው።"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU ምላሽ መስጠትን አስገድድ"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"ለ2-ልኬት መሳል የGPU ስራ አስገድድ"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA አስገድድ"</string>
diff --git a/packages/SettingsLib/res/values-ar/strings.xml b/packages/SettingsLib/res/values-ar/strings.xml
index 24b51ec..829123c 100644
--- a/packages/SettingsLib/res/values-ar/strings.xml
+++ b/packages/SettingsLib/res/values-ar/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"عرض حدود وهوامش المقطع وما إلى ذلك."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"فرض اتجاه التنسيق ليكون من اليمين إلى اليسار"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"فرض اتجاه تنسيق الشاشة ليكون من اليمين إلى اليسار لجميع اللغات"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"‏عرض استخدام CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"‏عرض تراكب الشاشة لاستخدام CPU الحالي"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"‏فرض عرض رسومات GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"فرض استخدام وحدة معالجة الرسومات للرسم ثنائي الأبعاد"</string>
     <string name="force_msaa" msgid="7920323238677284387">"‏فرض 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-az-rAZ/strings.xml b/packages/SettingsLib/res/values-az-rAZ/strings.xml
index 5eb7a00..483770f 100644
--- a/packages/SettingsLib/res/values-az-rAZ/strings.xml
+++ b/packages/SettingsLib/res/values-az-rAZ/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Klip sərhədləri, boşluqları və s. göstər"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL düzən istiqamətinə məcbur edin"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Ekran düzən istiqamətini RTL üzərinə bütün yerli variantlar üçün məcbur edin"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU istifadəsini göstər"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Ekran örtüşməsi cari CPU istifadəsini göstərir"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU renderə məcbur edin"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d rəsm üçün GPU məcburi istifadə"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA məcbur edin"</string>
diff --git a/packages/SettingsLib/res/values-b+sr+Latn/strings.xml b/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
index 1acc445..5498580a 100644
--- a/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
+++ b/packages/SettingsLib/res/values-b+sr+Latn/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Prikaži granice klipa, margine itd."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Nametni smer rasporeda zdesna nalevo"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Nametni smer rasporeda ekrana zdesna nalevo za sve lokalitete"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Prik. upotrebu procesora"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Postav. element sa trenutnom upotrebom procesora"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Prinudni prikaz pom. GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Prinudno koristi GPU za 2D crtanje"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Nametni 4x MSAA"</string>
@@ -283,7 +281,7 @@
     <string name="enable_webview_multiprocess_desc" msgid="2485604010404197724">"Pokrećite WebView prikazivače zasebno"</string>
     <string name="select_webview_provider_title" msgid="4628592979751918907">"Primena WebView-a"</string>
     <string name="select_webview_provider_dialog_title" msgid="4370551378720004872">"Podesite primenu WebView-a"</string>
-    <string name="select_webview_provider_toast_text" msgid="5466970498308266359">"Ovaj izbor više nije važeći. Pokušajte ponovo."</string>
+    <string name="select_webview_provider_toast_text" msgid="5466970498308266359">"Ovaj izbor više nije važeći. Probajte ponovo."</string>
     <string name="convert_to_file_encryption" msgid="3060156730651061223">"Konvertuj u šifrovanje datoteka"</string>
     <string name="convert_to_file_encryption_enabled" msgid="2861258671151428346">"Konvertuj..."</string>
     <string name="convert_to_file_encryption_done" msgid="7859766358000523953">"Već se koristi šifrovanje datoteka"</string>
diff --git a/packages/SettingsLib/res/values-be-rBY/strings.xml b/packages/SettingsLib/res/values-be-rBY/strings.xml
index 0e3faca..f233db9 100644
--- a/packages/SettingsLib/res/values-be-rBY/strings.xml
+++ b/packages/SettingsLib/res/values-be-rBY/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Паказаць межы кліпу, палі і г. д."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Прымусовая раскладка справа налева"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Прымусовая раскладка экрана справа налева для ўсіх рэгіянальных налад"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Паказаць выкарыстанне ЦП"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Наклад на экран з бягучым выкарыстаннем працэсара"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Прымусовае адлюстраванне GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Прымусовае выкарыстанне GPU для 2-мерных чарцяжоў"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Прымусовае выкананне 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-bg/strings.xml b/packages/SettingsLib/res/values-bg/strings.xml
index 1d618d7..cd77792 100644
--- a/packages/SettingsLib/res/values-bg/strings.xml
+++ b/packages/SettingsLib/res/values-bg/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Показв. на границите на изрязване, полетата и др."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Принуд. оформл. отдясно наляво"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Принуд. оформл. на екрана отдясно наляво за вс. локали"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Употреба на процесора"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Наслагване на екрана показва употр. на процесора"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Принудително изобразяване"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Принуд. използв. на GPU за двуизмерно начертаване"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Задаване на 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-bn-rBD/strings.xml b/packages/SettingsLib/res/values-bn-rBD/strings.xml
index c094d27..a011fcf 100644
--- a/packages/SettingsLib/res/values-bn-rBD/strings.xml
+++ b/packages/SettingsLib/res/values-bn-rBD/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"ক্লিপ বাউন্ড, মার্জিন ইত্যাদি দেখান"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL লেআউট দিকনির্দেশ জোর দিন"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"সমস্ত স্থানের জন্য RTL এ স্ক্রীন লেআউট দিকনির্দেশে জোর দেয়"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU এর ব্যবহার দেখান"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"স্ক্রীন ওভারলে বর্তমান CPU ব্যবহার দেখাচ্ছে"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"জোর করে GPU রেন্ডারিং করুন"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2D অঙ্কনের জন্য GPU-এর ব্যবহারে জোর দিন"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA এ জোর দিন"</string>
diff --git a/packages/SettingsLib/res/values-bs-rBA/strings.xml b/packages/SettingsLib/res/values-bs-rBA/strings.xml
index b7a7d29..1df5ec9 100644
--- a/packages/SettingsLib/res/values-bs-rBA/strings.xml
+++ b/packages/SettingsLib/res/values-bs-rBA/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Prikaži granice isječka, margine itd."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Prisilno postavi raspored s desna u lijevo"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Prisilno postavi raspored ekrana s desna u lijevo za sve regije"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Prikaži korištenje CPU-a"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Trenutno korištenje CPU-a prikazuje se u nadsloju preko ekrana"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Prisili GPU iscrtavanje"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Prisilno koristite GPU za 2d crtanje"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Prinudno primjeni 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-ca/strings.xml b/packages/SettingsLib/res/values-ca/strings.xml
index 0d696d5..92e9005 100644
--- a/packages/SettingsLib/res/values-ca/strings.xml
+++ b/packages/SettingsLib/res/values-ca/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Mostra els límits de clips, els marges, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Força direcció dreta-esquerra"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Força direcció de pantalla dreta-esquerra en totes les llengües"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Mostra l\'ús de la CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Superposa l\'ús de la CPU a la pantalla"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Força acceleració GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Força l\'ús de GPU per a dibuixos en 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Força MSAA  4x"</string>
diff --git a/packages/SettingsLib/res/values-cs/strings.xml b/packages/SettingsLib/res/values-cs/strings.xml
index 486819a..8ec531c 100644
--- a/packages/SettingsLib/res/values-cs/strings.xml
+++ b/packages/SettingsLib/res/values-cs/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Zobrazit u výstřižku ohraničení, okraje atd."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Vynutit rozvržení zprava doleva"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Vynutit ve všech jazycích rozvržení obrazovky zprava doleva"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Zobrazit využití CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Překryvná vrstva s aktuálním využitím procesoru"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Vykreslování pomocí GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Vynutit použití GPU pro 2D vykreslování"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Vynutit 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-da/strings.xml b/packages/SettingsLib/res/values-da/strings.xml
index af4bf05..a65c58f 100644
--- a/packages/SettingsLib/res/values-da/strings.xml
+++ b/packages/SettingsLib/res/values-da/strings.xml
@@ -152,7 +152,7 @@
     <string name="clear_adb_keys" msgid="4038889221503122743">"Tilbagekald tilladelser for USB-fejlfinding"</string>
     <string name="bugreport_in_power" msgid="7923901846375587241">"Genvej til fejlrapporting"</string>
     <string name="bugreport_in_power_summary" msgid="1778455732762984579">"Vis en knap til oprettelse af fejlrapporter i menu for slukknap"</string>
-    <string name="keep_screen_on" msgid="1146389631208760344">"Undgå dvale"</string>
+    <string name="keep_screen_on" msgid="1146389631208760344">"Lås ikke"</string>
     <string name="keep_screen_on_summary" msgid="2173114350754293009">"Skærmen går ikke i dvale under opladning"</string>
     <string name="bt_hci_snoop_log" msgid="3340699311158865670">"Aktivér Bluetooth HCI snoop log"</string>
     <string name="bt_hci_snoop_log_summary" msgid="730247028210113851">"Gem alle Bluetooth HCI-pakker i en fil"</string>
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Vis grænser for klip, margener osv."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Tving læsning mod venstre"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Tving til højre mod venstre-layout for alle sprog"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Vis CPU-forbrug"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Skærmoverlejring viser det aktuelle CPU-forbrug"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Tving gengivelse af GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Gennemtving brug af GPU til 2D-tegning"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Tving 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-de/strings.xml b/packages/SettingsLib/res/values-de/strings.xml
index e4da20d..923eca1 100644
--- a/packages/SettingsLib/res/values-de/strings.xml
+++ b/packages/SettingsLib/res/values-de/strings.xml
@@ -39,7 +39,7 @@
     <string name="bluetooth_disconnecting" msgid="8913264760027764974">"Verbindung wird getrennt..."</string>
     <string name="bluetooth_connecting" msgid="8555009514614320497">"Verbindung wird hergestellt..."</string>
     <string name="bluetooth_connected" msgid="6038755206916626419">"Verbunden"</string>
-    <string name="bluetooth_pairing" msgid="1426882272690346242">"Pairing läuft…"</string>
+    <string name="bluetooth_pairing" msgid="1426882272690346242">"Kopplung läuft…"</string>
     <string name="bluetooth_connected_no_headset" msgid="2866994875046035609">"Verbunden (kein Telefon)"</string>
     <string name="bluetooth_connected_no_a2dp" msgid="4576188601581440337">"Verbunden (außer Audiomedien)"</string>
     <string name="bluetooth_connected_no_map" msgid="6504436917057479986">"Verbunden (ohne Nachrichtenzugriff)"</string>
@@ -70,12 +70,12 @@
     <string name="bluetooth_headset_profile_summary_use_for" msgid="8705753622443862627">"Für Audiosystem des Telefons verwenden"</string>
     <string name="bluetooth_opp_profile_summary_use_for" msgid="1255674547144769756">"Für Dateiübertragung verwenden"</string>
     <string name="bluetooth_hid_profile_summary_use_for" msgid="232727040453645139">"Für Eingabe verwenden"</string>
-    <string name="bluetooth_pairing_accept" msgid="6163520056536604875">"Pairing durchführen"</string>
-    <string name="bluetooth_pairing_accept_all_caps" msgid="6061699265220789149">"Pairing durchführen"</string>
+    <string name="bluetooth_pairing_accept" msgid="6163520056536604875">"Koppeln"</string>
+    <string name="bluetooth_pairing_accept_all_caps" msgid="6061699265220789149">"KOPPELN"</string>
     <string name="bluetooth_pairing_decline" msgid="4185420413578948140">"Abbrechen"</string>
-    <string name="bluetooth_pairing_will_share_phonebook" msgid="4982239145676394429">"Über das Pairing kann auf deine Kontakte und auf deinen Anrufverlauf zugegriffen werden, wenn eine Verbindung besteht."</string>
-    <string name="bluetooth_pairing_error_message" msgid="3748157733635947087">"Pairing mit <xliff:g id="DEVICE_NAME">%1$s</xliff:g> war nicht möglich."</string>
-    <string name="bluetooth_pairing_pin_error_message" msgid="8337234855188925274">"Pairing mit <xliff:g id="DEVICE_NAME">%1$s</xliff:g> war nicht möglich, weil die eingegebene PIN oder der Zugangscode falsch ist."</string>
+    <string name="bluetooth_pairing_will_share_phonebook" msgid="4982239145676394429">"Über die Kopplung kann auf deine Kontakte und auf deinen Anrufverlauf zugegriffen werden, wenn eine Verbindung besteht."</string>
+    <string name="bluetooth_pairing_error_message" msgid="3748157733635947087">"Kopplung mit <xliff:g id="DEVICE_NAME">%1$s</xliff:g> war nicht möglich."</string>
+    <string name="bluetooth_pairing_pin_error_message" msgid="8337234855188925274">"Kopplung mit <xliff:g id="DEVICE_NAME">%1$s</xliff:g> war nicht möglich, weil die eingegebene PIN oder der Zugangscode falsch ist."</string>
     <string name="bluetooth_pairing_device_down_error_message" msgid="7870998403045801381">"Kommunikation mit <xliff:g id="DEVICE_NAME">%1$s</xliff:g> ist nicht möglich."</string>
     <string name="bluetooth_pairing_rejected_error_message" msgid="1648157108520832454">"Verbindung wurde von <xliff:g id="DEVICE_NAME">%1$s</xliff:g> abgelehnt."</string>
     <string name="accessibility_wifi_off" msgid="1166761729660614716">"WLAN: aus"</string>
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Clip-Begrenzungen, Ränder usw. anzeigen"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL-Layout erzwingen"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"RTL-Bildschirmlayout für alle Sprachen erzwingen"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU-Auslastung anzeigen"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Bildschirm-Overlay mit aktueller CPU-Auslastung"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU-Rendering erzwingen"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Einsatz von GPU für 2D-Zeichnung erzwingen"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA erzwingen"</string>
diff --git a/packages/SettingsLib/res/values-el/strings.xml b/packages/SettingsLib/res/values-el/strings.xml
index 715b6c4..017fff8 100644
--- a/packages/SettingsLib/res/values-el/strings.xml
+++ b/packages/SettingsLib/res/values-el/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Εμφάνιση ορίων κλιπ, περιθωρίων, κλπ."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Επιβολή κατ. διάταξης RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Επιβολή διάταξης οθόν. RTL για όλες τις τοπ. ρυθμ."</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Προβολή χρήσης CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Επικάλυψη οθόνης για προβολή τρέχουσας χρήσης CPU"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Αναγκαστική απόδοση GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Αναγκαστική χρήση του GPU για σχέδιο 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Αναγκαστικά 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-en-rAU/strings.xml b/packages/SettingsLib/res/values-en-rAU/strings.xml
index f3bc540..8ed7444 100644
--- a/packages/SettingsLib/res/values-en-rAU/strings.xml
+++ b/packages/SettingsLib/res/values-en-rAU/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Show clip bounds, margins, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Force RTL layout direction"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Force screen layout direction to RTL for all locales"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Show CPU usage"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Screen overlay showing current CPU usage"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Force GPU rendering"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Force use of GPU for 2D drawing"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Force 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-en-rGB/strings.xml b/packages/SettingsLib/res/values-en-rGB/strings.xml
index f3bc540..8ed7444 100644
--- a/packages/SettingsLib/res/values-en-rGB/strings.xml
+++ b/packages/SettingsLib/res/values-en-rGB/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Show clip bounds, margins, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Force RTL layout direction"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Force screen layout direction to RTL for all locales"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Show CPU usage"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Screen overlay showing current CPU usage"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Force GPU rendering"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Force use of GPU for 2D drawing"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Force 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-en-rIN/strings.xml b/packages/SettingsLib/res/values-en-rIN/strings.xml
index f3bc540..8ed7444 100644
--- a/packages/SettingsLib/res/values-en-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-en-rIN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Show clip bounds, margins, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Force RTL layout direction"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Force screen layout direction to RTL for all locales"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Show CPU usage"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Screen overlay showing current CPU usage"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Force GPU rendering"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Force use of GPU for 2D drawing"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Force 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-es-rUS/strings.xml b/packages/SettingsLib/res/values-es-rUS/strings.xml
index 8f91cb7..cdfbc01 100644
--- a/packages/SettingsLib/res/values-es-rUS/strings.xml
+++ b/packages/SettingsLib/res/values-es-rUS/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Mostrar límites de recortes, márgenes, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forzar diseño der. a izq."</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Forzar diseño pantalla der.&gt;izq., cualquier idioma"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Mostrar el uso de CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Mostrar superposición en pantalla con uso actual de la CPU"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forzar representación GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forzar uso de GPU para dibujar en 2d"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forzar MSAA 4x"</string>
diff --git a/packages/SettingsLib/res/values-es/strings.xml b/packages/SettingsLib/res/values-es/strings.xml
index fc8da79..2a21d22 100644
--- a/packages/SettingsLib/res/values-es/strings.xml
+++ b/packages/SettingsLib/res/values-es/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Mostrar límites de vídeo, márgenes, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forzar dirección diseño RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Forzar dirección (RTL) para todas configuraciones"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Mostrar uso de la CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Suporponer el uso de la CPU en la pantalla"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forzar aceleración GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forzar uso de GPU para dibujos en 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forzar MSAA 4x"</string>
diff --git a/packages/SettingsLib/res/values-et-rEE/strings.xml b/packages/SettingsLib/res/values-et-rEE/strings.xml
index d28818b..644bf59 100644
--- a/packages/SettingsLib/res/values-et-rEE/strings.xml
+++ b/packages/SettingsLib/res/values-et-rEE/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Kuva klipi piirid, veerised jms"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Paremalt vasakule paig."</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Määra lokaatides ekraanipaig. paremalt vasakule"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU-kasutuse kuvamine"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Praegust CPU-kasutust kuvav ekraani ülekate"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Jõusta GPU renderdamine"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Jõusta GPU kasutam. kahemõõtmeliste jooniste puhul"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Jõusta 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-eu-rES/strings.xml b/packages/SettingsLib/res/values-eu-rES/strings.xml
index a975971..2217611 100644
--- a/packages/SettingsLib/res/values-eu-rES/strings.xml
+++ b/packages/SettingsLib/res/values-eu-rES/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Erakutsi kliparen mugak, marjinak, etab."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Behartu eskuin-ezker norabidea."</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Behartu pantaila-diseinuaren norabidea eskuin-ezker izatera eskualdeko ezarpen guztiekin."</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Erakutsi PUZ erabilera"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"PUZ erabilera erakusten duen pantaila-gainjartzea"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Behartu GPU errendatzea"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Behartu GPUa erabiltzera 2 dimentsioko marrazkietan."</string>
     <string name="force_msaa" msgid="7920323238677284387">"Behartu 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-fa/strings.xml b/packages/SettingsLib/res/values-fa/strings.xml
index 8f613aa..88ed7fa 100644
--- a/packages/SettingsLib/res/values-fa/strings.xml
+++ b/packages/SettingsLib/res/values-fa/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"نمایش مرزها، حاشیه‌ها و ویژگی‌های دیگر کلیپ."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"‏اجباری کردن چیدمان RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"‏اجباری کردن چیدمان RTL صفحه برای همه زبان‌ها"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"‏نمایش میزان استفاده از CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"‏هم‌پوشانی صفحه‌نمایش میزان استفاده از CPU فعلی"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"‏پردازش اجباری GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"‏استفاده اجباری از GPU برای طراحی دوم"</string>
     <string name="force_msaa" msgid="7920323238677284387">"‏اجبار 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-fi/strings.xml b/packages/SettingsLib/res/values-fi/strings.xml
index ea2a17f..d26fc05 100644
--- a/packages/SettingsLib/res/values-fi/strings.xml
+++ b/packages/SettingsLib/res/values-fi/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Näytä leikkeiden rajat, marginaalit jne."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Pakota RTL-ulkoasun suunta"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Pakota kaikkien kielten näytön ulkoasun suunnaksi RTL"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Näytä suorittimen käyttö"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Näytön peittokuva näyttää nykyisen suoritinkäytön"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Pakota GPU-hahmonnus"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Käytä GPU:ta 2d-piirtämiseen"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Pakota 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-fr-rCA/strings.xml b/packages/SettingsLib/res/values-fr-rCA/strings.xml
index 3001a69..caad889 100644
--- a/packages/SettingsLib/res/values-fr-rCA/strings.xml
+++ b/packages/SettingsLib/res/values-fr-rCA/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Afficher les limites, les marges de clip, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forcer orient. : g. à d."</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Forcer l\'orientation: g. à droite (toutes langues)"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Afficher mém. CPU utilisée"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Superposition écran indiquant mémoire CPU utilisée"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forcer le rendu GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forcer l\'utilisation du GPU pour le dessin 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forcer MSAA 4x"</string>
diff --git a/packages/SettingsLib/res/values-fr/strings.xml b/packages/SettingsLib/res/values-fr/strings.xml
index c00a030..91bbaf0 100644
--- a/packages/SettingsLib/res/values-fr/strings.xml
+++ b/packages/SettingsLib/res/values-fr/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Afficher les limites de coupe, les marges, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forcer droite à gauche"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Forcer orient. droite à gauche pour toutes langues"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Afficher mém. CPU utilisée"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Superposition écran indiquant mémoire CPU utilisée"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forcer le rendu GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forcer l\'utilisation du GPU pour le dessin 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forcer MSAA 4x"</string>
diff --git a/packages/SettingsLib/res/values-gl-rES/strings.xml b/packages/SettingsLib/res/values-gl-rES/strings.xml
index 03cf223..b717382 100644
--- a/packages/SettingsLib/res/values-gl-rES/strings.xml
+++ b/packages/SettingsLib/res/values-gl-rES/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Mostra os límites dos clips, as marxes, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forzar dirección do deseño RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Forza a dirección de pantalla a RTL (dereita a esquerda) para todas as configuración rexionais"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Mostrar uso da CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Superpoñer o uso da CPU na pantalla"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forzar procesamento GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forzar o uso de GPU para o debuxo en 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forzar MSAA 4x"</string>
diff --git a/packages/SettingsLib/res/values-gu-rIN/strings.xml b/packages/SettingsLib/res/values-gu-rIN/strings.xml
index 737af54..5605189 100644
--- a/packages/SettingsLib/res/values-gu-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-gu-rIN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"ક્લિપ બાઉન્ડ્સ, હાંસિયાં વગેરે બતાવો."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL લેઆઉટ દિશા નિર્દેશની ફરજ પાડો"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"તમામ લૉકેલ્સ માટે સ્ક્રીન લેઆઉટ દિશા નિર્દેશને RTL ની ફરજ પાડો"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU સંગ્રહ બતાવો"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"વર્તમાન CPU વપરાશ દર્શાવતું સ્ક્રીન ઓવરલે"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU રેન્ડરિંગની ફરજ પાડો"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2જા રેખાંકન માટે GPU ના ઉપયોગની ફરજ પાડો"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA ને ફરજ પાડો"</string>
diff --git a/packages/SettingsLib/res/values-hi/strings.xml b/packages/SettingsLib/res/values-hi/strings.xml
index efefca3..d579ec4 100644
--- a/packages/SettingsLib/res/values-hi/strings.xml
+++ b/packages/SettingsLib/res/values-hi/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"क्लिप सीमाएं, मार्जिन, आदि दिखाएं."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL लेआउट दिशा लागू करें"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"सभी भाषाओं के लिए स्क्रीन लेआउट दिशा को RTL रखें"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU उपयोग दिखाएं"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"स्‍क्रीन ओवरले वर्तमान CPU उपयोग को दिखा रहा है"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"बलपूर्वक GPU रेंडर करें"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d ड्रॉइंग के लिए GPU का बलपूर्वक उपयोग करें"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA को बाध्य करें"</string>
diff --git a/packages/SettingsLib/res/values-hr/strings.xml b/packages/SettingsLib/res/values-hr/strings.xml
index 8990536..94229b1 100644
--- a/packages/SettingsLib/res/values-hr/strings.xml
+++ b/packages/SettingsLib/res/values-hr/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Prikazuju se obrubi, margine itd. isječaka."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Nametni zdesna ulijevo"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Nametni smjer zdesna ulijevo za sve zemlje/jezike"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Prikaži upotrebu procesora"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Na zaslonu se prikazuje iskorištenost procesora."</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Nametni GPU renderiranje"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Nametni upotrebu GPU-a za 2D crteže"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Nametni 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-hu/strings.xml b/packages/SettingsLib/res/values-hu/strings.xml
index c557161..34f06e5 100644
--- a/packages/SettingsLib/res/values-hu/strings.xml
+++ b/packages/SettingsLib/res/values-hu/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Kliphatárok, margók stb. megjelenítése."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Elrendezés jobbról balra"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Elrendezés jobbról balra minden nyelvnél"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU-használat mutatása"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Képernyőfedvény a jelenlegi CPU-használattal"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU-megjelenítés"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"GPU használatának kényszerítése 2D rajzhoz"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA kényszerítése"</string>
diff --git a/packages/SettingsLib/res/values-hy-rAM/strings.xml b/packages/SettingsLib/res/values-hy-rAM/strings.xml
index 41556dc..9428e17 100644
--- a/packages/SettingsLib/res/values-hy-rAM/strings.xml
+++ b/packages/SettingsLib/res/values-hy-rAM/strings.xml
@@ -28,7 +28,7 @@
     <string name="wifi_disabled_wifi_failure" msgid="3081668066612876581">"WiFi կապի ձախողում"</string>
     <string name="wifi_disabled_password_failure" msgid="8659805351763133575">"Նույնականացման խնդիր"</string>
     <string name="wifi_not_in_range" msgid="1136191511238508967">"Ընդգրկույթից դուրս է"</string>
-    <string name="wifi_no_internet_no_reconnect" msgid="5724903347310541706">"Ավտոմատ միացում չի կատարվի"</string>
+    <string name="wifi_no_internet_no_reconnect" msgid="5724903347310541706">"Չի միանա ավտոմատ"</string>
     <string name="wifi_no_internet" msgid="3880396223819116454">"Ինտերնետ կապ չկա"</string>
     <string name="saved_network" msgid="4352716707126620811">"Պահել է հետևյալ օգտվողը՝ <xliff:g id="NAME">%1$s</xliff:g>"</string>
     <string name="connected_via_wfa" msgid="3805736726317410714">"Կապակցված է Wi‑Fi Օգնականի միջոցով"</string>
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Ցույց տալ կտրվածքի սահմանները, լուսանցքները և այլն"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Փոխել RTL-ի դասավորության ուղղությունը"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Դարձնել էկրանի դասավորության ուղղությունը դեպի RTL բոլոր լեզուների համար"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Ցույց տալ CPU-ի աշխատանքը"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Էկրանի վերադրումը ցույց է տալիս ընթացիկ CPU օգտագործումը"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Ստիպել GPU-ին մատուցել"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Ստիպողաբար GPU-ի օգտագործում 2-րդ պատկերի համար"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Ստիպել  4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-in/strings.xml b/packages/SettingsLib/res/values-in/strings.xml
index 039457d..a382e37 100644
--- a/packages/SettingsLib/res/values-in/strings.xml
+++ b/packages/SettingsLib/res/values-in/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Tampilkan batas klip, margin, dll."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Paksa arah tata letak RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Paksa arah tata letak layar RTL untuk semua lokal"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Tampilkan penggunaan CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Hamparan layar menampilkan penggunaan CPU saat ini"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Paksa perenderan GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Paksa penggunaan GPU untuk gambar 2d"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Force 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-is-rIS/strings.xml b/packages/SettingsLib/res/values-is-rIS/strings.xml
index a3126bf..44517a8 100644
--- a/packages/SettingsLib/res/values-is-rIS/strings.xml
+++ b/packages/SettingsLib/res/values-is-rIS/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Sýna skurðlínur, spássíur o.s.frv."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Þvinga umbrot frá hægri til vinstri"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Þvinga umbrot skjás frá hægri til vinstri fyrir alla tungumálskóða"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Sýna örgjörvanotkun"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Skjáyfirlögn sem sýnir núverandi örgjörvanotkun"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Þvinga skjákortsteiknun"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Þvinga notkun skjákorts fyrir tvívíða teikningu"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Þvinga 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-it/strings.xml b/packages/SettingsLib/res/values-it/strings.xml
index bff3bb7..7a32827 100644
--- a/packages/SettingsLib/res/values-it/strings.xml
+++ b/packages/SettingsLib/res/values-it/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Mostra limiti, margini dei clip e così via"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forza direzione layout RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Direzione layout schermo RTL per tutte le lingue"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Mostra utilizzo CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Overlay schermo che mostra l\'uso corrente della CPU"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forza rendering GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forza l\'uso della GPU per i disegni 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forza MSAA 4x"</string>
diff --git a/packages/SettingsLib/res/values-iw/strings.xml b/packages/SettingsLib/res/values-iw/strings.xml
index 4d794fc..2e85770 100644
--- a/packages/SettingsLib/res/values-iw/strings.xml
+++ b/packages/SettingsLib/res/values-iw/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"הצג גבולות קליפ, שוליים וכו\'"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"אלץ כיוון פריסה מימין לשמאל"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"אלץ כיוון פריסת מסך מימין לשמאל עבור כל השפות בכל המקומות"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"‏הצג את השימוש ב-CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"‏שכבת-על של מסך שמציגה את השימוש הנוכחי ב-CPU"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"‏אלץ עיבוד ב-GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"‏אכוף שימוש ב-GPU לשרטוט דו-מימדי"</string>
     <string name="force_msaa" msgid="7920323238677284387">"‏אלץ הפעלת 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-ja/strings.xml b/packages/SettingsLib/res/values-ja/strings.xml
index 4c4eed0..00e323c 100644
--- a/packages/SettingsLib/res/values-ja/strings.xml
+++ b/packages/SettingsLib/res/values-ja/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"クリップの境界線、マージンなどを表示"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTLレイアウト方向を使用"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"すべての言語/地域で画面レイアウト方向をRTLに設定"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU使用状況を表示"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"現在のCPU使用状況をオーバーレイ表示する"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPUレンダリングを使用"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2D描画にGPUを常に使用する"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAAを適用"</string>
diff --git a/packages/SettingsLib/res/values-ka-rGE/strings.xml b/packages/SettingsLib/res/values-ka-rGE/strings.xml
index 2142fa3..2b9e8cb 100644
--- a/packages/SettingsLib/res/values-ka-rGE/strings.xml
+++ b/packages/SettingsLib/res/values-ka-rGE/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"კლიპის საზღვრების, მინდვრების ჩვენება და ა.შ."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"მარჯვნიდან მარცხნივ განლაგების მიმართულების იძულება"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"ეკრანის RTL მიმართულებაზე იძულება ყველა ლოკალისათვის"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"ცენტრალური პროცესორის ჩატვირთვის ჩვენება"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"ეკრანის გადაფარვა აჩვენებს CPU ამჟამინდელ გამოყენებას"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU-აჩქარება"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"GPU-ის ძალით გამოყენება 2d drawing-თვის"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA-ს ჩართვა"</string>
diff --git a/packages/SettingsLib/res/values-kk-rKZ/strings.xml b/packages/SettingsLib/res/values-kk-rKZ/strings.xml
index e00e820..0037c11 100644
--- a/packages/SettingsLib/res/values-kk-rKZ/strings.xml
+++ b/packages/SettingsLib/res/values-kk-rKZ/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Қию шектерін, жиектерін, т.б көрсету."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Оңнан солға орналасу бағытына реттеу"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Экранның орналасу бағытын барлық тілдер үшін оңнан солға қарату"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU (орталық өңдеу бірлігі) қолданысы"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Экран бетіне ағымдағы CPU қолданысы көрсетіледі"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU рендерингін жылдамдату"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Графикалық процессорды 2d сызбаларына қолдану"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA қолдану"</string>
diff --git a/packages/SettingsLib/res/values-km-rKH/strings.xml b/packages/SettingsLib/res/values-km-rKH/strings.xml
index b1a27ce..235ea6a 100644
--- a/packages/SettingsLib/res/values-km-rKH/strings.xml
+++ b/packages/SettingsLib/res/values-km-rKH/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"បង្ហាញ​ការ​ភ្ជាប់​អត្ថបទ​សម្រង់ រឹម ។ល។"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"បង្ខំ​ទិស​ប្លង់ RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"បង្ខំ​ទិស​ប្លង់​អេក្រង់​ទៅកាន់ RTL សម្រាប់​មូលដ្ឋាន​ទាំងអស់"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"បង្ហាញ​​ការ​ប្រើ CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"អេក្រង់​ត្រួត​គ្នា​បង្ហាញ​​ការ​ប្រើ CPU បច្ចុប្បន្ន"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"បង្ខំ​ឲ្យ​បង្ហាញ GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"បង្ខំ​ប្រើ GPU សម្រាប់​ការ​គូរ​លើក​ទី​ពីរ"</string>
     <string name="force_msaa" msgid="7920323238677284387">"បង្ខំ 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-kn-rIN/strings.xml b/packages/SettingsLib/res/values-kn-rIN/strings.xml
index 312beae..b89bad8 100644
--- a/packages/SettingsLib/res/values-kn-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-kn-rIN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"ಕ್ಲಿಪ್‌ನ ಗಡಿಗಳು, ಅಂಚುಗಳು, ಇತ್ಯಾದಿ ತೋರಿಸು."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL ಲೇಔಟ್‌ ಪರಿಮಿತಿ ಬಲಗೊಳಿಸಿ"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"ಎಲ್ಲ ಸ್ಥಳಗಳಿಗಾಗಿ RTL ಗೆ ಸ್ಕ್ರೀನ್‌ ಲೇಔಟ್‌ ದಿಕ್ಕನ್ನು ಪ್ರಬಲಗೊಳಿಸಿ"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU ಬಳಕೆಯನ್ನು ತೋರಿಸು"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"ಪ್ರಸ್ತುತ CPU ಬಳಕೆಯನ್ನು ತೋರಿಸುತ್ತಿರುವ ಪರದೆಯ ಓವರ್‌ಲೇ"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU ನೀಡುವಿಕೆ ಬಲಗೊಳಿಸು"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d ಚಿತ್ರಕಲೆಗಾಗಿ GPU ಬಳಕೆ ಬಲಗೊಳಿಸಿ"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA ಪ್ರಬಲಗೊಳಿಸಿ"</string>
diff --git a/packages/SettingsLib/res/values-ko/strings.xml b/packages/SettingsLib/res/values-ko/strings.xml
index 72b5fe3..21bbc3f 100644
--- a/packages/SettingsLib/res/values-ko/strings.xml
+++ b/packages/SettingsLib/res/values-ko/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"클립 경계, 여백 등을 표시"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL 레이아웃 방향 강제 적용"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"모든 언어에 대해 화면 레이아웃 방향을 RTL로 강제 적용"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU 사용량 표시"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"현재 CPU 사용량 오버레이 표시"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU 렌더링 강제 설정"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2D 드로잉용으로 GPU 강제 사용"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA 강제 사용"</string>
diff --git a/packages/SettingsLib/res/values-ky-rKG/strings.xml b/packages/SettingsLib/res/values-ky-rKG/strings.xml
index a5386c8..ca716cae 100644
--- a/packages/SettingsLib/res/values-ky-rKG/strings.xml
+++ b/packages/SettingsLib/res/values-ky-rKG/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Клиптин чектерин, талааларын ж.б. көргөзүү"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Солдон оңго багытына мажбурлоо"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Экрандын жайгашуу багытын бардык тилдер үчүн Оңдон-солго кылуу"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU колдонулушун көрсөтүү"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Учурдагы CPU колдонулушун көрсөтүүчү экран катмары"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU иштетүүсүн мажбурлоо"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d тартуу үчүн GPU\'ну колдонууга мажбурлоо"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA мажбурлоо"</string>
diff --git a/packages/SettingsLib/res/values-lo-rLA/strings.xml b/packages/SettingsLib/res/values-lo-rLA/strings.xml
index 2dc4fd7..0108c2c 100644
--- a/packages/SettingsLib/res/values-lo-rLA/strings.xml
+++ b/packages/SettingsLib/res/values-lo-rLA/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"ສະແດງໜ້າປົກຄລິບ, ຂອບ ແລະອື່ນໆ."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"ບັງ​ຄັບ​ໃຫ້ຮູບຮ່າງຂຽນຈາກຂວາຫາຊ້າຍ"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"ບັງຄັບໃຫ້ຮູບຮ່າງໜ້າຈໍ ຂຽນຈາກຂວາໄປຊ້າຍ ສຳລັບທຸກພາສາ"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"ສະແດງການນຳໃຊ້ CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"ການວາງຊ້ອນໜ້າຈໍທີ່ສະແດງການນຳໃຊ້ CPU ໃນປັດຈຸບັນ"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"ບັງຄັບໃຊ້ GPU ປະມວນພາບ"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"ບັງຄັບໃຊ້ GPU ເພື່ອການແຕ້ມພາບ 2 ມິຕິ"</string>
     <string name="force_msaa" msgid="7920323238677284387">"ບັງຄັບໃຊ້ 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-lt/strings.xml b/packages/SettingsLib/res/values-lt/strings.xml
index 51fb7fa..154864f 100644
--- a/packages/SettingsLib/res/values-lt/strings.xml
+++ b/packages/SettingsLib/res/values-lt/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Rodyti iškarpų ribas, kraštines ir t. t."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Išdėst. iš dešin. į kairę"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Nust. visų lokalių ekran. išdėst. iš deš. į kairę"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Rodyti centr. proc. naud."</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Ekrano perdanga rodo dabartinį centr. proc. naud."</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Priverst. GPU atvaizd."</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Priverstinai naudoti GPU atvaizduojant 2D formatą"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Priverst. vykdyti 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-lv/strings.xml b/packages/SettingsLib/res/values-lv/strings.xml
index 9d4d055..df91cb1 100644
--- a/packages/SettingsLib/res/values-lv/strings.xml
+++ b/packages/SettingsLib/res/values-lv/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Rādīt klipu robežas, malas utt."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Virziens no labās uz kreiso (Obligāts) WL: 295"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Obl. izkārt. virz. no labās uz kr. pusi visām lok."</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Rādīt CPU lietojumu"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Ekrāna pārklājums ar aktuālo CPU lietojumu"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Piespiedu GPU render."</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Izmantot GPU atveidi divdimensiju zīmējumiem"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA piespiedu palaiš."</string>
diff --git a/packages/SettingsLib/res/values-mk-rMK/strings.xml b/packages/SettingsLib/res/values-mk-rMK/strings.xml
index 7521250..42bc33f 100644
--- a/packages/SettingsLib/res/values-mk-rMK/strings.xml
+++ b/packages/SettingsLib/res/values-mk-rMK/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Прикажи граници на клип, маргини, итн."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Сила на RTL за насока на слој"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Присилно постави насока на распоред на екран во РТЛ за сите локални стандарди"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Прикажи употреба на ЦПУ"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Прекривка на екран прикаж. употреба на тековен ЦПУ"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Присили рендерирање на GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Присилно користење на GPU за цртеж 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Сила 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-ml-rIN/strings.xml b/packages/SettingsLib/res/values-ml-rIN/strings.xml
index 5983992..a6017d5 100644
--- a/packages/SettingsLib/res/values-ml-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-ml-rIN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"ക്ലിപ്പ് ബൗണ്ടുകൾ, മാർജിനുകൾ തുടങ്ങിയവ ദൃശ്യമാക്കുക"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL ലേഔട്ട് ഡയറക്ഷൻ നിർബന്ധമാക്കുക"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"എല്ലാ ഭാഷകൾക്കുമായി സ്‌ക്രീൻ ലേഔട്ട് ഡയറക്ഷൻ RTL-ലേക്ക് നിർബന്ധമാക്കുക"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU ഉപയോഗം ദൃശ്യമാക്കുക"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"സ്ക്രീൻ ഓവർലേ നിലവിലെ CPU ഉപയോഗം ദൃശ്യമാക്കുന്നു"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU റെൻഡറിംഗ് ഫോഴ്സ്ചെയ്യുക"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d ഡ്രോയിംഗിനായുള്ള നിരബന്ധിത GPU ഉപയോഗം"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA നിർബന്ധമാക്കുക"</string>
diff --git a/packages/SettingsLib/res/values-mn-rMN/strings.xml b/packages/SettingsLib/res/values-mn-rMN/strings.xml
index 3d32aea..cb6327a 100644
--- a/packages/SettingsLib/res/values-mn-rMN/strings.xml
+++ b/packages/SettingsLib/res/values-mn-rMN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Клипийн зах, хязгаар зэргийг харуулах"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL байрлалын чиглэлийг хүчээр тогтоох"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Бүх локалын хувьд дэлгэцийн байрлалын чиглэлийг хүчээр RTL болгох"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU ашиглалтыг харуулах"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Дэлгэцийн давхцалаар одоогийн CPU ашиглалтыг харуулж байна"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Хүчээр GPU ашиглах"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"GPU-г 2d зурагт хүчээр ашиглах"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Хүчээр 4x MSAA ашиглах"</string>
diff --git a/packages/SettingsLib/res/values-mr-rIN/strings.xml b/packages/SettingsLib/res/values-mr-rIN/strings.xml
index e81b5ae..b6adb4f 100644
--- a/packages/SettingsLib/res/values-mr-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-mr-rIN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"क्लिप सीमा, समास इत्यादी दर्शवा."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL लेआउट दिशानिर्देशाची सक्ती करा"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"सर्व लोकॅलसाठी RTL स्क्रीन लेआउट दिशानिर्देशाची सक्ती करा"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU वापर दर्शवा"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"वर्तमान CPU वापर दर्शविणारे स्क्रीन आच्छादन"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU प्रस्तुतीस सक्ती करा"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d रेखांकनासाठी GPU च्या वापराची सक्ती करा"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA ची सक्ती करा"</string>
diff --git a/packages/SettingsLib/res/values-ms-rMY/strings.xml b/packages/SettingsLib/res/values-ms-rMY/strings.xml
index ccceb12..9886d3e 100644
--- a/packages/SettingsLib/res/values-ms-rMY/strings.xml
+++ b/packages/SettingsLib/res/values-ms-rMY/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Tunjukkan batas klip, margin dll."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Paksa arah reka letak RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Paksa arah reka letak skrin RTL bagi semua tempat peristiwa"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Tunjukkan penggunaan CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Tindihan skrin menunjukkan penggunaan semasa CPU"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Paksa pemaparan GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Paksa penggunaan GPU untuk lukisan 2d"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Paksa 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-my-rMM/strings.xml b/packages/SettingsLib/res/values-my-rMM/strings.xml
index 95711a4..935ad40 100644
--- a/packages/SettingsLib/res/values-my-rMM/strings.xml
+++ b/packages/SettingsLib/res/values-my-rMM/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"ဖြတ်ပိုင်းအနားသတ်များ၊ အနားများ စသဖြင့် ပြပါ။"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL ဖွဲ့စည်းပုံအညွှန်း မဖြစ်မနေလုပ်ပါ"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"လိုကယ်လ်အားလုံးအတွက် မျက်နှာပြင် ဖွဲ့စည်းပုံအညွှန်း မဖြစ်မနေလုပ်ရန်"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPUအသုံးပြုမှုအား ပြသရန်"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"လက်ရှိCPUအသုံးပြုမှုအားလုံး မျက်နှာပြင်တွင်ပြသမှု"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPUအား အတင်းအကျပ်ဖြစ်စေမည်"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"GPUကို ၂ဖက်မြင်ပုံဆွဲခြင်းအတွက် မဖြစ်မနေအသုံးပြုစေရန်"</string>
     <string name="force_msaa" msgid="7920323238677284387">"တွန်းအား ၄× MSAA"</string>
diff --git a/packages/SettingsLib/res/values-nb/strings.xml b/packages/SettingsLib/res/values-nb/strings.xml
index 69fcafc..18b6f60 100644
--- a/packages/SettingsLib/res/values-nb/strings.xml
+++ b/packages/SettingsLib/res/values-nb/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Vis kanter, marger osv."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Tving layoutretning for RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Tving RTL-retning på skjermen for alle språk"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Vis CPU-bruk"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Skjermoverlegg viser gjeldende CPU-bruk"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Tving GPU-gjengivelse"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Tving bruk av GPU for 2D-tegning"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Tving 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-ne-rNP/strings.xml b/packages/SettingsLib/res/values-ne-rNP/strings.xml
index 0a7cdab..478e19d 100644
--- a/packages/SettingsLib/res/values-ne-rNP/strings.xml
+++ b/packages/SettingsLib/res/values-ne-rNP/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"क्लिप सीमा, मार्जिन, इत्यादि देखाउनुहोस्।"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL लेआउट दिशामा जबर्जस्ती गर्नुहोस्"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"सबै लोकेलहरूको लागि RTLमा स्क्रिन लेआउट दिशामा जबर्जस्ती गर्नुहोस्"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU उपयोग देखाउनुहोस्"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"स्क्रिन ओभरले वर्तमान CPU प्रयोग देखाउँदै"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU रेन्डर गर्न जोड गर्नुहोस्"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d चित्र कोर्नका लागि GPU को प्रयोगलाई जोड दिनुहोस्"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA जोड गर्नुहोस्"</string>
diff --git a/packages/SettingsLib/res/values-nl/arrays.xml b/packages/SettingsLib/res/values-nl/arrays.xml
index e1bc58d..8f73bf9 100644
--- a/packages/SettingsLib/res/values-nl/arrays.xml
+++ b/packages/SettingsLib/res/values-nl/arrays.xml
@@ -50,12 +50,12 @@
   </string-array>
   <string-array name="hdcp_checking_titles">
     <item msgid="441827799230089869">"Nooit controleren"</item>
-    <item msgid="6042769699089883931">"Alleen controleren op DRM-inhoud"</item>
+    <item msgid="6042769699089883931">"Alleen controleren op DRM-content"</item>
     <item msgid="9174900380056846820">"Altijd controleren"</item>
   </string-array>
   <string-array name="hdcp_checking_summaries">
     <item msgid="505558545611516707">"HDCP-controle nooit gebruiken"</item>
-    <item msgid="3878793616631049349">"HDCP-controle alleen voor DRM-inhoud gebruiken"</item>
+    <item msgid="3878793616631049349">"HDCP-controle alleen voor DRM-content gebruiken"</item>
     <item msgid="45075631231212732">"HDCP-controle altijd gebruiken"</item>
   </string-array>
   <string-array name="select_logd_size_titles">
diff --git a/packages/SettingsLib/res/values-nl/strings.xml b/packages/SettingsLib/res/values-nl/strings.xml
index 27478a4..78e1ee1 100644
--- a/packages/SettingsLib/res/values-nl/strings.xml
+++ b/packages/SettingsLib/res/values-nl/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Clipgrenzen, marges en meer weergeven"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"V.r.n.l.-indelingsrichting afdwingen"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Schermindelingsrichting geforceerd instellen op v.r.n.l. voor alle talen"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU-gebruik weergeven"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Schermoverlay met huidig CPU-gebruik"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU-rendering afdwingen"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Gebruik van GPU voor 2D-tekening forceren"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA forceren"</string>
diff --git a/packages/SettingsLib/res/values-pa-rIN/strings.xml b/packages/SettingsLib/res/values-pa-rIN/strings.xml
index d06a88f..b678aac 100644
--- a/packages/SettingsLib/res/values-pa-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-pa-rIN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"ਕਲਿਪ ਬਾਊਂਡਸ, ਮਾਰਜਿਨ ਆਦਿ ਦਿਖਾਓ"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL ਲੇਆਉਟ ਦਿਸ਼ਾ ਤੇ ਜ਼ੋਰ ਪਾਓ"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"ਸਾਰੇ ਸਥਾਨਾਂ ਲਈ RTL ਵੱਲ ਸਕ੍ਰੀਨ ਲੇਆਉਟ ਦਿਸ਼ਾ ਤੇ ਜ਼ੋਰ ਪਾਓ"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU ਵਰਤੋਂ ਦਿਖਾਓ"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"ਸਕ੍ਰੀਨ ਓਵਰਲੇ ਵਰਤਮਾਨ CPU ਵਰਤੋਂ ਦਿਖਾ ਰਿਹਾ ਹੈ"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU ਪ੍ਰਗਟਾਅ ਤੇ ਜ਼ੋਰ ਪਾਓ"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d ਡ੍ਰਾਇੰਗ ਲਈ GPU ਦੀ ਵਰਤੋਂ ਤੇ ਜ਼ੋਰ ਪਾਓ"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA ਤੇ ਜ਼ੋਰ ਪਾਓ"</string>
diff --git a/packages/SettingsLib/res/values-pl/strings.xml b/packages/SettingsLib/res/values-pl/strings.xml
index 3c09335..77a23f2 100644
--- a/packages/SettingsLib/res/values-pl/strings.xml
+++ b/packages/SettingsLib/res/values-pl/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Pokaż granice przycięcia, marginesy itd."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Układ od prawej do lewej"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Wymuś wszędzie układ ekranu od prawej do lewej"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Pokaż użycie procesora"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Nakładka na ekranie pokazująca użycie procesora"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Renderowanie na GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Wymuszaj użycie GPU do rysowania 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Wymuś 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-pt-rBR/strings.xml b/packages/SettingsLib/res/values-pt-rBR/strings.xml
index 1b46c84..588ca67 100644
--- a/packages/SettingsLib/res/values-pt-rBR/strings.xml
+++ b/packages/SettingsLib/res/values-pt-rBR/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Mostrar limites de corte, margens, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forçar dir. layout (RTL)"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Forçar direção do layout (RTL) p/ todas as local."</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Mostrar o uso da CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Sobreposição de tela que mostra o uso da CPU atual"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forçar renderização GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forçar uso da GPU para desenho em 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forçar 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-pt-rPT/strings.xml b/packages/SettingsLib/res/values-pt-rPT/strings.xml
index c8be0da..763cb70 100644
--- a/packages/SettingsLib/res/values-pt-rPT/strings.xml
+++ b/packages/SettingsLib/res/values-pt-rPT/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Apresentar limites de clipes, margens, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forçar dir. do esq. RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Forçar dir. do esq. do ecrã p. RTL tds os locais"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Mostrar utilização da CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Sobrep. de ecrã que mostra a utiliz. atual da CPU"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forçar composição GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forçar a utilização de GPU para desenho 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forçar 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-pt/strings.xml b/packages/SettingsLib/res/values-pt/strings.xml
index 1b46c84..588ca67 100644
--- a/packages/SettingsLib/res/values-pt/strings.xml
+++ b/packages/SettingsLib/res/values-pt/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Mostrar limites de corte, margens, etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Forçar dir. layout (RTL)"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Forçar direção do layout (RTL) p/ todas as local."</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Mostrar o uso da CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Sobreposição de tela que mostra o uso da CPU atual"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forçar renderização GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forçar uso da GPU para desenho em 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forçar 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-ro/strings.xml b/packages/SettingsLib/res/values-ro/strings.xml
index b022163..6a2122a 100644
--- a/packages/SettingsLib/res/values-ro/strings.xml
+++ b/packages/SettingsLib/res/values-ro/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Afișați limitele clipului, marginile etc."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Direcție aspect dreapta - stânga"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Direcție obligatorie aspect ecran dreapta - stânga"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Afișați utiliz. procesor"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Suprapunere care indică utilizare curentă procesor"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Forțați redarea cu GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Forțați utilizarea GPU pentru desen în 2D"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Forțați MSAA 4x"</string>
diff --git a/packages/SettingsLib/res/values-ru/strings.xml b/packages/SettingsLib/res/values-ru/strings.xml
index 3a4e85b..a6d0cba 100644
--- a/packages/SettingsLib/res/values-ru/strings.xml
+++ b/packages/SettingsLib/res/values-ru/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Показывать границы клипа, поля и т. д."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Написание справа налево"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Включить написание справа налево для всех языков"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Показывать загрузку ЦП"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Экран, показывающий текущую загрузку ЦП"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU-ускорение"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Всегда использовать GPU для двухмерного рисования"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Включить 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-si-rLK/strings.xml b/packages/SettingsLib/res/values-si-rLK/strings.xml
index 24779b3..e415544 100644
--- a/packages/SettingsLib/res/values-si-rLK/strings.xml
+++ b/packages/SettingsLib/res/values-si-rLK/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"ක්ලිප් සීමා, මායිම්, ආදිය පෙන්වන්න."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"බල RTL පිරිසැලසුම් දිශාව"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"සියලු පෙදෙසි සඳහා RTL වෙත බල තිර පිරිසැලසුම"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU භාවිතය පෙන්වන්න"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"තීර උඩැතිරිය වත්මන් CPU භාවිතය පෙන්නුම් කරයි"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU විදහාපෑම බලකරන්න"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d ඇඳීම් සඳහා GPU බලයෙන් භාවිතා කරන්න"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA බල කරන්න"</string>
diff --git a/packages/SettingsLib/res/values-sk/strings.xml b/packages/SettingsLib/res/values-sk/strings.xml
index e8db85b..7e636fe7 100644
--- a/packages/SettingsLib/res/values-sk/strings.xml
+++ b/packages/SettingsLib/res/values-sk/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Zobraziť vo výstrižku ohraničenie, okraje a pod."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Rozloženia sprava doľava"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Vynútiť pre všetky jazyky rozloženie obrazovky sprava doľava"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Zobraziť využitie CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Prekryvná vrstva s aktuálnym využitím procesora"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Vykresľovat pomocou GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Používať GPU na dvojrozmerné vykresľovanie"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Vynútiť 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-sl/strings.xml b/packages/SettingsLib/res/values-sl/strings.xml
index d908e6d..78fa3fd 100644
--- a/packages/SettingsLib/res/values-sl/strings.xml
+++ b/packages/SettingsLib/res/values-sl/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Pokaži meje obrezovanja, obrobe ipd."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Vsili od desne proti levi"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Vsili smer postavitve na zaslonu od desne proti levi za vse jezike"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Prikaži uporabo CPE-ja"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Prekrivanje zaslona prikazuje tren. uporabo CPE-ja"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Vsili upodabljanje z GPE-jem"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Za risanje 2D vsili uporabo grafičnega procesorja"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Vsili 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-sq-rAL/strings.xml b/packages/SettingsLib/res/values-sq-rAL/strings.xml
index 69318a1..ad4cf61 100644
--- a/packages/SettingsLib/res/values-sq-rAL/strings.xml
+++ b/packages/SettingsLib/res/values-sq-rAL/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Shfaq konturet e klipit, hapësirat etj."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Detyro drejtimin e shkrimit nga e djathta në të majtë"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Ndrysho me detyrim drejtimin e planit të ekranit nga e djathta në të majtë për të gjitha vendet"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Shfaq përdorimin e CPU-së"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Mbivendosja e ekranit tregon përdorimin e CPU-së"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Detyro interpretimin e GPU-së"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Detyro përdorimin e GPU-së për vizatimin e dytë"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Detyro 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-sr/strings.xml b/packages/SettingsLib/res/values-sr/strings.xml
index 459d92e..02eb615 100644
--- a/packages/SettingsLib/res/values-sr/strings.xml
+++ b/packages/SettingsLib/res/values-sr/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Прикажи границе клипа, маргине итд."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Наметни смер распореда здесна налево"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Наметни смер распореда екрана здесна налево за све локалитете"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Прик. употребу процесора"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Постав. елемент са тренутном употребом процесора"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Принудни приказ пом. GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Принудно користи GPU за 2D цртање"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Наметни 4x MSAA"</string>
@@ -283,7 +281,7 @@
     <string name="enable_webview_multiprocess_desc" msgid="2485604010404197724">"Покрећите WebView приказиваче засебно"</string>
     <string name="select_webview_provider_title" msgid="4628592979751918907">"Примена WebView-а"</string>
     <string name="select_webview_provider_dialog_title" msgid="4370551378720004872">"Подесите примену WebView-а"</string>
-    <string name="select_webview_provider_toast_text" msgid="5466970498308266359">"Овај избор више није важећи. Покушајте поново."</string>
+    <string name="select_webview_provider_toast_text" msgid="5466970498308266359">"Овај избор више није важећи. Пробајте поново."</string>
     <string name="convert_to_file_encryption" msgid="3060156730651061223">"Конвертуј у шифровање датотека"</string>
     <string name="convert_to_file_encryption_enabled" msgid="2861258671151428346">"Конвертуј..."</string>
     <string name="convert_to_file_encryption_done" msgid="7859766358000523953">"Већ се користи шифровање датотека"</string>
diff --git a/packages/SettingsLib/res/values-sv/strings.xml b/packages/SettingsLib/res/values-sv/strings.xml
index d52882a..a936c3e 100644
--- a/packages/SettingsLib/res/values-sv/strings.xml
+++ b/packages/SettingsLib/res/values-sv/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Visa gränser för videoklipp, marginaler m.m."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Tvinga fram RTL-layout"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Tvinga fram RTL-skärmlayout (hö–vä) för alla språk"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Visa CPU-användning"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Överlägg på skärmen med aktuell CPU-användning"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Framtvinga GPU-rendering"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Tvingad användning av GPU för 2D-ritning"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Force 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-sw/strings.xml b/packages/SettingsLib/res/values-sw/strings.xml
index 6f2e0cb..25f79b6 100644
--- a/packages/SettingsLib/res/values-sw/strings.xml
+++ b/packages/SettingsLib/res/values-sw/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Onyesha mipaka ya picha, kingo, nk."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Lazimisha uelekezaji wa muundo wa RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Lazimisha uelekezaji wa muundo wa skrini kwa RTL kwa lugha zote"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Onyesha matumizi ya CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Kuegeshwa kwa skrini ikionyesha matumizi ya sasa ya CPU"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Lazimisha kutungiliza  GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Lazimisha matumizi ya GPU kwa uchoraji wa 2d"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Lazimisha 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-ta-rIN/strings.xml b/packages/SettingsLib/res/values-ta-rIN/strings.xml
index 5f218e0..9e9e92c 100644
--- a/packages/SettingsLib/res/values-ta-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-ta-rIN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"கிளிப் எல்லைகள், ஓரங்கள், மேலும் பலவற்றைக் காட்டு"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL தளவமைப்பின் திசையை வலியுறுத்து"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"எல்லா மொழிகளுக்கும் திரையின் தளவமைப்பு திசையை RTL க்கு மாற்று"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU பயன்பாட்டைக் காட்டு"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"தற்போதைய CPU பயன்பாட்டைக் காட்டும் திரை மேலடுக்கு"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU காட்சியாக்கத்தை வலியுறுத்து"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d வரைபடத்திற்கு GPU பயன்பாட்டை வலியுறுத்து"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA ஐ வலியுறுத்து"</string>
diff --git a/packages/SettingsLib/res/values-te-rIN/strings.xml b/packages/SettingsLib/res/values-te-rIN/strings.xml
index 0bd77f7..27f8e09 100644
--- a/packages/SettingsLib/res/values-te-rIN/strings.xml
+++ b/packages/SettingsLib/res/values-te-rIN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"క్లిప్ సరిహద్దులు, అంచులు మొ. చూపు"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"RTL లేఅవుట్ దిశను నిర్భందం చేయండి"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"అన్ని లొకేల్‌ల కోసం RTLకి స్క్రీన్ లేఅవుట్ దిశను నిర్భందించు"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU వినియోగాన్ని చూపు"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"ప్రస్తుత CPU వినియోగాన్ని చూపేలా స్క్రీన్ అతివ్యాప్తి చేయబడుతుంది"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"నిర్బంధంగా GPU భాషాంతరీకరణ"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2d డ్రాయింగ్ కోసం GPU నిర్భంద వినియోగం"</string>
     <string name="force_msaa" msgid="7920323238677284387">"నిర్భందం 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-th/strings.xml b/packages/SettingsLib/res/values-th/strings.xml
index d8ee2f3..6005972 100644
--- a/packages/SettingsLib/res/values-th/strings.xml
+++ b/packages/SettingsLib/res/values-th/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"แสดงหน้าปกคลิป ขอบ ฯลฯ"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"บังคับทิศทางการจัดวาง RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"บังคับทิศทางการจัดวางหน้าจอเป็น RTL สำหรับทุกภาษา"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"แสดงการใช้ CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"การวางซ้อนหน้าจอที่แสดงการใช้ CPU ในปัจจุบัน"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"เร่งการแสดงผลของ GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"ต้องใช้ GPU สำหรับการวาดภาพ 2 มิติ"</string>
     <string name="force_msaa" msgid="7920323238677284387">"บังคับใช้ 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-tl/strings.xml b/packages/SettingsLib/res/values-tl/strings.xml
index 9b9d26f..e9feded 100644
--- a/packages/SettingsLib/res/values-tl/strings.xml
+++ b/packages/SettingsLib/res/values-tl/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Ipakita ang mga hangganan ng clip, margin, atbp."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Force RTL layout dir."</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Force screen layout dir. sa RTL sa lahat ng lokal"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Ipakita paggamit ng CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Ipinapakita ng screen overlay ang paggamit ng CPU ngayon"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Ipilit ang pag-render ng GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Sapilitang paggamit sa GPU para sa 2d na pagguhit"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Puwersahin ang 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-tr/strings.xml b/packages/SettingsLib/res/values-tr/strings.xml
index e3e50d5..0e73b7b 100644
--- a/packages/SettingsLib/res/values-tr/strings.xml
+++ b/packages/SettingsLib/res/values-tr/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Klip sınırlarını, kenar boşluklarını vb. göster"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Sağdan sola düzenini zorla"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Tüm yerel ayarlar için sağdan sola ekran düzenini zorlar"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"CPU kullanımını göster"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Mevcut CPU kullanımını gösteren yer paylaşımı"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU oluşturmayı zorla"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"2D çizimde GPU kullanımını zorla"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAA\'yı zorla"</string>
diff --git a/packages/SettingsLib/res/values-uk/strings.xml b/packages/SettingsLib/res/values-uk/strings.xml
index b1fbef5..1015e1c 100644
--- a/packages/SettingsLib/res/values-uk/strings.xml
+++ b/packages/SettingsLib/res/values-uk/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Показувати межі роликів, поля тощо"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Макет письма справа наліво"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Застосовувати макет письма справа наліво для всіх мов"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Показати використання ЦП"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Показувати на екрані поточне використання ЦП"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Примусова візуалізація GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Примусово використовувати GPU для 2D-малювання"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Примус. запустити 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-ur-rPK/strings.xml b/packages/SettingsLib/res/values-ur-rPK/strings.xml
index 322b468..61dc5ab 100644
--- a/packages/SettingsLib/res/values-ur-rPK/strings.xml
+++ b/packages/SettingsLib/res/values-ur-rPK/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"کلپ باؤنڈز، حاشیے وغیرہ دکھائیں"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"‏RTL لے آؤٹ سمت زبردستی نافذ کریں"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"‏سبھی زبانوں کیلئے اسکرین لے آؤٹ کی سمت کو RTL پر مجبور کریں"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"‏CPU استعمال دکھائیں"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"‏موجودہ CPU استعمال دکھانے والا اسکرین اوورلے"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"‏GPU رینڈرنگ زبردستی نافذ کریں"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"‏2D ڈرائنگ کیلئے GPU کا استعمال زبردستی نافذ کریں"</string>
     <string name="force_msaa" msgid="7920323238677284387">"‏4x MSAA زبردستی نافذ کریں"</string>
diff --git a/packages/SettingsLib/res/values-uz-rUZ/strings.xml b/packages/SettingsLib/res/values-uz-rUZ/strings.xml
index 09ac4b1..a6f9ab8 100644
--- a/packages/SettingsLib/res/values-uz-rUZ/strings.xml
+++ b/packages/SettingsLib/res/values-uz-rUZ/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Klip, maydon va h.k. chegaralarini ko‘rsatish"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"O‘ngdan chapga qarab yozish"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Barcha tillarda o‘ngdan chapga qarab yozish"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"MP yuklanishini ko‘rsatish"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Joriy MP yuklanishini ko‘rsatuvchi ekran"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"GPU yordamida tezlatish"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Ikki o‘lchamli chizma uchun doim GPU ishlatilsin"</string>
     <string name="force_msaa" msgid="7920323238677284387">"4x MSAAni yoqish"</string>
diff --git a/packages/SettingsLib/res/values-vi/strings.xml b/packages/SettingsLib/res/values-vi/strings.xml
index fa41b45..f09e0e5 100644
--- a/packages/SettingsLib/res/values-vi/strings.xml
+++ b/packages/SettingsLib/res/values-vi/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Hiển thị viền đoạn video, lề, v.v.."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Buộc hướng bố cục RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Buộc hướng bố cục màn hình RTL cho tất cả ngôn ngữ"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Hiển thị mức sử dụng CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Lớp phủ màn hình hiển thị mức sử dụng CPU hiện tại"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Bắt buộc kết xuất GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Bắt buộc sử dụng GPU cho bản vẽ 2d"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Bắt buộc 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-zh-rCN/strings.xml b/packages/SettingsLib/res/values-zh-rCN/strings.xml
index 152e78e..7268dcd 100644
--- a/packages/SettingsLib/res/values-zh-rCN/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rCN/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"显示剪辑边界、边距等。"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"强制使用从右到左的布局方向"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"强制将所有语言区域的屏幕布局方向改为从右到左"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"显示 CPU 使用情况"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"屏幕叠加层显示当前 CPU 使用情况"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"强制进行 GPU 渲染"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"强制使用 GPU 进行 2D 绘图"</string>
     <string name="force_msaa" msgid="7920323238677284387">"强制启用 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-zh-rHK/strings.xml b/packages/SettingsLib/res/values-zh-rHK/strings.xml
index f6c2f93..ac9de74 100644
--- a/packages/SettingsLib/res/values-zh-rHK/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rHK/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"顯示剪輯範圍、邊界等"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"強制使用從右至左的版面配置方向"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"強制將所有語言代碼的畫面配置方向改為從右至左"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"顯示 CPU 使用量"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"在螢幕上重疊顯示目前的 CPU 使用量"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"強制使用 GPU 轉譯"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"強制使用 GPU 進行 2D 繪圖"</string>
     <string name="force_msaa" msgid="7920323238677284387">"強制 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-zh-rTW/strings.xml b/packages/SettingsLib/res/values-zh-rTW/strings.xml
index df9238a..f17b523 100644
--- a/packages/SettingsLib/res/values-zh-rTW/strings.xml
+++ b/packages/SettingsLib/res/values-zh-rTW/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"顯示剪輯範圍、邊界等。"</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"強制使用從右至左版面配置方向"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"強制將所有語言代碼的畫面配置方向改為從右至左"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"顯示 CPU 使用量"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"在螢幕上方顯示目前的 CPU 使用量"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"強制使用 GPU 轉譯"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"強制使用 GPU 進行 2D 繪圖"</string>
     <string name="force_msaa" msgid="7920323238677284387">"強制 4x MSAA"</string>
diff --git a/packages/SettingsLib/res/values-zu/strings.xml b/packages/SettingsLib/res/values-zu/strings.xml
index fc9e81f..1fc551f 100644
--- a/packages/SettingsLib/res/values-zu/strings.xml
+++ b/packages/SettingsLib/res/values-zu/strings.xml
@@ -234,8 +234,6 @@
     <string name="debug_layout_summary" msgid="2001775315258637682">"Bonisa imikhawulo, imiphetho, njll, yesiqeshana."</string>
     <string name="force_rtl_layout_all_locales" msgid="2259906643093138978">"Phoqelela isikhombisi-ndlela sesakhiwo se-RTL"</string>
     <string name="force_rtl_layout_all_locales_summary" msgid="9192797796616132534">"Phoqelela isikhombisi-ndlela sesikrini ku-RTL kuzo zonke izifunda"</string>
-    <string name="show_cpu_usage" msgid="2389212910758076024">"Bonisa ukusebenzisa i-CPU"</string>
-    <string name="show_cpu_usage_summary" msgid="2113341923988958266">"Imbondela yesikrini ibonisa ukusetshenziswa kwe-CPU okwamanje"</string>
     <string name="force_hw_ui" msgid="6426383462520888732">"Phoqa ukunikeza i-GPU"</string>
     <string name="force_hw_ui_summary" msgid="5535991166074861515">"Phoqelela ukusetshenziswa kwe-GPU ngomdwebo we-2d"</string>
     <string name="force_msaa" msgid="7920323238677284387">"Phoqelela i-4x MSAA"</string>
diff --git a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
index 4bcbea7..a332332 100755
--- a/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/bluetooth/BluetoothEventManager.java
@@ -268,16 +268,16 @@
             if (cachedDevice == null) {
                 Log.w(TAG, "CachedBluetoothDevice for device " + device +
                         " not found, calling readPairedDevices().");
-                if (!readPairedDevices()) {
-                    Log.e(TAG, "Got bonding state changed for " + device +
-                            ", but we have no record of that device.");
-                    return;
+                if (readPairedDevices()) {
+                    cachedDevice = mDeviceManager.findDevice(device);
                 }
-                cachedDevice = mDeviceManager.findDevice(device);
+
                 if (cachedDevice == null) {
-                    Log.e(TAG, "Got bonding state changed for " + device +
-                            ", but device not added in cache.");
-                    return;
+                    Log.w(TAG, "Got bonding state changed for " + device +
+                            ", but we have no record of that device.");
+
+                    cachedDevice = mDeviceManager.addDevice(mLocalAdapter, mProfileManager, device);
+                    dispatchDeviceAdded(cachedDevice);
                 }
             }
 
diff --git a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
index a514ebb..c6b9c1a0 100644
--- a/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
+++ b/packages/SettingsLib/src/com/android/settingslib/wifi/AccessPoint.java
@@ -288,7 +288,7 @@
 
     public boolean matches(WifiConfiguration config) {
         if (config.isPasspoint() && mConfig != null && mConfig.isPasspoint()) {
-            return config.FQDN.equals(mConfig.providerFriendlyName);
+            return config.FQDN.equals(mConfig.FQDN);
         } else {
             return ssid.equals(removeDoubleQuotes(config.SSID))
                     && security == getSecurity(config)
diff --git a/packages/SystemUI/AndroidManifest.xml b/packages/SystemUI/AndroidManifest.xml
index f1545c1..02518f2 100644
--- a/packages/SystemUI/AndroidManifest.xml
+++ b/packages/SystemUI/AndroidManifest.xml
@@ -223,12 +223,6 @@
                 android:permission="android.permission.BIND_WALLPAPER"
                 android:exported="true" />
 
-        <receiver android:name=".BootReceiver" androidprv:systemUserOnly="true">
-            <intent-filter android:priority="1000">
-                <action android:name="android.intent.action.BOOT_COMPLETED" />
-            </intent-filter>
-        </receiver>
-
         <activity android:name=".tuner.TunerActivity"
                   android:enabled="false"
                   android:icon="@drawable/tuner"
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginInstanceManager.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginInstanceManager.java
index f98667d..75a5434 100644
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginInstanceManager.java
+++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/PluginInstanceManager.java
@@ -114,7 +114,9 @@
 
     public void disableAll() {
         ArrayList<PluginInfo> plugins = new ArrayList<>(mPluginHandler.mPlugins);
-        plugins.forEach(this::disable);
+        for (int i = 0; i < plugins.size(); i++) {
+            disable(plugins.get(i));
+        }
     }
 
     private void disable(PluginInfo info) {
diff --git a/packages/SystemUI/res/values-af/strings.xml b/packages/SystemUI/res/values-af/strings.xml
index 7d3eb8d..82229e3 100644
--- a/packages/SystemUI/res/values-af/strings.xml
+++ b/packages/SystemUI/res/values-af/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> waarskuwing"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Werkmodus"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Aandbeligting"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Aandbeligting is aan, tik om af te skakel"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Aandbeligting is af, tik om aan te skakel"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Geen onlangse items nie"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Jy het alles toegemaak"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Programinligting"</string>
diff --git a/packages/SystemUI/res/values-am/strings.xml b/packages/SystemUI/res/values-am/strings.xml
index fb73729..35ed921 100644
--- a/packages/SystemUI/res/values-am/strings.xml
+++ b/packages/SystemUI/res/values-am/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"የ<xliff:g id="DATA_LIMIT">%s</xliff:g> ማስጠንቀቂያ"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"የሥራ ሁነታ"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"የምሽት ብርሃን"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"የምሽት ብርሃን በርቷል፣ ለማጥፋት መታ ያድርጉ"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"የምሽት ብርሃን ጠፍቷል፣ ለማብራት መታ ያድርጉ"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"ምንም የቅርብ ጊዜ ንጥሎች የሉም"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"ሁሉንም ነገር አጽድተዋል"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"የመተግበሪያ መረጃ"</string>
diff --git a/packages/SystemUI/res/values-ar/strings.xml b/packages/SystemUI/res/values-ar/strings.xml
index b7bb97e..5fc9976 100644
--- a/packages/SystemUI/res/values-ar/strings.xml
+++ b/packages/SystemUI/res/values-ar/strings.xml
@@ -327,8 +327,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"تحذير <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"وضع العمل"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"إضاءة ليلية"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"الإضاءة الليلية قيد العمل، انقر لإيقافها."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"الإضاءة الليلية قيد الإيقاف، انقر لتشغيلها."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"ليست هناك عناصر تم استخدامها مؤخرًا"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"لقد محوتَ كل شيء"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"معلومات التطبيق"</string>
diff --git a/packages/SystemUI/res/values-az-rAZ/strings.xml b/packages/SystemUI/res/values-az-rAZ/strings.xml
index ee98b8f..451f205 100644
--- a/packages/SystemUI/res/values-az-rAZ/strings.xml
+++ b/packages/SystemUI/res/values-az-rAZ/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> xəbərdarlığı"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"İş rejimi"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Gecə işığı"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Gecə işığı aktivdir, deaktiv etmək üçün tıklayın"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Gecə işığı deaktivdir, aktiv etmək üçün tıklayın"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Son elementlər yoxdur"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Hərşeyi təmizlədiniz"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Tətbiq haqqında"</string>
diff --git a/packages/SystemUI/res/values-b+sr+Latn/strings.xml b/packages/SystemUI/res/values-b+sr+Latn/strings.xml
index ac8699b..a64028d 100644
--- a/packages/SystemUI/res/values-b+sr+Latn/strings.xml
+++ b/packages/SystemUI/res/values-b+sr+Latn/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Upozorenje za <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Režim rada"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Noćno svetlo"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Noćno svetlo je uključeno, dodirnite da biste ga isključili"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Noćno svetlo je isključeno, dodirnite da biste ga uključili"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nema nedavnih stavki"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Obrisali ste sve"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informacije o aplikaciji"</string>
diff --git a/packages/SystemUI/res/values-be-rBY/strings.xml b/packages/SystemUI/res/values-be-rBY/strings.xml
index fb43971..81d3e8f 100644
--- a/packages/SystemUI/res/values-be-rBY/strings.xml
+++ b/packages/SystemUI/res/values-be-rBY/strings.xml
@@ -325,8 +325,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Папярэджанне: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Рэжым працы"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Начная падсветка"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"\"Начная падсветка\" ўключана; дакраніцеся, каб выключыць"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"\"Начная падсветка\" выключана; дакраніцеся, каб уключыць"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Няма нядаўніх элементаў"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Вы ачысцілі усё"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Звесткі аб праграме"</string>
diff --git a/packages/SystemUI/res/values-bg/strings.xml b/packages/SystemUI/res/values-bg/strings.xml
index 8ef1c85..c70a377 100644
--- a/packages/SystemUI/res/values-bg/strings.xml
+++ b/packages/SystemUI/res/values-bg/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Предупреждение: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Работен режим"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Нощно осветление"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Функцията за нощно осветление е включена. Докоснете, за да я изключите"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Функцията за нощно осветление е изключена. Докоснете, за да я включите"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Няма скорошни елементи"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Изчистихте всичко"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Информация за приложението"</string>
diff --git a/packages/SystemUI/res/values-bn-rBD/strings.xml b/packages/SystemUI/res/values-bn-rBD/strings.xml
index 3ef8892..7bd6193 100644
--- a/packages/SystemUI/res/values-bn-rBD/strings.xml
+++ b/packages/SystemUI/res/values-bn-rBD/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> সতর্কতা"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"কাজের মোড"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"নাইট লাইট"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"নাইট লাইট চালু আছে, বন্ধ করতে আলতো চাপুন"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"নাইট লাইট বন্ধ আছে, চালু করতে আলতো চাপুন"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"কোনো সাম্প্রতিক আইটেম নেই"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"আপনি সবকিছু সাফ করেছেন"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"অ্যাপ্লিকেশানের তথ্য"</string>
diff --git a/packages/SystemUI/res/values-bs-rBA/strings.xml b/packages/SystemUI/res/values-bs-rBA/strings.xml
index 6ce6dbe..1699581 100644
--- a/packages/SystemUI/res/values-bs-rBA/strings.xml
+++ b/packages/SystemUI/res/values-bs-rBA/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Upozorenje <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Poslovni režim"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Noćno svjetlo"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Noćno svjetlo je uključeno, dodirnite da isključite"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Noćno svjetlo je isključeno, dodirnite da uključite"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nema nedavnih stavki"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Sve ste obrisali"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informacije o aplikaciji"</string>
diff --git a/packages/SystemUI/res/values-ca/strings.xml b/packages/SystemUI/res/values-ca/strings.xml
index 8810ce3..260be35 100644
--- a/packages/SystemUI/res/values-ca/strings.xml
+++ b/packages/SystemUI/res/values-ca/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Advertiment: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Mode de feina"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Llum nocturna"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"La llum nocturna està encesa; toca aquí per apagar-la"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"La llum nocturna està apagada; toca aquí per encendre-la"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"No hi ha cap element recent"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Ho has esborrat tot"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informació de l\'aplicació"</string>
diff --git a/packages/SystemUI/res/values-cs/strings.xml b/packages/SystemUI/res/values-cs/strings.xml
index 01f4d9e..87fb004 100644
--- a/packages/SystemUI/res/values-cs/strings.xml
+++ b/packages/SystemUI/res/values-cs/strings.xml
@@ -325,8 +325,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Upozornění při <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Pracovní režim"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Noční režim"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Noční režim je zapnut, klepnutím jej vypnete"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Noční režim je vypnut, klepnutím jej zapnete"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Žádné nedávné položky"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Vše je vymazáno"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informace o aplikaci"</string>
diff --git a/packages/SystemUI/res/values-da/strings.xml b/packages/SystemUI/res/values-da/strings.xml
index d23bd26..fb3e16b 100644
--- a/packages/SystemUI/res/values-da/strings.xml
+++ b/packages/SystemUI/res/values-da/strings.xml
@@ -303,7 +303,7 @@
     <string name="quick_settings_inversion_label" msgid="8790919884718619648">"Byt om på farver"</string>
     <string name="quick_settings_color_space_label" msgid="853443689745584770">"Farvekorrigeringstilstand"</string>
     <string name="quick_settings_more_settings" msgid="326112621462813682">"Flere indstillinger"</string>
-    <string name="quick_settings_done" msgid="3402999958839153376">"Udført"</string>
+    <string name="quick_settings_done" msgid="3402999958839153376">"Udfør"</string>
     <string name="quick_settings_connected" msgid="1722253542984847487">"Tilsluttet"</string>
     <string name="quick_settings_connecting" msgid="47623027419264404">"Opretter forbindelse…"</string>
     <string name="quick_settings_tethering_label" msgid="7153452060448575549">"Netdeling"</string>
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Advarsel ved <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Arbejdstilstand"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nattelys"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nattelys er tændt. Tryk for at slukke"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nattelys er slukket. Tryk for at tænde"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Ingen nye elementer"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Du har ryddet alt"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Oplysninger om applikationen"</string>
@@ -520,7 +518,7 @@
     <string name="notification_importance_high" msgid="1729480727023990427">"Se altid smugkig. Ingen afbrydelse af fuld skærm."</string>
     <string name="notification_importance_max" msgid="2508384624461849111">"Se altid smugkig, og tillad afbrydelse af fuld skærm."</string>
     <string name="notification_more_settings" msgid="816306283396553571">"Flere indstillinger"</string>
-    <string name="notification_done" msgid="5279426047273930175">"Færdig"</string>
+    <string name="notification_done" msgid="5279426047273930175">"Udfør"</string>
     <string name="notification_gear_accessibility" msgid="94429150213089611">"Kontrolelementer til underretninger for <xliff:g id="APP_NAME">%1$s</xliff:g>"</string>
     <string name="battery_panel_title" msgid="7944156115535366613">"Batteriforbrug"</string>
     <string name="battery_detail_charging_summary" msgid="1279095653533044008">"Batterisparefunktionen er ikke tilgængelig under opladning"</string>
diff --git a/packages/SystemUI/res/values-de/strings.xml b/packages/SystemUI/res/values-de/strings.xml
index 3ba8f5dd..68af5e5 100644
--- a/packages/SystemUI/res/values-de/strings.xml
+++ b/packages/SystemUI/res/values-de/strings.xml
@@ -270,7 +270,7 @@
     <string name="quick_settings_bluetooth_label" msgid="6304190285170721401">"Bluetooth"</string>
     <string name="quick_settings_bluetooth_multiple_devices_label" msgid="3912245565613684735">"Bluetooth (<xliff:g id="NUMBER">%d</xliff:g> Geräte)"</string>
     <string name="quick_settings_bluetooth_off_label" msgid="8159652146149219937">"Bluetooth aus"</string>
-    <string name="quick_settings_bluetooth_detail_empty_text" msgid="4910015762433302860">"Keine Pairing-Geräte verfügbar"</string>
+    <string name="quick_settings_bluetooth_detail_empty_text" msgid="4910015762433302860">"Keine gekoppelten Geräte verfügbar"</string>
     <string name="quick_settings_brightness_label" msgid="6968372297018755815">"Helligkeit"</string>
     <string name="quick_settings_rotation_unlocked_label" msgid="7305323031808150099">"Automatisch drehen"</string>
     <string name="accessibility_quick_settings_rotation" msgid="4231661040698488779">"Bildschirm automatisch drehen"</string>
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Warnung für <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Arbeitsmodus"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nachtlicht"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nachtlicht an, zum Deaktivieren tippen"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nachtlicht aus, zum Aktivieren tippen"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Keine kürzlich verwendeten Elemente"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Du hast alles gelöscht"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"App-Info"</string>
diff --git a/packages/SystemUI/res/values-el/strings.xml b/packages/SystemUI/res/values-el/strings.xml
index fc248cf..d8d5e09 100644
--- a/packages/SystemUI/res/values-el/strings.xml
+++ b/packages/SystemUI/res/values-el/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Προειδοποίηση για <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Λειτουργία εργασίας"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Νυχτερινός φωτισμός"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Ο Νυχτερινός φωτισμός είναι ενεργοποιημένος. Πατήστε για απενεργοποίηση."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Ο Νυχτερινός φωτισμός είναι απενεργοποιημένος. Πατήστε για ενεργοποίηση."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Δεν υπάρχουν πρόσφατα στοιχεία"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Έχει γίνει εκκαθάριση όλων των στοιχείων"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Πληροφορίες εφαρμογής"</string>
diff --git a/packages/SystemUI/res/values-en-rAU/strings.xml b/packages/SystemUI/res/values-en-rAU/strings.xml
index 75ec92f..570ee82 100644
--- a/packages/SystemUI/res/values-en-rAU/strings.xml
+++ b/packages/SystemUI/res/values-en-rAU/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> warning"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Work mode"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Night Light"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Night Light on, tap to turn off"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Night Light off, tap to turn on"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"No recent items"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"You\'ve cleared everything"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Application Info"</string>
diff --git a/packages/SystemUI/res/values-en-rGB/strings.xml b/packages/SystemUI/res/values-en-rGB/strings.xml
index 75ec92f..570ee82 100644
--- a/packages/SystemUI/res/values-en-rGB/strings.xml
+++ b/packages/SystemUI/res/values-en-rGB/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> warning"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Work mode"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Night Light"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Night Light on, tap to turn off"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Night Light off, tap to turn on"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"No recent items"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"You\'ve cleared everything"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Application Info"</string>
diff --git a/packages/SystemUI/res/values-en-rIN/strings.xml b/packages/SystemUI/res/values-en-rIN/strings.xml
index 75ec92f..570ee82 100644
--- a/packages/SystemUI/res/values-en-rIN/strings.xml
+++ b/packages/SystemUI/res/values-en-rIN/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> warning"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Work mode"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Night Light"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Night Light on, tap to turn off"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Night Light off, tap to turn on"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"No recent items"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"You\'ve cleared everything"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Application Info"</string>
diff --git a/packages/SystemUI/res/values-es-rUS/strings.xml b/packages/SystemUI/res/values-es-rUS/strings.xml
index 5c98ae7..7b09b25 100644
--- a/packages/SystemUI/res/values-es-rUS/strings.xml
+++ b/packages/SystemUI/res/values-es-rUS/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Advertencia de <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modo de trabajo"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Luz nocturna"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Presiona para desactivar la Luz nocturna"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Presiona para activar la Luz nocturna"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"No hay elementos recientes"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Todo borrado"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Información de la aplicación"</string>
diff --git a/packages/SystemUI/res/values-es/strings.xml b/packages/SystemUI/res/values-es/strings.xml
index 4da5ba4..004a2b4 100644
--- a/packages/SystemUI/res/values-es/strings.xml
+++ b/packages/SystemUI/res/values-es/strings.xml
@@ -232,8 +232,8 @@
     <string name="accessibility_quick_settings_work_mode_on" msgid="7650588553988014341">"Modo de trabajo activado."</string>
     <string name="accessibility_quick_settings_work_mode_changed_off" msgid="5605534876107300711">"Modo de trabajo desactivado."</string>
     <string name="accessibility_quick_settings_work_mode_changed_on" msgid="249840330756998612">"Modo de trabajo activado."</string>
-    <string name="accessibility_quick_settings_data_saver_changed_off" msgid="650231949881093289">"Economizador de Datos desactivado."</string>
-    <string name="accessibility_quick_settings_data_saver_changed_on" msgid="4218725402373934151">"Economizador de Datos activado."</string>
+    <string name="accessibility_quick_settings_data_saver_changed_off" msgid="650231949881093289">"Ahorro de datos desactivado."</string>
+    <string name="accessibility_quick_settings_data_saver_changed_on" msgid="4218725402373934151">"Ahorro de datos activado."</string>
     <string name="accessibility_brightness" msgid="8003681285547803095">"Brillo de la pantalla"</string>
     <string name="data_usage_disabled_dialog_3g_title" msgid="5281770593459841889">"Datos 2G-3G pausados"</string>
     <string name="data_usage_disabled_dialog_4g_title" msgid="1601769736881078016">"Datos 4G pausados"</string>
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Advertencia de <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modo de trabajo"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Luz nocturna"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Luz nocturna activada; toca aquí para desactivarla"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Luz nocturna desactivada; toca aquí para activarla"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"No hay elementos recientes"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Has rechazado todo"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Información de la aplicación"</string>
@@ -579,9 +577,9 @@
     <string name="headset" msgid="4534219457597457353">"Auriculares"</string>
     <string name="accessibility_status_bar_headphones" msgid="9156307120060559989">"Auriculares conectados"</string>
     <string name="accessibility_status_bar_headset" msgid="8666419213072449202">"Auriculares conectados"</string>
-    <string name="data_saver" msgid="5037565123367048522">"Economizador de Datos"</string>
-    <string name="accessibility_data_saver_on" msgid="8454111686783887148">"Economizador de Datos activado"</string>
-    <string name="accessibility_data_saver_off" msgid="8841582529453005337">"Economizador de Datos desactivado"</string>
+    <string name="data_saver" msgid="5037565123367048522">"Ahorro de datos"</string>
+    <string name="accessibility_data_saver_on" msgid="8454111686783887148">"Ahorro de datos activado"</string>
+    <string name="accessibility_data_saver_off" msgid="8841582529453005337">"Ahorro de datos desactivado"</string>
     <string name="switch_bar_on" msgid="1142437840752794229">"Sí"</string>
     <string name="switch_bar_off" msgid="8803270596930432874">"No"</string>
     <string name="nav_bar" msgid="1993221402773877607">"Barra de navegación"</string>
diff --git a/packages/SystemUI/res/values-et-rEE/strings.xml b/packages/SystemUI/res/values-et-rEE/strings.xml
index 0a09e48..10be679 100644
--- a/packages/SystemUI/res/values-et-rEE/strings.xml
+++ b/packages/SystemUI/res/values-et-rEE/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> hoiatus"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Töörežiim"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Öövalgus"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Öövalgus on sees, puudutage väljalülitamiseks"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Öövalgus on väljas, puudutage sisselülitamiseks"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Hiljutisi üksusi pole"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Olete kõik ära kustutanud"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Rakenduste teave"</string>
diff --git a/packages/SystemUI/res/values-eu-rES/strings.xml b/packages/SystemUI/res/values-eu-rES/strings.xml
index 74b3a61..7514e8e 100644
--- a/packages/SystemUI/res/values-eu-rES/strings.xml
+++ b/packages/SystemUI/res/values-eu-rES/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Abisua: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Lan modua"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Gaueko argia"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Aktibatuta dago gaueko argia. Sakatu desaktibatzeko."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Desaktibatuta dago gaueko argia. Sakatu aktibatzeko."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Ez dago azkenaldi honetako ezer"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Dena garbitu duzu"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Aplikazioaren informazioa"</string>
diff --git a/packages/SystemUI/res/values-fa/strings.xml b/packages/SystemUI/res/values-fa/strings.xml
index 1ccc804..a4b9798 100644
--- a/packages/SystemUI/res/values-fa/strings.xml
+++ b/packages/SystemUI/res/values-fa/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"هشدار <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"حالت کار"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"نور شب"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"نور شب روشن است، برای خاموش‌کردن آن ضربه بزنید"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"نور شب خاموش است، برای روشن‌شدن آن ضربه بزنید"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"بدون موارد اخیر"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"همه‌چیز را پاک کرده‌اید"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"اطلاعات برنامه"</string>
diff --git a/packages/SystemUI/res/values-fi/strings.xml b/packages/SystemUI/res/values-fi/strings.xml
index 9ec1ffd..42c8ae0 100644
--- a/packages/SystemUI/res/values-fi/strings.xml
+++ b/packages/SystemUI/res/values-fi/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> – varoitus"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Työtila"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Yövalo"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Yövalo on käytössä. Poista se käytöstä koskettamalla."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Yövalo ei ole käytössä. Ota se käyttöön koskettamalla."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Ei viimeaikaisia kohteita"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Kaikki on hoidettu."</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Sovellustiedot"</string>
diff --git a/packages/SystemUI/res/values-fr-rCA/strings.xml b/packages/SystemUI/res/values-fr-rCA/strings.xml
index 67e717e..8b4faef 100644
--- a/packages/SystemUI/res/values-fr-rCA/strings.xml
+++ b/packages/SystemUI/res/values-fr-rCA/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Avertissement : <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Mode Travail"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Éclairage nocturne"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Le mode Éclairage nocturne est activé. Touchez ici pour le désactiver."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Le mode Éclairage nocturne est désactivé. Touchez ici pour l\'activer."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Aucun élément récent"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Vous avez tout effacé"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Détails de l\'application"</string>
diff --git a/packages/SystemUI/res/values-fr/strings.xml b/packages/SystemUI/res/values-fr/strings.xml
index 7310a47..52728bd 100644
--- a/packages/SystemUI/res/values-fr/strings.xml
+++ b/packages/SystemUI/res/values-fr/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Avertissement : <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Mode Travail"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Éclairage nocturne"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Éclairage nocturne activé, appuyer pour désactiver"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Éclairage nocturne désactivé, appuyer pour activer"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Aucun élément récent"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Vous avez tout effacé."</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Infos application"</string>
diff --git a/packages/SystemUI/res/values-gl-rES/strings.xml b/packages/SystemUI/res/values-gl-rES/strings.xml
index 6152872..d489a64 100644
--- a/packages/SystemUI/res/values-gl-rES/strings.xml
+++ b/packages/SystemUI/res/values-gl-rES/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Advertencia <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modo de traballo"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Luz nocturna"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"A función Luz nocturna está activada. Toca para desactivala"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"A función Luz nocturna está desactivada. Toca para activala"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Non hai elementos recentes"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Borraches todo"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Información da aplicación"</string>
diff --git a/packages/SystemUI/res/values-gu-rIN/strings.xml b/packages/SystemUI/res/values-gu-rIN/strings.xml
index 26b1c06..42546f6e 100644
--- a/packages/SystemUI/res/values-gu-rIN/strings.xml
+++ b/packages/SystemUI/res/values-gu-rIN/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> ચેતવણી"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"કાર્ય મોડ"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"રાત્રિ પ્રકાશ"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"રાત્રિ પ્રકાશ ચાલુ છે, બંધ કરવા માટે ટપ કરો"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"રાત્રિ પ્રકાશ બંધ છે, ચાલુ કરવા માટે ટૅપ કરો"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"કોઇ તાજેતરની આઇટમ્સ નથી"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"તમે બધું સાફ કર્યું"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"ઍપ્લિકેશન માહિતી"</string>
diff --git a/packages/SystemUI/res/values-hi/strings.xml b/packages/SystemUI/res/values-hi/strings.xml
index 42c049d..49a4650 100644
--- a/packages/SystemUI/res/values-hi/strings.xml
+++ b/packages/SystemUI/res/values-hi/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> चेतावनी"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"कार्य मोड"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"नाइट लाइट"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"नाइट लाइट चालू है, बंद करने के लिए टैप करें"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"नाइट लाइट बंद है, चालू करने के लिए टैप करें"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"हाल ही का कोई आइटम नहीं"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"आपने सब कुछ साफ़ कर दिया है"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"एप्‍लिकेशन जानकारी"</string>
diff --git a/packages/SystemUI/res/values-hr/strings.xml b/packages/SystemUI/res/values-hr/strings.xml
index 58dd92e..1bbae8b 100644
--- a/packages/SystemUI/res/values-hr/strings.xml
+++ b/packages/SystemUI/res/values-hr/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Upozorenje <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Način rada"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Noćno svjetlo"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Noćno je svjetlo uključeno, dodirnite da biste ga isključili"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Noćno je svjetlo isključeno, dodirnite da biste ga uključili"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nema nedavnih stavki"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Izbrisali ste sve"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informacije o aplikaciji"</string>
diff --git a/packages/SystemUI/res/values-hu/strings.xml b/packages/SystemUI/res/values-hu/strings.xml
index 0804093..7792ac1 100644
--- a/packages/SystemUI/res/values-hu/strings.xml
+++ b/packages/SystemUI/res/values-hu/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Figyelem! <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Munka mód"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Éjszakai fény"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Éjszakai fény bekapcsolva, koppintson a kikapcsoláshoz"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Éjszakai fény kikapcsolva, koppintson a bekapcsoláshoz"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nincsenek mostanában használt elemek"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Mindent törölt"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Az alkalmazás adatai"</string>
diff --git a/packages/SystemUI/res/values-hy-rAM/strings.xml b/packages/SystemUI/res/values-hy-rAM/strings.xml
index c1c8bf9..9d07927 100644
--- a/packages/SystemUI/res/values-hy-rAM/strings.xml
+++ b/packages/SystemUI/res/values-hy-rAM/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> զգուշացում"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Աշխատանքային ռեժիմ"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Գիշերային լույս"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Գիշերային լույսը միացված է, հպեք՝ անջատելու համար"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Գիշերային լույսն անջատված է, հպեք՝ միացնելու համար"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Վերջին տարրեր չկան"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Դուք ջնջել եք ամենը"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Հավելվածի մասին"</string>
diff --git a/packages/SystemUI/res/values-in/strings.xml b/packages/SystemUI/res/values-in/strings.xml
index be27eca..20ef37d 100644
--- a/packages/SystemUI/res/values-in/strings.xml
+++ b/packages/SystemUI/res/values-in/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Peringatan <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Mode kerja"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Cahaya Malam"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Cahaya Malam hidup, ketuk untuk mematikan"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Cahaya Malam mati, ketuk untuk menyalakan"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Tidak ada item baru-baru ini"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Anda sudah menghapus semua"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Info Aplikasi"</string>
diff --git a/packages/SystemUI/res/values-is-rIS/strings.xml b/packages/SystemUI/res/values-is-rIS/strings.xml
index 0b65a95..6a5de8a 100644
--- a/packages/SystemUI/res/values-is-rIS/strings.xml
+++ b/packages/SystemUI/res/values-is-rIS/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> viðvörun"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Vinnustilling"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Næturljós"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Kveikt á næturljósi, ýttu til að slökkva"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Slökkt á næturljósi, ýttu til að kveikja"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Engin nýleg atriði"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Þú hefur hreinsað allt"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Forritsupplýsingar"</string>
diff --git a/packages/SystemUI/res/values-it/strings.xml b/packages/SystemUI/res/values-it/strings.xml
index 5eae72c..39221ad 100644
--- a/packages/SystemUI/res/values-it/strings.xml
+++ b/packages/SystemUI/res/values-it/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Avviso <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modalità Lavoro"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Luminosità notturna"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Luminosità notturna attiva, tocca per disattivarla"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Luminosità notturna disattivata, tocca per attivarla"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nessun elemento recente"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Hai cancellato tutto"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informazioni sull\'applicazione"</string>
diff --git a/packages/SystemUI/res/values-iw/strings.xml b/packages/SystemUI/res/values-iw/strings.xml
index ef4d683..43eeae4 100644
--- a/packages/SystemUI/res/values-iw/strings.xml
+++ b/packages/SystemUI/res/values-iw/strings.xml
@@ -323,8 +323,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"אזהרה - <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"מצב עבודה"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"תאורת לילה"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"תאורת לילה פועלת, הקש כדי לכבות"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"תאורת לילה כבויה, הקש כדי להפעיל"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"אין פריטים אחרונים"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"מחקת הכול"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"מידע על האפליקציה"</string>
diff --git a/packages/SystemUI/res/values-ja/strings.xml b/packages/SystemUI/res/values-ja/strings.xml
index fcc5ae1..7df0a9e 100644
--- a/packages/SystemUI/res/values-ja/strings.xml
+++ b/packages/SystemUI/res/values-ja/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"警告: 上限は<xliff:g id="DATA_LIMIT">%s</xliff:g>です"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Work モード"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"読書灯"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"読書灯 ON: タップすると OFF になります"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"読書灯 OFF: タップすると ON になります"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"最近のタスクはありません"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"すべてのタスクを消去しました"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"アプリ情報"</string>
diff --git a/packages/SystemUI/res/values-ka-rGE/strings.xml b/packages/SystemUI/res/values-ka-rGE/strings.xml
index b799116..a63de78 100644
--- a/packages/SystemUI/res/values-ka-rGE/strings.xml
+++ b/packages/SystemUI/res/values-ka-rGE/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> გაფრთხილება"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"სამსახურის რეჟიმი"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"ღამის განათება"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"ღამის განათება ჩართულია, შეეხეთ გამოსართავად"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"ღამის განათება გამორთულია, შეეხეთ ჩასართავად"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"ბოლოს გამოყენებული ერთეულები არ არის"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"ყველაფერი გასუფთავდა"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"აპლიკაციის შესახებ"</string>
diff --git a/packages/SystemUI/res/values-kk-rKZ/strings.xml b/packages/SystemUI/res/values-kk-rKZ/strings.xml
index 872caa7..f39e44a 100644
--- a/packages/SystemUI/res/values-kk-rKZ/strings.xml
+++ b/packages/SystemUI/res/values-kk-rKZ/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> туралы ескерту"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Жұмыс режимі"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Түнгі жарық"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Түнгі жарық қосулы, өшіру үшін оны түртіңіз"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Түнгі жарық өшірулі, қосу үшін оны түртіңіз"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Жақындағы элементтер жоқ"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Сіз барлығын өшірдіңіз"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Қолданба туралы ақпарат"</string>
diff --git a/packages/SystemUI/res/values-km-rKH/strings.xml b/packages/SystemUI/res/values-km-rKH/strings.xml
index 23db2d0..36d0e44 100644
--- a/packages/SystemUI/res/values-km-rKH/strings.xml
+++ b/packages/SystemUI/res/values-km-rKH/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> ការ​ព្រមាន"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"របៀបការងារ"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"ពន្លឺពេលយប់"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"ពន្លឺពេលយប់បើកហើយ ប៉ះដើម្បីបិទ"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"ពន្លឺពេលយប់បិទហើយ ប៉ះដើម្បីបើក"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"មិនមានធាតុថ្មីៗទេ"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"អ្នកបានជម្រះអ្វីៗទាំងអស់"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"ព័ត៌មាន​កម្មវិធី"</string>
diff --git a/packages/SystemUI/res/values-kn-rIN/strings.xml b/packages/SystemUI/res/values-kn-rIN/strings.xml
index 189cce0..3f74b1d 100644
--- a/packages/SystemUI/res/values-kn-rIN/strings.xml
+++ b/packages/SystemUI/res/values-kn-rIN/strings.xml
@@ -84,7 +84,7 @@
     <string name="accessibility_home" msgid="8217216074895377641">"ಮುಖಪುಟ"</string>
     <string name="accessibility_menu" msgid="316839303324695949">"ಮೆನು"</string>
     <string name="accessibility_recent" msgid="5208608566793607626">"ಸಮಗ್ರ ನೋಟ"</string>
-    <string name="accessibility_search_light" msgid="1103867596330271848">"ಹುಡುಕು"</string>
+    <string name="accessibility_search_light" msgid="1103867596330271848">"ಹುಡುಕಿ"</string>
     <string name="accessibility_camera_button" msgid="8064671582820358152">"ಕ್ಯಾಮರಾ"</string>
     <string name="accessibility_phone_button" msgid="6738112589538563574">"ಫೋನ್"</string>
     <string name="accessibility_voice_assist_button" msgid="487611083884852965">"ಧ್ವನಿ ಸಹಾಯಕ"</string>
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> ಎಚ್ಚರಿಕೆ"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"ಕೆಲಸದ ಮೋಡ್"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"ನೈಟ್ ಲೈಟ್"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"ನೈಟ್ ಲೈಟ್ ಆನ್ ಆಗಿದೆ, ಆಫ್ ಮಾಡಲು ಟ್ಯಾಪ್ ಮಾಡಿ"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"ನೈಟ್ ಲೈಟ್ ಆಫ್ ಆಗಿದೆ, ಆನ್ ಮಾಡಲು ಟ್ಯಾಪ್ ಮಾಡಿ"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"ಯಾವುದೇ ಇತ್ತೀಚಿನ ಐಟಂಗಳಿಲ್ಲ"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"ನೀವು ಎಲ್ಲವನ್ನೂ ತೆರವುಗೊಳಿಸಿರುವಿರಿ"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"ಅಪ್ಲಿಕೇಶನ್ ಮಾಹಿತಿ"</string>
diff --git a/packages/SystemUI/res/values-ko/strings.xml b/packages/SystemUI/res/values-ko/strings.xml
index af40128..5f1f5cd 100644
--- a/packages/SystemUI/res/values-ko/strings.xml
+++ b/packages/SystemUI/res/values-ko/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> 경고"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"작업 모드"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"야간 조명"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"야간 조명 사용 설정됨, 사용 중지하려면 탭"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"야간 조명 사용 중지됨, 사용 설정하려면 탭"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"최근 항목이 없습니다."</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"모든 항목을 삭제했습니다."</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"애플리케이션 정보"</string>
diff --git a/packages/SystemUI/res/values-ky-rKG/strings.xml b/packages/SystemUI/res/values-ky-rKG/strings.xml
index 91ebf7c..9b35ef7 100644
--- a/packages/SystemUI/res/values-ky-rKG/strings.xml
+++ b/packages/SystemUI/res/values-ky-rKG/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> эскертүү"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Иштөө режими"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Түнкү жарык"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Түнкү жарык күйүк, өчүрүү үчүн таптап коюңуз"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Түнкү жарык өчүк, күйгүзүү үчүн таптап коюңуз"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Акыркы колдонмолор жок"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Баарын тазаладыңыз"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Колдонмо жөнүндө маалымат"</string>
diff --git a/packages/SystemUI/res/values-lo-rLA/strings.xml b/packages/SystemUI/res/values-lo-rLA/strings.xml
index 81ee168..d4acc77 100644
--- a/packages/SystemUI/res/values-lo-rLA/strings.xml
+++ b/packages/SystemUI/res/values-lo-rLA/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"ຄຳ​ເຕືອນ <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"ໂໝດການເຮັດວຽກ"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"ແສງກາງຄືນ"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"ເປີດແສງກາງຄືນຢູ່, ແຕະເພື່ອປິດໄວ້"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"ປິດແສງກາງຄືນຢູ່, ແຕະເພື່ອເປີດໃຊ້"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"ບໍ່ມີລາຍການຫຼ້າສຸດ"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"ທ່ານລຶບລ້າງທຸກຢ່າງແລ້ວ"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"​ຂໍ້​ມູນ​ແອັບ​ພ​ລິ​ເຄ​ຊັນ"</string>
diff --git a/packages/SystemUI/res/values-lt/strings.xml b/packages/SystemUI/res/values-lt/strings.xml
index df1765a..5de6b7f 100644
--- a/packages/SystemUI/res/values-lt/strings.xml
+++ b/packages/SystemUI/res/values-lt/strings.xml
@@ -323,8 +323,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> įspėjimas"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Darbo režimas"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nakties šviesa"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nakties šviesa įjungta. Palieskite, kad išjungtumėte"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nakties šviesa išjungta. Palieskite, kad įjungtumėte"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nėra jokių naujausių elementų"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Viską išvalėte"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Programos informacija"</string>
diff --git a/packages/SystemUI/res/values-lv/strings.xml b/packages/SystemUI/res/values-lv/strings.xml
index ffad77b..091c47f 100644
--- a/packages/SystemUI/res/values-lv/strings.xml
+++ b/packages/SystemUI/res/values-lv/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> brīdinājums"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Darba režīms"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nakts režīms"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nakts režīms ir ieslēgts. Pieskarieties, lai to izslēgtu."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nakts režīms ir izslēgts. Pieskarieties, lai to ieslēgtu."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nav nesenu vienumu"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Visi uzdevumi ir notīrīti"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informācija par lietojumprogrammu"</string>
diff --git a/packages/SystemUI/res/values-mk-rMK/strings.xml b/packages/SystemUI/res/values-mk-rMK/strings.xml
index 4aa1821..020118b 100644
--- a/packages/SystemUI/res/values-mk-rMK/strings.xml
+++ b/packages/SystemUI/res/values-mk-rMK/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Предупредување за <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Режим на работа"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Ноќно светло"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Ноќното светло е вклучено, допрете за да се исклучи"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Ноќното светло е исклучено, допрете за да се вклучи"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Нема неодамнешни ставки"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Исчистивте сѐ"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Информации за апликацијата"</string>
diff --git a/packages/SystemUI/res/values-ml-rIN/strings.xml b/packages/SystemUI/res/values-ml-rIN/strings.xml
index 225a284..e07a758 100644
--- a/packages/SystemUI/res/values-ml-rIN/strings.xml
+++ b/packages/SystemUI/res/values-ml-rIN/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> മുന്നറിയിപ്പ്"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"പ്രവർത്തന മോഡ്"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"നൈറ്റ് ലൈറ്റ്"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"നൈറ്റ് ലൈറ്റ് ഓണാണ്, ഓഫാക്കുന്നതിന് ടാപ്പുചെയ്യുക"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"നൈറ്റ് ലൈറ്റ് ഓഫാണ്, ഓണാക്കുന്നതിന് ടാപ്പുചെയ്യുക"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"സമീപകാല ഇനങ്ങൾ ഒന്നുമില്ല"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"നിങ്ങൾ എല്ലാം മായ്ച്ചിരിക്കുന്നു"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"ആപ്പ് വിവരം"</string>
diff --git a/packages/SystemUI/res/values-mn-rMN/strings.xml b/packages/SystemUI/res/values-mn-rMN/strings.xml
index a84aae6..fcd39d9 100644
--- a/packages/SystemUI/res/values-mn-rMN/strings.xml
+++ b/packages/SystemUI/res/values-mn-rMN/strings.xml
@@ -317,8 +317,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> анхааруулга"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Ажлын горим"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Шөнийн гэрэл"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Шөнийн гэрэл асаалттай байна. Унтраахын тулд товшино уу"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Шөнийн гэрэл унтраалттай байна. Асаахын тулд товшино уу"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Сүүлийн үеийн зүйл байхгүй"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Та бүгдийг нь устгасан"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Аппликешны мэдээлэл"</string>
diff --git a/packages/SystemUI/res/values-mr-rIN/strings.xml b/packages/SystemUI/res/values-mr-rIN/strings.xml
index 6c92213..285fd57 100644
--- a/packages/SystemUI/res/values-mr-rIN/strings.xml
+++ b/packages/SystemUI/res/values-mr-rIN/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> चेतावणी"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"कार्य मोड"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"रात्रीचा प्रकाश"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"रात्रीचा प्रकाश चालू आहे, बंद करण्यासाठी टॅप करा"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"रात्रीचा प्रकाश बंद आहे, चालू करण्यासाठी टॅप करा"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"अलीकडील कोणतेही आयटम नाहीत"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"आपण सर्वकाही साफ केले"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"अनुप्रयोग माहिती"</string>
diff --git a/packages/SystemUI/res/values-ms-rMY/strings.xml b/packages/SystemUI/res/values-ms-rMY/strings.xml
index 95e7a4d..88894b5 100644
--- a/packages/SystemUI/res/values-ms-rMY/strings.xml
+++ b/packages/SystemUI/res/values-ms-rMY/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Amaran <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Mod kerja"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Cahaya Malam"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Cahaya Malam dihidupkan, ketik untuk mematikannya"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Cahaya Malam dimatikan, ketik untuk menghidupkannya"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Tiada item terbaharu"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Anda telah mengetepikan semua item"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Maklumat Aplikasi"</string>
diff --git a/packages/SystemUI/res/values-my-rMM/strings.xml b/packages/SystemUI/res/values-my-rMM/strings.xml
index 905c865..a79c1ae 100644
--- a/packages/SystemUI/res/values-my-rMM/strings.xml
+++ b/packages/SystemUI/res/values-my-rMM/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> သတိပေးချက်"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"အလုပ် မုဒ်"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"ညအလင်းရောင်"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"ညအလင်းရောင်ကို ဖွင့်ထားသည်၊ ပိတ်ရန်တို့ပါ"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"ညအလင်းရောင်ကို ပိတ်ထားသည်၊ ဖွင့်ရန်တို့ပါ"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"မကြာမီကဖွင့်ထားသည်များ မရှိပါ"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"သင်အားလုံးကို ရှင်းလင်းပြီးပါပြီ"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"အပလီကေးရှင်းအင်ဖို"</string>
diff --git a/packages/SystemUI/res/values-nb/strings.xml b/packages/SystemUI/res/values-nb/strings.xml
index 41d70e6..1784641 100644
--- a/packages/SystemUI/res/values-nb/strings.xml
+++ b/packages/SystemUI/res/values-nb/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Advarsel for <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Arbeidsmodus"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nattlys"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nattlys er på, trykk for å slå av"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nattlys er av, trykk for å slå på"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Ingen nylige elementer"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Du har fjernet alt"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Appinformasjon"</string>
diff --git a/packages/SystemUI/res/values-ne-rNP/strings.xml b/packages/SystemUI/res/values-ne-rNP/strings.xml
index d0dfd66..625f959 100644
--- a/packages/SystemUI/res/values-ne-rNP/strings.xml
+++ b/packages/SystemUI/res/values-ne-rNP/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> चेतावनी दिँदै"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"कार्य मोड"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"रात्रिको प्रकाश"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"रात्रिको प्रकाश सक्रिय छ, निष्क्रिय पार्न ट्याप गर्नुहोस्"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"रात्रिको प्रकाश निष्क्रिय छ, सक्रिय गर्न ट्याप गर्नुहोस्"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"हालका कुनै पनि वस्तुहरू छैनन्"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"तपाईँले सबै कुरा खाली गर्नुभएको छ"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"अनुप्रयोग जानकारी"</string>
diff --git a/packages/SystemUI/res/values-nl/strings.xml b/packages/SystemUI/res/values-nl/strings.xml
index 6bcd642..f7e180f 100644
--- a/packages/SystemUI/res/values-nl/strings.xml
+++ b/packages/SystemUI/res/values-nl/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Waarschuwing voor <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Werkmodus"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nachtverlichting"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nachtverlichting is ingeschakeld. Tik om deze uit te schakelen."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nachtverlichting is uitgeschakeld. Tik om deze in te schakelen."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Geen recente items"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Je hebt alles gewist"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"App-informatie"</string>
diff --git a/packages/SystemUI/res/values-pa-rIN/strings.xml b/packages/SystemUI/res/values-pa-rIN/strings.xml
index d5b4a5d..0587023 100644
--- a/packages/SystemUI/res/values-pa-rIN/strings.xml
+++ b/packages/SystemUI/res/values-pa-rIN/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> ਚਿਤਾਵਨੀ"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"ਕੰਮ ਮੋਡ"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"ਰਾਤਰੀ ਲਾਈਟ"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"ਰਾਤਰੀ ਲਾਈਟ ਚਾਲੂ ਹੈ, ਬੰਦ ਕਰਨ ਲਈ ਟੈਪ ਕਰੋ"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"ਰਾਤਰੀ ਲਾਈਟ ਬੰਦ ਹੈ, ਚਾਲੂ ਕਰਨ ਲਈ ਟੈਪ ਕਰੋ"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"ਕੋਈ ਹਾਲੀਆ ਆਈਟਮਾਂ ਨਹੀਂ"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"ਤੁਸੀਂ ਸਭ ਕੁਝ ਸਾਫ਼ ਕਰ ਦਿੱਤਾ ਹੈ"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"ਐਪਲੀਕੇਸ਼ਨ ਜਾਣਕਾਰੀ"</string>
diff --git a/packages/SystemUI/res/values-pl/strings.xml b/packages/SystemUI/res/values-pl/strings.xml
index 92df542..5bf6a99 100644
--- a/packages/SystemUI/res/values-pl/strings.xml
+++ b/packages/SystemUI/res/values-pl/strings.xml
@@ -323,8 +323,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Ostrzeżenie: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Tryb pracy"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Podświetlenie nocne"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Podświetlenie nocne włączone – kliknij, by wyłączyć"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Podświetlenie nocne wyłączone – kliknij, by włączyć"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Brak ostatnich elementów"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Wszystko zostało wyczyszczone"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informacje o aplikacji"</string>
diff --git a/packages/SystemUI/res/values-pt-rBR/strings.xml b/packages/SystemUI/res/values-pt-rBR/strings.xml
index 5fe2def..aa1e718 100644
--- a/packages/SystemUI/res/values-pt-rBR/strings.xml
+++ b/packages/SystemUI/res/values-pt-rBR/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Aviso de <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modo de trabalho"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Modo noturno"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Modo noturno ativado. Toque para desativar"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Modo noturno desativado. Toque para ativar"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nenhum item recente"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Você limpou tudo"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informações do app"</string>
diff --git a/packages/SystemUI/res/values-pt-rPT/strings.xml b/packages/SystemUI/res/values-pt-rPT/strings.xml
index ff5f566..6037da1 100644
--- a/packages/SystemUI/res/values-pt-rPT/strings.xml
+++ b/packages/SystemUI/res/values-pt-rPT/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Aviso de <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modo de trabalho"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Luz noturna"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Luz noturna ativada; toque para desativar"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Luz noturna desativada; toque para ativar"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nenhum item recente"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Limpou tudo"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informações da aplicação"</string>
diff --git a/packages/SystemUI/res/values-pt/strings.xml b/packages/SystemUI/res/values-pt/strings.xml
index 5fe2def..aa1e718 100644
--- a/packages/SystemUI/res/values-pt/strings.xml
+++ b/packages/SystemUI/res/values-pt/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Aviso de <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modo de trabalho"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Modo noturno"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Modo noturno ativado. Toque para desativar"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Modo noturno desativado. Toque para ativar"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nenhum item recente"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Você limpou tudo"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informações do app"</string>
diff --git a/packages/SystemUI/res/values-ro/strings.xml b/packages/SystemUI/res/values-ro/strings.xml
index 11ce950..da6a32d 100644
--- a/packages/SystemUI/res/values-ro/strings.xml
+++ b/packages/SystemUI/res/values-ro/strings.xml
@@ -323,8 +323,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Avertizare: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modul de lucru"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Lumină de noapte"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Lumina de noapte este activată; atingeți pentru a o dezactiva"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Lumina de noapte este dezactivată; atingeți pentru a o activa"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Niciun element recent"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Ați șters tot"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informații despre aplicație"</string>
diff --git a/packages/SystemUI/res/values-ru/strings.xml b/packages/SystemUI/res/values-ru/strings.xml
index 0e49132..8257b87 100644
--- a/packages/SystemUI/res/values-ru/strings.xml
+++ b/packages/SystemUI/res/values-ru/strings.xml
@@ -325,8 +325,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Предупреждение: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Рабочий режим"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Ночной режим"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Ночной режим включен. Нажмите, чтобы отключить."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Ночной режим отключен. Нажмите, чтобы включить."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Недавних приложений нет"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Вы очистили всё"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Сведения о приложении"</string>
diff --git a/packages/SystemUI/res/values-si-rLK/strings.xml b/packages/SystemUI/res/values-si-rLK/strings.xml
index ff8031e..7ee1e6b 100644
--- a/packages/SystemUI/res/values-si-rLK/strings.xml
+++ b/packages/SystemUI/res/values-si-rLK/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> අවවාද කිරීම"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"වැඩ ප්‍රකාරය"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"රාත්‍රී ආලෝකය"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"රාත්‍රී ආලෝකය ක්‍රියාත්මකයි, ක්‍රියාවිරහිත කිරීමට තට්ටු කරන්න"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"රාත්‍රී ආලෝකය ක්‍රියාවිරහිතයි, ක්‍රියාත්මක කිරීමට තට්ටු කරන්න"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"මෑත අයිතම නැත"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"ඔබ සියලු දේ හිස් කර ඇත"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"යෙදුම් තොරතුරු"</string>
diff --git a/packages/SystemUI/res/values-sk/strings.xml b/packages/SystemUI/res/values-sk/strings.xml
index cc61b6e..9b68465 100644
--- a/packages/SystemUI/res/values-sk/strings.xml
+++ b/packages/SystemUI/res/values-sk/strings.xml
@@ -325,8 +325,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Upozornenie pri <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Pracovný režim"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nočný režim"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nočný režim je zapnutý (vypnete ho klepnutím)"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nočný režim je vypnutý (zapnete ho klepnutím)"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Žiadne nedávne položky"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Vymazali ste všetko"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informácie o aplikácii"</string>
diff --git a/packages/SystemUI/res/values-sl/strings.xml b/packages/SystemUI/res/values-sl/strings.xml
index 9f2f7c4..fccd6f9 100644
--- a/packages/SystemUI/res/values-sl/strings.xml
+++ b/packages/SystemUI/res/values-sl/strings.xml
@@ -325,8 +325,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Opozorilo – <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Način za delo"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nočna svetloba"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nočna svetloba je vklopljena. Dotaknite se, če jo želite izklopiti."</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nočna svetloba je izklopljena. Dotaknite se, če jo želite vklopiti."</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Ni nedavnih elementov"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Vse te počistili"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Podatki o aplikaciji"</string>
diff --git a/packages/SystemUI/res/values-sq-rAL/strings.xml b/packages/SystemUI/res/values-sq-rAL/strings.xml
index b07f551..855c96c 100644
--- a/packages/SystemUI/res/values-sq-rAL/strings.xml
+++ b/packages/SystemUI/res/values-sq-rAL/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Paralajmërim për kufirin prej <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Modaliteti i punës"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Drita e natës"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Drita e natës është joaktive, trokit për ta çaktivizuar"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Drita e natës është joaktive, trokit për ta aktivizuar"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Nuk ka asnjë artikull të fundit"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"I ke pastruar të gjitha"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Informacioni i aplikacionit"</string>
diff --git a/packages/SystemUI/res/values-sr/strings.xml b/packages/SystemUI/res/values-sr/strings.xml
index 35d7d52..22b0ba1 100644
--- a/packages/SystemUI/res/values-sr/strings.xml
+++ b/packages/SystemUI/res/values-sr/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Упозорење за <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Режим рада"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Ноћно светло"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Ноћно светло је укључено, додирните да бисте га искључили"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Ноћно светло је искључено, додирните да бисте га укључили"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Нема недавних ставки"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Обрисали сте све"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Информације о апликацији"</string>
diff --git a/packages/SystemUI/res/values-sv/strings.xml b/packages/SystemUI/res/values-sv/strings.xml
index 7e2ec6e..830df0c 100644
--- a/packages/SystemUI/res/values-sv/strings.xml
+++ b/packages/SystemUI/res/values-sv/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Varning <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Arbetsläge"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Nattljus"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Nattljus har aktiverats. Tryck för att inaktivera"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Nattljus har inaktiverats. Tryck för att aktivera"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Listan med de senaste åtgärderna är tom"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Du har tömt listan"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Appinformation"</string>
diff --git a/packages/SystemUI/res/values-sw/strings.xml b/packages/SystemUI/res/values-sw/strings.xml
index 396731b..9ec6ca8 100644
--- a/packages/SystemUI/res/values-sw/strings.xml
+++ b/packages/SystemUI/res/values-sw/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Onyo <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Hali ya kazi"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Mwanga wa Usiku"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Umewasha hali ya Mwanga wa Usiku, gonga ili uizime"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Umezima hali ya Mwanga wa Usiku, gonga ili uiwashe"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Hakuna vipengee vya hivi karibuni"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Umeondoa vipengee vyote"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Maelezo ya Programu"</string>
diff --git a/packages/SystemUI/res/values-ta-rIN/strings.xml b/packages/SystemUI/res/values-ta-rIN/strings.xml
index 465d70e..30223c7 100644
--- a/packages/SystemUI/res/values-ta-rIN/strings.xml
+++ b/packages/SystemUI/res/values-ta-rIN/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> எச்சரிக்கை"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"பணிப் பயன்முறை"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"இரவு ஒளி"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"இரவு ஒளி இயக்கப்பட்டுள்ளது. முடக்க, தட்டவும்"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"இரவு ஒளி முடக்கப்பட்டுள்ளது. இயக்க, தட்டவும்"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"சமீபத்திய பணிகள் இல்லை"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"எல்லாவற்றையும் அழித்துவிட்டீர்கள்"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"பயன்பாட்டு தகவல்"</string>
diff --git a/packages/SystemUI/res/values-te-rIN/strings.xml b/packages/SystemUI/res/values-te-rIN/strings.xml
index 783664d..4613354 100644
--- a/packages/SystemUI/res/values-te-rIN/strings.xml
+++ b/packages/SystemUI/res/values-te-rIN/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> హెచ్చరిక"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"పని మోడ్"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"రాత్రి కాంతి"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"రాత్రి కాంతి ఆన్‌లో ఉంది, ఆఫ్ చేయడానికి నొక్కండి"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"రాత్రి కాంతి ఆఫ్‌లో ఉంది, ఆన్ చేయడానికి నొక్కండి"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"ఇటీవలి అంశాలు ఏవీ లేవు"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"మీరు అన్నింటినీ తీసివేసారు"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"అనువర్తన సమాచారం"</string>
diff --git a/packages/SystemUI/res/values-th/strings.xml b/packages/SystemUI/res/values-th/strings.xml
index 4f8341f..804bdef 100644
--- a/packages/SystemUI/res/values-th/strings.xml
+++ b/packages/SystemUI/res/values-th/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"คำเตือน <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"โหมดการทำงาน"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"แสงตอนกลางคืน"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"แสงตอนกลางคืนเปิดอยู่ แตะเพื่อปิด"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"แสงตอนกลางคืนปิดอยู่ แตะเพื่อเปิด"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"ไม่มีรายการล่าสุด"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"คุณได้ล้างทุกอย่างแล้ว"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"ข้อมูลแอปพลิเคชัน"</string>
diff --git a/packages/SystemUI/res/values-tl/strings.xml b/packages/SystemUI/res/values-tl/strings.xml
index acaf86c..e2e8c27 100644
--- a/packages/SystemUI/res/values-tl/strings.xml
+++ b/packages/SystemUI/res/values-tl/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Babala sa <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Work mode"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Night Light"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Naka-on ang Night Light, i-tap upang i-off"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Naka-off ang Night Light, i-tap upang i-on"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Walang mga kamakailang item"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Na-clear mo ang lahat"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Impormasyon ng Application"</string>
diff --git a/packages/SystemUI/res/values-tr/strings.xml b/packages/SystemUI/res/values-tr/strings.xml
index b4dc25d..8ee4e1f 100644
--- a/packages/SystemUI/res/values-tr/strings.xml
+++ b/packages/SystemUI/res/values-tr/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> uyarısı"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Çalışma modu"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Gece Işığı"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Geçe Işığı açık, kapatmak için dokunun"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Gece Işığı kapalı, açmak için dokunun"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Yeni öğe yok"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Her şeyi sildiniz"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Uygulama Bilgileri"</string>
diff --git a/packages/SystemUI/res/values-uk/strings.xml b/packages/SystemUI/res/values-uk/strings.xml
index 4d2b6c39..7327a08 100644
--- a/packages/SystemUI/res/values-uk/strings.xml
+++ b/packages/SystemUI/res/values-uk/strings.xml
@@ -325,8 +325,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Застереження: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Робочий режим"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Нічний режим"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Нічний режим увімкнено. Торкніться, щоб вимкнути його"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Нічний режим вимкнено. Торкніться, щоб увімкнути його"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Немає нещодавніх завдань"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Ви очистили все"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Інформація про додаток"</string>
diff --git a/packages/SystemUI/res/values-ur-rPK/strings.xml b/packages/SystemUI/res/values-ur-rPK/strings.xml
index cbe3d23..8048289 100644
--- a/packages/SystemUI/res/values-ur-rPK/strings.xml
+++ b/packages/SystemUI/res/values-ur-rPK/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> وارننگ"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"کام موڈ"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"نائٹ لائٹ"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"نائٹ لائٹ آن ہے، آف کرنے کیلئے تھپتھپائیں"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"نائٹ لائٹ آف ہے، آن کرنے کیلئے تھپتھپائیں"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"کوئی حالیہ آئٹم نہیں"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"آپ نے سب کچھ صاف کر دیا ہے"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"ایپلیکیشن کی معلومات"</string>
diff --git a/packages/SystemUI/res/values-uz-rUZ/strings.xml b/packages/SystemUI/res/values-uz-rUZ/strings.xml
index 3f1bb9b..c14ad93 100644
--- a/packages/SystemUI/res/values-uz-rUZ/strings.xml
+++ b/packages/SystemUI/res/values-uz-rUZ/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Ogohlantirish: <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Ish rejimi"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Tungi rejim"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Tunji rejim yoniq, o‘chirish uchun bosing"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Tunji rejim o‘chiq, yoqish uchun bosing"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Hozircha hech narsa yo‘q"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Hammasi o‘chirildi"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Ilova haqida ma’lumot"</string>
diff --git a/packages/SystemUI/res/values-vi/strings.xml b/packages/SystemUI/res/values-vi/strings.xml
index ceeaf18..062c6c2 100644
--- a/packages/SystemUI/res/values-vi/strings.xml
+++ b/packages/SystemUI/res/values-vi/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"Cảnh báo <xliff:g id="DATA_LIMIT">%s</xliff:g>"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Chế độ làm việc"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Đèn đọc sách"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Đèn đọc sách được bật, nhấn để tắt"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Đèn đọc sách bị tắt, nhấn để bật"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Không có mục gần đây nào"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Bạn đã xóa mọi nội dung"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Thông tin ứng dụng"</string>
diff --git a/packages/SystemUI/res/values-zh-rCN/strings.xml b/packages/SystemUI/res/values-zh-rCN/strings.xml
index 1217318..b98bf14 100644
--- a/packages/SystemUI/res/values-zh-rCN/strings.xml
+++ b/packages/SystemUI/res/values-zh-rCN/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g>警告"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"工作模式"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"夜间模式"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"夜间模式已开启,点按即可关闭"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"夜间模式已关闭,点按即可开启"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"近期没有任何内容"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"您已清除所有内容"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"应用信息"</string>
diff --git a/packages/SystemUI/res/values-zh-rHK/strings.xml b/packages/SystemUI/res/values-zh-rHK/strings.xml
index bb51ebe..d581592 100644
--- a/packages/SystemUI/res/values-zh-rHK/strings.xml
+++ b/packages/SystemUI/res/values-zh-rHK/strings.xml
@@ -321,8 +321,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> 警告"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"工作模式"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"夜燈模式"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"夜燈模式已開啟,輕按即可關閉"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"夜燈模式已關閉,輕按即可開啟"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"沒有最近項目"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"您已清除所有項目"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"應用程式資料"</string>
diff --git a/packages/SystemUI/res/values-zh-rTW/strings.xml b/packages/SystemUI/res/values-zh-rTW/strings.xml
index ac6b002..fa4cacb 100644
--- a/packages/SystemUI/res/values-zh-rTW/strings.xml
+++ b/packages/SystemUI/res/values-zh-rTW/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> 警告"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"工作模式"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"夜燈"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"夜燈功能已開啟,輕觸即可關閉"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"夜燈功能已關閉,輕觸即可開啟"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"最近沒有任何項目"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"您已清除所有工作"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"應用程式資訊"</string>
diff --git a/packages/SystemUI/res/values-zu/strings.xml b/packages/SystemUI/res/values-zu/strings.xml
index 78e22f1..97aa758 100644
--- a/packages/SystemUI/res/values-zu/strings.xml
+++ b/packages/SystemUI/res/values-zu/strings.xml
@@ -319,8 +319,6 @@
     <string name="quick_settings_cellular_detail_data_warning" msgid="2440098045692399009">"<xliff:g id="DATA_LIMIT">%s</xliff:g> isexwayiso"</string>
     <string name="quick_settings_work_mode_label" msgid="6244915274350490429">"Imodi yomsebenzi"</string>
     <string name="quick_settings_night_display_label" msgid="3577098011487644395">"Ukukhanya kwasebusuku"</string>
-    <string name="quick_settings_night_display_summary_on" msgid="1814901757887526769">"Ukukhanya kwasebusuku kuvuliwe, thepha ukuze uvale"</string>
-    <string name="quick_settings_night_display_summary_off" msgid="7892102914128777905">"Ukukhanya kwasebusuku kuvaliwe, thepha ukuze uvule"</string>
     <string name="recents_empty_message" msgid="808480104164008572">"Azikho izinto zakamuva"</string>
     <string name="recents_empty_message_dismissed_all" msgid="2791312568666558651">"Usule yonke into"</string>
     <string name="recents_app_info_button_label" msgid="2890317189376000030">"Ulwazi lohlelo lokusebenza"</string>
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 3f485c3..92e10d2 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -755,10 +755,6 @@
     <string name="quick_settings_work_mode_label">Work mode</string>
     <!-- QuickSettings: Label for the toggle to activate Night display (renamed "Night Light" with title caps). [CHAR LIMIT=20] -->
     <string name="quick_settings_night_display_label">Night Light</string>
-    <!-- QuickSettings: Summary for the toggle to deactivate Night display when it's on (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
-    <string name="quick_settings_night_display_summary_on">Night Light on, tap to turn off</string>
-    <!-- QuickSettings: Label for the toggle to activate Night display when it's off (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
-    <string name="quick_settings_night_display_summary_off">Night Light off, tap to turn on</string>
 
     <!-- Recents: The empty recents string. [CHAR LIMIT=NONE] -->
     <string name="recents_empty_message">No recent items</string>
@@ -1438,8 +1434,8 @@
     <string name="keyboard_shortcut_group_applications_contacts">Contacts</string>
     <!-- User visible title for the keyboard shortcut that takes the user to the email app. -->
     <string name="keyboard_shortcut_group_applications_email">Email</string>
-    <!-- User visible title for the keyboard shortcut that takes the user to the instant messaging app. -->
-    <string name="keyboard_shortcut_group_applications_im">IM</string>
+    <!-- User visible title for the keyboard shortcut that takes the user to the SMS messaging app. -->
+    <string name="keyboard_shortcut_group_applications_sms">SMS</string>
     <!-- User visible title for the keyboard shortcut that takes the user to the music app. -->
     <string name="keyboard_shortcut_group_applications_music">Music</string>
     <!-- User visible title for the keyboard shortcut that takes the user to the YouTube app. -->
diff --git a/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java b/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java
index 40ef6eb..0cd6490 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/customize/TileQueryHelper.java
@@ -64,7 +64,10 @@
         for (int i = 0; i < possibleTiles.length; i++) {
             final String spec = possibleTiles[i];
             final QSTile<?> tile = host.createTile(spec);
-            if (tile == null || !tile.isAvailable()) {
+            if (tile == null) {
+                continue;
+            } else if (!tile.isAvailable()) {
+                tile.destroy();
                 continue;
             }
             tile.setListening(this, true);
@@ -78,6 +81,7 @@
                     tile.getState().copyTo(state);
                     // Ignore the current state and get the generic label instead.
                     state.label = tile.getTileLabel();
+                    tile.destroy();
                     mainHandler.post(new Runnable() {
                         @Override
                         public void run() {
@@ -126,6 +130,7 @@
         state.label = label;
         state.contentDescription = label;
         state.icon = new DrawableIcon(drawable);
+        state.autoMirrorDrawable = false;
         addTile(spec, appLabel, state, false);
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
index b36221d..484e008 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/external/CustomTile.java
@@ -221,7 +221,9 @@
 
     @Override
     public State newTileState() {
-        return new State();
+        State state = new State();
+        state.autoMirrorDrawable = false;
+        return state;
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java
index 89bb1d2..ec4ab51 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/DndTile.java
@@ -69,12 +69,23 @@
 
     private boolean mListening;
     private boolean mShowingDetail;
+    private boolean mReceiverRegistered;
 
     public DndTile(Host host) {
         super(host);
         mController = host.getZenModeController();
         mDetailAdapter = new DndDetailAdapter();
         mContext.registerReceiver(mReceiver, new IntentFilter(ACTION_SET_VISIBLE));
+        mReceiverRegistered = true;
+    }
+
+    @Override
+    protected void handleDestroy() {
+        super.handleDestroy();
+        if (mReceiverRegistered) {
+            mContext.unregisterReceiver(mReceiver);
+            mReceiverRegistered = false;
+        }
     }
 
     public static void setVisible(Context context, boolean visible) {
diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java b/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java
index 9415b27..c02e5ae 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/NightDisplayTile.java
@@ -75,14 +75,12 @@
     protected void handleUpdateState(BooleanState state, Object arg) {
         final boolean isActivated = mController.isActivated();
         state.value = isActivated;
-        state.label = mContext.getString(R.string.quick_settings_night_display_label);
+        state.label = state.contentDescription =
+                mContext.getString(R.string.quick_settings_night_display_label);
         state.icon = ResourceIcon.get(isActivated ? R.drawable.ic_qs_night_display_on
                 : R.drawable.ic_qs_night_display_off);
-        state.contentDescription = mContext.getString(isActivated
-                ? R.string.quick_settings_night_display_summary_on
-                : R.string.quick_settings_night_display_summary_off);
-        state.minimalAccessibilityClassName = state.expandedAccessibilityClassName
-                = Switch.class.getName();
+        state.minimalAccessibilityClassName = state.expandedAccessibilityClassName =
+                Switch.class.getName();
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/recents/Recents.java b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
index 5b25f052..3c245b4 100644
--- a/packages/SystemUI/src/com/android/systemui/recents/Recents.java
+++ b/packages/SystemUI/src/com/android/systemui/recents/Recents.java
@@ -479,6 +479,7 @@
                 return COUNTER_WINDOW_UNSUPPORTED;
             case ActivityInfo.RESIZE_MODE_RESIZEABLE:
             case ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE:
+            case ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION:
                 return COUNTER_WINDOW_SUPPORTED;
             default:
                 return COUNTER_WINDOW_INCOMPATIBLE;
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java
index cb77d7b..4e34bbc 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerView.java
@@ -1113,6 +1113,7 @@
 
     public final void onBusEvent(RecentsActivityStartingEvent recentsActivityStartingEvent) {
         if (mGrowRecents && getWindowManagerProxy().getDockSide() == WindowManager.DOCKED_TOP
+                && getSnapAlgorithm().getMiddleTarget() != getSnapAlgorithm().getLastSplitTarget()
                 && getCurrentPosition() == getSnapAlgorithm().getLastSplitTarget().position) {
             mState.growAfterRecentsDrawn = true;
             startDragging(false /* animate */, false /* touching */);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
index 7a1ea47..4cc7a16 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java
@@ -1719,6 +1719,23 @@
                         sbn.getPackageContext(mContext),
                         contentContainerPublic, mOnClickHandler);
             }
+
+            if (contentViewLocal != null) {
+                contentViewLocal.setIsRootNamespace(true);
+                contentContainer.setContractedChild(contentViewLocal);
+            }
+            if (bigContentViewLocal != null) {
+                bigContentViewLocal.setIsRootNamespace(true);
+                contentContainer.setExpandedChild(bigContentViewLocal);
+            }
+            if (headsUpContentViewLocal != null) {
+                headsUpContentViewLocal.setIsRootNamespace(true);
+                contentContainer.setHeadsUpChild(headsUpContentViewLocal);
+            }
+            if (publicViewLocal != null) {
+                publicViewLocal.setIsRootNamespace(true);
+                contentContainerPublic.setContractedChild(publicViewLocal);
+            }
         }
         catch (RuntimeException e) {
             final String ident = sbn.getPackageName() + "/0x" + Integer.toHexString(sbn.getId());
@@ -1726,23 +1743,6 @@
             return false;
         }
 
-        if (contentViewLocal != null) {
-            contentViewLocal.setIsRootNamespace(true);
-            contentContainer.setContractedChild(contentViewLocal);
-        }
-        if (bigContentViewLocal != null) {
-            bigContentViewLocal.setIsRootNamespace(true);
-            contentContainer.setExpandedChild(bigContentViewLocal);
-        }
-        if (headsUpContentViewLocal != null) {
-            headsUpContentViewLocal.setIsRootNamespace(true);
-            contentContainer.setHeadsUpChild(headsUpContentViewLocal);
-        }
-        if (publicViewLocal != null) {
-            publicViewLocal.setIsRootNamespace(true);
-            contentContainerPublic.setContractedChild(publicViewLocal);
-        }
-
         // Extract target SDK version.
         try {
             ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
index e781f1b..f438762 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyboardShortcuts.java
@@ -488,9 +488,9 @@
         final Icon messagingIcon = getIconForIntentCategory(Intent.CATEGORY_APP_MESSAGING, userId);
         if (messagingIcon != null) {
             keyboardShortcutInfoAppItems.add(new KeyboardShortcutInfo(
-                    mContext.getString(R.string.keyboard_shortcut_group_applications_im),
+                    mContext.getString(R.string.keyboard_shortcut_group_applications_sms),
                     messagingIcon,
-                    KeyEvent.KEYCODE_T,
+                    KeyEvent.KEYCODE_S,
                     KeyEvent.META_META_ON));
         }
 
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 20dddab..7b35cbd 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -1313,9 +1313,12 @@
             }
             return;
         }
-        boolean belowFalsingThreshold = isFalseTouch();
-        if (belowFalsingThreshold) {
+
+        // If we move in the opposite direction, reset velocity and use a different duration.
+        boolean oppositeDirection = false;
+        if (vel > 0 && !expand || vel < 0 && expand) {
             vel = 0;
+            oppositeDirection = true;
         }
         ValueAnimator animator = ValueAnimator.ofFloat(mQsExpansionHeight, target);
         if (isClick) {
@@ -1324,7 +1327,7 @@
         } else {
             mFlingAnimationUtils.apply(animator, mQsExpansionHeight, target, vel);
         }
-        if (belowFalsingThreshold) {
+        if (oppositeDirection) {
             animator.setDuration(350);
         }
         animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java
index b0b86be..a8b0122 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStatusBarHeader.java
@@ -350,9 +350,7 @@
             }
         } else if (v == mAlarmStatus && mNextAlarm != null) {
             PendingIntent showIntent = mNextAlarm.getShowIntent();
-            if (showIntent != null && showIntent.isActivity()) {
-                mActivityStarter.startActivity(showIntent.getIntent(), true /* dismissShade */);
-            }
+            mActivityStarter.startPendingIntentDismissingKeyguard(showIntent);
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
index e3ede46..77c60fb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
@@ -264,10 +264,12 @@
             }
         }
         mOccluded = occluded;
-        mPhoneStatusBar.updateMediaMetaData(false, animate && !occluded);
+        if (mShowing) {
+            mPhoneStatusBar.updateMediaMetaData(false, animate && !occluded);
+        }
         mStatusBarWindowManager.setKeyguardOccluded(occluded);
         reset();
-        if (animate && !occluded) {
+        if (animate && !occluded && mShowing) {
             mPhoneStatusBar.animateKeyguardUnoccluding();
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
index 9bb9830..4b46578 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
@@ -1057,7 +1057,7 @@
     @Override
     public int getMaxExpandHeight(ExpandableView view) {
         int maxContentHeight = view.getMaxContentHeight();
-        if (view.isSummaryWithChildren()) {
+        if (view.isSummaryWithChildren() && view.getParent() == this) {
             // Faking a measure with the group expanded to simulate how the group would look if
             // it was. Doing a calculation here would be highly non-trivial because of the
             // algorithm
@@ -1072,8 +1072,11 @@
                     row.getStatusBarNotification());
             mGroupExpandedForMeasure = false;
             row.setForceUnlocked(false);
-            int height = mCurrentStackScrollState.getViewStateForView(view).height;
-            return Math.min(height, maxContentHeight);
+            StackViewState viewState = mCurrentStackScrollState.getViewStateForView(view);
+            if (viewState != null) {
+                // The view could have been removed
+                return Math.min(viewState.height, maxContentHeight);
+            }
         }
         return maxContentHeight;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java b/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
index 53a54d6..75c2bcd 100644
--- a/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/tv/pip/PipManager.java
@@ -19,13 +19,13 @@
 import android.app.ActivityManager.RunningTaskInfo;
 import android.app.ActivityManager.StackInfo;
 import android.app.ActivityManagerNative;
-import android.app.ActivityOptions;
 import android.app.IActivityManager;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.PackageManager;
 import android.content.res.Resources;
 import android.graphics.Rect;
 import android.media.session.MediaController;
@@ -33,24 +33,27 @@
 import android.media.session.PlaybackState;
 import android.os.Debug;
 import android.os.Handler;
+import android.os.Looper;
 import android.os.RemoteException;
 import android.os.SystemProperties;
 import android.text.TextUtils;
 import android.util.Log;
 import android.util.Pair;
-
+import android.view.IWindowManager;
+import android.view.InputChannel;
+import android.view.InputEvent;
+import android.view.InputEventReceiver;
+import android.view.WindowManagerGlobal;
 import com.android.systemui.Prefs;
 import com.android.systemui.R;
-import com.android.systemui.SystemUIApplication;
-import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
 import com.android.systemui.recents.misc.SystemServicesProxy;
-import com.android.systemui.statusbar.tv.TvStatusBar;
+import com.android.systemui.recents.misc.SystemServicesProxy.TaskStackListener;
 
 import java.util.ArrayList;
 import java.util.List;
 
-import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
+import static android.view.WindowManager.INPUT_CONSUMER_PIP;
 import static com.android.systemui.Prefs.Key.TV_PICTURE_IN_PICTURE_ONBOARDING_SHOWN;
 
 /**
@@ -160,6 +163,9 @@
     private boolean mOnboardingShown;
     private String[] mLastPackagesResourceGranted;
 
+    private InputChannel mInputChannel;
+    private PipInputEventReceiver mInputEventReceiver;
+
     private final Runnable mResizePinnedStackRunnable = new Runnable() {
         @Override
         public void run() {
@@ -197,6 +203,25 @@
                 }
             };
 
+    /**
+     * Input handler used for Pip windows.  Currently eats all the input events.
+     */
+    private final class PipInputEventReceiver extends InputEventReceiver {
+        public PipInputEventReceiver(InputChannel inputChannel, Looper looper) {
+            super(inputChannel, looper);
+        }
+
+        @Override
+        public void onInputEvent(InputEvent event) {
+            boolean handled = true;
+            try {
+                // To be implemented for input handling over Pip windows
+            } finally {
+                finishInputEvent(event, handled);
+            }
+        }
+    }
+
     private PipManager() { }
 
     /**
@@ -221,6 +246,20 @@
         mPipRecentsOverlayManager = new PipRecentsOverlayManager(context);
         mMediaSessionManager =
                 (MediaSessionManager) mContext.getSystemService(Context.MEDIA_SESSION_SERVICE);
+
+        PackageManager pm = mContext.getPackageManager();
+        if (!pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY)) {
+            // Initialize the Pip input consumer
+            mInputChannel = new InputChannel();
+            try {
+                IWindowManager wm = WindowManagerGlobal.getWindowManagerService();
+                wm.destroyInputConsumer(INPUT_CONSUMER_PIP);
+                wm.createInputConsumer(INPUT_CONSUMER_PIP, mInputChannel);
+                mInputEventReceiver = new PipInputEventReceiver(mInputChannel, Looper.myLooper());
+            } catch (RemoteException e) {
+                Log.e(TAG, "Failed to create Pip input consumer", e);
+            }
+        }
     }
 
     private void loadConfigurationsAndApply() {
@@ -308,7 +347,11 @@
      */
     private void showPipOverlay() {
         if (DEBUG) Log.d(TAG, "showPipOverlay()");
-        PipOverlayActivity.showPipOverlay(mContext);
+        // Temporary workaround to prevent the overlay on phones
+        PackageManager pm = mContext.getPackageManager();
+        if (pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK_ONLY)) {
+            PipOverlayActivity.showPipOverlay(mContext);
+        }
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/tv/pip/PipUI.java b/packages/SystemUI/src/com/android/systemui/tv/pip/PipUI.java
index b3e9f43..3306cb3 100644
--- a/packages/SystemUI/src/com/android/systemui/tv/pip/PipUI.java
+++ b/packages/SystemUI/src/com/android/systemui/tv/pip/PipUI.java
@@ -21,11 +21,10 @@
 
 import com.android.systemui.SystemUI;
 
-import static android.content.pm.PackageManager.FEATURE_LEANBACK;
 import static android.content.pm.PackageManager.FEATURE_PICTURE_IN_PICTURE;
 
 /**
- * Controls the picture-in-picture window for TV devices.
+ * Controls the picture-in-picture window.
  */
 public class PipUI extends SystemUI {
     private boolean mSupportPip;
@@ -33,8 +32,7 @@
     @Override
     public void start() {
         PackageManager pm = mContext.getPackageManager();
-        mSupportPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE)
-                && pm.hasSystemFeature(FEATURE_LEANBACK);
+        mSupportPip = pm.hasSystemFeature(FEATURE_PICTURE_IN_PICTURE);
         if (!mSupportPip) {
             return;
         }
diff --git a/preloaded-classes b/preloaded-classes
index 42f290e..5ddd08b 100644
--- a/preloaded-classes
+++ b/preloaded-classes
@@ -2077,9 +2077,6 @@
 android.view.HandlerActionQueue
 android.view.HandlerActionQueue$HandlerAction
 android.view.HardwareLayer
-android.view.IAssetAtlas
-android.view.IAssetAtlas$Stub
-android.view.IAssetAtlas$Stub$Proxy
 android.view.IGraphicsStats
 android.view.IGraphicsStats$Stub
 android.view.IGraphicsStats$Stub$Proxy
diff --git a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
index 54c9afe..4819c0a 100644
--- a/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
+++ b/services/accessibility/java/com/android/server/accessibility/AccessibilityManagerService.java
@@ -64,6 +64,7 @@
 import android.os.SystemClock;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.os.UserManagerInternal;
 import android.provider.Settings;
 import android.text.TextUtils;
 import android.text.TextUtils.SimpleStringSplitter;
@@ -1301,14 +1302,8 @@
     private void updateServicesLocked(UserState userState) {
         Map<ComponentName, Service> componentNameToServiceMap =
                 userState.mComponentNameToServiceMap;
-        boolean isUnlockingOrUnlocked;
-        final long identity = Binder.clearCallingIdentity();
-        try {
-            isUnlockingOrUnlocked = mContext.getSystemService(UserManager.class)
+        boolean isUnlockingOrUnlocked = LocalServices.getService(UserManagerInternal.class)
                     .isUserUnlockingOrUnlocked(userState.mUserId);
-        } finally {
-            Binder.restoreCallingIdentity(identity);
-        }
 
         for (int i = 0, count = userState.mInstalledServices.size(); i < count; i++) {
             AccessibilityServiceInfo installedService = userState.mInstalledServices.get(i);
diff --git a/services/backup/java/com/android/server/backup/BackupManagerService.java b/services/backup/java/com/android/server/backup/BackupManagerService.java
index 497eac9..8424b39 100644
--- a/services/backup/java/com/android/server/backup/BackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/BackupManagerService.java
@@ -6057,7 +6057,11 @@
                                         // the app developer's cert, so they're different on every
                                         // device.
                                         if (signaturesMatch(sigs, pkgInfo)) {
-                                            if (pkgInfo.versionCode >= version) {
+                                            if ((pkgInfo.applicationInfo.flags
+                                                    & ApplicationInfo.FLAG_RESTORE_ANY_VERSION) != 0) {
+                                                Slog.i(TAG, "Package has restoreAnyVersion; taking data");
+                                                policy = RestorePolicy.ACCEPT;
+                                            } else if (pkgInfo.versionCode >= version) {
                                                 Slog.i(TAG, "Sig + version match; taking data");
                                                 policy = RestorePolicy.ACCEPT;
                                             } else {
@@ -7479,7 +7483,11 @@
                                         // the app developer's cert, so they're different on every
                                         // device.
                                         if (signaturesMatch(sigs, pkgInfo)) {
-                                            if (pkgInfo.versionCode >= version) {
+                                            if ((pkgInfo.applicationInfo.flags
+                                                    & ApplicationInfo.FLAG_RESTORE_ANY_VERSION) != 0) {
+                                                Slog.i(TAG, "Package has restoreAnyVersion; taking data");
+                                                policy = RestorePolicy.ACCEPT;
+                                            } else if (pkgInfo.versionCode >= version) {
                                                 Slog.i(TAG, "Sig + version match; taking data");
                                                 policy = RestorePolicy.ACCEPT;
                                             } else {
diff --git a/services/core/Android.mk b/services/core/Android.mk
index 58f2074..9efafb7 100644
--- a/services/core/Android.mk
+++ b/services/core/Android.mk
@@ -17,7 +17,12 @@
 LOCAL_AIDL_INCLUDES += \
     system/netd/server/binder
 
-LOCAL_JAVA_LIBRARIES := services.net telephony-common
+LOCAL_JAVA_LIBRARIES := \
+    services.net \
+    telephony-common \
+    android.hardware.power@1.0-java \
+    android.hardware.light@2.0-java
+
 LOCAL_STATIC_JAVA_LIBRARIES := tzdata_update
 LOCAL_PROTOC_OPTIMIZE_TYPE := nano
 
diff --git a/services/core/java/com/android/server/AssetAtlasService.java b/services/core/java/com/android/server/AssetAtlasService.java
deleted file mode 100644
index b0f6048..0000000
--- a/services/core/java/com/android/server/AssetAtlasService.java
+++ /dev/null
@@ -1,717 +0,0 @@
-/*
- * Copyright (C) 2013 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 com.android.server;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.res.Resources;
-import android.graphics.Atlas;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
-import android.graphics.Paint;
-import android.graphics.PixelFormat;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffXfermode;
-import android.graphics.drawable.Drawable;
-import android.os.Environment;
-import android.os.RemoteException;
-import android.os.SystemProperties;
-import android.util.Log;
-import android.util.LongSparseArray;
-import android.view.GraphicBuffer;
-import android.view.IAssetAtlas;
-
-import java.io.BufferedReader;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.OutputStreamWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * This service is responsible for packing preloaded bitmaps into a single
- * atlas texture. The resulting texture can be shared across processes to
- * reduce overall memory usage.
- *
- * @hide
- */
-public class AssetAtlasService extends IAssetAtlas.Stub {
-    /**
-     * Name of the <code>AssetAtlasService</code>.
-     */
-    public static final String ASSET_ATLAS_SERVICE = "assetatlas";
-
-    private static final String LOG_TAG = "AssetAtlas";
-
-    // Turns debug logs on/off. Debug logs are kept to a minimum and should
-    // remain on to diagnose issues
-    private static final boolean DEBUG_ATLAS = true;
-
-    // When set to true the content of the atlas will be saved to disk
-    // in /data/system/atlas.png. The shared GraphicBuffer may be empty
-    private static final boolean DEBUG_ATLAS_TEXTURE = false;
-
-    // Minimum size in pixels to consider for the resulting texture
-    private static final int MIN_SIZE = 512;
-    // Maximum size in pixels to consider for the resulting texture
-    private static final int MAX_SIZE = 2048;
-    // Increment in number of pixels between size variants when looking
-    // for the best texture dimensions
-    private static final int STEP = 64;
-
-    // This percentage of the total number of pixels represents the minimum
-    // number of pixels we want to be able to pack in the atlas
-    private static final float PACKING_THRESHOLD = 0.8f;
-
-    // Defines the number of int fields used to represent a single entry
-    // in the atlas map. This number defines the size of the array returned
-    // by the getMap(). See the mAtlasMap field for more information
-    private static final int ATLAS_MAP_ENTRY_FIELD_COUNT = 3;
-
-    // Specifies how our GraphicBuffer will be used. To get proper swizzling
-    // the buffer will be written to using OpenGL (from JNI) so we can leave
-    // the software flag set to "never"
-    private static final int GRAPHIC_BUFFER_USAGE = GraphicBuffer.USAGE_SW_READ_NEVER |
-            GraphicBuffer.USAGE_SW_WRITE_NEVER | GraphicBuffer.USAGE_HW_TEXTURE;
-
-    // This boolean is set to true if an atlas was successfully
-    // computed and rendered
-    private final AtomicBoolean mAtlasReady = new AtomicBoolean(false);
-
-    private final Context mContext;
-
-    // Version name of the current build, used to identify changes to assets list
-    private final String mVersionName;
-
-    // Holds the atlas' data. This buffer can be mapped to
-    // OpenGL using an EGLImage
-    private GraphicBuffer mBuffer;
-
-    // Describes how bitmaps are placed in the atlas. Each bitmap is
-    // represented by several entries in the array:
-    // long0: SkBitmap*, the native bitmap object
-    // long1: x position
-    // long2: y position
-    private long[] mAtlasMap;
-
-    /**
-     * Creates a new service. Upon creating, the service will gather the list of
-     * assets to consider for packing into the atlas and spawn a new thread to
-     * start the packing work.
-     *
-     * @param context The context giving access to preloaded resources
-     */
-    public AssetAtlasService(Context context) {
-        mContext = context;
-        mVersionName = queryVersionName(context);
-
-        Collection<Bitmap> bitmaps = new HashSet<Bitmap>(300);
-        int totalPixelCount = 0;
-
-        // We only care about drawables that hold bitmaps
-        final Resources resources = context.getResources();
-        final LongSparseArray<Drawable.ConstantState> drawables = resources.getPreloadedDrawables();
-
-        final int count = drawables.size();
-        for (int i = 0; i < count; i++) {
-            try {
-                totalPixelCount += drawables.valueAt(i).addAtlasableBitmaps(bitmaps);
-            } catch (Throwable t) {
-                Log.e("AssetAtlas", "Failed to fetch preloaded drawable state", t);
-                throw t;
-            }
-        }
-
-        ArrayList<Bitmap> sortedBitmaps = new ArrayList<Bitmap>(bitmaps);
-        // Our algorithms perform better when the bitmaps are first sorted
-        // The comparator will sort the bitmap by width first, then by height
-        Collections.sort(sortedBitmaps, new Comparator<Bitmap>() {
-            @Override
-            public int compare(Bitmap b1, Bitmap b2) {
-                if (b1.getWidth() == b2.getWidth()) {
-                    return b2.getHeight() - b1.getHeight();
-                }
-                return b2.getWidth() - b1.getWidth();
-            }
-        });
-
-        // Kick off the packing work on a worker thread
-        new Thread(new Renderer(sortedBitmaps, totalPixelCount)).start();
-    }
-
-    /**
-     * Queries the version name stored in framework's AndroidManifest.
-     * The version name can be used to identify possible changes to
-     * framework resources.
-     *
-     * @see #getBuildIdentifier(String)
-     */
-    private static String queryVersionName(Context context) {
-        try {
-            String packageName = context.getPackageName();
-            PackageInfo info = context.getPackageManager().getPackageInfo(packageName,
-                    PackageManager.MATCH_DEBUG_TRIAGED_MISSING);
-            return info.versionName;
-        } catch (PackageManager.NameNotFoundException e) {
-            Log.w(LOG_TAG, "Could not get package info", e);
-        }
-        return null;
-    }
-
-    /**
-     * Callback invoked by the server thread to indicate we can now run
-     * 3rd party code.
-     */
-    public void systemRunning() {
-    }
-
-    /**
-     * The renderer does all the work:
-     */
-    private class Renderer implements Runnable {
-        private final ArrayList<Bitmap> mBitmaps;
-        private final int mPixelCount;
-
-        Renderer(ArrayList<Bitmap> bitmaps, int pixelCount) {
-            mBitmaps = bitmaps;
-            mPixelCount = pixelCount;
-        }
-
-        /**
-         * 1. On first boot or after every update, brute-force through all the
-         *    possible atlas configurations and look for the best one (maximimize
-         *    number of packed assets and minimize texture size)
-         *    a. If a best configuration was computed, write it out to disk for
-         *       future use
-         * 2. Read best configuration from disk
-         * 3. Compute the packing using the best configuration
-         * 4. Allocate a GraphicBuffer
-         * 5. Render assets in the buffer
-         */
-        @Override
-        public void run() {
-            Configuration config = chooseConfiguration(mBitmaps, mPixelCount, mVersionName);
-            if (DEBUG_ATLAS) Log.d(LOG_TAG, "Loaded configuration: " + config);
-
-            if (config != null) {
-                mBuffer = GraphicBuffer.create(config.width, config.height,
-                        PixelFormat.RGBA_8888, GRAPHIC_BUFFER_USAGE);
-
-                if (mBuffer != null) {
-                    Atlas atlas = new Atlas(config.type, config.width, config.height, config.flags);
-                    if (renderAtlas(mBuffer, atlas, config.count)) {
-                        mAtlasReady.set(true);
-                    }
-                }
-            }
-        }
-
-        /**
-         * Renders a list of bitmaps into the atlas. The position of each bitmap
-         * was decided by the packing algorithm and will be honored by this
-         * method.
-         *
-         * @param buffer The buffer to render the atlas entries into
-         * @param atlas The atlas to pack the bitmaps into
-         * @param packCount The number of bitmaps that will be packed in the atlas
-         *
-         * @return true if the atlas was rendered, false otherwise
-         */
-        @SuppressWarnings("MismatchedReadAndWriteOfArray")
-        private boolean renderAtlas(GraphicBuffer buffer, Atlas atlas, int packCount) {
-            // Use a Source blend mode to improve performance, the target bitmap
-            // will be zero'd out so there's no need to waste time applying blending
-            final Paint paint = new Paint();
-            paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
-
-            // We always render the atlas into a bitmap. This bitmap is then
-            // uploaded into the GraphicBuffer using OpenGL to swizzle the content
-            final Bitmap atlasBitmap = Bitmap.createBitmap(
-                    buffer.getWidth(), buffer.getHeight(), Bitmap.Config.ARGB_8888);
-            final Canvas canvas = new Canvas(atlasBitmap);
-
-            final Atlas.Entry entry = new Atlas.Entry();
-
-            mAtlasMap = new long[packCount * ATLAS_MAP_ENTRY_FIELD_COUNT];
-            long[] atlasMap = mAtlasMap;
-            int mapIndex = 0;
-
-            boolean result = false;
-            final long startRender = System.nanoTime();
-            final int count = mBitmaps.size();
-
-            for (int i = 0; i < count; i++) {
-                final Bitmap bitmap = mBitmaps.get(i);
-                if (atlas.pack(bitmap.getWidth(), bitmap.getHeight(), entry) != null) {
-                    // We have more bitmaps to pack than the current configuration
-                    // says, we were most likely not able to detect a change in the
-                    // list of preloaded drawables, abort and delete the configuration
-                    if (mapIndex >= mAtlasMap.length) {
-                        deleteDataFile();
-                        break;
-                    }
-
-                    canvas.save();
-                    canvas.translate(entry.x, entry.y);
-                    canvas.drawBitmap(bitmap, 0.0f, 0.0f, null);
-                    canvas.restore();
-                    atlasMap[mapIndex++] = bitmap.refSkPixelRef();
-                    atlasMap[mapIndex++] = entry.x;
-                    atlasMap[mapIndex++] = entry.y;
-                }
-            }
-
-            final long endRender = System.nanoTime();
-            releaseCanvas(canvas, atlasBitmap);
-            result = nUploadAtlas(buffer, atlasBitmap);
-            atlasBitmap.recycle();
-            final long endUpload = System.nanoTime();
-
-            if (DEBUG_ATLAS) {
-                float renderDuration = (endRender - startRender) / 1000.0f / 1000.0f;
-                float uploadDuration = (endUpload - endRender) / 1000.0f / 1000.0f;
-                Log.d(LOG_TAG, String.format("Rendered atlas in %.2fms (%.2f+%.2fms)",
-                        renderDuration + uploadDuration, renderDuration, uploadDuration));
-            }
-
-            return result;
-        }
-
-        /**
-         * Releases the canvas used to render into the buffer. Calling this method
-         * will release any resource previously acquired. If {@link #DEBUG_ATLAS_TEXTURE}
-         * is turend on, calling this method will write the content of the atlas
-         * to disk in /data/system/atlas.png for debugging.
-         */
-        private void releaseCanvas(Canvas canvas, Bitmap atlasBitmap) {
-            canvas.setBitmap(null);
-            if (DEBUG_ATLAS_TEXTURE) {
-
-                File systemDirectory = new File(Environment.getDataDirectory(), "system");
-                File dataFile = new File(systemDirectory, "atlas.png");
-
-                try {
-                    FileOutputStream out = new FileOutputStream(dataFile);
-                    atlasBitmap.compress(Bitmap.CompressFormat.PNG, 100, out);
-                    out.close();
-                } catch (FileNotFoundException e) {
-                    // Ignore
-                } catch (IOException e) {
-                    // Ignore
-                }
-            }
-        }
-    }
-
-    private static native boolean nUploadAtlas(GraphicBuffer buffer, Bitmap bitmap);
-
-    @Override
-    public boolean isCompatible(int ppid) {
-        return ppid == android.os.Process.myPpid();
-    }
-
-    @Override
-    public GraphicBuffer getBuffer() throws RemoteException {
-        return mAtlasReady.get() ? mBuffer : null;
-    }
-
-    @Override
-    public long[] getMap() throws RemoteException {
-        return mAtlasReady.get() ? mAtlasMap : null;
-    }
-
-    /**
-     * Finds the best atlas configuration to pack the list of supplied bitmaps.
-     * This method takes advantage of multi-core systems by spawning a number
-     * of threads equal to the number of available cores.
-     */
-    private static Configuration computeBestConfiguration(
-            ArrayList<Bitmap> bitmaps, int pixelCount) {
-        if (DEBUG_ATLAS) Log.d(LOG_TAG, "Computing best atlas configuration...");
-
-        long begin = System.nanoTime();
-        List<WorkerResult> results = Collections.synchronizedList(new ArrayList<WorkerResult>());
-
-        // Don't bother with an extra thread if there's only one processor
-        int cpuCount = Runtime.getRuntime().availableProcessors();
-        if (cpuCount == 1) {
-            new ComputeWorker(MIN_SIZE, MAX_SIZE, STEP, bitmaps, pixelCount, results, null).run();
-        } else {
-            int start = MIN_SIZE + (cpuCount - 1) * STEP;
-            int end = MAX_SIZE;
-            int step = STEP * cpuCount;
-
-            final CountDownLatch signal = new CountDownLatch(cpuCount);
-
-            for (int i = 0; i < cpuCount; i++, start -= STEP, end -= STEP) {
-                ComputeWorker worker = new ComputeWorker(start, end, step,
-                        bitmaps, pixelCount, results, signal);
-                new Thread(worker, "Atlas Worker #" + (i + 1)).start();
-            }
-
-            boolean isAllWorkerFinished;
-            try {
-                isAllWorkerFinished = signal.await(10, TimeUnit.SECONDS);
-            } catch (InterruptedException e) {
-                Log.w(LOG_TAG, "Could not complete configuration computation");
-                return null;
-            }
-
-            if (!isAllWorkerFinished) {
-                // We have to abort here, otherwise the async updates on "results" would crash the
-                // sort later.
-                Log.w(LOG_TAG, "Could not complete configuration computation before timeout.");
-                return null;
-            }
-        }
-
-        // Maximize the number of packed bitmaps, minimize the texture size
-        Collections.sort(results, new Comparator<WorkerResult>() {
-            @Override
-            public int compare(WorkerResult r1, WorkerResult r2) {
-                int delta = r2.count - r1.count;
-                if (delta != 0) return delta;
-                return r1.width * r1.height - r2.width * r2.height;
-            }
-        });
-
-        if (DEBUG_ATLAS) {
-            float delay = (System.nanoTime() - begin) / 1000.0f / 1000.0f / 1000.0f;
-            Log.d(LOG_TAG, String.format("Found best atlas configuration (out of %d) in %.2fs",
-                    results.size(), delay));
-        }
-
-        WorkerResult result = results.get(0);
-        return new Configuration(result.type, result.width, result.height, result.count);
-    }
-
-    /**
-     * Returns the path to the file containing the best computed
-     * atlas configuration.
-     */
-    private static File getDataFile() {
-        File systemDirectory = new File(Environment.getDataDirectory(), "system");
-        return new File(systemDirectory, "framework_atlas.config");
-    }
-
-    private static void deleteDataFile() {
-        Log.w(LOG_TAG, "Current configuration inconsistent with assets list");
-        if (!getDataFile().delete()) {
-            Log.w(LOG_TAG, "Could not delete the current configuration");
-        }
-    }
-
-    private File getFrameworkResourcesFile() {
-        return new File(mContext.getApplicationInfo().sourceDir);
-    }
-
-    /**
-     * Returns the best known atlas configuration. This method will either
-     * read the configuration from disk or start a brute-force search
-     * and save the result out to disk.
-     */
-    private Configuration chooseConfiguration(ArrayList<Bitmap> bitmaps, int pixelCount,
-            String versionName) {
-        Configuration config = null;
-
-        final File dataFile = getDataFile();
-        if (dataFile.exists()) {
-            config = readConfiguration(dataFile, versionName);
-        }
-
-        if (config == null) {
-            config = computeBestConfiguration(bitmaps, pixelCount);
-            if (config != null) writeConfiguration(config, dataFile, versionName);
-        }
-
-        return config;
-    }
-
-    /**
-     * Writes the specified atlas configuration to the specified file.
-     */
-    private void writeConfiguration(Configuration config, File file, String versionName) {
-        BufferedWriter writer = null;
-        try {
-            writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
-            writer.write(getBuildIdentifier(versionName));
-            writer.newLine();
-            writer.write(config.type.toString());
-            writer.newLine();
-            writer.write(String.valueOf(config.width));
-            writer.newLine();
-            writer.write(String.valueOf(config.height));
-            writer.newLine();
-            writer.write(String.valueOf(config.count));
-            writer.newLine();
-            writer.write(String.valueOf(config.flags));
-            writer.newLine();
-        } catch (FileNotFoundException e) {
-            Log.w(LOG_TAG, "Could not write " + file, e);
-        } catch (IOException e) {
-            Log.w(LOG_TAG, "Could not write " + file, e);
-        } finally {
-            if (writer != null) {
-                try {
-                    writer.close();
-                } catch (IOException e) {
-                    // Ignore
-                }
-            }
-        }
-    }
-
-    /**
-     * Reads an atlas configuration from the specified file. This method
-     * returns null if an error occurs or if the configuration is invalid.
-     */
-    private Configuration readConfiguration(File file, String versionName) {
-        BufferedReader reader = null;
-        Configuration config = null;
-        try {
-            reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
-
-            if (checkBuildIdentifier(reader, versionName)) {
-                Atlas.Type type = Atlas.Type.valueOf(reader.readLine());
-                int width = readInt(reader, MIN_SIZE, MAX_SIZE);
-                int height = readInt(reader, MIN_SIZE, MAX_SIZE);
-                int count = readInt(reader, 0, Integer.MAX_VALUE);
-                int flags = readInt(reader, Integer.MIN_VALUE, Integer.MAX_VALUE);
-
-                config = new Configuration(type, width, height, count, flags);
-            }
-        } catch (IllegalArgumentException e) {
-            Log.w(LOG_TAG, "Invalid parameter value in " + file, e);
-        } catch (FileNotFoundException e) {
-            Log.w(LOG_TAG, "Could not read " + file, e);
-        } catch (IOException e) {
-            Log.w(LOG_TAG, "Could not read " + file, e);
-        } finally {
-            if (reader != null) {
-                try {
-                    reader.close();
-                } catch (IOException e) {
-                    // Ignore
-                }
-            }
-        }
-        return config;
-    }
-
-    private static int readInt(BufferedReader reader, int min, int max) throws IOException {
-        return Math.max(min, Math.min(max, Integer.parseInt(reader.readLine())));
-    }
-
-    /**
-     * Compares the next line in the specified buffered reader to the current
-     * build identifier. Returns whether the two values are equal.
-     *
-     * @see #getBuildIdentifier(String)
-     */
-    private boolean checkBuildIdentifier(BufferedReader reader, String versionName)
-            throws IOException {
-        String deviceBuildId = getBuildIdentifier(versionName);
-        String buildId = reader.readLine();
-        return deviceBuildId.equals(buildId);
-    }
-
-    /**
-     * Returns an identifier for the current build that can be used to detect
-     * likely changes to framework resources. The build identifier is made of
-     * several distinct values:
-     *
-     * build fingerprint/framework version name/file size of framework resources apk
-     *
-     * Only the build fingerprint should be necessary on user builds but
-     * the other values are useful to detect changes on eng builds during
-     * development.
-     *
-     * This identifier does not attempt to be exact: a new identifier does not
-     * necessarily mean the preloaded drawables have changed. It is important
-     * however that whenever the list of preloaded drawables changes, this
-     * identifier changes as well.
-     *
-     * @see #checkBuildIdentifier(java.io.BufferedReader, String)
-     */
-    private String getBuildIdentifier(String versionName) {
-        return SystemProperties.get("ro.build.fingerprint", "") + '/' + versionName + '/' +
-                String.valueOf(getFrameworkResourcesFile().length());
-    }
-
-    /**
-     * Atlas configuration. Specifies the algorithm, dimensions and flags to use.
-     */
-    private static class Configuration {
-        final Atlas.Type type;
-        final int width;
-        final int height;
-        final int count;
-        final int flags;
-
-        Configuration(Atlas.Type type, int width, int height, int count) {
-            this(type, width, height, count, Atlas.FLAG_DEFAULTS);
-        }
-
-        Configuration(Atlas.Type type, int width, int height, int count, int flags) {
-            this.type = type;
-            this.width = width;
-            this.height = height;
-            this.count = count;
-            this.flags = flags;
-        }
-
-        @Override
-        public String toString() {
-            return type.toString() + " (" + width + "x" + height + ") flags=0x" +
-                    Integer.toHexString(flags) + " count=" + count;
-        }
-    }
-
-    /**
-     * Used during the brute-force search to gather information about each
-     * variant of the packing algorithm.
-     */
-    private static class WorkerResult {
-        Atlas.Type type;
-        int width;
-        int height;
-        int count;
-
-        WorkerResult(Atlas.Type type, int width, int height, int count) {
-            this.type = type;
-            this.width = width;
-            this.height = height;
-            this.count = count;
-        }
-
-        @Override
-        public String toString() {
-            return String.format("%s %dx%d", type.toString(), width, height);
-        }
-    }
-
-    /**
-     * A compute worker will try a finite number of variations of the packing
-     * algorithms and save the results in a supplied list.
-     */
-    private static class ComputeWorker implements Runnable {
-        private final int mStart;
-        private final int mEnd;
-        private final int mStep;
-        private final List<Bitmap> mBitmaps;
-        private final List<WorkerResult> mResults;
-        private final CountDownLatch mSignal;
-        private final int mThreshold;
-
-        /**
-         * Creates a new compute worker to brute-force through a range of
-         * packing algorithms variants.
-         *
-         * @param start The minimum texture width to try
-         * @param end The maximum texture width to try
-         * @param step The number of pixels to increment the texture width by at each step
-         * @param bitmaps The list of bitmaps to pack in the atlas
-         * @param pixelCount The total number of pixels occupied by the list of bitmaps
-         * @param results The list of results in which to save the brute-force search results
-         * @param signal Latch to decrement when this worker is done, may be null
-         */
-        ComputeWorker(int start, int end, int step, List<Bitmap> bitmaps, int pixelCount,
-                List<WorkerResult> results, CountDownLatch signal) {
-            mStart = start;
-            mEnd = end;
-            mStep = step;
-            mBitmaps = bitmaps;
-            mResults = results;
-            mSignal = signal;
-
-            // Minimum number of pixels we want to be able to pack
-            int threshold = (int) (pixelCount * PACKING_THRESHOLD);
-            // Make sure we can find at least one configuration
-            while (threshold > MAX_SIZE * MAX_SIZE) {
-                threshold >>= 1;
-            }
-            mThreshold = threshold;
-        }
-
-        @Override
-        public void run() {
-            if (DEBUG_ATLAS) Log.d(LOG_TAG, "Running " + Thread.currentThread().getName());
-
-            Atlas.Entry entry = new Atlas.Entry();
-
-            for (int width = mEnd; width > mStart; width -= mStep) {
-                for (int height = MAX_SIZE; height > MIN_SIZE; height -= STEP) {
-                    // If the atlas is not big enough, skip it
-                    if (width * height <= mThreshold) continue;
-
-                    boolean packSuccess = false;
-
-                    for (Atlas.Type type : Atlas.Type.values()) {
-                        final int count = packBitmaps(type, width, height, entry);
-                        if (count > 0) {
-                            mResults.add(new WorkerResult(type, width, height, count));
-                            if (count == mBitmaps.size()) {
-                                // If we were able to pack everything let's stop here
-                                // Changing the type further won't make things better
-                                packSuccess = true;
-                                break;
-                            }
-                        }
-                    }
-
-                    // If we were not able to pack everything let's stop here
-                    // Decreasing the height further won't make things better
-                    if (!packSuccess) {
-                        break;
-                    }
-                }
-            }
-
-            if (mSignal != null) {
-                mSignal.countDown();
-            }
-        }
-
-        private int packBitmaps(Atlas.Type type, int width, int height, Atlas.Entry entry) {
-            int total = 0;
-            Atlas atlas = new Atlas(type, width, height);
-
-            final int count = mBitmaps.size();
-            for (int i = 0; i < count; i++) {
-                final Bitmap bitmap = mBitmaps.get(i);
-                if (atlas.pack(bitmap.getWidth(), bitmap.getHeight(), entry) != null) {
-                    total++;
-                }
-            }
-
-            return total;
-        }
-    }
-}
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index e85fa25..097d2a5 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1121,18 +1121,12 @@
      */
     final AppOpsService mAppOpsService;
 
-    /**
-     * Current global configuration information. Contains general settings for the entire system,
-     * also corresponds to the merged configuration of the default display.
-     */
-    Configuration mGlobalConfiguration = new Configuration();
-
     /** Current sequencing integer of the configuration, for skipping old configurations. */
     private int mConfigurationSeq;
 
     /**
      * Temp object used when global configuration is updated. It is also sent to outer world
-     * instead of {@link #mGlobalConfiguration} because we don't trust anyone...
+     * instead of {@link #getGlobalConfiguration} because we don't trust anyone...
      */
     private Configuration mTempGlobalConfig = new Configuration();
 
@@ -1582,6 +1576,14 @@
 
     final boolean mPermissionReviewRequired;
 
+    /**
+     * Current global configuration information. Contains general settings for the entire system,
+     * also corresponds to the merged configuration of the default display.
+     */
+    Configuration getGlobalConfiguration() {
+        return mStackSupervisor.getConfiguration();
+    }
+
     final class KillHandler extends Handler {
         static final int KILL_PROCESS_GROUP_MSG = 4000;
 
@@ -2329,7 +2331,7 @@
                     callingPackage = r.info.getComponentName();
                     if (mInVrMode != vrMode) {
                         mInVrMode = vrMode;
-                        mShowDialogs = shouldShowDialogs(mGlobalConfiguration, mInVrMode);
+                        mShowDialogs = shouldShowDialogs(getGlobalConfiguration(), mInVrMode);
                         if (r.app != null) {
                             ProcessRecord proc = r.app;
                             if (proc.vrThreadTid > 0) {
@@ -2705,15 +2707,16 @@
 
         mTrackingAssociations = "1".equals(SystemProperties.get("debug.track-associations"));
 
-        mGlobalConfiguration.setToDefaults();
-        mGlobalConfiguration.setLocales(LocaleList.getDefault());
+        mTempGlobalConfig.setToDefaults();
+        mTempGlobalConfig.setLocales(LocaleList.getDefault());
+        mConfigurationSeq = mTempGlobalConfig.seq = 1;
 
-        mConfigurationSeq = mGlobalConfiguration.seq = 1;
         mProcessCpuTracker.init();
 
+        mStackSupervisor = new ActivityStackSupervisor(this);
+        mStackSupervisor.onConfigurationChanged(mTempGlobalConfig);
         mCompatModePackages = new CompatModePackages(this, systemDir, mHandler);
         mIntentFirewall = new IntentFirewall(new IntentFirewallInterface(), mHandler);
-        mStackSupervisor = new ActivityStackSupervisor(this);
         mActivityStarter = new ActivityStarter(this, mStackSupervisor);
         mRecentTasks = new RecentTasks(this, mStackSupervisor);
 
@@ -3145,8 +3148,9 @@
     }
 
     final void showUnsupportedZoomDialogIfNeededLocked(ActivityRecord r) {
-        if (mGlobalConfiguration.densityDpi != DisplayMetrics.DENSITY_DEVICE_STABLE
-                && r.appInfo.requiresSmallestWidthDp > mGlobalConfiguration.smallestScreenWidthDp) {
+        final Configuration globalConfig = getGlobalConfiguration();
+        if (globalConfig.densityDpi != DisplayMetrics.DENSITY_DEVICE_STABLE
+                && r.appInfo.requiresSmallestWidthDp > globalConfig.smallestScreenWidthDp) {
             final Message msg = Message.obtain();
             msg.what = SHOW_UNSUPPORTED_DISPLAY_SIZE_DIALOG_MSG;
             msg.obj = r;
@@ -4757,7 +4761,7 @@
             final long origId = Binder.clearCallingIdentity();
             mWindowManager.setAppOrientation(r.appToken, requestedOrientation);
             Configuration config = mWindowManager.updateOrientationFromAppTokens(
-                    mGlobalConfiguration, r.mayFreezeScreenLocked(r.app) ? r.appToken : null);
+                    getGlobalConfiguration(), r.mayFreezeScreenLocked(r.app) ? r.appToken : null);
             if (config != null) {
                 r.frozenBeforeDestroy = true;
                 if (!updateConfigurationLocked(config, r, false)) {
@@ -4789,7 +4793,8 @@
             final long origId = Binder.clearCallingIdentity();
             try {
                 r.forceNewConfig = true;
-                r.getStack().ensureActivityConfigurationLocked(r, 0, false);
+                r.ensureActivityConfigurationLocked(0 /* globalChanges */,
+                        false /* preserveWindow */);
             } finally {
                 Binder.restoreCallingIdentity(origId);
             }
@@ -6544,7 +6549,7 @@
                                  PackageManager.NOTIFY_PACKAGE_USE_INSTRUMENTATION);
             }
             if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Binding proc "
-                    + processName + " with config " + mGlobalConfiguration);
+                    + processName + " with config " + getGlobalConfiguration());
             ApplicationInfo appInfo = app.instrumentationInfo != null
                     ? app.instrumentationInfo : app.info;
             app.compat = compatibilityInfoForPackageLocked(appInfo);
@@ -6569,7 +6574,7 @@
                     app.instrumentationUiAutomationConnection, testMode,
                     mBinderTransactionTrackingEnabled, enableTrackAllocation,
                     isRestrictedBackupMode || !normalMode, app.persistent,
-                    new Configuration(mGlobalConfiguration), app.compat,
+                    new Configuration(getGlobalConfiguration()), app.compat,
                     getCommonServicesLocked(app.isolated),
                     mCoreSettingsObserver.getCoreSettingsLocked(),
                     buildSerial);
@@ -6897,10 +6902,7 @@
     public final void activityResumed(IBinder token) {
         final long origId = Binder.clearCallingIdentity();
         synchronized(this) {
-            ActivityStack stack = ActivityRecord.getStackLocked(token);
-            if (stack != null) {
-                stack.activityResumedLocked(token);
-            }
+            ActivityRecord.activityResumedLocked(token);
         }
         Binder.restoreCallingIdentity(origId);
     }
@@ -6932,7 +6934,7 @@
         synchronized (this) {
             final ActivityRecord r = ActivityRecord.isInStackLocked(token);
             if (r != null) {
-                r.getStack().activityStoppedLocked(r, icicle, persistentState, description);
+                r.activityStoppedLocked(icicle, persistentState, description);
             }
         }
 
@@ -9325,17 +9327,9 @@
                     }
                 }
 
-                // Use the full screen as the context for the task thumbnail
-                final Point displaySize = new Point();
-                final TaskThumbnailInfo thumbnailInfo = new TaskThumbnailInfo();
-                r.getStack().getDisplaySize(displaySize);
-                thumbnailInfo.taskWidth = displaySize.x;
-                thumbnailInfo.taskHeight = displaySize.y;
-                thumbnailInfo.screenOrientation = mGlobalConfiguration.orientation;
-
                 TaskRecord task = new TaskRecord(this,
                         mStackSupervisor.getNextTaskIdForUserLocked(r.userId),
-                        ainfo, intent, description, thumbnailInfo);
+                        ainfo, intent, description, new TaskThumbnailInfo());
 
                 int trimIdx = mRecentTasks.trimForTaskLocked(task, false);
                 if (trimIdx >= 0) {
@@ -9570,7 +9564,7 @@
         for (int i = 0; i < procsToKill.size(); i++) {
             ProcessRecord pr = procsToKill.get(i);
             if (pr.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND
-                    && pr.curReceiver == null) {
+                    && pr.curReceivers.isEmpty()) {
                 pr.kill("remove task", true);
             } else {
                 // We delay killing processes that are not in the background or running a receiver.
@@ -13170,8 +13164,8 @@
             // This happens before any activities are started, so we can change global configuration
             // in-place.
             updateConfigurationLocked(configuration, null, true);
-            if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                    "Initial config: " + mGlobalConfiguration);
+            final Configuration globalConfig = getGlobalConfiguration();
+            if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION, "Initial config: " + globalConfig);
 
             // Load resources only after the current configuration has been set.
             final Resources res = mContext.getResources();
@@ -13186,11 +13180,10 @@
                     com.android.internal.R.string.config_appsNotReportingCrashes));
             mUserController.mUserSwitchUiEnabled = !res.getBoolean(
                     com.android.internal.R.bool.config_customUserSwitchUi);
-            if ((mGlobalConfiguration.uiMode & UI_MODE_TYPE_TELEVISION)
-                    == UI_MODE_TYPE_TELEVISION) {
+            if ((globalConfig.uiMode & UI_MODE_TYPE_TELEVISION) == UI_MODE_TYPE_TELEVISION) {
                 mFullscreenThumbnailScale = (float) res
                     .getInteger(com.android.internal.R.integer.thumbnail_width_tv) /
-                    (float) mGlobalConfiguration.screenWidthDp;
+                    (float) globalConfig.screenWidthDp;
             } else {
                 mFullscreenThumbnailScale = res.getFraction(
                     com.android.internal.R.fraction.thumbnail_fullscreen_scale, 1, 1);
@@ -14785,7 +14778,7 @@
             pw.println("  mHeavyWeightProcess: " + mHeavyWeightProcess);
         }
         if (dumpPackage == null) {
-            pw.println("  mGlobalConfiguration: " + mGlobalConfiguration);
+            pw.println("  mGlobalConfiguration: " + getGlobalConfiguration());
         }
         if (dumpAll) {
             pw.println("  mConfigWillChange: " + getFocusedStack().mConfigWillChange);
@@ -18768,15 +18761,16 @@
     public ConfigurationInfo getDeviceConfigurationInfo() {
         ConfigurationInfo config = new ConfigurationInfo();
         synchronized (this) {
-            config.reqTouchScreen = mGlobalConfiguration.touchscreen;
-            config.reqKeyboardType = mGlobalConfiguration.keyboard;
-            config.reqNavigation = mGlobalConfiguration.navigation;
-            if (mGlobalConfiguration.navigation == Configuration.NAVIGATION_DPAD
-                    || mGlobalConfiguration.navigation == Configuration.NAVIGATION_TRACKBALL) {
+            final Configuration globalConfig = getGlobalConfiguration();
+            config.reqTouchScreen = globalConfig.touchscreen;
+            config.reqKeyboardType = globalConfig.keyboard;
+            config.reqNavigation = globalConfig.navigation;
+            if (globalConfig.navigation == Configuration.NAVIGATION_DPAD
+                    || globalConfig.navigation == Configuration.NAVIGATION_TRACKBALL) {
                 config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
             }
-            if (mGlobalConfiguration.keyboard != Configuration.KEYBOARD_UNDEFINED
-                    && mGlobalConfiguration.keyboard != Configuration.KEYBOARD_NOKEYS) {
+            if (globalConfig.keyboard != Configuration.KEYBOARD_UNDEFINED
+                    && globalConfig.keyboard != Configuration.KEYBOARD_NOKEYS) {
                 config.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
             }
             config.reqGlEsVersion = GL_ES_VERSION;
@@ -18800,7 +18794,7 @@
     public Configuration getConfiguration() {
         Configuration ci;
         synchronized(this) {
-            ci = new Configuration(mGlobalConfiguration);
+            ci = new Configuration(getGlobalConfiguration());
             ci.userSetLocale = false;
         }
         return ci;
@@ -18858,7 +18852,7 @@
     private void updateFontScaleIfNeeded(@UserIdInt int userId) {
         final float scaleFactor = Settings.System.getFloatForUser(mContext.getContentResolver(),
                 FONT_SCALE, 1.0f, userId);
-        if (mGlobalConfiguration.fontScale != scaleFactor) {
+        if (getGlobalConfiguration().fontScale != scaleFactor) {
             final Configuration configuration = mWindowManager.computeNewConfiguration();
             configuration.fontScale = scaleFactor;
             synchronized (this) {
@@ -18918,7 +18912,7 @@
     }
 
     void updateUserConfigurationLocked() {
-        final Configuration configuration = new Configuration(mGlobalConfiguration);
+        final Configuration configuration = new Configuration(getGlobalConfiguration());
         final int currentUserId = mUserController.getCurrentUserIdLocked();
         Settings.System.adjustConfigurationForUser(mContext.getContentResolver(), configuration,
                 currentUserId, Settings.System.canWrite(mContext));
@@ -18989,7 +18983,7 @@
     /** Update default (global) configuration and notify listeners about changes. */
     private int updateGlobalConfiguration(@NonNull Configuration values, boolean initLocale,
             boolean persistent, int userId, boolean deferResume) {
-        mTempGlobalConfig.setTo(mGlobalConfiguration);
+        mTempGlobalConfig.setTo(getGlobalConfiguration());
         final int changes = mTempGlobalConfig.updateFrom(values);
         if (changes == 0) {
             return 0;
@@ -19019,7 +19013,9 @@
         mConfigurationSeq = Math.max(++mConfigurationSeq, 1);
         mTempGlobalConfig.seq = mConfigurationSeq;
 
-        mGlobalConfiguration.setTo(mTempGlobalConfig);
+        // Update stored global config and notify everyone about the change.
+        mStackSupervisor.onConfigurationChanged(mTempGlobalConfig);
+
         Slog.i(TAG, "Config changes=" + Integer.toHexString(changes) + " " + mTempGlobalConfig);
         // TODO(multi-display): Update UsageEvents#Event to include displayId.
         mUsageStatsService.reportConfigurationChange(mTempGlobalConfig,
@@ -19041,7 +19037,7 @@
 
         // We need another copy of global config because we're scheduling some calls instead of
         // running them in place. We need to be sure that object we send will be handled unchanged.
-        final Configuration configCopy = new Configuration(mGlobalConfiguration);
+        final Configuration configCopy = new Configuration(mTempGlobalConfig);
         if (persistent && Settings.System.hasInterestingConfigurationChanges(changes)) {
             Message msg = mHandler.obtainMessage(UPDATE_CONFIGURATION_MSG);
             msg.obj = configCopy;
@@ -19119,7 +19115,8 @@
             }
 
             if (starting != null) {
-                kept = mainStack.ensureActivityConfigurationLocked(starting, changes, false);
+                kept = starting.ensureActivityConfigurationLocked(changes,
+                        false /* preserveWindow */);
                 // And we need to make sure at this point that all other activities
                 // are made visible with the correct configuration.
                 mStackSupervisor.ensureActivitiesVisibleLocked(starting, changes,
@@ -19206,26 +19203,28 @@
     // LIFETIME MANAGEMENT
     // =========================================================
 
-    // Returns which broadcast queue the app is the current [or imminent] receiver
-    // on, or 'null' if the app is not an active broadcast recipient.
-    private BroadcastQueue isReceivingBroadcast(ProcessRecord app) {
-        BroadcastRecord r = app.curReceiver;
-        if (r != null) {
-            return r.queue;
+    // Returns whether the app is receiving broadcast.
+    // If receiving, fetch all broadcast queues which the app is
+    // the current [or imminent] receiver on.
+    private boolean isReceivingBroadcastLocked(ProcessRecord app,
+            ArraySet<BroadcastQueue> receivingQueues) {
+        if (!app.curReceivers.isEmpty()) {
+            for (BroadcastRecord r : app.curReceivers) {
+                receivingQueues.add(r.queue);
+            }
+            return true;
         }
 
         // It's not the current receiver, but it might be starting up to become one
-        synchronized (this) {
-            for (BroadcastQueue queue : mBroadcastQueues) {
-                r = queue.mPendingBroadcast;
-                if (r != null && r.curApp == app) {
-                    // found it; report which queue it's in
-                    return queue;
-                }
+        for (BroadcastQueue queue : mBroadcastQueues) {
+            final BroadcastRecord r = queue.mPendingBroadcast;
+            if (r != null && r.curApp == app) {
+                // found it; report which queue it's in
+                receivingQueues.add(queue);
             }
         }
 
-        return null;
+        return !receivingQueues.isEmpty();
     }
 
     Association startAssociationLocked(int sourceUid, String sourceProcess, int sourceState,
@@ -19392,7 +19391,7 @@
         int schedGroup;
         int procState;
         boolean foregroundActivities = false;
-        BroadcastQueue queue;
+        final ArraySet<BroadcastQueue> queues = new ArraySet<BroadcastQueue>();
         if (app == TOP_APP) {
             // The last app on the list is the foreground app.
             adj = ProcessList.FOREGROUND_APP_ADJ;
@@ -19406,13 +19405,13 @@
             schedGroup = ProcessList.SCHED_GROUP_DEFAULT;
             app.adjType = "instrumentation";
             procState = ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE;
-        } else if ((queue = isReceivingBroadcast(app)) != null) {
+        } else if (isReceivingBroadcastLocked(app, queues)) {
             // An app that is currently receiving a broadcast also
             // counts as being in the foreground for OOM killer purposes.
             // It's placed in a sched group based on the nature of the
             // broadcast as reflected by which queue it's active in.
             adj = ProcessList.FOREGROUND_APP_ADJ;
-            schedGroup = (queue == mFgBroadcastQueue)
+            schedGroup = (queues.contains(mFgBroadcastQueue))
                     ? ProcessList.SCHED_GROUP_DEFAULT : ProcessList.SCHED_GROUP_BACKGROUND;
             app.adjType = "broadcast";
             procState = ActivityManager.PROCESS_STATE_RECEIVER;
@@ -20423,7 +20422,7 @@
             if (DEBUG_SWITCH || DEBUG_OOM_ADJ) Slog.v(TAG_OOM_ADJ,
                     "Setting sched group of " + app.processName
                     + " to " + app.curSchedGroup);
-            if (app.waitingToKill != null && app.curReceiver == null
+            if (app.waitingToKill != null && app.curReceivers.isEmpty()
                     && app.setSchedGroup == ProcessList.SCHED_GROUP_BACKGROUND) {
                 app.kill(app.waitingToKill, true);
                 success = false;
@@ -21363,7 +21362,7 @@
             for (i=mRemovedProcesses.size()-1; i>=0; i--) {
                 final ProcessRecord app = mRemovedProcesses.get(i);
                 if (app.activities.size() == 0
-                        && app.curReceiver == null && app.services.size() == 0) {
+                        && app.curReceivers.isEmpty() && app.services.size() == 0) {
                     Slog.i(
                         TAG, "Exiting empty application process "
                         + app.toShortString() + " ("
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
index 40d6d14..d89f02d 100644
--- a/services/core/java/com/android/server/am/ActivityRecord.java
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -20,22 +20,38 @@
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
 import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
-import static android.content.pm.ActivityInfo.FLAG_ON_TOP_LAUNCHER;
+import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
+import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
+import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
+import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
 import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
-import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
 import static android.content.pm.ActivityInfo.FLAG_ALWAYS_FOCUSABLE;
+import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
 import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
 import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
+import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
+import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
+import static android.view.Display.DEFAULT_DISPLAY;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SCREENSHOTS;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_THUMBNAILS;
+import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_VISIBILITY;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SCREENSHOTS;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_THUMBNAILS;
+import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_VISIBILITY;
 import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
 import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
+import static com.android.server.am.ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS;
 import static com.android.server.am.TaskRecord.INVALID_TASK_ID;
 
+import android.annotation.NonNull;
 import android.app.ActivityManager.TaskDescription;
 import android.app.ActivityOptions;
 import android.app.PendingIntent;
@@ -50,6 +66,7 @@
 import android.graphics.Rect;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Debug;
 import android.os.IBinder;
 import android.os.Message;
 import android.os.PersistableBundle;
@@ -81,6 +98,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Objects;
 
 import org.xmlpull.v1.XmlPullParser;
@@ -92,12 +110,16 @@
  */
 final class ActivityRecord {
     private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityRecord" : TAG_AM;
+    private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;
+    private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE;
+    private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS;
     private static final String TAG_STATES = TAG + POSTFIX_STATES;
     private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
     private static final String TAG_THUMBNAILS = TAG + POSTFIX_THUMBNAILS;
+    private static final String TAG_VISIBILITY = TAG + POSTFIX_VISIBILITY;
 
     private static final boolean SHOW_ACTIVITY_START_TIME = true;
-    final public static String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
+    private static final String RECENTS_PACKAGE_NAME = "com.android.systemui.recents";
 
     private static final String ATTR_ID = "id";
     private static final String TAG_INTENT = "intent";
@@ -150,11 +172,11 @@
     long cpuTimeAtResume;   // the cpu time of host process at the time of resuming activity
     long pauseTime;         // last time we started pausing the activity
     long launchTickTime;    // base time for launch tick messages
-    Configuration configuration; // configuration activity was last running in
+    private Configuration mLastReportedConfiguration; // configuration activity was last running in
     // Overridden configuration by the activity task
-    // WARNING: Reference points to {@link TaskRecord#mOverrideConfig}, so its internal state
-    // should never be altered directly.
-    Configuration taskConfigOverride;
+    // WARNING: Reference points to {@link TaskRecord#getMergedOverrideConfig}, so its internal
+    // state should never be altered directly.
+    private Configuration mLastReportedOverrideConfiguration;
     CompatibilityInfo compat;// last used compatibility mode
     ActivityRecord resultTo; // who started this entry, so will get our reply
     final String resultWho; // additional identifier for use by resultTo.
@@ -231,6 +253,12 @@
     // on the window.
     int mRotationAnimationHint = -1;
 
+    /**
+     * Temp configs used in {@link #ensureActivityConfigurationLocked(int, boolean)}
+     */
+    private final Configuration mTmpGlobalConfig = new Configuration();
+    private final Configuration mTmpTaskConfig = new Configuration();
+
     private static String startingWindowStateToString(int state) {
         switch (state) {
             case STARTING_WINDOW_NOT_SHOWN:
@@ -279,8 +307,10 @@
                 pw.print(" labelRes=0x"); pw.print(Integer.toHexString(labelRes));
                 pw.print(" icon=0x"); pw.print(Integer.toHexString(icon));
                 pw.print(" theme=0x"); pw.println(Integer.toHexString(theme));
-        pw.print(prefix); pw.print("config="); pw.println(configuration);
-        pw.print(prefix); pw.print("taskConfigOverride="); pw.println(taskConfigOverride);
+        pw.print(prefix); pw.print("mLastReportedConfiguration=");
+                pw.println(mLastReportedConfiguration);
+        pw.print(prefix); pw.print("mLastReportedOverrideConfiguration=");
+                pw.println(mLastReportedOverrideConfiguration);
         if (resultTo != null || resultWho != null) {
             pw.print(prefix); pw.print("resultTo="); pw.print(resultTo);
                     pw.print(" resultWho="); pw.print(resultWho);
@@ -401,15 +431,15 @@
         }
     }
 
-    public boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
+    private boolean crossesHorizontalSizeThreshold(int firstDp, int secondDp) {
         return crossesSizeThreshold(mHorizontalSizeConfigurations, firstDp, secondDp);
     }
 
-    public boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
+    private boolean crossesVerticalSizeThreshold(int firstDp, int secondDp) {
         return crossesSizeThreshold(mVerticalSizeConfigurations, firstDp, secondDp);
     }
 
-    public boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
+    private boolean crossesSmallestSizeThreshold(int firstDp, int secondDp) {
         return crossesSizeThreshold(mSmallestSizeConfigurations, firstDp, secondDp);
     }
 
@@ -442,14 +472,14 @@
         return false;
     }
 
-    public void setSizeConfigurations(int[] horizontalSizeConfiguration,
+    void setSizeConfigurations(int[] horizontalSizeConfiguration,
             int[] verticalSizeConfigurations, int[] smallestSizeConfigurations) {
         mHorizontalSizeConfigurations = horizontalSizeConfiguration;
         mVerticalSizeConfigurations = verticalSizeConfigurations;
         mSmallestSizeConfigurations = smallestSizeConfigurations;
     }
 
-    void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) {
+    private void scheduleConfigurationChanged(Configuration config, boolean reportToActivity) {
         if (app == null || app.thread == null) {
             return;
         }
@@ -457,7 +487,8 @@
             if (DEBUG_CONFIGURATION) Slog.v(TAG, "Sending new config to " + this + " " +
                     "reportToActivity=" + reportToActivity + " and config: " + config);
 
-            app.thread.scheduleActivityConfigurationChanged(appToken, config, reportToActivity);
+            app.thread.scheduleActivityConfigurationChanged(appToken, new Configuration(config),
+                    reportToActivity);
         } catch (RemoteException e) {
             // If process died, whatever.
         }
@@ -527,7 +558,6 @@
                 if (r != null) {
                     if (DEBUG_SWITCH) Log.v(TAG_SWITCH, "windowsGone(): " + r);
                     r.nowVisible = false;
-                    return;
                 }
             }
         }
@@ -543,7 +573,7 @@
                     return false;
                 }
                 anrActivity = r.getWaitingHistoryRecordLocked();
-                anrApp = r != null ? r.app : null;
+                anrApp = r.app;
             }
             return mService.inputDispatchingTimedOut(anrApp, anrActivity, r, false, reason);
         }
@@ -560,7 +590,7 @@
             }
         }
 
-        private static final ActivityRecord tokenToActivityRecordLocked(Token token) {
+        private static ActivityRecord tokenToActivityRecordLocked(Token token) {
             if (token == null) {
                 return null;
             }
@@ -614,8 +644,8 @@
         resolvedType = _resolvedType;
         componentSpecified = _componentSpecified;
         rootVoiceInteraction = _rootVoiceInteraction;
-        configuration = _configuration;
-        taskConfigOverride = Configuration.EMPTY;
+        mLastReportedConfiguration = new Configuration(_configuration);
+        mLastReportedOverrideConfiguration = new Configuration();
         resultTo = _resultTo;
         resultWho = _resultWho;
         requestCode = _reqCode;
@@ -768,6 +798,12 @@
                 && isHomeIntent(intent) && !isResolverActivity()) {
             // This sure looks like a home activity!
             mActivityType = HOME_ACTIVITY_TYPE;
+
+            if (info.resizeMode == RESIZE_MODE_FORCE_RESIZEABLE
+                    || info.resizeMode == RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION) {
+                // We only allow home activities to be resizeable if they explicitly requested it.
+                info.resizeMode = RESIZE_MODE_UNRESIZEABLE;
+            }
         } else if (realActivity.getClassName().contains(RECENTS_PACKAGE_NAME)) {
             mActivityType = RECENTS_ACTIVITY_TYPE;
         } else {
@@ -860,7 +896,7 @@
     }
 
     boolean isResizeable() {
-        return !isHomeActivity() && ActivityInfo.isResizeableMode(info.resizeMode);
+        return ActivityInfo.isResizeableMode(info.resizeMode);
     }
 
     boolean isResizeableOrForced() {
@@ -868,8 +904,9 @@
     }
 
     boolean isNonResizableOrForced() {
-        return !isHomeActivity() && info.resizeMode != RESIZE_MODE_RESIZEABLE
-                && info.resizeMode != RESIZE_MODE_RESIZEABLE_AND_PIPABLE;
+        return info.resizeMode != RESIZE_MODE_RESIZEABLE
+                && info.resizeMode != RESIZE_MODE_RESIZEABLE_AND_PIPABLE
+                && info.resizeMode != RESIZE_MODE_RESIZEABLE_VIA_SDK_VERSION;
     }
 
     boolean supportsPictureInPicture() {
@@ -877,18 +914,13 @@
     }
 
     boolean canGoInDockedStack() {
-        return !isHomeActivity()
-                && (isResizeableOrForced() || info.resizeMode == RESIZE_MODE_CROP_WINDOWS);
+        return !isHomeActivity() && isResizeableOrForced();
     }
 
     boolean isAlwaysFocusable() {
         return (info.flags & FLAG_ALWAYS_FOCUSABLE) != 0;
     }
 
-    boolean isOnTopLauncher() {
-        return isHomeActivity() && (info.flags & FLAG_ON_TOP_LAUNCHER) != 0;
-    }
-
     void makeFinishingLocked() {
         if (!finishing) {
             final ActivityStack stack = getStack();
@@ -939,7 +971,7 @@
         }
     }
 
-    void addNewIntentLocked(ReferrerIntent intent) {
+    private void addNewIntentLocked(ReferrerIntent intent) {
         if (newIntents == null) {
             newIntents = new ArrayList<>();
         }
@@ -1120,12 +1152,251 @@
                     "Setting thumbnail of " + this + " to " + newThumbnail);
             boolean thumbnailUpdated = task.setLastThumbnailLocked(newThumbnail);
             if (thumbnailUpdated && isPersistable()) {
-                mStackSupervisor.mService.notifyTaskPersisterLocked(task, false);
+                service.notifyTaskPersisterLocked(task, false);
             }
         }
         task.lastDescription = description;
     }
 
+    final Bitmap screenshotActivityLocked() {
+        if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivityLocked: " + this);
+        if (noDisplay) {
+            if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display");
+            return null;
+        }
+
+        final ActivityStack stack = getStack();
+        if (stack.isHomeStack()) {
+            // This is an optimization -- since we never show Home or Recents within Recents itself,
+            // we can just go ahead and skip taking the screenshot if this is the home stack.
+            if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack");
+            return null;
+        }
+
+        int w = service.mThumbnailWidth;
+        int h = service.mThumbnailHeight;
+
+        if (w <= 0) {
+            Slog.e(TAG, "\tInvalid thumbnail dimensions: " + w + "x" + h);
+            return null;
+        }
+
+        if (stack.mStackId == DOCKED_STACK_ID && mStackSupervisor.mIsDockMinimized) {
+            // When the docked stack is minimized its app windows are cropped significantly so any
+            // screenshot taken will not display the apps contain. So, we avoid taking a screenshot
+            // in that case.
+            if (DEBUG_SCREENSHOTS) Slog.e(TAG, "\tIn minimized docked stack");
+            return null;
+        }
+
+        final float scale;
+        if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot");
+
+        // When this flag is set, we currently take the fullscreen screenshot of the activity but
+        // scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to use within
+        // SystemUI while keeping memory usage low.
+        if (TAKE_FULLSCREEN_SCREENSHOTS) {
+            w = h = -1;
+            scale = service.mFullscreenThumbnailScale;
+        }
+
+        return service.mWindowManager.screenshotApplications(appToken, DEFAULT_DISPLAY, w, h,
+                scale);
+    }
+
+    void setVisible(boolean newVisible) {
+        visible = newVisible;
+        if (!visible && mUpdateTaskThumbnailWhenHidden) {
+            updateThumbnailLocked(screenshotActivityLocked(), null /* description */);
+            mUpdateTaskThumbnailWhenHidden = false;
+        }
+        service.mWindowManager.setAppVisibility(appToken, visible);
+        final ArrayList<ActivityContainer> containers = mChildContainers;
+        for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) {
+            final ActivityContainer container = containers.get(containerNdx);
+            container.setVisible(visible);
+        }
+        mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
+    }
+
+    /** Return true if the input activity should be made visible */
+    boolean shouldBeVisible(boolean behindTranslucentActivity, boolean stackVisibleBehind,
+            ActivityRecord visibleBehind, boolean behindFullscreenActivity) {
+        if (!okToShowLocked()) {
+            return false;
+        }
+
+        // mLaunchingBehind: Activities launching behind are at the back of the task stack
+        // but must be drawn initially for the animation as though they were visible.
+        final boolean activityVisibleBehind =
+                (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == this;
+
+        boolean isVisible =
+                !behindFullscreenActivity || mLaunchTaskBehind || activityVisibleBehind;
+
+        if (service.mSupportsLeanbackOnly && isVisible && isRecentsActivity()) {
+            // On devices that support leanback only (Android TV), Recents activity can only be
+            // visible if the home stack is the focused stack or we are in split-screen mode.
+            isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null
+                    || mStackSupervisor.isFocusedStack(getStack());
+        }
+
+        return isVisible;
+    }
+
+    void makeVisibleIfNeeded(ActivityRecord starting) {
+        // This activity is not currently visible, but is running. Tell it to become visible.
+        if (state == ActivityState.RESUMED || this == starting) {
+            if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY,
+                    "Not making visible, r=" + this + " state=" + state + " starting=" + starting);
+            return;
+        }
+
+        // If this activity is paused, tell it to now show its window.
+        if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
+                "Making visible and scheduling visibility: " + this);
+        final ActivityStack stack = getStack();
+        try {
+            if (stack.mTranslucentActivityWaiting != null) {
+                updateOptionsLocked(returningOptions);
+                stack.mUndrawnActivitiesBelowTopTranslucent.add(this);
+            }
+            setVisible(true);
+            sleeping = false;
+            app.pendingUiClean = true;
+            app.thread.scheduleWindowVisibility(appToken, true /* showWindow */);
+            // The activity may be waiting for stop, but that is no longer appropriate for it.
+            mStackSupervisor.mStoppingActivities.remove(this);
+            mStackSupervisor.mGoingToSleepActivities.remove(this);
+        } catch (Exception e) {
+            // Just skip on any failure; we'll make it visible when it next restarts.
+            Slog.w(TAG, "Exception thrown making visibile: " + intent.getComponent(), e);
+        }
+        handleAlreadyVisible();
+    }
+
+    boolean handleAlreadyVisible() {
+        stopFreezingScreenLocked(false);
+        try {
+            if (returningOptions != null) {
+                app.thread.scheduleOnNewActivityOptions(appToken, returningOptions);
+            }
+        } catch(RemoteException e) {
+        }
+        return state == ActivityState.RESUMED;
+    }
+
+    static void activityResumedLocked(IBinder token) {
+        final ActivityRecord r = ActivityRecord.forTokenLocked(token);
+        if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
+        if (r != null) {
+            r.icicle = null;
+            r.haveState = false;
+        }
+    }
+
+    /**
+     * Once we know that we have asked an application to put an activity in the resumed state
+     * (either by launching it or explicitly telling it), this function updates the rest of our
+     * state to match that fact.
+     */
+    void completeResumeLocked() {
+        final boolean wasVisible = visible;
+        visible = true;
+        if (!wasVisible) {
+            // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
+            mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
+        }
+        idle = false;
+        results = null;
+        newIntents = null;
+        stopped = false;
+
+        if (isHomeActivity()) {
+            ProcessRecord app = task.mActivities.get(0).app;
+            if (app != null && app != service.mHomeProcess) {
+                service.mHomeProcess = app;
+            }
+        }
+
+        if (nowVisible) {
+            // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
+            mStackSupervisor.reportActivityVisibleLocked(this);
+            mStackSupervisor.notifyActivityDrawnForKeyguard();
+        }
+
+        // Schedule an idle timeout in case the app doesn't do it for us.
+        mStackSupervisor.scheduleIdleTimeoutLocked(this);
+
+        mStackSupervisor.reportResumedActivityLocked(this);
+
+        resumeKeyDispatchingLocked();
+        final ActivityStack stack = getStack();
+        stack.mNoAnimActivities.clear();
+
+        // Mark the point when the activity is resuming
+        // TODO: To be more accurate, the mark should be before the onCreate,
+        //       not after the onResume. But for subsequent starts, onResume is fine.
+        if (app != null) {
+            cpuTimeAtResume = service.mProcessCpuTracker.getCpuTimeForPid(app.pid);
+        } else {
+            cpuTimeAtResume = 0; // Couldn't get the cpu time of process
+        }
+
+        returningOptions = null;
+
+        if (stack.getVisibleBehindActivity() == this) {
+            // When resuming an activity, require it to call requestVisibleBehind() again.
+            stack.setVisibleBehindActivity(null /* ActivityRecord */);
+        }
+        mStackSupervisor.checkReadyForSleepLocked();
+    }
+
+    final void activityStoppedLocked(Bundle newIcicle, PersistableBundle newPersistentState,
+            CharSequence description) {
+        final ActivityStack stack = getStack();
+        if (state != ActivityState.STOPPING) {
+            Slog.i(TAG, "Activity reported stop, but no longer stopping: " + this);
+            stack.mHandler.removeMessages(ActivityStack.STOP_TIMEOUT_MSG, this);
+            return;
+        }
+        if (newPersistentState != null) {
+            persistentState = newPersistentState;
+            service.notifyTaskPersisterLocked(task, false);
+        }
+        if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + this + ": " + icicle);
+        if (newIcicle != null) {
+            // If icicle is null, this is happening due to a timeout, so we haven't really saved
+            // the state.
+            icicle = newIcicle;
+            haveState = true;
+            launchCount = 0;
+            updateThumbnailLocked(null /* newThumbnail */, description);
+        }
+        if (!stopped) {
+            if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + this + " (stop complete)");
+            stack.mHandler.removeMessages(ActivityStack.STOP_TIMEOUT_MSG, this);
+            stopped = true;
+            state = ActivityState.STOPPED;
+
+            service.mWindowManager.notifyAppStopped(appToken);
+
+            if (stack.getVisibleBehindActivity() == this) {
+                mStackSupervisor.requestVisibleBehindLocked(this, false /* visible */);
+            }
+            if (finishing) {
+                clearOptionsLocked();
+            } else {
+                if (deferRelaunchUntilPaused) {
+                    stack.destroyActivityLocked(this, true /* removeFromApp */, "stop-config");
+                    mStackSupervisor.resumeFocusedStackTopActivityLocked();
+                } else {
+                    mStackSupervisor.updatePreviousProcessLocked(this);
+                }
+            }
+        }
+    }
+
     void startLaunchTickingLocked() {
         if (ActivityManagerService.IS_USER_BUILD) {
             return;
@@ -1433,6 +1704,255 @@
         }
     }
 
+    // TODO: now used only in one place to address race-condition. Remove when that will be fixed.
+    void setLastReportedConfiguration(@NonNull Configuration config) {
+        mLastReportedConfiguration.setTo(config);
+    }
+
+    /** Call when override config was sent to the Window Manager to update internal records. */
+    void onOverrideConfigurationSent() {
+        mLastReportedOverrideConfiguration.setTo(task.getMergedOverrideConfiguration());
+    }
+
+    /**
+     * Make sure the given activity matches the current configuration. Returns false if the activity
+     * had to be destroyed.  Returns true if the configuration is the same, or the activity will
+     * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the
+     * correct configuration and all other bookkeeping is handled.
+     */
+    boolean ensureActivityConfigurationLocked(int globalChanges, boolean preserveWindow) {
+        final ActivityStack stack = getStack();
+        if (stack.mConfigWillChange) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                    "Skipping config check (will change): " + this);
+            return true;
+        }
+
+        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                "Ensuring correct configuration: " + this);
+
+        // Short circuit: if the two configurations are equal (the common case), then there is
+        // nothing to do.
+        final Configuration newGlobalConfig = service.getGlobalConfiguration();
+        final Configuration newTaskMergedOverrideConfig = task.getMergedOverrideConfiguration();
+        if (mLastReportedConfiguration.equals(newGlobalConfig)
+                && mLastReportedOverrideConfiguration.equals(newTaskMergedOverrideConfig)
+                && !forceNewConfig) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                    "Configuration unchanged in " + this);
+            return true;
+        }
+
+        // We don't worry about activities that are finishing.
+        if (finishing) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                    "Configuration doesn't matter in finishing " + this);
+            stopFreezingScreenLocked(false);
+            return true;
+        }
+
+        // Okay we now are going to make this activity have the new config.
+        // But then we need to figure out how it needs to deal with that.
+        mTmpGlobalConfig.setTo(mLastReportedConfiguration);
+        mTmpTaskConfig.setTo(mLastReportedOverrideConfiguration);
+        mLastReportedConfiguration.setTo(newGlobalConfig);
+        mLastReportedOverrideConfiguration.setTo(newTaskMergedOverrideConfig);
+
+        int taskChanges = getTaskConfigurationChanges(this, newTaskMergedOverrideConfig,
+                mTmpTaskConfig);
+        final int changes = mTmpGlobalConfig.diff(newGlobalConfig) | taskChanges;
+        if (changes == 0 && !forceNewConfig) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                    "Configuration no differences in " + this);
+            // There are no significant differences, so we won't relaunch but should still deliver
+            // the new configuration to the client process.
+            scheduleConfigurationChanged(newTaskMergedOverrideConfig, true);
+            return true;
+        }
+
+        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                "Configuration changes for " + this + " ; taskChanges="
+                        + Configuration.configurationDiffToString(taskChanges) + ", allChanges="
+                        + Configuration.configurationDiffToString(changes));
+
+        // If the activity isn't currently running, just leave the new configuration and it will
+        // pick that up next time it starts.
+        if (app == null || app.thread == null) {
+            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                    "Configuration doesn't matter not running " + this);
+            stopFreezingScreenLocked(false);
+            forceNewConfig = false;
+            return true;
+        }
+
+        // Figure out how to handle the changes between the configurations.
+        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                "Checking to restart " + info.name + ": changed=0x"
+                        + Integer.toHexString(changes) + ", handles=0x"
+                        + Integer.toHexString(info.getRealConfigChanged())
+                        + ", newGlobalConfig=" + newGlobalConfig
+                        + ", newTaskMergedOverrideConfig=" + newTaskMergedOverrideConfig);
+
+        if ((changes&(~info.getRealConfigChanged())) != 0 || forceNewConfig) {
+            // Aha, the activity isn't handling the change, so DIE DIE DIE.
+            configChangeFlags |= changes;
+            startFreezingScreenLocked(app, globalChanges);
+            forceNewConfig = false;
+            preserveWindow &= isResizeOnlyChange(changes);
+            if (app == null || app.thread == null) {
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                        "Config is destroying non-running " + this);
+                stack.destroyActivityLocked(this, true, "config");
+            } else if (state == ActivityState.PAUSING) {
+                // A little annoying: we are waiting for this activity to finish pausing. Let's not
+                // do anything now, but just flag that it needs to be restarted when done pausing.
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                        "Config is skipping already pausing " + this);
+                deferRelaunchUntilPaused = true;
+                preserveWindowOnDeferredRelaunch = preserveWindow;
+                return true;
+            } else if (state == ActivityState.RESUMED) {
+                // Try to optimize this case: the configuration is changing and we need to restart
+                // the top, resumed activity. Instead of doing the normal handshaking, just say
+                // "restart!".
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                        "Config is relaunching resumed " + this);
+
+                if (DEBUG_STATES && !visible) {
+                    Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + this
+                            + " called by " + Debug.getCallers(4));
+                }
+
+                relaunchActivityLocked(true /* andResume */, preserveWindow);
+            } else {
+                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
+                        "Config is relaunching non-resumed " + this);
+                relaunchActivityLocked(false /* andResume */, preserveWindow);
+            }
+
+            // All done...  tell the caller we weren't able to keep this activity around.
+            return false;
+        }
+
+        // Default case: the activity can handle this new configuration, so hand it over.
+        // NOTE: We only forward the task override configuration as the system level configuration
+        // changes is always sent to all processes when they happen so it can just use whatever
+        // system level configuration it last got.
+        scheduleConfigurationChanged(newTaskMergedOverrideConfig, true);
+        stopFreezingScreenLocked(false);
+
+        return true;
+    }
+
+    private static int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig,
+            Configuration oldTaskOverride) {
+        // If we went from full-screen to non-full-screen, make sure to use the correct
+        // configuration task diff, so the diff stays as small as possible.
+        if (Configuration.EMPTY.equals(oldTaskOverride)
+                && !Configuration.EMPTY.equals(taskConfig)) {
+            oldTaskOverride = record.task.extractOverrideConfig(record.mLastReportedConfiguration);
+        }
+
+        // Conversely, do the same when going the other direction.
+        if (Configuration.EMPTY.equals(taskConfig)
+                && !Configuration.EMPTY.equals(oldTaskOverride)) {
+            taskConfig = record.task.extractOverrideConfig(record.mLastReportedConfiguration);
+        }
+
+        // Determine what has changed.  May be nothing, if this is a config that has come back from
+        // the app after going idle.  In that case we just want to leave the official config object
+        // now in the activity and do nothing else.
+        int taskChanges = oldTaskOverride.diff(taskConfig, true /* skipUndefined */);
+        // We don't want to use size changes if they don't cross boundaries that are important to
+        // the app.
+        if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) {
+            final boolean crosses = record.crossesHorizontalSizeThreshold(
+                    oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp)
+                    || record.crossesVerticalSizeThreshold(
+                    oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp);
+            if (!crosses) {
+                taskChanges &= ~CONFIG_SCREEN_SIZE;
+            }
+        }
+        if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
+            final int oldSmallest = oldTaskOverride.smallestScreenWidthDp;
+            final int newSmallest = taskConfig.smallestScreenWidthDp;
+            if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
+                taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE;
+            }
+        }
+        return taskChanges;
+    }
+
+    private static boolean isResizeOnlyChange(int change) {
+        return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
+                | CONFIG_SCREEN_LAYOUT)) == 0;
+    }
+
+    void relaunchActivityLocked(boolean andResume, boolean preserveWindow) {
+        if (service.mSuppressResizeConfigChanges && preserveWindow) {
+            configChangeFlags = 0;
+            return;
+        }
+
+        List<ResultInfo> pendingResults = null;
+        List<ReferrerIntent> pendingNewIntents = null;
+        if (andResume) {
+            pendingResults = results;
+            pendingNewIntents = newIntents;
+        }
+        if (DEBUG_SWITCH) Slog.v(TAG_SWITCH,
+                "Relaunching: " + this + " with results=" + pendingResults
+                        + " newIntents=" + pendingNewIntents + " andResume=" + andResume
+                        + " preserveWindow=" + preserveWindow);
+        EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY
+                        : EventLogTags.AM_RELAUNCH_ACTIVITY, userId, System.identityHashCode(this),
+                task.taskId, shortComponentName);
+
+        startFreezingScreenLocked(app, 0);
+
+        mStackSupervisor.removeChildActivityContainers(this);
+
+        try {
+            if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH,
+                    "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + this
+                            + " callers=" + Debug.getCallers(6));
+            forceNewConfig = false;
+            mStackSupervisor.activityRelaunchingLocked(this);
+            app.thread.scheduleRelaunchActivity(appToken, pendingResults, pendingNewIntents,
+                    configChangeFlags, !andResume,
+                    new Configuration(service.getGlobalConfiguration()),
+                    new Configuration(task.getMergedOverrideConfiguration()), preserveWindow);
+            // Note: don't need to call pauseIfSleepingLocked() here, because the caller will only
+            // pass in 'andResume' if this activity is currently resumed, which implies we aren't
+            // sleeping.
+        } catch (RemoteException e) {
+            if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e);
+        }
+
+        if (andResume) {
+            if (DEBUG_STATES) {
+                Slog.d(TAG_STATES, "Resumed after relaunch " + this);
+            }
+            results = null;
+            newIntents = null;
+            service.showUnsupportedZoomDialogIfNeededLocked(this);
+            service.showAskCompatModeDialogLocked(this);
+        } else {
+            service.mHandler.removeMessages(ActivityStack.PAUSE_TIMEOUT_MSG, this);
+            state = ActivityState.PAUSED;
+            // if the app is relaunched when it's stopped, and we're not resuming,
+            // put it back into stopped state.
+            if (stopped) {
+                getStack().addToStopping(this, true /* immediate */);
+            }
+        }
+
+        configChangeFlags = 0;
+        deferRelaunchUntilPaused = false;
+        preserveWindowOnDeferredRelaunch = false;
+    }
+
     void saveToXml(XmlSerializer out) throws IOException, XmlPullParserException {
         out.attribute(null, ATTR_ID, String.valueOf(createTime));
         out.attribute(null, ATTR_LAUNCHEDFROMUID, String.valueOf(launchedFromUid));
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 5dda02d..55066fd 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -22,26 +22,20 @@
 import static android.app.ActivityManager.StackId.HOME_STACK_ID;
 import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
 import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
-import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
 import static android.content.pm.ActivityInfo.CONFIG_SCREEN_LAYOUT;
-import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
-import static android.content.pm.ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
 import static android.content.pm.ActivityInfo.FLAG_RESUME_WHILE_PAUSING;
 import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
-import static android.content.res.Configuration.SCREENLAYOUT_UNDEFINED;
 import static android.view.Display.DEFAULT_DISPLAY;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ALL;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_APP;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CLEANUP;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONFIGURATION;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_CONTAINERS;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKSCREEN;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_PAUSE;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RELEASE;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_RESULTS;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SAVED_STATE;
-import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SCREENSHOTS;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STACK;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_STATES;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_SWITCH;
@@ -52,13 +46,11 @@
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_ADD_REMOVE;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_APP;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CLEANUP;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONFIGURATION;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_CONTAINERS;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_PAUSE;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RELEASE;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_RESULTS;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SAVED_STATE;
-import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SCREENSHOTS;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STACK;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_STATES;
 import static com.android.server.am.ActivityManagerDebugConfig.POSTFIX_SWITCH;
@@ -69,7 +61,6 @@
 import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
 import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
 import static com.android.server.am.ActivityManagerService.LOCK_SCREEN_SHOWN;
-import static com.android.server.am.ActivityManagerService.TAKE_FULLSCREEN_SCREENSHOTS;
 import static com.android.server.am.ActivityRecord.APPLICATION_ACTIVITY_TYPE;
 import static com.android.server.am.ActivityRecord.HOME_ACTIVITY_TYPE;
 import static com.android.server.am.ActivityRecord.STARTING_WINDOW_REMOVED;
@@ -99,7 +90,6 @@
 import android.content.pm.ActivityInfo;
 import android.content.pm.ApplicationInfo;
 import android.content.res.Configuration;
-import android.graphics.Bitmap;
 import android.graphics.Point;
 import android.graphics.Rect;
 import android.net.Uri;
@@ -110,7 +100,6 @@
 import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
-import android.os.PersistableBundle;
 import android.os.RemoteException;
 import android.os.SystemClock;
 import android.os.Trace;
@@ -124,7 +113,6 @@
 import android.view.Display;
 
 import com.android.internal.app.IVoiceInteractor;
-import com.android.internal.content.ReferrerIntent;
 import com.android.internal.os.BatteryStatsImpl;
 import com.android.server.Watchdog;
 import com.android.server.am.ActivityManagerService.ItemMatcher;
@@ -143,19 +131,17 @@
 /**
  * State and management of a single stack of activities.
  */
-final class ActivityStack {
+final class ActivityStack extends ConfigurationContainer {
 
     private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStack" : TAG_AM;
     private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
     private static final String TAG_APP = TAG + POSTFIX_APP;
     private static final String TAG_CLEANUP = TAG + POSTFIX_CLEANUP;
-    private static final String TAG_CONFIGURATION = TAG + POSTFIX_CONFIGURATION;
     private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS;
     private static final String TAG_PAUSE = TAG + POSTFIX_PAUSE;
     private static final String TAG_RELEASE = TAG + POSTFIX_RELEASE;
     private static final String TAG_RESULTS = TAG + POSTFIX_RESULTS;
     private static final String TAG_SAVED_STATE = TAG + POSTFIX_SAVED_STATE;
-    private static final String TAG_SCREENSHOTS = TAG + POSTFIX_SCREENSHOTS;
     private static final String TAG_STACK = TAG + POSTFIX_STACK;
     private static final String TAG_STATES = TAG + POSTFIX_STATES;
     private static final String TAG_SWITCH = TAG + POSTFIX_SWITCH;
@@ -170,36 +156,47 @@
     // How long we wait until giving up on the last activity to pause.  This
     // is short because it directly impacts the responsiveness of starting the
     // next activity.
-    static final int PAUSE_TIMEOUT = 500;
+    private static final int PAUSE_TIMEOUT = 500;
 
     // How long we wait for the activity to tell us it has stopped before
     // giving up.  This is a good amount of time because we really need this
     // from the application in order to get its saved state.
-    static final int STOP_TIMEOUT = 10 * 1000;
+    private static final int STOP_TIMEOUT = 10 * 1000;
 
     // How long we wait until giving up on an activity telling us it has
     // finished destroying itself.
-    static final int DESTROY_TIMEOUT = 10 * 1000;
+    private static final int DESTROY_TIMEOUT = 10 * 1000;
 
     // How long until we reset a task when the user returns to it.  Currently
     // disabled.
-    static final long ACTIVITY_INACTIVE_RESET_TIME = 0;
-
-    // How long between activity launches that we consider safe to not warn
-    // the user about an unexpected activity being launched on top.
-    static final long START_WARN_TIME = 5 * 1000;
+    private static final long ACTIVITY_INACTIVE_RESET_TIME = 0;
 
     // Set to false to disable the preview that is shown while a new activity
     // is being started.
-    static final boolean SHOW_APP_STARTING_PREVIEW = true;
+    private static final boolean SHOW_APP_STARTING_PREVIEW = true;
 
     // How long to wait for all background Activities to redraw following a call to
     // convertToTranslucent().
-    static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000;
+    private static final long TRANSLUCENT_CONVERSION_TIMEOUT = 2000;
 
     // How many activities have to be scheduled to stop to force a stop pass.
     private static final int MAX_STOPPING_TO_FORCE = 3;
 
+    @Override
+    protected int getChildCount() {
+        return mTaskHistory.size();
+    }
+
+    @Override
+    protected ConfigurationContainer getChildAt(int index) {
+        return mTaskHistory.get(index);
+    }
+
+    @Override
+    protected ConfigurationContainer getParent() {
+        return mActivityContainer.mActivityDisplay;
+    }
+
     enum ActivityState {
         INITIALIZING,
         RESUMED,
@@ -218,18 +215,18 @@
     static final int STACK_VISIBLE = 1;
     // Stack is considered visible, but only becuase it has activity that is visible behind other
     // activities and there is a specific combination of stacks.
-    static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2;
+    private static final int STACK_VISIBLE_ACTIVITY_BEHIND = 2;
 
     /* The various modes for the method {@link #removeTask}. */
     // Task is being completely removed from all stacks in the system.
-    static final int REMOVE_TASK_MODE_DESTROYING = 0;
+    private static final int REMOVE_TASK_MODE_DESTROYING = 0;
     // Task is being removed from this stack so we can add it to another stack. In the case we are
     // moving we don't want to perform some operations on the task like removing it from window
     // manager or recents.
     static final int REMOVE_TASK_MODE_MOVING = 1;
     // Similar to {@link #REMOVE_TASK_MODE_MOVING} and the task will be added to the top of its new
     // stack and the new stack will be on top of all stacks.
-    static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2;
+    private static final int REMOVE_TASK_MODE_MOVING_TO_TOP = 2;
 
     // The height/width divide used when fitting a task within a bounds with method
     // {@link #fitWithinBounds}.
@@ -239,7 +236,7 @@
     private static final int FIT_WITHIN_BOUNDS_DIVIDER = 3;
 
     final ActivityManagerService mService;
-    final WindowManagerService mWindowManager;
+    private final WindowManagerService mWindowManager;
     private final RecentTasks mRecentTasks;
 
     /**
@@ -286,13 +283,6 @@
      */
     ActivityRecord mResumedActivity = null;
 
-    /**
-     * This is the last activity that has been started.  It is only used to
-     * identify when multiple activities are started at once so that the user
-     * can be warned they may not be in the activity they think they are.
-     */
-    ActivityRecord mLastStartedActivity = null;
-
     // The topmost Activity passed to convertToTranslucent(). When non-null it means we are
     // waiting for all Activities in mUndrawnActivitiesBelowTopTranslucent to be removed as they
     // are drawn. When the last member of mUndrawnActivitiesBelowTopTranslucent is removed the
@@ -300,7 +290,7 @@
     // Activity.onTranslucentConversionComplete(false). If a timeout occurs prior to the last
     // background activity being drawn then the same call will be made with a true value.
     ActivityRecord mTranslucentActivityWaiting = null;
-    private ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>();
+    ArrayList<ActivityRecord> mUndrawnActivitiesBelowTopTranslucent = new ArrayList<>();
 
     /**
      * Set when we know we are going to be calling updateConfiguration()
@@ -313,11 +303,11 @@
     // Current bounds of the stack or null if fullscreen.
     Rect mBounds = null;
 
-    boolean mUpdateBoundsDeferred;
-    boolean mUpdateBoundsDeferredCalled;
-    final Rect mDeferredBounds = new Rect();
-    final Rect mDeferredTaskBounds = new Rect();
-    final Rect mDeferredTaskInsetBounds = new Rect();
+    private boolean mUpdateBoundsDeferred;
+    private boolean mUpdateBoundsDeferredCalled;
+    private final Rect mDeferredBounds = new Rect();
+    private final Rect mDeferredTaskBounds = new Rect();
+    private final Rect mDeferredTaskInsetBounds = new Rect();
 
     long mLaunchStartTime = 0;
     long mFullyDrawnStartTime = 0;
@@ -338,7 +328,7 @@
     private final Rect tempRect2 = new Rect();
 
     /** Run all ActivityStacks through this */
-    final ActivityStackSupervisor mStackSupervisor;
+    private final ActivityStackSupervisor mStackSupervisor;
 
     private final LaunchingTaskPositioner mTaskPositioner;
 
@@ -351,7 +341,7 @@
     static final int RELEASE_BACKGROUND_RESOURCES_TIMEOUT_MSG =
             ActivityManagerService.FIRST_ACTIVITY_STACK_MSG + 7;
 
-    static class ScheduleDestroyArgs {
+    private static class ScheduleDestroyArgs {
         final ProcessRecord mOwner;
         final String mReason;
         ScheduleDestroyArgs(ProcessRecord owner, String reason) {
@@ -362,7 +352,7 @@
 
     final Handler mHandler;
 
-    final class ActivityStackHandler extends Handler {
+    private class ActivityStackHandler extends Handler {
 
         ActivityStackHandler(Looper looper) {
             super(looper);
@@ -407,7 +397,8 @@
                     Slog.w(TAG, "Activity stop timeout for " + r);
                     synchronized (mService) {
                         if (r.isInHistory()) {
-                            activityStoppedLocked(r, null, null, null);
+                            r.activityStoppedLocked(null /* icicle */,
+                                    null /* persistentState */, null /* description */);
                         }
                     }
                 } break;
@@ -466,6 +457,7 @@
             mTaskPositioner.setDisplay(activityDisplay.mDisplay);
             mTaskPositioner.configure(mBounds);
         }
+        onParentChanged();
 
         if (mStackId == DOCKED_STACK_ID) {
             // If we created a docked stack we want to resize it so it resizes all other stacks
@@ -482,6 +474,7 @@
             mTaskPositioner.reset();
         }
         mWindowManager.detachStack(mStackId);
+        onParentChanged();
         if (mStackId == DOCKED_STACK_ID) {
             // If we removed a docked stack we want to resize it so it resizes all other stacks
             // in the system to fullscreen.
@@ -490,7 +483,7 @@
         }
     }
 
-    public void getDisplaySize(Point out) {
+    void getDisplaySize(Point out) {
         mActivityContainer.mActivityDisplay.mDisplay.getSize(out);
     }
 
@@ -720,7 +713,7 @@
     /**
      * @param task If non-null, the task will be moved to the back of the stack.
      * */
-    void moveToBack(TaskRecord task) {
+    private void moveToBack(TaskRecord task) {
         if (!isAttached()) {
             return;
         }
@@ -914,7 +907,7 @@
         if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to RESUMED: " + r + " (starting new instance)"
                 + " callers=" + Debug.getCallers(5));
         setResumedActivityLocked(r, "minimalResumeActivityLocked");
-        completeResumeLocked(r);
+        r.completeResumeLocked();
         setLaunchTime(r);
         if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE,
                 "Launch completed; removing icicle of " + r.icicle);
@@ -955,7 +948,7 @@
         }
     }
 
-    void clearLaunchTime(ActivityRecord r) {
+    private void clearLaunchTime(ActivityRecord r) {
         // Make sure that there is no activity waiting for this to launch.
         if (mStackSupervisor.mWaitingActivityLaunched.isEmpty()) {
             r.displayStartTime = r.fullyDrawnStartTime = 0;
@@ -1037,50 +1030,6 @@
         }
     }
 
-    public final Bitmap screenshotActivitiesLocked(ActivityRecord who) {
-        if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "screenshotActivitiesLocked: " + who);
-        if (who.noDisplay) {
-            if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tNo display");
-            return null;
-        }
-
-        if (isHomeStack()) {
-            // This is an optimization -- since we never show Home or Recents within Recents itself,
-            // we can just go ahead and skip taking the screenshot if this is the home stack.
-            if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tHome stack");
-            return null;
-        }
-
-        int w = mService.mThumbnailWidth;
-        int h = mService.mThumbnailHeight;
-
-        if (w <= 0) {
-            Slog.e(TAG, "\tInvalid thumbnail dimensions: " + w + "x" + h);
-            return null;
-        }
-
-        if (mStackId == DOCKED_STACK_ID && mStackSupervisor.mIsDockMinimized) {
-            // When the docked stack is minimized its app windows are cropped significantly so any
-            // screenshot taken will not display the apps contain. So, we avoid taking a screenshot
-            // in that case.
-            if (DEBUG_SCREENSHOTS) Slog.e(TAG, "\tIn minimized docked stack");
-            return null;
-        }
-
-        float scale = 1f;
-        if (DEBUG_SCREENSHOTS) Slog.d(TAG_SCREENSHOTS, "\tTaking screenshot");
-
-        // When this flag is set, we currently take the fullscreen screenshot of the activity but
-        // scaled to half the size. This gives us a "good-enough" fullscreen thumbnail to use within
-        // SystemUI while keeping memory usage low.
-        if (TAKE_FULLSCREEN_SCREENSHOTS) {
-            w = h = -1;
-            scale = mService.mFullscreenThumbnailScale;
-        }
-
-        return mWindowManager.screenshotApplications(who.appToken, DEFAULT_DISPLAY, w, h, scale);
-    }
-
     /**
      * Start pausing the currently resumed activity.  It is an error to call this if there
      * is already an activity being paused or there is no resumed activity.
@@ -1239,57 +1188,6 @@
         mStackSupervisor.ensureActivitiesVisibleLocked(null, 0, !PRESERVE_WINDOWS);
     }
 
-    final void activityResumedLocked(IBinder token) {
-        final ActivityRecord r = ActivityRecord.forTokenLocked(token);
-        if (DEBUG_SAVED_STATE) Slog.i(TAG_STATES, "Resumed activity; dropping state of: " + r);
-        r.icicle = null;
-        r.haveState = false;
-    }
-
-    final void activityStoppedLocked(ActivityRecord r, Bundle icicle,
-            PersistableBundle persistentState, CharSequence description) {
-        if (r.state != ActivityState.STOPPING) {
-            Slog.i(TAG, "Activity reported stop, but no longer stopping: " + r);
-            mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
-            return;
-        }
-        if (persistentState != null) {
-            r.persistentState = persistentState;
-            mService.notifyTaskPersisterLocked(r.task, false);
-        }
-        if (DEBUG_SAVED_STATE) Slog.i(TAG_SAVED_STATE, "Saving icicle of " + r + ": " + icicle);
-        if (icicle != null) {
-            // If icicle is null, this is happening due to a timeout, so we
-            // haven't really saved the state.
-            r.icicle = icicle;
-            r.haveState = true;
-            r.launchCount = 0;
-            r.updateThumbnailLocked(null, description);
-        }
-        if (!r.stopped) {
-            if (DEBUG_STATES) Slog.v(TAG_STATES, "Moving to STOPPED: " + r + " (stop complete)");
-            mHandler.removeMessages(STOP_TIMEOUT_MSG, r);
-            r.stopped = true;
-            r.state = ActivityState.STOPPED;
-
-            mWindowManager.notifyAppStopped(r.appToken);
-
-            if (getVisibleBehindActivity() == r) {
-                mStackSupervisor.requestVisibleBehindLocked(r, false);
-            }
-            if (r.finishing) {
-                r.clearOptionsLocked();
-            } else {
-                if (r.deferRelaunchUntilPaused) {
-                    destroyActivityLocked(r, true, "stop-config");
-                    mStackSupervisor.resumeFocusedStackTopActivityLocked();
-                } else {
-                    mStackSupervisor.updatePreviousProcessLocked(r);
-                }
-            }
-        }
-    }
-
     private void completePauseLocked(boolean resumeNext, ActivityRecord resuming) {
         ActivityRecord prev = mPausingActivity;
         if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Complete pause: " + prev);
@@ -1310,7 +1208,7 @@
                 if (prev.deferRelaunchUntilPaused) {
                     // Complete the deferred relaunch that was waiting for pause to complete.
                     if (DEBUG_PAUSE) Slog.v(TAG_PAUSE, "Re-launching after pause: " + prev);
-                    relaunchActivityLocked(prev, prev.configChangeFlags, false,
+                    prev.relaunchActivityLocked(false /* andResume */,
                             prev.preserveWindowOnDeferredRelaunch);
                 } else if (wasStopping) {
                     // We are also stopping, the stop request must have gone soon after the pause.
@@ -1387,7 +1285,7 @@
         mStackSupervisor.ensureActivitiesVisibleLocked(resuming, 0, !PRESERVE_WINDOWS);
     }
 
-    private void addToStopping(ActivityRecord r, boolean immediate) {
+    void addToStopping(ActivityRecord r, boolean immediate) {
         if (!mStackSupervisor.mStoppingActivities.contains(r)) {
             mStackSupervisor.mStoppingActivities.add(r);
         }
@@ -1408,77 +1306,6 @@
         }
     }
 
-    /**
-     * Once we know that we have asked an application to put an activity in
-     * the resumed state (either by launching it or explicitly telling it),
-     * this function updates the rest of our state to match that fact.
-     */
-    private void completeResumeLocked(ActivityRecord next) {
-        boolean wasVisible = next.visible;
-        next.visible = true;
-        if (!wasVisible) {
-            // Visibility has changed, so take a note of it so we call the TaskStackChangedListener
-            mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
-        }
-        next.idle = false;
-        next.results = null;
-        next.newIntents = null;
-        next.stopped = false;
-
-        if (next.isHomeActivity()) {
-            ProcessRecord app = next.task.mActivities.get(0).app;
-            if (app != null && app != mService.mHomeProcess) {
-                mService.mHomeProcess = app;
-            }
-        }
-
-        if (next.nowVisible) {
-            // We won't get a call to reportActivityVisibleLocked() so dismiss lockscreen now.
-            mStackSupervisor.reportActivityVisibleLocked(next);
-            mStackSupervisor.notifyActivityDrawnForKeyguard();
-        }
-
-        // schedule an idle timeout in case the app doesn't do it for us.
-        mStackSupervisor.scheduleIdleTimeoutLocked(next);
-
-        mStackSupervisor.reportResumedActivityLocked(next);
-
-        next.resumeKeyDispatchingLocked();
-        mNoAnimActivities.clear();
-
-        // Mark the point when the activity is resuming
-        // TODO: To be more accurate, the mark should be before the onCreate,
-        //       not after the onResume. But for subsequent starts, onResume is fine.
-        if (next.app != null) {
-            next.cpuTimeAtResume = mService.mProcessCpuTracker.getCpuTimeForPid(next.app.pid);
-        } else {
-            next.cpuTimeAtResume = 0; // Couldn't get the cpu time of process
-        }
-
-        next.returningOptions = null;
-
-        if (getVisibleBehindActivity() == next) {
-            // When resuming an activity, require it to call requestVisibleBehind() again.
-            setVisibleBehindActivity(null);
-        }
-        mStackSupervisor.checkReadyForSleepLocked();
-    }
-
-    private void setVisible(ActivityRecord r, boolean visible) {
-        r.visible = visible;
-        if (!visible && r.mUpdateTaskThumbnailWhenHidden) {
-            r.updateThumbnailLocked(r.task.getStack().screenshotActivitiesLocked(r), null);
-            r.mUpdateTaskThumbnailWhenHidden = false;
-        }
-        mWindowManager.setAppVisibility(r.appToken, visible);
-        final ArrayList<ActivityContainer> containers = r.mChildContainers;
-        for (int containerNdx = containers.size() - 1; containerNdx >= 0; --containerNdx) {
-            ActivityContainer container = containers.get(containerNdx);
-            container.setVisible(visible);
-        }
-        mStackSupervisor.mAppVisibilitiesChangedSinceLastPause = true;
-    }
-
     // Find the first visible activity above the passed activity and if it is translucent return it
     // otherwise return null;
     ActivityRecord findNextTranslucentActivity(ActivityRecord r) {
@@ -1781,7 +1608,8 @@
                     // is finishing, we no longer change its visibility, but we still need to take
                     // the screenshots if startPausingLocked decided it should be taken.
                     if (r.mUpdateTaskThumbnailWhenHidden) {
-                        r.updateThumbnailLocked(screenshotActivitiesLocked(r), null);
+                        r.updateThumbnailLocked(r.screenshotActivityLocked(),
+                                null /* description */);
                         r.mUpdateTaskThumbnailWhenHidden = false;
                     }
                     continue;
@@ -1792,14 +1620,14 @@
                 }
                 aboveTop = false;
 
-                if (shouldBeVisible(r, behindTranslucentActivity, stackVisibleBehind,
+                if (r.shouldBeVisible(behindTranslucentActivity, stackVisibleBehind,
                         visibleBehind, behindFullscreenActivity)) {
                     if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Make visible? " + r
                             + " finishing=" + r.finishing + " state=" + r.state);
                     // First: if this is not the current activity being started, make
                     // sure it matches the current configuration.
                     if (r != starting) {
-                        ensureActivityConfigurationLocked(r, 0, preserveWindows);
+                        r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindows);
                     }
 
                     if (r.app == null || r.app.thread == null) {
@@ -1817,11 +1645,11 @@
                         if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
                                 "Skipping: already visible at " + r);
 
-                        if (handleAlreadyVisible(r)) {
+                        if (r.handleAlreadyVisible()) {
                             resumeNextActivity = false;
                         }
                     } else {
-                        makeVisibleIfNeeded(starting, r);
+                        r.makeVisibleIfNeeded(starting);
                     }
                     // Aggregate current change flags.
                     configChanges |= r.configChangeFlags;
@@ -1902,33 +1730,6 @@
         }
     }
 
-    /** Return true if the input activity should be made visible */
-    private boolean shouldBeVisible(ActivityRecord r, boolean behindTranslucentActivity,
-            boolean stackVisibleBehind, ActivityRecord visibleBehind,
-            boolean behindFullscreenActivity) {
-
-        if (r == null || !r.okToShowLocked()) {
-            return false;
-        }
-
-        // mLaunchingBehind: Activities launching behind are at the back of the task stack
-        // but must be drawn initially for the animation as though they were visible.
-        final boolean activityVisibleBehind =
-                (behindTranslucentActivity || stackVisibleBehind) && visibleBehind == r;
-
-        boolean isVisible =
-                !behindFullscreenActivity || r.mLaunchTaskBehind || activityVisibleBehind;
-
-        if (mService.mSupportsLeanbackOnly && isVisible && r.isRecentsActivity()) {
-            // On devices that support leanback only (Android TV), Recents activity can only be
-            // visible if the home stack is the focused stack or we are in split-screen mode.
-            isVisible = mStackSupervisor.getStack(DOCKED_STACK_ID) != null
-                    || mStackSupervisor.isFocusedStack(this);
-        }
-
-        return isVisible;
-    }
-
     private void checkTranslucentActivityWaiting(ActivityRecord top) {
         if (mTranslucentActivityWaiting != top) {
             mUndrawnActivitiesBelowTopTranslucent.clear();
@@ -1956,7 +1757,7 @@
             }
             if (!r.visible || r.mLaunchTaskBehind) {
                 if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Starting and making visible: " + r);
-                setVisible(r, true);
+                r.setVisible(true);
             }
             if (r != starting) {
                 mStackSupervisor.startSpecificActivityLocked(r, andResume, false);
@@ -1975,7 +1776,7 @@
         // keeping the screen frozen.
         if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY, "Making invisible: " + r + " " + r.state);
         try {
-            setVisible(r, false);
+            r.setVisible(false);
             switch (r.state) {
                 case STOPPING:
                 case STOPPED:
@@ -2025,50 +1826,6 @@
         return behindFullscreenActivity;
     }
 
-    private void makeVisibleIfNeeded(ActivityRecord starting, ActivityRecord r) {
-
-        // This activity is not currently visible, but is running. Tell it to become visible.
-        if (r.state == ActivityState.RESUMED || r == starting) {
-            if (DEBUG_VISIBILITY) Slog.d(TAG_VISIBILITY,
-                    "Not making visible, r=" + r + " state=" + r.state + " starting=" + starting);
-            return;
-        }
-
-        // If this activity is paused, tell it to now show its window.
-        if (DEBUG_VISIBILITY) Slog.v(TAG_VISIBILITY,
-                "Making visible and scheduling visibility: " + r);
-        try {
-            if (mTranslucentActivityWaiting != null) {
-                r.updateOptionsLocked(r.returningOptions);
-                mUndrawnActivitiesBelowTopTranslucent.add(r);
-            }
-            setVisible(r, true);
-            r.sleeping = false;
-            r.app.pendingUiClean = true;
-            r.app.thread.scheduleWindowVisibility(r.appToken, true);
-            // The activity may be waiting for stop, but that is no longer
-            // appropriate for it.
-            mStackSupervisor.mStoppingActivities.remove(r);
-            mStackSupervisor.mGoingToSleepActivities.remove(r);
-        } catch (Exception e) {
-            // Just skip on any failure; we'll make it
-            // visible when it next restarts.
-            Slog.w(TAG, "Exception thrown making visibile: " + r.intent.getComponent(), e);
-        }
-        handleAlreadyVisible(r);
-    }
-
-    private boolean handleAlreadyVisible(ActivityRecord r) {
-        r.stopFreezingScreenLocked(false);
-        try {
-            if (r.returningOptions != null) {
-                r.app.thread.scheduleOnNewActivityOptions(r.appToken, r.returningOptions);
-            }
-        } catch(RemoteException e) {
-        }
-        return r.state == ActivityState.RESUMED;
-    }
-
     void convertActivityToTranslucent(ActivityRecord r) {
         mTranslucentActivityWaiting = r;
         mUndrawnActivitiesBelowTopTranslucent.clear();
@@ -2529,7 +2286,7 @@
             boolean notUpdated = true;
             if (mStackSupervisor.isFocusedStack(this)) {
                 Configuration config = mWindowManager.updateOrientationFromAppTokens(
-                        mService.mGlobalConfiguration,
+                        mService.getGlobalConfiguration(),
                         next.mayFreezeScreenLocked(next.app) ? next.appToken : null);
                 if (config != null) {
                     next.frozenBeforeDestroy = true;
@@ -2554,7 +2311,7 @@
                 if (!next.visible || next.stopped) {
                     mWindowManager.setAppVisibility(next.appToken, true);
                 }
-                completeResumeLocked(next);
+                next.completeResumeLocked();
                 if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
                 return true;
             }
@@ -2628,7 +2385,7 @@
             // From this point on, if something goes wrong there is no way
             // to recover the activity.
             try {
-                completeResumeLocked(next);
+                next.completeResumeLocked();
             } catch (Exception e) {
                 // If any exception gets thrown, toss away this
                 // activity and try the next one.
@@ -2903,7 +2660,7 @@
      * @param forceReset
      * @return An ActivityOptions that needs to be processed.
      */
-    final ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) {
+    private ActivityOptions resetTargetTaskIfNeededLocked(TaskRecord task, boolean forceReset) {
         ActivityOptions topOptions = null;
 
         int replyChainEnd = -1;
@@ -3485,7 +3242,7 @@
         return true;
     }
 
-    final void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) {
+    private void finishActivityResultsLocked(ActivityRecord r, int resultCode, Intent resultData) {
         // send the result
         ActivityRecord resultTo = r.resultTo;
         if (resultTo != null) {
@@ -3811,8 +3568,7 @@
      *
      * Note: Call before #removeActivityFromHistoryLocked.
      */
-    final void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices,
-            boolean setState) {
+    private void cleanUpActivityLocked(ActivityRecord r, boolean cleanServices, boolean setState) {
         if (mResumedActivity == r) {
             mResumedActivity = null;
         }
@@ -3902,7 +3658,7 @@
     /**
      * Perform clean-up of service connections in an activity record.
      */
-    final void cleanUpActivityServicesLocked(ActivityRecord r) {
+    private void cleanUpActivityServicesLocked(ActivityRecord r) {
         // Throw away any services that have been bound by this activity.
         if (r.connections != null) {
             Iterator<ConnectionRecord> it = r.connections.iterator();
@@ -3920,7 +3676,7 @@
         mHandler.sendMessage(msg);
     }
 
-    final void destroyActivitiesLocked(ProcessRecord owner, String reason) {
+    private void destroyActivitiesLocked(ProcessRecord owner, String reason) {
         boolean lastIsOpaque = false;
         boolean activityRemoved = false;
         for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
@@ -4197,7 +3953,7 @@
         }
     }
 
-    boolean removeHistoryRecordsForAppLocked(ProcessRecord app) {
+    private boolean removeHistoryRecordsForAppLocked(ProcessRecord app) {
         removeHistoryRecordsForAppLocked(mLRUActivities, app, "mLRUActivities");
         removeHistoryRecordsForAppLocked(mStackSupervisor.mStoppingActivities, app,
                 "mStoppingActivities");
@@ -4288,7 +4044,7 @@
         return hasVisibleActivities;
     }
 
-    final void updateTransitLocked(int transit, ActivityOptions options) {
+    private void updateTransitLocked(int transit, ActivityOptions options) {
         if (options != null) {
             ActivityRecord r = topRunningActivityLocked();
             if (r != null && r.state != ActivityState.RESUMED) {
@@ -4300,7 +4056,7 @@
         mWindowManager.prepareAppTransition(transit, false);
     }
 
-    void updateTaskMovement(TaskRecord task, boolean toFront) {
+    private void updateTaskMovement(TaskRecord task, boolean toFront) {
         if (task.isPersistable) {
             task.mLastTimeMoved = System.currentTimeMillis();
             // Sign is used to keep tasks sorted when persisted. Tasks sent to the bottom most
@@ -4509,8 +4265,7 @@
         return true;
     }
 
-    static final void logStartActivity(int tag, ActivityRecord r,
-            TaskRecord task) {
+    static void logStartActivity(int tag, ActivityRecord r, TaskRecord task) {
         final Uri data = r.intent.getData();
         final String strData = data != null ? data.toSafeString() : null;
 
@@ -4539,7 +4294,8 @@
                     (start.task == task) ? activities.indexOf(start) : activities.size() - 1;
             for (; activityIndex >= 0; --activityIndex) {
                 final ActivityRecord r = activities.get(activityIndex);
-                updatedConfig |= ensureActivityConfigurationLocked(r, 0, preserveWindow);
+                updatedConfig |= r.ensureActivityConfigurationLocked(0 /* globalChanges */,
+                        preserveWindow);
                 if (r.fullscreen) {
                     behindFullscreen = true;
                     break;
@@ -4582,7 +4338,7 @@
                 }
             }
 
-            mTmpConfigs.put(task.taskId, task.mOverrideConfig);
+            mTmpConfigs.put(task.taskId, task.getOverrideConfiguration());
             mTmpBounds.put(task.taskId, task.mBounds);
             if (tempTaskInsetBounds != null) {
                 mTmpInsetBounds.put(task.taskId, tempTaskInsetBounds);
@@ -4636,245 +4392,6 @@
         }
     }
 
-    /**
-     * Make sure the given activity matches the current configuration. Returns false if the activity
-     * had to be destroyed.  Returns true if the configuration is the same, or the activity will
-     * remain running as-is for whatever reason. Ensures the HistoryRecord is updated with the
-     * correct configuration and all other bookkeeping is handled.
-     */
-    boolean ensureActivityConfigurationLocked(
-            ActivityRecord r, int globalChanges, boolean preserveWindow) {
-        if (mConfigWillChange) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                    "Skipping config check (will change): " + r);
-            return true;
-        }
-
-        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                "Ensuring correct configuration: " + r);
-
-        // Short circuit: if the two configurations are equal (the common case), then there is
-        // nothing to do.
-        final Configuration newConfig = mService.mGlobalConfiguration;
-        r.task.sanitizeOverrideConfiguration(newConfig);
-        final Configuration taskConfig = r.task.mOverrideConfig;
-        if (r.configuration.equals(newConfig)
-                && r.taskConfigOverride.equals(taskConfig)
-                && !r.forceNewConfig) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                    "Configuration unchanged in " + r);
-            return true;
-        }
-
-        // We don't worry about activities that are finishing.
-        if (r.finishing) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                    "Configuration doesn't matter in finishing " + r);
-            r.stopFreezingScreenLocked(false);
-            return true;
-        }
-
-        // Okay we now are going to make this activity have the new config.
-        // But then we need to figure out how it needs to deal with that.
-        final Configuration oldConfig = r.configuration;
-        final Configuration oldTaskOverride = r.taskConfigOverride;
-        r.configuration = newConfig;
-        r.taskConfigOverride = taskConfig;
-
-        int taskChanges = getTaskConfigurationChanges(r, taskConfig, oldTaskOverride);
-        final int changes = oldConfig.diff(newConfig) | taskChanges;
-        if (changes == 0 && !r.forceNewConfig) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                    "Configuration no differences in " + r);
-            // There are no significant differences, so we won't relaunch but should still deliver
-            // the new configuration to the client process.
-            r.scheduleConfigurationChanged(taskConfig, true);
-            return true;
-        }
-
-        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                "Configuration changes for " + r + " ; taskChanges="
-                        + Configuration.configurationDiffToString(taskChanges) + ", allChanges="
-                        + Configuration.configurationDiffToString(changes));
-
-        // If the activity isn't currently running, just leave the new
-        // configuration and it will pick that up next time it starts.
-        if (r.app == null || r.app.thread == null) {
-            if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                    "Configuration doesn't matter not running " + r);
-            r.stopFreezingScreenLocked(false);
-            r.forceNewConfig = false;
-            return true;
-        }
-
-        // Figure out how to handle the changes between the configurations.
-        if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                "Checking to restart " + r.info.name + ": changed=0x"
-                + Integer.toHexString(changes) + ", handles=0x"
-                + Integer.toHexString(r.info.getRealConfigChanged()) + ", newConfig=" + newConfig
-                + ", taskConfig=" + taskConfig);
-
-        if ((changes&(~r.info.getRealConfigChanged())) != 0 || r.forceNewConfig) {
-            // Aha, the activity isn't handling the change, so DIE DIE DIE.
-            r.configChangeFlags |= changes;
-            r.startFreezingScreenLocked(r.app, globalChanges);
-            r.forceNewConfig = false;
-            preserveWindow &= isResizeOnlyChange(changes);
-            if (r.app == null || r.app.thread == null) {
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                        "Config is destroying non-running " + r);
-                destroyActivityLocked(r, true, "config");
-            } else if (r.state == ActivityState.PAUSING) {
-                // A little annoying: we are waiting for this activity to finish pausing. Let's not
-                // do anything now, but just flag that it needs to be restarted when done pausing.
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                        "Config is skipping already pausing " + r);
-                r.deferRelaunchUntilPaused = true;
-                r.preserveWindowOnDeferredRelaunch = preserveWindow;
-                return true;
-            } else if (r.state == ActivityState.RESUMED) {
-                // Try to optimize this case: the configuration is changing and we need to restart
-                // the top, resumed activity. Instead of doing the normal handshaking, just say
-                // "restart!".
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                        "Config is relaunching resumed " + r);
-
-                if (DEBUG_STATES && !r.visible) {
-                    Slog.v(TAG_STATES, "Config is relaunching resumed invisible activity " + r
-                            + " called by " + Debug.getCallers(4));
-                }
-
-                relaunchActivityLocked(r, r.configChangeFlags, true, preserveWindow);
-            } else {
-                if (DEBUG_SWITCH || DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
-                        "Config is relaunching non-resumed " + r);
-                relaunchActivityLocked(r, r.configChangeFlags, false, preserveWindow);
-            }
-
-            // All done...  tell the caller we weren't able to keep this activity around.
-            return false;
-        }
-
-        // Default case: the activity can handle this new configuration, so hand it over.
-        // NOTE: We only forward the task override configuration as the system level configuration
-        // changes is always sent to all processes when they happen so it can just use whatever
-        // system level configuration it last got.
-        r.scheduleConfigurationChanged(taskConfig, true);
-        r.stopFreezingScreenLocked(false);
-
-        return true;
-    }
-
-    private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig,
-            Configuration oldTaskOverride) {
-
-        // If we went from full-screen to non-full-screen, make sure to use the correct
-        // configuration task diff, so the diff stays as small as possible.
-        if (Configuration.EMPTY.equals(oldTaskOverride)
-                && !Configuration.EMPTY.equals(taskConfig)) {
-            oldTaskOverride = record.task.extractOverrideConfig(record.configuration);
-        }
-
-        // Conversely, do the same when going the other direction.
-        if (Configuration.EMPTY.equals(taskConfig)
-                && !Configuration.EMPTY.equals(oldTaskOverride)) {
-            taskConfig = record.task.extractOverrideConfig(record.configuration);
-        }
-
-        // Determine what has changed.  May be nothing, if this is a config
-        // that has come back from the app after going idle.  In that case
-        // we just want to leave the official config object now in the
-        // activity and do nothing else.
-        int taskChanges = oldTaskOverride.diff(taskConfig, true /* skipUndefined */);
-        // We don't want to use size changes if they don't cross boundaries that are important to
-        // the app.
-        if ((taskChanges & CONFIG_SCREEN_SIZE) != 0) {
-            final boolean crosses = record.crossesHorizontalSizeThreshold(
-                    oldTaskOverride.screenWidthDp, taskConfig.screenWidthDp)
-                    || record.crossesVerticalSizeThreshold(
-                    oldTaskOverride.screenHeightDp, taskConfig.screenHeightDp);
-            if (!crosses) {
-                taskChanges &= ~CONFIG_SCREEN_SIZE;
-            }
-        }
-        if ((taskChanges & CONFIG_SMALLEST_SCREEN_SIZE) != 0) {
-            final int oldSmallest = oldTaskOverride.smallestScreenWidthDp;
-            final int newSmallest = taskConfig.smallestScreenWidthDp;
-            if (!record.crossesSmallestSizeThreshold(oldSmallest, newSmallest)) {
-                taskChanges &= ~CONFIG_SMALLEST_SCREEN_SIZE;
-            }
-        }
-        return taskChanges;
-    }
-
-    private static boolean isResizeOnlyChange(int change) {
-        return (change & ~(CONFIG_SCREEN_SIZE | CONFIG_SMALLEST_SCREEN_SIZE | CONFIG_ORIENTATION
-                | CONFIG_SCREEN_LAYOUT)) == 0;
-    }
-
-    private void relaunchActivityLocked(
-            ActivityRecord r, int changes, boolean andResume, boolean preserveWindow) {
-        if (mService.mSuppressResizeConfigChanges && preserveWindow) {
-            r.configChangeFlags = 0;
-            return;
-        }
-
-        List<ResultInfo> results = null;
-        List<ReferrerIntent> newIntents = null;
-        if (andResume) {
-            results = r.results;
-            newIntents = r.newIntents;
-        }
-        if (DEBUG_SWITCH) Slog.v(TAG_SWITCH,
-                "Relaunching: " + r + " with results=" + results + " newIntents=" + newIntents
-                + " andResume=" + andResume + " preserveWindow=" + preserveWindow);
-        EventLog.writeEvent(andResume ? EventLogTags.AM_RELAUNCH_RESUME_ACTIVITY
-                : EventLogTags.AM_RELAUNCH_ACTIVITY, r.userId, System.identityHashCode(r),
-                r.task.taskId, r.shortComponentName);
-
-        r.startFreezingScreenLocked(r.app, 0);
-
-        mStackSupervisor.removeChildActivityContainers(r);
-
-        try {
-            if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH,
-                    "Moving to " + (andResume ? "RESUMED" : "PAUSED") + " Relaunching " + r
-                    + " callers=" + Debug.getCallers(6));
-            r.forceNewConfig = false;
-            mStackSupervisor.activityRelaunchingLocked(r);
-            r.app.thread.scheduleRelaunchActivity(r.appToken, results, newIntents, changes,
-                    !andResume, new Configuration(mService.mGlobalConfiguration),
-                    new Configuration(r.task.mOverrideConfig), preserveWindow);
-            // Note: don't need to call pauseIfSleepingLocked() here, because
-            // the caller will only pass in 'andResume' if this activity is
-            // currently resumed, which implies we aren't sleeping.
-        } catch (RemoteException e) {
-            if (DEBUG_SWITCH || DEBUG_STATES) Slog.i(TAG_SWITCH, "Relaunch failed", e);
-        }
-
-        if (andResume) {
-            if (DEBUG_STATES) {
-                Slog.d(TAG_STATES, "Resumed after relaunch " + r);
-            }
-            r.results = null;
-            r.newIntents = null;
-            mService.showUnsupportedZoomDialogIfNeededLocked(r);
-            mService.showAskCompatModeDialogLocked(r);
-        } else {
-            mHandler.removeMessages(PAUSE_TIMEOUT_MSG, r);
-            r.state = ActivityState.PAUSED;
-            // if the app is relaunched when it's stopped, and we're not resuming,
-            // put it back into stopped state.
-            if (r.stopped) {
-                addToStopping(r, true /* immediate */);
-            }
-        }
-
-        r.configChangeFlags = 0;
-        r.deferRelaunchUntilPaused = false;
-        r.preserveWindowOnDeferredRelaunch = false;
-    }
-
     boolean willActivityBeVisibleLocked(IBinder token) {
         for (int taskNdx = mTaskHistory.size() - 1; taskNdx >= 0; --taskNdx) {
             final ArrayList<ActivityRecord> activities = mTaskHistory.get(taskNdx).mActivities;
@@ -5028,7 +4545,7 @@
         }
     }
 
-    public void unhandledBackLocked() {
+    void unhandledBackLocked() {
         final int top = mTaskHistory.size() - 1;
         if (DEBUG_SWITCH) Slog.d(TAG_SWITCH, "Performing unhandledBack(): top activity at " + top);
         if (top >= 0) {
@@ -5314,10 +4831,11 @@
         mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken,
                 r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
                 (r.info.flags & FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId, r.info.configChanges,
-                task.voiceSession != null, r.mLaunchTaskBehind, bounds, task.mOverrideConfig,
-                task.mResizeMode, r.isAlwaysFocusable(), task.isHomeTask(),
-                r.appInfo.targetSdkVersion, r.mRotationAnimationHint, task.isOnTopLauncher());
-        r.taskConfigOverride = task.mOverrideConfig;
+                task.voiceSession != null, r.mLaunchTaskBehind, bounds,
+                task.getOverrideConfiguration(), task.mResizeMode, r.isAlwaysFocusable(),
+                task.isHomeTask(), r.appInfo.targetSdkVersion, r.mRotationAnimationHint,
+                task.isOnTopLauncher());
+        r.onOverrideConfigurationSent();
     }
 
     void moveToFrontAndResumeStateIfNeeded(
@@ -5368,9 +4886,10 @@
 
     private void setAppTask(ActivityRecord r, TaskRecord task) {
         final Rect bounds = task.updateOverrideConfigurationFromLaunchBounds();
-        mWindowManager.setAppTask(r.appToken, task.taskId, mStackId, bounds, task.mOverrideConfig,
-                task.mResizeMode, task.isHomeTask(), task.isOnTopLauncher());
-        r.taskConfigOverride = task.mOverrideConfig;
+        mWindowManager.setAppTask(r.appToken, task.taskId, mStackId, bounds,
+                task.getOverrideConfiguration(), task.mResizeMode, task.isHomeTask(),
+                task.isOnTopLauncher());
+        r.onOverrideConfigurationSent();
     }
 
     public int getStackId() {
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index e1fe0d2..cd7481c 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -178,7 +178,8 @@
 import static com.android.server.am.TaskRecord.LOCK_TASK_AUTH_WHITELISTED;
 import static com.android.server.wm.AppTransition.TRANSIT_DOCK_TASK_FROM_RECENTS;
 
-public final class ActivityStackSupervisor implements DisplayListener {
+public final class ActivityStackSupervisor extends ConfigurationContainer
+        implements DisplayListener {
     private static final String TAG = TAG_WITH_CLASS_NAME ? "ActivityStackSupervisor" : TAG_AM;
     private static final String TAG_CONTAINERS = TAG + POSTFIX_CONTAINERS;
     private static final String TAG_FOCUS = TAG + POSTFIX_FOCUS;
@@ -412,6 +413,21 @@
 
     private final ResizeDockedStackTimeout mResizeDockedStackTimeout;
 
+    @Override
+    protected int getChildCount() {
+        return mActivityDisplays.size();
+    }
+
+    @Override
+    protected ConfigurationContainer getChildAt(int index) {
+        return mActivityDisplays.valueAt(index);
+    }
+
+    @Override
+    protected ConfigurationContainer getParent() {
+        return null;
+    }
+
     static class FindTaskResult {
         ActivityRecord r;
         boolean matchedByRootAffinity;
@@ -1182,7 +1198,7 @@
         // just restarting it anyway.
         if (checkConfig) {
             Configuration config = mWindowManager.updateOrientationFromAppTokens(
-                    mService.mGlobalConfiguration,
+                    mService.getGlobalConfiguration(),
                     r.mayFreezeScreenLocked(app) ? r.appToken : null);
             // Deferring resume here because we're going to launch new activity shortly.
             // We don't want to perform a redundant launch of the same record while ensuring
@@ -1272,12 +1288,16 @@
                 app.pendingUiClean = true;
             }
             app.forceProcessStateUpTo(mService.mTopProcessState);
+            // Because we could be starting an Activity in the system process this may not go across
+            // a Binder interface which would create a new Configuration. Consequently we have to
+            // always create a new Configuration here.
             app.thread.scheduleLaunchActivity(new Intent(r.intent), r.appToken,
                     System.identityHashCode(r), r.info,
-                    new Configuration(mService.mGlobalConfiguration),
-                    new Configuration(task.mOverrideConfig), r.compat, r.launchedFromPackage,
-                    task.voiceInteractor, app.repProcState, r.icicle, r.persistentState, results,
-                    newIntents, !andResume, mService.isNextTransitionForward(), profilerInfo);
+                    new Configuration(mService.getGlobalConfiguration()),
+                    new Configuration(task.getMergedOverrideConfiguration()), r.compat,
+                    r.launchedFromPackage, task.voiceInteractor, app.repProcState, r.icicle,
+                    r.persistentState, results, newIntents, !andResume,
+                    mService.isNextTransitionForward(), profilerInfo);
 
             if ((app.info.privateFlags&ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) {
                 // This may be a heavy-weight process!  Note that the package
@@ -1599,7 +1619,7 @@
             // We'll update with whatever configuration it now says
             // it used to launch.
             if (config != null) {
-                r.configuration = config;
+                r.setLastReportedConfiguration(config);
             }
 
             // We are now idle.  If someone is waiting for a thumbnail from
@@ -1865,8 +1885,9 @@
                     // WM resizeTask must be done after the task is moved to the correct stack,
                     // because Task's setBounds() also updates dim layer's bounds, but that has
                     // dependency on the stack.
-                    mWindowManager.resizeTask(task.taskId, task.mBounds, task.mOverrideConfig,
-                            false /* relayout */, false /* forced */);
+                    mWindowManager.resizeTask(task.taskId, task.mBounds,
+                            task.getOverrideConfiguration(), false /* relayout */,
+                            false /* forced */);
                 }
             }
         }
@@ -2234,11 +2255,9 @@
         if (updatedConfig) {
             final ActivityRecord r = task.topRunningActivityLocked();
             if (r != null) {
-                final ActivityStack stack = r.getStack();
-                kept = stack.ensureActivityConfigurationLocked(r, 0, preserveWindow);
+                kept = r.ensureActivityConfigurationLocked(0 /* globalChanges */, preserveWindow);
 
                 if (!deferResume) {
-
                     // All other activities must be made visible with their correct configuration.
                     ensureActivitiesVisibleLocked(r, 0, !PRESERVE_WINDOWS);
                     if (!kept) {
@@ -2247,7 +2266,8 @@
                 }
             }
         }
-        mWindowManager.resizeTask(task.taskId, task.mBounds, task.mOverrideConfig, kept, forced);
+        mWindowManager.resizeTask(task.taskId, task.mBounds, task.getOverrideConfiguration(), kept,
+                forced);
 
         Trace.traceEnd(TRACE_TAG_ACTIVITY_MANAGER);
         return kept;
@@ -2589,7 +2609,7 @@
         task.updateOverrideConfigurationForStack(stack);
 
         mWindowManager.positionTaskInStack(
-                taskId, stackId, position, task.mBounds, task.mOverrideConfig);
+                taskId, stackId, position, task.mBounds, task.getOverrideConfiguration());
         stack.positionTask(task, position);
         // The task might have already been running and its visibility needs to be synchronized with
         // the visibility of the stack / windows.
@@ -2862,12 +2882,12 @@
     }
 
     // Called when WindowManager has finished animating the launchingBehind activity to the back.
-    void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) {
+    private void handleLaunchTaskBehindCompleteLocked(ActivityRecord r) {
         final TaskRecord task = r.task;
         final ActivityStack stack = task.getStack();
 
         r.mLaunchTaskBehind = false;
-        task.setLastThumbnailLocked(stack.screenshotActivitiesLocked(r));
+        task.setLastThumbnailLocked(r.screenshotActivityLocked());
         mRecentTasks.addLocked(task);
         mService.notifyTaskStackChangedLocked();
         mWindowManager.setAppVisibility(r.appToken, false);
@@ -4230,7 +4250,7 @@
 
     /** Exactly one of these classes per Display in the system. Capable of holding zero or more
      * attached {@link ActivityStack}s */
-    class ActivityDisplay {
+    class ActivityDisplay extends ConfigurationContainer {
         /** Actual Display this object tracks. */
         int mDisplayId;
         Display mDisplay;
@@ -4290,6 +4310,21 @@
         public String toString() {
             return "ActivityDisplay={" + mDisplayId + " numStacks=" + mStacks.size() + "}";
         }
+
+        @Override
+        protected int getChildCount() {
+            return mStacks.size();
+        }
+
+        @Override
+        protected ConfigurationContainer getChildAt(int index) {
+            return mStacks.get(index);
+        }
+
+        @Override
+        protected ConfigurationContainer getParent() {
+            return ActivityStackSupervisor.this;
+        }
     }
 
     class VirtualActivityDisplay extends ActivityDisplay {
diff --git a/services/core/java/com/android/server/am/ActivityStarter.java b/services/core/java/com/android/server/am/ActivityStarter.java
index 8252775..a834af7 100644
--- a/services/core/java/com/android/server/am/ActivityStarter.java
+++ b/services/core/java/com/android/server/am/ActivityStarter.java
@@ -98,6 +98,7 @@
 import android.content.pm.UserInfo;
 import android.content.res.Configuration;
 import android.graphics.Rect;
+import android.hardware.power.V1_0.PowerHint;
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.IBinder;
@@ -469,9 +470,9 @@
         }
 
         ActivityRecord r = new ActivityRecord(mService, callerApp, callingUid, callingPackage,
-                intent, resolvedType, aInfo, mService.mGlobalConfiguration, resultRecord, resultWho,
-                requestCode, componentSpecified, voiceSession != null, mSupervisor, container,
-                options, sourceRecord);
+                intent, resolvedType, aInfo, mService.getGlobalConfiguration(), resultRecord,
+                resultWho, requestCode, componentSpecified, voiceSession != null, mSupervisor,
+                container, options, sourceRecord);
         if (outActivity != null) {
             outActivity[0] = r;
         }
@@ -781,7 +782,7 @@
                 stack = container.mStack;
             }
             stack.mConfigWillChange = globalConfig != null
-                    && mService.mGlobalConfiguration.diff(globalConfig) != 0;
+                    && mService.getGlobalConfiguration().diff(globalConfig) != 0;
             if (DEBUG_CONFIGURATION) Slog.v(TAG_CONFIGURATION,
                     "Starting activity when config will change = " + stack.mConfigWillChange);
 
@@ -1003,7 +1004,7 @@
                 curTop.task != null && mStartActivity != null &&
                 curTop.task != mStartActivity.task )) &&
                 mService.mLocalPowerManager != null) {
-            mService.mLocalPowerManager.powerHint(PowerManagerInternal.POWER_HINT_LAUNCH, 1);
+            mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 1);
             mPowerHintSent = true;
         }
     }
@@ -1011,7 +1012,7 @@
     void sendPowerHintForLaunchEndIfNeeded() {
         // Trigger launch power hint if activity is launched
         if (mPowerHintSent && mService.mLocalPowerManager != null) {
-            mService.mLocalPowerManager.powerHint(PowerManagerInternal.POWER_HINT_LAUNCH, 0);
+            mService.mLocalPowerManager.powerHint(PowerHint.LAUNCH, 0);
             mPowerHintSent = false;
         }
     }
diff --git a/services/core/java/com/android/server/am/BroadcastQueue.java b/services/core/java/com/android/server/am/BroadcastQueue.java
index 00497d4..4e69162 100644
--- a/services/core/java/com/android/server/am/BroadcastQueue.java
+++ b/services/core/java/com/android/server/am/BroadcastQueue.java
@@ -268,7 +268,7 @@
 
         r.receiver = app.thread.asBinder();
         r.curApp = app;
-        app.curReceiver = r;
+        app.curReceivers.add(r);
         app.forceProcessStateUpTo(ActivityManager.PROCESS_STATE_RECEIVER);
         mService.updateLruProcessLocked(app, false, null);
         mService.updateOomAdjLocked();
@@ -296,7 +296,7 @@
                         "Process cur broadcast " + r + ": NOT STARTED!");
                 r.receiver = null;
                 r.curApp = null;
-                app.curReceiver = null;
+                app.curReceivers.remove(r);
             }
         }
     }
@@ -397,8 +397,8 @@
         }
         r.receiver = null;
         r.intent.setComponent(null);
-        if (r.curApp != null && r.curApp.curReceiver == r) {
-            r.curApp.curReceiver = null;
+        if (r.curApp != null && r.curApp.curReceivers.contains(r)) {
+            r.curApp.curReceivers.remove(r);
         }
         if (r.curFilter != null) {
             r.curFilter.receiverList.curBroadcast = null;
@@ -651,7 +651,7 @@
                 // things that directly call the IActivityManager API, which
                 // are already core system stuff so don't matter for this.
                 r.curApp = filter.receiverList.app;
-                filter.receiverList.app.curReceiver = r;
+                filter.receiverList.app.curReceivers.add(r);
                 mService.updateOomAdjLocked(r.curApp);
             }
         }
@@ -679,7 +679,7 @@
                 r.curFilter = null;
                 filter.receiverList.curBroadcast = null;
                 if (filter.receiverList.app != null) {
-                    filter.receiverList.app.curReceiver = null;
+                    filter.receiverList.app.curReceivers.remove(r);
                 }
             }
         }
diff --git a/services/core/java/com/android/server/am/CompatModePackages.java b/services/core/java/com/android/server/am/CompatModePackages.java
index 0b282ed..bfc0456 100644
--- a/services/core/java/com/android/server/am/CompatModePackages.java
+++ b/services/core/java/com/android/server/am/CompatModePackages.java
@@ -38,6 +38,7 @@
 import android.content.pm.ApplicationInfo;
 import android.content.pm.IPackageManager;
 import android.content.res.CompatibilityInfo;
+import android.content.res.Configuration;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.Message;
@@ -197,18 +198,19 @@
     }
 
     public CompatibilityInfo compatibilityInfoForPackageLocked(ApplicationInfo ai) {
-        CompatibilityInfo ci = new CompatibilityInfo(ai, mService.mGlobalConfiguration.screenLayout,
-                mService.mGlobalConfiguration.smallestScreenWidthDp,
+        final Configuration globalConfig = mService.getGlobalConfiguration();
+        CompatibilityInfo ci = new CompatibilityInfo(ai, globalConfig.screenLayout,
+                globalConfig.smallestScreenWidthDp,
                 (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0);
         //Slog.i(TAG, "*********** COMPAT FOR PKG " + ai.packageName + ": " + ci);
         return ci;
     }
 
     public int computeCompatModeLocked(ApplicationInfo ai) {
-        boolean enabled = (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0;
-        CompatibilityInfo info = new CompatibilityInfo(ai,
-                mService.mGlobalConfiguration.screenLayout,
-                mService.mGlobalConfiguration.smallestScreenWidthDp, enabled);
+        final boolean enabled = (getPackageFlags(ai.packageName)&COMPAT_FLAG_ENABLED) != 0;
+        final Configuration globalConfig = mService.getGlobalConfiguration();
+        final CompatibilityInfo info = new CompatibilityInfo(ai, globalConfig.screenLayout,
+                globalConfig.smallestScreenWidthDp, enabled);
         if (info.alwaysSupportsScreen()) {
             return ActivityManager.COMPAT_MODE_NEVER;
         }
@@ -383,7 +385,8 @@
             }
 
             if (starting != null) {
-                stack.ensureActivityConfigurationLocked(starting, 0, false);
+                starting.ensureActivityConfigurationLocked(0 /* globalChanges */,
+                        false /* preserveWindow */);
                 // And we need to make sure at this point that all other activities
                 // are made visible with the correct configuration.
                 stack.ensureActivitiesVisibleLocked(starting, 0, !PRESERVE_WINDOWS);
@@ -408,8 +411,9 @@
             out.startTag(null, "compat-packages");
 
             final IPackageManager pm = AppGlobals.getPackageManager();
-            final int screenLayout = mService.mGlobalConfiguration.screenLayout;
-            final int smallestScreenWidthDp = mService.mGlobalConfiguration.smallestScreenWidthDp;
+            final Configuration globalConfig = mService.getGlobalConfiguration();
+            final int screenLayout = globalConfig.screenLayout;
+            final int smallestScreenWidthDp = globalConfig.smallestScreenWidthDp;
             final Iterator<Map.Entry<String, Integer>> it = pkgs.entrySet().iterator();
             while (it.hasNext()) {
                 Map.Entry<String, Integer> entry = it.next();
diff --git a/services/core/java/com/android/server/am/ConfigurationContainer.java b/services/core/java/com/android/server/am/ConfigurationContainer.java
new file mode 100644
index 0000000..30f5309
--- /dev/null
+++ b/services/core/java/com/android/server/am/ConfigurationContainer.java
@@ -0,0 +1,128 @@
+/*
+ * Copyright (C) 2016 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 com.android.server.am;
+
+import android.content.res.Configuration;
+
+/**
+ * Contains common logic for classes that have override configurations and are organized in a
+ * hierarchy.
+ */
+abstract class ConfigurationContainer<E extends ConfigurationContainer> {
+
+    /** Contains override configuration settings applied to this configuration container. */
+    private Configuration mOverrideConfiguration = new Configuration();
+
+    /**
+     * Contains full configuration applied to this configuration container. Corresponds to full
+     * parent's config with applied {@link #mOverrideConfiguration}.
+     */
+    private Configuration mFullConfiguration = new Configuration();
+
+    /**
+     * Contains merged override configuration settings from the top of the hierarchy down to this
+     * particular instance. It is different from {@link #mFullConfiguration} because it starts from
+     * topmost container's override config instead of global config.
+     */
+    private Configuration mMergedOverrideConfiguration = new Configuration();
+
+    /**
+     * Returns full configuration applied to this configuration container.
+     * This method should be used for getting settings applied in each particular level of the
+     * hierarchy.
+     */
+    Configuration getConfiguration() {
+        return mFullConfiguration;
+    }
+
+    /**
+     * Notify that parent config changed and we need to update full configuration.
+     * @see #mFullConfiguration
+     */
+    void onConfigurationChanged(Configuration newParentConfig) {
+        mFullConfiguration.setTo(newParentConfig);
+        mFullConfiguration.updateFrom(mOverrideConfiguration);
+        for (int i = getChildCount() - 1; i >= 0; --i) {
+            final ConfigurationContainer child = getChildAt(i);
+            child.onConfigurationChanged(mFullConfiguration);
+        }
+    }
+
+    /** Returns override configuration applied to this configuration container. */
+    Configuration getOverrideConfiguration() {
+        return mOverrideConfiguration;
+    }
+
+    /**
+     * Update override configuration and recalculate full config.
+     * @see #mOverrideConfiguration
+     * @see #mFullConfiguration
+     */
+    void onOverrideConfigurationChanged(Configuration overrideConfiguration) {
+        mOverrideConfiguration.setTo(overrideConfiguration);
+        // Update full configuration of this container and all its children.
+        final ConfigurationContainer parent = getParent();
+        onConfigurationChanged(parent != null ? parent.getConfiguration() : Configuration.EMPTY);
+        // Update merged override config of this container and all its children.
+        onMergedOverrideConfigurationChanged();
+    }
+
+    /**
+     * Get merged override configuration from the top of the hierarchy down to this particular
+     * instance. This should be reported to client as override config.
+     */
+    Configuration getMergedOverrideConfiguration() {
+        return mMergedOverrideConfiguration;
+    }
+
+    /**
+     * Update merged override configuration based on corresponding parent's config and notify all
+     * its children. If there is no parent, merged override configuration will set equal to current
+     * override config.
+     * @see #mMergedOverrideConfiguration
+     */
+    private void onMergedOverrideConfigurationChanged() {
+        final ConfigurationContainer parent = getParent();
+        if (parent != null) {
+            mMergedOverrideConfiguration.setTo(parent.getMergedOverrideConfiguration());
+            mMergedOverrideConfiguration.updateFrom(mOverrideConfiguration);
+        } else {
+            mMergedOverrideConfiguration.setTo(mOverrideConfiguration);
+        }
+        for (int i = getChildCount() - 1; i >= 0; --i) {
+            final ConfigurationContainer child = getChildAt(i);
+            child.onMergedOverrideConfigurationChanged();
+        }
+    }
+
+    /**
+     * Must be called when new parent for the container was set.
+     */
+    void onParentChanged() {
+        final ConfigurationContainer parent = getParent();
+        // Update full configuration of this container and all its children.
+        onConfigurationChanged(parent != null ? parent.mFullConfiguration : Configuration.EMPTY);
+        // Update merged override configuration of this container and all its children.
+        onMergedOverrideConfigurationChanged();
+    }
+
+    abstract protected int getChildCount();
+
+    abstract protected E getChildAt(int index);
+
+    abstract protected ConfigurationContainer getParent();
+}
diff --git a/services/core/java/com/android/server/am/ProcessRecord.java b/services/core/java/com/android/server/am/ProcessRecord.java
index 3fffefb..49fe79c 100644
--- a/services/core/java/com/android/server/am/ProcessRecord.java
+++ b/services/core/java/com/android/server/am/ProcessRecord.java
@@ -143,7 +143,7 @@
     Bundle instrumentationArguments;// as given to us
     ComponentName instrumentationResultClass;// copy of instrumentationClass
     boolean usingWrapper;       // Set to true when process was launched with a wrapper attached
-    BroadcastRecord curReceiver;// receiver currently running in the app
+    final ArraySet<BroadcastRecord> curReceivers = new ArraySet<BroadcastRecord>();// receivers currently running in the app
     long lastWakeTime;          // How long proc held wake lock at last check
     long lastCpuTime;           // How long proc has run CPU at last check
     long curCpuTime;            // How long proc has run CPU most recently
@@ -427,8 +427,11 @@
                 pw.print(prefix); pw.print("  - "); pw.println(conProviders.get(i).toShortString());
             }
         }
-        if (curReceiver != null) {
-            pw.print(prefix); pw.print("curReceiver="); pw.println(curReceiver);
+        if (!curReceivers.isEmpty()) {
+            pw.print(prefix); pw.println("Current Receivers:");
+            for (int i=0; i < curReceivers.size(); i++) {
+                pw.print(prefix); pw.print("  - "); pw.println(curReceivers.valueAt(i));
+            }
         }
         if (receivers.size() > 0) {
             pw.print(prefix); pw.println("Receivers:");
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 4d7c4d3..77d0db3 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -56,6 +56,8 @@
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 import java.util.Objects;
 
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
@@ -67,15 +69,13 @@
 import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
 import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
 import static android.content.pm.ActivityInfo.FLAG_ON_TOP_LAUNCHER;
+import static android.content.pm.ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
 import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
 import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_DEFAULT;
 import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_IF_WHITELISTED;
 import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_NEVER;
-import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
 import static android.content.pm.ActivityInfo.RESIZE_MODE_FORCE_RESIZEABLE;
 import static android.content.pm.ApplicationInfo.PRIVATE_FLAG_PRIVILEGED;
-import static android.content.res.Configuration.SCREENLAYOUT_LONG_MASK;
-import static android.content.res.Configuration.SCREENLAYOUT_SIZE_MASK;
 import static android.provider.Settings.Secure.USER_SETUP_COMPLETE;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_ADD_REMOVE;
 import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_LOCKTASK;
@@ -93,18 +93,18 @@
 import static com.android.server.am.ActivityRecord.RECENTS_ACTIVITY_TYPE;
 import static com.android.server.am.ActivityRecord.STARTING_WINDOW_SHOWN;
 
-final class TaskRecord {
+final class TaskRecord extends ConfigurationContainer {
     private static final String TAG = TAG_WITH_CLASS_NAME ? "TaskRecord" : TAG_AM;
     private static final String TAG_ADD_REMOVE = TAG + POSTFIX_ADD_REMOVE;
     private static final String TAG_RECENTS = TAG + POSTFIX_RECENTS;
     private static final String TAG_LOCKTASK = TAG + POSTFIX_LOCKTASK;
     private static final String TAG_TASKS = TAG + POSTFIX_TASKS;
 
-    static final String ATTR_TASKID = "task_id";
+    private static final String ATTR_TASKID = "task_id";
     private static final String TAG_INTENT = "intent";
     private static final String TAG_AFFINITYINTENT = "affinity_intent";
-    static final String ATTR_REALACTIVITY = "real_activity";
-    static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
+    private static final String ATTR_REALACTIVITY = "real_activity";
+    private static final String ATTR_REALACTIVITY_SUSPENDED = "real_activity_suspended";
     private static final String ATTR_ORIGACTIVITY = "orig_activity";
     private static final String TAG_ACTIVITY = "activity";
     private static final String ATTR_AFFINITY = "affinity";
@@ -121,7 +121,7 @@
     private static final String ATTR_LASTDESCRIPTION = "last_description";
     private static final String ATTR_LASTTIMEMOVED = "last_time_moved";
     private static final String ATTR_NEVERRELINQUISH = "never_relinquish_identity";
-    static final String ATTR_TASK_AFFILIATION = "task_affiliation";
+    private static final String ATTR_TASK_AFFILIATION = "task_affiliation";
     private static final String ATTR_PREV_AFFILIATION = "prev_affiliation";
     private static final String ATTR_NEXT_AFFILIATION = "next_affiliation";
     private static final String ATTR_TASK_AFFILIATION_COLOR = "task_affiliation_color";
@@ -137,7 +137,7 @@
     private static final String TASK_THUMBNAIL_SUFFIX = "_task_thumbnail";
 
     static final int INVALID_TASK_ID = -1;
-    static final int INVALID_MIN_SIZE = -1;
+    private static final int INVALID_MIN_SIZE = -1;
 
     final int taskId;       // Unique identifier for this task.
     String affinity;        // The affinity name for this task, or null; may change identity.
@@ -173,8 +173,8 @@
                             // Based on the {@link ActivityInfo#resizeMode} of the root activity.
     boolean mTemporarilyUnresizable; // Separate flag from mResizeMode used to suppress resize
                                      // changes on a temporary basis.
-    int mLockTaskMode;      // Which tasklock mode to launch this task in. One of
-                            // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
+    private int mLockTaskMode;  // Which tasklock mode to launch this task in. One of
+                                // ActivityManager.LOCK_TASK_LAUNCH_MODE_*
     private boolean mPrivileged;    // The root activity application of this task holds
                                     // privileged permissions.
     private boolean mIsOnTopLauncher; // Whether this task is an on-top launcher. See
@@ -223,7 +223,7 @@
     private int mTaskToReturnTo = APPLICATION_ACTIVITY_TYPE;
 
     /** If original intent did not allow relinquishing task identity, save that information */
-    boolean mNeverRelinquishIdentity = true;
+    private boolean mNeverRelinquishIdentity = true;
 
     // Used in the unique case where we are clearing the task in order to reuse it. In that case we
     // do not want to delete the stack when the task goes empty.
@@ -271,8 +271,8 @@
     // This number will be assigned when we evaluate OOM scores for all visible tasks.
     int mLayerRank = -1;
 
-    /** Contains configurations settings that are different from the parent's configuration. */
-    Configuration mOverrideConfig = Configuration.EMPTY;
+    /** Helper object used for updating override configuration. */
+    private Configuration mTmpConfig = new Configuration();
 
     TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
             IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
@@ -402,7 +402,7 @@
     private void setIntent(Intent _intent, ActivityInfo info) {
         if (intent == null) {
             mNeverRelinquishIdentity =
-                    (info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0;
+                    (info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0;
         } else if (mNeverRelinquishIdentity) {
             return;
         }
@@ -531,8 +531,10 @@
         return mStack;
     }
 
+    /** Must be used for setting parent stack because it performs configuration updates. */
     void setStack(ActivityStack stack) {
         mStack = stack;
+        onParentChanged();
     }
 
     /**
@@ -542,6 +544,21 @@
         return mStack != null ? mStack.mStackId : INVALID_STACK_ID;
     }
 
+    @Override
+    protected int getChildCount() {
+        return 0;
+    }
+
+    @Override
+    protected ConfigurationContainer getChildAt(int index) {
+        return null;
+    }
+
+    @Override
+    protected ConfigurationContainer getParent() {
+        return mStack;
+    }
+
     // Close up recents linked list.
     void closeRecentsChain() {
         if (mPrevAffiliate != null) {
@@ -591,7 +608,6 @@
      * @return whether the thumbnail was set
      */
     boolean setLastThumbnailLocked(Bitmap thumbnail) {
-        final Configuration serviceConfig = mService.mGlobalConfiguration;
         int taskWidth = 0;
         int taskHeight = 0;
         if (mBounds != null) {
@@ -607,7 +623,11 @@
         } else {
             Slog.e(TAG, "setLastThumbnailLocked() called on Task without stack");
         }
-        return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, serviceConfig.orientation);
+        // We need to provide the current orientation of the display on which this task resides,
+        // not the orientation of the task.
+        final int orientation =
+                getStack().mActivityContainer.mActivityDisplay.getConfiguration().orientation;
+        return setLastThumbnailLocked(thumbnail, taskWidth, taskHeight, orientation);
     }
 
     /**
@@ -954,11 +974,11 @@
         return null;
     }
 
-    public TaskThumbnail getTaskThumbnailLocked() {
+    TaskThumbnail getTaskThumbnailLocked() {
         if (mStack != null) {
             final ActivityRecord resumedActivity = mStack.mResumedActivity;
             if (resumedActivity != null && resumedActivity.task == this) {
-                final Bitmap thumbnail = mStack.screenshotActivitiesLocked(resumedActivity);
+                final Bitmap thumbnail = resumedActivity.screenshotActivityLocked();
                 setLastThumbnailLocked(thumbnail);
             }
         }
@@ -967,7 +987,7 @@
         return taskThumbnail;
     }
 
-    public void removeTaskActivitiesLocked() {
+    void removeTaskActivitiesLocked() {
         // Just remove the entire task.
         performClearTaskAtIndexLocked(0);
     }
@@ -1047,20 +1067,16 @@
     }
 
     boolean isResizeable() {
-        return !isHomeTask() && (mService.mForceResizableActivities
-                || ActivityInfo.isResizeableMode(mResizeMode)) && !mTemporarilyUnresizable;
+        return (mService.mForceResizableActivities || ActivityInfo.isResizeableMode(mResizeMode))
+                && !mTemporarilyUnresizable;
     }
 
     boolean isOnTopLauncher() {
         return isHomeTask() && mIsOnTopLauncher;
     }
 
-    boolean inCropWindowsResizeMode() {
-        return !isResizeable() && mResizeMode == RESIZE_MODE_CROP_WINDOWS;
-    }
-
     boolean canGoInDockedStack() {
-        return isResizeable() || inCropWindowsResizeMode();
+        return isResizeable();
     }
 
     /**
@@ -1087,12 +1103,12 @@
         // utility activities.
         int activityNdx;
         final int numActivities = mActivities.size();
-        final boolean relinquish = numActivities == 0 ? false :
-                (mActivities.get(0).info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) != 0;
+        final boolean relinquish = numActivities != 0 &&
+                (mActivities.get(0).info.flags & FLAG_RELINQUISH_TASK_IDENTITY) != 0;
         for (activityNdx = Math.min(numActivities, 1); activityNdx < numActivities;
                 ++activityNdx) {
             final ActivityRecord r = mActivities.get(activityNdx);
-            if (relinquish && (r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
+            if (relinquish && (r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
                 // This will be the top activity for determining taskDescription. Pre-inc to
                 // overcome initial decrement below.
                 ++activityNdx;
@@ -1147,7 +1163,7 @@
                 continue;
             }
             effectiveNdx = activityNdx;
-            if ((r.info.flags & ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
+            if ((r.info.flags & FLAG_RELINQUISH_TASK_IDENTITY) == 0) {
                 break;
             }
         }
@@ -1342,8 +1358,6 @@
                 callingPackage = attrValue;
             } else if (ATTR_RESIZE_MODE.equals(attrName)) {
                 resizeMode = Integer.parseInt(attrValue);
-                resizeMode = (resizeMode == RESIZE_MODE_CROP_WINDOWS)
-                        ? RESIZE_MODE_FORCE_RESIZEABLE : resizeMode;
             } else if (ATTR_PRIVILEGED.equals(attrName)) {
                 privileged = Boolean.parseBoolean(attrValue);
             } else if (ATTR_NON_FULLSCREEN_BOUNDS.equals(attrName)) {
@@ -1487,8 +1501,9 @@
         if (Objects.equals(mBounds, bounds)) {
             return false;
         }
-        final Configuration oldConfig = mOverrideConfig;
+        mTmpConfig.setTo(getOverrideConfiguration());
         final boolean oldFullscreen = mFullscreen;
+        final Configuration newConfig = getOverrideConfiguration();
 
         mFullscreen = bounds == null;
         if (mFullscreen) {
@@ -1496,7 +1511,7 @@
                 mLastNonFullscreenBounds = mBounds;
             }
             mBounds = null;
-            mOverrideConfig = Configuration.EMPTY;
+            newConfig.unset();
         } else {
             mTmpRect.set(bounds);
             adjustForMinimalTaskDimensions(mTmpRect);
@@ -1508,15 +1523,16 @@
             if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
                 mLastNonFullscreenBounds = mBounds;
             }
-            mOverrideConfig = calculateOverrideConfig(mTmpRect, insetBounds,
+            calculateOverrideConfig(newConfig, mTmpRect, insetBounds,
                     mTmpRect.right != bounds.right, mTmpRect.bottom != bounds.bottom);
         }
+        onOverrideConfigurationChanged(newConfig);
 
         if (mFullscreen != oldFullscreen) {
             mService.mStackSupervisor.scheduleReportMultiWindowModeChanged(this);
         }
 
-        return !mOverrideConfig.equals(oldConfig);
+        return !mTmpConfig.equals(newConfig);
     }
 
     private void subtractNonDecorInsets(Rect inOutBounds, Rect inInsetBounds,
@@ -1541,8 +1557,9 @@
         inOutBounds.inset(leftInset, topInset, rightInset, bottomInset);
     }
 
-    private Configuration calculateOverrideConfig(Rect bounds, Rect insetBounds,
-                                                  boolean overrideWidth, boolean overrideHeight) {
+    /** Clears passed config and fills it with new override values. */
+    private void calculateOverrideConfig(Configuration config, Rect bounds, Rect insetBounds,
+            boolean overrideWidth, boolean overrideHeight) {
         mTmpNonDecorBounds.set(bounds);
         mTmpStableBounds.set(bounds);
         subtractNonDecorInsets(
@@ -1552,16 +1569,16 @@
                 mTmpStableBounds, insetBounds != null ? insetBounds : bounds,
                 overrideWidth, overrideHeight);
 
-        // For calculating screenWidthDp, screenWidthDp, we use the stable inset screen area,
+        // For calculating screenWidthDp, screenHeightDp, we use the stable inset screen area,
         // i.e. the screen area without the system bars.
-        final Configuration serviceConfig = mService.mGlobalConfiguration;
-        final Configuration config = new Configuration(Configuration.EMPTY);
-        // TODO(multidisplay): Update Dp to that of display stack is on.
-        final float density = serviceConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
+        // Additionally task dimensions should not be bigger than its parents dimensions.
+        final Configuration parentConfig = getParent().getConfiguration();
+        config.unset();
+        final float density = parentConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
         config.screenWidthDp =
-                Math.min((int)(mTmpStableBounds.width() / density), serviceConfig.screenWidthDp);
+                Math.min((int)(mTmpStableBounds.width() / density), parentConfig.screenWidthDp);
         config.screenHeightDp =
-                Math.min((int)(mTmpStableBounds.height() / density), serviceConfig.screenHeightDp);
+                Math.min((int)(mTmpStableBounds.height() / density), parentConfig.screenHeightDp);
 
         // TODO: Orientation?
         config.orientation = (config.screenWidthDp <= config.screenHeightDp)
@@ -1573,14 +1590,15 @@
         // never go away in Honeycomb.
         final int compatScreenWidthDp = (int)(mTmpNonDecorBounds.width() / density);
         final int compatScreenHeightDp = (int)(mTmpNonDecorBounds.height() / density);
-        final int sl = Configuration.resetScreenLayout(serviceConfig.screenLayout);
+        // We're only overriding LONG, SIZE and COMPAT parts of screenLayout, so we start override
+        // calculation with partial default.
+        final int sl = Configuration.SCREENLAYOUT_LONG_YES | Configuration.SCREENLAYOUT_SIZE_XLARGE;
         final int longSize = Math.max(compatScreenHeightDp, compatScreenWidthDp);
-        final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);;
+        final int shortSize = Math.min(compatScreenHeightDp, compatScreenWidthDp);
         config.screenLayout = Configuration.reduceScreenLayout(sl, longSize, shortSize);
 
         config.smallestScreenWidthDp = mService.mWindowManager.getSmallestWidthForTaskBounds(
                 insetBounds != null ? insetBounds : bounds);
-        return config;
     }
 
     /**
@@ -1589,12 +1607,14 @@
      * {@param config}.
      */
     Configuration extractOverrideConfig(Configuration config) {
-        final Configuration extracted = new Configuration(Configuration.EMPTY);
+        final Configuration extracted = new Configuration();
         extracted.screenWidthDp = config.screenWidthDp;
         extracted.screenHeightDp = config.screenHeightDp;
         extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
         extracted.orientation = config.orientation;
-        extracted.screenLayout = config.screenLayout;
+        // We're only overriding LONG, SIZE and COMPAT parts of screenLayout.
+        extracted.screenLayout = config.screenLayout & (Configuration.SCREENLAYOUT_LONG_MASK
+                | Configuration.SCREENLAYOUT_SIZE_MASK | Configuration.SCREENLAYOUT_COMPAT_NEEDED);
         return extracted;
     }
 
@@ -1607,29 +1627,6 @@
         return bounds;
     }
 
-    /**
-     * Update fields that are not overridden for task from global configuration.
-     *
-     * @param globalConfig global configuration to update from.
-     */
-    void sanitizeOverrideConfiguration(Configuration globalConfig) {
-        // If it's fullscreen, the override config should be empty and we should leave it alone.
-        if (mFullscreen) {
-            return;
-        }
-
-        // screenLayout field is set in #calculateOverrideConfig but only part of it is really
-        // overridden - aspect ratio and size. Other flags (like layout direction) can be updated
-        // separately in global config and they also must be updated in override config.
-        int overrideScreenLayout = mOverrideConfig.screenLayout;
-        int newScreenLayout = globalConfig.screenLayout;
-        newScreenLayout = (newScreenLayout & ~SCREENLAYOUT_LONG_MASK)
-                | (overrideScreenLayout & SCREENLAYOUT_LONG_MASK);
-        newScreenLayout = (newScreenLayout & ~SCREENLAYOUT_SIZE_MASK)
-                | (overrideScreenLayout & SCREENLAYOUT_SIZE_MASK);
-        mOverrideConfig.screenLayout = newScreenLayout;
-    }
-
     static Rect validateBounds(Rect bounds) {
         if (bounds != null && bounds.isEmpty()) {
             Slog.wtf(TAG, "Received strange task bounds: " + bounds, new Throwable());
diff --git a/services/core/java/com/android/server/connectivity/NetdEventListenerService.java b/services/core/java/com/android/server/connectivity/NetdEventListenerService.java
index e7198d3..363d7cb 100644
--- a/services/core/java/com/android/server/connectivity/NetdEventListenerService.java
+++ b/services/core/java/com/android/server/connectivity/NetdEventListenerService.java
@@ -134,7 +134,9 @@
 
     @Override
     // Called concurrently by multiple binder threads.
-    public synchronized void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs) {
+    // This method must not block or perform long-running operations.
+    public synchronized void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs,
+            String hostname, String[] ipAddresses, int ipAddressesCount, int uid) {
         maybeVerboseLog(String.format("onDnsEvent(%d, %d, %d, %d)",
                 netId, eventType, returnCode, latencyMs));
 
@@ -146,6 +148,14 @@
         batch.addResult((byte) eventType, (byte) returnCode, latencyMs);
     }
 
+    @Override
+    // Called concurrently by multiple binder threads.
+    // This method must not block or perform long-running operations.
+    public synchronized void onConnectEvent(int netId, int latencyMs, String ipAddr, int port,
+            int uid) {
+        maybeVerboseLog(String.format("onConnectEvent(%d, %d)", netId, latencyMs));
+    }
+
     public synchronized void dump(PrintWriter writer) {
         IndentingPrintWriter pw = new IndentingPrintWriter(writer, "  ");
         pw.println(TAG + ":");
diff --git a/services/core/java/com/android/server/connectivity/Tethering.java b/services/core/java/com/android/server/connectivity/Tethering.java
index da9c547..921fd23 100644
--- a/services/core/java/com/android/server/connectivity/Tethering.java
+++ b/services/core/java/com/android/server/connectivity/Tethering.java
@@ -897,7 +897,7 @@
                     }
                 } else {
                     mUsbTetherRequested = true;
-                    usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS);
+                    usbManager.setCurrentFunction(UsbManager.USB_FUNCTION_RNDIS, false);
                 }
             } else {
                 final long ident = Binder.clearCallingIdentity();
@@ -907,7 +907,7 @@
                     Binder.restoreCallingIdentity(ident);
                 }
                 if (mRndisEnabled) {
-                    usbManager.setCurrentFunction(null);
+                    usbManager.setCurrentFunction(null, false);
                 }
                 mUsbTetherRequested = false;
             }
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index ede3bda..afc6247 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -27,6 +27,8 @@
 import android.annotation.UserIdInt;
 import android.app.AppGlobals;
 import android.app.AppOpsManager;
+import android.app.Notification;
+import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
@@ -76,6 +78,7 @@
 import android.util.ArraySet;
 import android.util.Log;
 
+import com.android.internal.R;
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.net.LegacyVpnInfo;
@@ -241,12 +244,14 @@
     /**
      * Update current state, dispaching event to listeners.
      */
-    private void updateState(DetailedState detailedState, String reason) {
+    @VisibleForTesting
+    protected void updateState(DetailedState detailedState, String reason) {
         if (LOGD) Log.d(TAG, "setting state=" + detailedState + ", reason=" + reason);
         mNetworkInfo.setDetailedState(detailedState, reason, null);
         if (mNetworkAgent != null) {
             mNetworkAgent.sendNetworkInfo(mNetworkInfo);
         }
+        updateAlwaysOnNotification(detailedState);
     }
 
     /**
@@ -280,7 +285,10 @@
         }
 
         mLockdown = (mAlwaysOn && lockdown);
-        if (!isCurrentPreparedPackage(packageName)) {
+        if (isCurrentPreparedPackage(packageName)) {
+            updateAlwaysOnNotification(mNetworkInfo.getDetailedState());
+        } else {
+            // Prepare this app. The notification will update as a side-effect of updateState().
             prepareInternal(packageName);
         }
         maybeRegisterPackageChangeReceiverLocked(packageName);
@@ -682,22 +690,19 @@
         }
     }
 
-    private void agentDisconnect(NetworkInfo networkInfo, NetworkAgent networkAgent) {
-        networkInfo.setIsAvailable(false);
-        networkInfo.setDetailedState(DetailedState.DISCONNECTED, null, null);
+    private void agentDisconnect(NetworkAgent networkAgent) {
         if (networkAgent != null) {
+            NetworkInfo networkInfo = new NetworkInfo(mNetworkInfo);
+            networkInfo.setIsAvailable(false);
+            networkInfo.setDetailedState(DetailedState.DISCONNECTED, null, null);
             networkAgent.sendNetworkInfo(networkInfo);
         }
     }
 
-    private void agentDisconnect(NetworkAgent networkAgent) {
-        NetworkInfo networkInfo = new NetworkInfo(mNetworkInfo);
-        agentDisconnect(networkInfo, networkAgent);
-    }
-
     private void agentDisconnect() {
         if (mNetworkInfo.isConnected()) {
-            agentDisconnect(mNetworkInfo, mNetworkAgent);
+            mNetworkInfo.setIsAvailable(false);
+            updateState(DetailedState.DISCONNECTED, "agentDisconnect");
             mNetworkAgent = null;
         }
     }
@@ -1250,6 +1255,43 @@
         }
     }
 
+    private void updateAlwaysOnNotification(DetailedState networkState) {
+        final boolean visible = (mAlwaysOn && networkState != DetailedState.CONNECTED);
+        updateAlwaysOnNotificationInternal(visible);
+    }
+
+    @VisibleForTesting
+    protected void updateAlwaysOnNotificationInternal(boolean visible) {
+        final UserHandle user = UserHandle.of(mUserHandle);
+        final long token = Binder.clearCallingIdentity();
+        try {
+            final NotificationManager notificationManager = NotificationManager.from(mContext);
+            if (!visible) {
+                notificationManager.cancelAsUser(TAG, 0, user);
+                return;
+            }
+            final Intent intent = new Intent(Settings.ACTION_VPN_SETTINGS);
+            final PendingIntent configIntent = PendingIntent.getActivityAsUser(
+                    mContext, /* request */ 0, intent,
+                    PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT,
+                    null, user);
+            final Notification.Builder builder = new Notification.Builder(mContext)
+                    .setDefaults(0)
+                    .setSmallIcon(R.drawable.vpn_connected)
+                    .setContentTitle(mContext.getString(R.string.vpn_lockdown_disconnected))
+                    .setContentText(mContext.getString(R.string.vpn_lockdown_config))
+                    .setContentIntent(configIntent)
+                    .setCategory(Notification.CATEGORY_SYSTEM)
+                    .setPriority(Notification.PRIORITY_LOW)
+                    .setVisibility(Notification.VISIBILITY_PUBLIC)
+                    .setOngoing(true)
+                    .setColor(mContext.getColor(R.color.system_notification_accent_color));
+            notificationManager.notifyAsUser(TAG, 0, builder.build(), user);
+        } finally {
+            Binder.restoreCallingIdentity(token);
+        }
+    }
+
     private native int jniCreate(int mtu);
     private native String jniGetName(int tun);
     private native int jniSetAddresses(String interfaze, String addresses);
diff --git a/services/core/java/com/android/server/content/SyncManager.java b/services/core/java/com/android/server/content/SyncManager.java
index 2d6bef4..72feab7 100644
--- a/services/core/java/com/android/server/content/SyncManager.java
+++ b/services/core/java/com/android/server/content/SyncManager.java
@@ -795,7 +795,17 @@
      *           Use {@link AuthorityInfo#UNDEFINED} to sync all authorities.
      */
     public void scheduleSync(Account requestedAccount, int userId, int reason,
-            String requestedAuthority, Bundle extras, int targetSyncState) {
+                             String requestedAuthority, Bundle extras, int targetSyncState) {
+        scheduleSync(requestedAccount, userId, reason, requestedAuthority, extras, targetSyncState,
+                0 /* min delay */);
+    }
+
+    /**
+     * @param minDelayMillis The sync can't land before this delay expires.
+     */
+    private void scheduleSync(Account requestedAccount, int userId, int reason,
+                             String requestedAuthority, Bundle extras, int targetSyncState,
+                             final long minDelayMillis) {
         final boolean isLoggable = Log.isLoggable(TAG, Log.VERBOSE);
         if (extras == null) {
             extras = new Bundle();
@@ -906,7 +916,7 @@
                                 if (result != null
                                         && result.getBoolean(AccountManager.KEY_BOOLEAN_RESULT)) {
                                     scheduleSync(account.account, userId, reason, authority,
-                                            finalExtras, targetSyncState);
+                                            finalExtras, targetSyncState, minDelayMillis);
                                 }
                             }
                         ));
@@ -967,7 +977,8 @@
                     postScheduleSyncMessage(
                             new SyncOperation(account.account, account.userId,
                                     owningUid, owningPackage, reason, source,
-                                    authority, newExtras, allowParallelSyncs)
+                                    authority, newExtras, allowParallelSyncs),
+                            minDelayMillis
                     );
                 } else if (targetSyncState == AuthorityInfo.UNDEFINED
                         || targetSyncState == isSyncable) {
@@ -982,7 +993,8 @@
                     postScheduleSyncMessage(
                             new SyncOperation(account.account, account.userId,
                                     owningUid, owningPackage, reason, source,
-                                    authority, extras, allowParallelSyncs)
+                                    authority, extras, allowParallelSyncs),
+                            minDelayMillis
                     );
                 }
             }
@@ -1088,14 +1100,14 @@
     }
 
     /**
-     * Schedule sync based on local changes to a provider. Occurs within interval
-     * [LOCAL_SYNC_DELAY, 2*LOCAL_SYNC_DELAY].
+     * Schedule sync based on local changes to a provider. We wait for at least LOCAL_SYNC_DELAY
+     * ms to batch syncs.
      */
     public void scheduleLocalSync(Account account, int userId, int reason, String authority) {
         final Bundle extras = new Bundle();
         extras.putBoolean(ContentResolver.SYNC_EXTRAS_UPLOAD, true);
         scheduleSync(account, userId, reason, authority, extras,
-                AuthorityInfo.UNDEFINED);
+                AuthorityInfo.UNDEFINED, LOCAL_SYNC_DELAY);
     }
 
     public SyncAdapterType[] getSyncAdapterTypes(int userId) {
@@ -1152,9 +1164,10 @@
         mSyncHandler.sendMessageDelayed(monitorMessage, SYNC_MONITOR_WINDOW_LENGTH_MILLIS);
     }
 
-    private void postScheduleSyncMessage(SyncOperation syncOperation) {
-        mSyncHandler.obtainMessage(mSyncHandler.MESSAGE_SCHEDULE_SYNC, syncOperation)
-                .sendToTarget();
+    private void postScheduleSyncMessage(SyncOperation syncOperation, long minDelayMillis) {
+        ScheduleSyncMessagePayload payload =
+                new ScheduleSyncMessagePayload(syncOperation, minDelayMillis);
+        mSyncHandler.obtainMessage(mSyncHandler.MESSAGE_SCHEDULE_SYNC, payload).sendToTarget();
     }
 
     /**
@@ -1194,6 +1207,16 @@
         }
     }
 
+    private static class ScheduleSyncMessagePayload {
+        final SyncOperation syncOperation;
+        final long minDelayMillis;
+
+        ScheduleSyncMessagePayload(SyncOperation syncOperation, long minDelayMillis) {
+            this.syncOperation = syncOperation;
+            this.minDelayMillis = minDelayMillis;
+        }
+    }
+
     private void clearBackoffSetting(EndPoint target) {
         Pair<Long, Long> backoff = mSyncStorageEngine.getBackoff(target);
         if (backoff != null && backoff.first == SyncStorageEngine.NOT_IN_BACKOFF_MODE &&
@@ -1262,7 +1285,7 @@
             if (!op.isPeriodic && op.target.matchesSpec(target)) {
                 count++;
                 getJobScheduler().cancel(op.jobId);
-                postScheduleSyncMessage(op);
+                postScheduleSyncMessage(op, 0 /* min delay */);
             }
         }
         if (Log.isLoggable(TAG, Log.VERBOSE)) {
@@ -2417,8 +2440,10 @@
                 mDataConnectionIsConnected = readDataConnectionState();
                 switch (msg.what) {
                     case MESSAGE_SCHEDULE_SYNC:
-                        SyncOperation op = (SyncOperation) msg.obj;
-                        scheduleSyncOperationH(op);
+                        ScheduleSyncMessagePayload syncPayload =
+                                (ScheduleSyncMessagePayload) msg.obj;
+                        SyncOperation op = syncPayload.syncOperation;
+                        scheduleSyncOperationH(op, syncPayload.minDelayMillis);
                         break;
 
                     case MESSAGE_START_SYNC:
@@ -3101,7 +3126,8 @@
                         maybeRescheduleSync(syncResult, syncOperation);
                     } else {
                         // create a normal sync instance that will respect adapter backoffs
-                        postScheduleSyncMessage(syncOperation.createOneTimeSyncOperation());
+                        postScheduleSyncMessage(syncOperation.createOneTimeSyncOperation(),
+                                0 /* min delay */);
                     }
                     historyMessage = ContentResolver.syncErrorToString(
                             syncResultToErrorNumber(syncResult));
diff --git a/services/core/java/com/android/server/emergency/EmergencyAffordanceService.java b/services/core/java/com/android/server/emergency/EmergencyAffordanceService.java
index cca9f10..353f450 100644
--- a/services/core/java/com/android/server/emergency/EmergencyAffordanceService.java
+++ b/services/core/java/com/android/server/emergency/EmergencyAffordanceService.java
@@ -99,6 +99,7 @@
     };
     private boolean mSimNeedsEmergencyAffordance;
     private boolean mNetworkNeedsEmergencyAffordance;
+    private boolean mVoiceCapable;
 
     private void requestCellScan() {
         mHandler.obtainMessage(CELL_INFO_STATE_CHANGED).sendToTarget();
@@ -125,8 +126,8 @@
 
     private void updateEmergencyAffordanceNeeded() {
         synchronized (mLock) {
-            mEmergencyAffordanceNeeded = mSimNeedsEmergencyAffordance ||
-                    mNetworkNeedsEmergencyAffordance;
+            mEmergencyAffordanceNeeded = mVoiceCapable && (mSimNeedsEmergencyAffordance ||
+                    mNetworkNeedsEmergencyAffordance);
             Settings.Global.putInt(mContext.getContentResolver(),
                     Settings.Global.EMERGENCY_AFFORDANCE_NEEDED,
                     mEmergencyAffordanceNeeded ? 1 : 0);
@@ -157,6 +158,11 @@
     public void onBootPhase(int phase) {
         if (phase == PHASE_THIRD_PARTY_APPS_CAN_START) {
             mTelephonyManager = mContext.getSystemService(TelephonyManager.class);
+            mVoiceCapable = mTelephonyManager.isVoiceCapable();
+            if (!mVoiceCapable) {
+                updateEmergencyAffordanceNeeded();
+                return;
+            }
             mSubscriptionManager = SubscriptionManager.from(mContext);
             HandlerThread thread = new HandlerThread(TAG);
             thread.start();
diff --git a/services/core/java/com/android/server/hdmi/HdmiControlService.java b/services/core/java/com/android/server/hdmi/HdmiControlService.java
index 5dc9d02..72ee218 100644
--- a/services/core/java/com/android/server/hdmi/HdmiControlService.java
+++ b/services/core/java/com/android/server/hdmi/HdmiControlService.java
@@ -2011,6 +2011,9 @@
     @ServiceThreadOnly
     void standby() {
         assertRunOnServiceThread();
+        if (!canGoToStandby()) {
+            return;
+        }
         mStandbyMessageReceived = true;
         mPowerManager.goToSleep(SystemClock.uptimeMillis(), PowerManager.GO_TO_SLEEP_REASON_HDMI, 0);
         // PowerManger will send the broadcast Intent.ACTION_SCREEN_OFF and after this gets
@@ -2038,10 +2041,13 @@
     @ServiceThreadOnly
     private void onStandby(final int standbyAction) {
         assertRunOnServiceThread();
-        if (!canGoToStandby()) return;
         mPowerStatus = HdmiControlManager.POWER_STATUS_TRANSIENT_TO_STANDBY;
         invokeVendorCommandListenersOnControlStateChanged(false,
                 HdmiControlManager.CONTROL_STATE_CHANGED_REASON_STANDBY);
+        if (!canGoToStandby()) {
+            mPowerStatus = HdmiControlManager.POWER_STATUS_STANDBY;
+            return;
+        }
 
         final List<HdmiCecLocalDevice> devices = getAllLocalDevices();
         disableDevices(new PendingActionClearedCallback() {
diff --git a/services/core/java/com/android/server/lights/Light.java b/services/core/java/com/android/server/lights/Light.java
index b18a181..0bab86b 100644
--- a/services/core/java/com/android/server/lights/Light.java
+++ b/services/core/java/com/android/server/lights/Light.java
@@ -16,25 +16,28 @@
 
 package com.android.server.lights;
 
+import android.hardware.light.V2_0.Flash;
+import android.hardware.light.V2_0.Brightness;
+
 public abstract class Light {
-    public static final int LIGHT_FLASH_NONE = 0;
-    public static final int LIGHT_FLASH_TIMED = 1;
-    public static final int LIGHT_FLASH_HARDWARE = 2;
+    public static final int LIGHT_FLASH_NONE = Flash.NONE;
+    public static final int LIGHT_FLASH_TIMED = Flash.TIMED;
+    public static final int LIGHT_FLASH_HARDWARE = Flash.HARDWARE;
 
     /**
      * Light brightness is managed by a user setting.
      */
-    public static final int BRIGHTNESS_MODE_USER = 0;
+    public static final int BRIGHTNESS_MODE_USER = Brightness.USER;
 
     /**
      * Light brightness is managed by a light sensor.
      */
-    public static final int BRIGHTNESS_MODE_SENSOR = 1;
+    public static final int BRIGHTNESS_MODE_SENSOR = Brightness.SENSOR;
 
     /**
      * Low-persistence light mode.
      */
-    public static final int BRIGHTNESS_MODE_LOW_PERSISTENCE = 2;
+    public static final int BRIGHTNESS_MODE_LOW_PERSISTENCE = Brightness.LOW_PERSISTENCE;
 
     public abstract void setBrightness(int brightness);
     public abstract void setBrightness(int brightness, int brightnessMode);
diff --git a/services/core/java/com/android/server/lights/LightsManager.java b/services/core/java/com/android/server/lights/LightsManager.java
index 2f20509..be20a44 100644
--- a/services/core/java/com/android/server/lights/LightsManager.java
+++ b/services/core/java/com/android/server/lights/LightsManager.java
@@ -16,16 +16,18 @@
 
 package com.android.server.lights;
 
+import android.hardware.light.V2_0.Type;
+
 public abstract class LightsManager {
-    public static final int LIGHT_ID_BACKLIGHT = 0;
-    public static final int LIGHT_ID_KEYBOARD = 1;
-    public static final int LIGHT_ID_BUTTONS = 2;
-    public static final int LIGHT_ID_BATTERY = 3;
-    public static final int LIGHT_ID_NOTIFICATIONS = 4;
-    public static final int LIGHT_ID_ATTENTION = 5;
-    public static final int LIGHT_ID_BLUETOOTH = 6;
-    public static final int LIGHT_ID_WIFI = 7;
-    public static final int LIGHT_ID_COUNT = 8;
+    public static final int LIGHT_ID_BACKLIGHT = Type.BACKLIGHT;
+    public static final int LIGHT_ID_KEYBOARD = Type.KEYBOARD;
+    public static final int LIGHT_ID_BUTTONS = Type.BUTTONS;
+    public static final int LIGHT_ID_BATTERY = Type.BATTERY;
+    public static final int LIGHT_ID_NOTIFICATIONS = Type.NOTIFICATIONS;
+    public static final int LIGHT_ID_ATTENTION = Type.ATTENTION;
+    public static final int LIGHT_ID_BLUETOOTH = Type.BLUETOOTH;
+    public static final int LIGHT_ID_WIFI = Type.WIFI;
+    public static final int LIGHT_ID_COUNT = Type.COUNT;
 
     public abstract Light getLight(int id);
 }
diff --git a/services/core/java/com/android/server/lights/LightsService.java b/services/core/java/com/android/server/lights/LightsService.java
index ca64817..bba0a50 100644
--- a/services/core/java/com/android/server/lights/LightsService.java
+++ b/services/core/java/com/android/server/lights/LightsService.java
@@ -133,7 +133,7 @@
                 Trace.traceBegin(Trace.TRACE_TAG_POWER, "setLight(" + mId + ", 0x"
                         + Integer.toHexString(color) + ")");
                 try {
-                    setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode);
+                    setLight_native(mId, color, mode, onMS, offMS, brightnessMode);
                 } finally {
                     Trace.traceEnd(Trace.TRACE_TAG_POWER);
                 }
@@ -155,8 +155,6 @@
     public LightsService(Context context) {
         super(context);
 
-        mNativePointer = init_native();
-
         for (int i = 0; i < LightsManager.LIGHT_ID_COUNT; i++) {
             mLights[i] = new LightImpl(i);
         }
@@ -217,7 +215,7 @@
     private final LightsManager mService = new LightsManager() {
         @Override
         public Light getLight(int id) {
-            if (id < LIGHT_ID_COUNT) {
+            if (0 <= id && id < LIGHT_ID_COUNT) {
                 return mLights[id];
             } else {
                 return null;
@@ -225,12 +223,6 @@
         }
     };
 
-    @Override
-    protected void finalize() throws Throwable {
-        finalize_native(mNativePointer);
-        super.finalize();
-    }
-
     private Handler mH = new Handler() {
         @Override
         public void handleMessage(Message msg) {
@@ -239,11 +231,6 @@
         }
     };
 
-    private static native long init_native();
-    private static native void finalize_native(long ptr);
-
-    static native void setLight_native(long ptr, int light, int color, int mode,
+    static native void setLight_native(int light, int color, int mode,
             int onMS, int offMS, int brightnessMode);
-
-    private long mNativePointer;
 }
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 0c7c8aa..61bf3bd 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -30,6 +30,7 @@
 import static android.service.notification.NotificationRankerService.REASON_PACKAGE_CHANGED;
 import static android.service.notification.NotificationRankerService.REASON_PACKAGE_SUSPENDED;
 import static android.service.notification.NotificationRankerService.REASON_PROFILE_TURNED_OFF;
+import static android.service.notification.NotificationRankerService.REASON_SNOOZED;
 import static android.service.notification.NotificationRankerService.REASON_UNAUTOBUNDLED;
 import static android.service.notification.NotificationRankerService.REASON_USER_STOPPED;
 import static android.service.notification.NotificationListenerService.HINT_HOST_DISABLE_EFFECTS;
@@ -309,6 +310,8 @@
     private float mMaxPackageEnqueueRate = DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE;
     private String mSystemNotificationSound;
 
+    private SnoozeHelper mSnoozeHelper;
+
     private static class Archive {
         final int mBufferSize;
         final ArrayDeque<StatusBarNotification> mBuffer;
@@ -999,6 +1002,22 @@
                 sendRegisteredOnlyBroadcast(NotificationManager.ACTION_NOTIFICATION_POLICY_CHANGED);
             }
         });
+        mSnoozeHelper = new SnoozeHelper(getContext(), new SnoozeHelper.Callback() {
+            @Override
+            public void repost(int userId, NotificationRecord r) {
+                try {
+                    if (DBG) {
+                        Slog.d(TAG, "Reposting " + r.getKey());
+                    }
+                    enqueueNotificationInternal(r.sbn.getPackageName(), r.sbn.getOpPkg(),
+                            r.sbn.getUid(), r.sbn.getInitialPid(), r.sbn.getTag(), r.sbn.getId(),
+                            r.sbn.getNotification(), new int[1], userId);
+                } catch (Exception e) {
+                    Slog.e(TAG, "Cannot un-snooze notification", e);
+                }
+            }
+        }, mUserProfiles);
+
         final File systemDir = new File(Environment.getDataDirectory(), "system");
         mPolicyFile = new AtomicFile(new File(systemDir, "notification_policy.xml"));
 
@@ -1810,6 +1829,13 @@
             }
         }
 
+        /**
+         * Allow an INotificationListener to simulate clearing (dismissing) a single notification.
+         *
+         * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onNotificationClear}
+         *
+         * @param token The binder for the listener, to check that the caller is allowed
+         */
         private void cancelNotificationFromListenerLocked(ManagedServiceInfo info,
                 int callingUid, int callingPid, String pkg, String tag, int id, int userId) {
             cancelNotification(callingUid, callingPid, pkg, tag, id, 0,
@@ -1819,6 +1845,23 @@
         }
 
         /**
+         * Allow an INotificationListener to snooze a single notification.
+         *
+         * @param token The binder for the listener, to check that the caller is allowed
+         */
+        @Override
+        public void snoozeNotificationFromListener(INotificationListener token, String key,
+                long snoozeUntil) {
+            long identity = Binder.clearCallingIdentity();
+            try {
+                final ManagedServiceInfo info = mListeners.checkServiceTokenLocked(token);
+                snoozeNotificationInt(key, snoozeUntil, info);
+            } finally {
+                Binder.restoreCallingIdentity(identity);
+            }
+        }
+
+        /**
          * Allow an INotificationListener to simulate clearing (dismissing) a single notification.
          *
          * {@see com.android.server.StatusBarManagerService.NotificationCallbacks#onNotificationClear}
@@ -2592,6 +2635,11 @@
                 pw.println("\n  Notification ranker services:");
                 mRankerServices.dump(pw, filter);
             }
+
+            if (!zenOnly) {
+                mSnoozeHelper.dump(pw, filter);
+            }
+
             pw.println("\n  Policy access:");
             pw.print("    mPolicyAccess: "); pw.println(mPolicyAccess);
 
@@ -2765,6 +2813,16 @@
         public void run() {
 
             synchronized (mNotificationList) {
+                if (mSnoozeHelper.isSnoozed(userId, r.sbn.getPackageName(), r.getKey())) {
+                    // TODO: log to event log
+                    if (DBG) {
+                        Slog.d(TAG, "Ignored enqueue for snoozed notification " + r.getKey());
+                    }
+                    mSnoozeHelper.update(userId, r);
+                    savePolicyFile();
+                    return;
+                }
+
                 final StatusBarNotification n = r.sbn;
                 if (DBG) Slog.d(TAG, "EnqueueNotificationRunnable.run for: " + n.getKey());
                 NotificationRecord old = mNotificationsByKey.get(n.getKey());
@@ -3578,6 +3636,11 @@
                         cancelGroupChildrenLocked(r, callingUid, callingPid, listenerName,
                                 REASON_GROUP_SUMMARY_CANCELED, sendDelete);
                         updateLightsLocked();
+                    } else {
+                        final boolean wasSnoozed = mSnoozeHelper.cancel(userId, pkg, tag, id);
+                        if (wasSnoozed) {
+                            savePolicyFile();
+                        }
                     }
                 }
             }
@@ -3641,7 +3704,7 @@
                 if (pkg != null && !r.sbn.getPackageName().equals(pkg)) {
                     continue;
                 }
-                if (channelId == null || !channelId.equals(r.getChannel().getId())) {
+                if (channelId != null && !channelId.equals(r.getChannel().getId())) {
                     continue;
                 }
                 if (canceledNotifications == null) {
@@ -3654,6 +3717,7 @@
                 mNotificationList.remove(i);
                 cancelNotificationLocked(r, false, reason);
             }
+            mSnoozeHelper.cancel(userId, pkg);
             if (doit && canceledNotifications != null) {
                 final int M = canceledNotifications.size();
                 for (int i = 0; i < M; i++) {
@@ -3668,6 +3732,28 @@
         }
     }
 
+    void snoozeNotificationInt(String key, long until, ManagedServiceInfo listener) {
+        String listenerName = listener == null ? null : listener.component.toShortString();
+        // TODO: write to event log
+        if (DBG) {
+            Slog.d(TAG, String.format("snooze event(%s, %d, %s)", key, until,
+                    listenerName));
+        }
+        if (until < System.currentTimeMillis()) {
+            return;
+        }
+        synchronized (mNotificationList) {
+            final NotificationRecord r = mNotificationsByKey.get(key);
+            if (r != null) {
+                mNotificationList.remove(r);
+                cancelNotificationLocked(r, false, REASON_SNOOZED);
+                updateLightsLocked();
+                mSnoozeHelper.snooze(r, r.getUser().getIdentifier(), until);
+                savePolicyFile();
+            }
+        }
+    }
+
     void cancelAllLocked(int callingUid, int callingPid, int userId, int reason,
             ManagedServiceInfo listener, boolean includeCurrentProfiles) {
         String listenerName = listener == null ? null : listener.component.toShortString();
@@ -3699,6 +3785,7 @@
                 canceledNotifications.add(r);
             }
         }
+        mSnoozeHelper.cancel(userId, includeCurrentProfiles);
         int M = canceledNotifications != null ? canceledNotifications.size() : 0;
         for (int i = 0; i < M; i++) {
             cancelGroupChildrenLocked(canceledNotifications.get(i), callingUid, callingPid,
diff --git a/services/core/java/com/android/server/notification/RankingHelper.java b/services/core/java/com/android/server/notification/RankingHelper.java
index 7182da1..d59115e 100644
--- a/services/core/java/com/android/server/notification/RankingHelper.java
+++ b/services/core/java/com/android/server/notification/RankingHelper.java
@@ -162,6 +162,7 @@
                             r = mRestoredWithoutUids.get(name);
                             if (r == null) {
                                 r = new Record();
+                                r.pkg = name;
                                 mRestoredWithoutUids.put(name, r);
                             }
                         } else {
@@ -606,7 +607,7 @@
     }
 
     public void onPackagesChanged(boolean removingPackage, String[] pkgList) {
-        if (!removingPackage || pkgList == null || pkgList.length == 0
+        if (removingPackage || pkgList == null || pkgList.length == 0
                 || mRestoredWithoutUids.isEmpty()) {
             return; // nothing to do
         }
diff --git a/services/core/java/com/android/server/notification/SnoozeHelper.java b/services/core/java/com/android/server/notification/SnoozeHelper.java
new file mode 100644
index 0000000..738403e
--- /dev/null
+++ b/services/core/java/com/android/server/notification/SnoozeHelper.java
@@ -0,0 +1,281 @@
+/*
+ * Copyright (C) 2016 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 com.android.server.notification;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+import org.xmlpull.v1.XmlSerializer;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.net.Uri;
+import android.service.notification.StatusBarNotification;
+import android.util.ArrayMap;
+import android.util.Log;
+import android.util.Slog;
+
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Date;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+/**
+ * NotificationManagerService helper for handling snoozed notifications.
+ */
+public class SnoozeHelper {
+    private static final String TAG = "SnoozeHelper";
+    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
+    private static final String INDENT = "    ";
+
+    private static final String REPOST_ACTION = SnoozeHelper.class.getSimpleName() + ".EVALUATE";
+    private static final int REQUEST_CODE_REPOST = 1;
+    private static final String REPOST_SCHEME = "repost";
+    private static final String EXTRA_PKG = "pkg";
+    private static final String EXTRA_KEY = "key";
+    private static final String EXTRA_USER_ID = "userId";
+
+    private final Context mContext;
+    private AlarmManager mAm;
+    private final ManagedServices.UserProfiles mUserProfiles;
+
+    // User id : package name : notification key : record.
+    private ArrayMap<Integer, ArrayMap<String, ArrayMap<String, NotificationRecord>>>
+            mSnoozedNotifications = new ArrayMap<>();
+    private Callback mCallback;
+
+    public SnoozeHelper(Context context, Callback callback,
+            ManagedServices.UserProfiles userProfiles) {
+        mContext = context;
+        IntentFilter filter = new IntentFilter(REPOST_ACTION);
+        filter.addDataScheme(REPOST_SCHEME);
+        mContext.registerReceiver(mBroadcastReceiver, filter);
+        mAm = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
+        mCallback = callback;
+        mUserProfiles = userProfiles;
+    }
+
+    protected boolean isSnoozed(int userId, String pkg, String key) {
+        return mSnoozedNotifications.containsKey(userId)
+                && mSnoozedNotifications.get(userId).containsKey(pkg)
+                && mSnoozedNotifications.get(userId).get(pkg).containsKey(key);
+    }
+
+    /**
+     * Records a notification that should be snoozed until the given time and schedules an alarm
+     * to repost at that time.
+     */
+    protected void snooze(NotificationRecord record, int userId, long until) {
+        ArrayMap<String, ArrayMap<String, NotificationRecord>> records =
+                mSnoozedNotifications.get(userId);
+        if (records == null) {
+            records = new ArrayMap<>();
+        }
+        ArrayMap<String, NotificationRecord> pkgRecords = records.get(record.sbn.getPackageName());
+        if (pkgRecords == null) {
+            pkgRecords = new ArrayMap<>();
+        }
+        pkgRecords.put(record.getKey(), record);
+        records.put(record.sbn.getPackageName(), pkgRecords);
+        mSnoozedNotifications.put(userId, records);
+        if (DEBUG) {
+            Slog.d(TAG, "Snoozing " + record.getKey() + " until " + new Date(until));
+        }
+        scheduleRepost(record.sbn.getPackageName(), record.getKey(), userId, until);
+    }
+
+
+    protected boolean cancel(int userId, String pkg, String tag, int id) {
+        if (mSnoozedNotifications.containsKey(userId)) {
+            ArrayMap<String, NotificationRecord> recordsForPkg =
+                    mSnoozedNotifications.get(userId).get(pkg);
+            if (recordsForPkg != null) {
+                final Set<Map.Entry<String, NotificationRecord>> records = recordsForPkg.entrySet();
+                String key = null;
+                for (Map.Entry<String, NotificationRecord> record : records) {
+                    final StatusBarNotification sbn = record.getValue().sbn;
+                    if (Objects.equals(sbn.getTag(), tag) && sbn.getId() == id) {
+                        key = record.getKey();
+                    }
+                }
+                if (key != null) {
+                    recordsForPkg.remove(key);
+                    cancelAlarm(userId, pkg, key);
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    protected boolean cancel(int userId, boolean includeCurrentProfiles) {
+        int[] userIds = {userId};
+        if (includeCurrentProfiles) {
+            userIds = mUserProfiles.getCurrentProfileIds();
+        }
+        final int N = userIds.length;
+        for (int i = 0; i < N; i++) {
+            final ArrayMap<String, ArrayMap<String, NotificationRecord>> snoozedPkgs =
+                    mSnoozedNotifications.remove(userIds[i]);
+            if (snoozedPkgs != null) {
+                final int M = snoozedPkgs.size();
+                for (int j = 0; j < M; j++) {
+                    final ArrayMap<String, NotificationRecord> records = snoozedPkgs.valueAt(j);
+                    if (records != null) {
+                        int P = records.size();
+                        for (int k = 0; k < P; k++) {
+                            cancelAlarm(userId, snoozedPkgs.keyAt(j), records.keyAt(k));
+                        }
+                    }
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    protected boolean cancel(int userId, String pkg) {
+        if (mSnoozedNotifications.containsKey(userId)) {
+            if (mSnoozedNotifications.get(userId).containsKey(pkg)) {
+                ArrayMap<String, NotificationRecord> records =
+                        mSnoozedNotifications.get(userId).remove(pkg);
+                int N = records.size();
+                for (int i = 0; i < N; i++) {
+                    cancelAlarm(userId, pkg, records.keyAt(i));
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    private void cancelAlarm(int userId, String pkg, String key) {
+        final PendingIntent pi = createPendingIntent(pkg, key, userId);
+        mAm.cancel(pi);
+    }
+
+    /**
+     * Updates the notification record so the most up to date information is shown on re-post.
+     */
+    protected void update(int userId, NotificationRecord record) {
+        ArrayMap<String, ArrayMap<String, NotificationRecord>> records =
+                mSnoozedNotifications.get(userId);
+        if (records == null) {
+            return;
+        }
+        ArrayMap<String, NotificationRecord> pkgRecords = records.get(record.sbn.getPackageName());
+        if (pkgRecords == null) {
+            return;
+        }
+        pkgRecords.put(record.getKey(), record);
+    }
+
+    @VisibleForTesting
+    void repost(String pkg, String key, int userId) {
+        ArrayMap<String, ArrayMap<String, NotificationRecord>> records =
+                mSnoozedNotifications.get(userId);
+        if (records == null) {
+            return;
+        }
+        ArrayMap<String, NotificationRecord> pkgRecords = records.get(pkg);
+        if (pkgRecords == null) {
+            return;
+        }
+        final NotificationRecord record = pkgRecords.remove(key);
+        if (record != null) {
+            mCallback.repost(userId, record);
+        }
+    }
+
+    private PendingIntent createPendingIntent(String pkg, String key, int userId) {
+        return PendingIntent.getBroadcast(mContext,
+                REQUEST_CODE_REPOST,
+                new Intent(REPOST_ACTION)
+                        .setData(new Uri.Builder().scheme(REPOST_SCHEME).appendPath(key).build())
+                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND)
+                        .putExtra(EXTRA_PKG, pkg)
+                        .putExtra(EXTRA_KEY, key)
+                        .putExtra(EXTRA_USER_ID, userId),
+                PendingIntent.FLAG_UPDATE_CURRENT);
+    }
+
+    private void scheduleRepost(String pkg, String key, int userId, long time) {
+        final PendingIntent pi = createPendingIntent(pkg, key, userId);
+        mAm.cancel(pi);
+        if (DEBUG) Slog.d(TAG, "Scheduling evaluate for " + new Date(time));
+        mAm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, time, pi);
+    }
+
+    public void dump(PrintWriter pw, NotificationManagerService.DumpFilter filter) {
+        pw.println("\n  Snoozed notifications:");
+        for (int userId : mSnoozedNotifications.keySet()) {
+            pw.print(INDENT);
+            pw.println("user: " + userId);
+            ArrayMap<String, ArrayMap<String, NotificationRecord>> snoozedPkgs =
+                    mSnoozedNotifications.get(userId);
+            for (String pkg : snoozedPkgs.keySet()) {
+                pw.print(INDENT);
+                pw.print(INDENT);
+                pw.println("package: " + pkg);
+                Set<String> snoozedKeys = snoozedPkgs.get(pkg).keySet();
+                for (String key : snoozedKeys) {
+                    pw.print(INDENT);
+                    pw.print(INDENT);
+                    pw.print(INDENT);
+                    pw.println(key);
+                }
+            }
+        }
+    }
+
+    protected void writeXml(XmlSerializer out, boolean forBackup) throws IOException {
+
+    }
+
+    public void readXml(XmlPullParser parser, boolean forRestore)
+            throws XmlPullParserException, IOException {
+
+    }
+
+    @VisibleForTesting
+    void setAlarmManager(AlarmManager am) {
+        mAm = am;
+    }
+
+    protected interface Callback {
+        void repost(int userId, NotificationRecord r);
+    }
+
+    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
+        @Override
+        public void onReceive(Context context, Intent intent) {
+            if (DEBUG) {
+                Slog.d(TAG, "Reposting notification");
+            }
+            if (REPOST_ACTION.equals(intent.getAction())) {
+                repost(intent.getStringExtra(EXTRA_PKG), intent.getStringExtra(EXTRA_KEY),
+                        intent.getIntExtra(EXTRA_USER_ID, 0));
+            }
+        }
+    };
+}
diff --git a/services/core/java/com/android/server/os/DeviceIdentifiersPolicyService.java b/services/core/java/com/android/server/os/DeviceIdentifiersPolicyService.java
index 759030b..5f08257 100644
--- a/services/core/java/com/android/server/os/DeviceIdentifiersPolicyService.java
+++ b/services/core/java/com/android/server/os/DeviceIdentifiersPolicyService.java
@@ -20,6 +20,7 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.os.Binder;
 import android.os.Build;
 import android.os.IDeviceIdentifiersPolicyService;
@@ -53,9 +54,15 @@
 
         @Override
         public @Nullable String getSerial() throws RemoteException {
-            if (UserHandle.getAppId(Binder.getCallingUid()) != Process.SYSTEM_UID) {
-                mContext.enforceCallingOrSelfPermission(
-                        Manifest.permission.READ_PHONE_STATE, "getSerial");
+            if (UserHandle.getAppId(Binder.getCallingUid()) != Process.SYSTEM_UID
+                    && mContext.checkCallingOrSelfPermission(
+                            Manifest.permission.READ_PHONE_STATE)
+                                    != PackageManager.PERMISSION_GRANTED
+                    && mContext.checkCallingOrSelfPermission(
+                            Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
+                                    != PackageManager.PERMISSION_GRANTED) {
+                throw new SecurityException("getSerial requires READ_PHONE_STATE"
+                        + " or READ_PRIVILEGED_PHONE_STATE permission");
             }
             return SystemProperties.get("ro.serialno", Build.UNKNOWN);
         }
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index c1dd24a..e48d6fb 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -466,8 +466,8 @@
 
     private static final String VENDOR_OVERLAY_DIR = "/vendor/overlay";
     /**
-     * If VENDOR_OVERLAY_SKU_PROPERTY is set, search for runtime resource overlay APKs in
-     * VENDOR_OVERLAY_DIR/<value of VENDOR_OVERLAY_SKU_PROPERTY> rather than in
+     * If VENDOR_OVERLAY_SKU_PROPERTY is set, search for runtime resource overlay APKs also in
+     * VENDOR_OVERLAY_DIR/<value of VENDOR_OVERLAY_SKU_PROPERTY> in addition to
      * VENDOR_OVERLAY_DIR.
      */
     private static final String VENDOR_OVERLAY_SKU_PROPERTY = "ro.boot.vendor.overlay.sku";
@@ -2285,18 +2285,17 @@
                 }
             }
 
-            // Collect vendor overlay packages.
-            // (Do this before scanning any apps.)
+            // Collect vendor overlay packages. (Do this before scanning any apps.)
             // For security and version matching reason, only consider
             // overlay packages if they reside in the right directory.
-            File vendorOverlayDir;
             String overlaySkuDir = SystemProperties.get(VENDOR_OVERLAY_SKU_PROPERTY);
             if (!overlaySkuDir.isEmpty()) {
-                vendorOverlayDir = new File(VENDOR_OVERLAY_DIR, overlaySkuDir);
-            } else {
-                vendorOverlayDir = new File(VENDOR_OVERLAY_DIR);
+                scanDirTracedLI(new File(VENDOR_OVERLAY_DIR, overlaySkuDir), mDefParseFlags
+                        | PackageParser.PARSE_IS_SYSTEM
+                        | PackageParser.PARSE_IS_SYSTEM_DIR
+                        | PackageParser.PARSE_TRUSTED_OVERLAY, scanFlags | SCAN_TRUSTED_OVERLAY, 0);
             }
-            scanDirTracedLI(vendorOverlayDir, mDefParseFlags
+            scanDirTracedLI(new File(VENDOR_OVERLAY_DIR), mDefParseFlags
                     | PackageParser.PARSE_IS_SYSTEM
                     | PackageParser.PARSE_IS_SYSTEM_DIR
                     | PackageParser.PARSE_TRUSTED_OVERLAY, scanFlags | SCAN_TRUSTED_OVERLAY, 0);
diff --git a/services/core/java/com/android/server/pm/Settings.java b/services/core/java/com/android/server/pm/Settings.java
index 4ba5d07..6d514e4 100644
--- a/services/core/java/com/android/server/pm/Settings.java
+++ b/services/core/java/com/android/server/pm/Settings.java
@@ -4255,7 +4255,7 @@
         ApplicationInfo.FLAG_LARGE_HEAP, "LARGE_HEAP",
     };
 
-    static final Object[] PRIVATE_FLAG_DUMP_SPEC = new Object[] {
+    private static final Object[] PRIVATE_FLAG_DUMP_SPEC = new Object[] {
         ApplicationInfo.PRIVATE_FLAG_HIDDEN, "HIDDEN",
         ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE, "CANT_SAVE_STATE",
         ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK, "FORWARD_LOCK",
@@ -4267,7 +4267,8 @@
         ApplicationInfo.PRIVATE_FLAG_PARTIALLY_DIRECT_BOOT_AWARE, "PARTIALLY_DIRECT_BOOT_AWARE",
         ApplicationInfo.PRIVATE_FLAG_EPHEMERAL, "EPHEMERAL",
         ApplicationInfo.PRIVATE_FLAG_REQUIRED_FOR_SYSTEM_USER, "REQUIRED_FOR_SYSTEM_USER",
-        ApplicationInfo.PRIVATE_FLAG_RESIZEABLE_ACTIVITIES, "RESIZEABLE_ACTIVITIES",
+        ApplicationInfo.PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_EXPLICITLY_SET, "RESIZEABLE_ACTIVITIES_EXPLICITLY_SET",
+        ApplicationInfo.PRIVATE_FLAG_RESIZEABLE_ACTIVITIES_VIA_SDK_VERSION, "RESIZEABLE_ACTIVITIES_VIA_SDK_VERSION",
         ApplicationInfo.PRIVATE_FLAG_BACKUP_IN_FOREGROUND, "BACKUP_IN_FOREGROUND",
     };
 
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java
index c0de214..efd6f46 100644
--- a/services/core/java/com/android/server/pm/UserManagerService.java
+++ b/services/core/java/com/android/server/pm/UserManagerService.java
@@ -592,7 +592,7 @@
     @Override
     public int[] getProfileIds(int userId, boolean enabledOnly) {
         if (userId != UserHandle.getCallingUserId()) {
-            checkManageUsersPermission("getting profiles related to user " + userId);
+            checkManageOrCreateUsersPermission("getting profiles related to user " + userId);
         }
         final long ident = Binder.clearCallingIdentity();
         try {
@@ -673,12 +673,10 @@
     public boolean isSameProfileGroup(int userId, int otherUserId) {
         if (userId == otherUserId) return true;
         checkManageUsersPermission("check if in the same profile group");
-        synchronized (mPackagesLock) {
-            return isSameProfileGroupLP(userId, otherUserId);
-        }
+        return isSameProfileGroupNoChecks(userId, otherUserId);
     }
 
-    private boolean isSameProfileGroupLP(int userId, int otherUserId) {
+    private boolean isSameProfileGroupNoChecks(int userId, int otherUserId) {
         synchronized (mUsersLock) {
             UserInfo userInfo = getUserInfoLU(userId);
             if (userInfo == null || userInfo.profileGroupId == UserInfo.NO_PROFILE_GROUP_ID) {
@@ -880,12 +878,10 @@
     public boolean isManagedProfile(int userId) {
         int callingUserId = UserHandle.getCallingUserId();
         if (callingUserId != userId && !hasManageUsersPermission()) {
-            synchronized (mPackagesLock) {
-                if (!isSameProfileGroupLP(callingUserId, userId)) {
-                    throw new SecurityException(
-                            "You need MANAGE_USERS permission to: check if specified user a " +
-                            "managed profile outside your profile group");
-                }
+            if (!isSameProfileGroupNoChecks(callingUserId, userId)) {
+                throw new SecurityException(
+                        "You need MANAGE_USERS permission to: check if specified user a " +
+                        "managed profile outside your profile group");
             }
         }
         synchronized (mUsersLock) {
@@ -895,6 +891,18 @@
     }
 
     @Override
+    public boolean isUserUnlockingOrUnlocked(int userId) {
+        int callingUserId = UserHandle.getCallingUserId();
+        if (callingUserId != userId && !hasManageUsersPermission()) {
+            if (!isSameProfileGroupNoChecks(callingUserId, userId)) {
+                throw new SecurityException(
+                        "You need MANAGE_USERS permission to: check isUserUnlockingOrUnlocked");
+            }
+        }
+        return mLocalService.isUserUnlockingOrUnlocked(userId);
+    }
+
+    @Override
     public boolean isDemoUser(int userId) {
         int callingUserId = UserHandle.getCallingUserId();
         if (callingUserId != userId && !hasManageUsersPermission()) {
diff --git a/services/core/java/com/android/server/policy/BurnInProtectionHelper.java b/services/core/java/com/android/server/policy/BurnInProtectionHelper.java
index e6ec6a6..92729dc 100644
--- a/services/core/java/com/android/server/policy/BurnInProtectionHelper.java
+++ b/services/core/java/com/android/server/policy/BurnInProtectionHelper.java
@@ -43,7 +43,10 @@
     // Default value when max burnin radius is not set.
     public static final int BURN_IN_MAX_RADIUS_DEFAULT = -1;
 
-    private static final long BURNIN_PROTECTION_WAKEUP_INTERVAL_MS = TimeUnit.MINUTES.toMillis(1);
+    private static final long BURNIN_PROTECTION_FIRST_WAKEUP_INTERVAL_MS =
+            TimeUnit.MINUTES.toMillis(1);
+    private static final long BURNIN_PROTECTION_SUBSEQUENT_WAKEUP_INTERVAL_MS =
+            TimeUnit.MINUTES.toMillis(2);
     private static final long BURNIN_PROTECTION_MINIMAL_INTERVAL_MS = TimeUnit.SECONDS.toMillis(10);
 
     private static final boolean DEBUG = false;
@@ -138,6 +141,9 @@
             // We don't want to adjust offsets immediately after the device goes into ambient mode.
             // Instead, we want to wait until it's more likely that the user is not observing the
             // screen anymore.
+            final long interval = mFirstUpdate
+                ? BURNIN_PROTECTION_FIRST_WAKEUP_INTERVAL_MS
+                : BURNIN_PROTECTION_SUBSEQUENT_WAKEUP_INTERVAL_MS;
             if (mFirstUpdate) {
                 mFirstUpdate = false;
             } else {
@@ -156,8 +162,7 @@
             // Next adjustment at least ten seconds in the future.
             long nextWall = nowWall + BURNIN_PROTECTION_MINIMAL_INTERVAL_MS;
             // And aligned to the minute.
-            nextWall = nextWall - nextWall % BURNIN_PROTECTION_WAKEUP_INTERVAL_MS
-                    + BURNIN_PROTECTION_WAKEUP_INTERVAL_MS;
+            nextWall = (nextWall - (nextWall % interval)) + interval;
             // Use elapsed real time that is adjusted to full minute on wall clock.
             final long nextElapsed = nowElapsed + (nextWall - nowWall);
             if (DEBUG) {
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 3107b93..b8b16d5 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -28,6 +28,7 @@
 import static android.view.WindowManager.DOCKED_TOP;
 import static android.view.WindowManager.DOCKED_LEFT;
 import static android.view.WindowManager.DOCKED_RIGHT;
+import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
 import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
 import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;
 import static android.view.WindowManager.LayoutParams.*;
@@ -72,6 +73,7 @@
 import android.hardware.hdmi.HdmiPlaybackClient;
 import android.hardware.hdmi.HdmiPlaybackClient.OneTouchPlayCallback;
 import android.hardware.input.InputManagerInternal;
+import android.hardware.power.V1_0.PowerHint;
 import android.media.AudioAttributes;
 import android.media.AudioManager;
 import android.media.AudioSystem;
@@ -907,7 +909,7 @@
             @Override
             public void run() {
                 // send interaction hint to improve redraw performance
-                mPowerManagerInternal.powerHint(PowerManagerInternal.POWER_HINT_INTERACTION, 0);
+                mPowerManagerInternal.powerHint(PowerHint.INTERACTION, 0);
                 updateRotation(false);
             }
         };
@@ -1838,7 +1840,7 @@
                     public void onFling(int duration) {
                         if (mPowerManagerInternal != null) {
                             mPowerManagerInternal.powerHint(
-                                    PowerManagerInternal.POWER_HINT_INTERACTION, duration);
+                                    PowerHint.INTERACTION, duration);
                         }
                     }
                     @Override
@@ -2733,7 +2735,7 @@
                 }
             }
 
-            if (overrideConfig != null && overrideConfig != EMPTY) {
+            if (overrideConfig != null && !overrideConfig.equals(EMPTY)) {
                 if (DEBUG_STARTING_WINDOW) Slog.d(TAG, "addStartingWindow: creating context based"
                         + " on overrideConfig" + overrideConfig + " for starting window");
                 final Context overrideContext = context.createConfigurationContext(overrideConfig);
@@ -3959,14 +3961,6 @@
             }
         }
     }
-    final InputEventReceiver.Factory mHideNavInputEventReceiverFactory =
-            new InputEventReceiver.Factory() {
-        @Override
-        public InputEventReceiver createInputEventReceiver(
-                InputChannel inputChannel, Looper looper) {
-            return new HideNavInputEventReceiver(inputChannel, looper);
-        }
-    };
 
     @Override
     public void setRecentsVisibilityLw(boolean visible) {
@@ -4191,8 +4185,9 @@
                     mInputConsumer = null;
                 }
             } else if (mInputConsumer == null) {
-                mInputConsumer = mWindowManagerFuncs.addInputConsumer(mHandler.getLooper(),
-                        mHideNavInputEventReceiverFactory);
+                mInputConsumer = mWindowManagerFuncs.createInputConsumer(mHandler.getLooper(),
+                        INPUT_CONSUMER_NAVIGATION,
+                        (channel, looper) -> new HideNavInputEventReceiver(channel, looper));
             }
 
             // For purposes of positioning and showing the nav bar, if we have
@@ -5483,6 +5478,10 @@
             mStatusBar.getAttrs().privateFlags &= ~PRIVATE_FLAG_KEYGUARD;
             mStatusBar.getAttrs().flags &= ~FLAG_SHOW_WALLPAPER;
             return true;
+        } else if (wasOccluded != isOccluded) {
+            mKeyguardOccluded = isOccluded;
+            mKeyguardDelegate.setOccluded(isOccluded, false /* animate */);
+            return false;
         } else {
             return false;
         }
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index 7576cddad..706828b 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -31,6 +31,7 @@
 import android.hardware.SystemSensorManager;
 import android.hardware.display.DisplayManagerInternal;
 import android.hardware.display.DisplayManagerInternal.DisplayPowerRequest;
+import android.hardware.power.V1_0.PowerHint;
 import android.net.Uri;
 import android.os.BatteryManager;
 import android.os.BatteryManagerInternal;
@@ -84,7 +85,6 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 
-import static android.os.PowerManagerInternal.POWER_HINT_INTERACTION;
 import static android.os.PowerManagerInternal.WAKEFULNESS_ASLEEP;
 import static android.os.PowerManagerInternal.WAKEFULNESS_AWAKE;
 import static android.os.PowerManagerInternal.WAKEFULNESS_DOZING;
@@ -163,10 +163,6 @@
     // How long a partial wake lock must be held until we consider it a long wake lock.
     static final long MIN_LONG_WAKE_CHECK_INTERVAL = 60*1000;
 
-    // Power hints defined in hardware/libhardware/include/hardware/power.h.
-    private static final int POWER_HINT_LOW_POWER = 5;
-    private static final int POWER_HINT_VR_MODE = 7;
-
     // Power features defined in hardware/libhardware/include/hardware/power.h.
     private static final int POWER_FEATURE_DOUBLE_TAP_TO_WAKE = 1;
 
@@ -826,7 +822,7 @@
 
         if (mLowPowerModeEnabled != lowPowerModeEnabled) {
             mLowPowerModeEnabled = lowPowerModeEnabled;
-            powerHintInternal(POWER_HINT_LOW_POWER, lowPowerModeEnabled ? 1 : 0);
+            powerHintInternal(PowerHint.LOW_POWER, lowPowerModeEnabled ? 1 : 0);
             postAfterBootCompleted(new Runnable() {
                 @Override
                 public void run() {
@@ -1152,7 +1148,7 @@
         Trace.traceBegin(Trace.TRACE_TAG_POWER, "userActivity");
         try {
             if (eventTime > mLastInteractivePowerHintTime) {
-                powerHintInternal(POWER_HINT_INTERACTION, 0);
+                powerHintInternal(PowerHint.INTERACTION, 0);
                 mLastInteractivePowerHintTime = eventTime;
             }
 
@@ -3083,7 +3079,7 @@
     private final IVrStateCallbacks mVrStateCallbacks = new IVrStateCallbacks.Stub() {
         @Override
         public void onVrStateChanged(boolean enabled) {
-            powerHintInternal(POWER_HINT_VR_MODE, enabled ? 1 : 0);
+            powerHintInternal(PowerHint.VR_MODE, enabled ? 1 : 0);
         }
     };
 
diff --git a/services/core/java/com/android/server/tv/TvInputManagerService.java b/services/core/java/com/android/server/tv/TvInputManagerService.java
index b488297..47414a0 100644
--- a/services/core/java/com/android/server/tv/TvInputManagerService.java
+++ b/services/core/java/com/android/server/tv/TvInputManagerService.java
@@ -915,7 +915,11 @@
         public void updateTvInputInfo(TvInputInfo inputInfo, int userId) {
             String inputInfoPackageName = inputInfo.getServiceInfo().packageName;
             String callingPackageName = getCallingPackageName();
-            if (!TextUtils.equals(inputInfoPackageName, callingPackageName)) {
+            if (!TextUtils.equals(inputInfoPackageName, callingPackageName)
+                    && mContext.checkCallingPermission(
+                            android.Manifest.permission.WRITE_SECURE_SETTINGS)
+                                    != PackageManager.PERMISSION_GRANTED) {
+                // Only the app owning the input and system settings are allowed to update info.
                 throw new IllegalArgumentException("calling package " + callingPackageName
                         + " is not allowed to change TvInputInfo for " + inputInfoPackageName);
             }
diff --git a/services/core/java/com/android/server/utils/PriorityDump.java b/services/core/java/com/android/server/utils/PriorityDump.java
new file mode 100644
index 0000000..c05cc3f
--- /dev/null
+++ b/services/core/java/com/android/server/utils/PriorityDump.java
@@ -0,0 +1,179 @@
+/**
+ * Copyright (c) 2016, 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 com.android.server.utils;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+/**
+ * Helper for {@link android.os.Binder#dump(java.io.FileDescriptor, String[])} that supports the
+ * {@link #PRIORITY_ARG} argument.
+ * <p>
+ * Typical usage:
+ *
+ * <pre><code>
+public class SpringfieldNuclearPowerPlant extends Binder {
+
+ private final PriorityDump.PriorityDumper mPriorityDumper = new PriorityDump.PriorityDumper() {
+
+     @Override
+     public void dumpCritical(FileDescriptor fd, PrintWriter pw, String[] args) {
+       pw.println("Donuts in the box: 1");
+     }
+
+     @Override
+     public void dumpNormal(FileDescriptor fd, PrintWriter pw, String[] args) {
+       pw.println("Nuclear reactor status: DANGER - MELTDOWN IMMINENT");
+     }
+  };
+
+  @Override
+  protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+      PriorityDump.dump(mPriorityDumper, fd, pw, args);
+  }
+}
+
+ * </code></pre>
+ *
+ * <strong>Disclaimer</strong>: a real-life service should prioritize core status over donuts :-)
+ *
+ * <p>Then to invoke it:
+ *
+ * <pre><code>
+ *
+    $ adb shell dumpsys snpp
+    Donuts in the box: 1
+    Nuclear reactor status: DANGER - MELTDOWN IMMINENT
+
+    $ adb shell dumpsys snpp --dump_priority CRITICAL
+    Donuts in the box: 1
+
+    $ adb shell dumpsys snpp --dump_priority NORMAL
+    Nuclear reactor status: DANGER - MELTDOWN IMMINENT
+
+ * </code></pre>
+ *
+ *
+ *
+ * <p>To run the unit tests:
+ * <pre><code>
+ *
+ mmm -j32 frameworks/base/services/tests/servicestests/ && \
+ adb install -r -g ${ANDROID_PRODUCT_OUT}/data/app/FrameworksServicesTests/FrameworksServicesTests.apk && \
+ adb shell am instrument -e class "com.android.server.utils.PriorityDumpTest" \
+ -w "com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner"
+
+ * </code></pre>
+ *
+ *
+ * @hide
+ */
+public final class PriorityDump {
+
+    public static final String PRIORITY_ARG = "--dump_priority";
+
+    private PriorityDump() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * Parses {@code} and call the proper {@link PriorityDumper} method when the first argument is
+     * {@code --dump_priority}, stripping the priority and its type.
+     * <p>
+     * For example, if called as {@code --dump_priority HIGH arg1 arg2 arg3}, it will call
+     * <code>dumper.dumpHigh(fd, pw, {"arg1", "arg2", "arg3"}) </code>
+     * <p>
+     * If the {@code --dump_priority} is not set, it calls
+     * {@link PriorityDumper#dump(FileDescriptor, PrintWriter, String[])} passing the whole
+     * {@code args} instead.
+     */
+    public static void dump(PriorityDumper dumper, FileDescriptor fd, PrintWriter pw,
+            String[] args) {
+        if (args != null && args.length >= 2 && args[0].equals(PRIORITY_ARG)) {
+            final String priority = args[1];
+            switch (priority) {
+                case "CRITICAL": {
+                    dumper.dumpCritical(fd, pw, getStrippedArgs(args));
+                    return;
+                }
+                case "HIGH": {
+                    dumper.dumpHigh(fd, pw, getStrippedArgs(args));
+                    return;
+                }
+                case "NORMAL": {
+                    dumper.dumpNormal(fd, pw, getStrippedArgs(args));
+                    return;
+                }
+            }
+        }
+        dumper.dump(fd, pw, args);
+    }
+
+    /**
+     * Gets an array without the {@code --dump_priority PRIORITY} prefix.
+     */
+    private static String[] getStrippedArgs(String[] args) {
+        final String[] stripped = new String[args.length - 2];
+        System.arraycopy(args, 2, stripped, 0, stripped.length);
+        return stripped;
+    }
+
+    /**
+     * Helper for {@link android.os.Binder#dump(java.io.FileDescriptor, String[])} that supports the
+     * {@link #PRIORITY_ARG} argument.
+     *
+     * @hide
+     */
+    public static interface PriorityDumper {
+
+        /**
+         * Dumps only the critical section.
+         */
+        @SuppressWarnings("unused")
+        default void dumpCritical(FileDescriptor fd, PrintWriter pw, String[] args) {
+        }
+
+        /**
+         * Dumps only the high-priority section.
+         */
+        @SuppressWarnings("unused")
+        default void dumpHigh(FileDescriptor fd, PrintWriter pw, String[] args) {
+        }
+
+        /**
+         * Dumps only the normal section.
+         */
+        @SuppressWarnings("unused")
+        default void dumpNormal(FileDescriptor fd, PrintWriter pw, String[] args) {
+        }
+
+        /**
+         * Dumps all sections.
+         * <p>
+         * This method is called when
+         * {@link PriorityDump#dump(PriorityDumper, FileDescriptor, PrintWriter, String[])} is
+         * called without priority arguments. By default, it calls the 3 {@code dumpTYPE} methods,
+         * so sub-classes just need to implement the priority types they support.
+         */
+        @SuppressWarnings("unused")
+        default void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            dumpCritical(fd, pw, args);
+            dumpHigh(fd, pw, args);
+            dumpNormal(fd, pw, args);
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
index 9b22760..7439f535 100644
--- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
+++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java
@@ -1479,7 +1479,7 @@
         lockWP.cropHint.set(sysWP.cropHint);
         lockWP.width = sysWP.width;
         lockWP.height = sysWP.height;
-        lockWP.allowBackup = false;
+        lockWP.allowBackup = sysWP.allowBackup;
 
         // Migrate the bitmap files outright; no need to copy
         try {
diff --git a/services/core/java/com/android/server/webkit/WebViewUpdateService.java b/services/core/java/com/android/server/webkit/WebViewUpdateService.java
index 43cdf59..6d97796 100644
--- a/services/core/java/com/android/server/webkit/WebViewUpdateService.java
+++ b/services/core/java/com/android/server/webkit/WebViewUpdateService.java
@@ -20,6 +20,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.IntentFilter;
+import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
 import android.os.Binder;
 import android.os.PatternMatcher;
@@ -224,7 +225,13 @@
 
         @Override // Binder call
         public String getCurrentWebViewPackageName() {
-            return WebViewUpdateService.this.mImpl.getCurrentWebViewPackageName();
+            PackageInfo pi = WebViewUpdateService.this.mImpl.getCurrentWebViewPackage();
+            return pi == null ? null : pi.packageName;
+        }
+
+        @Override // Binder call
+        public PackageInfo getCurrentWebViewPackage() {
+            return WebViewUpdateService.this.mImpl.getCurrentWebViewPackage();
         }
 
         @Override // Binder call
diff --git a/services/core/java/com/android/server/webkit/WebViewUpdateServiceImpl.java b/services/core/java/com/android/server/webkit/WebViewUpdateServiceImpl.java
index 3a93b46..b69a8c1 100644
--- a/services/core/java/com/android/server/webkit/WebViewUpdateServiceImpl.java
+++ b/services/core/java/com/android/server/webkit/WebViewUpdateServiceImpl.java
@@ -145,8 +145,8 @@
         return mSystemInterface.getWebViewPackages();
     }
 
-    String getCurrentWebViewPackageName() {
-        return mWebViewUpdater.getCurrentWebViewPackageName();
+    PackageInfo getCurrentWebViewPackage() {
+        return mWebViewUpdater.getCurrentWebViewPackage();
     }
 
     void enableFallbackLogic(boolean enable) {
@@ -316,6 +316,7 @@
                                 onWebViewProviderChanged(newPackage);
                             }
                         } catch (WebViewPackageMissingException e) {
+                            mCurrentWebViewPackage = null;
                             Slog.e(TAG, "Could not find valid WebView package to create " +
                                     "relro with " + e);
                         }
@@ -371,6 +372,7 @@
                     providerChanged = (oldPackage == null)
                             || !newPackage.packageName.equals(oldPackage.packageName);
                 } catch (WebViewPackageMissingException e) {
+                    mCurrentWebViewPackage = null;
                     Slog.e(TAG, "Tried to change WebView provider but failed to fetch WebView " +
                             "package " + e);
                     // If we don't perform the user change but don't have an installed WebView
@@ -548,11 +550,9 @@
             return new WebViewProviderResponse(webViewPackage, webViewStatus);
         }
 
-        public String getCurrentWebViewPackageName() {
+        public PackageInfo getCurrentWebViewPackage() {
             synchronized(mLock) {
-                if (mCurrentWebViewPackage == null)
-                    return null;
-                return mCurrentWebViewPackage.packageName;
+                return mCurrentWebViewPackage;
             }
         }
 
@@ -579,6 +579,7 @@
                         PackageInfo newPackage = findPreferredWebViewPackage();
                         onWebViewProviderChanged(newPackage);
                     } catch (WebViewPackageMissingException e) {
+                        mCurrentWebViewPackage = null;
                         // If we can't find any valid WebView package we are now in a state where
                         // mAnyWebViewInstalled is false, so loading WebView will be blocked and we
                         // should simply wait until we receive an intent declaring a new package was
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 508cf24..f1df94f 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -158,8 +158,10 @@
     ArrayDeque<Rect> mFrozenBounds = new ArrayDeque<>();
     ArrayDeque<Configuration> mFrozenMergedConfig = new ArrayDeque<>();
 
-    AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction) {
-        super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true);
+    AppWindowToken(WindowManagerService service, IApplicationToken token, boolean _voiceInteraction,
+            DisplayContent displayContent) {
+        super(service, token != null ? token.asBinder() : null, TYPE_APPLICATION, true,
+                displayContent);
         appToken = token;
         voiceInteraction = _voiceInteraction;
         mInputApplicationHandle = new InputApplicationHandle(this);
@@ -416,7 +418,7 @@
      * surfaces that's eligible, if the app is already stopped.
      */
     private void destroySurfaces(boolean cleanupOnResume) {
-        final DisplayContentList displayList = new DisplayContentList();
+        final ArrayList<DisplayContent> displayList = new ArrayList();
         for (int i = mChildren.size() - 1; i >= 0; i--) {
             final WindowState win = mChildren.get(i);
             final boolean destroyed = win.destroySurface(cleanupOnResume, mAppStopped);
@@ -897,7 +899,7 @@
     }
 
     boolean transferStartingWindow(IBinder transferFrom) {
-        final AppWindowToken fromToken = mService.findAppWindowToken(transferFrom);
+        final AppWindowToken fromToken = getDisplayContent().getAppWindowToken(transferFrom);
         if (fromToken == null) {
             return false;
         }
@@ -1182,16 +1184,16 @@
         }
     }
 
-    int rebuildWindowListUnchecked(DisplayContent dc, int addIndex) {
-        return super.rebuildWindowList(dc, addIndex);
+    int rebuildWindowListUnchecked(int addIndex) {
+        return super.rebuildWindowList(addIndex);
     }
 
     @Override
-    int rebuildWindowList(DisplayContent dc, int addIndex) {
+    int rebuildWindowList(int addIndex) {
         if (mIsExiting && !waitingForReplacement()) {
             return addIndex;
         }
-        return rebuildWindowListUnchecked(dc, addIndex);
+        return rebuildWindowListUnchecked(addIndex);
     }
 
     @Override
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index fb37c9f..65f2906 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -23,6 +23,12 @@
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_BEHIND;
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSET;
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+import static android.view.Display.DEFAULT_DISPLAY;
+import static android.view.Display.FLAG_PRIVATE;
+import static android.view.Surface.ROTATION_0;
+import static android.view.Surface.ROTATION_180;
+import static android.view.Surface.ROTATION_270;
+import static android.view.Surface.ROTATION_90;
 import static android.view.WindowManager.DOCKED_BOTTOM;
 import static android.view.WindowManager.DOCKED_INVALID;
 import static android.view.WindowManager.DOCKED_TOP;
@@ -43,22 +49,27 @@
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_VISIBILITY;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ORIENTATION;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
+import static com.android.server.wm.WindowManagerService.dipToPixel;
+import static com.android.server.wm.WindowManagerService.localLOGV;
 import static com.android.server.wm.WindowState.RESIZE_HANDLE_WIDTH_IN_DP;
 
 import android.annotation.NonNull;
 import android.app.ActivityManager.StackId;
 import android.content.res.Configuration;
+import android.graphics.Matrix;
 import android.graphics.Rect;
+import android.graphics.RectF;
 import android.graphics.Region;
 import android.graphics.Region.Op;
 import android.hardware.display.DisplayManagerInternal;
 import android.os.Debug;
+import android.os.IBinder;
 import android.util.DisplayMetrics;
 import android.util.Slog;
 import android.view.Display;
 import android.view.DisplayInfo;
 import android.view.IWindow;
-import android.view.Surface;
+
 import com.android.internal.util.FastPrintWriter;
 
 import java.io.FileDescriptor;
@@ -66,11 +77,11 @@
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 
-class DisplayContentList extends ArrayList<DisplayContent> {
-}
-
 /**
  * Utility class for keeping track of the WindowStates and other pertinent contents of a
  * particular Display.
@@ -78,15 +89,24 @@
  * IMPORTANT: No method from this class should ever be used without holding
  * WindowManagerService.mWindowMap.
  */
-class DisplayContent extends WindowContainer<TaskStack> {
+class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowContainer> {
 
     /** Unique identifier of this stack. */
     private final int mDisplayId;
 
+    // The display only has 2 child window containers. mTaskStackContainers which contains all
+    // window containers that are related to apps (Activities) and mNonAppWindowContainers which
+    // contains all window containers not related to apps (e.g. Status bar).
+    private final TaskStackContainers mTaskStackContainers = new TaskStackContainers();
+    private final NonAppWindowContainers mNonAppWindowContainers = new NonAppWindowContainers();
+
     /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element
      * from mDisplayWindows; */
     private final WindowList mWindows = new WindowList();
 
+    // Mapping from a token IBinder to a WindowToken object on this display.
+    private final HashMap<IBinder, WindowToken> mTokenMap = new HashMap();
+
     int mInitialDisplayWidth = 0;
     int mInitialDisplayHeight = 0;
     int mInitialDisplayDensity = 0;
@@ -122,6 +142,8 @@
     /** Save allocating when calculating rects */
     private final Rect mTmpRect = new Rect();
     private final Rect mTmpRect2 = new Rect();
+    private final RectF mTmpRectF = new RectF();
+    private final Matrix mTmpMatrix = new Matrix();
     private final Region mTmpRegion = new Region();
 
     final WindowManagerService mService;
@@ -143,6 +165,10 @@
     private final GetWindowOnDisplaySearchResult mTmpGetWindowOnDisplaySearchResult =
             new GetWindowOnDisplaySearchResult();
 
+    // True if this display is in the process of being removed. Used to determine if the removal of
+    // the display's direct children should be allowed.
+    private boolean mRemovingDisplay = false;
+
     /**
      * @param display May not be null.
      * @param service You know.
@@ -152,11 +178,15 @@
         mDisplayId = display.getDisplayId();
         display.getDisplayInfo(mDisplayInfo);
         display.getMetrics(mDisplayMetrics);
-        isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
+        isDefaultDisplay = mDisplayId == DEFAULT_DISPLAY;
         mService = service;
         initializeDisplayBaseInfo();
         mDividerControllerLocked = new DockedStackDividerController(service, this);
         mDimLayerController = new DimLayerController(this);
+
+        // These are the only direct children we should ever have and they are permanent.
+        super.addChild(mTaskStackContainers, null);
+        super.addChild(mNonAppWindowContainers, null);
     }
 
     int getDisplayId() {
@@ -167,6 +197,45 @@
         return mWindows;
     }
 
+    WindowToken getWindowToken(IBinder binder) {
+        return mTokenMap.get(binder);
+    }
+
+    AppWindowToken getAppWindowToken(IBinder binder) {
+        final WindowToken token = getWindowToken(binder);
+        if (token == null) {
+            return null;
+        }
+        return token.asAppWindowToken();
+    }
+
+    void setWindowToken(IBinder binder, WindowToken token) {
+        final DisplayContent dc = mService.mRoot.getWindowTokenDisplay(token);
+        if (dc != null) {
+            // We currently don't support adding a window token to the display if the display
+            // already has the binder mapped to another token. If there is a use case for supporting
+            // this moving forward we will either need to merge the WindowTokens some how or have
+            // the binder map to a list of window tokens.
+            throw new IllegalArgumentException("Can't map token=" + token + " to display=" + this
+                    + " already mapped to display=" + dc + " tokens=" + dc.mTokenMap);
+        }
+        mTokenMap.put(binder, token);
+
+        if (token.asAppWindowToken() == null) {
+            // Add non-app token to container hierarchy on the display. App tokens are added through
+            // the parent container managing them (e.g. Tasks).
+            mNonAppWindowContainers.addChild(token, null);
+        }
+    }
+
+    WindowToken removeWindowToken(IBinder binder) {
+        final WindowToken token = mTokenMap.remove(binder);
+        if (token != null && token.asAppWindowToken() == null) {
+            mNonAppWindowContainers.removeChild(token);
+        }
+        return token;
+    }
+
     Display getDisplay() {
         return mDisplay;
     }
@@ -191,19 +260,19 @@
     }
 
     boolean isPrivate() {
-        return (mDisplay.getFlags() & Display.FLAG_PRIVATE) != 0;
+        return (mDisplay.getFlags() & FLAG_PRIVATE) != 0;
     }
 
     TaskStack getHomeStack() {
-        if (mHomeStack == null && mDisplayId == Display.DEFAULT_DISPLAY) {
+        if (mHomeStack == null && mDisplayId == DEFAULT_DISPLAY) {
             Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
         }
         return mHomeStack;
     }
 
     TaskStack getStackById(int stackId) {
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            final TaskStack stack = mChildren.get(i);
+        for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+            final TaskStack stack = mTaskStackContainers.get(i);
             if (stack.mStackId == stackId) {
                 return stack;
             }
@@ -228,8 +297,8 @@
      * bounds were updated.
      */
     void updateStackBoundsAfterConfigChange(@NonNull List<Integer> changedStackList) {
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            final TaskStack stack = mChildren.get(i);
+        for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+            final TaskStack stack = mTaskStackContainers.get(i);
             if (stack.updateBoundsAfterConfigChange()) {
                 changedStackList.add(stack.mStackId);
             }
@@ -294,8 +363,8 @@
     void updateDisplayInfo() {
         mDisplay.getDisplayInfo(mDisplayInfo);
         mDisplay.getMetrics(mDisplayMetrics);
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            mChildren.get(i).updateDisplayInfo(null);
+        for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+            mTaskStackContainers.get(i).updateDisplayInfo(null);
         }
     }
 
@@ -318,8 +387,7 @@
     void getLogicalDisplayRect(Rect out) {
         // Uses same calculation as in LogicalDisplay#configureDisplayInTransactionLocked.
         final int orientation = mDisplayInfo.rotation;
-        boolean rotated = (orientation == Surface.ROTATION_90
-                || orientation == Surface.ROTATION_270);
+        boolean rotated = (orientation == ROTATION_90 || orientation == ROTATION_270);
         final int physWidth = rotated ? mBaseDisplayHeight : mBaseDisplayWidth;
         final int physHeight = rotated ? mBaseDisplayWidth : mBaseDisplayHeight;
         int width = mDisplayInfo.logicalWidth;
@@ -329,51 +397,53 @@
         out.set(left, top, left + width, top + height);
     }
 
+    private void getLogicalDisplayRect(Rect out, int orientation) {
+        getLogicalDisplayRect(out);
+
+        // Rotate the Rect if needed.
+        final int currentRotation = mDisplayInfo.rotation;
+        final int rotationDelta = deltaRotation(currentRotation, orientation);
+        if (rotationDelta == ROTATION_90 || rotationDelta == ROTATION_270) {
+            createRotationMatrix(rotationDelta, mBaseDisplayWidth, mBaseDisplayHeight, mTmpMatrix);
+            mTmpRectF.set(out);
+            mTmpMatrix.mapRect(mTmpRectF);
+            mTmpRectF.round(out);
+        }
+    }
+
     void getContentRect(Rect out) {
         out.set(mContentRect);
     }
 
     /** Refer to {@link WindowManagerService#attachStack(int, int, boolean)} */
     void attachStack(TaskStack stack, boolean onTop) {
-        if (stack.mStackId == HOME_STACK_ID) {
-            if (mHomeStack != null) {
-                throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
-            }
-            mHomeStack = stack;
-        }
-        addChild(stack, onTop);
+        mTaskStackContainers.attachStack(stack, onTop);
     }
 
     void moveStack(TaskStack stack, boolean toTop) {
-        if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
-            // This stack is always-on-top silly...
-            Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
-            return;
-        }
-
-        if (!mChildren.contains(stack)) {
-            Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
-        }
-        removeChild(stack);
-        addChild(stack, toTop);
+        mTaskStackContainers.moveStack(stack, toTop);
     }
 
-    private void addChild(TaskStack stack, boolean toTop) {
-        int addIndex = toTop ? mChildren.size() : 0;
+    @Override
+    protected void addChild(DisplayChildWindowContainer child,
+            Comparator<DisplayChildWindowContainer> comparator) {
+        throw new UnsupportedOperationException("See DisplayChildWindowContainer");
+    }
 
-        if (toTop
-                && mService.isStackVisibleLocked(PINNED_STACK_ID)
-                && stack.mStackId != PINNED_STACK_ID) {
-            // The pinned stack is always the top most stack (always-on-top) when it is visible.
-            // So, stack is moved just below the pinned stack.
-            addIndex--;
-            TaskStack topStack = mChildren.get(addIndex);
-            if (topStack.mStackId != PINNED_STACK_ID) {
-                throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
-            }
+    @Override
+    protected void addChild(DisplayChildWindowContainer child, int index) {
+        throw new UnsupportedOperationException("See DisplayChildWindowContainer");
+    }
+
+    @Override
+    protected void removeChild(DisplayChildWindowContainer child) {
+        // Only allow removal of direct children from this display if the display is in the process
+        // of been removed.
+        if (mRemovingDisplay) {
+            super.removeChild(child);
+            return;
         }
-        addChild(stack, addIndex);
-        setLayoutNeeded();
+        throw new UnsupportedOperationException("See DisplayChildWindowContainer");
     }
 
     /**
@@ -385,8 +455,8 @@
     }
 
     int taskIdFromPoint(int x, int y) {
-        for (int stackNdx = mChildren.size() - 1; stackNdx >= 0; --stackNdx) {
-            final TaskStack stack = mChildren.get(stackNdx);
+        for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = mTaskStackContainers.get(stackNdx);
             final int taskId = stack.taskIdFromPoint(x, y);
             if (taskId != -1) {
                 return taskId;
@@ -400,10 +470,10 @@
      * Returns null if the touch doesn't fall into a resizing area.
      */
     Task findTaskForResizePoint(int x, int y) {
-        final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
+        final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
         mTmpTaskForResizePointSearchResult.reset();
-        for (int stackNdx = mChildren.size() - 1; stackNdx >= 0; --stackNdx) {
-            TaskStack stack = mChildren.get(stackNdx);
+        for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = mTaskStackContainers.get(stackNdx);
             if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
                 return null;
             }
@@ -418,10 +488,10 @@
 
     void setTouchExcludeRegion(Task focusedTask) {
         mTouchExcludeRegion.set(mBaseDisplayRect);
-        final int delta = mService.dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
+        final int delta = dipToPixel(RESIZE_HANDLE_WIDTH_IN_DP, mDisplayMetrics);
         mTmpRect2.setEmpty();
-        for (int stackNdx = mChildren.size() - 1; stackNdx >= 0; --stackNdx) {
-            final TaskStack stack = mChildren.get(stackNdx);
+        for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = mTaskStackContainers.get(stackNdx);
             stack.setTouchExcludeRegion(
                     focusedTask, delta, mTouchExcludeRegion, mContentRect, mTmpRect2);
         }
@@ -465,16 +535,16 @@
             }
         }
 
-        for (int stackNdx = mChildren.size() - 1; stackNdx >= 0; --stackNdx) {
-            mChildren.get(stackNdx).switchUser();
+        for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
+            mTaskStackContainers.get(stackNdx).switchUser();
         }
 
         rebuildAppWindowList();
     }
 
     void resetAnimationBackgroundAnimator() {
-        for (int stackNdx = mChildren.size() - 1; stackNdx >= 0; --stackNdx) {
-            mChildren.get(stackNdx).resetAnimationBackgroundAnimator();
+        for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
+            mTaskStackContainers.get(stackNdx).resetAnimationBackgroundAnimator();
         }
     }
 
@@ -505,12 +575,17 @@
 
     @Override
     void removeImmediately() {
-        super.removeImmediately();
-        if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
-        mDimLayerController.close();
-        if (mDisplayId == Display.DEFAULT_DISPLAY) {
-            mService.unregisterPointerEventListener(mTapDetector);
-            mService.unregisterPointerEventListener(mService.mMousePositionTracker);
+        mRemovingDisplay = true;
+        try {
+            super.removeImmediately();
+            if (DEBUG_DISPLAY) Slog.v(TAG_WM, "Removing display=" + this);
+            mDimLayerController.close();
+            if (mDisplayId == DEFAULT_DISPLAY) {
+                mService.unregisterPointerEventListener(mTapDetector);
+                mService.unregisterPointerEventListener(mService.mMousePositionTracker);
+            }
+        } finally {
+            mRemovingDisplay = false;
         }
     }
 
@@ -531,8 +606,8 @@
             float dividerAnimationTarget) {
         boolean updated = false;
 
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            final TaskStack stack = mChildren.get(i);
+        for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+            final TaskStack stack = mTaskStackContainers.get(i);
             if (stack == null || !stack.isAdjustedForIme()) {
                 continue;
             }
@@ -560,8 +635,8 @@
 
     boolean clearImeAdjustAnimation() {
         boolean changed = false;
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            final TaskStack stack = mChildren.get(i);
+        for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+            final TaskStack stack = mTaskStackContainers.get(i);
             if (stack != null && stack.isAdjustedForIme()) {
                 stack.resetAdjustedForIme(true /* adjustBoundsNow */);
                 changed  = true;
@@ -571,8 +646,8 @@
     }
 
     void beginImeAdjustAnimation() {
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            final TaskStack stack = mChildren.get(i);
+        for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+            final TaskStack stack = mTaskStackContainers.get(i);
             if (stack.isVisible() && stack.isAdjustedForIme()) {
                 stack.beginImeAdjustAnimation();
             }
@@ -601,8 +676,8 @@
         // - If IME is not visible, divider is not moved and is normal width.
 
         if (imeVisible && dockVisible && (imeOnTop || imeOnBottom) && !dockMinimized) {
-            for (int i = mChildren.size() - 1; i >= 0; --i) {
-                final TaskStack stack = mChildren.get(i);
+            for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+                final TaskStack stack = mTaskStackContainers.get(i);
                 final boolean isDockedOnBottom = stack.getDockSide() == DOCKED_BOTTOM;
                 if (stack.isVisible() && (imeOnBottom || isDockedOnBottom)) {
                     stack.setAdjustedForIme(imeWin, imeOnBottom && imeHeightChanged);
@@ -613,8 +688,8 @@
             mDividerControllerLocked.setAdjustedForIme(
                     imeOnBottom /*ime*/, true /*divider*/, true /*animate*/, imeWin, imeHeight);
         } else {
-            for (int i = mChildren.size() - 1; i >= 0; --i) {
-                final TaskStack stack = mChildren.get(i);
+            for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+                final TaskStack stack = mTaskStackContainers.get(i);
                 stack.resetAdjustedForIme(!dockVisible);
             }
             mDividerControllerLocked.setAdjustedForIme(
@@ -623,39 +698,23 @@
     }
 
     void prepareFreezingTaskBounds() {
-        for (int stackNdx = mChildren.size() - 1; stackNdx >= 0; --stackNdx) {
-            final TaskStack stack = mChildren.get(stackNdx);
+        for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = mTaskStackContainers.get(stackNdx);
             stack.prepareFreezingTaskBounds();
         }
     }
 
     void rotateBounds(int oldRotation, int newRotation, Rect bounds) {
-        final int rotationDelta = DisplayContent.deltaRotation(oldRotation, newRotation);
-        getLogicalDisplayRect(mTmpRect);
-        switch (rotationDelta) {
-            case Surface.ROTATION_0:
-                mTmpRect2.set(bounds);
-                break;
-            case Surface.ROTATION_90:
-                mTmpRect2.top = mTmpRect.bottom - bounds.right;
-                mTmpRect2.left = bounds.top;
-                mTmpRect2.right = mTmpRect2.left + bounds.height();
-                mTmpRect2.bottom = mTmpRect2.top + bounds.width();
-                break;
-            case Surface.ROTATION_180:
-                mTmpRect2.top = mTmpRect.bottom - bounds.bottom;
-                mTmpRect2.left = mTmpRect.right - bounds.right;
-                mTmpRect2.right = mTmpRect2.left + bounds.width();
-                mTmpRect2.bottom = mTmpRect2.top + bounds.height();
-                break;
-            case Surface.ROTATION_270:
-                mTmpRect2.top = bounds.left;
-                mTmpRect2.left = mTmpRect.right - bounds.bottom;
-                mTmpRect2.right = mTmpRect2.left + bounds.height();
-                mTmpRect2.bottom = mTmpRect2.top + bounds.width();
-                break;
-        }
-        bounds.set(mTmpRect2);
+        getLogicalDisplayRect(mTmpRect, newRotation);
+
+        // Compute a transform matrix to undo the coordinate space transformation,
+        // and present the window at the same physical position it previously occupied.
+        final int deltaRotation = deltaRotation(newRotation, oldRotation);
+        createRotationMatrix(deltaRotation, mTmpRect.width(), mTmpRect.height(), mTmpMatrix);
+
+        mTmpRectF.set(bounds);
+        mTmpMatrix.mapRect(mTmpRectF);
+        mTmpRectF.round(bounds);
     }
 
     static int deltaRotation(int oldRotation, int newRotation) {
@@ -664,6 +723,35 @@
         return delta;
     }
 
+    private static void createRotationMatrix(int rotation, float displayWidth, float displayHeight,
+            Matrix outMatrix) {
+        // For rotations without Z-ordering we don't need the target rectangle's position.
+        createRotationMatrix(rotation, 0 /* rectLeft */, 0 /* rectTop */, displayWidth,
+                displayHeight, outMatrix);
+    }
+
+    static void createRotationMatrix(int rotation, float rectLeft, float rectTop,
+            float displayWidth, float displayHeight, Matrix outMatrix) {
+        switch (rotation) {
+            case ROTATION_0:
+                outMatrix.reset();
+                break;
+            case ROTATION_270:
+                outMatrix.setRotate(270, 0, 0);
+                outMatrix.postTranslate(0, displayHeight);
+                outMatrix.postTranslate(rectTop, 0);
+                break;
+            case ROTATION_180:
+                outMatrix.reset();
+                break;
+            case ROTATION_90:
+                outMatrix.setRotate(90, 0, 0);
+                outMatrix.postTranslate(displayWidth, 0);
+                outMatrix.postTranslate(-rectTop, rectLeft);
+                break;
+        }
+    }
+
     public void dump(String prefix, PrintWriter pw) {
         pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
         final String subPrefix = "  " + prefix;
@@ -695,8 +783,8 @@
 
         pw.println();
         pw.println("  Application tokens in top down Z order:");
-        for (int stackNdx = mChildren.size() - 1; stackNdx >= 0; --stackNdx) {
-            final TaskStack stack = mChildren.get(stackNdx);
+        for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
+            final TaskStack stack = mTaskStackContainers.get(stackNdx);
             stack.dump(prefix + "  ", pw);
         }
 
@@ -705,7 +793,7 @@
             pw.println();
             pw.println("  Exiting tokens:");
             for (int i = mExitingTokens.size() - 1; i >= 0; i--) {
-                WindowToken token = mExitingTokens.get(i);
+                final WindowToken token = mExitingTokens.get(i);
                 pw.print("  Exiting #"); pw.print(i);
                 pw.print(' '); pw.print(token);
                 pw.println(':');
@@ -720,11 +808,11 @@
 
     @Override
     public String toString() {
-        return getName() + " stacks=" + mChildren;
+        return "Display " + mDisplayId + " info=" + mDisplayInfo + " stacks=" + mChildren;
     }
 
     String getName() {
-        return "Display " + mDisplayId + " info=" + mDisplayInfo;
+        return "Display " + mDisplayId + " name=\"" + mDisplayInfo.name + "\"";
     }
 
     /**
@@ -792,8 +880,7 @@
         return true;
     }
 
-    void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus,
-                                                   WindowState newFocus) {
+    void scheduleToastWindowsTimeoutIfNeededLocked(WindowState oldFocus, WindowState newFocus) {
         if (oldFocus == null || (newFocus != null && newFocus.mOwnerUid == oldFocus.mOwnerUid)) {
             return;
         }
@@ -877,15 +964,15 @@
         }
 
         // No windows from this token on this display
-        if (mService.localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
+        if (localLOGV) Slog.v(TAG_WM, "Figuring out where to add app window "
                 + client.asBinder() + " (token=" + this + ")");
 
         final WindowToken wToken = win.mToken;
 
         // Figure out where the window should go, based on the order of applications.
         mTmpGetWindowOnDisplaySearchResult.reset();
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            final TaskStack stack = mChildren.get(i);
+        for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+            final TaskStack stack = mTaskStackContainers.get(i);
             stack.getWindowOnDisplayBeforeToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
             if (mTmpGetWindowOnDisplaySearchResult.reachedToken) {
                 // We have reach the token we are interested in. End search.
@@ -899,7 +986,7 @@
         // position; else we need to look some more.
         if (pos != null) {
             // Move behind any windows attached to this one.
-            final WindowToken atoken = mService.mTokenMap.get(pos.mClient.asBinder());
+            final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
             if (atoken != null) {
                 tokenWindowList = getTokenWindowsOnDisplay(atoken);
                 final int NC = tokenWindowList.size();
@@ -916,8 +1003,8 @@
 
         // Continue looking down until we find the first token that has windows on this display.
         mTmpGetWindowOnDisplaySearchResult.reset();
-        for (int i = mChildren.size() - 1; i >= 0; --i) {
-            final TaskStack stack = mChildren.get(i);
+        for (int i = mTaskStackContainers.size() - 1; i >= 0; --i) {
+            final TaskStack stack = mTaskStackContainers.get(i);
             stack.getWindowOnDisplayAfterToken(this, wToken, mTmpGetWindowOnDisplaySearchResult);
             if (mTmpGetWindowOnDisplaySearchResult.foundWindow != null) {
                 // We have found a window after the token. End search.
@@ -929,7 +1016,7 @@
 
         if (pos != null) {
             // Move in front of any windows attached to this one.
-            final WindowToken atoken = mService.mTokenMap.get(pos.mClient.asBinder());
+            final WindowToken atoken = getWindowToken(pos.mClient.asBinder());
             if (atoken != null) {
                 final WindowState top = atoken.getTopWindow();
                 if (top != null && top.mSubLayer >= 0) {
@@ -987,6 +1074,10 @@
         mService.mWindowsChanged = true;
     }
 
+    void addToWindowList(WindowState win, int index) {
+        mWindows.add(index, win);
+    }
+
     void addChildWindowToWindowList(WindowState win) {
         final WindowState parentWindow = win.getParentWindow();
 
@@ -1081,18 +1172,18 @@
         // First add all of the exiting app tokens...  these are no longer in the main app list,
         // but still have windows shown. We put them in the back because now that the animation is
         // over we no longer will care about them.
-        final int numStacks = mChildren.size();
+        final int numStacks = mTaskStackContainers.size();
         for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            AppTokenList exitingAppTokens = mChildren.get(stackNdx).mExitingAppTokens;
+            AppTokenList exitingAppTokens = mTaskStackContainers.get(stackNdx).mExitingAppTokens;
             int NT = exitingAppTokens.size();
             for (int j = 0; j < NT; j++) {
-                i = exitingAppTokens.get(j).rebuildWindowListUnchecked(this, i);
+                i = exitingAppTokens.get(j).rebuildWindowListUnchecked(i);
             }
         }
 
         // And add in the still active app tokens in Z order.
         for (int stackNdx = 0; stackNdx < numStacks; ++stackNdx) {
-            i = mChildren.get(stackNdx).rebuildWindowList(this, i);
+            i = mTaskStackContainers.get(stackNdx).rebuildWindowList(i);
         }
 
         i -= lastBelow;
@@ -1238,6 +1329,39 @@
         }
     }
 
+    void dumpTokens(PrintWriter pw, boolean dumpAll) {
+        if (mTokenMap.isEmpty()) {
+            return;
+        }
+        pw.println("  Display #" + mDisplayId);
+        final Iterator<WindowToken> it = mTokenMap.values().iterator();
+        while (it.hasNext()) {
+            final WindowToken token = it.next();
+            pw.print("  ");
+            pw.print(token);
+            if (dumpAll) {
+                pw.println(':');
+                token.dump(pw, "    ");
+            } else {
+                pw.println();
+            }
+        }
+    }
+
+    void enableSurfaceTrace(FileDescriptor fd) {
+        for (int i = mWindows.size() - 1; i >= 0; i--) {
+            final WindowState win = mWindows.get(i);
+            win.mWinAnimator.enableSurfaceTrace(fd);
+        }
+    }
+
+    void disableSurfaceTrace() {
+        for (int i = mWindows.size() - 1; i >= 0; i--) {
+            final WindowState win = mWindows.get(i);
+            win.mWinAnimator.disableSurfaceTrace();
+        }
+    }
+
     static final class GetWindowOnDisplaySearchResult {
         boolean reachedToken;
         WindowState foundWindow;
@@ -1258,17 +1382,89 @@
         }
     }
 
-    void enableSurfaceTrace(FileDescriptor fd) {
-        for (int i = mWindows.size()  - 1; i >= 0; i--) {
-            final WindowState win = mWindows.get(i);
-            win.mWinAnimator.enableSurfaceTrace(fd);
+    /**
+     * Base class for any direct child window container of {@link #DisplayContent} need to inherit
+     * from. This is mainly a pass through class that allows {@link #DisplayContent} to have
+     * homogeneous children type which is currently required by sub-classes of
+     * {@link WindowContainer} class.
+     */
+    static class DisplayChildWindowContainer<E extends WindowContainer> extends WindowContainer<E> {
+
+        int size() {
+            return mChildren.size();
+        }
+
+        E get(int index) {
+            return mChildren.get(index);
+        }
+
+        @Override
+        boolean fillsParent() {
+            return true;
+        }
+
+        @Override
+        boolean isVisible() {
+            return true;
         }
     }
 
-    void disableSurfaceTrace() {
-        for (int i = mWindows.size()  - 1; i >= 0; i--) {
-            final WindowState win = mWindows.get(i);
-            win.mWinAnimator.disableSurfaceTrace();
+    /**
+     * Window container class that contains all containers on this display relating to Apps.
+     * I.e Activities.
+     */
+    private class TaskStackContainers extends DisplayChildWindowContainer<TaskStack> {
+
+        void attachStack(TaskStack stack, boolean onTop) {
+            if (stack.mStackId == HOME_STACK_ID) {
+                if (mHomeStack != null) {
+                    throw new IllegalArgumentException("attachStack: HOME_STACK_ID (0) not first.");
+                }
+                mHomeStack = stack;
+            }
+            addChild(stack, onTop);
+            stack.onDisplayChanged(DisplayContent.this);
         }
+
+        void moveStack(TaskStack stack, boolean toTop) {
+            if (StackId.isAlwaysOnTop(stack.mStackId) && !toTop) {
+                // This stack is always-on-top silly...
+                Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + stack + " to bottom");
+                return;
+            }
+
+            if (!mChildren.contains(stack)) {
+                Slog.wtf(TAG_WM, "moving stack that was not added: " + stack, new Throwable());
+            }
+            removeChild(stack);
+            addChild(stack, toTop);
+        }
+
+        private void addChild(TaskStack stack, boolean toTop) {
+            int addIndex = toTop ? mChildren.size() : 0;
+
+            if (toTop
+                    && mService.isStackVisibleLocked(PINNED_STACK_ID)
+                    && stack.mStackId != PINNED_STACK_ID) {
+                // The pinned stack is always the top most stack (always-on-top) when it is visible.
+                // So, stack is moved just below the pinned stack.
+                addIndex--;
+                TaskStack topStack = mChildren.get(addIndex);
+                if (topStack.mStackId != PINNED_STACK_ID) {
+                    throw new IllegalStateException("Pinned stack isn't top stack??? " + mChildren);
+                }
+            }
+            addChild(stack, addIndex);
+            setLayoutNeeded();
+        }
+
+    }
+
+    /**
+     * Window container class that contains all containers on this display that are not related to
+     * Apps. E.g. status bar.
+     */
+    private static class NonAppWindowContainers extends DisplayChildWindowContainer<WindowToken> {
+
     }
 }
diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java
index a5387bd..065a3dc 100644
--- a/services/core/java/com/android/server/wm/InputMonitor.java
+++ b/services/core/java/com/android/server/wm/InputMonitor.java
@@ -16,6 +16,8 @@
 
 package com.android.server.wm;
 
+import static android.view.WindowManager.INPUT_CONSUMER_PIP;
+import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
@@ -25,14 +27,17 @@
 import android.app.ActivityManagerNative;
 import android.graphics.Rect;
 import android.os.Debug;
+import android.os.Looper;
 import android.os.RemoteException;
+import android.util.ArrayMap;
 import android.util.Log;
 import android.util.Slog;
-import android.view.Display;
 import android.view.InputChannel;
+import android.view.InputEventReceiver;
 import android.view.KeyEvent;
 import android.view.WindowManager;
 
+import android.view.WindowManagerPolicy;
 import com.android.server.input.InputApplicationHandle;
 import com.android.server.input.InputManagerService;
 import com.android.server.input.InputWindowHandle;
@@ -69,10 +74,103 @@
     private final Object mInputDevicesReadyMonitor = new Object();
     private boolean mInputDevicesReady;
 
+    /**
+     * The set of input consumer added to the window manager by name, which consumes input events
+     * for the windows below it.
+     */
+    private final ArrayMap<String, InputConsumerImpl> mInputConsumers = new ArrayMap();
+
+    private static final class EventReceiverInputConsumer extends InputConsumerImpl
+            implements WindowManagerPolicy.InputConsumer {
+        private InputMonitor mInputMonitor;
+        private final InputEventReceiver mInputEventReceiver;
+
+        EventReceiverInputConsumer(WindowManagerService service, InputMonitor monitor,
+                                   Looper looper, String name,
+                                   InputEventReceiver.Factory inputEventReceiverFactory) {
+            super(service, name, null);
+            mInputMonitor = monitor;
+            mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
+                    mClientChannel, looper);
+        }
+
+        @Override
+        public void dismiss() {
+            synchronized (mService.mWindowMap) {
+                if (mInputMonitor.destroyInputConsumer(mWindowHandle.name)) {
+                    mInputEventReceiver.dispose();
+                }
+            }
+        }
+    }
+
     public InputMonitor(WindowManagerService service) {
         mService = service;
     }
 
+    void addInputConsumer(String name, InputConsumerImpl consumer) {
+        mInputConsumers.put(name, consumer);
+        updateInputWindowsLw(true /* force */);
+    }
+
+    boolean destroyInputConsumer(String name) {
+        if (disposeInputConsumer(mInputConsumers.remove(name))) {
+            updateInputWindowsLw(true /* force */);
+            return true;
+        }
+        return false;
+    }
+
+    private boolean disposeInputConsumer(InputConsumerImpl consumer) {
+        if (consumer != null) {
+            consumer.disposeChannelsLw();
+            return true;
+        }
+        return false;
+    }
+
+    InputConsumerImpl getInputConsumer(String name) {
+        return mInputConsumers.get(name);
+    }
+
+    void layoutInputConsumers(int dw, int dh) {
+        for (int i = mInputConsumers.size() - 1; i >= 0; i--) {
+            mInputConsumers.valueAt(i).layout(dw, dh);
+        }
+    }
+
+    WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
+            InputEventReceiver.Factory inputEventReceiverFactory) {
+        if (mInputConsumers.containsKey(name)) {
+            throw new IllegalStateException("Existing input consumer found with name: " + name);
+        }
+
+        final EventReceiverInputConsumer consumer = new EventReceiverInputConsumer(mService,
+                this, looper, name, inputEventReceiverFactory);
+        addInputConsumer(name, consumer);
+        return consumer;
+    }
+
+    void createInputConsumer(String name, InputChannel inputChannel) {
+        if (mInputConsumers.containsKey(name)) {
+            throw new IllegalStateException("Existing input consumer found with name: " + name);
+        }
+
+        final InputConsumerImpl consumer = new InputConsumerImpl(mService, name, inputChannel);
+        switch (name) {
+            case INPUT_CONSUMER_WALLPAPER:
+                consumer.mWindowHandle.hasWallpaper = true;
+                break;
+            case INPUT_CONSUMER_PIP:
+                // The touchable region of the Pip input window is cropped to the bounds of the
+                // stack, and we need FLAG_NOT_TOUCH_MODAL to ensure other events fall through
+                consumer.mWindowHandle.layoutParamsFlags |=
+                        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
+                break;
+        }
+        addInputConsumer(name, consumer);
+    }
+
     /* Notifies the window manager about a broken input channel.
      *
      * Called by the InputManager.
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index 9bd3118..4622329 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -19,8 +19,10 @@
 import android.app.AppOpsManager;
 import android.content.res.Configuration;
 import android.graphics.Rect;
+import android.hardware.power.V1_0.PowerHint;
 import android.os.Binder;
 import android.os.Debug;
+import android.os.IBinder;
 import android.os.ParcelFileDescriptor;
 import android.os.PowerManager;
 import android.os.RemoteException;
@@ -41,9 +43,15 @@
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.LinkedList;
 
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
+import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
+import static android.view.Display.DEFAULT_DISPLAY;
+import static android.view.WindowManager.INPUT_CONSUMER_NAVIGATION;
+import static android.view.WindowManager.INPUT_CONSUMER_PIP;
+import static android.view.WindowManager.INPUT_CONSUMER_WALLPAPER;
 import static android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
 import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
@@ -57,8 +65,11 @@
 import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_LAYOUT;
 import static android.view.WindowManagerPolicy.FINISH_LAYOUT_REDO_WALLPAPER;
 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
+import static com.android.server.wm.AppTransition.TRANSIT_UNSET;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_ADD_REMOVE;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_APP_TRANSITIONS;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DISPLAY;
+import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_KEEP_SCREEN_ON;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_LAYOUT_REPEATS;
@@ -78,6 +89,7 @@
 import static com.android.server.wm.WindowManagerService.H.REPORT_LOSING_FOCUS;
 import static com.android.server.wm.WindowManagerService.H.SEND_NEW_CONFIGURATION;
 import static com.android.server.wm.WindowManagerService.LAYOUT_REPEAT_THRESHOLD;
+import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL;
 import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_PLACING_SURFACES;
 import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES;
 import static com.android.server.wm.WindowManagerService.WINDOWS_FREEZING_SCREENS_NONE;
@@ -136,6 +148,15 @@
 
     private final LinkedList<AppWindowToken> mTmpUpdateAllDrawn = new LinkedList();
 
+    private final ArrayList<WindowToken> mTmpTokensList = new ArrayList();
+
+    // Collection of binder tokens mapped to their window type we are allowed to create window
+    // tokens for but that are not current attached to any display. We need to track this here
+    // because a binder token can be added through {@link WindowManagerService#addWindowToken},
+    // but we don't know what display windows for the token will be added to until
+    // {@link WindowManagerService#addWindow} is called.
+    private final HashMap<IBinder, Integer> mUnattachedBinderTokens = new HashMap();
+
     // State for the RemoteSurfaceTrace system used in testing. If this is enabled SurfaceControl
     // instances will be replaced with an instance that writes a binary representation of all
     // commands to mSurfaceTraceFd.
@@ -178,7 +199,7 @@
         return dc;
     }
 
-    private DisplayContent getDisplayContent(int displayId) {
+    DisplayContent getDisplayContent(int displayId) {
         for (int i = mChildren.size() - 1; i >= 0; --i) {
             final DisplayContent current = mChildren.get(i);
             if (current.getDisplayId() == displayId) {
@@ -252,7 +273,6 @@
         }
 
         if (!attachedToDisplay) {
-            stack.attachDisplayContent(dc);
             dc.attachStack(stack, onTop);
         }
 
@@ -337,6 +357,202 @@
         return null;
     }
 
+    /** Return the window token associated with the input binder token on the input display */
+    WindowToken getWindowToken(IBinder binder, DisplayContent dc) {
+        final WindowToken token = dc.getWindowToken(binder);
+        if (token != null) {
+            return token;
+        }
+
+        // There is no window token mapped to the binder on the display. Create and map a window
+        // token if it is currently allowed.
+        if (!mUnattachedBinderTokens.containsKey(binder)) {
+            return null;
+        }
+
+        final int type = mUnattachedBinderTokens.get(binder);
+        return new WindowToken(mService, binder, type, true, dc);
+    }
+
+    /** Returns all window tokens mapped to the input binder. */
+    ArrayList<WindowToken> getWindowTokens(IBinder binder) {
+        mTmpTokensList.clear();
+        for (int i = mChildren.size() - 1; i >= 0; --i) {
+            final DisplayContent dc = mChildren.get(i);
+            final WindowToken token = dc.getWindowToken(binder);
+            if (token != null) {
+                mTmpTokensList.add(token);
+            }
+        }
+        return mTmpTokensList;
+    }
+
+    /**
+     * Returns the app window token for the input binder if it exist in the system.
+     * NOTE: Only one AppWindowToken is allowed to exist in the system for a binder token, since
+     * AppWindowToken represents an activity which can only exist on one display.
+     */
+    AppWindowToken getAppWindowToken(IBinder binder) {
+        for (int i = mChildren.size() - 1; i >= 0; --i) {
+            final DisplayContent dc = mChildren.get(i);
+            final AppWindowToken atoken = dc.getAppWindowToken(binder);
+            if (atoken != null) {
+                return atoken;
+            }
+        }
+        return null;
+    }
+
+    /** Returns the display object the input window token is currently mapped on. */
+    DisplayContent getWindowTokenDisplay(WindowToken token) {
+        if (token == null) {
+            return null;
+        }
+
+        for (int i = mChildren.size() - 1; i >= 0; --i) {
+            final DisplayContent dc = mChildren.get(i);
+            final WindowToken current = dc.getWindowToken(token.token);
+            if (current == token) {
+                return dc;
+            }
+        }
+
+        return null;
+    }
+
+    void addWindowToken(IBinder binder, int type) {
+        if (mUnattachedBinderTokens.containsKey(binder)) {
+            Slog.w(TAG_WM, "addWindowToken: Attempted to add existing binder token: " + binder);
+            return;
+        }
+
+        final ArrayList<WindowToken> tokens = getWindowTokens(binder);
+
+        if (!tokens.isEmpty()) {
+            Slog.w(TAG_WM, "addWindowToken: Attempted to add binder token: " + binder
+                    + " for already created window tokens: " + tokens);
+            return;
+        }
+
+        mUnattachedBinderTokens.put(binder, type);
+
+        // TODO(multi-display): By default we add this to the default display, but maybe we
+        // should provide an API for a token to be added to any display?
+        final WindowToken token = new WindowToken(mService, binder, type, true,
+                getDisplayContent(DEFAULT_DISPLAY));
+        if (type == TYPE_WALLPAPER) {
+            mService.mWallpaperControllerLocked.addWallpaperToken(token);
+        }
+    }
+
+    ArrayList<WindowToken> removeWindowToken(IBinder binder) {
+        mUnattachedBinderTokens.remove(binder);
+
+        mTmpTokensList.clear();
+        for (int i = mChildren.size() - 1; i >= 0; --i) {
+            final DisplayContent dc = mChildren.get(i);
+            final WindowToken token = dc.removeWindowToken(binder);
+            if (token != null) {
+                mTmpTokensList.add(token);
+            }
+        }
+        return mTmpTokensList;
+    }
+
+    /**
+     * Removed the mapping to the input binder for the system if it no longer as a window token
+     * associated with it on any display.
+     */
+    void removeWindowTokenIfPossible(IBinder binder) {
+        for (int i = mChildren.size() - 1; i >= 0; --i) {
+            final DisplayContent dc = mChildren.get(i);
+            final WindowToken token = dc.getWindowToken(binder);
+            if (token != null) {
+                return;
+            }
+        }
+
+        mUnattachedBinderTokens.remove(binder);
+    }
+
+    void removeAppToken(IBinder binder) {
+        final ArrayList<WindowToken> removedTokens = removeWindowToken(binder);
+        if (removedTokens == null || removedTokens.isEmpty()) {
+            Slog.w(TAG_WM, "removeAppToken: Attempted to remove non-existing token: " + binder);
+            return;
+        }
+
+        for (int i = removedTokens.size() - 1; i >= 0; --i) {
+            WindowToken wtoken = removedTokens.get(i);
+            AppWindowToken appToken = wtoken.asAppWindowToken();
+
+            if (appToken == null) {
+                Slog.w(TAG_WM,
+                        "Attempted to remove non-App token: " + binder + " wtoken=" + wtoken);
+                continue;
+            }
+
+            AppWindowToken startingToken = null;
+
+            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + appToken);
+
+            boolean delayed = appToken.setVisibility(null, false, TRANSIT_UNSET, true,
+                    appToken.voiceInteraction);
+
+            mService.mOpeningApps.remove(appToken);
+            appToken.waitingToShow = false;
+            if (mService.mClosingApps.contains(appToken)) {
+                delayed = true;
+            } else if (mService.mAppTransition.isTransitionSet()) {
+                mService.mClosingApps.add(appToken);
+                delayed = true;
+            }
+
+            if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app " + appToken
+                    + " delayed=" + delayed
+                    + " animation=" + appToken.mAppAnimator.animation
+                    + " animating=" + appToken.mAppAnimator.animating);
+
+            if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
+                    + appToken + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
+
+            final TaskStack stack = appToken.mTask.mStack;
+            if (delayed && !appToken.isEmpty()) {
+                // set the token aside because it has an active animation to be finished
+                if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
+                        "removeAppToken make exiting: " + appToken);
+                stack.mExitingAppTokens.add(appToken);
+                appToken.mIsExiting = true;
+            } else {
+                // Make sure there is no animation running on this token, so any windows associated
+                // with it will be removed as soon as their animations are complete
+                appToken.mAppAnimator.clearAnimation();
+                appToken.mAppAnimator.animating = false;
+                appToken.removeIfPossible();
+            }
+
+            appToken.removed = true;
+            if (appToken.startingData != null) {
+                startingToken = appToken;
+            }
+            appToken.stopFreezingScreen(true, true);
+            if (mService.mFocusedApp == appToken) {
+                if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + appToken);
+                mService.mFocusedApp = null;
+                mService.updateFocusedWindowLocked(
+                        UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
+                mService.mInputMonitor.setFocusedAppLw(null);
+            }
+
+            if (!delayed) {
+                appToken.updateReportedVisibilityLocked();
+            }
+
+            // Will only remove if startingToken non null.
+            mService.scheduleRemoveStartingWindowLocked(startingToken);
+        }
+    }
+
     // TODO: Users would have their own window containers under the display container?
     void switchUser() {
         final int count = mChildren.size();
@@ -488,8 +704,16 @@
     }
 
     void updateInputWindows(InputMonitor inputMonitor, WindowState inputFocus, boolean inDrag) {
-        boolean addInputConsumerHandle = mService.mInputConsumer != null;
-        boolean addWallpaperInputConsumerHandle = mService.mWallpaperInputConsumer != null;
+        final InputConsumerImpl navInputConsumer =
+                mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_NAVIGATION);
+        final InputConsumerImpl pipInputConsumer =
+                mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_PIP);
+        final InputConsumerImpl wallpaperInputConsumer =
+                mService.mInputMonitor.getInputConsumer(INPUT_CONSUMER_WALLPAPER);
+        boolean addInputConsumerHandle = navInputConsumer != null;
+        boolean addPipInputConsumerHandle = pipInputConsumer != null;
+        boolean addWallpaperInputConsumerHandle = wallpaperInputConsumer != null;
+        final Rect pipTouchableBounds = addPipInputConsumerHandle ? new Rect() : null;
         final WallpaperController wallpaperController = mService.mWallpaperControllerLocked;
         boolean disableWallpaperTouchEvents = false;
 
@@ -506,9 +730,20 @@
                     // Skip this window because it cannot possibly receive input.
                     continue;
                 }
+
+                if (addPipInputConsumerHandle
+                        && child.getStackId() == PINNED_STACK_ID
+                        && inputWindowHandle.layer <= pipInputConsumer.mWindowHandle.layer) {
+                    // Update the bounds of the Pip input consumer to match the Pinned stack
+                    child.getStack().getBounds(pipTouchableBounds);
+                    pipInputConsumer.mWindowHandle.touchableRegion.set(pipTouchableBounds);
+                    inputMonitor.addInputWindowHandle(pipInputConsumer.mWindowHandle);
+                    addPipInputConsumerHandle = false;
+                }
+
                 if (addInputConsumerHandle
-                        && inputWindowHandle.layer <= mService.mInputConsumer.mWindowHandle.layer) {
-                    inputMonitor.addInputWindowHandle(mService.mInputConsumer.mWindowHandle);
+                        && inputWindowHandle.layer <= navInputConsumer.mWindowHandle.layer) {
+                    inputMonitor.addInputWindowHandle(navInputConsumer.mWindowHandle);
                     addInputConsumerHandle = false;
                 }
 
@@ -516,8 +751,7 @@
                     if (child.mAttrs.type == WindowManager.LayoutParams.TYPE_WALLPAPER &&
                             child.isVisibleLw()) {
                         // Add the wallpaper input consumer above the first visible wallpaper.
-                        inputMonitor.addInputWindowHandle(
-                                mService.mWallpaperInputConsumer.mWindowHandle);
+                        inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
                         addWallpaperInputConsumerHandle = false;
                     }
                 }
@@ -551,7 +785,7 @@
 
         if (addWallpaperInputConsumerHandle) {
             // No visible wallpaper found, add the wallpaper input consumer at the end.
-            inputMonitor.addInputWindowHandle(mService.mWallpaperInputConsumer.mWindowHandle);
+            inputMonitor.addInputWindowHandle(wallpaperInputConsumer.mWindowHandle);
         }
     }
 
@@ -890,7 +1124,7 @@
         if (mSustainedPerformanceModeCurrent != mSustainedPerformanceModeEnabled) {
             mSustainedPerformanceModeEnabled = mSustainedPerformanceModeCurrent;
             mService.mPowerManagerInternal.powerHint(
-                    mService.mPowerManagerInternal.POWER_HINT_SUSTAINED_PERFORMANCE_MODE,
+                    PowerHint.SUSTAINED_PERFORMANCE,
                     (mSustainedPerformanceModeEnabled ? 1 : 0));
         }
 
@@ -929,7 +1163,7 @@
             }
             mService.mPendingRemove.toArray(mService.mPendingRemoveTmp);
             mService.mPendingRemove.clear();
-            DisplayContentList displayList = new DisplayContentList();
+            ArrayList<DisplayContent> displayList = new ArrayList();
             for (i = 0; i < N; i++) {
                 final WindowState w = mService.mPendingRemoveTmp[i];
                 w.removeImmediately();
@@ -1360,6 +1594,13 @@
         }
     }
 
+    void dumpTokens(PrintWriter pw, boolean dumpAll) {
+        pw.println("  All tokens:");
+        for (int i = mChildren.size() - 1; i >= 0; --i) {
+            mChildren.get(i).dumpTokens(pw, dumpAll);
+        }
+    }
+
     @Override
     String getName() {
         return "ROOT";
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index f6598c1..19c9b7d 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -20,7 +20,6 @@
 import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
 import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.HOME_STACK_ID;
-import static android.content.pm.ActivityInfo.RESIZE_MODE_CROP_WINDOWS;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_STACK;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
 import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
@@ -35,7 +34,6 @@
 import android.view.DisplayInfo;
 import android.view.Surface;
 
-import android.view.SurfaceControl;
 import com.android.server.EventLogTags;
 
 import java.io.PrintWriter;
@@ -43,17 +41,17 @@
 class Task extends WindowContainer<AppWindowToken> implements DimLayer.DimLayerUser {
     static final String TAG = TAG_WITH_CLASS_NAME ? "Task" : TAG_WM;
     // Return value from {@link setBounds} indicating no change was made to the Task bounds.
-    static final int BOUNDS_CHANGE_NONE = 0;
+    private static final int BOUNDS_CHANGE_NONE = 0;
     // Return value from {@link setBounds} indicating the position of the Task bounds changed.
-    static final int BOUNDS_CHANGE_POSITION = 1;
+    private static final int BOUNDS_CHANGE_POSITION = 1;
     // Return value from {@link setBounds} indicating the size of the Task bounds changed.
-    static final int BOUNDS_CHANGE_SIZE = 1 << 1;
+    private static final int BOUNDS_CHANGE_SIZE = 1 << 1;
 
     // TODO: Track parent marks like this in WindowContainer.
     TaskStack mStack;
     final int mTaskId;
     final int mUserId;
-    boolean mDeferRemoval = false;
+    private boolean mDeferRemoval = false;
     final WindowManagerService mService;
 
     // Content limits relative to the DisplayContent this sits in.
@@ -65,7 +63,7 @@
     private final Rect mTempInsetBounds = new Rect();
 
     // Device rotation as of the last time {@link #mBounds} was set.
-    int mRotation;
+    private int mRotation;
 
     // Whether mBounds is fullscreen
     private boolean mFillsParent = true;
@@ -164,7 +162,8 @@
         stack.addTask(this, toTop);
     }
 
-    void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) {
+    void positionTaskInStack(TaskStack stack, int position, Rect bounds,
+            Configuration overrideConfig) {
         if (mStack != null && stack != mStack) {
             if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId
                     + " from stack=" + mStack);
@@ -172,7 +171,7 @@
             mStack.removeChild(this);
         }
         stack.positionTask(this, position, showForAllUsers());
-        resizeLocked(bounds, config, false /* force */);
+        resizeLocked(bounds, overrideConfig, false /* force */);
 
         for (int activityNdx = mChildren.size() - 1; activityNdx >= 0; --activityNdx) {
             mChildren.get(activityNdx).notifyMovedInStack();
@@ -278,8 +277,7 @@
     }
 
     boolean isResizeable() {
-        return !mHomeTask
-                && (ActivityInfo.isResizeableMode(mResizeMode) || mService.mForceResizableTasks);
+        return ActivityInfo.isResizeableMode(mResizeMode) || mService.mForceResizableTasks;
     }
 
     boolean isOnTopLauncher() {
@@ -287,7 +285,7 @@
     }
 
     boolean cropWindowsToStackBounds() {
-        return !mHomeTask && (isResizeable() || mResizeMode == RESIZE_MODE_CROP_WINDOWS);
+        return isResizeable();
     }
 
     boolean isHomeTask() {
@@ -561,7 +559,7 @@
 
     @Override
     public boolean dimFullscreen() {
-        return isHomeTask() || isFullscreen();
+        return isFullscreen();
     }
 
     boolean isFullscreen() {
diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java
index e98fc39..56fdc33 100644
--- a/services/core/java/com/android/server/wm/TaskStack.java
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -94,16 +94,16 @@
     private boolean mFillsParent = true;
 
     // Device rotation as of the last time {@link #mBounds} was set.
-    int mRotation;
+    private int mRotation;
 
     /** Density as of last time {@link #mBounds} was set. */
-    int mDensity;
+    private int mDensity;
 
     /** Support for non-zero {@link android.view.animation.Animation#getBackgroundColor()} */
-    DimLayer mAnimationBackgroundSurface;
+    private DimLayer mAnimationBackgroundSurface;
 
     /** The particular window with an Animation with non-zero background color. */
-    WindowStateAnimator mAnimationBackgroundAnimator;
+    private WindowStateAnimator mAnimationBackgroundAnimator;
 
     /** Application tokens that are exiting, but still on screen for animations. */
     final AppTokenList mExitingAppTokens = new AppTokenList();
@@ -606,12 +606,12 @@
         }
     }
 
-    void attachDisplayContent(DisplayContent displayContent) {
+    void onDisplayChanged(DisplayContent dc) {
         if (mDisplayContent != null) {
-            throw new IllegalStateException("attachDisplayContent: Already attached");
+            throw new IllegalStateException("onDisplayChanged: Already attached");
         }
 
-        mDisplayContent = displayContent;
+        mDisplayContent = dc;
         mAnimationBackgroundSurface = new DimLayer(mService, this, mDisplayContent.getDisplayId(),
                 "animation background stackId=" + mStackId);
 
@@ -625,7 +625,7 @@
             // not fullscreen. If it's fullscreen, it means that we are in the transition of
             // dismissing it, so we must not resize this stack.
             bounds = new Rect();
-            displayContent.getLogicalDisplayRect(mTmpRect);
+            dc.getLogicalDisplayRect(mTmpRect);
             mTmpRect2.setEmpty();
             if (dockedStack != null) {
                 dockedStack.getRawBounds(mTmpRect2);
@@ -638,6 +638,8 @@
         }
 
         updateDisplayInfo(bounds);
+
+        super.onDisplayChanged(dc);
     }
 
     void getStackDockedModeBoundsLocked(Rect outBounds, boolean ignoreVisibility) {
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 902f4ae..981b813 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -254,6 +254,17 @@
         }
     }
 
+    /**
+     * Notify that the display this container is on has changed.
+     * @param dc The new display this container is on.
+     */
+    void onDisplayChanged(DisplayContent dc) {
+        for (int i = mChildren.size() - 1; i >= 0; --i) {
+            final WindowContainer child = mChildren.get(i);
+            child.onDisplayChanged(dc);
+        }
+    }
+
     void setWaitingForDrawnIfResizingChanged() {
         for (int i = mChildren.size() - 1; i >= 0; --i) {
             final WindowContainer wc = mChildren.get(i);
@@ -472,16 +483,15 @@
 
     /**
      * Rebuilds the WindowList for the input display content.
-     * @param dc The display content to rebuild the window list for.
      * @param addIndex The index in the window list to add the next entry to.
      * @return The next index in the window list to.
      */
     // TODO: Hoping we can get rid of WindowList so this method wouldn't be needed.
-    int rebuildWindowList(DisplayContent dc, int addIndex) {
+    int rebuildWindowList(int addIndex) {
         final int count = mChildren.size();
         for (int i = 0; i < count; i++) {
             final WindowContainer wc = mChildren.get(i);
-            addIndex = wc.rebuildWindowList(dc, addIndex);
+            addIndex = wc.rebuildWindowList(addIndex);
         }
         return addIndex;
     }
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index 12ad09c..3ad43ce 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -163,7 +163,6 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 
 import static android.Manifest.permission.MANAGE_APP_TOKENS;
@@ -403,11 +402,6 @@
     final HashMap<IBinder, WindowState> mWindowMap = new HashMap<>();
 
     /**
-     * Mapping from a token IBinder to a WindowToken object.
-     */
-    final HashMap<IBinder, WindowToken> mTokenMap = new HashMap<>();
-
-    /**
      * List of window tokens that have finished starting their application,
      * and now need to have the policy remove their windows.
      */
@@ -427,17 +421,6 @@
     final ArrayList<AppWindowToken> mWindowReplacementTimeouts = new ArrayList<>();
 
     /**
-     * The input consumer added to the window manager which consumes input events to windows below
-     * it.
-     */
-    InputConsumerImpl mInputConsumer;
-
-    /**
-     * The input consumer added to the window manager before all wallpaper windows.
-     */
-    InputConsumerImpl mWallpaperInputConsumer;
-
-    /**
      * Windows that are being resized.  Used so we can tell the client about
      * the resize after closing the transaction in which we resized the
      * underlying surface.
@@ -912,7 +895,7 @@
         @Override
         public void onAppTransitionFinishedLocked(IBinder token) {
             mH.sendEmptyMessage(H.NOTIFY_APP_TRANSITION_FINISHED);
-            AppWindowToken atoken = findAppWindowToken(token);
+            final AppWindowToken atoken = mRoot.getAppWindowToken(token);
             if (atoken == null) {
                 return;
             }
@@ -1263,7 +1246,8 @@
             // excercise to find the appropriate input method target (used for animations
             // and dialog adjustments), but for purposes of Z ordering we simply wish to
             // place it above the docked divider. Unless it is already above the divider.
-            WindowState dockedDivider = w.mDisplayContent.mDividerControllerLocked.getWindow();
+            final WindowState dockedDivider =
+                    w.getDisplayContent().mDividerControllerLocked.getWindow();
             if (dockedDivider != null && dockedDivider.isVisibleLw()) {
                 int dividerIndex = windows.indexOf(dockedDivider);
                 if (dividerIndex > 0 && dividerIndex > i) {
@@ -1281,21 +1265,6 @@
         return -1;
     }
 
-    void addInputMethodWindowToListLocked(WindowState win) {
-        int pos = findDesiredInputMethodWindowIndexLocked(true);
-        if (pos >= 0) {
-            if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(
-                    TAG_WM, "Adding input method window " + win + " at " + pos);
-            // TODO(multidisplay): IMEs are only supported on the default display.
-            getDefaultWindowListLocked().add(pos, win);
-            mWindowsChanged = true;
-            moveInputMethodDialogsLocked(pos + 1);
-            return;
-        }
-        win.mToken.addWindow(win);
-        moveInputMethodDialogsLocked(pos);
-    }
-
     private void reAddWindowToListInOrderLocked(WindowState win) {
         win.mToken.addWindow(win);
         // This is a hack to get all of the child windows added as well at the right position. Child
@@ -1310,7 +1279,7 @@
         }
     }
 
-    void logWindowList(final WindowList windows, String prefix) {
+    private void logWindowList(final WindowList windows, String prefix) {
         int N = windows.size();
         while (N > 0) {
             N--;
@@ -1535,7 +1504,8 @@
             final boolean hasParent = parentWindow != null;
             // Use existing parent window token for child windows since they go in the same token
             // as there parent window so we can apply the same policy on them.
-            WindowToken token = mTokenMap.get(hasParent ? parentWindow.mAttrs.token : attrs.token);
+            WindowToken token = mRoot.getWindowToken(
+                    hasParent ? parentWindow.mAttrs.token : attrs.token, displayContent);
             // If this is a child window, we want to apply the same type checking rules as the
             // parent window type.
             final int rootType = hasParent ? parentWindow.mAttrs.type : type;
@@ -1587,7 +1557,7 @@
                         return WindowManagerGlobal.ADD_BAD_APP_TOKEN;
                     }
                 }
-                token = new WindowToken(this, attrs.token, -1, false);
+                token = new WindowToken(this, attrs.token, -1, false, displayContent);
             } else if (rootType >= FIRST_APPLICATION_WINDOW && rootType <= LAST_APPLICATION_WINDOW) {
                 atoken = token.asAppWindowToken();
                 if (atoken == null) {
@@ -1655,11 +1625,11 @@
                 // It is not valid to use an app token with other system types; we will
                 // instead make a new token for it (as if null had been passed in for the token).
                 attrs.token = null;
-                token = new WindowToken(this, null, -1, false);
+                token = new WindowToken(this, null, -1, false, displayContent);
             }
 
             WindowState win = new WindowState(this, session, client, token, parentWindow,
-                    appOp[0], seq, attrs, viewVisibility, displayContent, session.mUid);
+                    appOp[0], seq, attrs, viewVisibility, session.mUid);
             if (win.mDeathRecipient == null) {
                 // Client has apparently died, so there is no reason to
                 // continue.
@@ -1750,7 +1720,7 @@
             if (type == TYPE_INPUT_METHOD) {
                 win.mGivenInsetsPending = true;
                 mInputMethodWindow = win;
-                addInputMethodWindowToListLocked(win);
+                win.mToken.addImeWindow(win);
                 imMayMove = false;
             } else if (type == TYPE_INPUT_METHOD_DIALOG) {
                 mInputMethodDialogs.add(win);
@@ -1984,7 +1954,7 @@
         }
     }
 
-    public void removeWindow(Session session, IWindow client) {
+    void removeWindow(Session session, IWindow client) {
         synchronized(mWindowMap) {
             WindowState win = windowForClientLocked(session, client, false);
             if (win == null) {
@@ -2025,7 +1995,7 @@
         // Window will already be removed from token before this post clean-up method is called.
         if (token.isEmpty()) {
             if (!token.explicit) {
-                mTokenMap.remove(token.token);
+                token.removeImmediately();
             } else if (atoken != null) {
                 // TODO: Should this be moved into AppWindowToken.removeWindow? Might go away after
                 // re-factor.
@@ -2750,14 +2720,6 @@
         return !mDisplayFrozen && mDisplayEnabled && mPolicy.isScreenOn();
     }
 
-    AppWindowToken findAppWindowToken(IBinder token) {
-        WindowToken wtoken = mTokenMap.get(token);
-        if (wtoken == null) {
-            return null;
-        }
-        return wtoken.asAppWindowToken();
-    }
-
     @Override
     public void addWindowToken(IBinder token, int type) {
         if (!checkCallingPermission(MANAGE_APP_TOKENS, "addWindowToken()")) {
@@ -2765,15 +2727,7 @@
         }
 
         synchronized(mWindowMap) {
-            WindowToken wtoken = mTokenMap.get(token);
-            if (wtoken != null) {
-                Slog.w(TAG_WM, "Attempted to add existing input method token: " + token);
-                return;
-            }
-            wtoken = new WindowToken(this, token, type, true);
-            if (type == TYPE_WALLPAPER) {
-                mWallpaperControllerLocked.addWallpaperToken(wtoken);
-            }
+            mRoot.addWindowToken(token, type);
         }
     }
 
@@ -2784,20 +2738,28 @@
         }
 
         final long origId = Binder.clearCallingIdentity();
-        synchronized(mWindowMap) {
-            final WindowToken wtoken = mTokenMap.remove(token);
-            if (wtoken != null) {
-                wtoken.setExiting();
-                if (wtoken.windowType == TYPE_WALLPAPER) {
-                    mWallpaperControllerLocked.removeWallpaperToken(wtoken);
+        try {
+            synchronized (mWindowMap) {
+                final ArrayList<WindowToken> removedTokens = mRoot.removeWindowToken(token);
+                if (removedTokens == null || removedTokens.isEmpty()) {
+                    Slog.w(TAG_WM,
+                            "removeWindowToken: Attempted to remove non-existing token: " + token);
+                    return;
                 }
 
-                mInputMonitor.updateInputWindowsLw(true /*force*/);
-            } else {
-                Slog.w(TAG_WM, "Attempted to remove non-existing token: " + token);
+                for (int i = removedTokens.size() - 1; i >= 0; --i) {
+                    final WindowToken wtoken = removedTokens.get(i);
+                    wtoken.setExiting();
+                    if (wtoken.windowType == TYPE_WALLPAPER) {
+                        mWallpaperControllerLocked.removeWallpaperToken(wtoken);
+                    }
+
+                    mInputMonitor.updateInputWindowsLw(true /*force*/);
+                }
             }
+        } finally {
+            Binder.restoreCallingIdentity(origId);
         }
-        Binder.restoreCallingIdentity(origId);
     }
 
     private Task createTaskLocked(int taskId, int stackId, int userId, AppWindowToken atoken,
@@ -2841,12 +2803,18 @@
         }
 
         synchronized(mWindowMap) {
-            AppWindowToken atoken = findAppWindowToken(token.asBinder());
+            AppWindowToken atoken = mRoot.getAppWindowToken(token.asBinder());
             if (atoken != null) {
                 Slog.w(TAG_WM, "Attempted to add existing app token: " + token);
                 return;
             }
-            atoken = new AppWindowToken(this, token, voiceInteraction);
+
+            final TaskStack stack = mStackIdToStack.get(stackId);
+            if (stack == null) {
+                throw new IllegalArgumentException("addAppToken: invalid stackId=" + stackId);
+            }
+
+            atoken = new AppWindowToken(this, token, voiceInteraction, stack.getDisplayContent());
             atoken.inputDispatchingTimeoutNanos = inputDispatchingTimeoutNanos;
             atoken.setFillsParent(fullscreen);
             atoken.showForAllUsers = showForAllUsers;
@@ -2882,7 +2850,7 @@
         }
 
         synchronized(mWindowMap) {
-            final AppWindowToken atoken = findAppWindowToken(token);
+            final AppWindowToken atoken = mRoot.getAppWindowToken(token);
             if (atoken == null) {
                 Slog.w(TAG_WM, "Attempted to set task id of non-existing app token: " + token);
                 return;
@@ -2998,12 +2966,10 @@
         Configuration config = null;
 
         if (updateOrientationFromAppTokensLocked(false)) {
-            // If we changed the orientation but mOrientationChangeComplete is
-            // already true, we used seamless rotation, and we don't need
-            // to freeze the screen.
-            if (freezeThisOneIfNeeded != null &&
-                    !mRoot.mOrientationChangeComplete) {
-                final AppWindowToken atoken = findAppWindowToken(freezeThisOneIfNeeded);
+            // If we changed the orientation but mOrientationChangeComplete is already true,
+            // we used seamless rotation, and we don't need to freeze the screen.
+            if (freezeThisOneIfNeeded != null && !mRoot.mOrientationChangeComplete) {
+                final AppWindowToken atoken = mRoot.getAppWindowToken(freezeThisOneIfNeeded);
                 if (atoken != null) {
                     atoken.startFreezingScreen();
                 }
@@ -3117,7 +3083,7 @@
         }
 
         synchronized(mWindowMap) {
-            final AppWindowToken atoken = findAppWindowToken(token.asBinder());
+            final AppWindowToken atoken = mRoot.getAppWindowToken(token.asBinder());
             if (atoken == null) {
                 Slog.w(TAG_WM, "Attempted to set orientation of non-existing app token: " + token);
                 return;
@@ -3130,9 +3096,9 @@
     @Override
     public int getAppOrientation(IApplicationToken token) {
         synchronized(mWindowMap) {
-            AppWindowToken wtoken = findAppWindowToken(token.asBinder());
+            final AppWindowToken wtoken = mRoot.getAppWindowToken(token.asBinder());
             if (wtoken == null) {
-                return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
+                return SCREEN_ORIENTATION_UNSPECIFIED;
             }
 
             return wtoken.getOrientation();
@@ -3161,7 +3127,7 @@
                 if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Clearing focused app, was " + mFocusedApp);
                 newFocus = null;
             } else {
-                newFocus = findAppWindowToken(token);
+                newFocus = mRoot.getAppWindowToken(token);
                 if (newFocus == null) {
                     Slog.w(TAG_WM, "Attempted to set focus to non-existing app token: " + token);
                 }
@@ -3353,7 +3319,7 @@
                     TAG_WM, "setAppStartingWindow: token=" + token + " pkg=" + pkg
                     + " transferFrom=" + transferFrom);
 
-            AppWindowToken wtoken = findAppWindowToken(token);
+            final AppWindowToken wtoken = mRoot.getAppWindowToken(token);
             if (wtoken == null) {
                 Slog.w(TAG_WM, "Attempted to set icon of non-existing app token: " + token);
                 return false;
@@ -3440,14 +3406,14 @@
 
     public void removeAppStartingWindow(IBinder token) {
         synchronized (mWindowMap) {
-            final AppWindowToken wtoken = mTokenMap.get(token).asAppWindowToken();
+            final AppWindowToken wtoken = mRoot.getAppWindowToken(token);
             scheduleRemoveStartingWindowLocked(wtoken);
         }
     }
 
     public void setAppFullscreen(IBinder token, boolean toOpaque) {
         synchronized (mWindowMap) {
-            final AppWindowToken atoken = findAppWindowToken(token);
+            final AppWindowToken atoken = mRoot.getAppWindowToken(token);
             if (atoken != null) {
                 atoken.setFillsParent(toOpaque);
                 setWindowOpaqueLocked(token, toOpaque);
@@ -3463,7 +3429,7 @@
     }
 
     private void setWindowOpaqueLocked(IBinder token, boolean isOpaque) {
-        final AppWindowToken wtoken = findAppWindowToken(token);
+        final AppWindowToken wtoken = mRoot.getAppWindowToken(token);
         if (wtoken != null) {
             final WindowState win = wtoken.findMainWindow();
             if (win != null) {
@@ -3488,8 +3454,7 @@
         }
 
         synchronized(mWindowMap) {
-            final AppWindowToken wtoken;
-            wtoken = findAppWindowToken(token);
+            final AppWindowToken wtoken = mRoot.getAppWindowToken(token);
             if (wtoken == null) {
                 Slog.w(TAG_WM, "Attempted to notify resumed of non-existing app token: " + token);
                 return;
@@ -3506,7 +3471,7 @@
 
         synchronized(mWindowMap) {
             final AppWindowToken wtoken;
-            wtoken = findAppWindowToken(token);
+            wtoken = mRoot.getAppWindowToken(token);
             if (wtoken == null) {
                 Slog.w(TAG_WM, "Attempted to notify stopped of non-existing app token: " + token);
                 return;
@@ -3524,7 +3489,7 @@
         AppWindowToken wtoken;
 
         synchronized(mWindowMap) {
-            wtoken = findAppWindowToken(token);
+            wtoken = mRoot.getAppWindowToken(token);
             if (wtoken == null) {
                 Slog.w(TAG_WM, "Attempted to set visibility of non-existing app token: " + token);
                 return;
@@ -3644,7 +3609,7 @@
                 return;
             }
 
-            final AppWindowToken wtoken = findAppWindowToken(token);
+            final AppWindowToken wtoken = mRoot.getAppWindowToken(token);
             if (wtoken == null || wtoken.appToken == null) {
                 Slog.w(TAG_WM, "Attempted to freeze screen with non-existing app token: " + wtoken);
                 return;
@@ -3662,7 +3627,7 @@
         }
 
         synchronized(mWindowMap) {
-            final AppWindowToken wtoken = findAppWindowToken(token);
+            final AppWindowToken wtoken = mRoot.getAppWindowToken(token);
             if (wtoken == null || wtoken.appToken == null) {
                 return;
             }
@@ -3680,71 +3645,14 @@
             throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
         }
 
-        AppWindowToken wtoken = null;
-        AppWindowToken startingToken = null;
-        boolean delayed = false;
-
         final long origId = Binder.clearCallingIdentity();
-        synchronized(mWindowMap) {
-            WindowToken basewtoken = mTokenMap.remove(token);
-            if (basewtoken != null && (wtoken = basewtoken.asAppWindowToken()) != null) {
-                if (DEBUG_APP_TRANSITIONS) Slog.v(TAG_WM, "Removing app token: " + wtoken);
-                delayed = wtoken.setVisibility(null, false,
-                        TRANSIT_UNSET, true, wtoken.voiceInteraction);
-                mOpeningApps.remove(wtoken);
-                wtoken.waitingToShow = false;
-                if (mClosingApps.contains(wtoken)) {
-                    delayed = true;
-                } else if (mAppTransition.isTransitionSet()) {
-                    mClosingApps.add(wtoken);
-                    delayed = true;
-                }
-                if (DEBUG_APP_TRANSITIONS) Slog.v(
-                        TAG_WM, "Removing app " + wtoken + " delayed=" + delayed
-                        + " animation=" + wtoken.mAppAnimator.animation
-                        + " animating=" + wtoken.mAppAnimator.animating);
-                if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM, "removeAppToken: "
-                        + wtoken + " delayed=" + delayed + " Callers=" + Debug.getCallers(4));
-                final TaskStack stack = wtoken.mTask.mStack;
-                if (delayed && !wtoken.isEmpty()) {
-                    // set the token aside because it has an active animation to be finished
-                    if (DEBUG_ADD_REMOVE || DEBUG_TOKEN_MOVEMENT) Slog.v(TAG_WM,
-                            "removeAppToken make exiting: " + wtoken);
-                    stack.mExitingAppTokens.add(wtoken);
-                    wtoken.mIsExiting = true;
-                } else {
-                    // Make sure there is no animation running on this token,
-                    // so any windows associated with it will be removed as
-                    // soon as their animations are complete
-                    wtoken.mAppAnimator.clearAnimation();
-                    wtoken.mAppAnimator.animating = false;
-                    wtoken.removeIfPossible();
-                }
-
-                wtoken.removed = true;
-                if (wtoken.startingData != null) {
-                    startingToken = wtoken;
-                }
-                wtoken.stopFreezingScreen(true, true);
-                if (mFocusedApp == wtoken) {
-                    if (DEBUG_FOCUS_LIGHT) Slog.v(TAG_WM, "Removing focused app token:" + wtoken);
-                    mFocusedApp = null;
-                    updateFocusedWindowLocked(UPDATE_FOCUS_NORMAL, true /*updateInputWindows*/);
-                    mInputMonitor.setFocusedAppLw(null);
-                }
-            } else {
-                Slog.w(TAG_WM, "Attempted to remove non-existing app token: " + token);
+        try {
+            synchronized(mWindowMap) {
+                mRoot.removeAppToken(token);
             }
-
-            if (!delayed && wtoken != null) {
-                wtoken.updateReportedVisibilityLocked();
-            }
-
-            // Will only remove if startingToken non null.
-            scheduleRemoveStartingWindowLocked(startingToken);
+        } finally {
+            Binder.restoreCallingIdentity(origId);
         }
-        Binder.restoreCallingIdentity(origId);
-
     }
 
     void scheduleRemoveStartingWindowLocked(AppWindowToken wtoken) {
@@ -4040,7 +3948,7 @@
     }
 
     public void positionTaskInStack(int taskId, int stackId, int position, Rect bounds,
-            Configuration config) {
+            Configuration overrideConfig) {
         synchronized (mWindowMap) {
             if (DEBUG_STACK) Slog.i(TAG_WM, "positionTaskInStack: positioning taskId=" + taskId
                     + " in stackId=" + stackId + " at " + position);
@@ -4056,7 +3964,7 @@
                         "positionTaskInStack: could not find stackId=" + stackId);
                 return;
             }
-            task.positionTaskInStack(stack, position, bounds, config);
+            task.positionTaskInStack(stack, position, bounds, overrideConfig);
             final DisplayContent displayContent = stack.getDisplayContent();
             displayContent.setLayoutNeeded();
             mWindowPlacerLocked.performSurfacePlacement();
@@ -5496,7 +5404,8 @@
         final WindowList windows = displayContent.getWindowList();
 
         final int oldRotation = mRotation;
-        boolean rotateSeamlessly = mPolicy.shouldRotateSeamlessly(oldRotation, mRotation);
+        int rotation = mPolicy.rotationForOrientationLw(mLastOrientation, mRotation);
+        boolean rotateSeamlessly = mPolicy.shouldRotateSeamlessly(oldRotation, rotation);
 
         if (rotateSeamlessly) {
             for (int i = windows.size() - 1; i >= 0; i--) {
@@ -5529,7 +5438,6 @@
         //       an orientation that has different metrics than it expected.
         //       eg. Portrait instead of Landscape.
 
-        int rotation = mPolicy.rotationForOrientationLw(mLastOrientation, mRotation);
         boolean altOrientation = !mPolicy.rotationHasCompatibleMetricsLw(
                 mLastOrientation, rotation);
 
@@ -5542,7 +5450,7 @@
 
         if (mRotation == rotation && mAltOrientation == altOrientation) {
             // No change.
-             return false;
+            return false;
         }
 
         if (DEBUG_ORIENTATION) {
@@ -6616,9 +6524,11 @@
         }
 
         synchronized (mWindowMap) {
-            WindowToken token = mTokenMap.get(_token);
-            if (token != null) {
-                mInputMonitor.pauseDispatchingLw(token);
+            final ArrayList<WindowToken> tokens = mRoot.getWindowTokens(_token);
+            if (tokens != null && !tokens.isEmpty()) {
+                for (int i = tokens.size() - 1; i >= 0; --i) {
+                    mInputMonitor.pauseDispatchingLw(tokens.get(i));
+                }
             }
         }
     }
@@ -6630,9 +6540,11 @@
         }
 
         synchronized (mWindowMap) {
-            WindowToken token = mTokenMap.get(_token);
-            if (token != null) {
-                mInputMonitor.resumeDispatchingLw(token);
+            final ArrayList<WindowToken> tokens = mRoot.getWindowTokens(_token);
+            if (tokens != null && !tokens.isEmpty()) {
+                for (int i = tokens.size() - 1; i >= 0; --i) {
+                    mInputMonitor.resumeDispatchingLw(tokens.get(i));
+                }
             }
         }
     }
@@ -8530,68 +8442,25 @@
         }
     }
 
-    private static final class HideNavInputConsumer extends InputConsumerImpl
-            implements WindowManagerPolicy.InputConsumer {
-        private final InputEventReceiver mInputEventReceiver;
-
-        HideNavInputConsumer(WindowManagerService service, Looper looper,
-                             InputEventReceiver.Factory inputEventReceiverFactory) {
-            super(service, "input consumer", null);
-            mInputEventReceiver = inputEventReceiverFactory.createInputEventReceiver(
-                    mClientChannel, looper);
-        }
-
-        @Override
-        public void dismiss() {
-            if (mService.removeInputConsumer()) {
-                synchronized (mService.mWindowMap) {
-                    mInputEventReceiver.dispose();
-                    disposeChannelsLw();
-                }
-            }
-        }
-    }
-
     @Override
-    public WindowManagerPolicy.InputConsumer addInputConsumer(Looper looper,
+    public WindowManagerPolicy.InputConsumer createInputConsumer(Looper looper, String name,
             InputEventReceiver.Factory inputEventReceiverFactory) {
         synchronized (mWindowMap) {
-            HideNavInputConsumer inputConsumerImpl = new HideNavInputConsumer(
-                    this, looper, inputEventReceiverFactory);
-            mInputConsumer = inputConsumerImpl;
-            mInputMonitor.updateInputWindowsLw(true);
-            return inputConsumerImpl;
-        }
-    }
-
-    boolean removeInputConsumer() {
-        synchronized (mWindowMap) {
-            if (mInputConsumer != null) {
-                mInputConsumer = null;
-                mInputMonitor.updateInputWindowsLw(true);
-                return true;
-            }
-            return false;
+            return mInputMonitor.createInputConsumer(looper, name, inputEventReceiverFactory);
         }
     }
 
     @Override
-    public void createWallpaperInputConsumer(InputChannel inputChannel) {
+    public void createInputConsumer(String name, InputChannel inputChannel) {
         synchronized (mWindowMap) {
-            mWallpaperInputConsumer = new InputConsumerImpl(this, "wallpaper input", inputChannel);
-            mWallpaperInputConsumer.mWindowHandle.hasWallpaper = true;
-            mInputMonitor.updateInputWindowsLw(true);
+            mInputMonitor.createInputConsumer(name, inputChannel);
         }
     }
 
     @Override
-    public void removeWallpaperInputConsumer() {
+    public boolean destroyInputConsumer(String name) {
         synchronized (mWindowMap) {
-            if (mWallpaperInputConsumer != null) {
-                mWallpaperInputConsumer.disposeChannelsLw();
-                mWallpaperInputConsumer = null;
-                mInputMonitor.updateInputWindowsLw(true);
-            }
+            return mInputMonitor.destroyInputConsumer(name);
         }
     }
 
@@ -8661,7 +8530,7 @@
 
     public void notifyAppRelaunching(IBinder token) {
         synchronized (mWindowMap) {
-            AppWindowToken appWindow = findAppWindowToken(token);
+            final AppWindowToken appWindow = mRoot.getAppWindowToken(token);
             if (appWindow != null) {
                 appWindow.startRelaunching();
             }
@@ -8670,7 +8539,7 @@
 
     public void notifyAppRelaunchingFinished(IBinder token) {
         synchronized (mWindowMap) {
-            AppWindowToken appWindow = findAppWindowToken(token);
+            final AppWindowToken appWindow = mRoot.getAppWindowToken(token);
             if (appWindow != null) {
                 appWindow.finishRelaunching();
             }
@@ -8679,7 +8548,7 @@
 
     public void notifyAppRelaunchesCleared(IBinder token) {
         synchronized (mWindowMap) {
-            final AppWindowToken appWindow = findAppWindowToken(token);
+            final AppWindowToken appWindow = mRoot.getAppWindowToken(token);
             if (appWindow != null) {
                 appWindow.clearRelaunching();
             }
@@ -8703,20 +8572,7 @@
 
     private void dumpTokensLocked(PrintWriter pw, boolean dumpAll) {
         pw.println("WINDOW MANAGER TOKENS (dumpsys window tokens)");
-        if (!mTokenMap.isEmpty()) {
-            pw.println("  All tokens:");
-            Iterator<WindowToken> it = mTokenMap.values().iterator();
-            while (it.hasNext()) {
-                WindowToken token = it.next();
-                pw.print("  "); pw.print(token);
-                if (dumpAll) {
-                    pw.println(':');
-                    token.dump(pw, "    ");
-                } else {
-                    pw.println();
-                }
-            }
-        }
+        mRoot.dumpTokens(pw, dumpAll);
         mWallpaperControllerLocked.dumpTokens(pw, "  ", dumpAll);
         if (!mFinishedStarting.isEmpty()) {
             pw.println();
@@ -9248,7 +9104,7 @@
      */
     public void setWillReplaceWindow(IBinder token, boolean animate) {
         synchronized (mWindowMap) {
-            final AppWindowToken appWindowToken = findAppWindowToken(token);
+            final AppWindowToken appWindowToken = mRoot.getAppWindowToken(token);
             if (appWindowToken == null || !appWindowToken.hasContentToDisplay()) {
                 Slog.w(TAG_WM, "Attempted to set replacing window on non-existing app token "
                         + token);
@@ -9270,9 +9126,9 @@
      */
     // TODO: The s at the end of the method name is the only difference with the name of the method
     // above. We should combine them or find better names.
-    public void setWillReplaceWindows(IBinder token, boolean childrenOnly) {
+    void setWillReplaceWindows(IBinder token, boolean childrenOnly) {
         synchronized (mWindowMap) {
-            final AppWindowToken appWindowToken = findAppWindowToken(token);
+            final AppWindowToken appWindowToken = mRoot.getAppWindowToken(token);
             if (appWindowToken == null || !appWindowToken.hasContentToDisplay()) {
                 Slog.w(TAG_WM, "Attempted to set replacing window on non-existing app token "
                         + token);
@@ -9300,7 +9156,7 @@
      */
     public void scheduleClearWillReplaceWindows(IBinder token, boolean replacing) {
         synchronized (mWindowMap) {
-            final AppWindowToken appWindowToken = findAppWindowToken(token);
+            final AppWindowToken appWindowToken = mRoot.getAppWindowToken(token);
             if (appWindowToken == null) {
                 Slog.w(TAG_WM, "Attempted to reset replacing window on non-existing app token "
                         + token);
@@ -9480,6 +9336,7 @@
      */
     public int getSmallestWidthForTaskBounds(Rect bounds) {
         synchronized (mWindowMap) {
+            // TODO(multi-display): Use correct display content here
             return getDefaultDisplayContentLocked().getDockedDividerController()
                     .getSmallestWidthDpForBounds(bounds);
         }
@@ -9765,9 +9622,12 @@
         public void removeWindowToken(IBinder token, boolean removeWindows) {
             synchronized(mWindowMap) {
                 if (removeWindows) {
-                    final WindowToken wtoken = mTokenMap.remove(token);
-                    if (wtoken != null) {
-                        wtoken.removeAllWindows();
+                    final ArrayList<WindowToken> removedTokens = mRoot.removeWindowToken(token);
+                    if (removedTokens != null && !removedTokens.isEmpty()) {
+                        for (int i = removedTokens.size() - 1; i >= 0; --i) {
+                            final WindowToken wtoken = removedTokens.get(i);
+                            wtoken.removeAllWindows();
+                        }
                     }
                 }
                 WindowManagerService.this.removeWindowToken(token);
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 184b6cd..a13c4d0 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -71,6 +71,7 @@
 import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION;
 import static android.view.ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_VISIBLE;
 import static android.view.WindowManager.LayoutParams.FIRST_SUB_WINDOW;
+import static android.view.WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW;
 import static android.view.WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON;
 import static android.view.WindowManager.LayoutParams.FLAG_DIM_BEHIND;
 import static android.view.WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
@@ -468,9 +469,6 @@
 
     boolean mHasSurface = false;
 
-    private boolean mNotOnAppsDisplay = false;
-    DisplayContent  mDisplayContent;
-
     /** When true this window can be displayed on screens owther than mOwnerUid's */
     private boolean mShowToOwnerOnly;
 
@@ -563,7 +561,7 @@
 
     WindowState(WindowManagerService service, Session s, IWindow c, WindowToken token,
            WindowState parentWindow, int appOp, int seq, WindowManager.LayoutParams a,
-           int viewVisibility, final DisplayContent displayContent, int ownerId) {
+           int viewVisibility, int ownerId) {
         mService = service;
         mSession = s;
         mClient = c;
@@ -587,7 +585,6 @@
         };
         mAttrs.copyFrom(a);
         mViewVisibility = viewVisibility;
-        mDisplayContent = displayContent;
         mPolicy = mService.mPolicy;
         mContext = mService.mContext;
         DeathRecipient deathRecipient = new DeathRecipient();
@@ -643,15 +640,10 @@
         }
         mIsFloatingLayer = mIsImWindow || mIsWallpaper;
 
-        if (mAppToken != null) {
-            final DisplayContent appDisplay = getDisplayContent();
-            mNotOnAppsDisplay = displayContent != appDisplay;
-
-            if (mAppToken.showForAllUsers) {
-                // Windows for apps that can show for all users should also show when the
-                // device is locked.
-                mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
-            }
+        if (mAppToken != null && mAppToken.showForAllUsers) {
+            // Windows for apps that can show for all users should also show when the device is
+            // locked.
+            mAttrs.flags |= FLAG_SHOW_WHEN_LOCKED;
         }
 
         mWinAnimator = new WindowStateAnimator(this);
@@ -666,7 +658,7 @@
         mLayer = 0;
         mInputWindowHandle = new InputWindowHandle(
                 mAppToken != null ? mAppToken.mInputApplicationHandle : null, this,
-                displayContent.getDisplayId());
+                getDisplayContent().getDisplayId());
     }
 
     void attach() {
@@ -714,6 +706,7 @@
         final Task task = getTask();
         final boolean fullscreenTask = !isInMultiWindowMode();
         final boolean windowsAreFloating = task != null && task.isFloating();
+        final DisplayContent dc = getDisplayContent();
 
         // If the task has temp inset bounds set, we have to make sure all its windows uses
         // the temp inset frame. Otherwise different display frames get applied to the main
@@ -779,8 +772,7 @@
             layoutXDiff = !mInsetFrame.isEmpty() ? mInsetFrame.left - mContainingFrame.left : 0;
             layoutYDiff = !mInsetFrame.isEmpty() ? mInsetFrame.top - mContainingFrame.top : 0;
             layoutContainingFrame = !mInsetFrame.isEmpty() ? mInsetFrame : mContainingFrame;
-            mTmpRect.set(0, 0, mDisplayContent.getDisplayInfo().logicalWidth,
-                    mDisplayContent.getDisplayInfo().logicalHeight);
+            mTmpRect.set(0, 0, dc.getDisplayInfo().logicalWidth, dc.getDisplayInfo().logicalHeight);
             subtractInsets(mDisplayFrame, layoutContainingFrame, df, mTmpRect);
             if (!layoutInParentFrame()) {
                 subtractInsets(mContainingFrame, layoutContainingFrame, pf, mTmpRect);
@@ -852,7 +844,7 @@
             mVisibleFrame.set(mContentFrame);
             mStableFrame.set(mContentFrame);
         } else if (mAttrs.type == TYPE_DOCK_DIVIDER) {
-            mDisplayContent.getDockedDividerController().positionDockedStackedDivider(mFrame);
+            dc.getDockedDividerController().positionDockedStackedDivider(mFrame);
             mContentFrame.set(mFrame);
             if (!mFrame.equals(mLastFrame)) {
                 mMovedByResize = true;
@@ -1187,20 +1179,16 @@
         }
     }
 
-    public DisplayContent getDisplayContent() {
-        if (mAppToken == null || mNotOnAppsDisplay) {
-            return mDisplayContent;
-        }
-        final TaskStack stack = getStack();
-        return stack == null ? mDisplayContent : stack.getDisplayContent();
+    DisplayContent getDisplayContent() {
+        return mToken.getDisplayContent();
     }
 
-    public DisplayInfo getDisplayInfo() {
+    DisplayInfo getDisplayInfo() {
         final DisplayContent displayContent = getDisplayContent();
         return displayContent != null ? displayContent.getDisplayInfo() : null;
     }
 
-    public int getDisplayId() {
+    int getDisplayId() {
         final DisplayContent displayContent = getDisplayContent();
         if (displayContent == null) {
             return -1;
@@ -1221,8 +1209,8 @@
         }
         // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
         // associate them with some stack to enable dimming.
-        return mAttrs.type >= WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
-                && mDisplayContent != null ? mDisplayContent.getHomeStack() : null;
+        final DisplayContent dc = getDisplayContent();
+        return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getHomeStack() : null;
     }
 
     /**
@@ -2000,12 +1988,12 @@
     }
 
     void scheduleAnimationIfDimming() {
-        if (mDisplayContent == null) {
+        final DisplayContent dc = getDisplayContent();
+        if (dc == null) {
             return;
         }
         final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
-        if (dimLayerUser != null && mDisplayContent.mDimLayerController.isDimming(
-                dimLayerUser, mWinAnimator)) {
+        if (dimLayerUser != null && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator)) {
             // Force an animation pass just to update the mDimLayer layer.
             mService.scheduleAnimationLocked();
         }
@@ -2118,16 +2106,17 @@
             return;
         }
 
+        final DisplayContent dc = getDisplayContent();
         if (!mAnimatingExit && mAppDied) {
             // If app died visible, apply a dim over the window to indicate that it's inactive
-            mDisplayContent.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
+            dc.mDimLayerController.applyDimAbove(getDimLayerUser(), mWinAnimator);
         } else if ((mAttrs.flags & FLAG_DIM_BEHIND) != 0
-                && mDisplayContent != null && !mAnimatingExit && isVisibleUnchecked()) {
-            mDisplayContent.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
+                && dc != null && !mAnimatingExit && isVisibleUnchecked()) {
+            dc.mDimLayerController.applyDimBehind(getDimLayerUser(), mWinAnimator);
         }
     }
 
-    DimLayer.DimLayerUser getDimLayerUser() {
+    private DimLayer.DimLayerUser getDimLayerUser() {
         Task task = getTask();
         if (task != null) {
             return task;
@@ -2186,8 +2175,9 @@
     }
 
     void setDisplayLayoutNeeded() {
-        if (mDisplayContent != null) {
-            mDisplayContent.setLayoutNeeded();
+        final DisplayContent dc = getDisplayContent();
+        if (dc != null) {
+            dc.setLayoutNeeded();
         }
     }
 
@@ -2908,18 +2898,19 @@
     @Override
     public boolean isDimming() {
         final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
-        return dimLayerUser != null && mDisplayContent != null &&
-                mDisplayContent.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
+        final DisplayContent dc = getDisplayContent();
+        return dimLayerUser != null && dc != null
+                && dc.mDimLayerController.isDimming(dimLayerUser, mWinAnimator);
     }
 
-    public void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
+    void setShowToOwnerOnlyLocked(boolean showToOwnerOnly) {
         mShowToOwnerOnly = showToOwnerOnly;
     }
 
     boolean isHiddenFromUserLocked() {
         // Child windows are evaluated based on their parent window.
         final WindowState win = getTopParentWindow();
-        if (win.mAttrs.type < WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW
+        if (win.mAttrs.type < FIRST_SYSTEM_WINDOW
                 && win.mAppToken != null && win.mAppToken.showForAllUsers) {
 
             // All window frames that are fullscreen extend above status bar, but some don't extend
@@ -3021,9 +3012,7 @@
             return mAppToken.mFrozenMergedConfig.peek();
         }
 
-        // TODO: Remove when all windows' hierarchies will start from same root.
-        return mAppToken != null
-                ? super.getConfiguration() : getDisplayContent().getConfiguration();
+        return super.getConfiguration();
     }
 
     void reportResized() {
@@ -3038,7 +3027,7 @@
             } else {
                 newConfig = null;
             }
-            if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING)
+            if (DEBUG_ORIENTATION && mWinAnimator.mDrawState == DRAW_PENDING)
                 Slog.i(TAG, "Resizing " + this + " WITH DRAW PENDING");
 
             final Rect frame = mFrame;
@@ -3047,7 +3036,7 @@
             final Rect visibleInsets = mLastVisibleInsets;
             final Rect stableInsets = mLastStableInsets;
             final Rect outsets = mLastOutsets;
-            final boolean reportDraw = mWinAnimator.mDrawState == WindowStateAnimator.DRAW_PENDING;
+            final boolean reportDraw = mWinAnimator.mDrawState == DRAW_PENDING;
             if (mAttrs.type != WindowManager.LayoutParams.TYPE_APPLICATION_STARTING
                     && mClient instanceof IWindow.Stub) {
                 // To prevent deadlock simulate one-way call if win.mClient is a local object.
@@ -3214,7 +3203,7 @@
      * @return Whether we reported "resize while not drag resizing" to the application.
      * @see #isResizedWhileNotDragResizing()
      */
-    boolean isResizedWhileNotDragResizingReported() {
+    private boolean isResizedWhileNotDragResizingReported() {
         return mResizedWhileNotDragResizingReported;
     }
 
@@ -3222,7 +3211,7 @@
         return mResizeMode;
     }
 
-    boolean computeDragResizing() {
+    private boolean computeDragResizing() {
         final Task task = getTask();
         if (task == null) {
             return false;
@@ -3240,7 +3229,7 @@
         // and the bounds we clip this window to might be different. In order to avoid holes, we
         // simulate that we are still resizing so the app fills the hole with the resizing
         // background.
-        return (mDisplayContent.mDividerControllerLocked.isResizing()
+        return (getDisplayContent().mDividerControllerLocked.isResizing()
                         || mAppToken != null && !mAppToken.mFrozenBounds.isEmpty()) &&
                 !task.inFreeformWorkspace() && !isGoneForLayoutLw();
 
@@ -3256,7 +3245,7 @@
         if (task != null && task.isDragResizing()) {
             mResizeMode = task.getDragResizeMode();
         } else {
-            mResizeMode = mDragResizing && mDisplayContent.mDividerControllerLocked.isResizing()
+            mResizeMode = mDragResizing && getDisplayContent().mDividerControllerLocked.isResizing()
                     ? DRAG_RESIZE_MODE_DOCKED_DIVIDER
                     : DRAG_RESIZE_MODE_FREEFORM;
         }
@@ -3276,9 +3265,6 @@
                 if (stack != null) {
                     pw.print(" stackId="); pw.print(stack.mStackId);
                 }
-                if (mNotOnAppsDisplay) {
-                    pw.print(" mNotOnAppsDisplay="); pw.print(mNotOnAppsDisplay);
-                }
                 pw.print(" mSession="); pw.print(mSession);
                 pw.print(" mClient="); pw.println(mClient.asBinder());
         pw.print(prefix); pw.print("mOwnerUid="); pw.print(mOwnerUid);
@@ -3664,9 +3650,10 @@
     }
 
     void requestUpdateWallpaperIfNeeded() {
-        if (mDisplayContent != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
-            mDisplayContent.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
-            mDisplayContent.setLayoutNeeded();
+        final DisplayContent dc = getDisplayContent();
+        if (dc != null && (mAttrs.flags & FLAG_SHOW_WALLPAPER) != 0) {
+            dc.pendingLayoutChanges |= FINISH_LAYOUT_REDO_WALLPAPER;
+            dc.setLayoutNeeded();
             mService.mWindowPlacerLocked.requestTraversal();
         }
 
@@ -3692,12 +3679,12 @@
         return winY;
     }
 
-    void transferDimToReplacement() {
+    private void transferDimToReplacement() {
         final DimLayer.DimLayerUser dimLayerUser = getDimLayerUser();
-        if (dimLayerUser != null && mDisplayContent != null) {
-            mDisplayContent.mDimLayerController.applyDim(dimLayerUser,
-                    mReplacementWindow.mWinAnimator,
-                    (mAttrs.flags & FLAG_DIM_BEHIND) != 0 ? true : false);
+        final DisplayContent dc = getDisplayContent();
+        if (dimLayerUser != null && dc != null) {
+            dc.mDimLayerController.applyDim(dimLayerUser,
+                    mReplacementWindow.mWinAnimator, (mAttrs.flags & FLAG_DIM_BEHIND) != 0);
         }
     }
 
@@ -3795,13 +3782,13 @@
         }
 
         if (mAttrs.type == TYPE_INPUT_METHOD) {
-            mDisplayContent.mDividerControllerLocked.resetImeHideRequested();
+            getDisplayContent().mDividerControllerLocked.resetImeHideRequested();
         }
 
         return true;
     }
 
-    void logPerformShow(String prefix) {
+    private void logPerformShow(String prefix) {
         if (DEBUG_VISIBILITY
                 || (DEBUG_STARTING_WINDOW && mAttrs.type == TYPE_APPLICATION_STARTING)) {
             Slog.v(TAG, prefix + this
@@ -3811,11 +3798,11 @@
                     + " during animation: policyVis=" + mPolicyVisibility
                     + " parentHidden=" + isParentWindowHidden()
                     + " tok.hiddenRequested="
-                    + (mAppToken != null ? mAppToken.hiddenRequested : false)
-                    + " tok.hidden=" + (mAppToken != null ? mAppToken.hidden : false)
+                    + (mAppToken != null && mAppToken.hiddenRequested)
+                    + " tok.hidden=" + (mAppToken != null && mAppToken.hidden)
                     + " animating=" + mWinAnimator.mAnimating
                     + " tok animating="
-                    + (mWinAnimator.mAppAnimator != null ? mWinAnimator.mAppAnimator.animating : false)
+                    + (mWinAnimator.mAppAnimator != null && mWinAnimator.mAppAnimator.animating)
                     + " Callers=" + Debug.getCallers(4));
         }
     }
@@ -3873,13 +3860,8 @@
     }
 
     @Override
-    int rebuildWindowList(DisplayContent dc, int addIndex) {
-        final DisplayContent winDisplayContent = getDisplayContent();
-        if (winDisplayContent == dc || winDisplayContent == null) {
-            mDisplayContent = dc;
-            return reAddWindow(addIndex);
-        }
-        return addIndex;
+    int rebuildWindowList(int addIndex) {
+        return reAddWindow(addIndex);
     }
 
     // TODO: come-up with a better name for this method that represents what it does.
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
index 1fae77d..53fb99b 100644
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -1750,7 +1750,7 @@
         Trace.traceEnd(Trace.TRACE_TAG_WINDOW_MANAGER);
 
         if (mWin.mAttrs.type == TYPE_INPUT_METHOD) {
-            mWin.mDisplayContent.adjustForImeIfNeeded();
+            mWin.getDisplayContent().adjustForImeIfNeeded();
             if (isEntrance) {
                 mWin.setDisplayLayoutNeeded();
                 mService.mWindowPlacerLocked.requestTraversal();
@@ -1936,24 +1936,8 @@
         // Compute a transform matrix to undo the coordinate space transformation,
         // and present the window at the same physical position it previously occupied.
         final int deltaRotation = DisplayContent.deltaRotation(newRotation, oldRotation);
-        switch (deltaRotation) {
-        case Surface.ROTATION_0:
-            transform.reset();
-            break;
-        case Surface.ROTATION_270:
-            transform.setRotate(270, 0, 0);
-            transform.postTranslate(0, displayHeight);
-            transform.postTranslate(y, 0);
-            break;
-        case Surface.ROTATION_180:
-            transform.reset();
-            break;
-        case Surface.ROTATION_90:
-            transform.setRotate(90, 0, 0);
-            transform.postTranslate(displayWidth, 0);
-            transform.postTranslate(-y, x);
-            break;
-        }
+        DisplayContent.createRotationMatrix(deltaRotation, x, y, displayWidth, displayHeight,
+                transform);
 
         // We have two cases:
         //  1. Windows with NATIVE_WINDOW_TRANSFORM_INVERSE_DISPLAY:
diff --git a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
index cbdd181..285a75c 100644
--- a/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
+++ b/services/core/java/com/android/server/wm/WindowSurfacePlacer.java
@@ -226,14 +226,6 @@
         final int dw = displayInfo.logicalWidth;
         final int dh = displayInfo.logicalHeight;
 
-        if (mService.mInputConsumer != null) {
-            mService.mInputConsumer.layout(dw, dh);
-        }
-
-        if (mService.mWallpaperInputConsumer != null) {
-            mService.mWallpaperInputConsumer.layout(dw, dh);
-        }
-
         final int N = windows.size();
         int i;
 
@@ -380,6 +372,7 @@
         }
 
         // Window frames may have changed. Tell the input dispatcher about it.
+        mService.mInputMonitor.layoutInputConsumers(dw, dh);
         mService.mInputMonitor.setUpdateInputWindowsNeededLw();
         if (updateInputWindows) {
             mService.mInputMonitor.updateInputWindowsLw(false /*force*/);
diff --git a/services/core/java/com/android/server/wm/WindowToken.java b/services/core/java/com/android/server/wm/WindowToken.java
index 166107c..91eab14 100644
--- a/services/core/java/com/android/server/wm/WindowToken.java
+++ b/services/core/java/com/android/server/wm/WindowToken.java
@@ -78,12 +78,16 @@
     // windows will be put to the bottom of the list.
     boolean sendingToBottom;
 
-    WindowToken(WindowManagerService service, IBinder _token, int type, boolean _explicit) {
+    // The display this token is on.
+    private DisplayContent mDisplayContent;
+
+    WindowToken(WindowManagerService service, IBinder _token, int type, boolean _explicit,
+            DisplayContent dc) {
         mService = service;
         token = _token;
         windowType = type;
         explicit = _explicit;
-        mService.mTokenMap.put(token, this);
+        onDisplayChanged(dc);
     }
 
     void removeAllWindows() {
@@ -189,6 +193,25 @@
         }
     }
 
+    void addImeWindow(WindowState win) {
+        int pos = mService.findDesiredInputMethodWindowIndexLocked(true);
+
+        if (pos < 0) {
+            addWindow(win);
+            mService.moveInputMethodDialogsLocked(pos);
+            return;
+        }
+
+        if (DEBUG_WINDOW_MOVEMENT || DEBUG_ADD_REMOVE) Slog.v(TAG_WM,
+                "Adding input method window " + win + " at " + pos);
+        mDisplayContent.addToWindowList(win, pos);
+        if (!mChildren.contains(win)) {
+            addChild(win, null);
+        }
+        mService.mWindowsChanged = true;
+        mService.moveInputMethodDialogsLocked(pos + 1);
+    }
+
     /** Return the first window in the token window list that isn't a starting window or null. */
     WindowState getFirstNonStartingWindow() {
         final int count = mChildren.size();
@@ -400,6 +423,33 @@
         return null;
     }
 
+    DisplayContent getDisplayContent() {
+        return mDisplayContent;
+    }
+
+    @Override
+    void removeImmediately() {
+        super.removeImmediately();
+        if (mDisplayContent != null) {
+            mDisplayContent.removeWindowToken(token);
+            mService.mRoot.removeWindowTokenIfPossible(token);
+        }
+    }
+
+    void onDisplayChanged(DisplayContent dc) {
+        if (mDisplayContent == dc) {
+            return;
+        }
+
+        if (mDisplayContent != null) {
+            mDisplayContent.removeWindowToken(token);
+        }
+        mDisplayContent = dc;
+        mDisplayContent.setWindowToken(token, this);
+
+        super.onDisplayChanged(dc);
+    }
+
     void dump(PrintWriter pw, String prefix) {
         pw.print(prefix); pw.print("windows="); pw.println(mChildren);
         pw.print(prefix); pw.print("windowType="); pw.print(windowType);
diff --git a/services/core/jni/Android.mk b/services/core/jni/Android.mk
index 9459517..d328ade 100644
--- a/services/core/jni/Android.mk
+++ b/services/core/jni/Android.mk
@@ -7,7 +7,6 @@
 LOCAL_SRC_FILES += \
     $(LOCAL_REL_DIR)/com_android_server_AlarmManagerService.cpp \
     $(LOCAL_REL_DIR)/com_android_server_am_BatteryStatsService.cpp \
-    $(LOCAL_REL_DIR)/com_android_server_AssetAtlasService.cpp \
     $(LOCAL_REL_DIR)/com_android_server_connectivity_Vpn.cpp \
     $(LOCAL_REL_DIR)/com_android_server_ConsumerIrService.cpp \
     $(LOCAL_REL_DIR)/com_android_server_HardwarePropertiesManagerService.cpp \
@@ -65,4 +64,9 @@
     libEGL \
     libGLESv2 \
     libnetutils \
-
+    libhidl \
+    libhwbinder \
+    libutils \
+    android.hardware.power@1.0 \
+    android.hardware.vibrator@1.0 \
+    android.hardware.light@2.0 \
diff --git a/services/core/jni/com_android_server_AssetAtlasService.cpp b/services/core/jni/com_android_server_AssetAtlasService.cpp
deleted file mode 100644
index d004e30..0000000
--- a/services/core/jni/com_android_server_AssetAtlasService.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * Copyright (C) 2013 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.
- */
-
-#define LOG_TAG "AssetAtlasService"
-
-#include "jni.h"
-#include "JNIHelp.h"
-#include "android/graphics/GraphicsJNI.h"
-
-#include <android_view_GraphicBuffer.h>
-#include <cutils/log.h>
-
-#include <GLES2/gl2.h>
-#include <GLES2/gl2ext.h>
-
-#include <EGL/egl.h>
-#include <EGL/eglext.h>
-
-// Disable warnings for Skia.
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wunused-parameter"
-#include <SkCanvas.h>
-#include <SkBitmap.h>
-#pragma GCC diagnostic pop
-
-namespace android {
-
-// ----------------------------------------------------------------------------
-// Defines
-// ----------------------------------------------------------------------------
-
-// Defines how long to wait for the GPU when uploading the atlas
-// This timeout is defined in nanoseconds (see EGL_KHR_fence_sync extension)
-#define FENCE_TIMEOUT 2000000000
-
-// ----------------------------------------------------------------------------
-// Canvas management
-// ----------------------------------------------------------------------------
-
-#define CLEANUP_GL_AND_RETURN(result) \
-    if (fence != EGL_NO_SYNC_KHR) eglDestroySyncKHR(display, fence); \
-    if (image) eglDestroyImageKHR(display, image); \
-    if (texture) glDeleteTextures(1, &texture); \
-    if (surface != EGL_NO_SURFACE) eglDestroySurface(display, surface); \
-    if (context != EGL_NO_CONTEXT) eglDestroyContext(display, context); \
-    eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); \
-    eglReleaseThread(); \
-    eglTerminate(display); \
-    return result;
-
-static jboolean com_android_server_AssetAtlasService_upload(JNIEnv* env, jobject,
-        jobject graphicBuffer, jobject bitmapHandle) {
-
-    SkBitmap bitmap;
-    GraphicsJNI::getSkBitmap(env, bitmapHandle, &bitmap);
-    SkAutoLockPixels alp(bitmap);
-
-    // The goal of this method is to copy the bitmap into the GraphicBuffer
-    // using the GPU to swizzle the texture content
-    sp<GraphicBuffer> buffer(graphicBufferForJavaObject(env, graphicBuffer));
-
-    if (buffer != NULL) {
-        EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
-        if (display == EGL_NO_DISPLAY) return JNI_FALSE;
-
-        EGLint major;
-        EGLint minor;
-        if (!eglInitialize(display, &major, &minor)) {
-            ALOGW("Could not initialize EGL");
-            return JNI_FALSE;
-        }
-
-        // We're going to use a 1x1 pbuffer surface later on
-        // The configuration doesn't really matter for what we're trying to do
-        EGLint configAttrs[] = {
-                EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
-                EGL_RED_SIZE, 8,
-                EGL_GREEN_SIZE, 8,
-                EGL_BLUE_SIZE, 8,
-                EGL_ALPHA_SIZE, 0,
-                EGL_DEPTH_SIZE, 0,
-                EGL_STENCIL_SIZE, 0,
-                EGL_NONE
-        };
-        EGLConfig configs[1];
-        EGLint configCount;
-        if (!eglChooseConfig(display, configAttrs, configs, 1, &configCount)) {
-            ALOGW("Could not select EGL configuration");
-            eglReleaseThread();
-            eglTerminate(display);
-            return JNI_FALSE;
-        }
-        if (configCount <= 0) {
-            ALOGW("Could not find EGL configuration");
-            eglReleaseThread();
-            eglTerminate(display);
-            return JNI_FALSE;
-        }
-
-        // These objects are initialized below but the default "null"
-        // values are used to cleanup properly at any point in the
-        // initialization sequence
-        GLuint texture = 0;
-        EGLImageKHR image = EGL_NO_IMAGE_KHR;
-        EGLSurface surface = EGL_NO_SURFACE;
-        EGLSyncKHR fence = EGL_NO_SYNC_KHR;
-
-        EGLint attrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
-        EGLContext context = eglCreateContext(display, configs[0], EGL_NO_CONTEXT, attrs);
-        if (context == EGL_NO_CONTEXT) {
-            ALOGW("Could not create EGL context");
-            CLEANUP_GL_AND_RETURN(JNI_FALSE);
-        }
-
-        // Create the 1x1 pbuffer
-        EGLint surfaceAttrs[] = { EGL_WIDTH, 1, EGL_HEIGHT, 1, EGL_NONE };
-        surface = eglCreatePbufferSurface(display, configs[0], surfaceAttrs);
-        if (surface == EGL_NO_SURFACE) {
-            ALOGW("Could not create EGL surface");
-            CLEANUP_GL_AND_RETURN(JNI_FALSE);
-        }
-
-        if (!eglMakeCurrent(display, surface, surface, context)) {
-            ALOGW("Could not change current EGL context");
-            CLEANUP_GL_AND_RETURN(JNI_FALSE);
-        }
-
-        // We use an EGLImage to access the content of the GraphicBuffer
-        // The EGL image is later bound to a 2D texture
-        EGLClientBuffer clientBuffer = (EGLClientBuffer) buffer->getNativeBuffer();
-        EGLint imageAttrs[] = { EGL_IMAGE_PRESERVED_KHR, EGL_TRUE, EGL_NONE };
-        image = eglCreateImageKHR(display, EGL_NO_CONTEXT,
-                EGL_NATIVE_BUFFER_ANDROID, clientBuffer, imageAttrs);
-        if (image == EGL_NO_IMAGE_KHR) {
-            ALOGW("Could not create EGL image");
-            CLEANUP_GL_AND_RETURN(JNI_FALSE);
-        }
-
-        glGenTextures(1, &texture);
-        glBindTexture(GL_TEXTURE_2D, texture);
-        glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, image);
-        if (glGetError() != GL_NO_ERROR) {
-            ALOGW("Could not create/bind texture");
-            CLEANUP_GL_AND_RETURN(JNI_FALSE);
-        }
-
-        // Upload the content of the bitmap in the GraphicBuffer
-        glPixelStorei(GL_UNPACK_ALIGNMENT, bitmap.bytesPerPixel());
-        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap.width(), bitmap.height(),
-                GL_RGBA, GL_UNSIGNED_BYTE, bitmap.getPixels());
-        if (glGetError() != GL_NO_ERROR) {
-            ALOGW("Could not upload to texture");
-            CLEANUP_GL_AND_RETURN(JNI_FALSE);
-        }
-
-        // The fence is used to wait for the texture upload to finish
-        // properly. We cannot rely on glFlush() and glFinish() as
-        // some drivers completely ignore these API calls
-        fence = eglCreateSyncKHR(display, EGL_SYNC_FENCE_KHR, NULL);
-        if (fence == EGL_NO_SYNC_KHR) {
-            ALOGW("Could not create sync fence %#x", eglGetError());
-            CLEANUP_GL_AND_RETURN(JNI_FALSE);
-        }
-
-        // The flag EGL_SYNC_FLUSH_COMMANDS_BIT_KHR will trigger a
-        // pipeline flush (similar to what a glFlush() would do.)
-        EGLint waitStatus = eglClientWaitSyncKHR(display, fence,
-                EGL_SYNC_FLUSH_COMMANDS_BIT_KHR, FENCE_TIMEOUT);
-        if (waitStatus != EGL_CONDITION_SATISFIED_KHR) {
-            ALOGW("Failed to wait for the fence %#x", eglGetError());
-            CLEANUP_GL_AND_RETURN(JNI_FALSE);
-        }
-
-        CLEANUP_GL_AND_RETURN(JNI_TRUE);
-    }
-
-    return JNI_FALSE;
-}
-
-// ----------------------------------------------------------------------------
-// JNI Glue
-// ----------------------------------------------------------------------------
-
-#define FIND_CLASS(var, className) \
-        var = env->FindClass(className); \
-        LOG_FATAL_IF(! (var), "Unable to find class " className);
-
-#define GET_METHOD_ID(var, clazz, methodName, methodDescriptor) \
-        var = env->GetMethodID(clazz, methodName, methodDescriptor); \
-        LOG_FATAL_IF(!(var), "Unable to find method " methodName);
-
-const char* const kClassPathName = "com/android/server/AssetAtlasService";
-
-static const JNINativeMethod gMethods[] = {
-    { "nUploadAtlas", "(Landroid/view/GraphicBuffer;Landroid/graphics/Bitmap;)Z",
-            (void*) com_android_server_AssetAtlasService_upload },
-};
-
-int register_android_server_AssetAtlasService(JNIEnv* env) {
-    return jniRegisterNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
-}
-
-};
diff --git a/services/core/jni/com_android_server_VibratorService.cpp b/services/core/jni/com_android_server_VibratorService.cpp
index 03fbd19..cc52260 100644
--- a/services/core/jni/com_android_server_VibratorService.cpp
+++ b/services/core/jni/com_android_server_VibratorService.cpp
@@ -16,6 +16,9 @@
 
 #define LOG_TAG "VibratorService"
 
+#include <android/hardware/vibrator/1.0/IVibrator.h>
+#include <android/hardware/vibrator/1.0/types.h>
+
 #include "jni.h"
 #include "JNIHelp.h"
 #include "android_runtime/AndroidRuntime.h"
@@ -26,32 +29,27 @@
 
 #include <stdio.h>
 
+using android::hardware::getService;
+using android::hardware::vibrator::V1_0::IVibrator;
+using android::hardware::vibrator::V1_0::Status;
+
 namespace android
 {
 
-static hw_module_t *gVibraModule = NULL;
-static vibrator_device_t *gVibraDevice = NULL;
+static sp<IVibrator> mHal;
 
 static void vibratorInit(JNIEnv /* env */, jobject /* clazz */)
 {
-    if (gVibraModule != NULL) {
+    /* TODO(b/31632518) */
+    if (mHal != nullptr) {
         return;
     }
-
-    int err = hw_get_module(VIBRATOR_HARDWARE_MODULE_ID, (hw_module_t const**)&gVibraModule);
-
-    if (err) {
-        ALOGE("Couldn't load %s module (%s)", VIBRATOR_HARDWARE_MODULE_ID, strerror(-err));
-    } else {
-        if (gVibraModule) {
-            vibrator_open(gVibraModule, &gVibraDevice);
-        }
-    }
+    mHal = IVibrator::getService("vibrator");
 }
 
 static jboolean vibratorExists(JNIEnv* /* env */, jobject /* clazz */)
 {
-    if (gVibraModule && gVibraDevice) {
+    if (mHal != nullptr) {
         return JNI_TRUE;
     } else {
         return JNI_FALSE;
@@ -60,10 +58,10 @@
 
 static void vibratorOn(JNIEnv* /* env */, jobject /* clazz */, jlong timeout_ms)
 {
-    if (gVibraDevice) {
-        int err = gVibraDevice->vibrator_on(gVibraDevice, timeout_ms);
-        if (err != 0) {
-            ALOGE("The hw module failed in vibrator_on: %s", strerror(-err));
+    if (mHal != nullptr) {
+        Status retStatus = mHal->on(timeout_ms);
+        if (retStatus == Status::ERR) {
+            ALOGE("vibratorOn command failed.");
         }
     } else {
         ALOGW("Tried to vibrate but there is no vibrator device.");
@@ -72,10 +70,10 @@
 
 static void vibratorOff(JNIEnv* /* env */, jobject /* clazz */)
 {
-    if (gVibraDevice) {
-        int err = gVibraDevice->vibrator_off(gVibraDevice);
-        if (err != 0) {
-            ALOGE("The hw module failed in vibrator_off(): %s", strerror(-err));
+    if (mHal != nullptr) {
+        Status retStatus = mHal->off();
+        if (retStatus == Status::ERR) {
+            ALOGE("vibratorOff command failed.");
         }
     } else {
         ALOGW("Tried to stop vibrating but there is no vibrator device.");
diff --git a/services/core/jni/com_android_server_am_BatteryStatsService.cpp b/services/core/jni/com_android_server_am_BatteryStatsService.cpp
index ecdc71e..b22d5e7 100644
--- a/services/core/jni/com_android_server_am_BatteryStatsService.cpp
+++ b/services/core/jni/com_android_server_am_BatteryStatsService.cpp
@@ -17,6 +17,7 @@
 #define LOG_TAG "BatteryStatsService"
 //#define LOG_NDEBUG 0
 
+#include <android/hardware/power/1.0/IPower.h>
 #include <android_runtime/AndroidRuntime.h>
 #include <jni.h>
 
@@ -26,8 +27,6 @@
 #include <cutils/log.h>
 #include <utils/misc.h>
 #include <utils/Log.h>
-#include <hardware/hardware.h>
-#include <hardware/power.h>
 #include <suspend/autosuspend.h>
 
 #include <inttypes.h>
@@ -41,6 +40,14 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+using android::hardware::Return;
+using android::hardware::Void;
+using android::hardware::power::V1_0::IPower;
+using android::hardware::power::V1_0::PowerStatePlatformSleepState;
+using android::hardware::power::V1_0::PowerStateVoter;
+using android::hardware::power::V1_0::Status;
+using android::hardware::hidl_vec;
+
 namespace android
 {
 
@@ -49,7 +56,7 @@
 
 static bool wakeup_init = false;
 static sem_t wakeup_sem;
-extern struct power_module* gPowerModule;
+extern sp<IPower> gPowerHal;
 
 static void wakeup_callback(bool success)
 {
@@ -174,86 +181,34 @@
 }
 
 static jint getPlatformLowPowerStats(JNIEnv* env, jobject /* clazz */, jobject outBuf) {
-    int num_modes = -1;
-    char *output = (char*)env->GetDirectBufferAddress(outBuf), *offset = output;
+    char *output = (char*)env->GetDirectBufferAddress(outBuf);
+    char *offset = output;
     int remaining = (int)env->GetDirectBufferCapacity(outBuf);
-    power_state_platform_sleep_state_t *list;
-    size_t *voter_list;
     int total_added = -1;
 
     if (outBuf == NULL) {
         jniThrowException(env, "java/lang/NullPointerException", "null argument");
-        goto error;
+        return -1;
     }
 
-    if (!gPowerModule) {
-        ALOGE("%s: gPowerModule not loaded", POWER_HARDWARE_MODULE_ID);
-        goto error;
+    if (gPowerHal == nullptr) {
+        ALOGE("gPowerHal not loaded");
+        return -1;
     }
 
-    if (! (gPowerModule->get_platform_low_power_stats && gPowerModule->get_number_of_platform_modes
-       && gPowerModule->get_voter_list)) {
-        ALOGE("%s: Missing API", POWER_HARDWARE_MODULE_ID);
-        goto error;
-    }
+    gPowerHal->getPlatformLowPowerStats(
+        [&offset, &remaining, &total_added](hidl_vec<PowerStatePlatformSleepState> states,
+                Status status) {
+            if (status != Status::SUCCESS)
+                return;
+            for (size_t i = 0; i < states.size(); i++) {
+                int added;
+                const PowerStatePlatformSleepState& state = states[i];
 
-    if (gPowerModule->get_number_of_platform_modes) {
-        num_modes = gPowerModule->get_number_of_platform_modes(gPowerModule);
-    }
-
-    if (num_modes < 1) {
-        ALOGE("%s: Platform does not even have one low power mode", POWER_HARDWARE_MODULE_ID);
-        goto error;
-    }
-
-    list = (power_state_platform_sleep_state_t *)calloc(num_modes,
-        sizeof(power_state_platform_sleep_state_t));
-    if (!list) {
-        ALOGE("%s: power_state_platform_sleep_state_t allocation failed", POWER_HARDWARE_MODULE_ID);
-        goto error;
-    }
-
-    voter_list = (size_t *)calloc(num_modes, sizeof(*voter_list));
-    if (!voter_list) {
-        ALOGE("%s: voter_list allocation failed", POWER_HARDWARE_MODULE_ID);
-        goto err_free;
-    }
-
-    gPowerModule->get_voter_list(gPowerModule, voter_list);
-
-    for (int i = 0; i < num_modes; i++) {
-        list[i].voters = (power_state_voter_t *)calloc(voter_list[i],
-                         sizeof(power_state_voter_t));
-        if (!list[i].voters) {
-            ALOGE("%s: voter_t allocation failed", POWER_HARDWARE_MODULE_ID);
-            goto err_free;
-        }
-    }
-
-    if (!gPowerModule->get_platform_low_power_stats(gPowerModule, list)) {
-        for (int i = 0; i < num_modes; i++) {
-            int added;
-
-            added = snprintf(offset, remaining,
-                    "state_%d name=%s time=%" PRIu64 " count=%" PRIu64 " ",
-                    i + 1, list[i].name, list[i].residency_in_msec_since_boot,
-                    list[i].total_transitions);
-            if (added < 0) {
-                break;
-            }
-            if (added > remaining) {
-                added = remaining;
-            }
-            offset += added;
-            remaining -= added;
-            total_added += added;
-
-            for (unsigned int j = 0; j < list[i].number_of_voters; j++) {
                 added = snprintf(offset, remaining,
-                        "voter_%d name=%s time=%" PRIu64 " count=%" PRIu64 " ",
-                        j + 1, list[i].voters[j].name,
-                        list[i].voters[j].total_time_in_msec_voted_for_since_boot,
-                        list[i].voters[j].total_number_of_times_voted_since_boot);
+                    "state_%zu name=%s time=%" PRIu64 " count=%" PRIu64 " ",
+                    i + 1, state.name.c_str(), state.residencyInMsecSinceBoot,
+                    state.totalTransitions);
                 if (added < 0) {
                     break;
                 }
@@ -263,27 +218,37 @@
                 offset += added;
                 remaining -= added;
                 total_added += added;
-            }
 
-            if (remaining <= 0) {
-                /* rewrite NULL character*/
-                offset--;
-                total_added--;
-                ALOGE("%s module: buffer not enough", POWER_HARDWARE_MODULE_ID);
-                break;
+                for (size_t j = 0; j < state.voters.size(); j++) {
+                    const PowerStateVoter& voter = state.voters[j];
+                    added = snprintf(offset, remaining,
+                            "voter_%zu name=%s time=%" PRIu64 " count=%" PRIu64 " ",
+                            j + 1, voter.name.c_str(),
+                            voter.totalTimeInMsecVotedForSinceBoot,
+                            voter.totalNumberOfTimesVotedSinceBoot);
+                    if (added < 0) {
+                        break;
+                    }
+                    if (added > remaining) {
+                        added = remaining;
+                    }
+                    offset += added;
+                    remaining -= added;
+                    total_added += added;
+                }
+
+                if (remaining <= 0) {
+                    /* rewrite NULL character*/
+                    offset--;
+                    total_added--;
+                    ALOGE("PowerHal: buffer not enough");
+                    break;
+                }
             }
         }
-    }
+    );
     *offset = 0;
     total_added += 1;
-
-err_free:
-    for (int i = 0; i < num_modes; i++) {
-        free(list[i].voters);
-    }
-    free(list);
-    free(voter_list);
-error:
     return total_added;
 }
 
diff --git a/services/core/jni/com_android_server_lights_LightsService.cpp b/services/core/jni/com_android_server_lights_LightsService.cpp
index c8e3946..e6072bb 100644
--- a/services/core/jni/com_android_server_lights_LightsService.cpp
+++ b/services/core/jni/com_android_server_lights_LightsService.cpp
@@ -20,136 +20,105 @@
 #include "JNIHelp.h"
 #include "android_runtime/AndroidRuntime.h"
 
+#include <android/hardware/light/2.0/ILight.h>
+#include <android/hardware/light/2.0/types.h>
 #include <utils/misc.h>
 #include <utils/Log.h>
-#include <hardware/hardware.h>
-#include <hardware/lights.h>
-
+#include <map>
 #include <stdio.h>
 
-namespace android
-{
+namespace android {
 
-// These values must correspond with the LIGHT_ID constants in
-// LightsService.java
-enum {
-    LIGHT_INDEX_BACKLIGHT = 0,
-    LIGHT_INDEX_KEYBOARD = 1,
-    LIGHT_INDEX_BUTTONS = 2,
-    LIGHT_INDEX_BATTERY = 3,
-    LIGHT_INDEX_NOTIFICATIONS = 4,
-    LIGHT_INDEX_ATTENTION = 5,
-    LIGHT_INDEX_BLUETOOTH = 6,
-    LIGHT_INDEX_WIFI = 7,
-    LIGHT_COUNT
-};
+using ILight     = ::android::hardware::light::V2_0::ILight;
+using Brightness = ::android::hardware::light::V2_0::Brightness;
+using Flash      = ::android::hardware::light::V2_0::Flash;
+using Type       = ::android::hardware::light::V2_0::Type;
+using LightState = ::android::hardware::light::V2_0::LightState;
 
-struct Devices {
-    light_device_t* lights[LIGHT_COUNT];
-};
+static sp<ILight> gLight;
 
-static light_device_t* get_device(hw_module_t* module, char const* name)
-{
-    int err;
-    hw_device_t* device;
-    err = module->methods->open(module, name, &device);
-    if (err == 0) {
-        return (light_device_t*)device;
-    } else {
-        return NULL;
-    }
-}
+static bool validate(jint light, jint flash, jint brightness) {
+    bool valid = true;
 
-static jlong init_native(JNIEnv* /* env */, jobject /* clazz */)
-{
-    int err;
-    hw_module_t* module;
-    Devices* devices;
-    
-    devices = (Devices*)malloc(sizeof(Devices));
-
-    err = hw_get_module(LIGHTS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
-    if (err == 0) {
-        devices->lights[LIGHT_INDEX_BACKLIGHT]
-                = get_device(module, LIGHT_ID_BACKLIGHT);
-        devices->lights[LIGHT_INDEX_KEYBOARD]
-                = get_device(module, LIGHT_ID_KEYBOARD);
-        devices->lights[LIGHT_INDEX_BUTTONS]
-                = get_device(module, LIGHT_ID_BUTTONS);
-        devices->lights[LIGHT_INDEX_BATTERY]
-                = get_device(module, LIGHT_ID_BATTERY);
-        devices->lights[LIGHT_INDEX_NOTIFICATIONS]
-                = get_device(module, LIGHT_ID_NOTIFICATIONS);
-        devices->lights[LIGHT_INDEX_ATTENTION]
-                = get_device(module, LIGHT_ID_ATTENTION);
-        devices->lights[LIGHT_INDEX_BLUETOOTH]
-                = get_device(module, LIGHT_ID_BLUETOOTH);
-        devices->lights[LIGHT_INDEX_WIFI]
-                = get_device(module, LIGHT_ID_WIFI);
-    } else {
-        memset(devices, 0, sizeof(Devices));
+    if (light < 0 || light >= static_cast<int>(Type::COUNT)) {
+        ALOGE("Invalid light parameter %d.", light);
+        valid = false;
     }
 
-    return (jlong)devices;
+    if (flash != static_cast<int>(Flash::NONE) &&
+        flash != static_cast<int>(Flash::TIMED) &&
+        flash != static_cast<int>(Flash::HARDWARE)) {
+        ALOGE("Invalid flash parameter %d.", flash);
+        valid = false;
+    }
+
+    if (brightness != static_cast<int>(Brightness::USER) &&
+        brightness != static_cast<int>(Brightness::SENSOR) &&
+        brightness != static_cast<int>(Brightness::LOW_PERSISTENCE)) {
+        ALOGE("Invalid brightness parameter %d.", brightness);
+        valid = false;
+    }
+
+    return valid;
 }
 
-static void finalize_native(JNIEnv* /* env */, jobject /* clazz */, jlong ptr)
-{
-    Devices* devices = (Devices*)ptr;
-    if (devices == NULL) {
+static void setLight_native(
+        JNIEnv* /* env */,
+        jobject /* clazz */,
+        jint light,
+        jint colorARGB,
+        jint flashMode,
+        jint onMS,
+        jint offMS,
+        jint brightnessMode) {
+
+    if (!validate(light, flashMode, brightnessMode)) {
         return;
     }
 
-    free(devices);
-}
-
-static void setLight_native(JNIEnv* /* env */, jobject /* clazz */, jlong ptr,
-        jint light, jint colorARGB, jint flashMode, jint onMS, jint offMS, jint brightnessMode)
-{
-    Devices* devices = (Devices*)ptr;
-    light_state_t state;
-
-    if (light < 0 || light >= LIGHT_COUNT || devices->lights[light] == NULL) {
-        return ;
+    // TODO(b/31632518)
+    if (gLight == nullptr) {
+        gLight = ILight::getService("light");
     }
 
-    uint32_t version = devices->lights[light]->common.version;
+    if (gLight == nullptr) {
+        ALOGE("LightService unable to get ILight interface.");
+        return;
+    }
 
-    memset(&state, 0, sizeof(light_state_t));
+    Type type = static_cast<Type>(light);
+    Flash flash = static_cast<Flash>(flashMode);
+    Brightness brightness = static_cast<Brightness>(brightnessMode);
 
-    if (brightnessMode == BRIGHTNESS_MODE_LOW_PERSISTENCE) {
-        if (light != LIGHT_INDEX_BACKLIGHT) {
+    LightState state{};
+
+    if (brightnessMode == static_cast<int>(Brightness::LOW_PERSISTENCE)) {
+        if (light != static_cast<int>(Type::BACKLIGHT)) {
             ALOGE("Cannot set low-persistence mode for non-backlight device.");
             return;
         }
-        if (version < LIGHTS_DEVICE_API_VERSION_2_0) {
-            // HAL impl has not been upgraded to support this.
-            return;
-        }
+        state.flashMode = Flash::NONE;
     } else {
         // Only set non-brightness settings when not in low-persistence mode
         state.color = colorARGB;
-        state.flashMode = flashMode;
-        state.flashOnMS = onMS;
-        state.flashOffMS = offMS;
+        state.flashMode = flash;
+        state.flashOnMs = onMS;
+        state.flashOffMs = offMS;
     }
 
-    state.brightnessMode = brightnessMode;
+    state.brightnessMode = brightness;
 
     {
         ALOGD_IF_SLOW(50, "Excessive delay setting light");
-        devices->lights[light]->set_light(devices->lights[light], &state);
+        gLight->setLight(type, state);
     }
 }
 
 static const JNINativeMethod method_table[] = {
-    { "init_native", "()J", (void*)init_native },
-    { "finalize_native", "(J)V", (void*)finalize_native },
-    { "setLight_native", "(JIIIIII)V", (void*)setLight_native },
+    { "setLight_native", "(IIIIII)V", (void*)setLight_native },
 };
 
-int register_android_server_LightsService(JNIEnv *env)
-{
+int register_android_server_LightsService(JNIEnv *env) {
     return jniRegisterNativeMethods(env, "com/android/server/lights/LightsService",
             method_table, NELEM(method_table));
 }
diff --git a/services/core/jni/com_android_server_power_PowerManagerService.cpp b/services/core/jni/com_android_server_power_PowerManagerService.cpp
index 048ef76..b2372a3 100644
--- a/services/core/jni/com_android_server_power_PowerManagerService.cpp
+++ b/services/core/jni/com_android_server_power_PowerManagerService.cpp
@@ -18,6 +18,7 @@
 
 //#define LOG_NDEBUG 0
 
+#include <android/hardware/power/1.0/IPower.h>
 #include "JNIHelp.h"
 #include "jni.h"
 
@@ -37,6 +38,13 @@
 
 #include "com_android_server_power_PowerManagerService.h"
 
+using android::hardware::Return;
+using android::hardware::Void;
+using android::hardware::power::V1_0::IPower;
+using android::hardware::power::V1_0::PowerHint;
+using android::hardware::power::V1_0::Feature;
+using android::hardware::hidl_vec;
+
 namespace android {
 
 // ----------------------------------------------------------------------------
@@ -48,8 +56,7 @@
 // ----------------------------------------------------------------------------
 
 static jobject gPowerManagerServiceObj;
-struct power_module* gPowerModule;
-
+sp<IPower> gPowerHal;
 static nsecs_t gLastEventTime[USER_ACTIVITY_EVENT_LAST + 1];
 
 // Throttling interval for user activity calls.
@@ -69,8 +76,8 @@
 
 void android_server_PowerManagerService_userActivity(nsecs_t eventTime, int32_t eventType) {
     // Tell the power HAL when user activity occurs.
-    if (gPowerModule && gPowerModule->powerHint) {
-        gPowerModule->powerHint(gPowerModule, POWER_HINT_INTERACTION, NULL);
+    if (gPowerHal != nullptr) {
+        gPowerHal->powerHint(PowerHint::INTERACTION, 0);
     }
 
     if (gPowerManagerServiceObj) {
@@ -99,16 +106,13 @@
 }
 
 // ----------------------------------------------------------------------------
-
+//TODO(b/31632518)
 static void nativeInit(JNIEnv* env, jobject obj) {
     gPowerManagerServiceObj = env->NewGlobalRef(obj);
 
-    status_t err = hw_get_module(POWER_HARDWARE_MODULE_ID,
-            (hw_module_t const**)&gPowerModule);
-    if (!err) {
-        gPowerModule->init(gPowerModule);
-    } else {
-        ALOGE("Couldn't load %s module (%s)", POWER_HARDWARE_MODULE_ID, strerror(-err));
+    gPowerHal = IPower::getService("power");
+    if (gPowerHal == nullptr) {
+        ALOGE("Couldn't load PowerHAL module");
     }
 }
 
@@ -123,13 +127,13 @@
 }
 
 static void nativeSetInteractive(JNIEnv* /* env */, jclass /* clazz */, jboolean enable) {
-    if (gPowerModule) {
+    if (gPowerHal != nullptr) {
         if (enable) {
             ALOGD_IF_SLOW(20, "Excessive delay in setInteractive(true) while turning screen on");
-            gPowerModule->setInteractive(gPowerModule, true);
+            gPowerHal->setInteractive(true);
         } else {
             ALOGD_IF_SLOW(20, "Excessive delay in setInteractive(false) while turning screen off");
-            gPowerModule->setInteractive(gPowerModule, false);
+            gPowerHal->setInteractive(false);
         }
     }
 }
@@ -145,13 +149,11 @@
 }
 
 static void nativeSendPowerHint(JNIEnv *env, jclass clazz, jint hintId, jint data) {
-    int data_param = data;
-
-    if (gPowerModule && gPowerModule->powerHint) {
+    if (gPowerHal != nullptr) {
         if(data)
-            gPowerModule->powerHint(gPowerModule, (power_hint_t)hintId, &data_param);
+            gPowerHal->powerHint((PowerHint)hintId, data);
         else {
-            gPowerModule->powerHint(gPowerModule, (power_hint_t)hintId, NULL);
+            gPowerHal->powerHint((PowerHint)hintId, 0);
         }
     }
 }
@@ -159,8 +161,8 @@
 static void nativeSetFeature(JNIEnv *env, jclass clazz, jint featureId, jint data) {
     int data_param = data;
 
-    if (gPowerModule && gPowerModule->setFeature) {
-        gPowerModule->setFeature(gPowerModule, (feature_t)featureId, data_param);
+    if (gPowerHal != nullptr) {
+        gPowerHal->setFeature((Feature)featureId, data_param ? true : false);
     }
 }
 
@@ -215,7 +217,7 @@
         gLastEventTime[i] = LLONG_MIN;
     }
     gPowerManagerServiceObj = NULL;
-    gPowerModule = NULL;
+    gPowerHal = NULL;
     return 0;
 }
 
diff --git a/services/core/jni/onload.cpp b/services/core/jni/onload.cpp
index 327019d..d69c37f 100644
--- a/services/core/jni/onload.cpp
+++ b/services/core/jni/onload.cpp
@@ -21,7 +21,6 @@
 
 namespace android {
 int register_android_server_AlarmManagerService(JNIEnv* env);
-int register_android_server_AssetAtlasService(JNIEnv* env);
 int register_android_server_BatteryStatsService(JNIEnv* env);
 int register_android_server_ConsumerIrService(JNIEnv *env);
 int register_android_server_InputApplicationHandle(JNIEnv* env);
@@ -76,7 +75,6 @@
     register_android_server_location_GnssLocationProvider(env);
     register_android_server_location_FlpHardwareProvider(env);
     register_android_server_connectivity_Vpn(env);
-    register_android_server_AssetAtlasService(env);
     register_android_server_ConsumerIrService(env);
     register_android_server_BatteryStatsService(env);
     register_android_server_hdmi_HdmiCecController(env);
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 47efa05..88d8dd0 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -221,6 +221,7 @@
     private static final String ATTR_PERMISSION_POLICY = "permission-policy";
     private static final String ATTR_DEVICE_PROVISIONING_CONFIG_APPLIED =
             "device-provisioning-config-applied";
+    private static final String ATTR_DEVICE_PAIRED = "device-paired";
 
     private static final String ATTR_DELEGATED_CERT_INSTALLER = "delegated-cert-installer";
     private static final String ATTR_APPLICATION_RESTRICTIONS_MANAGER
@@ -301,6 +302,7 @@
     private static final int CODE_NONSYSTEM_USER_EXISTS = 5;
     private static final int CODE_ACCOUNTS_NOT_EMPTY = 6;
     private static final int CODE_NOT_SYSTEM_USER = 7;
+    private static final int CODE_HAS_PAIRED = 8;
 
     @Retention(RetentionPolicy.SOURCE)
     @IntDef({ CODE_OK, CODE_HAS_DEVICE_OWNER, CODE_USER_HAS_PROFILE_OWNER, CODE_USER_NOT_RUNNING,
@@ -344,6 +346,11 @@
      */
     boolean mHasFeature;
 
+    /**
+     * Whether or not this device is a watch.
+     */
+    boolean mIsWatch;
+
     private final SecurityLogMonitor mSecurityLogMonitor;
 
     private final AtomicBoolean mRemoteBugreportServiceIsActive = new AtomicBoolean();
@@ -424,6 +431,7 @@
         int mPasswordOwner = -1;
         long mLastMaximumTimeToLock = -1;
         boolean mUserSetupComplete = false;
+        boolean mPaired = false;
         int mUserProvisioningState;
         int mPermissionPolicy;
 
@@ -496,12 +504,6 @@
                     }
                 });
             }
-            // STOPSHIP: Remove this code once all dogfood devices are fixed. See b/31754835
-            if (Intent.ACTION_BOOT_COMPLETED.equals(action) && !mOwners.hasDeviceOwner()
-                    && !isBackupServiceEnabledInternal()) {
-                setBackupServiceEnabledInternal(true);
-                Slog.w(LOG_TAG, "Fix backup for device that is not in Device Owner mode.");
-            }
             if (Intent.ACTION_USER_UNLOCKED.equals(action)
                     || Intent.ACTION_USER_STARTED.equals(action)
                     || KeyChain.ACTION_TRUST_STORE_CHANGED.equals(action)) {
@@ -1621,6 +1623,8 @@
 
         mHasFeature = mContext.getPackageManager()
                 .hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN);
+        mIsWatch = mContext.getPackageManager()
+                .hasSystemFeature(PackageManager.FEATURE_WATCH);
         if (!mHasFeature) {
             // Skip the rest of the initialization
             return;
@@ -2221,6 +2225,10 @@
                 out.attribute(null, ATTR_SETUP_COMPLETE,
                         Boolean.toString(true));
             }
+            if (policy.mPaired) {
+                out.attribute(null, ATTR_DEVICE_PAIRED,
+                        Boolean.toString(true));
+            }
             if (policy.mDeviceProvisioningConfigApplied) {
                 out.attribute(null, ATTR_DEVICE_PROVISIONING_CONFIG_APPLIED,
                         Boolean.toString(true));
@@ -2385,6 +2393,10 @@
             if (userSetupComplete != null && Boolean.toString(true).equals(userSetupComplete)) {
                 policy.mUserSetupComplete = true;
             }
+            String paired = parser.getAttributeValue(null, ATTR_DEVICE_PAIRED);
+            if (paired != null && Boolean.toString(true).equals(paired)) {
+                policy.mPaired = true;
+            }
             String deviceProvisioningConfigApplied = parser.getAttributeValue(null,
                     ATTR_DEVICE_PROVISIONING_CONFIG_APPLIED);
             if (deviceProvisioningConfigApplied != null
@@ -2619,7 +2631,7 @@
         // Register an observer for watching for user setup complete.
         new SetupContentObserver(mHandler).register();
         // Initialize the user setup state, to handle the upgrade case.
-        updateUserSetupComplete();
+        updateUserSetupCompleteAndPaired();
 
         List<String> packageList;
         synchronized (this) {
@@ -6157,6 +6169,13 @@
         return getUserData(userHandle).mUserSetupComplete;
     }
 
+    private boolean hasPaired(int userHandle) {
+        if (!mHasFeature) {
+            return true;
+        }
+        return getUserData(userHandle).mPaired;
+    }
+
     @Override
     public int getUserProvisioningState() {
         if (!mHasFeature) {
@@ -6441,6 +6460,9 @@
             case CODE_ACCOUNTS_NOT_EMPTY:
                 throw new IllegalStateException("Not allowed to set the device owner because there "
                         + "are already some accounts on the device");
+            case CODE_HAS_PAIRED:
+                throw new IllegalStateException("Not allowed to set the device owner because this "
+                        + "device has already paired");
             default:
                 throw new IllegalStateException("Unknown @DeviceOwnerPreConditionCode " + code);
         }
@@ -8192,14 +8214,15 @@
     }
 
     /**
-     * We need to update the internal state of whether a user has completed setup once. After
-     * that, we ignore any changes that reset the Settings.Secure.USER_SETUP_COMPLETE changes
-     * as we don't trust any apps that might try to reset it.
+     * We need to update the internal state of whether a user has completed setup or a
+     * device has paired once. After that, we ignore any changes that reset the
+     * Settings.Secure.USER_SETUP_COMPLETE or Settings.Secure.DEVICE_PAIRED change
+     * as we don't trust any apps that might try to reset them.
      * <p>
      * Unfortunately, we don't know which user's setup state was changed, so we write all of
      * them.
      */
-    void updateUserSetupComplete() {
+    void updateUserSetupCompleteAndPaired() {
         List<UserInfo> users = mUserManager.getUsers(true);
         final int N = users.size();
         for (int i = 0; i < N; i++) {
@@ -8214,6 +8237,16 @@
                     }
                 }
             }
+            if (mIsWatch && mInjector.settingsSecureGetIntForUser(Settings.Secure.DEVICE_PAIRED, 0,
+                    userHandle) != 0) {
+                DevicePolicyData policy = getUserData(userHandle);
+                if (!policy.mPaired) {
+                    policy.mPaired = true;
+                    synchronized (this) {
+                        saveSettingsLocked(userHandle);
+                    }
+                }
+            }
         }
     }
 
@@ -8223,6 +8256,7 @@
                 Settings.Secure.USER_SETUP_COMPLETE);
         private final Uri mDeviceProvisioned = Settings.Global.getUriFor(
                 Settings.Global.DEVICE_PROVISIONED);
+        private final Uri mPaired = Settings.Secure.getUriFor(Settings.Secure.DEVICE_PAIRED);
 
         public SetupContentObserver(Handler handler) {
             super(handler);
@@ -8231,12 +8265,15 @@
         void register() {
             mInjector.registerContentObserver(mUserSetupComplete, false, this, UserHandle.USER_ALL);
             mInjector.registerContentObserver(mDeviceProvisioned, false, this, UserHandle.USER_ALL);
+            if (mIsWatch) {
+                mInjector.registerContentObserver(mPaired, false, this, UserHandle.USER_ALL);
+            }
         }
 
         @Override
         public void onChange(boolean selfChange, Uri uri) {
-            if (mUserSetupComplete.equals(uri)) {
-                updateUserSetupComplete();
+            if (mUserSetupComplete.equals(uri) || (mIsWatch && mPaired.equals(uri))) {
+                updateUserSetupCompleteAndPaired();
             } else if (mDeviceProvisioned.equals(uri)) {
                 synchronized (DevicePolicyManagerService.this) {
                     // Set PROPERTY_DEVICE_OWNER_PRESENT, for the SUW case where setting the property
@@ -8692,6 +8729,9 @@
         if (!mUserManager.isUserRunning(new UserHandle(deviceOwnerUserId))) {
             return CODE_USER_NOT_RUNNING;
         }
+        if (mIsWatch && hasPaired(UserHandle.USER_SYSTEM)) {
+            return CODE_HAS_PAIRED;
+        }
         if (isAdb) {
             // if shell command runs after user setup completed check device status. Otherwise, OK.
             if (hasUserSetupCompleted(UserHandle.USER_SYSTEM)) {
@@ -9357,16 +9397,13 @@
             return true;
         }
         synchronized (this) {
-            getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
-            return isBackupServiceEnabledInternal();
-        }
-    }
-    private boolean isBackupServiceEnabledInternal() {
-        try {
-            IBackupManager ibm = mInjector.getIBackupManager();
-            return ibm != null && ibm.isBackupServiceActive(UserHandle.USER_SYSTEM);
-        } catch (RemoteException e) {
-            throw new IllegalStateException("Failed requesting backup service state.", e);
+            try {
+                getActiveAdminForCallerLocked(admin, DeviceAdminInfo.USES_POLICY_DEVICE_OWNER);
+                IBackupManager ibm = mInjector.getIBackupManager();
+                return ibm != null && ibm.isBackupServiceActive(UserHandle.USER_SYSTEM);
+            } catch (RemoteException e) {
+                throw new IllegalStateException("Failed requesting backup service state.", e);
+            }
         }
     }
 
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 769b5ee..deb5238 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -747,7 +747,6 @@
         LocationManagerService location = null;
         CountryDetectorService countryDetector = null;
         ILockSettings lockSettings = null;
-        AssetAtlasService atlas = null;
         MediaRouterService mediaRouter = null;
 
         // Bring up services needed for UI.
@@ -1235,17 +1234,6 @@
                 traceEnd();
             }
 
-            if (!disableNonCoreServices && ZygoteInit.PRELOAD_RESOURCES) {
-                traceBeginAndSlog("StartAssetAtlasService");
-                try {
-                    atlas = new AssetAtlasService(context);
-                    ServiceManager.addService(AssetAtlasService.ASSET_ATLAS_SERVICE, atlas);
-                } catch (Throwable e) {
-                    reportWtf("starting AssetAtlasService", e);
-                }
-                traceEnd();
-            }
-
             if (!disableNonCoreServices) {
                 traceBeginAndSlog("AddGraphicsStatsService");
                 ServiceManager.addService(GraphicsStatsService.GRAPHICS_STATS_SERVICE,
@@ -1465,7 +1453,6 @@
         final CountryDetectorService countryDetectorF = countryDetector;
         final NetworkTimeUpdateService networkTimeUpdaterF = networkTimeUpdater;
         final CommonTimeManagementService commonTimeMgmtServiceF = commonTimeMgmtService;
-        final AssetAtlasService atlasF = atlas;
         final InputManagerService inputManagerF = inputManager;
         final TelephonyRegistry telephonyRegistryF = telephonyRegistry;
         final MediaRouterService mediaRouterF = mediaRouter;
@@ -1583,13 +1570,6 @@
                     reportWtf("Notifying CommonTimeManagementService running", e);
                 }
                 traceEnd();
-                traceBeginAndSlog("MakeAtlasServiceReady");
-                try {
-                    if (atlasF != null) atlasF.systemRunning();
-                } catch (Throwable e) {
-                    reportWtf("Notifying AssetAtlasService running", e);
-                }
-                traceEnd();
                 traceBeginAndSlog("MakeInputManagerServiceReady");
                 try {
                     // TODO(BT) Pass parameter to input manager
diff --git a/services/net/java/android/net/apf/ApfFilter.java b/services/net/java/android/net/apf/ApfFilter.java
index 957a8d3..a8356dc 100644
--- a/services/net/java/android/net/apf/ApfFilter.java
+++ b/services/net/java/android/net/apf/ApfFilter.java
@@ -283,10 +283,9 @@
         mReceiveThread.start();
     }
 
-    // Returns seconds since Unix Epoch.
-    // TODO: use SystemClock.elapsedRealtime() instead
+    // Returns seconds since device boot.
     private static long curTime() {
-        return System.currentTimeMillis() / DateUtils.SECOND_IN_MILLIS;
+        return SystemClock.elapsedRealtime() / DateUtils.SECOND_IN_MILLIS;
     }
 
     public static class InvalidRaException extends Exception {
@@ -379,16 +378,16 @@
         // TODO: Make this static once RA is its own class.
         private void prefixOptionToString(StringBuffer sb, int offset) {
             String prefix = IPv6AddresstoString(offset + 16);
-            int length = uint8(mPacket.get(offset + 2));
-            long valid = mPacket.getInt(offset + 4);
-            long preferred = mPacket.getInt(offset + 8);
+            int length = getUint8(mPacket, offset + 2);
+            long valid = getUint32(mPacket, offset + 4);
+            long preferred = getUint32(mPacket, offset + 8);
             sb.append(String.format("%s/%d %ds/%ds ", prefix, length, valid, preferred));
         }
 
         private void rdnssOptionToString(StringBuffer sb, int offset) {
-            int optLen = uint8(mPacket.get(offset + 1)) * 8;
+            int optLen = getUint8(mPacket, offset + 1) * 8;
             if (optLen < 24) return;  // Malformed or empty.
-            long lifetime = uint32(mPacket.getInt(offset + 4));
+            long lifetime = getUint32(mPacket, offset + 4);
             int numServers = (optLen - 8) / 16;
             sb.append("DNS ").append(lifetime).append("s");
             for (int server = 0; server < numServers; server++) {
@@ -402,7 +401,7 @@
                 sb.append(String.format("RA %s -> %s %ds ",
                         IPv6AddresstoString(IPV6_SRC_ADDR_OFFSET),
                         IPv6AddresstoString(IPV6_DEST_ADDR_OFFSET),
-                        uint16(mPacket.getShort(ICMP6_RA_ROUTER_LIFETIME_OFFSET))));
+                        getUint16(mPacket, ICMP6_RA_ROUTER_LIFETIME_OFFSET)));
                 for (int i: mPrefixOptionOffsets) {
                     prefixOptionToString(sb, i);
                 }
@@ -454,8 +453,8 @@
             // Sanity check packet in case a packet arrives before we attach RA filter
             // to our packet socket. b/29586253
             if (getUint16(mPacket, ETH_ETHERTYPE_OFFSET) != ETH_P_IPV6 ||
-                    uint8(mPacket.get(IPV6_NEXT_HEADER_OFFSET)) != IPPROTO_ICMPV6 ||
-                    uint8(mPacket.get(ICMP6_TYPE_OFFSET)) != ICMP6_ROUTER_ADVERTISEMENT) {
+                    getUint8(mPacket, IPV6_NEXT_HEADER_OFFSET) != IPPROTO_ICMPV6 ||
+                    getUint8(mPacket, ICMP6_TYPE_OFFSET) != ICMP6_ROUTER_ADVERTISEMENT) {
                 throw new InvalidRaException("Not an ICMP6 router advertisement");
             }
 
@@ -477,8 +476,8 @@
             mPacket.position(ICMP6_RA_OPTION_OFFSET);
             while (mPacket.hasRemaining()) {
                 final int position = mPacket.position();
-                final int optionType = uint8(mPacket.get(position));
-                final int optionLength = uint8(mPacket.get(position + 1)) * 8;
+                final int optionType = getUint8(mPacket, position);
+                final int optionLength = getUint8(mPacket, position + 1) * 8;
                 long lifetime;
                 switch (optionType) {
                     case ICMP6_PREFIX_OPTION_TYPE:
@@ -563,10 +562,10 @@
                 final long optionLifetime;
                 switch (lifetimeLength) {
                     case 2:
-                        optionLifetime = uint16(byteBuffer.getShort(offset));
+                        optionLifetime = getUint16(byteBuffer, offset);
                         break;
                     case 4:
-                        optionLifetime = uint32(byteBuffer.getInt(offset));
+                        optionLifetime = getUint32(byteBuffer, offset);
                         break;
                     default:
                         throw new IllegalStateException("bogus lifetime size " + lifetimeLength);
@@ -1162,7 +1161,11 @@
         return i & 0xffffffffL;
     }
 
-    private static long getUint16(ByteBuffer buffer, int position) {
+    private static int getUint8(ByteBuffer buffer, int position) {
+        return uint8(buffer.get(position));
+    }
+
+    private static int getUint16(ByteBuffer buffer, int position) {
         return uint16(buffer.getShort(position));
     }
 
diff --git a/services/net/java/android/net/ip/IpReachabilityMonitor.java b/services/net/java/android/net/ip/IpReachabilityMonitor.java
index a6bb40c..a883e28 100644
--- a/services/net/java/android/net/ip/IpReachabilityMonitor.java
+++ b/services/net/java/android/net/ip/IpReachabilityMonitor.java
@@ -50,9 +50,9 @@
 import java.net.SocketAddress;
 import java.net.SocketException;
 import java.nio.ByteBuffer;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -163,8 +163,7 @@
     private Map<InetAddress, Short> mIpWatchList = new HashMap<>();
     @GuardedBy("mLock")
     private int mIpWatchListVersion;
-    @GuardedBy("mLock")
-    private boolean mRunning;
+    private volatile boolean mRunning;
     // Time in milliseconds of the last forced probe request.
     private volatile long mLastProbeTimeMs;
 
@@ -246,7 +245,7 @@
     }
 
     public void stop() {
-        synchronized (mLock) { mRunning = false; }
+        mRunning = false;
         clearLinkProperties();
         mNetlinkSocketObserver.clearNetlinkSocket();
     }
@@ -281,12 +280,6 @@
         }
     }
 
-    private boolean stillRunning() {
-        synchronized (mLock) {
-            return mRunning;
-        }
-    }
-
     private static boolean isOnLink(List<RouteInfo> routes, InetAddress ip) {
         for (RouteInfo route : routes) {
             if (!route.hasGateway() && route.matches(ip)) {
@@ -390,12 +383,12 @@
     }
 
     public void probeAll() {
-        Set<InetAddress> ipProbeList = new HashSet<InetAddress>();
+        final List<InetAddress> ipProbeList;
         synchronized (mLock) {
-            ipProbeList.addAll(mIpWatchList.keySet());
+            ipProbeList = new ArrayList<>(mIpWatchList.keySet());
         }
 
-        if (!ipProbeList.isEmpty() && stillRunning()) {
+        if (!ipProbeList.isEmpty() && mRunning) {
             // Keep the CPU awake long enough to allow all ARP/ND
             // probes a reasonable chance at success. See b/23197666.
             //
@@ -406,7 +399,7 @@
         }
 
         for (InetAddress target : ipProbeList) {
-            if (!stillRunning()) {
+            if (!mRunning) {
                 break;
             }
             final int returnValue = probeNeighbor(mInterfaceIndex, target);
@@ -451,21 +444,21 @@
         @Override
         public void run() {
             if (VDBG) { Log.d(TAG, "Starting observing thread."); }
-            synchronized (mLock) { mRunning = true; }
+            mRunning = true;
 
             try {
                 setupNetlinkSocket();
             } catch (ErrnoException | SocketException e) {
                 Log.e(TAG, "Failed to suitably initialize a netlink socket", e);
-                synchronized (mLock) { mRunning = false; }
+                mRunning = false;
             }
 
-            ByteBuffer byteBuffer;
-            while (stillRunning()) {
+            while (mRunning) {
+                final ByteBuffer byteBuffer;
                 try {
                     byteBuffer = recvKernelReply();
                 } catch (ErrnoException e) {
-                    if (stillRunning()) { Log.w(TAG, "ErrnoException: ", e); }
+                    if (mRunning) { Log.w(TAG, "ErrnoException: ", e); }
                     break;
                 }
                 final long whenMs = SystemClock.elapsedRealtime();
@@ -477,7 +470,7 @@
 
             clearNetlinkSocket();
 
-            synchronized (mLock) { mRunning = false; }
+            mRunning = false; // Not a no-op when ErrnoException happened.
             if (VDBG) { Log.d(TAG, "Finishing observing thread."); }
         }
 
diff --git a/services/tests/servicestests/src/com/android/server/am/ConfigurationContainerTests.java b/services/tests/servicestests/src/com/android/server/am/ConfigurationContainerTests.java
new file mode 100644
index 0000000..92c442e
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/am/ConfigurationContainerTests.java
@@ -0,0 +1,238 @@
+/*
+ * Copyright (C) 2016 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 com.android.server.am;
+
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import android.content.res.Configuration;
+import android.platform.test.annotations.Presubmit;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test class for {@link ConfigurationContainer}. Mostly duplicates configuration tests from
+ * {@link com.android.server.wm.WindowContainerTests}.
+ *
+ * Build: mmma -j32 frameworks/base/services/tests/servicestests
+ * Install: adb install -r out/target/product/$TARGET_PRODUCT/data/app/FrameworksServicesTests/FrameworksServicesTests.apk
+ * Run: adb shell am instrument -w -e class com.android.server.am.ConfigurationContainerTests com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
+ */
+@SmallTest
+@Presubmit
+@RunWith(AndroidJUnit4.class)
+public class ConfigurationContainerTests {
+
+    @Test
+    public void testConfigurationInit() throws Exception {
+        // Check root container initial config.
+        final TestConfigurationContainer root = new TestConfigurationContainer();
+        assertEquals(Configuration.EMPTY, root.getOverrideConfiguration());
+        assertEquals(Configuration.EMPTY, root.getMergedOverrideConfiguration());
+        assertEquals(Configuration.EMPTY, root.getConfiguration());
+
+        // Check child initial config.
+        final TestConfigurationContainer child1 = root.addChild();
+        assertEquals(Configuration.EMPTY, child1.getOverrideConfiguration());
+        assertEquals(Configuration.EMPTY, child1.getMergedOverrideConfiguration());
+        assertEquals(Configuration.EMPTY, child1.getConfiguration());
+
+        // Check child initial config if root has overrides.
+        final Configuration rootOverrideConfig = new Configuration();
+        rootOverrideConfig.fontScale = 1.3f;
+        root.onOverrideConfigurationChanged(rootOverrideConfig);
+        final TestConfigurationContainer child2 = root.addChild();
+        assertEquals(Configuration.EMPTY, child2.getOverrideConfiguration());
+        assertEquals(rootOverrideConfig, child2.getMergedOverrideConfiguration());
+        assertEquals(rootOverrideConfig, child2.getConfiguration());
+
+        // Check child initial config if root has parent config set.
+        final Configuration rootParentConfig = new Configuration();
+        rootParentConfig.fontScale = 0.8f;
+        rootParentConfig.orientation = SCREEN_ORIENTATION_LANDSCAPE;
+        root.onConfigurationChanged(rootParentConfig);
+        final Configuration rootFullConfig = new Configuration(rootParentConfig);
+        rootFullConfig.updateFrom(rootOverrideConfig);
+
+        final TestConfigurationContainer child3 = root.addChild();
+        assertEquals(Configuration.EMPTY, child3.getOverrideConfiguration());
+        assertEquals(rootOverrideConfig, child3.getMergedOverrideConfiguration());
+        assertEquals(rootFullConfig, child3.getConfiguration());
+    }
+
+    @Test
+    public void testConfigurationChangeOnAddRemove() throws Exception {
+        // Init root's config.
+        final TestConfigurationContainer root = new TestConfigurationContainer();
+        final Configuration rootOverrideConfig = new Configuration();
+        rootOverrideConfig.fontScale = 1.3f;
+        root.onOverrideConfigurationChanged(rootOverrideConfig);
+
+        // Init child's config.
+        final TestConfigurationContainer child = root.addChild();
+        final Configuration childOverrideConfig = new Configuration();
+        childOverrideConfig.densityDpi = 320;
+        child.onOverrideConfigurationChanged(childOverrideConfig);
+
+        // Check configuration update when child is removed from parent.
+        root.removeChild(child);
+        assertEquals(childOverrideConfig, child.getOverrideConfiguration());
+        assertEquals(childOverrideConfig, child.getMergedOverrideConfiguration());
+        assertEquals(childOverrideConfig, child.getConfiguration());
+
+        // It may be paranoia... but let's check if parent's config didn't change after removal.
+        assertEquals(rootOverrideConfig, root.getOverrideConfiguration());
+        assertEquals(rootOverrideConfig, root.getMergedOverrideConfiguration());
+        assertEquals(rootOverrideConfig, root.getConfiguration());
+
+        // Check configuration update when child is added to parent.
+        final Configuration mergedOverrideConfig = new Configuration(root.getConfiguration());
+        mergedOverrideConfig.updateFrom(childOverrideConfig);
+        root.addChild(child);
+        assertEquals(childOverrideConfig, child.getOverrideConfiguration());
+        assertEquals(mergedOverrideConfig, child.getMergedOverrideConfiguration());
+        assertEquals(mergedOverrideConfig, child.getConfiguration());
+    }
+
+    @Test
+    public void testConfigurationChangePropagation() throws Exception {
+        // Builds 3-level vertical hierarchy with one configuration container on each level.
+        // In addition to different overrides on each level, everyone in hierarchy will have one
+        // common overridden value - orientation;
+
+        // Init root's config.
+        final TestConfigurationContainer root = new TestConfigurationContainer();
+        final Configuration rootOverrideConfig = new Configuration();
+        rootOverrideConfig.fontScale = 1.3f;
+        rootOverrideConfig.orientation = SCREEN_ORIENTATION_REVERSE_LANDSCAPE;
+        root.onOverrideConfigurationChanged(rootOverrideConfig);
+
+        // Init children.
+        final TestConfigurationContainer child1 = root.addChild();
+        final Configuration childOverrideConfig1 = new Configuration();
+        childOverrideConfig1.densityDpi = 320;
+        childOverrideConfig1.orientation = SCREEN_ORIENTATION_LANDSCAPE;
+        child1.onOverrideConfigurationChanged(childOverrideConfig1);
+
+        final TestConfigurationContainer child2 = child1.addChild();
+        final Configuration childOverrideConfig2 = new Configuration();
+        childOverrideConfig2.screenWidthDp = 150;
+        childOverrideConfig2.orientation = SCREEN_ORIENTATION_PORTRAIT;
+        child2.onOverrideConfigurationChanged(childOverrideConfig2);
+
+        // Check configuration on all levels when root override is updated.
+        rootOverrideConfig.smallestScreenWidthDp = 200;
+        root.onOverrideConfigurationChanged(rootOverrideConfig);
+
+        final Configuration mergedOverrideConfig1 = new Configuration(rootOverrideConfig);
+        mergedOverrideConfig1.updateFrom(childOverrideConfig1);
+        final Configuration mergedConfig1 = new Configuration(mergedOverrideConfig1);
+
+        final Configuration mergedOverrideConfig2 = new Configuration(mergedOverrideConfig1);
+        mergedOverrideConfig2.updateFrom(childOverrideConfig2);
+        final Configuration mergedConfig2 = new Configuration(mergedOverrideConfig2);
+
+        assertEquals(rootOverrideConfig, root.getOverrideConfiguration());
+        assertEquals(rootOverrideConfig, root.getMergedOverrideConfiguration());
+        assertEquals(rootOverrideConfig, root.getConfiguration());
+
+        assertEquals(childOverrideConfig1, child1.getOverrideConfiguration());
+        assertEquals(mergedOverrideConfig1, child1.getMergedOverrideConfiguration());
+        assertEquals(mergedConfig1, child1.getConfiguration());
+
+        assertEquals(childOverrideConfig2, child2.getOverrideConfiguration());
+        assertEquals(mergedOverrideConfig2, child2.getMergedOverrideConfiguration());
+        assertEquals(mergedConfig2, child2.getConfiguration());
+
+        // Check configuration on all levels when root parent config is updated.
+        final Configuration rootParentConfig = new Configuration();
+        rootParentConfig.screenHeightDp = 100;
+        rootParentConfig.orientation = SCREEN_ORIENTATION_REVERSE_PORTRAIT;
+        root.onConfigurationChanged(rootParentConfig);
+        final Configuration mergedRootConfig = new Configuration(rootParentConfig);
+        mergedRootConfig.updateFrom(rootOverrideConfig);
+
+        mergedConfig1.setTo(mergedRootConfig);
+        mergedConfig1.updateFrom(mergedOverrideConfig1);
+
+        mergedConfig2.setTo(mergedConfig1);
+        mergedConfig2.updateFrom(mergedOverrideConfig2);
+
+        assertEquals(rootOverrideConfig, root.getOverrideConfiguration());
+        assertEquals(rootOverrideConfig, root.getMergedOverrideConfiguration());
+        assertEquals(mergedRootConfig, root.getConfiguration());
+
+        assertEquals(childOverrideConfig1, child1.getOverrideConfiguration());
+        assertEquals(mergedOverrideConfig1, child1.getMergedOverrideConfiguration());
+        assertEquals(mergedConfig1, child1.getConfiguration());
+
+        assertEquals(childOverrideConfig2, child2.getOverrideConfiguration());
+        assertEquals(mergedOverrideConfig2, child2.getMergedOverrideConfiguration());
+        assertEquals(mergedConfig2, child2.getConfiguration());
+    }
+
+    /**
+     * Contains minimal implementation of {@link ConfigurationContainer}'s abstract behavior needed
+     * for testing.
+     */
+    private class TestConfigurationContainer
+            extends ConfigurationContainer<TestConfigurationContainer> {
+        private List<TestConfigurationContainer> mChildren = new ArrayList<>();
+        private TestConfigurationContainer mParent;
+
+        TestConfigurationContainer addChild(TestConfigurationContainer childContainer) {
+            childContainer.mParent = this;
+            childContainer.onParentChanged();
+            mChildren.add(childContainer);
+            return childContainer;
+        }
+
+        TestConfigurationContainer addChild() {
+            return addChild(new TestConfigurationContainer());
+        }
+
+        void removeChild(TestConfigurationContainer child) {
+            child.mParent = null;
+            child.onParentChanged();
+        }
+
+        @Override
+        protected int getChildCount() {
+            return mChildren.size();
+        }
+
+        @Override
+        protected TestConfigurationContainer getChildAt(int index) {
+            return mChildren.get(index);
+        }
+
+        @Override
+        protected ConfigurationContainer getParent() {
+            return mParent;
+        }
+    }
+}
diff --git a/services/tests/servicestests/src/com/android/server/connectivity/NetdEventListenerServiceTest.java b/services/tests/servicestests/src/com/android/server/connectivity/NetdEventListenerServiceTest.java
index 63d5d9fb..9e2fd62 100644
--- a/services/tests/servicestests/src/com/android/server/connectivity/NetdEventListenerServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/connectivity/NetdEventListenerServiceTest.java
@@ -158,7 +158,8 @@
 
     void log(int netId, int[] latencies) {
         for (int l : latencies) {
-            mNetdEventListenerService.onDnsEvent(netId, EVENT_TYPE, RETURN_CODE, l);
+            mNetdEventListenerService.onDnsEvent(netId, EVENT_TYPE, RETURN_CODE, l, null, null, 0,
+                    0);
         }
     }
 
diff --git a/services/tests/servicestests/src/com/android/server/connectivity/VpnTest.java b/services/tests/servicestests/src/com/android/server/connectivity/VpnTest.java
index 5d8b843..b51b277 100644
--- a/services/tests/servicestests/src/com/android/server/connectivity/VpnTest.java
+++ b/services/tests/servicestests/src/com/android/server/connectivity/VpnTest.java
@@ -25,9 +25,11 @@
 
 import android.annotation.UserIdInt;
 import android.app.AppOpsManager;
+import android.app.NotificationManager;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.pm.UserInfo;
+import android.net.NetworkInfo.DetailedState;
 import android.net.UidRange;
 import android.os.INetworkManagementService;
 import android.os.Looper;
@@ -43,6 +45,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.mockito.ArgumentCaptor;
+import org.mockito.InOrder;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
@@ -88,14 +92,18 @@
     @Mock private PackageManager mPackageManager;
     @Mock private INetworkManagementService mNetService;
     @Mock private AppOpsManager mAppOps;
+    @Mock private NotificationManager mNotificationManager;
 
     @Override
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
         when(mContext.getPackageManager()).thenReturn(mPackageManager);
         setMockedPackages(mPackages);
+        when(mContext.getPackageName()).thenReturn(Vpn.class.getPackage().getName());
         when(mContext.getSystemService(eq(Context.USER_SERVICE))).thenReturn(mUserManager);
         when(mContext.getSystemService(eq(Context.APP_OPS_SERVICE))).thenReturn(mAppOps);
+        when(mContext.getSystemService(eq(Context.NOTIFICATION_SERVICE)))
+                .thenReturn(mNotificationManager);
         doNothing().when(mNetService).registerObserver(any());
     }
 
@@ -103,7 +111,7 @@
     public void testRestrictedProfilesAreAddedToVpn() {
         setMockedUsers(primaryUser, secondaryUser, restrictedProfileA, restrictedProfileB);
 
-        final Vpn vpn = new MockVpn(primaryUser.id);
+        final Vpn vpn = spyVpn(primaryUser.id);
         final Set<UidRange> ranges = vpn.createUserAndRestrictedProfilesRanges(primaryUser.id,
                 null, null);
 
@@ -117,7 +125,7 @@
     public void testManagedProfilesAreNotAddedToVpn() {
         setMockedUsers(primaryUser, managedProfileA);
 
-        final Vpn vpn = new MockVpn(primaryUser.id);
+        final Vpn vpn = spyVpn(primaryUser.id);
         final Set<UidRange> ranges = vpn.createUserAndRestrictedProfilesRanges(primaryUser.id,
                 null, null);
 
@@ -130,7 +138,7 @@
     public void testAddUserToVpnOnlyAddsOneUser() {
         setMockedUsers(primaryUser, restrictedProfileA, managedProfileA);
 
-        final Vpn vpn = new MockVpn(primaryUser.id);
+        final Vpn vpn = spyVpn(primaryUser.id);
         final Set<UidRange> ranges = new ArraySet<>();
         vpn.addUserToRanges(ranges, primaryUser.id, null, null);
 
@@ -141,7 +149,7 @@
 
     @SmallTest
     public void testUidWhiteAndBlacklist() throws Exception {
-        final Vpn vpn = new MockVpn(primaryUser.id);
+        final Vpn vpn = spyVpn(primaryUser.id);
         final UidRange user = UidRange.createForUser(primaryUser.id);
         final String[] packages = {PKGS[0], PKGS[1], PKGS[2]};
 
@@ -166,15 +174,15 @@
 
     @SmallTest
     public void testLockdownChangingPackage() throws Exception {
-        final MockVpn vpn = new MockVpn(primaryUser.id);
+        final Vpn vpn = spyVpn(primaryUser.id);
         final UidRange user = UidRange.createForUser(primaryUser.id);
 
         // Default state.
-        vpn.assertUnblocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
+        assertUnblocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
 
         // Set always-on without lockdown.
         assertTrue(vpn.setAlwaysOnPackage(PKGS[1], false));
-        vpn.assertUnblocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
+        assertUnblocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
 
         // Set always-on with lockdown.
         assertTrue(vpn.setAlwaysOnPackage(PKGS[1], true));
@@ -182,8 +190,8 @@
             new UidRange(user.start, user.start + PKG_UIDS[1] - 1),
             new UidRange(user.start + PKG_UIDS[1] + 1, user.stop)
         }));
-        vpn.assertBlocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
-        vpn.assertUnblocked(user.start + PKG_UIDS[1]);
+        assertBlocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[2], user.start + PKG_UIDS[3]);
+        assertUnblocked(vpn, user.start + PKG_UIDS[1]);
 
         // Switch to another app.
         assertTrue(vpn.setAlwaysOnPackage(PKGS[3], true));
@@ -195,13 +203,13 @@
             new UidRange(user.start, user.start + PKG_UIDS[3] - 1),
             new UidRange(user.start + PKG_UIDS[3] + 1, user.stop)
         }));
-        vpn.assertBlocked(user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2]);
-        vpn.assertUnblocked(user.start + PKG_UIDS[3]);
+        assertBlocked(vpn, user.start + PKG_UIDS[0], user.start + PKG_UIDS[1], user.start + PKG_UIDS[2]);
+        assertUnblocked(vpn, user.start + PKG_UIDS[3]);
     }
 
     @SmallTest
     public void testLockdownAddingAProfile() throws Exception {
-        final MockVpn vpn = new MockVpn(primaryUser.id);
+        final Vpn vpn = spyVpn(primaryUser.id);
         setMockedUsers(primaryUser);
 
         // Make a copy of the restricted profile, as we're going to mark it deleted halfway through.
@@ -220,7 +228,7 @@
         }));
 
         // Verify restricted user isn't affected at first.
-        vpn.assertUnblocked(profile.start + PKG_UIDS[0]);
+        assertUnblocked(vpn, profile.start + PKG_UIDS[0]);
 
         // Add the restricted user.
         setMockedUsers(primaryUser, tempProfile);
@@ -239,24 +247,53 @@
         }));
     }
 
+    @SmallTest
+    public void testNotificationShownForAlwaysOnApp() {
+        final Vpn vpn = spyVpn(primaryUser.id);
+        final InOrder order = inOrder(vpn);
+        setMockedUsers(primaryUser);
+
+        // Don't show a notification for regular disconnected states.
+        vpn.updateState(DetailedState.DISCONNECTED, TAG);
+        order.verify(vpn).updateAlwaysOnNotificationInternal(false);
+
+        // Start showing a notification for disconnected once always-on.
+        vpn.setAlwaysOnPackage(PKGS[0], false);
+        order.verify(vpn).updateAlwaysOnNotificationInternal(true);
+
+        // Stop showing the notification once connected.
+        vpn.updateState(DetailedState.CONNECTED, TAG);
+        order.verify(vpn).updateAlwaysOnNotificationInternal(false);
+
+        // Show the notification if we disconnect again.
+        vpn.updateState(DetailedState.DISCONNECTED, TAG);
+        order.verify(vpn).updateAlwaysOnNotificationInternal(true);
+
+        // Notification should be cleared after unsetting always-on package.
+        vpn.setAlwaysOnPackage(null, false);
+        order.verify(vpn).updateAlwaysOnNotificationInternal(false);
+    }
+
     /**
-     * A subclass of {@link Vpn} with some of the fields pre-mocked.
+     * Mock some methods of vpn object.
      */
-    private class MockVpn extends Vpn {
-        public MockVpn(@UserIdInt int userId) {
-            super(Looper.myLooper(), mContext, mNetService, userId);
-        }
+    private Vpn spyVpn(@UserIdInt int userId) {
+        final Vpn vpn = spy(new Vpn(Looper.myLooper(), mContext, mNetService, userId));
 
-        public void assertBlocked(int... uids) {
-            for (int uid : uids) {
-                assertTrue("Uid " + uid + " should be blocked", isBlockingUid(uid));
-            }
-        }
+        // Block calls to the NotificationManager or PendingIntent#getActivity.
+        doNothing().when(vpn).updateAlwaysOnNotificationInternal(anyBoolean());
+        return vpn;
+    }
 
-        public void assertUnblocked(int... uids) {
-            for (int uid : uids) {
-                assertFalse("Uid " + uid + " should not be blocked", isBlockingUid(uid));
-            }
+    private static void assertBlocked(Vpn vpn, int... uids) {
+        for (int uid : uids) {
+            assertTrue("Uid " + uid + " should be blocked", vpn.isBlockingUid(uid));
+        }
+    }
+
+    private static void assertUnblocked(Vpn vpn, int... uids) {
+        for (int uid : uids) {
+            assertFalse("Uid " + uid + " should not be blocked", vpn.isBlockingUid(uid));
         }
     }
 
diff --git a/services/tests/servicestests/src/com/android/server/notification/SnoozeHelperTest.java b/services/tests/servicestests/src/com/android/server/notification/SnoozeHelperTest.java
new file mode 100644
index 0000000..ec1fdad
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/notification/SnoozeHelperTest.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright (C) 2016 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 com.android.server.notification;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import android.app.AlarmManager;
+import android.app.Notification;
+import android.app.NotificationChannel;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.os.UserHandle;
+import android.service.notification.StatusBarNotification;
+import android.support.test.InstrumentationRegistry;
+import android.support.test.runner.AndroidJUnit4;
+import android.test.suitebuilder.annotation.SmallTest;
+
+import static junit.framework.Assert.assertFalse;
+import static junit.framework.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class SnoozeHelperTest {
+    @Mock SnoozeHelper.Callback mCallback;
+    @Mock AlarmManager mAm;
+    @Mock ManagedServices.UserProfiles mUserProfiles;
+
+    private SnoozeHelper mSnoozeHelper;
+
+    private Context getContext() {
+        return InstrumentationRegistry.getTargetContext();
+    }
+
+    @Before
+    public void setUp() {
+        MockitoAnnotations.initMocks(this);
+
+        mSnoozeHelper = new SnoozeHelper(getContext(), mCallback, mUserProfiles);
+        mSnoozeHelper.setAlarmManager(mAm);
+    }
+
+    @Test
+    public void testSnooze() throws Exception {
+        NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);
+        mSnoozeHelper.snooze(r , UserHandle.USER_SYSTEM, 1000);
+        verify(mAm, times(1)).setExactAndAllowWhileIdle(
+                anyInt(), eq((long) 1000), any(PendingIntent.class));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey()));
+    }
+
+    @Test
+    public void testCancelByApp() throws Exception {
+        NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);
+        NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM);
+        mSnoozeHelper.snooze(r , UserHandle.USER_SYSTEM, 1000);
+        mSnoozeHelper.snooze(r2 , UserHandle.USER_SYSTEM, 1000);
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey()));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey()));
+
+        mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, r.sbn.getPackageName(), "one", 1);
+        // 3 = one for each snooze, above + one for cancel itself.
+        verify(mAm, times(3)).cancel(any(PendingIntent.class));
+        assertFalse(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey()));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey()));
+    }
+
+    @Test
+    public void testCancelAllForUser() throws Exception {
+        NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);
+        NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM);
+        NotificationRecord r3 = getNotificationRecord("pkg", 3, "three", UserHandle.ALL);
+        mSnoozeHelper.snooze(r , UserHandle.USER_SYSTEM, 1000);
+        mSnoozeHelper.snooze(r2 , UserHandle.USER_SYSTEM, 1000);
+        mSnoozeHelper.snooze(r3 , UserHandle.USER_ALL, 1000);
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey()));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey()));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_ALL, r3.sbn.getPackageName(), r3.getKey()));
+
+        mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, false);
+        // 5 = once for each snooze above (3) + once for each notification canceled (2).
+        verify(mAm, times(5)).cancel(any(PendingIntent.class));
+        assertFalse(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey()));
+        assertFalse(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey()));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_ALL, r3.sbn.getPackageName(), r3.getKey()));
+    }
+
+    @Test
+    public void testCancelAllByApp() throws Exception {
+        NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);
+        NotificationRecord r2 = getNotificationRecord("pkg", 2, "two", UserHandle.SYSTEM);
+        NotificationRecord r3 = getNotificationRecord("pkg2", 3, "three", UserHandle.SYSTEM);
+        mSnoozeHelper.snooze(r , UserHandle.USER_SYSTEM, 1000);
+        mSnoozeHelper.snooze(r2 , UserHandle.USER_SYSTEM, 1000);
+        mSnoozeHelper.snooze(r3 , UserHandle.USER_SYSTEM, 1000);
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey()));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey()));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r3.sbn.getPackageName(), r3.getKey()));
+
+        mSnoozeHelper.cancel(UserHandle.USER_SYSTEM, "pkg2");
+        // 4 = once for each snooze above (3) + once for each notification canceled (1).
+        verify(mAm, times(4)).cancel(any(PendingIntent.class));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r.sbn.getPackageName(), r.getKey()));
+        assertTrue(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r2.sbn.getPackageName(), r2.getKey()));
+        assertFalse(mSnoozeHelper.isSnoozed(
+                UserHandle.USER_SYSTEM, r3.sbn.getPackageName(), r3.getKey()));
+    }
+
+    @Test
+    public void testRepost() throws Exception {
+        NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);
+        mSnoozeHelper.snooze(r , UserHandle.USER_SYSTEM, 1000);
+        NotificationRecord r2 = getNotificationRecord("pkg", 2, "one", UserHandle.ALL);
+        mSnoozeHelper.snooze(r2 , UserHandle.USER_ALL, 1000);
+        mSnoozeHelper.repost(r.sbn.getPackageName(), r.getKey(), UserHandle.USER_SYSTEM);
+        verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r);
+    }
+
+    @Test
+    public void testUpdate() throws Exception {
+        NotificationRecord r = getNotificationRecord("pkg", 1, "one", UserHandle.SYSTEM);
+        mSnoozeHelper.snooze(r , UserHandle.USER_SYSTEM, 1000);
+        r.getNotification().category = "NEW CATEGORY";
+
+        mSnoozeHelper.update(UserHandle.USER_SYSTEM, r);
+        verify(mCallback, never()).repost(anyInt(), any(NotificationRecord.class));
+
+        mSnoozeHelper.repost(r.sbn.getPackageName(), r.getKey(), UserHandle.USER_SYSTEM);
+        verify(mCallback, times(1)).repost(UserHandle.USER_SYSTEM, r);
+    }
+
+    private NotificationRecord getNotificationRecord(String pkg, int id, String tag,
+            UserHandle user) {
+        Notification n = new Notification.Builder(getContext())
+                .setContentTitle("A")
+                .setGroup("G")
+                .setSortKey("A")
+                .setWhen(1205)
+                .build();
+        return new NotificationRecord(getContext(), new StatusBarNotification(
+                pkg, pkg, id, tag, 0, 0, 0, n, user),
+                new NotificationChannel(NotificationChannel.DEFAULT_CHANNEL_ID, "name"));
+    }
+
+}
diff --git a/services/tests/servicestests/src/com/android/server/utils/PriorityDumpTest.java b/services/tests/servicestests/src/com/android/server/utils/PriorityDumpTest.java
new file mode 100644
index 0000000..d378b7c
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/utils/PriorityDumpTest.java
@@ -0,0 +1,210 @@
+/**
+ * Copyright (c) 2016, 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 com.android.server.utils;
+
+import static com.android.server.utils.PriorityDump.dump;
+
+import static org.junit.Assert.assertSame;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Matchers.same;
+import static org.mockito.Mockito.verify;
+
+import android.platform.test.annotations.Presubmit;
+import android.support.test.filters.SmallTest;
+import com.android.server.utils.PriorityDump.PriorityDumper;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+@SmallTest
+@Presubmit
+@RunWith(JUnit4.class)
+public class PriorityDumpTest {
+
+    private static final String[] EMPTY_ARGS = {};
+
+    @Mock
+    private PriorityDumper mDumper;
+    @Mock
+    private PrintWriter mPw;
+
+    private final FileDescriptor mFd = FileDescriptor.err;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+    }
+
+    @Test
+    public void testNullArgs() {
+        dump(mDumper, mFd, mPw, null);
+        verify(mDumper).dump(same(mFd), same(mPw), eq(null));
+    }
+
+    @Test
+    public void testNoArgs() {
+        dump(mDumper, mFd, mPw, EMPTY_ARGS);
+        verify(mDumper).dump(same(mFd), same(mPw), same(EMPTY_ARGS));
+    }
+
+    @Test
+    public void testNonPriorityArgs() {
+        final String[] args = {
+                "--dumb_priority"
+        };
+        dump(mDumper, mFd, mPw, args);
+        verify(mDumper).dump(same(mFd), same(mPw), same(args));
+    }
+
+    @Test
+    public void testMissingPriority() {
+        final String[] args = {
+                "--dump_priority"
+        };
+        dump(mDumper, mFd, mPw, args);
+        verify(mDumper).dump(same(mFd), same(mPw), same(args));
+    }
+
+    @Test
+    public void testInvalidPriorityNoExtraArgs() {
+        final String[] args = {
+                "--dump_priority", "SUPER_HIGH"
+        };
+        dump(mDumper, mFd, mPw, args);
+        verify(mDumper).dump(same(mFd), same(mPw), same(args));
+    }
+
+    @Test
+    public void testInvalidPriorityExtraArgs() {
+        final String[] args = {
+                "--dump_priority", "SUPER_HIGH", "--high", "--five"
+        };
+        dump(mDumper, mFd, mPw, args);
+        verify(mDumper).dump(same(mFd), same(mPw), same(args));
+    }
+
+    @Test
+    public void testNoPriorityCallsAllMethods() {
+        final String[] args = {
+                "1", "2", "3"
+        };
+
+        // Cannot use mDumper here because it would mock the dump() call.
+        final FakeDumper fakeDumper = new FakeDumper();
+
+        dump(fakeDumper, mFd, mPw, args);
+
+        assertSame(mFd, fakeDumper.criticalFd);
+        assertSame(mPw, fakeDumper.criticalPw);
+        assertSame(args, fakeDumper.criticalArgs);
+        assertSame(mFd, fakeDumper.highFd);
+        assertSame(mPw, fakeDumper.highPw);
+        assertSame(args, fakeDumper.highArgs);
+        assertSame(mFd, fakeDumper.normalFd);
+        assertSame(mPw, fakeDumper.normalPw);
+        assertSame(args, fakeDumper.normalArgs);
+    }
+
+    @Test
+    public void testCriticalNoExtraArgs() {
+        dump(mDumper, mFd, mPw, new String[] {
+                "--dump_priority", "CRITICAL"
+        });
+        verify(mDumper).dumpCritical(same(mFd), same(mPw), eq(EMPTY_ARGS));
+    }
+
+    @Test
+    public void testCriticalExtraArgs() {
+        dump(mDumper, mFd, mPw, new String[] {
+                "--dump_priority", "CRITICAL", "--high", "--five"
+        });
+        verify(mDumper).dumpCritical(same(mFd), same(mPw), eq(new String[] {
+                "--high", "--five"
+        }));
+    }
+
+    @Test
+    public void testHighNoExtraArgs() {
+        dump(mDumper, mFd, mPw, new String[] {
+                "--dump_priority", "HIGH"
+        });
+        verify(mDumper).dumpHigh(same(mFd), same(mPw), eq(EMPTY_ARGS));
+    }
+
+    @Test
+    public void testHighExtraArgs() {
+        dump(mDumper, mFd, mPw, new String[] {
+                "--dump_priority", "HIGH", "--high", "--five"
+        });
+        verify(mDumper).dumpHigh(same(mFd), same(mPw), eq(new String[] {
+                "--high", "--five"
+        }));
+    }
+
+    @Test
+    public void testNormalNoExtraArgs() {
+        dump(mDumper, mFd, mPw, new String[] {
+                "--dump_priority", "NORMAL"
+        });
+        verify(mDumper).dumpNormal(same(mFd), same(mPw), eq(EMPTY_ARGS));
+    }
+
+    @Test
+    public void testNormalExtraArgs() {
+        dump(mDumper, mFd, mPw, new String[] {
+                "--dump_priority", "NORMAL", "--high", "--five"
+        });
+        verify(mDumper).dumpNormal(same(mFd), same(mPw), eq(new String[] {
+                "--high", "--five"
+        }));
+    }
+
+    private final class FakeDumper implements PriorityDumper {
+
+        String[] criticalArgs, highArgs, normalArgs;
+        FileDescriptor criticalFd, highFd, normalFd;
+        PrintWriter criticalPw, highPw, normalPw;
+
+        @Override
+        public void dumpCritical(FileDescriptor fd, PrintWriter pw, String[] args) {
+            criticalFd = fd;
+            criticalPw = pw;
+            criticalArgs = args;
+        }
+
+        @Override
+        public void dumpHigh(FileDescriptor fd, PrintWriter pw, String[] args) {
+            highFd = fd;
+            highPw = pw;
+            highArgs = args;
+        }
+
+        @Override
+        public void dumpNormal(FileDescriptor fd, PrintWriter pw, String[] args) {
+            normalFd = fd;
+            normalPw = pw;
+            normalArgs = args;
+        }
+    }
+}
diff --git a/services/tests/servicestests/src/com/android/server/webkit/WebViewUpdateServiceTest.java b/services/tests/servicestests/src/com/android/server/webkit/WebViewUpdateServiceTest.java
index 7f171fb..0f898e5 100644
--- a/services/tests/servicestests/src/com/android/server/webkit/WebViewUpdateServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/webkit/WebViewUpdateServiceTest.java
@@ -303,6 +303,31 @@
 
         WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
         assertEquals(WebViewFactory.LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES, response.status);
+        assertEquals(null, mWebViewUpdateServiceImpl.getCurrentWebViewPackage());
+
+        // Now install a package
+        String singlePackage = "singlePackage";
+        packages = new WebViewProviderInfo[]{
+            new WebViewProviderInfo(singlePackage, "", true, false, null)};
+        setupWithPackages(packages);
+        setEnabledAndValidPackageInfos(packages);
+
+        mWebViewUpdateServiceImpl.packageStateChanged(singlePackage,
+                WebViewUpdateService.PACKAGE_ADDED, 0);
+
+        checkPreparationPhasesForPackage(singlePackage, 1 /* number of finished preparations */);
+        assertEquals(singlePackage,
+                mWebViewUpdateServiceImpl.getCurrentWebViewPackage().packageName);
+
+        // Remove the package again
+        mTestSystemImpl.removePackageInfo(singlePackage);
+        mWebViewUpdateServiceImpl.packageStateChanged(singlePackage,
+                WebViewUpdateService.PACKAGE_ADDED, 0);
+
+        // Package removed - ensure our interface states that there is no package
+        response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
+        assertEquals(WebViewFactory.LIBLOAD_FAILED_LISTING_WEBVIEW_PACKAGES, response.status);
+        assertEquals(null, mWebViewUpdateServiceImpl.getCurrentWebViewPackage());
     }
 
     public void testFailListingInvalidWebviewPackage() {
@@ -395,7 +420,8 @@
         Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(
                 Mockito.argThat(new IsPackageInfoWithName(firstPackage)));
 
-        assertEquals(firstPackage, mWebViewUpdateServiceImpl.getCurrentWebViewPackageName());
+        assertEquals(firstPackage,
+                mWebViewUpdateServiceImpl.getCurrentWebViewPackage().packageName);
 
         new Thread(new Runnable() {
             @Override
@@ -1243,4 +1269,42 @@
 
         checkPreparationPhasesForPackage(primaryPackage, 3 /* third preparation phase */);
     }
+
+    public void testGetCurrentWebViewPackage() {
+        PackageInfo firstPackage = createPackageInfo("first", true /* enabled */,
+                        true /* valid */, true /* installed */);
+        firstPackage.versionCode = 100;
+        firstPackage.versionName = "first package version";
+        WebViewProviderInfo[] packages = new WebViewProviderInfo[] {
+            new WebViewProviderInfo(firstPackage.packageName, "", true, false, null)};
+        setupWithPackages(packages, true);
+        mTestSystemImpl.setPackageInfo(firstPackage);
+
+        mWebViewUpdateServiceImpl.prepareWebViewInSystemServer();
+
+        Mockito.verify(mTestSystemImpl).onWebViewProviderChanged(
+                Mockito.argThat(new IsPackageInfoWithName(firstPackage.packageName)));
+
+        mWebViewUpdateServiceImpl.notifyRelroCreationCompleted();
+
+        // Ensure the API is correct before running waitForAndGetProvider
+        assertEquals(firstPackage.packageName,
+                mWebViewUpdateServiceImpl.getCurrentWebViewPackage().packageName);
+        assertEquals(firstPackage.versionCode,
+                mWebViewUpdateServiceImpl.getCurrentWebViewPackage().versionCode);
+        assertEquals(firstPackage.versionName,
+                mWebViewUpdateServiceImpl.getCurrentWebViewPackage().versionName);
+
+        WebViewProviderResponse response = mWebViewUpdateServiceImpl.waitForAndGetProvider();
+        assertEquals(WebViewFactory.LIBLOAD_SUCCESS, response.status);
+        assertEquals(firstPackage.packageName, response.packageInfo.packageName);
+
+        // Ensure the API is still correct after running waitForAndGetProvider
+        assertEquals(firstPackage.packageName,
+                mWebViewUpdateServiceImpl.getCurrentWebViewPackage().packageName);
+        assertEquals(firstPackage.versionCode,
+                mWebViewUpdateServiceImpl.getCurrentWebViewPackage().versionCode);
+        assertEquals(firstPackage.versionName,
+                mWebViewUpdateServiceImpl.getCurrentWebViewPackage().versionName);
+    }
 }
diff --git a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java
index 27d9d10..74e8c9d 100644
--- a/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java
+++ b/services/tests/servicestests/src/com/android/server/wm/AppWindowTokenTests.java
@@ -76,15 +76,14 @@
     private WindowState createWindow(WindowState parent, int type, WindowToken token) {
         final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
 
-        return new WindowState(sWm, null, mIWindow, token, parent, 0, 0, attrs, 0,
-                sWm.getDefaultDisplayContentLocked(), 0);
+        return new WindowState(sWm, null, mIWindow, token, parent, 0, 0, attrs, 0, 0);
     }
 
     /* Used so we can gain access to some protected members of the {@link AppWindowToken} class */
     private class TestAppWindowToken extends AppWindowToken {
 
         TestAppWindowToken() {
-            super(sWm, null, false);
+            super(sWm, null, false, sWm.getDefaultDisplayContentLocked());
         }
 
         int getWindowsCount() {
diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
index 1259e0f..3df1df9 100644
--- a/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
+++ b/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
@@ -58,7 +58,8 @@
     public void setUp() throws Exception {
         final Context context = InstrumentationRegistry.getTargetContext();
         sWm = TestWindowManagerPolicy.getWindowManagerService(context);
-        mWindowToken = new WindowToken(sWm, new Binder(), 0, false);
+        mWindowToken = new WindowToken(sWm, new Binder(), 0, false,
+                sWm.getDefaultDisplayContentLocked());
     }
 
     @Test
@@ -162,7 +163,6 @@
     private WindowState createWindow(WindowState parent, int type) {
         final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
 
-        return new WindowState(sWm, null, mIWindow, mWindowToken, parent, 0, 0, attrs, 0,
-                sWm.getDefaultDisplayContentLocked(), 0);
+        return new WindowState(sWm, null, mIWindow, mWindowToken, parent, 0, 0, attrs, 0, 0);
     }
 }
diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowTokenTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowTokenTests.java
index 3279886..1a4dff9 100644
--- a/services/tests/servicestests/src/com/android/server/wm/WindowTokenTests.java
+++ b/services/tests/servicestests/src/com/android/server/wm/WindowTokenTests.java
@@ -157,15 +157,14 @@
     private WindowState createWindow(WindowState parent, int type, WindowToken token) {
         final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(type);
 
-        return new WindowState(mWm, null, mIWindow, token, parent, 0, 0, attrs, 0,
-                mWm.getDefaultDisplayContentLocked(), 0);
+        return new WindowState(mWm, null, mIWindow, token, parent, 0, 0, attrs, 0, 0);
     }
 
     /* Used so we can gain access to some protected members of the {@link WindowToken} class */
     private class TestWindowToken extends WindowToken {
 
         TestWindowToken() {
-            super(mWm, null, 0, false);
+            super(mWm, null, 0, false, mWm.getDefaultDisplayContentLocked());
         }
 
         int getWindowsCount() {
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index 220626a..a0c6e0e 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -84,6 +84,14 @@
     private static final String USB_CONFIG_PROPERTY = "sys.usb.config";
 
     /**
+     * The property which stores the current build type (user/userdebug/eng).
+     */
+    private static final String BUILD_TYPE_PROPERTY = "ro.build.type";
+
+    private static final String BUILD_TYPE_USERDEBUG = "userdebug";
+    private static final String BUILD_TYPE_ENG = "eng";
+
+    /**
      * The non-persistent property which stores the current USB actual state.
      */
     private static final String USB_STATE_PROPERTY = "sys.usb.state";
@@ -109,9 +117,8 @@
     private static final int MSG_SYSTEM_READY = 3;
     private static final int MSG_BOOT_COMPLETED = 4;
     private static final int MSG_USER_SWITCHED = 5;
-    private static final int MSG_SET_USB_DATA_UNLOCKED = 6;
-    private static final int MSG_UPDATE_USER_RESTRICTIONS = 7;
-    private static final int MSG_UPDATE_HOST_STATE = 8;
+    private static final int MSG_UPDATE_USER_RESTRICTIONS = 6;
+    private static final int MSG_UPDATE_HOST_STATE = 7;
 
     private static final int AUDIO_MODE_SOURCE = 1;
 
@@ -291,7 +298,7 @@
 
         if (functions != null) {
             mAccessoryModeRequestTime = SystemClock.elapsedRealtime();
-            setCurrentFunctions(functions);
+            setCurrentFunctions(functions, false);
         }
     }
 
@@ -340,14 +347,17 @@
                 // Restore default functions.
                 mCurrentFunctions = SystemProperties.get(USB_CONFIG_PROPERTY,
                         UsbManager.USB_FUNCTION_NONE);
-                if (UsbManager.USB_FUNCTION_NONE.equals(mCurrentFunctions)) {
-                    mCurrentFunctions = UsbManager.USB_FUNCTION_MTP;
-                }
                 mCurrentFunctionsApplied = mCurrentFunctions.equals(
                         SystemProperties.get(USB_STATE_PROPERTY));
                 mAdbEnabled = UsbManager.containsFunction(getDefaultFunctions(),
                         UsbManager.USB_FUNCTION_ADB);
-                setEnabledFunctions(null, false);
+
+                String buildType = SystemProperties.get(BUILD_TYPE_PROPERTY);
+                if (buildType.equals(BUILD_TYPE_USERDEBUG) || buildType.equals(BUILD_TYPE_ENG)) {
+                    setAdbEnabled(true);
+                }
+
+                setEnabledFunctions(null, false, false);
 
                 String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
                 updateState(state);
@@ -379,6 +389,14 @@
             sendMessage(m);
         }
 
+        public void sendMessage(int what, Object arg, boolean arg1) {
+            removeMessages(what);
+            Message m = Message.obtain(this, what);
+            m.obj = arg;
+            m.arg1 = (arg1 ? 1 : 0);
+            sendMessage(m);
+        }
+
         public void updateState(String state) {
             int connected, configured;
 
@@ -443,29 +461,28 @@
             return waitForState(config);
         }
 
-        private void setUsbDataUnlocked(boolean enable) {
-            if (DEBUG) Slog.d(TAG, "setUsbDataUnlocked: " + enable);
-            mUsbDataUnlocked = enable;
-            updateUsbNotification();
-            updateUsbStateBroadcastIfNeeded();
-            setEnabledFunctions(mCurrentFunctions, true);
-        }
-
         private void setAdbEnabled(boolean enable) {
             if (DEBUG) Slog.d(TAG, "setAdbEnabled: " + enable);
             if (enable != mAdbEnabled) {
                 mAdbEnabled = enable;
+                String oldFunctions = mCurrentFunctions;
 
-                // Due to the persist.sys.usb.config property trigger, changing adb state requires
-                // persisting default function
-                String oldFunctions = getDefaultFunctions();
-                String newFunctions = applyAdbFunction(oldFunctions);
-                if (!oldFunctions.equals(newFunctions)) {
-                    SystemProperties.set(USB_PERSISTENT_CONFIG_PROPERTY, newFunctions);
+                // Persist the adb setting
+                String newFunction = applyAdbFunction(SystemProperties.get(
+                            USB_PERSISTENT_CONFIG_PROPERTY, UsbManager.USB_FUNCTION_NONE));
+                SystemProperties.set(USB_PERSISTENT_CONFIG_PROPERTY, newFunction);
+
+                // Changing the persistent config also changes the normal
+                // config. Wait for this to happen before changing again.
+                waitForState(newFunction);
+
+                // Remove mtp from the config if file transfer is not enabled
+                if (oldFunctions.equals(UsbManager.USB_FUNCTION_MTP) && 
+                        !mUsbDataUnlocked && enable) {
+                    oldFunctions = UsbManager.USB_FUNCTION_NONE;
                 }
 
-                // After persisting them use the lock-down aware function set
-                setEnabledFunctions(mCurrentFunctions, false);
+                setEnabledFunctions(oldFunctions, false, mUsbDataUnlocked);
                 updateAdbNotification();
             }
 
@@ -477,10 +494,17 @@
         /**
          * Evaluates USB function policies and applies the change accordingly.
          */
-        private void setEnabledFunctions(String functions, boolean forceRestart) {
+        private void setEnabledFunctions(String functions, boolean forceRestart,
+                boolean usbDataUnlocked) {
             if (DEBUG) Slog.d(TAG, "setEnabledFunctions functions=" + functions + ", "
                     + "forceRestart=" + forceRestart);
 
+            if (usbDataUnlocked != mUsbDataUnlocked) {
+                mUsbDataUnlocked = usbDataUnlocked;
+                updateUsbNotification();
+                forceRestart = true;
+            }
+
             // Try to set the enabled functions.
             final String oldFunctions = mCurrentFunctions;
             final boolean oldFunctionsApplied = mCurrentFunctionsApplied;
@@ -517,7 +541,8 @@
         }
 
         private boolean trySetEnabledFunctions(String functions, boolean forceRestart) {
-            if (functions == null) {
+            if (functions == null || applyAdbFunction(functions)
+                    .equals(UsbManager.USB_FUNCTION_NONE)) {
                 functions = getDefaultFunctions();
             }
             functions = applyAdbFunction(functions);
@@ -529,9 +554,6 @@
                 mCurrentFunctions = functions;
                 mCurrentFunctionsApplied = false;
 
-                // Kick the USB stack to close existing connections.
-                setUsbConfig(UsbManager.USB_FUNCTION_NONE);
-
                 // Set the new USB configuration.
                 if (!setUsbConfig(functions)) {
                     Slog.e(TAG, "Failed to switch USB config to " + functions);
@@ -583,7 +605,7 @@
                 // make sure accessory mode is off
                 // and restore default functions
                 Slog.d(TAG, "exited USB accessory mode");
-                setEnabledFunctions(null, false);
+                setEnabledFunctions(null, false, false);
 
                 if (mCurrentAccessory != null) {
                     if (mBootCompleted) {
@@ -600,10 +622,6 @@
             if (mBroadcastedIntent == null) {
                 for (String key : keySet) {
                     if (intent.getBooleanExtra(key, false)) {
-                        // MTP function is enabled by default.
-                        if (UsbManager.USB_FUNCTION_MTP.equals(key)) {
-                            continue;
-                        }
                         return true;
                     }
                 }
@@ -716,10 +734,7 @@
                 case MSG_UPDATE_STATE:
                     mConnected = (msg.arg1 == 1);
                     mConfigured = (msg.arg2 == 1);
-                    if (!mConnected) {
-                        // When a disconnect occurs, relock access to sensitive user data
-                        mUsbDataUnlocked = false;
-                    }
+
                     updateUsbNotification();
                     updateAdbNotification();
                     if (UsbManager.containsFunction(mCurrentFunctions,
@@ -727,7 +742,7 @@
                         updateCurrentAccessory();
                     } else if (!mConnected) {
                         // restore defaults when USB is disconnected
-                        setEnabledFunctions(null, false);
+                        setEnabledFunctions(null, false, false);
                     }
                     if (mBootCompleted) {
                         updateUsbStateBroadcastIfNeeded();
@@ -750,13 +765,10 @@
                     break;
                 case MSG_SET_CURRENT_FUNCTIONS:
                     String functions = (String)msg.obj;
-                    setEnabledFunctions(functions, false);
+                    setEnabledFunctions(functions, false, msg.arg1 == 1);
                     break;
                 case MSG_UPDATE_USER_RESTRICTIONS:
-                    setEnabledFunctions(mCurrentFunctions, false);
-                    break;
-                case MSG_SET_USB_DATA_UNLOCKED:
-                    setUsbDataUnlocked(msg.arg1 == 1);
+                    setEnabledFunctions(mCurrentFunctions, false, mUsbDataUnlocked);
                     break;
                 case MSG_SYSTEM_READY:
                     updateUsbNotification();
@@ -784,8 +796,7 @@
                             Slog.v(TAG, "Current user switched to " + mCurrentUser
                                     + "; resetting USB host stack for MTP or PTP");
                             // avoid leaking sensitive data from previous user
-                            mUsbDataUnlocked = false;
-                            setEnabledFunctions(mCurrentFunctions, true);
+                            setEnabledFunctions(mCurrentFunctions, true, false);
                         }
                         mCurrentUser = msg.arg1;
                     }
@@ -969,14 +980,10 @@
         return UsbManager.containsFunction(SystemProperties.get(USB_CONFIG_PROPERTY), function);
     }
 
-    public void setCurrentFunctions(String functions) {
-        if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ")");
-        mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions);
-    }
-
-    public void setUsbDataUnlocked(boolean unlocked) {
-        if (DEBUG) Slog.d(TAG, "setUsbDataUnlocked(" + unlocked + ")");
-        mHandler.sendMessage(MSG_SET_USB_DATA_UNLOCKED, unlocked);
+    public void setCurrentFunctions(String functions, boolean usbDataUnlocked) {
+        if (DEBUG) Slog.d(TAG, "setCurrentFunctions(" + functions + ", " +
+				usbDataUnlocked + ")");
+        mHandler.sendMessage(MSG_SET_CURRENT_FUNCTIONS, functions, usbDataUnlocked);
     }
 
     private void readOemUsbOverrideConfig() {
diff --git a/services/usb/java/com/android/server/usb/UsbProfileGroupSettingsManager.java b/services/usb/java/com/android/server/usb/UsbProfileGroupSettingsManager.java
index cc0fb8d..e03a14f 100644
--- a/services/usb/java/com/android/server/usb/UsbProfileGroupSettingsManager.java
+++ b/services/usb/java/com/android/server/usb/UsbProfileGroupSettingsManager.java
@@ -34,6 +34,7 @@
 import android.hardware.usb.UsbDevice;
 import android.hardware.usb.UsbInterface;
 import android.hardware.usb.UsbManager;
+import android.os.AsyncTask;
 import android.os.Environment;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -42,6 +43,7 @@
 import android.util.Slog;
 import android.util.Xml;
 
+import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.Immutable;
 import com.android.internal.content.PackageMonitor;
 import com.android.internal.util.FastXmlSerializer;
@@ -60,7 +62,9 @@
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import libcore.io.IoUtils;
 
@@ -87,14 +91,24 @@
     private final UserManager mUserManager;
     private final @NonNull UsbSettingsManager mSettingsManager;
 
-    // Maps DeviceFilter to user preferred application package
+    /** Maps DeviceFilter to user preferred application package */
+    @GuardedBy("mLock")
     private final HashMap<DeviceFilter, UserPackage> mDevicePreferenceMap = new HashMap<>();
-    // Maps AccessoryFilter to user preferred application package
+
+    /** Maps AccessoryFilter to user preferred application package */
+    @GuardedBy("mLock")
     private final HashMap<AccessoryFilter, UserPackage> mAccessoryPreferenceMap = new HashMap<>();
 
     private final Object mLock = new Object();
 
     /**
+     * If a async task to persist the mDevicePreferenceMap and mAccessoryPreferenceMap is currently
+     * scheduled.
+     */
+    @GuardedBy("mLock")
+    private boolean mIsWriteSettingsScheduled;
+
+    /**
      * A package of a user.
      */
     @Immutable
@@ -591,6 +605,42 @@
                 });
     }
 
+    /**
+     * Remove all defaults for a user.
+     *
+     * @param userToRemove The user the defaults belong to.
+     */
+    void removeAllDefaultsForUser(@NonNull UserHandle userToRemove) {
+        synchronized (mLock) {
+            boolean needToPersist = false;
+            Iterator<Map.Entry<DeviceFilter, UserPackage>> devicePreferenceIt = mDevicePreferenceMap
+                    .entrySet().iterator();
+            while (devicePreferenceIt.hasNext()) {
+                Map.Entry<DeviceFilter, UserPackage> entry = devicePreferenceIt.next();
+
+                if (entry.getValue().user.equals(userToRemove)) {
+                    devicePreferenceIt.remove();
+                    needToPersist = true;
+                }
+            }
+
+            Iterator<Map.Entry<AccessoryFilter, UserPackage>> accessoryPreferenceIt =
+                    mAccessoryPreferenceMap.entrySet().iterator();
+            while (accessoryPreferenceIt.hasNext()) {
+                Map.Entry<AccessoryFilter, UserPackage> entry = accessoryPreferenceIt.next();
+
+                if (entry.getValue().user.equals(userToRemove)) {
+                    accessoryPreferenceIt.remove();
+                    needToPersist = true;
+                }
+            }
+
+            if (needToPersist) {
+                scheduleWriteSettingsLocked();
+            }
+        }
+    }
+
     private void readPreference(XmlPullParser parser)
             throws XmlPullParserException, IOException {
         String packageName = null;
@@ -657,7 +707,7 @@
                 IoUtils.closeQuietly(fis);
             }
 
-            writeSettingsLocked();
+            scheduleWriteSettingsLocked();
 
             // Success or failure, we delete single-user file
             sSingleUserSettingsFile.delete();
@@ -695,48 +745,68 @@
         }
     }
 
-    private void writeSettingsLocked() {
-        if (DEBUG) Slog.v(TAG, "writeSettingsLocked()");
-
-        FileOutputStream fos = null;
-        try {
-            fos = mSettingsFile.startWrite();
-
-            FastXmlSerializer serializer = new FastXmlSerializer();
-            serializer.setOutput(fos, StandardCharsets.UTF_8.name());
-            serializer.startDocument(null, true);
-            serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output", true);
-            serializer.startTag(null, "settings");
-
-            for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
-                serializer.startTag(null, "preference");
-                serializer.attribute(null, "package", mDevicePreferenceMap.get(filter).packageName);
-                serializer.attribute(null, "user",
-                        String.valueOf(getSerial(mDevicePreferenceMap.get(filter).user)));
-                filter.write(serializer);
-                serializer.endTag(null, "preference");
-            }
-
-            for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
-                serializer.startTag(null, "preference");
-                serializer.attribute(null, "package",
-                        mAccessoryPreferenceMap.get(filter).packageName);
-                serializer.attribute(null, "user",
-                        String.valueOf(getSerial(mAccessoryPreferenceMap.get(filter).user)));
-                filter.write(serializer);
-                serializer.endTag(null, "preference");
-            }
-
-            serializer.endTag(null, "settings");
-            serializer.endDocument();
-
-            mSettingsFile.finishWrite(fos);
-        } catch (IOException e) {
-            Slog.e(TAG, "Failed to write settings", e);
-            if (fos != null) {
-                mSettingsFile.failWrite(fos);
-            }
+    /**
+     * Schedule a async task to persist {@link #mDevicePreferenceMap} and
+     * {@link #mAccessoryPreferenceMap}. If a task is already scheduled but not completed, do
+     * nothing as the currently scheduled one will do the work.
+     * <p>Called with {@link #mLock} held.</p>
+     * <p>In the uncommon case that the system crashes in between the scheduling and the write the
+     * update is lost.</p>
+     */
+    private void scheduleWriteSettingsLocked() {
+        if (mIsWriteSettingsScheduled) {
+            return;
+        } else {
+            mIsWriteSettingsScheduled = true;
         }
+
+        AsyncTask.execute(() -> {
+            synchronized (mLock) {
+                FileOutputStream fos = null;
+                try {
+                    fos = mSettingsFile.startWrite();
+
+                    FastXmlSerializer serializer = new FastXmlSerializer();
+                    serializer.setOutput(fos, StandardCharsets.UTF_8.name());
+                    serializer.startDocument(null, true);
+                    serializer.setFeature("http://xmlpull.org/v1/doc/features.html#indent-output",
+                                    true);
+                    serializer.startTag(null, "settings");
+
+                    for (DeviceFilter filter : mDevicePreferenceMap.keySet()) {
+                        serializer.startTag(null, "preference");
+                        serializer.attribute(null, "package",
+                                mDevicePreferenceMap.get(filter).packageName);
+                        serializer.attribute(null, "user",
+                                String.valueOf(getSerial(mDevicePreferenceMap.get(filter).user)));
+                        filter.write(serializer);
+                        serializer.endTag(null, "preference");
+                    }
+
+                    for (AccessoryFilter filter : mAccessoryPreferenceMap.keySet()) {
+                        serializer.startTag(null, "preference");
+                        serializer.attribute(null, "package",
+                                mAccessoryPreferenceMap.get(filter).packageName);
+                        serializer.attribute(null, "user", String.valueOf(
+                                        getSerial(mAccessoryPreferenceMap.get(filter).user)));
+                        filter.write(serializer);
+                        serializer.endTag(null, "preference");
+                    }
+
+                    serializer.endTag(null, "settings");
+                    serializer.endDocument();
+
+                    mSettingsFile.finishWrite(fos);
+                } catch (IOException e) {
+                    Slog.e(TAG, "Failed to write settings", e);
+                    if (fos != null) {
+                        mSettingsFile.failWrite(fos);
+                    }
+                }
+
+                mIsWriteSettingsScheduled = false;
+            }
+        });
     }
 
     // Checks to see if a package matches a device or accessory.
@@ -1141,7 +1211,7 @@
             }
 
             if (changed) {
-                writeSettingsLocked();
+                scheduleWriteSettingsLocked();
             }
         }
     }
@@ -1178,7 +1248,7 @@
                 }
             }
             if (changed) {
-                writeSettingsLocked();
+                scheduleWriteSettingsLocked();
             }
         }
     }
@@ -1204,7 +1274,7 @@
                 }
             }
             if (changed) {
-                writeSettingsLocked();
+                scheduleWriteSettingsLocked();
             }
         }
     }
@@ -1237,7 +1307,7 @@
 
         synchronized (mLock) {
             if (clearPackageDefaultsLocked(userPackage)) {
-                writeSettingsLocked();
+                scheduleWriteSettingsLocked();
             }
         }
     }
diff --git a/services/usb/java/com/android/server/usb/UsbService.java b/services/usb/java/com/android/server/usb/UsbService.java
index 02c7214..a87ac9e 100644
--- a/services/usb/java/com/android/server/usb/UsbService.java
+++ b/services/usb/java/com/android/server/usb/UsbService.java
@@ -16,6 +16,7 @@
 
 package com.android.server.usb;
 
+import android.annotation.NonNull;
 import android.annotation.UserIdInt;
 import android.app.PendingIntent;
 import android.app.admin.DevicePolicyManager;
@@ -83,7 +84,7 @@
 
         @Override
         public void onStopUser(int userHandle) {
-            mUsbService.onStopUser(userHandle);
+            mUsbService.onStopUser(UserHandle.of(userHandle));
         }
     }
 
@@ -177,10 +178,10 @@
     /**
      * Execute operations when a user is stopped.
      *
-     * @param stoppedUserId The id of the used that is stopped
+     * @param stoppedUser The user that is stopped
      */
-    private void onStopUser(@UserIdInt int stoppedUserId) {
-        mSettingsManager.remove(stoppedUserId);
+    private void onStopUser(@NonNull UserHandle stoppedUser) {
+        mSettingsManager.remove(stoppedUser);
     }
 
     public void systemReady() {
@@ -371,7 +372,7 @@
     }
 
     @Override
-    public void setCurrentFunction(String function) {
+    public void setCurrentFunction(String function, boolean usbDataUnlocked) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
 
         if (!isSupportedCurrentFunction(function)) {
@@ -381,7 +382,7 @@
         }
 
         if (mDeviceManager != null) {
-            mDeviceManager.setCurrentFunctions(function);
+            mDeviceManager.setCurrentFunctions(function, usbDataUnlocked);
         } else {
             throw new IllegalStateException("USB device mode not supported");
         }
@@ -404,12 +405,6 @@
     }
 
     @Override
-    public void setUsbDataUnlocked(boolean unlocked) {
-        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
-        mDeviceManager.setUsbDataUnlocked(unlocked);
-    }
-
-    @Override
     public void allowUsbDebugging(boolean alwaysAllow, String publicKey) {
         mContext.enforceCallingOrSelfPermission(android.Manifest.permission.MANAGE_USB, null);
         mDeviceManager.allowUsbDebugging(alwaysAllow, publicKey);
diff --git a/services/usb/java/com/android/server/usb/UsbSettingsManager.java b/services/usb/java/com/android/server/usb/UsbSettingsManager.java
index b251d26..24d5f09 100644
--- a/services/usb/java/com/android/server/usb/UsbSettingsManager.java
+++ b/services/usb/java/com/android/server/usb/UsbSettingsManager.java
@@ -108,11 +108,26 @@
     /**
      * Remove the settings for a user.
      *
-     * @param userIdToRemove The user o remove
+     * @param userToRemove The user to remove
      */
-    void remove(@UserIdInt int userIdToRemove) {
+    void remove(@NonNull UserHandle userToRemove) {
         synchronized (mSettingsByUser) {
-            mSettingsByUser.remove(userIdToRemove);
+            mSettingsByUser.remove(userToRemove.getIdentifier());
+        }
+
+        synchronized (mSettingsByProfileGroup) {
+            if (mSettingsByProfileGroup.indexOfKey(userToRemove.getIdentifier()) >= 0) {
+                // The user to remove is the parent user of the group. The parent is the last user
+                // that gets removed. All state will be removed with the user
+                mSettingsByProfileGroup.remove(userToRemove.getIdentifier());
+            } else {
+                // We cannot find the parent user of the user that is removed, hence try to remove
+                // it from all profile groups.
+                int numProfileGroups = mSettingsByProfileGroup.size();
+                for (int i = 0; i < numProfileGroups; i++) {
+                    mSettingsByProfileGroup.valueAt(i).removeAllDefaultsForUser(userToRemove);
+                }
+            }
         }
     }
 
diff --git a/telecomm/java/android/telecom/Log.java b/telecomm/java/android/telecom/Log.java
index a965342..ecda3cd 100644
--- a/telecomm/java/android/telecom/Log.java
+++ b/telecomm/java/android/telecom/Log.java
@@ -18,9 +18,15 @@
 
 import android.net.Uri;
 import android.os.AsyncTask;
+import android.telecom.Logging.EventManager;
+import android.telecom.Logging.Session;
+import android.telecom.Logging.SessionManager;
 import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
 
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.IndentingPrintWriter;
+
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.IllegalFormatException;
@@ -31,24 +37,270 @@
  *
  * @hide
  */
-final public class Log {
+public class Log {
 
-    // Generic tag for all Telecom Framework logging
-    private static final String TAG = "TelecomFramework";
+    private static final long EXTENDED_LOGGING_DURATION_MILLIS = 60000 * 30; // 30 minutes
 
-    public static final boolean FORCE_LOGGING = false; /* STOP SHIP if true */
+    private static final int EVENTS_TO_CACHE = 10;
+    private static final int EVENTS_TO_CACHE_DEBUG = 20;
+
+    // Generic tag for all Telecom logging
+    @VisibleForTesting
+    public static String TAG = "TelecomFramework";
+
+    private static final boolean FORCE_LOGGING = false; /* STOP SHIP if true */
     public static final boolean DEBUG = isLoggable(android.util.Log.DEBUG);
     public static final boolean INFO = isLoggable(android.util.Log.INFO);
     public static final boolean VERBOSE = isLoggable(android.util.Log.VERBOSE);
     public static final boolean WARN = isLoggable(android.util.Log.WARN);
     public static final boolean ERROR = isLoggable(android.util.Log.ERROR);
 
+    // Used to synchronize singleton logging lazy initialization
+    private static final Object sSingletonSync = new Object();
+    private static EventManager sEventManager;
+    private static SessionManager sSessionManager;
+
+    /**
+     * Tracks whether user-activated extended logging is enabled.
+     */
+    private static boolean sIsUserExtendedLoggingEnabled = false;
+
+    /**
+     * The time when user-activated extended logging should be ended.  Used to determine when
+     * extended logging should automatically be disabled.
+     */
+    private static long sUserExtendedLoggingStopTime = 0;
+
+    private Log() {
+    }
+
+    public static void d(String prefix, String format, Object... args) {
+        if (sIsUserExtendedLoggingEnabled) {
+            maybeDisableLogging();
+            android.util.Slog.i(TAG, buildMessage(prefix, format, args));
+        } else if (DEBUG) {
+            android.util.Slog.d(TAG, buildMessage(prefix, format, args));
+        }
+    }
+
+    public static void d(Object objectPrefix, String format, Object... args) {
+        if (sIsUserExtendedLoggingEnabled) {
+            maybeDisableLogging();
+            android.util.Slog.i(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
+        } else if (DEBUG) {
+            android.util.Slog.d(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
+        }
+    }
+
+    public static void i(String prefix, String format, Object... args) {
+        if (INFO) {
+            android.util.Slog.i(TAG, buildMessage(prefix, format, args));
+        }
+    }
+
+    public static void i(Object objectPrefix, String format, Object... args) {
+        if (INFO) {
+            android.util.Slog.i(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
+        }
+    }
+
+    public static void v(String prefix, String format, Object... args) {
+        if (sIsUserExtendedLoggingEnabled) {
+            maybeDisableLogging();
+            android.util.Slog.i(TAG, buildMessage(prefix, format, args));
+        } else if (VERBOSE) {
+            android.util.Slog.v(TAG, buildMessage(prefix, format, args));
+        }
+    }
+
+    public static void v(Object objectPrefix, String format, Object... args) {
+        if (sIsUserExtendedLoggingEnabled) {
+            maybeDisableLogging();
+            android.util.Slog.i(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
+        } else if (VERBOSE) {
+            android.util.Slog.v(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
+        }
+    }
+
+    public static void w(String prefix, String format, Object... args) {
+        if (WARN) {
+            android.util.Slog.w(TAG, buildMessage(prefix, format, args));
+        }
+    }
+
+    public static void w(Object objectPrefix, String format, Object... args) {
+        if (WARN) {
+            android.util.Slog.w(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
+        }
+    }
+
+    public static void e(String prefix, Throwable tr, String format, Object... args) {
+        if (ERROR) {
+            android.util.Slog.e(TAG, buildMessage(prefix, format, args), tr);
+        }
+    }
+
+    public static void e(Object objectPrefix, Throwable tr, String format, Object... args) {
+        if (ERROR) {
+            android.util.Slog.e(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args),
+                    tr);
+        }
+    }
+
+    public static void wtf(String prefix, Throwable tr, String format, Object... args) {
+        android.util.Slog.wtf(TAG, buildMessage(prefix, format, args), tr);
+    }
+
+    public static void wtf(Object objectPrefix, Throwable tr, String format, Object... args) {
+        android.util.Slog.wtf(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args),
+                tr);
+    }
+
+    public static void wtf(String prefix, String format, Object... args) {
+        String msg = buildMessage(prefix, format, args);
+        android.util.Slog.wtf(TAG, msg, new IllegalStateException(msg));
+    }
+
+    public static void wtf(Object objectPrefix, String format, Object... args) {
+        String msg = buildMessage(getPrefixFromObject(objectPrefix), format, args);
+        android.util.Slog.wtf(TAG, msg, new IllegalStateException(msg));
+    }
+
+    /**
+     * The ease of use methods below only act mostly as proxies to the Session and Event Loggers.
+     * They also control the lazy loaders of the singleton instances, which will never be loaded if
+     * the proxy methods aren't used.
+     *
+     * Please see each method's documentation inside of their respective implementations in the
+     * loggers.
+     */
+
+    public static void startSession(String shortMethodName) {
+        getSessionManager().startSession(shortMethodName, null);
+    }
+
+    public static void startSession(String shortMethodName, String callerIdentification) {
+        getSessionManager().startSession(shortMethodName, callerIdentification);
+    }
+
+    public static Session createSubsession() {
+        return getSessionManager().createSubsession();
+    }
+
+    public static void cancelSubsession(Session subsession) {
+        getSessionManager().cancelSubsession(subsession);
+    }
+
+    public static void continueSession(Session subsession, String shortMethodName) {
+        getSessionManager().continueSession(subsession, shortMethodName);
+    }
+
+    public static void endSession() {
+        getSessionManager().endSession();
+    }
+
+    public static String getSessionId() {
+        // If the Session logger has not been initialized, then there have been no sessions logged.
+        // Don't load it now!
+        synchronized (sSingletonSync) {
+            if (sSessionManager != null) {
+                return getSessionManager().getSessionId();
+            } else {
+                return "";
+            }
+        }
+    }
+
+    public static void addEvent(EventManager.Loggable recordEntry, String event) {
+        getEventManager().event(recordEntry, event, null);
+    }
+
+    public static void addEvent(EventManager.Loggable recordEntry, String event, Object data) {
+        getEventManager().event(recordEntry, event, data);
+    }
+
+    public static void addEvent(EventManager.Loggable recordEntry, String event, String format,
+            Object... args) {
+        getEventManager().event(recordEntry, event, format, args);
+    }
+
+    public static void registerEventListener(EventManager.EventListener e) {
+        getEventManager().registerEventListener(e);
+    }
+
+    public static void addRequestResponsePair(EventManager.TimedEventPair p) {
+        getEventManager().addRequestResponsePair(p);
+    }
+
+    public static void dumpEvents(IndentingPrintWriter pw) {
+        // If the Events logger has not been initialized, then there have been no events logged.
+        // Don't load it now!
+        synchronized (sSingletonSync) {
+            if (sEventManager != null) {
+                getEventManager().dumpEvents(pw);
+            } else {
+                pw.println("No Historical Events Logged.");
+            }
+        }
+    }
+
+    /**
+     * Enable or disable extended telecom logging.
+     *
+     * @param isExtendedLoggingEnabled {@code true} if extended logging should be enabled,
+     *          {@code false} if it should be disabled.
+     */
+    public static void setIsExtendedLoggingEnabled(boolean isExtendedLoggingEnabled) {
+        // If the state hasn't changed, bail early.
+        if (sIsUserExtendedLoggingEnabled == isExtendedLoggingEnabled) {
+            return;
+        }
+
+        if (sEventManager != null) {
+            sEventManager.changeEventCacheSize(isExtendedLoggingEnabled ?
+                    EVENTS_TO_CACHE_DEBUG : EVENTS_TO_CACHE);
+        }
+
+        sIsUserExtendedLoggingEnabled = isExtendedLoggingEnabled;
+        if (sIsUserExtendedLoggingEnabled) {
+            sUserExtendedLoggingStopTime = System.currentTimeMillis()
+                    + EXTENDED_LOGGING_DURATION_MILLIS;
+        } else {
+            sUserExtendedLoggingStopTime = 0;
+        }
+    }
+
+    private static EventManager getEventManager() {
+        // Checking for null again outside of synchronization because we only need to synchronize
+        // during the lazy loading of the events logger. We don't need to synchronize elsewhere.
+        if (sEventManager == null) {
+            synchronized (sSingletonSync) {
+                if (sEventManager == null) {
+                    sEventManager = new EventManager(Log::getSessionId);
+                    return sEventManager;
+                }
+            }
+        }
+        return sEventManager;
+    }
+
+    private static SessionManager getSessionManager() {
+        // Checking for null again outside of synchronization because we only need to synchronize
+        // during the lazy loading of the session logger. We don't need to synchronize elsewhere.
+        if (sSessionManager == null) {
+            synchronized (sSingletonSync) {
+                if (sSessionManager == null) {
+                    sSessionManager = new SessionManager();
+                    return sSessionManager;
+                }
+            }
+        }
+        return sSessionManager;
+    }
+
     private static MessageDigest sMessageDigest;
-    private static final Object sMessageDigestLock = new Object();
 
-    private Log() {}
-
-    public static void initMd5Sum() {
+    static void initMd5Sum() {
         new AsyncTask<Void, Void, Void>() {
             @Override
             public Void doInBackground(Void... args) {
@@ -58,96 +310,69 @@
                 } catch (NoSuchAlgorithmException e) {
                     md = null;
                 }
-                synchronized (sMessageDigestLock) {
-                    sMessageDigest = md;
-                }
+                sMessageDigest = md;
                 return null;
             }
         }.execute();
     }
 
+    public static void setTag(String tag) {
+        TAG = tag;
+    }
+
+    /**
+     * If user enabled extended logging is enabled and the time limit has passed, disables the
+     * extended logging.
+     */
+    private static void maybeDisableLogging() {
+        if (!sIsUserExtendedLoggingEnabled) {
+            return;
+        }
+
+        if (sUserExtendedLoggingStopTime < System.currentTimeMillis()) {
+            sUserExtendedLoggingStopTime = 0;
+            sIsUserExtendedLoggingEnabled = false;
+        }
+    }
+
     public static boolean isLoggable(int level) {
         return FORCE_LOGGING || android.util.Log.isLoggable(TAG, level);
     }
 
-    public static void d(String prefix, String format, Object... args) {
-        if (DEBUG) {
-            android.util.Log.d(TAG, buildMessage(prefix, format, args));
+    public static String piiHandle(Object pii) {
+        if (pii == null || VERBOSE) {
+            return String.valueOf(pii);
         }
-    }
 
-    public static void d(Object objectPrefix, String format, Object... args) {
-        if (DEBUG) {
-            android.util.Log.d(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
+        StringBuilder sb = new StringBuilder();
+        if (pii instanceof Uri) {
+            Uri uri = (Uri) pii;
+            String scheme = uri.getScheme();
+
+            if (!TextUtils.isEmpty(scheme)) {
+                sb.append(scheme).append(":");
+            }
+
+            String textToObfuscate = uri.getSchemeSpecificPart();
+            if (PhoneAccount.SCHEME_TEL.equals(scheme)) {
+                for (int i = 0; i < textToObfuscate.length(); i++) {
+                    char c = textToObfuscate.charAt(i);
+                    sb.append(PhoneNumberUtils.isDialable(c) ? "*" : c);
+                }
+            } else if (PhoneAccount.SCHEME_SIP.equals(scheme)) {
+                for (int i = 0; i < textToObfuscate.length(); i++) {
+                    char c = textToObfuscate.charAt(i);
+                    if (c != '@' && c != '.') {
+                        c = '*';
+                    }
+                    sb.append(c);
+                }
+            } else {
+                sb.append(pii(pii));
+            }
         }
-    }
 
-    public static void i(String prefix, String format, Object... args) {
-        if (INFO) {
-            android.util.Log.i(TAG, buildMessage(prefix, format, args));
-        }
-    }
-
-    public static void i(Object objectPrefix, String format, Object... args) {
-        if (INFO) {
-            android.util.Log.i(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
-        }
-    }
-
-    public static void v(String prefix, String format, Object... args) {
-        if (VERBOSE) {
-            android.util.Log.v(TAG, buildMessage(prefix, format, args));
-        }
-    }
-
-    public static void v(Object objectPrefix, String format, Object... args) {
-        if (VERBOSE) {
-            android.util.Log.v(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
-        }
-    }
-
-    public static void w(String prefix, String format, Object... args) {
-        if (WARN) {
-            android.util.Log.w(TAG, buildMessage(prefix, format, args));
-        }
-    }
-
-    public static void w(Object objectPrefix, String format, Object... args) {
-        if (WARN) {
-            android.util.Log.w(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args));
-        }
-    }
-
-    public static void e(String prefix, Throwable tr, String format, Object... args) {
-        if (ERROR) {
-            android.util.Log.e(TAG, buildMessage(prefix, format, args), tr);
-        }
-    }
-
-    public static void e(Object objectPrefix, Throwable tr, String format, Object... args) {
-        if (ERROR) {
-            android.util.Log.e(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args),
-                    tr);
-        }
-    }
-
-    public static void wtf(String prefix, Throwable tr, String format, Object... args) {
-        android.util.Log.wtf(TAG, buildMessage(prefix, format, args), tr);
-    }
-
-    public static void wtf(Object objectPrefix, Throwable tr, String format, Object... args) {
-        android.util.Log.wtf(TAG, buildMessage(getPrefixFromObject(objectPrefix), format, args),
-                tr);
-    }
-
-    public static void wtf(String prefix, String format, Object... args) {
-        String msg = buildMessage(prefix, format, args);
-        android.util.Log.wtf(TAG, msg, new IllegalStateException(msg));
-    }
-
-    public static void wtf(Object objectPrefix, String format, Object... args) {
-        String msg = buildMessage(getPrefixFromObject(objectPrefix), format, args);
-        android.util.Log.wtf(TAG, msg, new IllegalStateException(msg));
+        return sb.toString();
     }
 
     /**
@@ -158,47 +383,18 @@
     public static String pii(Object pii) {
         if (pii == null || VERBOSE) {
             return String.valueOf(pii);
-        } if (pii instanceof Uri) {
-            return piiUri((Uri) pii);
         }
         return "[" + secureHash(String.valueOf(pii).getBytes()) + "]";
     }
 
-    private static String piiUri(Uri handle) {
-        StringBuilder sb = new StringBuilder();
-        String scheme = handle.getScheme();
-        if (!TextUtils.isEmpty(scheme)) {
-            sb.append(scheme).append(":");
-        }
-        String value = handle.getSchemeSpecificPart();
-        if (!TextUtils.isEmpty(value)) {
-            for (int i = 0; i < value.length(); i++) {
-                char c = value.charAt(i);
-                if (PhoneNumberUtils.isStartsPostDial(c)) {
-                    sb.append(c);
-                } else if (PhoneNumberUtils.isDialable(c)) {
-                    sb.append("*");
-                } else if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
-                    sb.append("*");
-                } else {
-                    sb.append(c);
-                }
-            }
-        }
-        return sb.toString();
-
-    }
-
     private static String secureHash(byte[] input) {
-        synchronized (sMessageDigestLock) {
-            if (sMessageDigest != null) {
-                sMessageDigest.reset();
-                sMessageDigest.update(input);
-                byte[] result = sMessageDigest.digest();
-                return encodeHex(result);
-            } else {
-                return "Uninitialized SHA1";
-            }
+        if (sMessageDigest != null) {
+            sMessageDigest.reset();
+            sMessageDigest.update(input);
+            byte[] result = sMessageDigest.digest();
+            return encodeHex(result);
+        } else {
+            return "Uninitialized SHA1";
         }
     }
 
@@ -221,15 +417,19 @@
     }
 
     private static String buildMessage(String prefix, String format, Object... args) {
+        // Incorporate thread ID and calling method into prefix
+        String sessionName = getSessionId();
+        String sessionPostfix = TextUtils.isEmpty(sessionName) ? "" : ": " + sessionName;
+
         String msg;
         try {
             msg = (args == null || args.length == 0) ? format
                     : String.format(Locale.US, format, args);
         } catch (IllegalFormatException ife) {
-            wtf("Log", ife, "IllegalFormatException: formatString='%s' numArgs=%d", format,
+            e("Log", ife, "IllegalFormatException: formatString='%s' numArgs=%d", format,
                     args.length);
             msg = format + " (An error occurred while formatting the message.)";
         }
-        return String.format(Locale.US, "%s: %s", prefix, msg);
+        return String.format(Locale.US, "%s: %s%s", prefix, msg, sessionPostfix);
     }
 }
diff --git a/telecomm/java/android/telecom/Logging/EventManager.java b/telecomm/java/android/telecom/Logging/EventManager.java
new file mode 100644
index 0000000..8e7a393
--- /dev/null
+++ b/telecomm/java/android/telecom/Logging/EventManager.java
@@ -0,0 +1,365 @@
+/*
+ * Copyright (C) 2016 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.telecom.Logging;
+
+import android.annotation.NonNull;
+import android.telecom.Log;
+import android.text.TextUtils;
+
+import com.android.internal.util.IndentingPrintWriter;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.IllegalFormatException;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * A utility class that provides the ability to define Events that a subsystem deems important, and
+ * then relate those events to other events so that information can be extracted. For example, a
+ * START and FINISH event can be defined and when a START and then FINISH occurs in a sequence, the
+ * time it took to complete that sequence can be saved to be retrieved later.
+ * @hide
+ */
+
+public class EventManager {
+
+    public static final String TAG = "Logging.Events";
+    public static final int DEFAULT_EVENTS_TO_CACHE = 10;  // Arbitrarily chosen.
+
+    public interface Loggable {
+        /**
+         * @return a unique String ID that will allow the Event to be recognized later in the logs.
+         */
+        String getId();
+
+        /**
+         * @return Formatted information about the state that will be printed out later in the logs.
+         */
+        String getDescription();
+    }
+
+    private final Map<Loggable, EventRecord> mCallEventRecordMap = new HashMap<>();
+    private LinkedBlockingQueue<EventRecord> mEventRecords =
+            new LinkedBlockingQueue<>(DEFAULT_EVENTS_TO_CACHE);
+
+    private List<EventListener> mEventListeners = new ArrayList<>();
+
+    public interface EventListener {
+        /**
+         * Notifies the implementation of this method that a new event record has been added.
+         * @param eventRecord Reference to the recently added EventRecord
+         */
+        void eventRecordAdded(EventRecord eventRecord);
+    }
+
+    private SessionManager.ISessionIdQueryHandler mSessionIdHandler;
+    /**
+     * Maps from request events to a list of possible response events. Used to track
+     * end-to-end timing for critical user-facing operations in Telecom.
+     */
+    public final Map<String, List<TimedEventPair>> requestResponsePairs = new HashMap<>();
+
+    private static final Object mSync = new Object();
+
+    /**
+     * Stores the various events.
+     * Also stores all request-response pairs amongst the events.
+     */
+    public static class TimedEventPair {
+        private static final long DEFAULT_TIMEOUT = 3000L;
+
+        String mRequest;
+        String mResponse;
+        String mName;
+        long mTimeoutMillis = DEFAULT_TIMEOUT;
+
+        public TimedEventPair(String request, String response, String name) {
+            this.mRequest = request;
+            this.mResponse = response;
+            this.mName = name;
+        }
+
+        public TimedEventPair(String request, String response, String name, long timeoutMillis) {
+            this.mRequest = request;
+            this.mResponse = response;
+            this.mName = name;
+            this.mTimeoutMillis = timeoutMillis;
+        }
+    }
+
+    public void addRequestResponsePair(TimedEventPair p) {
+        if (requestResponsePairs.containsKey(p.mRequest)) {
+            requestResponsePairs.get(p.mRequest).add(p);
+        } else {
+            ArrayList<TimedEventPair> responses = new ArrayList<>();
+            responses.add(p);
+            requestResponsePairs.put(p.mRequest, responses);
+        }
+    }
+
+    public static class Event {
+        public String eventId;
+        public String sessionId;
+        public long time;
+        public Object data;
+
+        public Event(String eventId, String sessionId, long time, Object data) {
+            this.eventId = eventId;
+            this.sessionId = sessionId;
+            this.time = time;
+            this.data = data;
+        }
+    }
+
+    public class EventRecord {
+        public class EventTiming extends TimedEvent<String> {
+            public String name;
+            public long time;
+
+            public EventTiming(String name, long time) {
+                this.name = name;
+                this.time = time;
+            }
+
+            public String getKey() {
+                return name;
+            }
+
+            public long getTime() {
+                return time;
+            }
+        }
+
+        private class PendingResponse {
+            String requestEventId;
+            long requestEventTimeMillis;
+            long timeoutMillis;
+            String name;
+
+            public PendingResponse(String requestEventId, long requestEventTimeMillis,
+                    long timeoutMillis, String name) {
+                this.requestEventId = requestEventId;
+                this.requestEventTimeMillis = requestEventTimeMillis;
+                this.timeoutMillis = timeoutMillis;
+                this.name = name;
+            }
+        }
+
+        private final DateFormat sDateFormat = new SimpleDateFormat("HH:mm:ss.SSS");
+        private final List<Event> mEvents = new LinkedList<>();
+        private final Loggable mRecordEntry;
+
+        public EventRecord(Loggable recordEntry) {
+            mRecordEntry = recordEntry;
+        }
+
+        public Loggable getRecordEntry() {
+            return mRecordEntry;
+        }
+
+        public void addEvent(String event, String sessionId, Object data) {
+            mEvents.add(new Event(event, sessionId, System.currentTimeMillis(), data));
+            Log.i("Event", "RecordEntry %s: %s, %s", mRecordEntry.getId(), event, data);
+        }
+
+        public List<Event> getEvents() {
+            return mEvents;
+        }
+
+        public List<EventTiming> extractEventTimings() {
+            if (mEvents == null) {
+                return Collections.emptyList();
+            }
+
+            LinkedList<EventTiming> result = new LinkedList<>();
+            Map<String, PendingResponse> pendingResponses = new HashMap<>();
+            for (Event event : mEvents) {
+                if (requestResponsePairs.containsKey(event.eventId)) {
+                    // This event expects a response, so add that expected response to the maps
+                    // of pending events.
+                    for (EventManager.TimedEventPair p : requestResponsePairs.get(event.eventId)) {
+                        pendingResponses.put(p.mResponse, new PendingResponse(event.eventId,
+                                event.time, p.mTimeoutMillis, p.mName));
+                    }
+                }
+
+                PendingResponse pendingResponse = pendingResponses.remove(event.eventId);
+                if (pendingResponse != null) {
+                    long elapsedTime = event.time - pendingResponse.requestEventTimeMillis;
+                    if (elapsedTime < pendingResponse.timeoutMillis) {
+                        result.add(new EventTiming(pendingResponse.name, elapsedTime));
+                    }
+                }
+            }
+
+            return result;
+        }
+
+        public void dump(IndentingPrintWriter pw) {
+            pw.print(mRecordEntry.getDescription());
+
+            pw.increaseIndent();
+            for (Event event : mEvents) {
+                pw.print(sDateFormat.format(new Date(event.time)));
+                pw.print(" - ");
+                pw.print(event.eventId);
+                if (event.data != null) {
+                    pw.print(" (");
+                    Object data = event.data;
+
+                    if (data instanceof Loggable) {
+                        // If the data is another Loggable, then change the data to the
+                        // Entry's Event ID instead.
+                        EventRecord record = mCallEventRecordMap.get(data);
+                        if (record != null) {
+                            data = "RecordEntry " + record.mRecordEntry.getId();
+                        }
+                    }
+
+                    pw.print(data);
+                    pw.print(")");
+                }
+                if (!TextUtils.isEmpty(event.sessionId)) {
+                    pw.print(":");
+                    pw.print(event.sessionId);
+                }
+                pw.println();
+            }
+
+            pw.println("Timings (average for this call, milliseconds):");
+            pw.increaseIndent();
+            Map<String, Double> avgEventTimings = EventTiming.averageTimings(extractEventTimings());
+            List<String> eventNames = new ArrayList<>(avgEventTimings.keySet());
+            Collections.sort(eventNames);
+            for (String eventName : eventNames) {
+                pw.printf("%s: %.2f\n", eventName, avgEventTimings.get(eventName));
+            }
+            pw.decreaseIndent();
+            pw.decreaseIndent();
+        }
+    }
+
+    public EventManager(@NonNull SessionManager.ISessionIdQueryHandler l) {
+        mSessionIdHandler = l;
+    }
+
+    public void event(Loggable recordEntry, String event, Object data) {
+        String currentSessionID = mSessionIdHandler.getSessionId();
+
+        if (recordEntry == null) {
+            Log.i(TAG, "Non-call EVENT: %s, %s", event, data);
+            return;
+        }
+        synchronized (mEventRecords) {
+            if (!mCallEventRecordMap.containsKey(recordEntry)) {
+                EventRecord newRecord = new EventRecord(recordEntry);
+                addEventRecord(newRecord);
+            }
+
+            EventRecord record = mCallEventRecordMap.get(recordEntry);
+            record.addEvent(event, currentSessionID, data);
+        }
+    }
+
+    public void event(Loggable recordEntry, String event, String format, Object... args) {
+        String msg;
+        try {
+            msg = (args == null || args.length == 0) ? format
+                    : String.format(Locale.US, format, args);
+        } catch (IllegalFormatException ife) {
+            Log.e("Log", ife, "IllegalFormatException: formatString='%s' numArgs=%d", format,
+                    args.length);
+            msg = format + " (An error occurred while formatting the message.)";
+        }
+
+        event(recordEntry, event, msg);
+    }
+
+    public void dumpEvents(IndentingPrintWriter pw) {
+        pw.println("Historical Events:");
+        pw.increaseIndent();
+        for (EventRecord eventRecord : mEventRecords) {
+            eventRecord.dump(pw);
+        }
+        pw.decreaseIndent();
+    }
+
+    public void changeEventCacheSize(int newSize) {
+
+        // Resize the event queue.
+        LinkedBlockingQueue<EventRecord> oldEventLog = mEventRecords;
+        mEventRecords = new LinkedBlockingQueue<>(newSize);
+        mCallEventRecordMap.clear();
+
+        oldEventLog.forEach((newRecord -> {
+            Loggable recordEntry = newRecord.getRecordEntry();
+            // Copy the existing queue into the new one.
+            // First remove the oldest entry if no new ones exist.
+            if (mEventRecords.remainingCapacity() == 0) {
+                EventRecord record = mEventRecords.poll();
+                if (record != null) {
+                    mCallEventRecordMap.remove(record.getRecordEntry());
+                }
+            }
+
+            // Now add a new entry
+            mEventRecords.add(newRecord);
+            mCallEventRecordMap.put(recordEntry, newRecord);
+
+            // Don't worry about notifying mEventListeners, since we are just resizing the records.
+        }));
+    }
+
+    public void registerEventListener(EventListener e) {
+        if (e != null) {
+            synchronized (mSync) {
+                mEventListeners.add(e);
+            }
+        }
+    }
+
+    private void addEventRecord(EventRecord newRecord) {
+        Loggable recordEntry = newRecord.getRecordEntry();
+
+        // First remove the oldest entry if no new ones exist.
+        if (mEventRecords.remainingCapacity() == 0) {
+            EventRecord record = mEventRecords.poll();
+            if (record != null) {
+                mCallEventRecordMap.remove(record.getRecordEntry());
+            }
+        }
+
+        // Now add a new entry
+        mEventRecords.add(newRecord);
+        mCallEventRecordMap.put(recordEntry, newRecord);
+
+        // TODO: Add Implementation of this in Telecom for Analytics
+        synchronized (mSync) {
+            for (EventListener l : mEventListeners) {
+                l.eventRecordAdded(newRecord);
+            }
+        }
+    }
+}
diff --git a/telecomm/java/android/telecom/Logging/Session.java b/telecomm/java/android/telecom/Logging/Session.java
new file mode 100644
index 0000000..14f4a0f
--- /dev/null
+++ b/telecomm/java/android/telecom/Logging/Session.java
@@ -0,0 +1,223 @@
+/*
+ * Copyright (C) 2016 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.telecom.Logging;
+
+import android.annotation.NonNull;
+
+import java.util.ArrayList;
+
+/**
+ * The session that stores information about a thread's point of entry into the Telecom code that
+ * persists until the thread exits Telecom.
+ * @hide
+ */
+public class Session {
+
+    public static final String START_SESSION = "START_SESSION";
+    public static final String CREATE_SUBSESSION = "CREATE_SUBSESSION";
+    public static final String CONTINUE_SUBSESSION = "CONTINUE_SUBSESSION";
+    public static final String END_SUBSESSION = "END_SUBSESSION";
+    public static final String END_SESSION = "END_SESSION";
+
+    public static final int UNDEFINED = -1;
+
+    private String mSessionId;
+    private String mShortMethodName;
+    private long mExecutionStartTimeMs;
+    private long mExecutionEndTimeMs = UNDEFINED;
+    private Session mParentSession;
+    private ArrayList<Session> mChildSessions;
+    private boolean mIsCompleted = false;
+    private int mChildCounter = 0;
+    // True if this is a subsession that has been started from the same thread as the parent
+    // session. This can happen if Log.startSession(...) is called multiple times on the same
+    // thread in the case of one Telecom entry point method calling another entry point method.
+    // In this case, we can just make this subsession "invisible," but still keep track of it so
+    // that the Log.endSession() calls match up.
+    private boolean mIsStartedFromActiveSession = false;
+    // Optionally provided info about the method/class/component that started the session in order
+    // to make Logging easier. This info will be provided in parentheses along with the session.
+    private String mOwnerInfo;
+
+    public Session(String sessionId, String shortMethodName, long startTimeMs, long threadID,
+            boolean isStartedFromActiveSession, String ownerInfo) {
+        setSessionId(sessionId);
+        setShortMethodName(shortMethodName);
+        mExecutionStartTimeMs = startTimeMs;
+        mParentSession = null;
+        mChildSessions = new ArrayList<>(5);
+        mIsStartedFromActiveSession = isStartedFromActiveSession;
+        mOwnerInfo = ownerInfo;
+    }
+
+    public void setSessionId(@NonNull String sessionId) {
+        if (sessionId == null) {
+            mSessionId = "?";
+        }
+        mSessionId = sessionId;
+    }
+
+    public String getShortMethodName() {
+        return mShortMethodName;
+    }
+
+    public void setShortMethodName(String shortMethodName) {
+        if (shortMethodName == null) {
+            shortMethodName = "";
+        }
+        mShortMethodName = shortMethodName;
+    }
+
+    public void setParentSession(Session parentSession) {
+        mParentSession = parentSession;
+    }
+
+    public void addChild(Session childSession) {
+        if (childSession != null) {
+            mChildSessions.add(childSession);
+        }
+    }
+
+    public void removeChild(Session child) {
+        if (child != null) {
+            mChildSessions.remove(child);
+        }
+    }
+
+    public long getExecutionStartTimeMilliseconds() {
+        return mExecutionStartTimeMs;
+    }
+
+    public void setExecutionStartTimeMs(long startTimeMs) {
+        mExecutionStartTimeMs = startTimeMs;
+    }
+
+    public Session getParentSession() {
+        return mParentSession;
+    }
+
+    public ArrayList<Session> getChildSessions() {
+        return mChildSessions;
+    }
+
+    public boolean isSessionCompleted() {
+        return mIsCompleted;
+    }
+
+    public boolean isStartedFromActiveSession() {
+        return mIsStartedFromActiveSession;
+    }
+
+    // Mark this session complete. This will be deleted by Log when all subsessions are complete
+    // as well.
+    public void markSessionCompleted(long executionEndTimeMs) {
+        mExecutionEndTimeMs = executionEndTimeMs;
+        mIsCompleted = true;
+    }
+
+    public long getLocalExecutionTime() {
+        if (mExecutionEndTimeMs == UNDEFINED) {
+            return UNDEFINED;
+        }
+        return mExecutionEndTimeMs - mExecutionStartTimeMs;
+    }
+
+    public synchronized String getNextChildId() {
+        return String.valueOf(mChildCounter++);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (!(obj instanceof Session)) {
+            return false;
+        }
+        if (obj == this) {
+            return true;
+        }
+        Session otherSession = (Session) obj;
+        return (mSessionId.equals(otherSession.mSessionId)) &&
+                (mShortMethodName.equals(otherSession.mShortMethodName)) &&
+                mExecutionStartTimeMs == otherSession.mExecutionStartTimeMs &&
+                mParentSession == otherSession.mParentSession &&
+                mChildSessions.equals(otherSession.mChildSessions) &&
+                mIsCompleted == otherSession.mIsCompleted &&
+                mExecutionEndTimeMs == otherSession.mExecutionEndTimeMs &&
+                mChildCounter == otherSession.mChildCounter &&
+                mIsStartedFromActiveSession == otherSession.mIsStartedFromActiveSession &&
+                mOwnerInfo == otherSession.mOwnerInfo;
+    }
+
+    // Builds full session id recursively
+    private String getFullSessionId() {
+        // Cache mParentSession locally to prevent a concurrency problem where
+        // Log.endParentSessions() is called while a logging statement is running (Log.i, for
+        // example) and setting mParentSession to null in a different thread after the null check
+        // occurred.
+        Session parentSession = mParentSession;
+        if (parentSession == null) {
+            return mSessionId;
+        } else {
+            return parentSession.getFullSessionId() + "_" + mSessionId;
+        }
+    }
+
+    // Print out the full Session tree from any subsession node
+    public String printFullSessionTree() {
+        // Get to the top of the tree
+        Session topNode = this;
+        while (topNode.getParentSession() != null) {
+            topNode = topNode.getParentSession();
+        }
+        return topNode.printSessionTree();
+    }
+
+    // Recursively move down session tree using DFS, but print out each node when it is reached.
+    public String printSessionTree() {
+        StringBuilder sb = new StringBuilder();
+        printSessionTree(0, sb);
+        return sb.toString();
+    }
+
+    private void printSessionTree(int tabI, StringBuilder sb) {
+        sb.append(toString());
+        for (Session child : mChildSessions) {
+            sb.append("\n");
+            for (int i = 0; i <= tabI; i++) {
+                sb.append("\t");
+            }
+            child.printSessionTree(tabI + 1, sb);
+        }
+    }
+
+    @Override
+    public String toString() {
+        if (mParentSession != null && mIsStartedFromActiveSession) {
+            // Log.startSession was called from within another active session. Use the parent's
+            // Id instead of the child to reduce confusion.
+            return mParentSession.toString();
+        } else {
+            StringBuilder methodName = new StringBuilder();
+            methodName.append(mShortMethodName);
+            if (mOwnerInfo != null && !mOwnerInfo.isEmpty()) {
+                methodName.append("(InCall package: ");
+                methodName.append(mOwnerInfo);
+                methodName.append(")");
+            }
+            return methodName.toString() + "@" + getFullSessionId();
+        }
+    }
+}
diff --git a/telecomm/java/android/telecom/Logging/SessionManager.java b/telecomm/java/android/telecom/Logging/SessionManager.java
new file mode 100644
index 0000000..a4e8977
--- /dev/null
+++ b/telecomm/java/android/telecom/Logging/SessionManager.java
@@ -0,0 +1,344 @@
+/*
+ * Copyright (C) 2016 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.telecom.Logging;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.provider.Settings;
+import android.util.Base64;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * TODO: Create better Sessions Documentation
+ * @hide
+ */
+
+public class SessionManager {
+
+    // Currently using 3 letters, So don't exceed 64^3
+    private static final long SESSION_ID_ROLLOVER_THRESHOLD = 262144;
+
+    // This parameter can be overridden in Telecom's Timeouts class.
+    public static final long DEFAULT_SESSION_TIMEOUT_MS = 30000L; // 30 seconds
+
+    private static String LOGGING_TAG = "Logging";
+
+    private static final String TIMEOUTS_PREFIX = "telecom.";
+
+    // Synchronized in all method calls
+    private int sCodeEntryCounter = 0;
+    private Context mContext;
+
+    @VisibleForTesting
+    public ConcurrentHashMap<Integer, Session> sSessionMapper = new ConcurrentHashMap<>(100);
+    @VisibleForTesting
+    public Handler sSessionCleanupHandler = new Handler(Looper.getMainLooper());
+    @VisibleForTesting
+    public java.lang.Runnable sCleanStaleSessions = () ->
+            cleanupStaleSessions(getSessionCleanupTimeoutMs());
+
+    // Overridden in LogTest to skip query to ContentProvider
+    private interface ISessionCleanupTimeoutMs {
+        long get();
+    }
+
+    @VisibleForTesting
+    public ISessionCleanupTimeoutMs sSessionCleanupTimeoutMs = () -> {
+        // mContext may be null in some cases, such as testing. For these cases, use the
+        // default value.
+        if (mContext == null) {
+            return DEFAULT_SESSION_TIMEOUT_MS;
+        }
+        return getCleanupTimeout(mContext);
+    };
+
+    // Usage is synchronized on this class.
+    private List<ISessionListener> mSessionListeners = new ArrayList<>();
+
+    public interface ISessionListener {
+        /**
+         * This method is run when a full Session has completed.
+         * @param sessionName The name of the Session that has completed.
+         * @param timeMs The time it took to complete in ms.
+         */
+        void sessionComplete(String sessionName, long timeMs);
+    }
+
+    public interface ISessionIdQueryHandler {
+        String getSessionId();
+    }
+
+    public void setContext(Context context) {
+        mContext = context;
+    }
+
+    public SessionManager() {
+    }
+
+    private long getSessionCleanupTimeoutMs() {
+        return sSessionCleanupTimeoutMs.get();
+    }
+
+    private synchronized void resetStaleSessionTimer() {
+        sSessionCleanupHandler.removeCallbacksAndMessages(null);
+        // Will be null in Log Testing
+        if (sCleanStaleSessions != null) {
+            sSessionCleanupHandler.postDelayed(sCleanStaleSessions, getSessionCleanupTimeoutMs());
+        }
+    }
+
+    /**
+     * Call at an entry point to the Telecom code to track the session. This code must be
+     * accompanied by a Log.endSession().
+     */
+    public synchronized void startSession(String shortMethodName,
+            String callerIdentification) {
+        resetStaleSessionTimer();
+        int threadId = getCallingThreadId();
+        Session activeSession = sSessionMapper.get(threadId);
+        // We have called startSession within an active session that has not ended... Register this
+        // session as a subsession.
+        if (activeSession != null) {
+            Session childSession = createSubsession(true);
+            continueSession(childSession, shortMethodName);
+            return;
+        }
+        Session newSession = new Session(getNextSessionID(), shortMethodName,
+                System.currentTimeMillis(), threadId, false, callerIdentification);
+        sSessionMapper.put(threadId, newSession);
+
+        android.telecom.Log.v(LOGGING_TAG, Session.START_SESSION);
+    }
+
+
+    /**
+     * Notifies the logging system that a subsession will be run at a later point and
+     * allocates the resources. Returns a session object that must be used in
+     * Log.continueSession(...) to start the subsession.
+     */
+    public Session createSubsession() {
+        return createSubsession(false);
+    }
+
+    private synchronized Session createSubsession(boolean isStartedFromActiveSession) {
+        int threadId = getCallingThreadId();
+        Session threadSession = sSessionMapper.get(threadId);
+        if (threadSession == null) {
+            android.telecom.Log.d(LOGGING_TAG, "Log.createSubsession was called with no session " +
+                    "active.");
+            return null;
+        }
+        // Start execution time of the session will be overwritten in continueSession(...).
+        Session newSubsession = new Session(threadSession.getNextChildId(),
+                threadSession.getShortMethodName(), System.currentTimeMillis(), threadId,
+                isStartedFromActiveSession, null);
+        threadSession.addChild(newSubsession);
+        newSubsession.setParentSession(threadSession);
+
+        if (!isStartedFromActiveSession) {
+            android.telecom.Log.v(LOGGING_TAG, Session.CREATE_SUBSESSION + " " +
+                    newSubsession.toString());
+        } else {
+            android.telecom.Log.v(LOGGING_TAG, Session.CREATE_SUBSESSION +
+                    " (Invisible subsession)");
+        }
+        return newSubsession;
+    }
+
+    /**
+     * Cancels a subsession that had Log.createSubsession() called on it, but will never have
+     * Log.continueSession(...) called on it due to an error. Allows the subsession to be cleaned
+     * gracefully instead of being removed by the sSessionCleanupHandler forcefully later.
+     */
+    public synchronized void cancelSubsession(Session subsession) {
+        if (subsession == null) {
+            return;
+        }
+
+        subsession.markSessionCompleted(0);
+        endParentSessions(subsession);
+    }
+
+    /**
+     * Starts the subsession that was created in Log.CreateSubsession. The Log.endSession() method
+     * must be called at the end of this method. The full session will complete when all
+     * subsessions are completed.
+     */
+    public synchronized void continueSession(Session subsession, String shortMethodName) {
+        if (subsession == null) {
+            return;
+        }
+        resetStaleSessionTimer();
+        String callingMethodName = subsession.getShortMethodName();
+        subsession.setShortMethodName(callingMethodName + "->" + shortMethodName);
+        subsession.setExecutionStartTimeMs(System.currentTimeMillis());
+        Session parentSession = subsession.getParentSession();
+        if (parentSession == null) {
+            android.telecom.Log.d(LOGGING_TAG, "Log.continueSession was called with no session " +
+                    "active for method %s.", shortMethodName);
+            return;
+        }
+
+        sSessionMapper.put(getCallingThreadId(), subsession);
+        if (!subsession.isStartedFromActiveSession()) {
+            android.telecom.Log.v(LOGGING_TAG, Session.CONTINUE_SUBSESSION);
+        } else {
+            android.telecom.Log.v(LOGGING_TAG, Session.CONTINUE_SUBSESSION +
+                    " (Invisible Subsession) with Method " + shortMethodName);
+        }
+    }
+
+    /**
+     * Ends the current session/subsession. Must be called after a Log.startSession(...) and
+     * Log.continueSession(...) call.
+     */
+    public synchronized void endSession() {
+        int threadId = getCallingThreadId();
+        Session completedSession = sSessionMapper.get(threadId);
+        if (completedSession == null) {
+            android.telecom.Log.w(LOGGING_TAG, "Log.endSession was called with no session active.");
+            return;
+        }
+
+        completedSession.markSessionCompleted(System.currentTimeMillis());
+        if (!completedSession.isStartedFromActiveSession()) {
+            android.telecom.Log.v(LOGGING_TAG, Session.END_SUBSESSION + " (dur: " +
+                    completedSession.getLocalExecutionTime() + " mS)");
+        } else {
+            android.telecom.Log.v(LOGGING_TAG, Session.END_SUBSESSION +
+                    " (Invisible Subsession) (dur: " + completedSession.getLocalExecutionTime() +
+                    " ms)");
+        }
+        // Remove after completed so that reference still exists for logging the end events
+        Session parentSession = completedSession.getParentSession();
+        sSessionMapper.remove(threadId);
+        endParentSessions(completedSession);
+        // If this subsession was started from a parent session using Log.startSession, return the
+        // ThreadID back to the parent after completion.
+        if (parentSession != null && !parentSession.isSessionCompleted() &&
+                completedSession.isStartedFromActiveSession()) {
+            sSessionMapper.put(threadId, parentSession);
+        }
+    }
+
+    // Recursively deletes all complete parent sessions of the current subsession if it is a leaf.
+    private void endParentSessions(Session subsession) {
+        // Session is not completed or not currently a leaf, so we can not remove because a child is
+        // still running
+        if (!subsession.isSessionCompleted() || subsession.getChildSessions().size() != 0) {
+            return;
+        }
+
+        Session parentSession = subsession.getParentSession();
+        if (parentSession != null) {
+            subsession.setParentSession(null);
+            parentSession.removeChild(subsession);
+            endParentSessions(parentSession);
+        } else {
+            // All of the subsessions have been completed and it is time to report on the full
+            // running time of the session.
+            long fullSessionTimeMs =
+                    System.currentTimeMillis() - subsession.getExecutionStartTimeMilliseconds();
+            android.telecom.Log.v(LOGGING_TAG, Session.END_SESSION + " (dur: " + fullSessionTimeMs
+                    + " ms): " + subsession.toString());
+            // TODO: Add analytics hook
+            for (ISessionListener l : mSessionListeners) {
+                l.sessionComplete(subsession.getShortMethodName(), fullSessionTimeMs);
+            }
+        }
+    }
+
+    public String getSessionId() {
+        Session currentSession = sSessionMapper.get(getCallingThreadId());
+        return currentSession != null ? currentSession.toString() : "";
+    }
+
+    public synchronized void registerSessionListener(ISessionListener l) {
+        if (l != null) {
+            mSessionListeners.add(l);
+        }
+    }
+
+    private synchronized String getNextSessionID() {
+        Integer nextId = sCodeEntryCounter++;
+        if (nextId >= SESSION_ID_ROLLOVER_THRESHOLD) {
+            restartSessionCounter();
+            nextId = sCodeEntryCounter++;
+        }
+        return getBase64Encoding(nextId);
+    }
+
+    @VisibleForTesting
+    public synchronized void restartSessionCounter() {
+        sCodeEntryCounter = 0;
+    }
+
+    @VisibleForTesting
+    public String getBase64Encoding(int number) {
+        byte[] idByteArray = ByteBuffer.allocate(4).putInt(number).array();
+        idByteArray = Arrays.copyOfRange(idByteArray, 2, 4);
+        return Base64.encodeToString(idByteArray, Base64.NO_WRAP | Base64.NO_PADDING);
+    }
+
+    public int getCallingThreadId() {
+        return android.os.Process.myTid();
+    }
+
+    @VisibleForTesting
+    private synchronized void cleanupStaleSessions(long timeoutMs) {
+        String logMessage = "Stale Sessions Cleaned:\n";
+        boolean isSessionsStale = false;
+        long currentTimeMs = System.currentTimeMillis();
+        // Remove references that are in the Session Mapper (causing GC to occur) on
+        // sessions that are lasting longer than LOGGING_SESSION_TIMEOUT_MS.
+        // If this occurs, then there is most likely a Session active that never had
+        // Log.endSession called on it.
+        for (Iterator<ConcurrentHashMap.Entry<Integer, Session>> it =
+             sSessionMapper.entrySet().iterator(); it.hasNext(); ) {
+            ConcurrentHashMap.Entry<Integer, Session> entry = it.next();
+            Session session = entry.getValue();
+            if (currentTimeMs - session.getExecutionStartTimeMilliseconds() > timeoutMs) {
+                it.remove();
+                logMessage += session.printFullSessionTree() + "\n";
+                isSessionsStale = true;
+            }
+        }
+        if (isSessionsStale) {
+            android.telecom.Log.w(LOGGING_TAG, logMessage);
+        } else {
+            android.telecom.Log.v(LOGGING_TAG, "No stale logging sessions needed to be cleaned...");
+        }
+    }
+
+    /**
+     * Returns the amount of time after a Logging session has been started that Telecom is set to
+     * perform a sweep to check and make sure that the session is still not incomplete (stale).
+     */
+    private long getCleanupTimeout(Context context) {
+        return Settings.Secure.getLong(context.getContentResolver(), TIMEOUTS_PREFIX +
+                "stale_session_cleanup_timeout_millis", DEFAULT_SESSION_TIMEOUT_MS);
+    }
+}
diff --git a/telecomm/java/android/telecom/Logging/TimedEvent.java b/telecomm/java/android/telecom/Logging/TimedEvent.java
new file mode 100644
index 0000000..6785e92
--- /dev/null
+++ b/telecomm/java/android/telecom/Logging/TimedEvent.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2016 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.telecom.Logging;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @hide
+ */
+public abstract class TimedEvent<T> {
+    public abstract long getTime();
+    public abstract T getKey();
+
+    public static <T> Map<T, Double> averageTimings(Collection<? extends TimedEvent<T>> events) {
+        HashMap<T, Integer> counts = new HashMap<>();
+        HashMap<T, Double> result = new HashMap<>();
+
+        for (TimedEvent<T> entry : events) {
+            if (counts.containsKey(entry.getKey())) {
+                counts.put(entry.getKey(), counts.get(entry.getKey()) + 1);
+                result.put(entry.getKey(), result.get(entry.getKey()) + entry.getTime());
+            } else {
+                counts.put(entry.getKey(), 1);
+                result.put(entry.getKey(), (double) entry.getTime());
+            }
+        }
+
+        for (Map.Entry<T, Double> entry : result.entrySet()) {
+            result.put(entry.getKey(), entry.getValue() / counts.get(entry.getKey()));
+        }
+
+        return result;
+    }
+}
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index fcef55f..31ea1d1 100644
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -761,6 +761,16 @@
     public static final String KEY_CARRIER_ADDITIONAL_CBS_CHANNELS_STRINGS =
             "carrier_additional_cbs_channels_strings";
 
+    /**
+      * Indicates whether STK LAUNCH_BROWSER command is disabled.
+      * If {@code true}, then the browser will not be launched
+      * on UI for the LAUNCH_BROWSER STK command.
+      * @hide
+      */
+    public static final String KEY_STK_DISABLE_LAUNCH_BROWSER_BOOL =
+            "stk_disable_launch_browser_bool";
+
+
     // These variables are used by the MMS service and exposed through another API, {@link
     // SmsManager}. The variable names and string values are copied from there.
     public static final String KEY_MMS_ALIAS_ENABLED_BOOL = "aliasEnabled";
@@ -1247,6 +1257,7 @@
         sDefaults.putBoolean(KEY_NOTIFY_VT_HANDOVER_TO_WIFI_FAILURE_BOOL, false);
         sDefaults.putStringArray(FILTERED_CNAP_NAMES_STRING_ARRAY, null);
         sDefaults.putBoolean(KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, false);
+        sDefaults.putBoolean(KEY_STK_DISABLE_LAUNCH_BROWSER_BOOL, false);
     }
 
     /**
diff --git a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
index a4aab7c..da27ea9 100644
--- a/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
+++ b/tests/StatusBar/src/com/android/statusbartest/NotificationTestList.java
@@ -87,6 +87,11 @@
     }
 
     private Test[] mTests = new Test[] {
+            new Test("cancel all") {
+                public void run() {
+                    mNM.cancelAll();
+                }
+            },
             new Test("Phone call") {
                 public void run()
                 {
diff --git a/tests/UiBench/AndroidManifest.xml b/tests/UiBench/AndroidManifest.xml
index b7b4894..29154aa 100644
--- a/tests/UiBench/AndroidManifest.xml
+++ b/tests/UiBench/AndroidManifest.xml
@@ -102,10 +102,18 @@
         <activity
             android:name=".SlowBindRecyclerViewActivity"
             android:label="General/Slow Bind RecyclerView" >
-        <intent-filter>
-            <action android:name="android.intent.action.MAIN" />
-            <category android:name="com.android.test.uibench.TEST" />
-        </intent-filter>
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="com.android.test.uibench.TEST" />
+            </intent-filter>
+        </activity>
+        <activity
+            android:name=".SlowNestedRecyclerViewActivity"
+            android:label="General/Slow Nested RecyclerView" >
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="com.android.test.uibench.TEST" />
+            </intent-filter>
         </activity>
         <activity
             android:name=".ActivityTransition"
diff --git a/tests/UiBench/src/com/android/test/uibench/SlowNestedRecyclerViewActivity.java b/tests/UiBench/src/com/android/test/uibench/SlowNestedRecyclerViewActivity.java
new file mode 100644
index 0000000..305c051
--- /dev/null
+++ b/tests/UiBench/src/com/android/test/uibench/SlowNestedRecyclerViewActivity.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2016 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 com.android.test.uibench;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Color;
+import android.graphics.drawable.GradientDrawable;
+import android.graphics.drawable.InsetDrawable;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.test.uibench.recyclerview.RvCompatListActivity;
+
+import java.util.ArrayList;
+import java.util.concurrent.TimeUnit;
+
+public class SlowNestedRecyclerViewActivity extends RvCompatListActivity {
+    private static final int OUTER_ITEM_COUNT = 100;
+    private static final int INNER_ITEM_COUNT = 20;
+
+    private static final long INNER_ITEM_CREATE_NS = TimeUnit.MILLISECONDS.toNanos(6);
+    private static final long INNER_ITEM_BIND_NS = TimeUnit.MILLISECONDS.toNanos(1);
+    private static final long INNER_ITEM_ATTACH_NS = TimeUnit.MILLISECONDS.toNanos(1);
+
+    private static final long OUTER_ITEM_CREATE_NS = TimeUnit.MILLISECONDS.toNanos(3);
+    private static final long OUTER_ITEM_BIND_NS = TimeUnit.MILLISECONDS.toNanos(1);
+    private static final long OUTER_ITEM_ATTACH_NS = TimeUnit.MILLISECONDS.toNanos(1);
+
+    private SizeData mSizeData;
+
+    private static class SizeData {
+        final int innerItemWidth;
+        final int innerItemHeight;
+        final int headerHeight;
+
+        SizeData(Resources resources) {
+            innerItemWidth = (int) (resources.getDisplayMetrics().widthPixels / 3.3f);
+            innerItemHeight = (int) (innerItemWidth * 1.6f);
+            headerHeight = (int) (resources.getDisplayMetrics().heightPixels * 0.5f);
+        }
+    }
+
+    private SizeData getSizeData(Resources resources) {
+        if (mSizeData == null) {
+            mSizeData = new SizeData(resources);
+        }
+        return mSizeData;
+    }
+
+    @Override
+    protected RecyclerView.LayoutManager createLayoutManager(Context context) {
+        return new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
+    }
+
+    @Override
+    protected RecyclerView.Adapter createAdapter() {
+        return new OuterAdapter();
+    }
+
+    private class InnerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+        @Override
+        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+            final long start = System.nanoTime();
+
+            final float density = parent.getResources().getDisplayMetrics().density;
+            View view = new View(parent.getContext()) {
+                @Override
+                protected void onAttachedToWindow() {
+                    final long start = System.nanoTime();
+                    super.onAttachedToWindow();
+                    while (System.nanoTime() - start < INNER_ITEM_ATTACH_NS);
+                }
+            };
+
+            SizeData sizeData = getSizeData(parent.getResources());
+            view.setMinimumWidth(sizeData.innerItemWidth);
+            view.setMinimumHeight(sizeData.innerItemHeight);
+
+            GradientDrawable bg = new GradientDrawable();
+            bg.setCornerRadius(10 * density);
+            bg.setColor(Color.BLACK);
+            final int pad = (int)(10 * density);
+            view.setPadding(pad, pad, pad, pad);
+            view.setBackgroundDrawable(new InsetDrawable(bg, pad));
+            RecyclerView.ViewHolder holder = new RecyclerView.ViewHolder(view) {};
+
+            while (System.nanoTime() - start < INNER_ITEM_CREATE_NS);
+            return holder;
+        }
+
+        @Override
+        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
+            final long start = System.nanoTime();
+            while (System.nanoTime() - start < INNER_ITEM_BIND_NS);
+        }
+
+        @Override
+        public int getItemCount() { return INNER_ITEM_COUNT; }
+    }
+
+    private class OuterAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
+        static final int TYPE_HEADER = 0;
+        static final int TYPE_RECYCLER = 1;
+
+        ArrayList<InnerAdapter> mAdapters = new ArrayList<>();
+        RecyclerView.RecycledViewPool mSharedPool = new RecyclerView.RecycledViewPool();
+
+        OuterAdapter() {
+            for (int i = 0; i < OUTER_ITEM_COUNT; i++) {
+                mAdapters.add(new InnerAdapter());
+            }
+        }
+
+        @Override
+        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+            SizeData sizeData = getSizeData(parent.getResources());
+            if (viewType == TYPE_HEADER) {
+                View view = new View(parent.getContext());
+                view.setMinimumHeight(sizeData.headerHeight);
+                return new RecyclerView.ViewHolder(view) {};
+            } else {
+                final long start = System.nanoTime();
+
+                RecyclerView rv = new RecyclerView(parent.getContext()) {
+                    @Override
+                    protected void onAttachedToWindow() {
+                        final long start = System.nanoTime();
+                        super.onAttachedToWindow();
+                        while (System.nanoTime() - start < OUTER_ITEM_ATTACH_NS);
+
+                    }
+                };
+
+                rv.setLayoutParams(new RecyclerView.LayoutParams(
+                        ViewGroup.LayoutParams.MATCH_PARENT, sizeData.innerItemHeight));
+                rv.setLayoutManager(new LinearLayoutManager(parent.getContext(),
+                        LinearLayoutManager.HORIZONTAL, false));
+                rv.setRecycledViewPool(mSharedPool);
+                RecyclerView.ViewHolder holder = new RecyclerView.ViewHolder(rv) {};
+
+                while (System.nanoTime() - start < OUTER_ITEM_CREATE_NS);
+                return holder;
+            }
+        }
+
+        @Override
+        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
+            if (getItemViewType(position) == TYPE_RECYCLER) {
+                final long start = System.nanoTime();
+                ((RecyclerView)holder.itemView).setAdapter(mAdapters.get(position));
+                while (System.nanoTime() - start < OUTER_ITEM_BIND_NS);
+            }
+        }
+
+        @Override
+        public int getItemViewType(int position) {
+            return position == 0 ? TYPE_HEADER : TYPE_RECYCLER;
+        }
+
+        @Override
+        public int getItemCount() {
+            return mAdapters.size();
+        }
+    }
+}
diff --git a/tools/aapt/Images.cpp b/tools/aapt/Images.cpp
index aea16c7..5f586a1 100644
--- a/tools/aapt/Images.cpp
+++ b/tools/aapt/Images.cpp
@@ -833,6 +833,7 @@
         bpp = 4;
     } else {
         printf("Unknown color type %d.\n", color_type);
+        return;
     }
 
     for (j = 0; j < h; j++) {
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
index bcfe3bf..090cee8 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -601,14 +601,6 @@
         return Arrays.equals(argb1, argb2);
     }
 
-    // Only used by AssetAtlasService, which we don't care about.
-    @LayoutlibDelegate
-    /*package*/ static long nativeRefPixelRef(long nativeBitmap) {
-        // Hack: This is called by Bitmap.refSkPixelRef() and LayoutLib uses that method to get
-        // the native pointer from a Bitmap. So, we return nativeBitmap here.
-        return nativeBitmap;
-    }
-
     // ---- Private delegate/helper methods ----
 
     private Bitmap_Delegate(BufferedImage image, Config config) {
diff --git a/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java b/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java
index f4f92ec..09ab657 100644
--- a/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java
+++ b/tools/layoutlib/bridge/src/android/view/IWindowManagerImpl.java
@@ -612,10 +612,13 @@
         throws RemoteException {}
 
     @Override
-    public void createWallpaperInputConsumer(InputChannel inputChannel) throws RemoteException {}
+    public void createInputConsumer(String name, InputChannel inputChannel)
+            throws RemoteException {}
 
     @Override
-    public void removeWallpaperInputConsumer() throws RemoteException {}
+    public boolean destroyInputConsumer(String name) throws RemoteException {
+        return false;
+    }
 
     @Override
     public Bitmap screenshotWallpaper() throws RemoteException {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index feed045..91a783a 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -358,7 +358,8 @@
                     mMeasuredScreenWidth, MeasureSpec.EXACTLY,
                     mMeasuredScreenHeight, MeasureSpec.EXACTLY);
             mViewRoot.layout(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight);
-            mSystemViewInfoList = visitAllChildren(mViewRoot, 0, params.getExtendedViewInfoMode(),
+            mSystemViewInfoList =
+                    visitAllChildren(mViewRoot, 0, 0, params.getExtendedViewInfoMode(),
                     false);
 
             return SUCCESS.createResult();
@@ -521,7 +522,8 @@
                         mMeasuredScreenHeight);
             }
 
-            mSystemViewInfoList = visitAllChildren(mViewRoot, 0, params.getExtendedViewInfoMode(),
+            mSystemViewInfoList =
+                    visitAllChildren(mViewRoot, 0, 0, params.getExtendedViewInfoMode(),
                     false);
 
             // success!
@@ -1242,20 +1244,22 @@
      * bounds of all the views.
      *
      * @param view the root View
-     * @param offset an offset for the view bounds.
+     * @param hOffset horizontal offset for the view bounds.
+     * @param vOffset vertical offset for the view bounds.
      * @param setExtendedInfo whether to set the extended view info in the {@link ViewInfo} object.
      * @param isContentFrame {@code true} if the {@code ViewInfo} to be created is part of the
      *                       content frame.
      *
      * @return {@code ViewInfo} containing the bounds of the view and it children otherwise.
      */
-    private ViewInfo visit(View view, int offset, boolean setExtendedInfo,
+    private ViewInfo visit(View view, int hOffset, int vOffset, boolean setExtendedInfo,
             boolean isContentFrame) {
-        ViewInfo result = createViewInfo(view, offset, setExtendedInfo, isContentFrame);
+        ViewInfo result = createViewInfo(view, hOffset, vOffset, setExtendedInfo, isContentFrame);
 
         if (view instanceof ViewGroup) {
             ViewGroup group = ((ViewGroup) view);
-            result.setChildren(visitAllChildren(group, isContentFrame ? 0 : offset,
+            result.setChildren(visitAllChildren(group, isContentFrame ? 0 : hOffset,
+                    isContentFrame ? 0 : vOffset,
                     setExtendedInfo, isContentFrame));
         }
         return result;
@@ -1267,20 +1271,22 @@
      * the children of the {@code mContentRoot}.
      *
      * @param viewGroup the root View
-     * @param offset an offset from the top for the content view frame.
+     * @param hOffset horizontal offset from the top for the content view frame.
+     * @param vOffset vertical offset from the top for the content view frame.
      * @param setExtendedInfo whether to set the extended view info in the {@link ViewInfo} object.
      * @param isContentFrame {@code true} if the {@code ViewInfo} to be created is part of the
      *                       content frame. {@code false} if the {@code ViewInfo} to be created is
      *                       part of the system decor.
      */
-    private List<ViewInfo> visitAllChildren(ViewGroup viewGroup, int offset,
+    private List<ViewInfo> visitAllChildren(ViewGroup viewGroup, int hOffset, int vOffset,
             boolean setExtendedInfo, boolean isContentFrame) {
         if (viewGroup == null) {
             return null;
         }
 
         if (!isContentFrame) {
-            offset += viewGroup.getTop();
+            vOffset += viewGroup.getTop();
+            hOffset += viewGroup.getLeft();
         }
 
         int childCount = viewGroup.getChildCount();
@@ -1288,7 +1294,8 @@
             List<ViewInfo> childrenWithoutOffset = new ArrayList<ViewInfo>(childCount);
             List<ViewInfo> childrenWithOffset = new ArrayList<ViewInfo>(childCount);
             for (int i = 0; i < childCount; i++) {
-                ViewInfo[] childViewInfo = visitContentRoot(viewGroup.getChildAt(i), offset,
+                ViewInfo[] childViewInfo =
+                        visitContentRoot(viewGroup.getChildAt(i), hOffset, vOffset,
                         setExtendedInfo);
                 childrenWithoutOffset.add(childViewInfo[0]);
                 childrenWithOffset.add(childViewInfo[1]);
@@ -1298,7 +1305,7 @@
         } else {
             List<ViewInfo> children = new ArrayList<ViewInfo>(childCount);
             for (int i = 0; i < childCount; i++) {
-                children.add(visit(viewGroup.getChildAt(i), offset, setExtendedInfo,
+                children.add(visit(viewGroup.getChildAt(i), hOffset, vOffset, setExtendedInfo,
                         isContentFrame));
             }
             return children;
@@ -1317,16 +1324,18 @@
      *         index 1 is with the offset.
      */
     @NonNull
-    private ViewInfo[] visitContentRoot(View view, int offset, boolean setExtendedInfo) {
+    private ViewInfo[] visitContentRoot(View view, int hOffset, int vOffset,
+            boolean setExtendedInfo) {
         ViewInfo[] result = new ViewInfo[2];
         if (view == null) {
             return result;
         }
 
-        result[0] = createViewInfo(view, 0, setExtendedInfo, true);
-        result[1] = createViewInfo(view, offset, setExtendedInfo, true);
+        result[0] = createViewInfo(view, 0, 0, setExtendedInfo, true);
+        result[1] = createViewInfo(view, hOffset, vOffset, setExtendedInfo, true);
         if (view instanceof ViewGroup) {
-            List<ViewInfo> children = visitAllChildren((ViewGroup) view, 0, setExtendedInfo, true);
+            List<ViewInfo> children =
+                    visitAllChildren((ViewGroup) view, 0, 0, setExtendedInfo, true);
             result[0].setChildren(children);
             result[1].setChildren(children);
         }
@@ -1337,9 +1346,12 @@
      * Creates a {@link ViewInfo} for the view. The {@code ViewInfo} corresponding to the children
      * of the {@code view} are not created. Consequently, the children of {@code ViewInfo} is not
      * set.
-     * @param offset an offset for the view bounds. Used only if view is part of the content frame.
+     * @param hOffset horizontal offset for the view bounds. Used only if view is part of the
+     * content frame.
+     * @param vOffset vertial an offset for the view bounds. Used only if view is part of the
+     * content frame.
      */
-    private ViewInfo createViewInfo(View view, int offset, boolean setExtendedInfo,
+    private ViewInfo createViewInfo(View view, int hOffset, int vOffset, boolean setExtendedInfo,
             boolean isContentFrame) {
         if (view == null) {
             return null;
@@ -1355,9 +1367,9 @@
             // The view is part of the layout added by the user. Hence,
             // the ViewCookie may be obtained only through the Context.
             result = new ViewInfo(view.getClass().getName(),
-                    getContext().getViewKey(view),
-                    -scrollX + view.getLeft(), -scrollY + view.getTop() + offset,
-                    -scrollX + view.getRight(), -scrollY + view.getBottom() + offset,
+                    getContext().getViewKey(view), -scrollX + view.getLeft() + hOffset,
+                    -scrollY + view.getTop() + vOffset, -scrollX + view.getRight() + hOffset,
+                    -scrollY + view.getBottom() + vOffset,
                     view, view.getLayoutParams());
         } else {
             // We are part of the system decor.
diff --git a/tools/streaming_proto/Android.mk b/tools/streaming_proto/Android.mk
new file mode 100644
index 0000000..5a54fd1
--- /dev/null
+++ b/tools/streaming_proto/Android.mk
@@ -0,0 +1,41 @@
+#
+# Copyright (C) 2015 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.
+#
+LOCAL_PATH:= $(call my-dir)
+
+# ==========================================================
+# Build the host executable: protoc-gen-javastream
+# ==========================================================
+include $(CLEAR_VARS)
+LOCAL_MODULE := protoc-gen-javastream
+LOCAL_SRC_FILES := \
+    Errors.cpp \
+    string_utils.cpp \
+    main.cpp
+LOCAL_SHARED_LIBRARIES := \
+    libprotoc
+include $(BUILD_HOST_EXECUTABLE)
+
+# ==========================================================
+# Build the java test
+# ==========================================================
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := \
+    $(call all-java-files-under, test) \
+    $(call all-proto-files-under, test)
+LOCAL_MODULE := StreamingProtoTest
+LOCAL_PROTOC_OPTIMIZE_TYPE := stream
+include $(BUILD_JAVA_LIBRARY)
+
diff --git a/tools/streaming_proto/Errors.cpp b/tools/streaming_proto/Errors.cpp
new file mode 100644
index 0000000..91c6b92
--- /dev/null
+++ b/tools/streaming_proto/Errors.cpp
@@ -0,0 +1,87 @@
+#include "Errors.h"
+
+#include <stdlib.h>
+
+namespace android {
+namespace javastream_proto {
+
+Errors ERRORS;
+
+const string UNKNOWN_FILE;
+const int UNKNOWN_LINE = 0;
+
+Error::Error()
+{
+}
+
+Error::Error(const Error& that)
+    :filename(that.filename),
+     lineno(that.lineno),
+     message(that.message)
+{
+}
+
+Error::Error(const string& f, int l, const char* m)
+    :filename(f),
+     lineno(l),
+     message(m)
+{
+}
+
+Errors::Errors()
+    :m_errors()
+{
+}
+
+Errors::~Errors()
+{
+}
+
+void
+Errors::Add(const string& filename, int lineno, const char* format, ...)
+{
+    va_list args;
+    va_start(args, format);
+    AddImpl(filename, lineno, format, args);
+    va_end(args);
+}
+
+void
+Errors::AddImpl(const string& filename, int lineno, const char* format, va_list args)
+{
+    va_list args2;
+    va_copy(args2, args);
+    int message_size = vsnprintf((char*)NULL, 0, format, args2);
+    va_end(args2);
+
+    char* buffer = new char[message_size+1];
+    vsnprintf(buffer, message_size, format, args);
+    Error error(filename, lineno, buffer);
+    delete[] buffer;
+
+    m_errors.push_back(error);
+}
+
+void
+Errors::Print() const
+{
+    for (vector<Error>::const_iterator it = m_errors.begin(); it != m_errors.end(); it++) {
+        if (it->filename == UNKNOWN_FILE) {
+            fprintf(stderr, "%s", it->message.c_str());
+        } else if (it->lineno == UNKNOWN_LINE) {
+            fprintf(stderr, "%s:%s", it->filename.c_str(), it->message.c_str());
+        } else {
+            fprintf(stderr, "%s:%d:%s", it->filename.c_str(), it->lineno, it->message.c_str());
+        }
+    }
+}
+
+bool
+Errors::HasErrors() const
+{
+    return m_errors.size() > 0;
+}
+
+} // namespace javastream_proto
+} // namespace android
+
diff --git a/tools/streaming_proto/Errors.h b/tools/streaming_proto/Errors.h
new file mode 100644
index 0000000..109195a
--- /dev/null
+++ b/tools/streaming_proto/Errors.h
@@ -0,0 +1,48 @@
+#include <stdio.h>
+
+#include <string>
+#include <vector>
+
+namespace android {
+namespace javastream_proto {
+
+using namespace std;
+
+struct Error
+{
+    Error();
+    explicit Error(const Error& that);
+    Error(const string& filename, int lineno, const char* message);
+
+    string filename;
+    int lineno;
+    string message;
+};
+
+class Errors
+{
+public:
+    Errors();
+    ~Errors();
+
+    // Add an error
+    void Add(const string& filename, int lineno, const char* format, ...);
+
+    // Print the errors to stderr if there are any.
+    void Print() const;
+
+    bool HasErrors() const;
+
+private:
+    // The errors that have been added
+    vector<Error> m_errors;
+    void AddImpl(const string& filename, int lineno, const char* format, va_list ap);
+};
+
+extern Errors ERRORS;
+extern const string UNKNOWN_FILE;
+extern const int UNKNOWN_LINE;
+
+
+} // namespace javastream_proto
+} // namespace android
diff --git a/tools/streaming_proto/main.cpp b/tools/streaming_proto/main.cpp
new file mode 100644
index 0000000..d286213
--- /dev/null
+++ b/tools/streaming_proto/main.cpp
@@ -0,0 +1,391 @@
+#include "Errors.h"
+
+#include "string_utils.h"
+
+#include "google/protobuf/compiler/plugin.pb.h"
+#include "google/protobuf/io/zero_copy_stream_impl.h"
+#include "google/protobuf/text_format.h"
+
+#include <stdio.h>
+#include <iomanip>
+#include <iostream>
+#include <sstream>
+#include <map>
+
+using namespace android::javastream_proto;
+using namespace google::protobuf;
+using namespace google::protobuf::compiler;
+using namespace google::protobuf::io;
+using namespace std;
+
+const int FIELD_TYPE_SHIFT = 32;
+const uint64_t FIELD_TYPE_DOUBLE = 1L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_FLOAT = 2L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_INT32 = 3L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_INT64 = 4L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_UINT32 = 5L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_UINT64 = 6L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_SINT32 = 7L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_SINT64 = 8L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_FIXED32 = 9L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_FIXED64 = 10L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_SFIXED32 = 11L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_SFIXED64 = 12L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_BOOL = 13L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_STRING = 14L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_BYTES = 15L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_ENUM = 16L << FIELD_TYPE_SHIFT;
+const uint64_t FIELD_TYPE_OBJECT = 17L << FIELD_TYPE_SHIFT;
+
+const int FIELD_COUNT_SHIFT = 40;
+const uint64_t FIELD_COUNT_SINGLE = 1L << FIELD_COUNT_SHIFT;
+const uint64_t FIELD_COUNT_REPEATED = 2L << FIELD_COUNT_SHIFT;
+const uint64_t FIELD_COUNT_PACKED = 5L << FIELD_COUNT_SHIFT;
+
+
+/**
+ * See if this is the file for this request, and not one of the imported ones.
+ */
+static bool
+should_generate_for_file(const CodeGeneratorRequest& request, const string& file)
+{
+    const int N = request.file_to_generate_size();
+    for (int i=0; i<N; i++) {
+        if (request.file_to_generate(i) == file) {
+            return true;
+        }
+    }
+    return false;
+}
+
+/**
+ * If the descriptor gives us a class name, use that. Otherwise make one up from
+ * the filename of the .proto file.
+ */
+static string
+make_outer_class_name(const FileDescriptorProto& file_descriptor)
+{
+    string name = file_descriptor.options().java_outer_classname();
+    if (name.size() == 0) {
+        name = to_camel_case(file_base_name(file_descriptor.name()));
+        if (name.size() == 0) {
+            ERRORS.Add(UNKNOWN_FILE, UNKNOWN_LINE,
+                    "Unable to make an outer class name for file: %s",
+                    file_descriptor.name().c_str());
+            name = "Unknown";
+        }
+    }
+    return name;
+}
+
+/**
+ * Figure out the package name that we are generating.
+ */
+static string
+make_java_package(const FileDescriptorProto& file_descriptor) {
+    if (file_descriptor.options().has_java_package()) {
+        return file_descriptor.options().java_package();
+    } else {
+        return file_descriptor.package();
+    }
+}
+
+/**
+ * Figure out the name of the file we are generating.
+ */
+static string
+make_file_name(const FileDescriptorProto& file_descriptor)
+{
+    string const package = make_java_package(file_descriptor);
+    string result;
+    if (package.size() > 0) {
+        result = replace_string(package, '.', '/');
+        result += '/';
+    }
+
+    result += make_outer_class_name(file_descriptor);
+    result += ".java";
+
+    return result;
+}
+
+static string
+indent_more(const string& indent)
+{
+    return indent + "    ";
+}
+
+/**
+ * Write the constants for an enum.
+ */
+static void
+write_enum(stringstream& text, const EnumDescriptorProto& enu, const string& indent)
+{
+    const int N = enu.value_size();
+    text << indent << "// enum " << enu.name() << endl;
+    for (int i=0; i<N; i++) {
+        const EnumValueDescriptorProto& value = enu.value(i);
+        text << indent << "public static final int "
+                << make_constant_name(value.name())
+                << " = " << value.number() << ";" << endl;
+    }
+    text << endl;
+}
+
+/**
+ * Get the string name for a field.
+ */
+static string
+get_proto_type(const FieldDescriptorProto& field)
+{
+    switch (field.type()) {
+        case FieldDescriptorProto::TYPE_DOUBLE:
+            return "double";
+        case FieldDescriptorProto::TYPE_FLOAT:
+            return "float";
+        case FieldDescriptorProto::TYPE_INT64:
+            return "int64";
+        case FieldDescriptorProto::TYPE_UINT64:
+            return "uint64";
+        case FieldDescriptorProto::TYPE_INT32:
+            return "int32";
+        case FieldDescriptorProto::TYPE_FIXED64:
+            return "fixed64";
+        case FieldDescriptorProto::TYPE_FIXED32:
+            return "fixed32";
+        case FieldDescriptorProto::TYPE_BOOL:
+            return "bool";
+        case FieldDescriptorProto::TYPE_STRING:
+            return "string";
+        case FieldDescriptorProto::TYPE_GROUP:
+            return "group<unsupported!>";
+        case FieldDescriptorProto::TYPE_MESSAGE:
+            return field.type_name();
+        case FieldDescriptorProto::TYPE_BYTES:
+            return "bytes";
+        case FieldDescriptorProto::TYPE_UINT32:
+            return "uint32";
+        case FieldDescriptorProto::TYPE_ENUM:
+            return field.type_name();
+        case FieldDescriptorProto::TYPE_SFIXED32:
+            return "sfixed32";
+        case FieldDescriptorProto::TYPE_SFIXED64:
+            return "sfixed64";
+        case FieldDescriptorProto::TYPE_SINT32:
+            return "sint32";
+        case FieldDescriptorProto::TYPE_SINT64:
+            return "sint64";
+        default:
+            // won't happen
+            return "void";
+    }
+}
+
+static uint64_t
+get_field_id(const FieldDescriptorProto& field)
+{
+    // Number
+    uint64_t result = (uint32_t)field.number();
+
+    // Type
+    switch (field.type()) {
+        case FieldDescriptorProto::TYPE_DOUBLE:
+            result |= FIELD_TYPE_DOUBLE;
+        case FieldDescriptorProto::TYPE_FLOAT:
+            result |= FIELD_TYPE_FLOAT;
+        case FieldDescriptorProto::TYPE_INT64:
+            result |= FIELD_TYPE_INT64;
+        case FieldDescriptorProto::TYPE_UINT64:
+            result |= FIELD_TYPE_UINT64;
+        case FieldDescriptorProto::TYPE_INT32:
+            result |= FIELD_TYPE_INT32;
+        case FieldDescriptorProto::TYPE_FIXED64:
+            result |= FIELD_TYPE_FIXED64;
+        case FieldDescriptorProto::TYPE_FIXED32:
+            result |= FIELD_TYPE_FIXED32;
+        case FieldDescriptorProto::TYPE_BOOL:
+            result |= FIELD_TYPE_BOOL;
+        case FieldDescriptorProto::TYPE_STRING:
+            result |= FIELD_TYPE_STRING;
+        case FieldDescriptorProto::TYPE_MESSAGE:
+            result |= FIELD_TYPE_OBJECT;
+        case FieldDescriptorProto::TYPE_BYTES:
+            result |= FIELD_TYPE_BYTES;
+        case FieldDescriptorProto::TYPE_UINT32:
+            result |= FIELD_TYPE_UINT32;
+        case FieldDescriptorProto::TYPE_ENUM:
+            result |= FIELD_TYPE_ENUM;
+        case FieldDescriptorProto::TYPE_SFIXED32:
+            result |= FIELD_TYPE_SFIXED32;
+        case FieldDescriptorProto::TYPE_SFIXED64:
+            result |= FIELD_TYPE_SFIXED64;
+        case FieldDescriptorProto::TYPE_SINT32:
+            result |= FIELD_TYPE_SINT32;
+        case FieldDescriptorProto::TYPE_SINT64:
+            result |= FIELD_TYPE_SINT64;
+        default:
+            ;
+    }
+
+    // Count
+    if (field.options().packed()) {
+        result |= FIELD_COUNT_PACKED;
+    } else if (field.label() == FieldDescriptorProto::LABEL_REPEATED) {
+        result |= FIELD_COUNT_REPEATED;
+    } else {
+        result |= FIELD_COUNT_SINGLE;
+    }
+
+    return result;
+}
+
+/**
+ * Write a field.
+ */
+static void
+write_field(stringstream& text, const FieldDescriptorProto& field, const string& indent)
+{
+    string optional_comment = field.label() == FieldDescriptorProto::LABEL_OPTIONAL
+            ? "optional " : "";
+    string repeated_comment = field.label() == FieldDescriptorProto::LABEL_REPEATED
+            ? "repeated " : "";
+    string proto_type = get_proto_type(field);
+    string packed_comment = field.options().packed()
+            ? " [packed=true]" : "";
+    text << indent << "// " << optional_comment << repeated_comment << proto_type << ' '
+            << field.name() << " = " << field.number() << packed_comment << ';' << endl;
+
+    text << indent << "public static final long " << make_constant_name(field.name()) << " = 0x";
+
+    ios::fmtflags fmt(text.flags());
+    text << setfill('0') << setw(16) << hex << get_field_id(field);
+    text.flags(fmt);
+
+    text << "L;" << endl;
+
+    text << endl;
+}
+
+/**
+ * Write a Message constants class.
+ */
+static void
+write_message(stringstream& text, const DescriptorProto& message, const string& indent)
+{
+    int N;
+    const string indented = indent_more(indent);
+
+    text << indent << "// message " << message.name() << endl;
+    text << indent << "public final class " << message.name() << " {" << endl;
+    text << endl;
+
+    // Enums
+    N = message.enum_type_size();
+    for (int i=0; i<N; i++) {
+        write_enum(text, message.enum_type(i), indented);
+    }
+
+    // Nested classes
+    N = message.nested_type_size();
+    for (int i=0; i<N; i++) {
+        write_message(text, message.nested_type(i), indented);
+    }
+
+    // Fields
+    N = message.field_size();
+    for (int i=0; i<N; i++) {
+        write_field(text, message.field(i), indented);
+    }
+
+    text << indent << "}" << endl;
+    text << endl;
+}
+
+/**
+ * Write the contents of a file.
+ */
+static void
+write_file(stringstream& text, const FileDescriptorProto& file_descriptor)
+{
+    string const package_name = make_java_package(file_descriptor);
+    string const outer_class_name = make_outer_class_name(file_descriptor);
+
+    text << "// Generated by protoc-gen-javastream. DO NOT MODIFY." << endl;
+    text << "// source: " << file_descriptor.name() << endl << endl;
+
+    if (package_name.size() > 0) {
+        if (package_name.size() > 0) {
+            text << "package " << package_name << ";" << endl;
+            text << endl;
+        }
+    }
+
+    // This bit of policy is android api rules specific: Raw proto classes
+    // must never be in the API, but they should all be available for testing.
+    text << "/** @hide */" << endl;
+    text << "@android.annotation.TestApi" << endl;
+
+    text << "public final class " << outer_class_name << " {" << endl;
+    text << endl;
+
+    int N;
+    const string indented = indent_more("");
+    
+    N = file_descriptor.enum_type_size();
+    for (int i=0; i<N; i++) {
+        write_enum(text, file_descriptor.enum_type(i), indented);
+    }
+
+    N = file_descriptor.message_type_size();
+    for (int i=0; i<N; i++) {
+        write_message(text, file_descriptor.message_type(i), indented);
+    }
+
+    text << "}" << endl;
+}
+
+/**
+ * Main.
+ */
+int
+main(int argc, char const*const* argv)
+{
+    (void)argc;
+    (void)argv;
+
+    GOOGLE_PROTOBUF_VERIFY_VERSION;
+
+    CodeGeneratorRequest request;
+    CodeGeneratorResponse response;
+
+    // Read the request
+    request.ParseFromIstream(&cin);
+
+    // Build the files we need.
+    const int N = request.proto_file_size();
+    for (int i=0; i<N; i++) {
+        const FileDescriptorProto& file_descriptor = request.proto_file(i);
+        if (should_generate_for_file(request, file_descriptor.name())) {
+            // Generate the text
+            stringstream text;
+            write_file(text, file_descriptor);
+
+            // Put the text in the response
+            CodeGeneratorResponse::File* file_response = response.add_file();
+            file_response->set_name(make_file_name(file_descriptor));
+            file_response->set_content(text.str());
+
+            cerr << "writing file: " << file_response->name() << endl;
+        }
+    }
+
+    // If we had errors, don't write the response. Print the errors and exit.
+    if (ERRORS.HasErrors()) {
+        ERRORS.Print();
+        return 1;
+    }
+
+    // If we didn't have errors, write the response and exit happily.
+    response.SerializeToOstream(&cout);
+    return 0;
+}
diff --git a/tools/streaming_proto/string_utils.cpp b/tools/streaming_proto/string_utils.cpp
new file mode 100644
index 0000000..cc738c4
--- /dev/null
+++ b/tools/streaming_proto/string_utils.cpp
@@ -0,0 +1,95 @@
+
+#include "string_utils.h"
+#include <iostream>
+
+namespace android {
+namespace javastream_proto {
+
+using namespace std;
+
+string
+to_camel_case(const string& str)
+{
+    string result;
+    const int N = str.size();
+    result.reserve(N);
+    bool capitalize_next = true;
+    for (int i=0; i<N; i++) {
+        char c = str[i];
+        if (c == '_') {
+            capitalize_next = true;
+        } else {
+            if (capitalize_next && c >= 'a' && c <= 'z') {
+                c = 'A' + c - 'a';
+                capitalize_next = false;
+            } else if (c >= 'A' && c <= 'Z') {
+                capitalize_next = false;
+            } else if (c >= '0' && c <= '9') {
+                capitalize_next = true;
+            } else {
+                // All other characters (e.g. non-latin) count as capital.
+                capitalize_next = false;
+            }
+            result += c;
+        }
+    }
+    return result;
+}
+
+string
+make_constant_name(const string& str)
+{
+    string result;
+    const int N = str.size();
+    bool underscore_next = false;
+    for (int i=0; i<N; i++) {
+        char c = str[i];
+        if (c >= 'A' && c <= 'Z') {
+            if (underscore_next) {
+                result += '_';
+                underscore_next = false;
+            }
+        } else if (c >= 'a' && c <= 'z') {
+            c = 'A' + c - 'a';
+            underscore_next = true;
+        } else if (c == '_') {
+            underscore_next = false;
+        }
+        result += c;
+    }
+    return result;
+}
+
+string
+file_base_name(const string& str)
+{
+    size_t start = str.rfind('/');
+    if (start == string::npos) {
+        start = 0;
+    } else {
+        start++;
+    }
+    size_t end = str.find('.', start);
+    if (end == string::npos) {
+        end = str.size();
+    }
+    return str.substr(start, end-start);
+}
+
+string
+replace_string(const string& str, const char replace, const char with)
+{
+    string result(str);
+    const int N = result.size();
+    for (int i=0; i<N; i++) {
+        if (result[i] == replace) {
+            result[i] = with;
+        }
+    }
+    return result;
+}
+
+} // namespace javastream_proto
+} // namespace android
+
+
diff --git a/tools/streaming_proto/string_utils.h b/tools/streaming_proto/string_utils.h
new file mode 100644
index 0000000..ffe83ca
--- /dev/null
+++ b/tools/streaming_proto/string_utils.h
@@ -0,0 +1,32 @@
+#include <string>
+
+namespace android {
+namespace javastream_proto {
+
+using namespace std;
+
+/**
+ * Capitalizes the string, removes underscores and makes the next letter
+ * capitalized, and makes the letter following numbers capitalized.
+ */
+string to_camel_case(const string& str);
+
+/**
+ * Capitalize and insert underscores for CamelCase.
+ */
+string make_constant_name(const string& str);
+
+/**
+ * Returns the part of a file name that isn't a path and isn't a type suffix.
+ */
+string file_base_name(const string& str);
+
+/**
+ * Replace all occurances of 'replace' with 'with'.
+ */
+string replace_string(const string& str, const char replace, const char with);
+
+
+} // namespace javastream_proto
+} // namespace android
+
diff --git a/tools/streaming_proto/test/imported.proto b/tools/streaming_proto/test/imported.proto
new file mode 100644
index 0000000..05c8f0c
--- /dev/null
+++ b/tools/streaming_proto/test/imported.proto
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+syntax = "proto2";
+
+package com.android.streaming_proto_test;
+
+/**
+ * Message that is used from the other file.
+ */
+message ImportedMessage {
+    optional int32 data = 1;
+};
diff --git a/tools/streaming_proto/test/src/com/android/streaming_proto_test/Main.java b/tools/streaming_proto/test/src/com/android/streaming_proto_test/Main.java
new file mode 100644
index 0000000..1246f53
--- /dev/null
+++ b/tools/streaming_proto/test/src/com/android/streaming_proto_test/Main.java
@@ -0,0 +1,7 @@
+package com.android.streaming_proto_test;
+
+public class Main {
+    public void main(String[] argv) {
+        System.out.println("hello world");
+    }
+}
diff --git a/tools/streaming_proto/test/test.proto b/tools/streaming_proto/test/test.proto
new file mode 100644
index 0000000..de80ed6
--- /dev/null
+++ b/tools/streaming_proto/test/test.proto
@@ -0,0 +1,124 @@
+/*
+ * Copyright (C) 2016 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.
+ */
+
+syntax = "proto2";
+
+import "frameworks/base/tools/streaming_proto/test/imported.proto";
+
+package com.android.streaming_proto_test;
+
+/**
+ * Enum that outside the scope of any classes.
+ */
+enum Outside {
+    OUTSIDE_0 = 0;
+    OUTSIDE_1 = 1;
+};
+
+message Sibling {
+    optional int32 int32_field = 1;
+}
+
+/**
+ * Message with all of the field types.
+ */
+message All {
+    /**
+     * Enum that is inside the scope of a class.
+     */
+    enum Inside {
+        option allow_alias = true;
+        INSIDE_0 = 0;
+        INSIDE_1 = 1;
+        INSIDE_1A = 1;
+    };
+
+    /**
+     * Message that is recursive.
+     */
+    message Nested {
+        optional int32 data = 10001;
+        optional Nested nested = 10002;
+    };
+
+    optional double double_field = 10;
+    repeated double double_field_repeated = 11;
+    repeated double double_field_packed = 12 [packed=true];
+
+    optional float float_field = 20;
+    repeated float float_field_repeated = 21;
+    repeated float float_field_packed = 22 [packed=true];
+
+    optional int32 int32_field = 30;
+    repeated int32 int32_field_repeated = 31;
+    repeated int32 int32_field_packed = 32 [packed=true];
+
+    optional int64 int64_field = 40;
+    repeated int64 int64_field_repeated = 41;
+    repeated int64 int64_field_packed = 42 [packed=true];
+
+    optional uint32 uint32_field = 50;
+    repeated uint32 uint32_field_repeated = 51;
+    repeated uint32 uint32_field_packed = 52 [packed=true];
+
+    optional uint64 uint64_field = 60;
+    repeated uint64 uint64_field_repeated = 61;
+    repeated uint64 uint64_field_packed = 62 [packed=true];
+
+    optional sint32 sint32_field = 70;
+    repeated sint32 sint32_field_repeated = 71;
+    repeated sint32 sint32_field_packed = 72 [packed=true];
+
+    optional sint64 sint64_field = 80;
+    repeated sint64 sint64_field_repeated = 81;
+    repeated sint64 sint64_field_packed = 82 [packed=true];
+
+    optional fixed32 fixed32_field = 90;
+    repeated fixed32 fixed32_field_repeated = 91;
+    repeated fixed32 fixed32_field_packed = 92 [packed=true];
+
+    optional fixed64 fixed64_field = 100;
+    repeated fixed64 fixed64_field_repeated = 101;
+    repeated fixed64 fixed64_field_packed = 102 [packed=true];
+
+    optional sfixed32 sfixed32_field = 110;
+    repeated sfixed32 sfixed32_field_repeated = 111;
+    repeated sfixed32 sfixed32_field_packed = 112 [packed=true];
+
+    optional sfixed64 sfixed64_field = 120;
+    repeated sfixed64 sfixed64_field_repeated = 121;
+    repeated sfixed64 sfixed64_field_packed = 122 [packed=true];
+
+    optional bool bool_field = 130;
+    repeated bool bool_field_repeated = 131;
+    repeated bool bool_field_packed = 132 [packed=true];
+
+    optional string string_field = 140;
+    repeated string string_field_repeated = 141;
+
+    optional bytes bytes_field = 150;
+    repeated bytes bytes_field_repeated = 151;
+
+    optional Outside outside_field = 160;
+    repeated Outside outside_field_repeated = 161;
+    repeated Outside outside_field_packed = 162 [packed=true];
+
+    optional Nested nested_field = 170;
+    repeated Nested nested_field_repeated = 171;
+
+    optional ImportedMessage imported_field = 180;
+    repeated ImportedMessage imported_field_repeated = 181;
+};