Merge "Fix OTA info persistence logic" into pi-dev
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index 2a67b75..6c3951d 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -9,3 +9,5 @@
                       services/usb/
 
 api_lint_hook = ${REPO_ROOT}/frameworks/base/tools/apilint/apilint_sha.sh ${PREUPLOAD_COMMIT}
+
+strings_lint_hook = ${REPO_ROOT}/frameworks/base/tools/stringslint/stringslint_sha.sh ${PREUPLOAD_COMMIT}
diff --git a/api/current.txt b/api/current.txt
index c5fd77c..2cc92b4 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -7289,6 +7289,7 @@
     method public final java.lang.String getType(android.net.Uri);
     method public final android.net.Uri insert(android.net.Uri, android.content.ContentValues);
     method public android.app.slice.Slice onBindSlice(android.net.Uri, java.util.List<android.app.slice.SliceSpec>);
+    method public android.app.PendingIntent onCreatePermissionRequest(android.net.Uri);
     method public java.util.Collection<android.net.Uri> onGetSliceDescendants(android.net.Uri);
     method public android.net.Uri onMapIntentToUri(android.content.Intent);
     method public void onSlicePinned(android.net.Uri);
@@ -15727,6 +15728,8 @@
     method public abstract void abortCaptures() throws android.hardware.camera2.CameraAccessException;
     method public abstract int capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
     method public abstract int captureBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
+    method public int captureBurstRequests(java.util.List<android.hardware.camera2.CaptureRequest>, java.util.concurrent.Executor, android.hardware.camera2.CameraCaptureSession.CaptureCallback) throws android.hardware.camera2.CameraAccessException;
+    method public int captureSingleRequest(android.hardware.camera2.CaptureRequest, java.util.concurrent.Executor, android.hardware.camera2.CameraCaptureSession.CaptureCallback) throws android.hardware.camera2.CameraAccessException;
     method public abstract void close();
     method public abstract void finalizeOutputConfigurations(java.util.List<android.hardware.camera2.params.OutputConfiguration>) throws android.hardware.camera2.CameraAccessException;
     method public abstract android.hardware.camera2.CameraDevice getDevice();
@@ -15734,7 +15737,9 @@
     method public abstract boolean isReprocessable();
     method public abstract void prepare(android.view.Surface) throws android.hardware.camera2.CameraAccessException;
     method public abstract int setRepeatingBurst(java.util.List<android.hardware.camera2.CaptureRequest>, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
+    method public int setRepeatingBurstRequests(java.util.List<android.hardware.camera2.CaptureRequest>, java.util.concurrent.Executor, android.hardware.camera2.CameraCaptureSession.CaptureCallback) throws android.hardware.camera2.CameraAccessException;
     method public abstract int setRepeatingRequest(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
+    method public int setSingleRepeatingRequest(android.hardware.camera2.CaptureRequest, java.util.concurrent.Executor, android.hardware.camera2.CameraCaptureSession.CaptureCallback) throws android.hardware.camera2.CameraAccessException;
     method public abstract void stopRepeating() throws android.hardware.camera2.CameraAccessException;
     method public void updateOutputConfiguration(android.hardware.camera2.params.OutputConfiguration) throws android.hardware.camera2.CameraAccessException;
   }
@@ -15902,8 +15907,11 @@
     method public android.hardware.camera2.CameraCharacteristics getCameraCharacteristics(java.lang.String) throws android.hardware.camera2.CameraAccessException;
     method public java.lang.String[] getCameraIdList() throws android.hardware.camera2.CameraAccessException;
     method public void openCamera(java.lang.String, android.hardware.camera2.CameraDevice.StateCallback, android.os.Handler) throws android.hardware.camera2.CameraAccessException;
+    method public void openCamera(java.lang.String, java.util.concurrent.Executor, android.hardware.camera2.CameraDevice.StateCallback) throws android.hardware.camera2.CameraAccessException;
     method public void registerAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback, android.os.Handler);
+    method public void registerAvailabilityCallback(java.util.concurrent.Executor, android.hardware.camera2.CameraManager.AvailabilityCallback);
     method public void registerTorchCallback(android.hardware.camera2.CameraManager.TorchCallback, android.os.Handler);
+    method public void registerTorchCallback(java.util.concurrent.Executor, android.hardware.camera2.CameraManager.TorchCallback);
     method public void setTorchMode(java.lang.String, boolean) throws android.hardware.camera2.CameraAccessException;
     method public void unregisterAvailabilityCallback(android.hardware.camera2.CameraManager.AvailabilityCallback);
     method public void unregisterTorchCallback(android.hardware.camera2.CameraManager.TorchCallback);
@@ -24472,29 +24480,6 @@
     field public static final int RATING_THUMB_UP_DOWN = 2; // 0x2
   }
 
-  public final class Rating2 {
-    method public static android.media.Rating2 fromBundle(android.content.Context, android.os.Bundle);
-    method public float getPercentRating();
-    method public int getRatingStyle();
-    method public float getStarRating();
-    method public boolean hasHeart();
-    method public boolean isRated();
-    method public boolean isThumbUp();
-    method public static android.media.Rating2 newHeartRating(android.content.Context, boolean);
-    method public static android.media.Rating2 newPercentageRating(android.content.Context, float);
-    method public static android.media.Rating2 newStarRating(android.content.Context, int, float);
-    method public static android.media.Rating2 newThumbRating(android.content.Context, boolean);
-    method public static android.media.Rating2 newUnratedRating(android.content.Context, int);
-    method public android.os.Bundle toBundle();
-    field public static final int RATING_3_STARS = 3; // 0x3
-    field public static final int RATING_4_STARS = 4; // 0x4
-    field public static final int RATING_5_STARS = 5; // 0x5
-    field public static final int RATING_HEART = 1; // 0x1
-    field public static final int RATING_NONE = 0; // 0x0
-    field public static final int RATING_PERCENTAGE = 6; // 0x6
-    field public static final int RATING_THUMB_UP_DOWN = 2; // 0x2
-  }
-
   public deprecated class RemoteControlClient {
     ctor public RemoteControlClient(android.app.PendingIntent);
     ctor public RemoteControlClient(android.app.PendingIntent, android.os.Looper);
@@ -27270,6 +27255,7 @@
     method public static long getMobileTxBytes();
     method public static long getMobileTxPackets();
     method public static int getThreadStatsTag();
+    method public static int getThreadStatsUid();
     method public static long getTotalRxBytes();
     method public static long getTotalRxPackets();
     method public static long getTotalTxBytes();
@@ -27289,7 +27275,7 @@
     method public static void incrementOperationCount(int);
     method public static void incrementOperationCount(int, int);
     method public static void setThreadStatsTag(int);
-    method public static void setThreadStatsUidSelf();
+    method public static void setThreadStatsUid(int);
     method public static void tagDatagramSocket(java.net.DatagramSocket) throws java.net.SocketException;
     method public static void tagFileDescriptor(java.io.FileDescriptor) throws java.io.IOException;
     method public static void tagSocket(java.net.Socket) throws java.net.SocketException;
@@ -32050,7 +32036,6 @@
     ctor public Build.VERSION();
     field public static final java.lang.String BASE_OS;
     field public static final java.lang.String CODENAME;
-    field public static final int FIRST_SDK_INT;
     field public static final java.lang.String INCREMENTAL;
     field public static final int MIN_SUPPORTED_TARGET_SDK_INT;
     field public static final int PREVIEW_SDK_INT;
@@ -33086,8 +33071,6 @@
   }
 
   public final class SystemClock {
-    method public static java.time.Clock currentNetworkTimeClock();
-    method public static long currentNetworkTimeMillis();
     method public static long currentThreadTimeMillis();
     method public static long elapsedRealtime();
     method public static long elapsedRealtimeNanos();
@@ -45063,18 +45046,6 @@
     field public static final deprecated boolean RELEASE = true;
   }
 
-  public class DataUnit extends java.lang.Enum {
-    method public long toBytes(long);
-    method public static android.util.DataUnit valueOf(java.lang.String);
-    method public static final android.util.DataUnit[] values();
-    enum_constant public static final android.util.DataUnit GIBIBYTES;
-    enum_constant public static final android.util.DataUnit GIGABYTES;
-    enum_constant public static final android.util.DataUnit KIBIBYTES;
-    enum_constant public static final android.util.DataUnit KILOBYTES;
-    enum_constant public static final android.util.DataUnit MEBIBYTES;
-    enum_constant public static final android.util.DataUnit MEGABYTES;
-  }
-
   public class DebugUtils {
     method public static boolean isObjectSelected(java.lang.Object);
   }
diff --git a/api/removed.txt b/api/removed.txt
index 1228fd1..64a9c3f 100644
--- a/api/removed.txt
+++ b/api/removed.txt
@@ -261,6 +261,10 @@
     method public static deprecated org.apache.http.conn.ssl.SSLSocketFactory getHttpSocketFactory(int, android.net.SSLSessionCache);
   }
 
+  public class TrafficStats {
+    method public static deprecated void setThreadStatsUidSelf();
+  }
+
 }
 
 package android.os {
diff --git a/api/test-current.txt b/api/test-current.txt
index e84d204..d323725 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -240,6 +240,7 @@
   public abstract class PackageManager {
     method public abstract java.lang.String getDefaultBrowserPackageNameAsUser(int);
     method public abstract int getInstallReason(java.lang.String, android.os.UserHandle);
+    method public abstract java.lang.String[] getNamesForUids(int[]);
     method public abstract java.lang.String getPermissionControllerPackageName();
     method public abstract boolean isPermissionReviewModeEnabled();
     field public static final java.lang.String FEATURE_ADOPTABLE_STORAGE = "android.software.adoptable_storage";
@@ -481,6 +482,7 @@
 package android.os {
 
   public static class Build.VERSION {
+    field public static final int FIRST_SDK_INT;
     field public static final int RESOURCES_SDK_INT;
   }
 
@@ -585,6 +587,7 @@
     field public static final java.lang.String HIDDEN_API_BLACKLIST_EXEMPTIONS = "hidden_api_blacklist_exemptions";
     field public static final java.lang.String LOCATION_GLOBAL_KILL_SWITCH = "location_global_kill_switch";
     field public static final java.lang.String LOW_POWER_MODE = "low_power";
+    field public static final java.lang.String LOW_POWER_MODE_STICKY = "low_power_sticky";
     field public static final java.lang.String USE_OPEN_WIFI_PACKAGE = "use_open_wifi_package";
   }
 
diff --git a/cmds/statsd/src/guardrail/StatsdStats.cpp b/cmds/statsd/src/guardrail/StatsdStats.cpp
index 7a55f60..ef637df 100644
--- a/cmds/statsd/src/guardrail/StatsdStats.cpp
+++ b/cmds/statsd/src/guardrail/StatsdStats.cpp
@@ -92,6 +92,10 @@
 const int FIELD_ID_UID_MAP_DROPPED_SNAPSHOTS = 4;
 const int FIELD_ID_UID_MAP_DROPPED_CHANGES = 5;
 
+const std::map<int, std::pair<size_t, size_t>> StatsdStats::kAtomDimensionKeySizeLimitMap = {
+        {android::util::CPU_TIME_PER_UID_FREQ, {6000, 10000}},
+};
+
 // TODO: add stats for pulled atoms.
 StatsdStats::StatsdStats() {
     mPushedAtomStats.resize(android::util::kMaxPushedAtomId + 1);
diff --git a/cmds/statsd/src/guardrail/StatsdStats.h b/cmds/statsd/src/guardrail/StatsdStats.h
index a4f64dd..7675888 100644
--- a/cmds/statsd/src/guardrail/StatsdStats.h
+++ b/cmds/statsd/src/guardrail/StatsdStats.h
@@ -81,6 +81,9 @@
     const static int kDimensionKeySizeSoftLimit = 300;
     const static int kDimensionKeySizeHardLimit = 500;
 
+    // Per atom dimension key size limit
+    static const std::map<int, std::pair<size_t, size_t>> kAtomDimensionKeySizeLimitMap;
+
     const static int kMaxConfigCount = 10;
     const static int kMaxAlertCountPerConfig = 100;
     const static int kMaxConditionCountPerConfig = 200;
diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
index 49034ac..f08d54a 100644
--- a/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/GaugeMetricProducer.cpp
@@ -17,9 +17,9 @@
 #define DEBUG false  // STOPSHIP if true
 #include "Log.h"
 
+#include "../guardrail/StatsdStats.h"
 #include "GaugeMetricProducer.h"
-#include "guardrail/StatsdStats.h"
-#include "stats_log_util.h"
+#include "../stats_log_util.h"
 
 #include <cutils/log.h>
 
@@ -60,12 +60,20 @@
 
 GaugeMetricProducer::GaugeMetricProducer(const ConfigKey& key, const GaugeMetric& metric,
                                          const int conditionIndex,
-                                         const sp<ConditionWizard>& wizard,
-                                         const int pullTagId, const uint64_t startTimeNs,
+                                         const sp<ConditionWizard>& wizard, const int pullTagId,
+                                         const uint64_t startTimeNs,
                                          shared_ptr<StatsPullerManager> statsPullerManager)
     : MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard),
       mStatsPullerManager(statsPullerManager),
-      mPullTagId(pullTagId) {
+      mPullTagId(pullTagId),
+      mDimensionSoftLimit(StatsdStats::kAtomDimensionKeySizeLimitMap.find(pullTagId) !=
+                                          StatsdStats::kAtomDimensionKeySizeLimitMap.end()
+                                  ? StatsdStats::kAtomDimensionKeySizeLimitMap.at(pullTagId).first
+                                  : StatsdStats::kDimensionKeySizeSoftLimit),
+      mDimensionHardLimit(StatsdStats::kAtomDimensionKeySizeLimitMap.find(pullTagId) !=
+                                          StatsdStats::kAtomDimensionKeySizeLimitMap.end()
+                                  ? StatsdStats::kAtomDimensionKeySizeLimitMap.at(pullTagId).second
+                                  : StatsdStats::kDimensionKeySizeHardLimit) {
     mCurrentSlicedBucket = std::make_shared<DimToGaugeAtomsMap>();
     mCurrentSlicedBucketForAnomaly = std::make_shared<DimToValMap>();
     int64_t bucketSizeMills = 0;
@@ -305,11 +313,11 @@
         return false;
     }
     // 1. Report the tuple count if the tuple count > soft limit
-    if (mCurrentSlicedBucket->size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
+    if (mCurrentSlicedBucket->size() > mDimensionSoftLimit - 1) {
         size_t newTupleCount = mCurrentSlicedBucket->size() + 1;
         StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mMetricId, newTupleCount);
         // 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
-        if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
+        if (newTupleCount > mDimensionHardLimit) {
             ALOGE("GaugeMetric %lld dropping data for dimension key %s",
                 (long long)mMetricId, newKey.toString().c_str());
             return true;
diff --git a/cmds/statsd/src/metrics/GaugeMetricProducer.h b/cmds/statsd/src/metrics/GaugeMetricProducer.h
index dd6aff4..4b543f8 100644
--- a/cmds/statsd/src/metrics/GaugeMetricProducer.h
+++ b/cmds/statsd/src/metrics/GaugeMetricProducer.h
@@ -150,6 +150,10 @@
 
     static const size_t kBucketSize = sizeof(GaugeBucket{});
 
+    const size_t mDimensionSoftLimit;
+
+    const size_t mDimensionHardLimit;
+
     FRIEND_TEST(GaugeMetricProducerTest, TestWithCondition);
     FRIEND_TEST(GaugeMetricProducerTest, TestNoCondition);
     FRIEND_TEST(GaugeMetricProducerTest, TestPushedEventsWithUpgrade);
diff --git a/cmds/statsd/src/metrics/ValueMetricProducer.cpp b/cmds/statsd/src/metrics/ValueMetricProducer.cpp
index 767260d..ed4d7e4 100644
--- a/cmds/statsd/src/metrics/ValueMetricProducer.cpp
+++ b/cmds/statsd/src/metrics/ValueMetricProducer.cpp
@@ -18,8 +18,8 @@
 #include "Log.h"
 
 #include "ValueMetricProducer.h"
-#include "guardrail/StatsdStats.h"
-#include "stats_log_util.h"
+#include "../guardrail/StatsdStats.h"
+#include "../stats_log_util.h"
 
 #include <cutils/log.h>
 #include <limits.h>
@@ -68,7 +68,15 @@
     : MetricProducer(metric.id(), key, startTimeNs, conditionIndex, wizard),
       mValueField(metric.value_field()),
       mStatsPullerManager(statsPullerManager),
-      mPullTagId(pullTagId) {
+      mPullTagId(pullTagId),
+      mDimensionSoftLimit(StatsdStats::kAtomDimensionKeySizeLimitMap.find(pullTagId) !=
+                                          StatsdStats::kAtomDimensionKeySizeLimitMap.end()
+                                  ? StatsdStats::kAtomDimensionKeySizeLimitMap.at(pullTagId).first
+                                  : StatsdStats::kDimensionKeySizeSoftLimit),
+      mDimensionHardLimit(StatsdStats::kAtomDimensionKeySizeLimitMap.find(pullTagId) !=
+                                          StatsdStats::kAtomDimensionKeySizeLimitMap.end()
+                                  ? StatsdStats::kAtomDimensionKeySizeLimitMap.at(pullTagId).second
+                                  : StatsdStats::kDimensionKeySizeHardLimit) {
     // TODO: valuemetric for pushed events may need unlimited bucket length
     int64_t bucketSizeMills = 0;
     if (metric.has_bucket()) {
@@ -266,11 +274,11 @@
     if (mCurrentSlicedBucket.find(newKey) != mCurrentSlicedBucket.end()) {
         return false;
     }
-    if (mCurrentSlicedBucket.size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
+    if (mCurrentSlicedBucket.size() > mDimensionSoftLimit - 1) {
         size_t newTupleCount = mCurrentSlicedBucket.size() + 1;
         StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mMetricId, newTupleCount);
         // 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
-        if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
+        if (newTupleCount > mDimensionHardLimit) {
             ALOGE("ValueMetric %lld dropping data for dimension key %s",
                 (long long)mMetricId, newKey.toString().c_str());
             return true;
diff --git a/cmds/statsd/src/metrics/ValueMetricProducer.h b/cmds/statsd/src/metrics/ValueMetricProducer.h
index be57183..c4477b3 100644
--- a/cmds/statsd/src/metrics/ValueMetricProducer.h
+++ b/cmds/statsd/src/metrics/ValueMetricProducer.h
@@ -149,6 +149,10 @@
 
     static const size_t kBucketSize = sizeof(ValueBucket{});
 
+    const size_t mDimensionSoftLimit;
+
+    const size_t mDimensionHardLimit;
+
     FRIEND_TEST(ValueMetricProducerTest, TestNonDimensionalEvents);
     FRIEND_TEST(ValueMetricProducerTest, TestEventsWithNonSlicedCondition);
     FRIEND_TEST(ValueMetricProducerTest, TestPushedEventsWithUpgrade);
diff --git a/cmds/statsd/src/packages/UidMap.cpp b/cmds/statsd/src/packages/UidMap.cpp
index 1cb20bc..8c8152d 100644
--- a/cmds/statsd/src/packages/UidMap.cpp
+++ b/cmds/statsd/src/packages/UidMap.cpp
@@ -116,32 +116,16 @@
         lock_guard<mutex> lock(mMutex);  // Exclusively lock for updates.
 
         mMap.clear();
-        ProtoOutputStream proto;
-        uint64_t token = proto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED |
-                                      FIELD_ID_SNAPSHOT_PACKAGE_INFO);
+        vector<const SnapshotPackageInfo> infos;
         for (size_t j = 0; j < uid.size(); j++) {
             string package = string(String8(packageName[j]).string());
             mMap.insert(make_pair(uid[j], AppData(package, versionCode[j])));
-            proto.write(FIELD_TYPE_STRING | FIELD_ID_SNAPSHOT_PACKAGE_NAME, package);
-            proto.write(FIELD_TYPE_INT32 | FIELD_ID_SNAPSHOT_PACKAGE_VERSION, (int)versionCode[j]);
-            proto.write(FIELD_TYPE_INT32 | FIELD_ID_SNAPSHOT_PACKAGE_UID, (int)uid[j]);
+            infos.emplace_back(package, versionCode[j], uid[j]);
         }
-        proto.end(token);
 
-        // Copy ProtoOutputStream output to
-        auto iter = proto.data();
-        size_t pos = 0;
-        vector<char> outData(proto.size());
-        while (iter.readBuffer() != NULL) {
-            size_t toRead = iter.currentToRead();
-            std::memcpy(&(outData[pos]), iter.readBuffer(), toRead);
-            pos += toRead;
-            iter.rp()->move(toRead);
-        }
-        SnapshotRecord record(timestamp, outData);
-        mSnapshots.push_back(record);
+        mSnapshots.emplace_back(timestamp, infos);
 
-        mBytesUsed += proto.size() + kBytesTimestampField;
+        mBytesUsed += mSnapshots.back().bytes;
         ensureBytesUsedBelowLimit();
         StatsdStats::getInstance().setCurrentUidMapMemory(mBytesUsed);
         StatsdStats::getInstance().setUidMapSnapshots(mSnapshots.size());
@@ -212,7 +196,7 @@
     while (mBytesUsed > limit) {
         ALOGI("Bytes used %zu is above limit %zu, need to delete something", mBytesUsed, limit);
         if (mSnapshots.size() > 0) {
-            mBytesUsed -= mSnapshots.front().bytes.size() + kBytesTimestampField;
+            mBytesUsed -= mSnapshots.front().bytes;
             mSnapshots.pop_front();
             StatsdStats::getInstance().noteUidMapDropped(1, 0);
         } else if (mChanges.size() > 0) {
@@ -365,8 +349,14 @@
             count++;
             proto->write(FIELD_TYPE_INT64 | FIELD_ID_SNAPSHOT_TIMESTAMP,
                          (long long)record.timestampNs);
-            proto->write(FIELD_TYPE_MESSAGE | FIELD_ID_SNAPSHOT_PACKAGE_INFO, record.bytes.data(),
-                         record.bytes.size());
+            for (const SnapshotPackageInfo& info : record.infos) {
+                uint64_t token = proto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED |
+                                              FIELD_ID_SNAPSHOT_PACKAGE_INFO);
+                proto->write(FIELD_TYPE_STRING | FIELD_ID_SNAPSHOT_PACKAGE_NAME, info.package);
+                proto->write(FIELD_TYPE_INT32 | FIELD_ID_SNAPSHOT_PACKAGE_VERSION, info.version);
+                proto->write(FIELD_TYPE_INT32 | FIELD_ID_SNAPSHOT_PACKAGE_UID, info.uid);
+                proto->end(token);
+            }
             proto->end(snapshotsToken);
         }
     }
@@ -380,7 +370,7 @@
         int64_t cutoff_nanos = newMin;
         for (auto it_snapshots = mSnapshots.begin(); it_snapshots != mSnapshots.end();) {
             if (it_snapshots->timestampNs < cutoff_nanos) {
-                mBytesUsed -= it_snapshots->bytes.size() + kBytesTimestampField;
+                mBytesUsed -= it_snapshots->bytes;
                 it_snapshots = mSnapshots.erase(it_snapshots);
             } else {
                 ++it_snapshots;
@@ -399,31 +389,13 @@
             // Produce another snapshot. This results in extra data being uploaded but
             // helps ensure we can re-construct the UID->app name, versionCode mapping
             // in server.
-            ProtoOutputStream snapshotProto;
-            uint64_t token = snapshotProto.start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED |
-                                                 FIELD_ID_SNAPSHOT_PACKAGE_INFO);
+            vector<const SnapshotPackageInfo> infos;
             for (const auto& it : mMap) {
-                snapshotProto.write(FIELD_TYPE_STRING | FIELD_ID_SNAPSHOT_PACKAGE_NAME,
-                                    it.second.packageName);
-                snapshotProto.write(FIELD_TYPE_INT32 | FIELD_ID_SNAPSHOT_PACKAGE_VERSION,
-                                    (int)it.second.versionCode);
-                snapshotProto.write(FIELD_TYPE_INT32 | FIELD_ID_SNAPSHOT_PACKAGE_UID,
-                                    (int)it.first);
+                infos.emplace_back(it.second.packageName, it.second.versionCode, it.first);
             }
-            snapshotProto.end(token);
 
-            // Copy ProtoOutputStream output to
-            auto iter = snapshotProto.data();
-            vector<char> snapshotData(snapshotProto.size());
-            size_t pos = 0;
-            while (iter.readBuffer() != NULL) {
-                size_t toRead = iter.currentToRead();
-                std::memcpy(&(snapshotData[pos]), iter.readBuffer(), toRead);
-                pos += toRead;
-                iter.rp()->move(toRead);
-            }
-            mSnapshots.emplace_back(timestamp, snapshotData);
-            mBytesUsed += kBytesTimestampField + snapshotData.size();
+            mSnapshots.emplace_back(timestamp, infos);
+            mBytesUsed += mSnapshots.back().bytes;
         }
     }
     StatsdStats::getInstance().setCurrentUidMapMemory(mBytesUsed);
diff --git a/cmds/statsd/src/packages/UidMap.h b/cmds/statsd/src/packages/UidMap.h
index 9dc73f4..a3632d2 100644
--- a/cmds/statsd/src/packages/UidMap.h
+++ b/cmds/statsd/src/packages/UidMap.h
@@ -74,17 +74,35 @@
 // less because of varint encoding).
 const unsigned int kBytesTimestampField = 10;
 
+struct SnapshotPackageInfo {
+    const string package;
+    const int32_t version;
+    const int32_t uid;
+    SnapshotPackageInfo(const string& package, const int32_t version, const int32_t uid)
+        : package(package), version(version), uid(uid) {
+    }
+};
+
+const unsigned int kBytesSnapshotInfo = sizeof(struct SnapshotPackageInfo);
+
 // When calling appendUidMap, we retrieve all the snapshots since the last
 // timestamp we called appendUidMap for this configuration key.
 struct SnapshotRecord {
     const int64_t timestampNs;
 
-    // For performance reasons, we convert the package_info field (which is a
-    // repeated field of PackageInfo messages).
-    vector<char> bytes;
+    // All the package info known.
+    vector<const SnapshotPackageInfo> infos;
 
-    SnapshotRecord(const int64_t timestampNs, vector<char> bytes)
-        : timestampNs(timestampNs), bytes(bytes) {
+    // Tracks the number of bytes this snapshot consumes.
+    uint32_t bytes;
+
+    SnapshotRecord(const int64_t timestampNs, vector<const SnapshotPackageInfo>& infos)
+        : timestampNs(timestampNs), infos(infos) {
+        bytes = 0;
+        for (auto info : infos) {
+            bytes += info.package.size() + kBytesSnapshotInfo;
+        }
+        bytes += kBytesTimestampField;
     }
 };
 
@@ -210,6 +228,7 @@
 
     // Allows unit-test to access private methods.
     FRIEND_TEST(UidMapTest, TestClearingOutput);
+    FRIEND_TEST(UidMapTest, TestOutputIncludesAtLeastOneSnapshot);
     FRIEND_TEST(UidMapTest, TestMemoryComputed);
     FRIEND_TEST(UidMapTest, TestMemoryGuardrail);
 };
diff --git a/cmds/statsd/tests/StatsLogProcessor_test.cpp b/cmds/statsd/tests/StatsLogProcessor_test.cpp
index efed42e..4b9a87d 100644
--- a/cmds/statsd/tests/StatsLogProcessor_test.cpp
+++ b/cmds/statsd/tests/StatsLogProcessor_test.cpp
@@ -14,6 +14,7 @@
 
 #include "StatsLogProcessor.h"
 #include "config/ConfigKey.h"
+#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
 #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
 #include "guardrail/StatsdStats.h"
 #include "logd/LogEvent.h"
@@ -122,6 +123,32 @@
     EXPECT_EQ(0, broadcastCount);
 }
 
+TEST(StatsLogProcessorTest, TestUidMapHasSnapshot) {
+    // Setup simple config key corresponding to empty config.
+    sp<UidMap> m = new UidMap();
+    m->updateMap({1, 2}, {1, 2}, {String16("p1"), String16("p2")});
+    sp<AlarmMonitor> anomalyAlarmMonitor;
+    sp<AlarmMonitor> subscriberAlarmMonitor;
+    int broadcastCount = 0;
+    StatsLogProcessor p(m, anomalyAlarmMonitor, subscriberAlarmMonitor, 0,
+                        [&broadcastCount](const ConfigKey& key) { broadcastCount++; });
+    ConfigKey key(3, 4);
+    StatsdConfig config;
+    config.add_allowed_log_source("AID_ROOT");
+    p.OnConfigUpdated(key, config);
+
+    // Expect to get no metrics, but snapshot specified above in uidmap.
+    vector<uint8_t> bytes;
+    p.onDumpReport(key, 1, &bytes);
+
+    ConfigMetricsReportList output;
+    output.ParseFromArray(bytes.data(), bytes.size());
+    EXPECT_TRUE(output.reports_size() > 0);
+    auto uidmap = output.reports(0).uid_map();
+    EXPECT_TRUE(uidmap.snapshots_size() > 0);
+    EXPECT_EQ(2, uidmap.snapshots(0).package_info_size());
+}
+
 #else
 GTEST_LOG_(INFO) << "This test does nothing.\n";
 #endif
diff --git a/cmds/statsd/tests/UidMap_test.cpp b/cmds/statsd/tests/UidMap_test.cpp
index c9492eb..a9b67e0 100644
--- a/cmds/statsd/tests/UidMap_test.cpp
+++ b/cmds/statsd/tests/UidMap_test.cpp
@@ -173,6 +173,33 @@
     results->ParseFromArray(bytes.data(), bytes.size());
 }
 
+// Test that uid map returns at least one snapshot even if we already obtained
+// this snapshot from a previous call to getData.
+TEST(UidMapTest, TestOutputIncludesAtLeastOneSnapshot) {
+    UidMap m;
+    // Initialize single config key.
+    ConfigKey config1(1, StringToId("config1"));
+    m.OnConfigUpdated(config1);
+    vector<int32_t> uids;
+    vector<int64_t> versions;
+    vector<String16> apps;
+    uids.push_back(1000);
+    apps.push_back(String16(kApp2.c_str()));
+    versions.push_back(5);
+    m.updateMap(1, uids, versions, apps);
+
+    // Set the last timestamp for this config key to be newer.
+    m.mLastUpdatePerConfigKey[config1] = 2;
+
+    ProtoOutputStream proto;
+    m.appendUidMap(3, config1, &proto);
+
+    // Check there's still a uidmap attached this one.
+    UidMapping results;
+    protoOutputStreamToUidMapping(&proto, &results);
+    EXPECT_EQ(1, results.snapshots_size());
+}
+
 TEST(UidMapTest, TestClearingOutput) {
     UidMap m;
 
@@ -199,7 +226,7 @@
     protoOutputStreamToUidMapping(&proto, &results);
     EXPECT_EQ(1, results.snapshots_size());
 
-    // It should be cleared now
+    // We have to keep at least one snapshot in memory at all times.
     EXPECT_EQ(1U, m.mSnapshots.size());
     proto.clear();
     m.appendUidMap(2, config1, &proto);
diff --git a/config/hiddenapi-light-greylist.txt b/config/hiddenapi-light-greylist.txt
index db6d945..8a9c738 100644
--- a/config/hiddenapi-light-greylist.txt
+++ b/config/hiddenapi-light-greylist.txt
@@ -167,10 +167,13 @@
 Landroid/app/ApplicationPackageManager;->mPM:Landroid/content/pm/IPackageManager;
 Landroid/app/AppOpsManager;->checkOp(IILjava/lang/String;)I
 Landroid/app/AppOpsManager;->checkOpNoThrow(IILjava/lang/String;)I
+Landroid/app/AppOpsManager;->getOpsForPackage(ILjava/lang/String;[I)Ljava/util/List;
 Landroid/app/AppOpsManager;->mService:Lcom/android/internal/app/IAppOpsService;
 Landroid/app/AppOpsManager;->noteOp(I)I
 Landroid/app/AppOpsManager;->noteOp(IILjava/lang/String;)I
 Landroid/app/AppOpsManager;->OP_COARSE_LOCATION:I
+Landroid/app/AppOpsManager$OpEntry;->getDuration()I
+Landroid/app/AppOpsManager$OpEntry;->getRejectTime()J
 Landroid/app/AppOpsManager;->OP_FINE_LOCATION:I
 Landroid/app/AppOpsManager;->OP_GET_USAGE_STATS:I
 Landroid/app/AppOpsManager;->OP_POST_NOTIFICATION:I
@@ -327,6 +330,8 @@
 Landroid/app/TaskStackListener;-><init>()V
 Landroid/app/TimePickerDialog;->mTimePicker:Landroid/widget/TimePicker;
 Landroid/app/trust/ITrustManager$Stub$Proxy;-><init>(Landroid/os/IBinder;)V
+Landroid/app/usage/StorageStatsManager;->getFreeBytes(Ljava/lang/String;)J
+Landroid/app/usage/StorageStatsManager;->getTotalBytes(Ljava/lang/String;)J
 Landroid/app/usage/UsageStatsManager;->mService:Landroid/app/usage/IUsageStatsManager;
 Landroid/app/usage/UsageStats;->mLastEvent:I
 Landroid/app/usage/UsageStats;->mTotalTimeInForeground:J
@@ -357,6 +362,7 @@
 Landroid/bluetooth/BluetoothAdapter;->setScanMode(II)Z
 Landroid/bluetooth/BluetoothAdapter;->setScanMode(I)Z
 Landroid/bluetooth/BluetoothDevice;->createBond(I)Z
+Landroid/bluetooth/BluetoothDevice;->getAlias()Ljava/lang/String;
 Landroid/bluetooth/BluetoothDevice;->getAliasName()Ljava/lang/String;
 Landroid/bluetooth/BluetoothGattCharacteristic;->mInstance:I
 Landroid/bluetooth/BluetoothGattCharacteristic;->mService:Landroid/bluetooth/BluetoothGattService;
@@ -614,6 +620,7 @@
 Landroid/graphics/drawable/BitmapDrawable;->getOpticalInsets()Landroid/graphics/Insets;
 Landroid/graphics/drawable/BitmapDrawable;->getTint()Landroid/content/res/ColorStateList;
 Landroid/graphics/drawable/BitmapDrawable;->getTintMode()Landroid/graphics/PorterDuff$Mode;
+Landroid/graphics/drawable/BitmapDrawable;->mTargetDensity:I
 Landroid/graphics/drawable/BitmapDrawable;->setBitmap(Landroid/graphics/Bitmap;)V
 Landroid/graphics/drawable/DrawableContainer$DrawableContainerState;->mConstantPadding:Landroid/graphics/Rect;
 Landroid/graphics/drawable/DrawableContainer;->getOpticalInsets()Landroid/graphics/Insets;
@@ -677,6 +684,7 @@
 Landroid/graphics/NinePatch$InsetStruct;-><init>(IIIIIIIIFIF)V
 Landroid/graphics/NinePatch;->mBitmap:Landroid/graphics/Bitmap;
 Landroid/graphics/Picture;->mNativePicture:J
+Landroid/graphics/PixelXorXfermode;-><init>(I)V
 Landroid/graphics/PorterDuffColorFilter;->setColor(I)V
 Landroid/graphics/PorterDuffColorFilter;->setMode(Landroid/graphics/PorterDuff$Mode;)V
 Landroid/graphics/Region;-><init>(JI)V
@@ -972,6 +980,7 @@
 Landroid/media/JetPlayer;->mNativePlayerInJavaObj:J
 Landroid/media/JetPlayer;->postEventFromNative(Ljava/lang/Object;III)V
 Landroid/media/MediaCodec$CodecException;-><init>(IILjava/lang/String;)V
+Landroid/media/MediaCodec;->getBuffers(Z)[Ljava/nio/ByteBuffer;
 Landroid/media/MediaCodec;->releaseOutputBuffer(IZZJ)V
 Landroid/media/MediaFile;->FIRST_AUDIO_FILE_TYPE:I
 Landroid/media/MediaFile;->getFileType(Ljava/lang/String;)Landroid/media/MediaFile$MediaFileType;
@@ -1348,6 +1357,7 @@
 Landroid/os/storage/VolumeInfo;->getPath()Ljava/io/File;
 Landroid/os/storage/VolumeInfo;->getState()I
 Landroid/os/storage/VolumeInfo;->getType()I
+Landroid/os/storage/VolumeInfo;->isMountedReadable()Z
 Landroid/os/storage/VolumeInfo;->isPrimary()Z
 Landroid/os/storage/VolumeInfo;->isVisible()Z
 Landroid/os/StrictMode;->disableDeathOnFileUriExposure()V
@@ -1899,10 +1909,10 @@
 Landroid/text/DynamicLayout;-><init>(Ljava/lang/CharSequence;Ljava/lang/CharSequence;Landroid/text/TextPaint;ILandroid/text/Layout$Alignment;Landroid/text/TextDirectionHeuristic;FFZIIILandroid/text/TextUtils$TruncateAt;I)V
 Landroid/text/DynamicLayout;->sStaticLayout:Landroid/text/StaticLayout;
 Landroid/text/Html;->withinStyle(Ljava/lang/StringBuilder;Ljava/lang/CharSequence;II)V
-Landroid/text/Layout;->DIRS_ALL_LEFT_TO_RIGHT:Landroid/text/Layout$Directions;
-Landroid/text/Layout;->getPrimaryHorizontal(IZ)F
 Landroid/text/Layout$Alignment;->ALIGN_LEFT:Landroid/text/Layout$Alignment;
 Landroid/text/Layout$Alignment;->ALIGN_RIGHT:Landroid/text/Layout$Alignment;
+Landroid/text/Layout;->DIRS_ALL_LEFT_TO_RIGHT:Landroid/text/Layout$Directions;
+Landroid/text/Layout;->getPrimaryHorizontal(IZ)F
 Landroid/text/method/LinkMovementMethod;->sInstance:Landroid/text/method/LinkMovementMethod;
 Landroid/text/SpannableStringBuilder;->mGapLength:I
 Landroid/text/SpannableStringBuilder;->mGapStart:I
@@ -1984,6 +1994,7 @@
 Landroid/util/Rational;->mNumerator:I
 Landroid/util/Rational;->readObject(Ljava/io/ObjectInputStream;)V
 Landroid/util/Singleton;->mInstance:Ljava/lang/Object;
+Landroid/util/Slog;->d(Ljava/lang/String;Ljava/lang/String;)I
 Landroid/util/SparseIntArray;->mKeys:[I
 Landroid/util/SparseIntArray;->mSize:I
 Landroid/util/SparseIntArray;->mValues:[I
diff --git a/core/java/android/app/slice/SliceManager.java b/core/java/android/app/slice/SliceManager.java
index 67a72ec..1afe53d 100644
--- a/core/java/android/app/slice/SliceManager.java
+++ b/core/java/android/app/slice/SliceManager.java
@@ -32,9 +32,11 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
+import android.os.Process;
 import android.os.RemoteException;
 import android.os.ServiceManager;
 import android.os.ServiceManager.ServiceNotFoundException;
+import android.os.UserHandle;
 import android.util.Log;
 
 import com.android.internal.util.Preconditions;
@@ -392,6 +394,9 @@
      */
     public void enforceSlicePermission(Uri uri, String pkg, int pid, int uid) {
         try {
+            if (UserHandle.isSameApp(uid, Process.myUid())) {
+                return;
+            }
             if (pkg == null) {
                 throw new SecurityException("No pkg specified");
             }
diff --git a/core/java/android/app/slice/SliceProvider.java b/core/java/android/app/slice/SliceProvider.java
index dd89293..bf856b7 100644
--- a/core/java/android/app/slice/SliceProvider.java
+++ b/core/java/android/app/slice/SliceProvider.java
@@ -37,7 +37,6 @@
 import android.os.Process;
 import android.os.StrictMode;
 import android.os.StrictMode.ThreadPolicy;
-import android.os.UserHandle;
 import android.util.Log;
 
 import java.util.ArrayList;
@@ -146,18 +145,6 @@
      * @hide
      */
     public static final String EXTRA_PROVIDER_PKG = "provider_pkg";
-    /**
-     * @hide
-     */
-    public static final String EXTRA_OVERRIDE_PKG = "override_pkg";
-    /**
-     * @hide
-     */
-    public static final String EXTRA_OVERRIDE_UID = "override_uid";
-    /**
-     * @hide
-     */
-    public static final String EXTRA_OVERRIDE_PID = "override_pid";
 
     private static final boolean DEBUG = false;
 
@@ -257,6 +244,23 @@
                 "This provider has not implemented intent to uri mapping");
     }
 
+    /**
+     * Called when an app requests a slice it does not have write permission
+     * to the uri for.
+     * <p>
+     * The return value will be the action on a slice that prompts the user that
+     * the calling app wants to show slices from this app. The default implementation
+     * launches a dialog that allows the user to grant access to this slice. Apps
+     * that do not want to allow this user grant, can override this and instead
+     * launch their own dialog with different behavior.
+     *
+     * @param sliceUri the Uri of the slice attempting to be bound.
+     * @see #getCallingPackage()
+     */
+    public @NonNull PendingIntent onCreatePermissionRequest(Uri sliceUri) {
+        return createPermissionIntent(getContext(), sliceUri, getCallingPackage());
+    }
+
     @Override
     public final int update(Uri uri, ContentValues values, String selection,
             String[] selectionArgs) {
@@ -312,17 +316,7 @@
             String callingPackage = getCallingPackage();
             int callingUid = Binder.getCallingUid();
             int callingPid = Binder.getCallingPid();
-            if (extras.containsKey(EXTRA_OVERRIDE_PKG)) {
-                if (Binder.getCallingUid() != Process.SYSTEM_UID) {
-                    throw new SecurityException("Only the system can override calling pkg");
-                }
-                // This is safe because we would grant SYSTEM_UID access to all slices
-                // and want to allow it to bind slices as if it were a less privileged app
-                // to check their permission levels.
-                callingPackage = extras.getString(EXTRA_OVERRIDE_PKG);
-                callingUid = extras.getInt(EXTRA_OVERRIDE_UID);
-                callingPid = extras.getInt(EXTRA_OVERRIDE_PID);
-            }
+
             Slice s = handleBindSlice(uri, supportedSpecs, callingPackage, callingUid, callingPid);
             Bundle b = new Bundle();
             b.putParcelable(EXTRA_SLICE, s);
@@ -406,13 +400,11 @@
         // SliceManager#bindSlice.
         String pkg = callingPkg != null ? callingPkg
                 : getContext().getPackageManager().getNameForUid(callingUid);
-        if (!UserHandle.isSameApp(callingUid, Process.myUid())) {
-            try {
-                mSliceManager.enforceSlicePermission(sliceUri, pkg,
-                        callingPid, callingUid);
-            } catch (SecurityException e) {
-                return createPermissionSlice(getContext(), sliceUri, pkg);
-            }
+        try {
+            mSliceManager.enforceSlicePermission(sliceUri, pkg,
+                    callingPid, callingUid);
+        } catch (SecurityException e) {
+            return createPermissionSlice(getContext(), sliceUri, pkg);
         }
         mCallback = "onBindSlice";
         Handler.getMain().postDelayed(mAnr, SLICE_BIND_ANR);
@@ -426,10 +418,18 @@
     /**
      * @hide
      */
-    public static Slice createPermissionSlice(Context context, Uri sliceUri,
+    public Slice createPermissionSlice(Context context, Uri sliceUri,
             String callingPackage) {
+        PendingIntent action;
+        mCallback = "onCreatePermissionRequest";
+        Handler.getMain().postDelayed(mAnr, SLICE_BIND_ANR);
+        try {
+            action = onCreatePermissionRequest(sliceUri);
+        } finally {
+            Handler.getMain().removeCallbacks(mAnr);
+        }
         return new Slice.Builder(sliceUri)
-                .addAction(createPermissionIntent(context, sliceUri, callingPackage),
+                .addAction(action,
                         new Slice.Builder(sliceUri.buildUpon().appendPath("permission").build())
                                 .addText(getPermissionString(context, callingPackage), null,
                                         Collections.emptyList())
diff --git a/core/java/android/bluetooth/BluetoothProfile.java b/core/java/android/bluetooth/BluetoothProfile.java
index 656188f..6aeb94d 100644
--- a/core/java/android/bluetooth/BluetoothProfile.java
+++ b/core/java/android/bluetooth/BluetoothProfile.java
@@ -38,7 +38,7 @@
      * This extra represents the current connection state of the profile of the
      * Bluetooth device.
      */
-    public static final String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
+    String EXTRA_STATE = "android.bluetooth.profile.extra.STATE";
 
     /**
      * Extra for the connection state intents of the individual profiles.
@@ -46,123 +46,130 @@
      * This extra represents the previous connection state of the profile of the
      * Bluetooth device.
      */
-    public static final String EXTRA_PREVIOUS_STATE =
+    String EXTRA_PREVIOUS_STATE =
             "android.bluetooth.profile.extra.PREVIOUS_STATE";
 
     /** The profile is in disconnected state */
-    public static final int STATE_DISCONNECTED = 0;
+    int STATE_DISCONNECTED = 0;
     /** The profile is in connecting state */
-    public static final int STATE_CONNECTING = 1;
+    int STATE_CONNECTING = 1;
     /** The profile is in connected state */
-    public static final int STATE_CONNECTED = 2;
+    int STATE_CONNECTED = 2;
     /** The profile is in disconnecting state */
-    public static final int STATE_DISCONNECTING = 3;
+    int STATE_DISCONNECTING = 3;
 
     /**
      * Headset and Handsfree profile
      */
-    public static final int HEADSET = 1;
+    int HEADSET = 1;
 
     /**
      * A2DP profile.
      */
-    public static final int A2DP = 2;
+    int A2DP = 2;
 
     /**
      * Health Profile
      */
-    public static final int HEALTH = 3;
+    int HEALTH = 3;
 
     /**
      * HID Host
      *
      * @hide
      */
-    public static final int HID_HOST = 4;
+    int HID_HOST = 4;
 
     /**
      * PAN Profile
      *
      * @hide
      */
-    public static final int PAN = 5;
+    int PAN = 5;
 
     /**
      * PBAP
      *
      * @hide
      */
-    public static final int PBAP = 6;
+    int PBAP = 6;
 
     /**
      * GATT
      */
-    public static final int GATT = 7;
+    int GATT = 7;
 
     /**
      * GATT_SERVER
      */
-    public static final int GATT_SERVER = 8;
+    int GATT_SERVER = 8;
 
     /**
      * MAP Profile
      *
      * @hide
      */
-    public static final int MAP = 9;
+    int MAP = 9;
 
     /*
      * SAP Profile
      * @hide
      */
-    public static final int SAP = 10;
+    int SAP = 10;
 
     /**
      * A2DP Sink Profile
      *
      * @hide
      */
-    public static final int A2DP_SINK = 11;
+    int A2DP_SINK = 11;
 
     /**
      * AVRCP Controller Profile
      *
      * @hide
      */
-    public static final int AVRCP_CONTROLLER = 12;
+    int AVRCP_CONTROLLER = 12;
+
+    /**
+     * AVRCP Target Profile
+     *
+     * @hide
+     */
+    int AVRCP = 13;
 
     /**
      * Headset Client - HFP HF Role
      *
      * @hide
      */
-    public static final int HEADSET_CLIENT = 16;
+    int HEADSET_CLIENT = 16;
 
     /**
      * PBAP Client
      *
      * @hide
      */
-    public static final int PBAP_CLIENT = 17;
+    int PBAP_CLIENT = 17;
 
     /**
      * MAP Messaging Client Equipment (MCE)
      *
      * @hide
      */
-    public static final int MAP_CLIENT = 18;
+    int MAP_CLIENT = 18;
 
     /**
      * HID Device
      */
-    public static final int HID_DEVICE = 19;
+    int HID_DEVICE = 19;
 
     /**
      * Object Push Profile (OPP)
      *
      * @hide
      */
-    public static final int OPP = 20;
+    int OPP = 20;
 
     /**
      * Hearing Aid Device
@@ -185,7 +192,7 @@
      *
      * @hide
      **/
-    public static final int PRIORITY_AUTO_CONNECT = 1000;
+    int PRIORITY_AUTO_CONNECT = 1000;
 
     /**
      * Default priority for devices that allow incoming
@@ -194,7 +201,7 @@
      * @hide
      **/
     @SystemApi
-    public static final int PRIORITY_ON = 100;
+    int PRIORITY_ON = 100;
 
     /**
      * Default priority for devices that does not allow incoming
@@ -203,14 +210,14 @@
      * @hide
      **/
     @SystemApi
-    public static final int PRIORITY_OFF = 0;
+    int PRIORITY_OFF = 0;
 
     /**
      * Default priority when not set or when the device is unpaired
      *
      * @hide
      */
-    public static final int PRIORITY_UNDEFINED = -1;
+    int PRIORITY_UNDEFINED = -1;
 
     /**
      * Get connected devices for this specific profile.
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index e1a00b1..920056a 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -621,7 +621,7 @@
      * @throws android.content.res.Resources.NotFoundException if the given ID
      *         does not exist.
      */
-    @NonNull
+    @Nullable
     public final Drawable getDrawable(@DrawableRes int id) {
         return getResources().getDrawable(id, getTheme());
     }
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 114c485..314eb98 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -3711,6 +3711,7 @@
      *
      * @hide
      */
+    @TestApi
     public abstract @Nullable String[] getNamesForUids(int[] uids);
 
     /**
diff --git a/core/java/android/content/res/Resources.java b/core/java/android/content/res/Resources.java
index d813382..c58cde0 100644
--- a/core/java/android/content/res/Resources.java
+++ b/core/java/android/content/res/Resources.java
@@ -847,6 +847,7 @@
      * @see #getDrawableForDensity(int, int, Theme)
      * @deprecated Use {@link #getDrawableForDensity(int, int, Theme)} instead.
      */
+    @Nullable
     @Deprecated
     public Drawable getDrawableForDensity(@DrawableRes int id, int density)
             throws NotFoundException {
@@ -864,12 +865,13 @@
      *            found in {@link DisplayMetrics}. A value of 0 means to use the
      *            density returned from {@link #getConfiguration()}.
      *            This is equivalent to calling {@link #getDrawable(int, Theme)}.
-     * @param theme The theme used to style the drawable attributes, may be {@code null}.
+     * @param theme The theme used to style the drawable attributes, may be {@code null} if the
+     *              drawable cannot be decoded.
      * @return Drawable An object that can be used to draw this resource.
      * @throws NotFoundException Throws NotFoundException if the given ID does
-     *             not exist, or cannot be decoded.
+     *             not exist.
      */
-    @NonNull
+    @Nullable
     public Drawable getDrawableForDensity(@DrawableRes int id, int density, @Nullable Theme theme) {
         final TypedValue value = obtainTempTypedValue();
         try {
diff --git a/core/java/android/content/res/ResourcesImpl.java b/core/java/android/content/res/ResourcesImpl.java
index 157910a..8c98067 100644
--- a/core/java/android/content/res/ResourcesImpl.java
+++ b/core/java/android/content/res/ResourcesImpl.java
@@ -544,7 +544,7 @@
         }
     }
 
-    @NonNull
+    @Nullable
     Drawable loadDrawable(@NonNull Resources wrapper, @NonNull TypedValue value, int id,
             int density, @Nullable Resources.Theme theme)
             throws NotFoundException {
@@ -757,6 +757,7 @@
      *
      * This call will handle closing ais.
      */
+    @Nullable
     private Drawable decodeImageDrawable(@NonNull AssetInputStream ais,
             @NonNull Resources wrapper, @NonNull TypedValue value) {
         ImageDecoder.Source src = new ImageDecoder.AssetInputStreamSource(ais,
@@ -774,8 +775,10 @@
 
     /**
      * Loads a drawable from XML or resources stream.
+     *
+     * @return Drawable, or null if Drawable cannot be decoded.
      */
-    @NonNull
+    @Nullable
     private Drawable loadDrawableForCookie(@NonNull Resources wrapper, @NonNull TypedValue value,
             int id, int density) {
         if (value.string == null) {
diff --git a/core/java/android/hardware/camera2/CameraCaptureSession.java b/core/java/android/hardware/camera2/CameraCaptureSession.java
index ff69bd8..eafe593 100644
--- a/core/java/android/hardware/camera2/CameraCaptureSession.java
+++ b/core/java/android/hardware/camera2/CameraCaptureSession.java
@@ -16,15 +16,16 @@
 
 package android.hardware.camera2;
 
+import android.annotation.CallbackExecutor;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.hardware.camera2.params.OutputConfiguration;
 import android.os.Handler;
 import android.view.Surface;
 
+import java.util.concurrent.Executor;
 import java.util.List;
 
-
 /**
  * A configured capture session for a {@link CameraDevice}, used for capturing images from the
  * camera or reprocessing images captured from the camera in the same session previously.
@@ -354,6 +355,50 @@
             throws CameraAccessException;
 
     /**
+     * <p>Submit a request for an image to be captured by the camera device.</p>
+     *
+     * <p>The behavior of this method matches that of
+     * {@link #capture(CaptureRequest, CaptureCallback, Handler)},
+     * except that it uses {@link java.util.concurrent.Executor} as an argument
+     * instead of {@link android.os.Handler}.</p>
+     *
+     * @param request the settings for this capture
+     * @param executor the executor which will be used for invoking the listener.
+     * @param listener The callback object to notify once this request has been
+     * processed.
+     *
+     * @return int A unique capture sequence ID used by
+     *             {@link CaptureCallback#onCaptureSequenceCompleted}.
+     *
+     * @throws CameraAccessException if the camera device is no longer connected or has
+     *                               encountered a fatal error
+     * @throws IllegalStateException if this session is no longer active, either because the session
+     *                               was explicitly closed, a new session has been created
+     *                               or the camera device has been closed.
+     * @throws IllegalArgumentException if the request targets no Surfaces or Surfaces that are not
+     *                                  configured as outputs for this session; or the request
+     *                                  targets a set of Surfaces that cannot be submitted
+     *                                  simultaneously in a reprocessable capture session; or a
+     *                                  reprocess capture request is submitted in a
+     *                                  non-reprocessable capture session; or the reprocess capture
+     *                                  request was created with a {@link TotalCaptureResult} from
+     *                                  a different session; or the capture targets a Surface in
+     *                                  the middle of being {@link #prepare prepared}; or the
+     *                                  executor is null, or the listener is not null.
+     *
+     * @see #captureBurst
+     * @see #setRepeatingRequest
+     * @see #setRepeatingBurst
+     * @see #abortCaptures
+     * @see CameraDevice#createReprocessableCaptureSession
+     */
+    public int captureSingleRequest(@NonNull CaptureRequest request,
+            @NonNull @CallbackExecutor Executor executor, @NonNull CaptureCallback listener)
+            throws CameraAccessException {
+        throw new UnsupportedOperationException("Subclasses must override this method");
+    }
+
+    /**
      * Submit a list of requests to be captured in sequence as a burst. The
      * burst will be captured in the minimum amount of time possible, and will
      * not be interleaved with requests submitted by other capture or repeat
@@ -416,6 +461,53 @@
             throws CameraAccessException;
 
     /**
+     * Submit a list of requests to be captured in sequence as a burst. The
+     * burst will be captured in the minimum amount of time possible, and will
+     * not be interleaved with requests submitted by other capture or repeat
+     * calls.
+     *
+     * <p>The behavior of this method matches that of
+     * {@link #captureBurst(List, CaptureCallback, Handler)},
+     * except that it uses {@link java.util.concurrent.Executor} as an argument
+     * instead of {@link android.os.Handler}.</p>
+     *
+     * @param requests the list of settings for this burst capture
+     * @param executor the executor which will be used for invoking the listener.
+     * @param listener The callback object to notify each time one of the
+     * requests in the burst has been processed.
+     *
+     * @return int A unique capture sequence ID used by
+     *             {@link CaptureCallback#onCaptureSequenceCompleted}.
+     *
+     * @throws CameraAccessException if the camera device is no longer connected or has
+     *                               encountered a fatal error
+     * @throws IllegalStateException if this session is no longer active, either because the session
+     *                               was explicitly closed, a new session has been created
+     *                               or the camera device has been closed.
+     * @throws IllegalArgumentException If the requests target no Surfaces, or the requests target
+     *                                  Surfaces not currently configured as outputs; or one of the
+     *                                  requests targets a set of Surfaces that cannot be submitted
+     *                                  simultaneously in a reprocessable capture session; or a
+     *                                  reprocess capture request is submitted in a
+     *                                  non-reprocessable capture session; or one of the reprocess
+     *                                  capture requests was created with a
+     *                                  {@link TotalCaptureResult} from a different session; or one
+     *                                  of the captures targets a Surface in the middle of being
+     *                                  {@link #prepare prepared}; or if the executor is null; or if
+     *                                  the listener is null.
+     *
+     * @see #capture
+     * @see #setRepeatingRequest
+     * @see #setRepeatingBurst
+     * @see #abortCaptures
+     */
+    public int captureBurstRequests(@NonNull List<CaptureRequest> requests,
+            @NonNull @CallbackExecutor Executor executor, @NonNull CaptureCallback listener)
+            throws CameraAccessException {
+        throw new UnsupportedOperationException("Subclasses must override this method");
+    }
+
+    /**
      * Request endlessly repeating capture of images by this capture session.
      *
      * <p>With this method, the camera device will continually capture images
@@ -483,6 +575,45 @@
             throws CameraAccessException;
 
     /**
+     * Request endlessly repeating capture of images by this capture session.
+     *
+     * <p>The behavior of this method matches that of
+     * {@link #setRepeatingRequest(CaptureRequest, CaptureCallback, Handler)},
+     * except that it uses {@link java.util.concurrent.Executor} as an argument
+     * instead of {@link android.os.Handler}.</p>
+     *
+     * @param request the request to repeat indefinitely
+     * @param executor the executor which will be used for invoking the listener.
+     * @param listener The callback object to notify every time the
+     * request finishes processing.
+     *
+     * @return int A unique capture sequence ID used by
+     *             {@link CaptureCallback#onCaptureSequenceCompleted}.
+     *
+     * @throws CameraAccessException if the camera device is no longer connected or has
+     *                               encountered a fatal error
+     * @throws IllegalStateException if this session is no longer active, either because the session
+     *                               was explicitly closed, a new session has been created
+     *                               or the camera device has been closed.
+     * @throws IllegalArgumentException If the request references no Surfaces or references Surfaces
+     *                                  that are not currently configured as outputs; or the request
+     *                                  is a reprocess capture request; or the capture targets a
+     *                                  Surface in the middle of being {@link #prepare prepared}; or
+     *                                  the executor is null; or the listener is null.
+     *
+     * @see #capture
+     * @see #captureBurst
+     * @see #setRepeatingBurst
+     * @see #stopRepeating
+     * @see #abortCaptures
+     */
+    public int setSingleRepeatingRequest(@NonNull CaptureRequest request,
+            @NonNull @CallbackExecutor Executor executor, @NonNull CaptureCallback listener)
+            throws CameraAccessException {
+        throw new UnsupportedOperationException("Subclasses must override this method");
+    }
+
+    /**
      * <p>Request endlessly repeating capture of a sequence of images by this
      * capture session.</p>
      *
@@ -555,6 +686,47 @@
             throws CameraAccessException;
 
     /**
+     * <p>Request endlessly repeating capture of a sequence of images by this
+     * capture session.</p>
+     *
+     * <p>The behavior of this method matches that of
+     * {@link #setRepeatingBurst(List, CaptureCallback, Handler)},
+     * except that it uses {@link java.util.concurrent.Executor} as an argument
+     * instead of {@link android.os.Handler}.</p>
+     *
+     * @param requests the list of requests to cycle through indefinitely
+     * @param executor the executor which will be used for invoking the listener.
+     * @param listener The callback object to notify each time one of the
+     * requests in the repeating bursts has finished processing.
+     *
+     * @return int A unique capture sequence ID used by
+     *             {@link CaptureCallback#onCaptureSequenceCompleted}.
+     *
+     * @throws CameraAccessException if the camera device is no longer connected or has
+     *                               encountered a fatal error
+     * @throws IllegalStateException if this session is no longer active, either because the session
+     *                               was explicitly closed, a new session has been created
+     *                               or the camera device has been closed.
+     * @throws IllegalArgumentException If the requests reference no Surfaces or reference Surfaces
+     *                                  not currently configured as outputs; or one of the requests
+     *                                  is a reprocess capture request; or one of the captures
+     *                                  targets a Surface in the middle of being
+     *                                  {@link #prepare prepared}; or the executor is null; or the
+     *                                  listener is null.
+     *
+     * @see #capture
+     * @see #captureBurst
+     * @see #setRepeatingRequest
+     * @see #stopRepeating
+     * @see #abortCaptures
+     */
+    public int setRepeatingBurstRequests(@NonNull List<CaptureRequest> requests,
+            @NonNull @CallbackExecutor Executor executor, @NonNull CaptureCallback listener)
+            throws CameraAccessException {
+        throw new UnsupportedOperationException("Subclasses must override this method");
+    }
+
+    /**
      * <p>Cancel any ongoing repeating capture set by either
      * {@link #setRepeatingRequest setRepeatingRequest} or
      * {@link #setRepeatingBurst}. Has no effect on requests submitted through
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index 4d64295..4124536 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -16,6 +16,7 @@
 
 package android.hardware.camera2;
 
+import android.annotation.CallbackExecutor;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.RequiresPermission;
@@ -134,6 +135,27 @@
     }
 
     /**
+     * Register a callback to be notified about camera device availability.
+     *
+     * <p>The behavior of this method matches that of
+     * {@link #registerAvailabilityCallback(AvailabilityCallback, Handler)},
+     * except that it uses {@link java.util.concurrent.Executor} as an argument
+     * instead of {@link android.os.Handler}.</p>
+     *
+     * @param executor The executor which will be used to invoke the callback.
+     * @param callback the new callback to send camera availability notices to
+     *
+     * @throws IllegalArgumentException if the executor is {@code null}.
+     */
+    public void registerAvailabilityCallback(@NonNull @CallbackExecutor Executor executor,
+            @NonNull AvailabilityCallback callback) {
+        if (executor == null) {
+            throw new IllegalArgumentException("executor was null");
+        }
+        CameraManagerGlobal.get().registerAvailabilityCallback(callback, executor);
+    }
+
+    /**
      * Remove a previously-added callback; the callback will no longer receive connection and
      * disconnection callbacks.
      *
@@ -173,6 +195,27 @@
     }
 
     /**
+     * Register a callback to be notified about torch mode status.
+     *
+     * <p>The behavior of this method matches that of
+     * {@link #registerTorchCallback(TorchCallback, Handler)},
+     * except that it uses {@link java.util.concurrent.Executor} as an argument
+     * instead of {@link android.os.Handler}.</p>
+     *
+     * @param executor The executor which will be used to invoke the callback
+     * @param callback The new callback to send torch mode status to
+     *
+     * @throws IllegalArgumentException if the executor is {@code null}.
+     */
+    public void registerTorchCallback(@NonNull @CallbackExecutor Executor executor,
+            @NonNull TorchCallback callback) {
+        if (executor == null) {
+            throw new IllegalArgumentException("executor was null");
+        }
+        CameraManagerGlobal.get().registerTorchCallback(callback, executor);
+    }
+
+    /**
      * Remove a previously-added callback; the callback will no longer receive torch mode status
      * callbacks.
      *
@@ -248,7 +291,7 @@
      *
      * @param cameraId The unique identifier of the camera device to open
      * @param callback The callback for the camera. Must not be null.
-     * @param handler  The handler to invoke the callback on. Must not be null.
+     * @param executor The executor to invoke the callback with. Must not be null.
      * @param uid      The UID of the application actually opening the camera.
      *                 Must be USE_CALLING_UID unless the caller is a service
      *                 that is trusted to open the device on behalf of an
@@ -267,7 +310,7 @@
      * @see android.app.admin.DevicePolicyManager#setCameraDisabled
      */
     private CameraDevice openCameraDeviceUserAsync(String cameraId,
-            CameraDevice.StateCallback callback, Handler handler, final int uid)
+            CameraDevice.StateCallback callback, Executor executor, final int uid)
             throws CameraAccessException {
         CameraCharacteristics characteristics = getCameraCharacteristics(cameraId);
         CameraDevice device = null;
@@ -280,7 +323,7 @@
                     new android.hardware.camera2.impl.CameraDeviceImpl(
                         cameraId,
                         callback,
-                        handler,
+                        executor,
                         characteristics,
                         mContext.getApplicationInfo().targetSdkVersion);
 
@@ -421,7 +464,47 @@
             @NonNull final CameraDevice.StateCallback callback, @Nullable Handler handler)
             throws CameraAccessException {
 
-        openCameraForUid(cameraId, callback, handler, USE_CALLING_UID);
+        openCameraForUid(cameraId, callback, CameraDeviceImpl.checkAndWrapHandler(handler),
+                USE_CALLING_UID);
+    }
+
+    /**
+     * Open a connection to a camera with the given ID.
+     *
+     * <p>The behavior of this method matches that of
+     * {@link #openCamera(String, StateCallback, Handler)}, except that it uses
+     * {@link java.util.concurrent.Executor} as an argument instead of
+     * {@link android.os.Handler}.</p>
+     *
+     * @param cameraId
+     *             The unique identifier of the camera device to open
+     * @param executor
+     *             The executor which will be used when invoking the callback.
+     * @param callback
+     *             The callback which is invoked once the camera is opened
+     *
+     * @throws CameraAccessException if the camera is disabled by device policy,
+     * has been disconnected, or is being used by a higher-priority camera API client.
+     *
+     * @throws IllegalArgumentException if cameraId, the callback or the executor was null,
+     * or the cameraId does not match any currently or previously available
+     * camera device.
+     *
+     * @throws SecurityException if the application does not have permission to
+     * access the camera
+     *
+     * @see #getCameraIdList
+     * @see android.app.admin.DevicePolicyManager#setCameraDisabled
+     */
+    @RequiresPermission(android.Manifest.permission.CAMERA)
+    public void openCamera(@NonNull String cameraId,
+            @NonNull @CallbackExecutor Executor executor,
+            @NonNull final CameraDevice.StateCallback callback)
+            throws CameraAccessException {
+        if (executor == null) {
+            throw new IllegalArgumentException("executor was null");
+        }
+        openCameraForUid(cameraId, callback, executor, USE_CALLING_UID);
     }
 
     /**
@@ -440,7 +523,7 @@
      * @hide
      */
     public void openCameraForUid(@NonNull String cameraId,
-            @NonNull final CameraDevice.StateCallback callback, @Nullable Handler handler,
+            @NonNull final CameraDevice.StateCallback callback, @NonNull Executor executor,
             int clientUid)
             throws CameraAccessException {
 
@@ -448,19 +531,12 @@
             throw new IllegalArgumentException("cameraId was null");
         } else if (callback == null) {
             throw new IllegalArgumentException("callback was null");
-        } else if (handler == null) {
-            if (Looper.myLooper() != null) {
-                handler = new Handler();
-            } else {
-                throw new IllegalArgumentException(
-                        "Handler argument is null, but no looper exists in the calling thread");
-            }
         }
         if (CameraManagerGlobal.sCameraServiceDisabled) {
             throw new IllegalArgumentException("No cameras available on device");
         }
 
-        openCameraDeviceUserAsync(cameraId, callback, handler, clientUid);
+        openCameraDeviceUserAsync(cameraId, callback, executor, clientUid);
     }
 
     /**
diff --git a/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
index 9cac71c..a4640c1 100644
--- a/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraCaptureSessionImpl.java
@@ -158,14 +158,7 @@
     @Override
     public int capture(CaptureRequest request, CaptureCallback callback,
             Handler handler) throws CameraAccessException {
-        if (request == null) {
-            throw new IllegalArgumentException("request must not be null");
-        } else if (request.isReprocess() && !isReprocessable()) {
-            throw new IllegalArgumentException("this capture session cannot handle reprocess " +
-                    "requests");
-        } else if (request.isReprocess() && request.getReprocessableSessionId() != mId) {
-            throw new IllegalArgumentException("capture request was created for another session");
-        }
+        checkCaptureRequest(request);
 
         synchronized (mDeviceImpl.mInterfaceLock) {
             checkNotClosed();
@@ -183,25 +176,45 @@
     }
 
     @Override
+    public int captureSingleRequest(CaptureRequest request, Executor executor,
+            CaptureCallback callback) throws CameraAccessException {
+        if (executor == null) {
+            throw new IllegalArgumentException("executor must not be null");
+        } else if (callback == null) {
+            throw new IllegalArgumentException("callback must not be null");
+        }
+        checkCaptureRequest(request);
+
+        synchronized (mDeviceImpl.mInterfaceLock) {
+            checkNotClosed();
+
+            executor = CameraDeviceImpl.checkExecutor(executor, callback);
+
+            if (DEBUG) {
+                Log.v(TAG, mIdString + "capture - request " + request + ", callback " + callback +
+                        " executor " + executor);
+            }
+
+            return addPendingSequence(mDeviceImpl.capture(request,
+                    createCaptureCallbackProxyWithExecutor(executor, callback), mDeviceExecutor));
+        }
+    }
+
+    private void checkCaptureRequest(CaptureRequest request) {
+        if (request == null) {
+            throw new IllegalArgumentException("request must not be null");
+        } else if (request.isReprocess() && !isReprocessable()) {
+            throw new IllegalArgumentException("this capture session cannot handle reprocess " +
+                    "requests");
+        } else if (request.isReprocess() && request.getReprocessableSessionId() != mId) {
+            throw new IllegalArgumentException("capture request was created for another session");
+        }
+    }
+
+    @Override
     public int captureBurst(List<CaptureRequest> requests, CaptureCallback callback,
             Handler handler) throws CameraAccessException {
-        if (requests == null) {
-            throw new IllegalArgumentException("Requests must not be null");
-        } else if (requests.isEmpty()) {
-            throw new IllegalArgumentException("Requests must have at least one element");
-        }
-
-        for (CaptureRequest request : requests) {
-            if (request.isReprocess()) {
-                if (!isReprocessable()) {
-                    throw new IllegalArgumentException("This capture session cannot handle " +
-                            "reprocess requests");
-                } else if (request.getReprocessableSessionId() != mId) {
-                    throw new IllegalArgumentException("Capture request was created for another " +
-                            "session");
-                }
-            }
-        }
+        checkCaptureRequests(requests);
 
         synchronized (mDeviceImpl.mInterfaceLock) {
             checkNotClosed();
@@ -220,13 +233,56 @@
     }
 
     @Override
+    public int captureBurstRequests(List<CaptureRequest> requests, Executor executor,
+            CaptureCallback callback) throws CameraAccessException {
+        if (executor == null) {
+            throw new IllegalArgumentException("executor must not be null");
+        } else if (callback == null) {
+            throw new IllegalArgumentException("callback must not be null");
+        }
+        checkCaptureRequests(requests);
+
+        synchronized (mDeviceImpl.mInterfaceLock) {
+            checkNotClosed();
+
+            executor = CameraDeviceImpl.checkExecutor(executor, callback);
+
+            if (DEBUG) {
+                CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
+                Log.v(TAG, mIdString + "captureBurst - requests " + Arrays.toString(requestArray) +
+                        ", callback " + callback + " executor " + executor);
+            }
+
+            return addPendingSequence(mDeviceImpl.captureBurst(requests,
+                    createCaptureCallbackProxyWithExecutor(executor, callback), mDeviceExecutor));
+        }
+    }
+
+    private void checkCaptureRequests(List<CaptureRequest> requests) {
+        if (requests == null) {
+            throw new IllegalArgumentException("Requests must not be null");
+        } else if (requests.isEmpty()) {
+            throw new IllegalArgumentException("Requests must have at least one element");
+        }
+
+        for (CaptureRequest request : requests) {
+            if (request.isReprocess()) {
+                if (!isReprocessable()) {
+                    throw new IllegalArgumentException("This capture session cannot handle " +
+                            "reprocess requests");
+                } else if (request.getReprocessableSessionId() != mId) {
+                    throw new IllegalArgumentException("Capture request was created for another " +
+                            "session");
+                }
+            }
+        }
+
+    }
+
+    @Override
     public int setRepeatingRequest(CaptureRequest request, CaptureCallback callback,
             Handler handler) throws CameraAccessException {
-        if (request == null) {
-            throw new IllegalArgumentException("request must not be null");
-        } else if (request.isReprocess()) {
-            throw new IllegalArgumentException("repeating reprocess requests are not supported");
-        }
+        checkRepeatingRequest(request);
 
         synchronized (mDeviceImpl.mInterfaceLock) {
             checkNotClosed();
@@ -244,20 +300,42 @@
     }
 
     @Override
+    public int setSingleRepeatingRequest(CaptureRequest request, Executor executor,
+            CaptureCallback callback) throws CameraAccessException {
+        if (executor == null) {
+            throw new IllegalArgumentException("executor must not be null");
+        } else if (callback == null) {
+            throw new IllegalArgumentException("callback must not be null");
+        }
+        checkRepeatingRequest(request);
+
+        synchronized (mDeviceImpl.mInterfaceLock) {
+            checkNotClosed();
+
+            executor = CameraDeviceImpl.checkExecutor(executor, callback);
+
+            if (DEBUG) {
+                Log.v(TAG, mIdString + "setRepeatingRequest - request " + request + ", callback " +
+                        callback + " executor" + " " + executor);
+            }
+
+            return addPendingSequence(mDeviceImpl.setRepeatingRequest(request,
+                    createCaptureCallbackProxyWithExecutor(executor, callback), mDeviceExecutor));
+        }
+    }
+
+    private void checkRepeatingRequest(CaptureRequest request) {
+        if (request == null) {
+            throw new IllegalArgumentException("request must not be null");
+        } else if (request.isReprocess()) {
+            throw new IllegalArgumentException("repeating reprocess requests are not supported");
+        }
+    }
+
+    @Override
     public int setRepeatingBurst(List<CaptureRequest> requests,
             CaptureCallback callback, Handler handler) throws CameraAccessException {
-        if (requests == null) {
-            throw new IllegalArgumentException("requests must not be null");
-        } else if (requests.isEmpty()) {
-            throw new IllegalArgumentException("requests must have at least one element");
-        }
-
-        for (CaptureRequest r : requests) {
-            if (r.isReprocess()) {
-                throw new IllegalArgumentException("repeating reprocess burst requests are not " +
-                        "supported");
-            }
-        }
+        checkRepeatingRequests(requests);
 
         synchronized (mDeviceImpl.mInterfaceLock) {
             checkNotClosed();
@@ -277,6 +355,48 @@
     }
 
     @Override
+    public int setRepeatingBurstRequests(List<CaptureRequest> requests, Executor executor,
+            CaptureCallback callback) throws CameraAccessException {
+        if (executor == null) {
+            throw new IllegalArgumentException("executor must not be null");
+        } else if (callback == null) {
+            throw new IllegalArgumentException("callback must not be null");
+        }
+        checkRepeatingRequests(requests);
+
+        synchronized (mDeviceImpl.mInterfaceLock) {
+            checkNotClosed();
+
+            executor = CameraDeviceImpl.checkExecutor(executor, callback);
+
+            if (DEBUG) {
+                CaptureRequest[] requestArray = requests.toArray(new CaptureRequest[0]);
+                Log.v(TAG, mIdString + "setRepeatingBurst - requests " +
+                        Arrays.toString(requestArray) + ", callback " + callback +
+                        " executor" + "" + executor);
+            }
+
+            return addPendingSequence(mDeviceImpl.setRepeatingBurst(requests,
+                    createCaptureCallbackProxyWithExecutor(executor, callback), mDeviceExecutor));
+        }
+    }
+
+    private void checkRepeatingRequests(List<CaptureRequest> requests) {
+        if (requests == null) {
+            throw new IllegalArgumentException("requests must not be null");
+        } else if (requests.isEmpty()) {
+            throw new IllegalArgumentException("requests must have at least one element");
+        }
+
+        for (CaptureRequest r : requests) {
+            if (r.isReprocess()) {
+                throw new IllegalArgumentException("repeating reprocess burst requests are not " +
+                        "supported");
+            }
+        }
+    }
+
+    @Override
     public void stopRepeating() throws CameraAccessException {
         synchronized (mDeviceImpl.mInterfaceLock) {
             checkNotClosed();
@@ -462,6 +582,11 @@
         final Executor executor = (callback != null) ? CameraDeviceImpl.checkAndWrapHandler(
                 handler) : null;
 
+        return createCaptureCallbackProxyWithExecutor(executor, callback);
+    }
+
+    private CameraDeviceImpl.CaptureCallback createCaptureCallbackProxyWithExecutor(
+            Executor executor, CaptureCallback callback) {
         return new CameraDeviceImpl.CaptureCallback() {
             @Override
             public void onCaptureStarted(CameraDevice camera,
diff --git a/core/java/android/hardware/camera2/impl/CameraConstrainedHighSpeedCaptureSessionImpl.java b/core/java/android/hardware/camera2/impl/CameraConstrainedHighSpeedCaptureSessionImpl.java
index 89f6172..3494a7f 100644
--- a/core/java/android/hardware/camera2/impl/CameraConstrainedHighSpeedCaptureSessionImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraConstrainedHighSpeedCaptureSessionImpl.java
@@ -193,6 +193,13 @@
     }
 
     @Override
+    public int captureSingleRequest(CaptureRequest request, Executor executor,
+            CaptureCallback listener) throws CameraAccessException {
+        throw new UnsupportedOperationException("Constrained high speed session doesn't support"
+                + " this method");
+    }
+
+    @Override
     public int captureBurst(List<CaptureRequest> requests, CaptureCallback listener,
             Handler handler) throws CameraAccessException {
         if (!isConstrainedHighSpeedRequestList(requests)) {
@@ -204,6 +211,17 @@
     }
 
     @Override
+    public int captureBurstRequests(List<CaptureRequest> requests, Executor executor,
+            CaptureCallback listener) throws CameraAccessException {
+        if (!isConstrainedHighSpeedRequestList(requests)) {
+            throw new IllegalArgumentException(
+                "Only request lists created by createHighSpeedRequestList() can be submitted to " +
+                "a constrained high speed capture session");
+        }
+        return mSessionImpl.captureBurstRequests(requests, executor, listener);
+    }
+
+    @Override
     public int setRepeatingRequest(CaptureRequest request, CaptureCallback listener,
             Handler handler) throws CameraAccessException {
         throw new UnsupportedOperationException("Constrained high speed session doesn't support"
@@ -211,6 +229,13 @@
     }
 
     @Override
+    public int setSingleRepeatingRequest(CaptureRequest request, Executor executor,
+            CaptureCallback listener) throws CameraAccessException {
+        throw new UnsupportedOperationException("Constrained high speed session doesn't support"
+                + " this method");
+    }
+
+    @Override
     public int setRepeatingBurst(List<CaptureRequest> requests, CaptureCallback listener,
             Handler handler) throws CameraAccessException {
         if (!isConstrainedHighSpeedRequestList(requests)) {
@@ -222,6 +247,17 @@
     }
 
     @Override
+    public int setRepeatingBurstRequests(List<CaptureRequest> requests, Executor executor,
+            CaptureCallback listener) throws CameraAccessException {
+        if (!isConstrainedHighSpeedRequestList(requests)) {
+            throw new IllegalArgumentException(
+                "Only request lists created by createHighSpeedRequestList() can be submitted to " +
+                "a constrained high speed capture session");
+        }
+        return mSessionImpl.setRepeatingBurstRequests(requests, executor, listener);
+    }
+
+    @Override
     public void stopRepeating() throws CameraAccessException {
         mSessionImpl.stopRepeating();
     }
diff --git a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
index 1f35f31..d967fba 100644
--- a/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
+++ b/core/java/android/hardware/camera2/impl/CameraDeviceImpl.java
@@ -240,14 +240,14 @@
         }
     };
 
-    public CameraDeviceImpl(String cameraId, StateCallback callback, Handler handler,
+    public CameraDeviceImpl(String cameraId, StateCallback callback, Executor executor,
                         CameraCharacteristics characteristics, int appTargetSdkVersion) {
-        if (cameraId == null || callback == null || handler == null || characteristics == null) {
+        if (cameraId == null || callback == null || executor == null || characteristics == null) {
             throw new IllegalArgumentException("Null argument given");
         }
         mCameraId = cameraId;
         mDeviceCallback = callback;
-        mDeviceExecutor = checkAndWrapHandler(handler);
+        mDeviceExecutor = executor;
         mCharacteristics = characteristics;
         mAppTargetSdkVersion = appTargetSdkVersion;
 
@@ -2349,7 +2349,7 @@
      *
      * <p>If the callback isn't null, check the executor, otherwise pass it through.</p>
      */
-    static <T> Executor checkExecutor(Executor executor, T callback) {
+    public static <T> Executor checkExecutor(Executor executor, T callback) {
         return (callback != null) ? checkExecutor(executor) : executor;
     }
 
diff --git a/core/java/android/hardware/usb/IUsbManager.aidl b/core/java/android/hardware/usb/IUsbManager.aidl
index 91bbdc7..6d9c913 100644
--- a/core/java/android/hardware/usb/IUsbManager.aidl
+++ b/core/java/android/hardware/usb/IUsbManager.aidl
@@ -105,6 +105,12 @@
     /* Gets the current screen unlocked functions. */
     long getScreenUnlockedFunctions();
 
+    /* Get the functionfs control handle for the given function. Usb
+     * descriptors will already be written, and the handle will be
+     * ready to use.
+     */
+    ParcelFileDescriptor getControlFd(long function);
+
     /* 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 572c585..46142e3 100644
--- a/core/java/android/hardware/usb/UsbManager.java
+++ b/core/java/android/hardware/usb/UsbManager.java
@@ -192,14 +192,6 @@
     public static final String USB_DATA_UNLOCKED = "unlocked";
 
     /**
-     * Boolean extra indicating whether the intent represents a change in the usb
-     * configuration (as opposed to a state update).
-     *
-     * {@hide}
-     */
-    public static final String USB_CONFIG_CHANGED = "config_changed";
-
-    /**
      * A placeholder indicating that no USB function is being specified.
      * Used for compatibility with old init scripts to indicate no functions vs. charging function.
      *
@@ -471,6 +463,25 @@
     }
 
     /**
+     * Gets the functionfs control file descriptor for the given function, with
+     * the usb descriptors and strings already written. The file descriptor is used
+     * by the function implementation to handle events and control requests.
+     *
+     * @param function to get control fd for. Currently {@link #FUNCTION_MTP} and
+     * {@link #FUNCTION_PTP} are supported.
+     * @return A ParcelFileDescriptor holding the valid fd, or null if the fd was not found.
+     *
+     * {@hide}
+     */
+    public ParcelFileDescriptor getControlFd(long function) {
+        try {
+            return mService.getControlFd(function);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
      * Returns true if the caller has permission to access the device.
      * Permission might have been granted temporarily via
      * {@link #requestPermission(UsbDevice, PendingIntent)} or
diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java
index 93b1b22..e07f586 100644
--- a/core/java/android/net/ConnectivityManager.java
+++ b/core/java/android/net/ConnectivityManager.java
@@ -3851,8 +3851,8 @@
 
     /**
      * The network watchlist is a list of domains and IP addresses that are associated with
-     * potentially harmful apps. This method returns the hash of the watchlist currently
-     * used by the system.
+     * potentially harmful apps. This method returns the SHA-256 of the watchlist config file
+     * currently used by the system for validation purposes.
      *
      * @return Hash of network watchlist config file. Null if config does not exist.
      */
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java
index 7922276..40d53b7 100644
--- a/core/java/android/net/TrafficStats.java
+++ b/core/java/android/net/TrafficStats.java
@@ -16,7 +16,6 @@
 
 package android.net;
 
-import android.annotation.RequiresPermission;
 import android.annotation.SuppressLint;
 import android.annotation.SystemApi;
 import android.annotation.TestApi;
@@ -259,30 +258,47 @@
     /**
      * Set specific UID to use when accounting {@link Socket} traffic
      * originating from the current thread. Designed for use when performing an
-     * operation on behalf of another application.
+     * operation on behalf of another application, or when another application
+     * is performing operations on your behalf.
+     * <p>
+     * Any app can <em>accept</em> blame for traffic performed on a socket
+     * originally created by another app by calling this method with the
+     * {@link android.system.Os#getuid()} value. However, only apps holding the
+     * {@code android.Manifest.permission#UPDATE_DEVICE_STATS} permission may
+     * <em>assign</em> blame to another UIDs.
      * <p>
      * Changes only take effect during subsequent calls to
      * {@link #tagSocket(Socket)}.
-     * <p>
-     * To take effect, caller must hold
-     * {@link android.Manifest.permission#UPDATE_DEVICE_STATS} permission.
-     *
-     * @hide
      */
     @SystemApi
-    @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
+    @SuppressLint("Doclava125")
     public static void setThreadStatsUid(int uid) {
         NetworkManagementSocketTagger.setThreadSocketStatsUid(uid);
     }
 
     /**
+     * Get the active UID used when accounting {@link Socket} traffic originating
+     * from the current thread. Only one active tag per thread is supported.
+     * {@link #tagSocket(Socket)}.
+     *
+     * @see #setThreadStatsUid(int)
+     */
+    public static int getThreadStatsUid() {
+        return NetworkManagementSocketTagger.getThreadSocketStatsUid();
+    }
+
+    /**
      * Set specific UID to use when accounting {@link Socket} traffic
      * originating from the current thread as the calling UID. Designed for use
      * when another application is performing operations on your behalf.
      * <p>
      * Changes only take effect during subsequent calls to
      * {@link #tagSocket(Socket)}.
+     *
+     * @removed
+     * @deprecated use {@link #setThreadStatsUid(int)} instead.
      */
+    @Deprecated
     public static void setThreadStatsUidSelf() {
         setThreadStatsUid(android.os.Process.myUid());
     }
diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java
index df6ce8e..e22c65f 100644
--- a/core/java/android/os/Build.java
+++ b/core/java/android/os/Build.java
@@ -242,7 +242,9 @@
          * Possible values are defined in {@link Build.VERSION_CODES}.
          *
          * @see #SDK_INT
+         * @hide
          */
+        @TestApi
         public static final int FIRST_SDK_INT = SystemProperties
                 .getInt("ro.product.first_api_level", 0);
 
diff --git a/core/java/android/os/FileUtils.java b/core/java/android/os/FileUtils.java
index 1160415..88d6e84 100644
--- a/core/java/android/os/FileUtils.java
+++ b/core/java/android/os/FileUtils.java
@@ -411,6 +411,9 @@
                 checkpoint = 0;
             }
         }
+        if (listener != null) {
+            listener.onProgress(progress);
+        }
         return progress;
     }
 
@@ -440,6 +443,9 @@
                 checkpoint = 0;
             }
         }
+        if (listener != null) {
+            listener.onProgress(progress);
+        }
         return progress;
     }
 
@@ -479,6 +485,9 @@
                 checkpoint = 0;
             }
         }
+        if (listener != null) {
+            listener.onProgress(progress);
+        }
         return progress;
     }
 
diff --git a/core/java/android/os/SystemClock.java b/core/java/android/os/SystemClock.java
index 0f70427..b254166 100644
--- a/core/java/android/os/SystemClock.java
+++ b/core/java/android/os/SystemClock.java
@@ -269,6 +269,7 @@
      * time or throw.
      *
      * @throws DateTimeException when no accurate network time can be provided.
+     * @hide
      */
     public static long currentNetworkTimeMillis() {
         final IAlarmManager mgr = IAlarmManager.Stub
@@ -302,6 +303,7 @@
      * time or throw.
      *
      * @throws DateTimeException when no accurate network time can be provided.
+     * @hide
      */
     public static @NonNull Clock currentNetworkTimeClock() {
         return new SimpleClock(ZoneOffset.UTC) {
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index a013d3d..b58e5b3 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -11004,13 +11004,21 @@
         public static final String SHOW_PROCESSES = "show_processes";
 
         /**
-         * If 1 low power mode is enabled.
+         * If 1 low power mode (aka battery saver) is enabled.
          * @hide
          */
         @TestApi
         public static final String LOW_POWER_MODE = "low_power";
 
         /**
+         * If 1, battery saver ({@link #LOW_POWER_MODE}) will be re-activated after the device
+         * is unplugged from a charger or rebooted.
+         * @hide
+         */
+        @TestApi
+        public static final String LOW_POWER_MODE_STICKY = "low_power_sticky";
+
+        /**
          * Battery level [1-100] at which low power mode automatically turns on.
          * If 0, it will not automatically turn on.
          * @hide
diff --git a/core/java/android/security/keystore/recovery/KeyChainProtectionParams.java b/core/java/android/security/keystore/recovery/KeyChainProtectionParams.java
index d42424e..2a66206 100644
--- a/core/java/android/security/keystore/recovery/KeyChainProtectionParams.java
+++ b/core/java/android/security/keystore/recovery/KeyChainProtectionParams.java
@@ -94,21 +94,6 @@
     private KeyDerivationParams mKeyDerivationParams;
     private byte[] mSecret; // Derived from user secret. The field must have limited visibility.
 
-    /**
-     * @param secret Constructor creates a reference to the secret. Caller must use
-     * @link {#clearSecret} to overwrite its value in memory.
-     * @hide
-     */
-    public KeyChainProtectionParams(@UserSecretType int userSecretType,
-            @LockScreenUiFormat int lockScreenUiFormat,
-            @NonNull KeyDerivationParams keyDerivationParams,
-            @NonNull byte[] secret) {
-        mUserSecretType = userSecretType;
-        mLockScreenUiFormat = lockScreenUiFormat;
-        mKeyDerivationParams = Preconditions.checkNotNull(keyDerivationParams);
-        mSecret = Preconditions.checkNotNull(secret);
-    }
-
     private KeyChainProtectionParams() {
 
     }
@@ -158,6 +143,7 @@
 
         /**
          * Sets user secret type.
+         * Default value is {@link TYPE_LOCKSCREEN}.
          *
          * @see TYPE_LOCKSCREEN
          * @param userSecretType The secret type
@@ -185,7 +171,7 @@
         /**
          * Sets parameters of the key derivation function.
          *
-         * @param keyDerivationParams Key derivation Params
+         * @param keyDerivationParams Key derivation parameters
          * @return This builder.
          */
         public Builder setKeyDerivationParams(@NonNull KeyDerivationParams
diff --git a/core/java/android/security/keystore/recovery/KeyChainSnapshot.java b/core/java/android/security/keystore/recovery/KeyChainSnapshot.java
index ccb627e..24ff182 100644
--- a/core/java/android/security/keystore/recovery/KeyChainSnapshot.java
+++ b/core/java/android/security/keystore/recovery/KeyChainSnapshot.java
@@ -252,12 +252,12 @@
         /**
          * Sets UI and key derivation parameters
          *
-         * @param recoveryMetadata The UI and key derivation parameters
+         * @param keyChainProtectionParams The UI and key derivation parameters
          * @return This builder.
          */
         public Builder setKeyChainProtectionParams(
-                @NonNull List<KeyChainProtectionParams> recoveryMetadata) {
-            mInstance.mKeyChainProtectionParams = recoveryMetadata;
+                @NonNull List<KeyChainProtectionParams> keyChainProtectionParams) {
+            mInstance.mKeyChainProtectionParams = keyChainProtectionParams;
             return this;
         }
 
@@ -292,7 +292,7 @@
          */
         @NonNull public KeyChainSnapshot build() {
             Preconditions.checkCollectionElementsNotNull(mInstance.mKeyChainProtectionParams,
-                    "recoveryMetadata");
+                    "keyChainProtectionParams");
             Preconditions.checkCollectionElementsNotNull(mInstance.mEntryRecoveryData,
                     "entryRecoveryData");
             Preconditions.checkNotNull(mInstance.mEncryptedRecoveryKeyBlob);
diff --git a/core/java/android/security/keystore/recovery/RecoveryController.java b/core/java/android/security/keystore/recovery/RecoveryController.java
index 61b4dd8..ab52d32 100644
--- a/core/java/android/security/keystore/recovery/RecoveryController.java
+++ b/core/java/android/security/keystore/recovery/RecoveryController.java
@@ -159,7 +159,7 @@
      * Gets a new instance of the class.
      */
     @RequiresPermission(android.Manifest.permission.RECOVER_KEYSTORE)
-    public static RecoveryController getInstance(Context context) {
+    @NonNull public static RecoveryController getInstance(@NonNull Context context) {
         ILockSettings lockSettings =
                 ILockSettings.Stub.asInterface(ServiceManager.getService("lock_settings"));
         return new RecoveryController(lockSettings, KeyStore.getInstance());
diff --git a/core/java/android/text/method/LinkMovementMethod.java b/core/java/android/text/method/LinkMovementMethod.java
index 31ed549..f332358 100644
--- a/core/java/android/text/method/LinkMovementMethod.java
+++ b/core/java/android/text/method/LinkMovementMethod.java
@@ -16,6 +16,7 @@
 
 package android.text.method;
 
+import android.os.Build;
 import android.text.Layout;
 import android.text.NoCopySpan;
 import android.text.Selection;
@@ -35,6 +36,8 @@
     private static final int UP = 2;
     private static final int DOWN = 3;
 
+    private static final int HIDE_FLOATING_TOOLBAR_DELAY_MS = 200;
+
     @Override
     public boolean canSelectArbitrarily() {
         return true;
@@ -65,7 +68,7 @@
 
         return super.up(widget, buffer);
     }
-        
+
     @Override
     protected boolean down(TextView widget, Spannable buffer) {
         if (action(DOWN, widget, buffer)) {
@@ -215,6 +218,12 @@
                 if (action == MotionEvent.ACTION_UP) {
                     links[0].onClick(widget);
                 } else if (action == MotionEvent.ACTION_DOWN) {
+                    if (widget.getContext().getApplicationInfo().targetSdkVersion
+                            > Build.VERSION_CODES.O_MR1) {
+                        // Selection change will reposition the toolbar. Hide it for a few ms for a
+                        // smoother transition.
+                        widget.hideFloatingToolbar(HIDE_FLOATING_TOOLBAR_DELAY_MS);
+                    }
                     Selection.setSelection(buffer,
                         buffer.getSpanStart(links[0]),
                         buffer.getSpanEnd(links[0]));
diff --git a/core/java/android/util/DataUnit.java b/core/java/android/util/DataUnit.java
index ea4266e..cf045b8 100644
--- a/core/java/android/util/DataUnit.java
+++ b/core/java/android/util/DataUnit.java
@@ -29,6 +29,8 @@
  * "kibibyte" as an IEC unit of 1024 bytes.
  * <p>
  * This design is mirrored after {@link TimeUnit} and {@link ChronoUnit}.
+ *
+ * @hide
  */
 public enum DataUnit {
     KILOBYTES { @Override public long toBytes(long v) { return v * 1_000; } },
diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java
index 5bee87c..01fd090 100644
--- a/core/java/android/view/autofill/AutofillManager.java
+++ b/core/java/android/view/autofill/AutofillManager.java
@@ -274,6 +274,16 @@
     public static final int STATE_DISABLED_BY_SERVICE = 4;
 
     /**
+     * Same as {@link #STATE_UNKNOWN}, but used on
+     * {@link AutofillManagerClient#setSessionFinished(int)} when the session was finished because
+     * the URL bar changed on client mode
+     *
+     * @hide
+     */
+    public static final int STATE_UNKNOWN_COMPAT_MODE = 5;
+
+
+    /**
      * Timeout in ms for calls to the field classification service.
      * @hide
      */
@@ -1947,15 +1957,24 @@
      * Marks the state of the session as finished.
      *
      * @param newState {@link #STATE_FINISHED} (because the autofill service returned a {@code null}
-     *  FillResponse), {@link #STATE_UNKNOWN} (because the session was removed), or
-     *  {@link #STATE_DISABLED_BY_SERVICE} (because the autofill service disabled further autofill
-     *  requests for the activity).
+     *  FillResponse), {@link #STATE_UNKNOWN} (because the session was removed),
+     *  {@link #STATE_UNKNOWN_COMPAT_MODE} (beucase the session was finished when the URL bar
+     *  changed on compat mode), or {@link #STATE_DISABLED_BY_SERVICE} (because the autofill service
+     *  disabled further autofill requests for the activity).
      */
     private void setSessionFinished(int newState) {
         synchronized (mLock) {
-            if (sVerbose) Log.v(TAG, "setSessionFinished(): from " + mState + " to " + newState);
-            resetSessionLocked(/* resetEnteredIds= */ false);
-            mState = newState;
+            if (sVerbose) {
+                Log.v(TAG, "setSessionFinished(): from " + getStateAsStringLocked() + " to "
+                        + getStateAsString(newState));
+            }
+            if (newState == STATE_UNKNOWN_COMPAT_MODE) {
+                resetSessionLocked(/* resetEnteredIds= */ true);
+                mState = STATE_UNKNOWN;
+            } else {
+                resetSessionLocked(/* resetEnteredIds= */ false);
+                mState = newState;
+            }
         }
     }
 
@@ -2107,19 +2126,26 @@
 
     @GuardedBy("mLock")
     private String getStateAsStringLocked() {
-        switch (mState) {
+        return getStateAsString(mState);
+    }
+
+    @NonNull
+    private static String getStateAsString(int state) {
+        switch (state) {
             case STATE_UNKNOWN:
-                return "STATE_UNKNOWN";
+                return "UNKNOWN";
             case STATE_ACTIVE:
-                return "STATE_ACTIVE";
+                return "ACTIVE";
             case STATE_FINISHED:
-                return "STATE_FINISHED";
+                return "FINISHED";
             case STATE_SHOWING_SAVE_UI:
-                return "STATE_SHOWING_SAVE_UI";
+                return "SHOWING_SAVE_UI";
             case STATE_DISABLED_BY_SERVICE:
-                return "STATE_DISABLED_BY_SERVICE";
+                return "DISABLED_BY_SERVICE";
+            case STATE_UNKNOWN_COMPAT_MODE:
+                return "UNKNOWN_COMPAT_MODE";
             default:
-                return "INVALID:" + mState;
+                return "INVALID:" + state;
         }
     }
 
diff --git a/core/java/android/widget/Editor.java b/core/java/android/widget/Editor.java
index 92285c7..3775835 100644
--- a/core/java/android/widget/Editor.java
+++ b/core/java/android/widget/Editor.java
@@ -289,6 +289,7 @@
     boolean mShowSoftInputOnFocus = true;
     private boolean mPreserveSelection;
     private boolean mRestartActionModeOnNextRefresh;
+    private boolean mRequestingLinkActionMode;
 
     private SelectionActionModeHelper mSelectionActionModeHelper;
 
@@ -2127,6 +2128,7 @@
             return;
         }
         stopTextActionMode();
+        mRequestingLinkActionMode = true;
         getSelectionActionModeHelper().startLinkActionModeAsync(start, end);
     }
 
@@ -2212,7 +2214,9 @@
         mTextActionMode = mTextView.startActionMode(actionModeCallback, ActionMode.TYPE_FLOATING);
 
         final boolean selectionStarted = mTextActionMode != null;
-        if (selectionStarted && !mTextView.isTextSelectable() && mShowSoftInputOnFocus) {
+        if (selectionStarted
+                && mTextView.isTextEditable() && !mTextView.isTextSelectable()
+                && mShowSoftInputOnFocus) {
             // Show the IME to be able to replace text, except when selecting non editable text.
             final InputMethodManager imm = InputMethodManager.peekInstance();
             if (imm != null) {
@@ -2322,10 +2326,14 @@
         if (!selectAllGotFocus && text.length() > 0) {
             // Move cursor
             final int offset = mTextView.getOffsetForPosition(event.getX(), event.getY());
-            Selection.setSelection((Spannable) text, offset);
-            if (mSpellChecker != null) {
-                // When the cursor moves, the word that was typed may need spell check
-                mSpellChecker.onSelectionChanged();
+
+            final boolean shouldInsertCursor = !mRequestingLinkActionMode;
+            if (shouldInsertCursor) {
+                Selection.setSelection((Spannable) text, offset);
+                if (mSpellChecker != null) {
+                    // When the cursor moves, the word that was typed may need spell check
+                    mSpellChecker.onSelectionChanged();
+                }
             }
 
             if (!extractedTextModeWillBeStarted()) {
@@ -2335,16 +2343,17 @@
                         mTextView.removeCallbacks(mInsertionActionModeRunnable);
                     }
 
-                    mShowSuggestionRunnable = new Runnable() {
-                        public void run() {
-                            replace();
-                        }
-                    };
+                    mShowSuggestionRunnable = this::replace;
+
                     // removeCallbacks is performed on every touch
                     mTextView.postDelayed(mShowSuggestionRunnable,
                             ViewConfiguration.getDoubleTapTimeout());
                 } else if (hasInsertionController()) {
-                    getInsertionController().show();
+                    if (shouldInsertCursor) {
+                        getInsertionController().show();
+                    } else {
+                        getInsertionController().hide();
+                    }
                 }
             }
         }
@@ -4170,6 +4179,7 @@
             }
 
             mAssistClickHandlers.clear();
+            mRequestingLinkActionMode = false;
         }
 
         @Override
diff --git a/core/java/android/widget/SelectionActionModeHelper.java b/core/java/android/widget/SelectionActionModeHelper.java
index 6e855ba..05204d0 100644
--- a/core/java/android/widget/SelectionActionModeHelper.java
+++ b/core/java/android/widget/SelectionActionModeHelper.java
@@ -71,7 +71,7 @@
     private final TextClassificationHelper mTextClassificationHelper;
     private final TextClassificationConstants mTextClassificationSettings;
 
-    private TextClassification mTextClassification;
+    @Nullable private TextClassification mTextClassification;
     private AsyncTask mTextClassificationAsyncTask;
 
     private final SelectionTracker mSelectionTracker;
@@ -124,7 +124,8 @@
                             : mTextClassificationHelper::classifyText,
                     mSmartSelectSprite != null
                             ? this::startSelectionActionModeWithSmartSelectAnimation
-                            : this::startSelectionActionMode)
+                            : this::startSelectionActionMode,
+                    mTextClassificationHelper::getOriginalSelection)
                     .execute();
         }
     }
@@ -143,7 +144,8 @@
                     mTextView,
                     mTextClassificationHelper.getTimeoutDuration(),
                     mTextClassificationHelper::classifyText,
-                    this::startLinkActionMode)
+                    this::startLinkActionMode,
+                    mTextClassificationHelper::getOriginalSelection)
                     .execute();
         }
     }
@@ -158,7 +160,8 @@
                     mTextView,
                     mTextClassificationHelper.getTimeoutDuration(),
                     mTextClassificationHelper::classifyText,
-                    this::invalidateActionMode)
+                    this::invalidateActionMode,
+                    mTextClassificationHelper::getOriginalSelection)
                     .execute();
         }
     }
@@ -822,6 +825,7 @@
         private final int mTimeOutDuration;
         private final Supplier<SelectionResult> mSelectionResultSupplier;
         private final Consumer<SelectionResult> mSelectionResultCallback;
+        private final Supplier<SelectionResult> mTimeOutResultSupplier;
         private final TextView mTextView;
         private final String mOriginalText;
 
@@ -830,16 +834,19 @@
          * @param timeOut time in milliseconds to timeout the query if it has not completed
          * @param selectionResultSupplier fetches the selection results. Runs on a background thread
          * @param selectionResultCallback receives the selection results. Runs on the UiThread
+         * @param timeOutResultSupplier default result if the task times out
          */
         TextClassificationAsyncTask(
                 @NonNull TextView textView, int timeOut,
                 @NonNull Supplier<SelectionResult> selectionResultSupplier,
-                @NonNull Consumer<SelectionResult> selectionResultCallback) {
+                @NonNull Consumer<SelectionResult> selectionResultCallback,
+                @NonNull Supplier<SelectionResult> timeOutResultSupplier) {
             super(textView != null ? textView.getHandler() : null);
             mTextView = Preconditions.checkNotNull(textView);
             mTimeOutDuration = timeOut;
             mSelectionResultSupplier = Preconditions.checkNotNull(selectionResultSupplier);
             mSelectionResultCallback = Preconditions.checkNotNull(selectionResultCallback);
+            mTimeOutResultSupplier = Preconditions.checkNotNull(timeOutResultSupplier);
             // Make a copy of the original text.
             mOriginalText = getText(mTextView).toString();
         }
@@ -863,7 +870,7 @@
 
         private void onTimeOut() {
             if (getStatus() == Status.RUNNING) {
-                onPostExecute(null);
+                onPostExecute(mTimeOutResultSupplier.get());
             }
             cancel(true);
         }
@@ -963,6 +970,10 @@
             return performClassification(selection);
         }
 
+        public SelectionResult getOriginalSelection() {
+            return new SelectionResult(mSelectionStart, mSelectionEnd, null, null);
+        }
+
         /**
          * Maximum time (in milliseconds) to wait for a textclassifier result before timing out.
          */
@@ -1025,14 +1036,14 @@
     private static final class SelectionResult {
         private final int mStart;
         private final int mEnd;
-        private final TextClassification mClassification;
+        @Nullable private final TextClassification mClassification;
         @Nullable private final TextSelection mSelection;
 
         SelectionResult(int start, int end,
-                TextClassification classification, @Nullable TextSelection selection) {
+                @Nullable TextClassification classification, @Nullable TextSelection selection) {
             mStart = start;
             mEnd = end;
-            mClassification = Preconditions.checkNotNull(classification);
+            mClassification = classification;
             mSelection = selection;
         }
     }
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index c366a91..7b1acb1 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -644,8 +644,12 @@
      */
     private Layout mSavedMarqueeModeLayout;
 
+    // Do not update following mText/mSpannable/mPrecomputed except for setTextInternal()
     @ViewDebug.ExportedProperty(category = "text")
-    private CharSequence mText;
+    private @Nullable CharSequence mText;
+    private @Nullable Spannable mSpannable;
+    private @Nullable PrecomputedText mPrecomputed;
+
     private CharSequence mTransformed;
     private BufferType mBufferType = BufferType.NORMAL;
 
@@ -874,7 +878,7 @@
             setImportantForAutofill(IMPORTANT_FOR_AUTOFILL_YES);
         }
 
-        mText = "";
+        setTextInternal("");
 
         final Resources res = getResources();
         final CompatibilityInfo compat = res.getCompatibilityInfo();
@@ -1615,6 +1619,13 @@
         }
     }
 
+    // Update mText and mPrecomputed
+    private void setTextInternal(@Nullable CharSequence text) {
+        mText = text;
+        mSpannable = (text instanceof Spannable) ? (Spannable) text : null;
+        mPrecomputed = (text instanceof PrecomputedText) ? (PrecomputedText) text : null;
+    }
+
     /**
      * Specify whether this widget should automatically scale the text to try to perfectly fit
      * within the layout bounds by using the default auto-size configuration.
@@ -1973,9 +1984,9 @@
                         }
                     }
                 }
-            } else if (mText instanceof Spannable) {
+            } else if (mSpannable != null) {
                 // Reset the selection.
-                Selection.setSelection((Spannable) mText, getSelectionEnd());
+                Selection.setSelection(mSpannable, getSelectionEnd());
             }
         }
     }
@@ -2359,7 +2370,7 @@
         if (mMovement != movement) {
             mMovement = movement;
 
-            if (movement != null && !(mText instanceof Spannable)) {
+            if (movement != null && mSpannable == null) {
                 setText(mText);
             }
 
@@ -2409,8 +2420,8 @@
             return;
         }
         if (mTransformation != null) {
-            if (mText instanceof Spannable) {
-                ((Spannable) mText).removeSpan(mTransformation);
+            if (mSpannable != null) {
+                mSpannable.removeSpan(mTransformation);
             }
         }
 
@@ -5254,7 +5265,7 @@
         ((Editable) mText).append(text, start, end);
 
         if (mAutoLinkMask != 0) {
-            boolean linksWereAdded = Linkify.addLinks((Spannable) mText, mAutoLinkMask);
+            boolean linksWereAdded = Linkify.addLinks(mSpannable, mAutoLinkMask);
             // Do not change the movement method for text that support text selection as it
             // would prevent an arbitrary cursor displacement.
             if (linksWereAdded && mLinksClickable && !textCanBeSelected()) {
@@ -5413,7 +5424,7 @@
         }
 
         if (ss.selStart >= 0 && ss.selEnd >= 0) {
-            if (mText instanceof Spannable) {
+            if (mSpannable != null) {
                 int len = mText.length();
 
                 if (ss.selStart > len || ss.selEnd > len) {
@@ -5426,7 +5437,7 @@
                     Log.e(LOG_TAG, "Saved cursor position " + ss.selStart + "/" + ss.selEnd
                             + " out of range for " + restored + "text " + mText);
                 } else {
-                    Selection.setSelection((Spannable) mText, ss.selStart, ss.selEnd);
+                    Selection.setSelection(mSpannable, ss.selStart, ss.selEnd);
 
                     if (ss.frozenWithFocus) {
                         createEditorIfNeeded();
@@ -5688,7 +5699,7 @@
                  * movement method, because setMovementMethod() may call
                  * setText() again to try to upgrade the buffer type.
                  */
-                mText = text;
+                setTextInternal(text);
 
                 // Do not change the movement method for text that support text selection as it
                 // would prevent an arbitrary cursor displacement.
@@ -5699,7 +5710,7 @@
         }
 
         mBufferType = type;
-        mText = text;
+        setTextInternal(text);
 
         if (mTransformation == null) {
             mTransformed = text;
@@ -5825,8 +5836,8 @@
         setText(text, type);
 
         if (start >= 0 || end >= 0) {
-            if (mText instanceof Spannable) {
-                Selection.setSelection((Spannable) mText,
+            if (mSpannable != null) {
+                Selection.setSelection(mSpannable,
                                        Math.max(0, Math.min(start, len)),
                                        Math.max(0, Math.min(end, len)));
             }
@@ -6020,7 +6031,7 @@
         }
 
         if (!isSuggestionsEnabled()) {
-            mText = removeSuggestionSpans(mText);
+            setTextInternal(removeSuggestionSpans(mText));
         }
 
         InputMethodManager imm = InputMethodManager.peekInstance();
@@ -6948,8 +6959,7 @@
     public boolean hasOverlappingRendering() {
         // horizontal fading edge causes SaveLayerAlpha, which doesn't support alpha modulation
         return ((getBackground() != null && getBackground().getCurrent() != null)
-                || mText instanceof Spannable || hasSelection()
-                || isHorizontalFadingEdgeEnabled());
+                || mSpannable != null || hasSelection() || isHorizontalFadingEdgeEnabled());
     }
 
     /**
@@ -7399,11 +7409,11 @@
 
     @Override
     public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
-        if (mText instanceof Spannable && mLinksClickable) {
+        if (mSpannable != null && mLinksClickable) {
             final float x = event.getX(pointerIndex);
             final float y = event.getY(pointerIndex);
             final int offset = getOffsetForPosition(x, y);
-            final ClickableSpan[] clickables = ((Spannable) mText).getSpans(offset, offset,
+            final ClickableSpan[] clickables = mSpannable.getSpans(offset, offset,
                     ClickableSpan.class);
             if (clickables.length > 0) {
                 return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_HAND);
@@ -7496,10 +7506,10 @@
 
         } else if (which == KEY_DOWN_HANDLED_BY_MOVEMENT_METHOD) {
             // mMovement is not null from doKeyDown
-            mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
+            mMovement.onKeyUp(this, mSpannable, keyCode, up);
             while (--repeatCount > 0) {
-                mMovement.onKeyDown(this, (Spannable) mText, keyCode, down);
-                mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
+                mMovement.onKeyDown(this, mSpannable, keyCode, down);
+                mMovement.onKeyUp(this, mSpannable, keyCode, up);
             }
         }
 
@@ -7694,8 +7704,7 @@
             boolean doDown = true;
             if (otherEvent != null) {
                 try {
-                    boolean handled = mMovement.onKeyOther(this, (Spannable) mText,
-                            otherEvent);
+                    boolean handled = mMovement.onKeyOther(this, mSpannable, otherEvent);
                     doDown = false;
                     if (handled) {
                         return KEY_EVENT_HANDLED;
@@ -7706,7 +7715,7 @@
                 }
             }
             if (doDown) {
-                if (mMovement.onKeyDown(this, (Spannable) mText, keyCode, event)) {
+                if (mMovement.onKeyDown(this, mSpannable, keyCode, event)) {
                     if (event.getRepeatCount() == 0 && !KeyEvent.isModifierKey(keyCode)) {
                         mPreventDefaultMovement = true;
                     }
@@ -7848,7 +7857,7 @@
         }
 
         if (mMovement != null && mLayout != null) {
-            if (mMovement.onKeyUp(this, (Spannable) mText, keyCode, event)) {
+            if (mMovement.onKeyUp(this, mSpannable, keyCode, event)) {
                 return true;
             }
         }
@@ -8314,13 +8323,23 @@
     }
 
     /**
+     * Returns true if DynamicLayout is required
+     *
+     * @hide
+     */
+    @VisibleForTesting
+    public boolean useDynamicLayout() {
+        return isTextSelectable() || (mSpannable != null && mPrecomputed == null);
+    }
+
+    /**
      * @hide
      */
     protected Layout makeSingleLayout(int wantWidth, BoringLayout.Metrics boring, int ellipsisWidth,
             Layout.Alignment alignment, boolean shouldEllipsize, TruncateAt effectiveEllipsize,
             boolean useSaved) {
         Layout result = null;
-        if (mText instanceof Spannable) {
+        if (useDynamicLayout()) {
             final DynamicLayout.Builder builder = DynamicLayout.Builder.obtain(mText, mTextPaint,
                     wantWidth)
                     .setDisplayText(mTransformed)
@@ -9262,7 +9281,7 @@
         }
 
         if (newStart != start) {
-            Selection.setSelection((Spannable) mText, newStart);
+            Selection.setSelection(mSpannable, newStart);
             return true;
         }
 
@@ -9999,9 +10018,8 @@
         if (mEditor != null) mEditor.onFocusChanged(focused, direction);
 
         if (focused) {
-            if (mText instanceof Spannable) {
-                Spannable sp = (Spannable) mText;
-                MetaKeyKeyListener.resetMetaState(sp);
+            if (mSpannable != null) {
+                MetaKeyKeyListener.resetMetaState(mSpannable);
             }
         }
 
@@ -10039,7 +10057,7 @@
      */
     public void clearComposingText() {
         if (mText instanceof Spannable) {
-            BaseInputConnection.removeComposingSpans((Spannable) mText);
+            BaseInputConnection.removeComposingSpans(mSpannable);
         }
     }
 
@@ -10095,7 +10113,7 @@
             boolean handled = false;
 
             if (mMovement != null) {
-                handled |= mMovement.onTouchEvent(this, (Spannable) mText, event);
+                handled |= mMovement.onTouchEvent(this, mSpannable, event);
             }
 
             final boolean textIsSelectable = isTextSelectable();
@@ -10103,7 +10121,7 @@
                 // The LinkMovementMethod which should handle taps on links has not been installed
                 // on non editable text that support text selection.
                 // We reproduce its behavior here to open links for these.
-                ClickableSpan[] links = ((Spannable) mText).getSpans(getSelectionStart(),
+                ClickableSpan[] links = mSpannable.getSpans(getSelectionStart(),
                     getSelectionEnd(), ClickableSpan.class);
 
                 if (links.length > 0) {
@@ -10138,7 +10156,7 @@
     public boolean onGenericMotionEvent(MotionEvent event) {
         if (mMovement != null && mText instanceof Spannable && mLayout != null) {
             try {
-                if (mMovement.onGenericMotionEvent(this, (Spannable) mText, event)) {
+                if (mMovement.onGenericMotionEvent(this, mSpannable, event)) {
                     return true;
                 }
             } catch (AbstractMethodError ex) {
@@ -10199,8 +10217,8 @@
 
     @Override
     public boolean onTrackballEvent(MotionEvent event) {
-        if (mMovement != null && mText instanceof Spannable && mLayout != null) {
-            if (mMovement.onTrackballEvent(this, (Spannable) mText, event)) {
+        if (mMovement != null && mSpannable != null && mLayout != null) {
+            if (mMovement.onTrackballEvent(this, mSpannable, event)) {
                 return true;
             }
         }
@@ -11121,7 +11139,7 @@
                 if (mText != null) {
                     int updatedTextLength = mText.length();
                     if (updatedTextLength > 0) {
-                        Selection.setSelection((Spannable) mText, updatedTextLength);
+                        Selection.setSelection(mSpannable, updatedTextLength);
                     }
                 }
             } return true;
@@ -11593,6 +11611,13 @@
         }
     }
 
+    /** @hide */
+    public void hideFloatingToolbar(int durationMs) {
+        if (mEditor != null) {
+            mEditor.hideFloatingToolbar(durationMs);
+        }
+    }
+
     boolean canUndo() {
         return mEditor != null && mEditor.canUndo();
     }
@@ -11687,10 +11712,10 @@
     boolean selectAllText() {
         if (mEditor != null) {
             // Hide the toolbar before changing the selection to avoid flickering.
-            mEditor.hideFloatingToolbar(FLOATING_TOOLBAR_SELECT_ALL_REFRESH_DELAY);
+            hideFloatingToolbar(FLOATING_TOOLBAR_SELECT_ALL_REFRESH_DELAY);
         }
         final int length = mText.length();
-        Selection.setSelection((Spannable) mText, 0, length);
+        Selection.setSelection(mSpannable, 0, length);
         return length > 0;
     }
 
@@ -11718,7 +11743,7 @@
                 }
                 if (paste != null) {
                     if (!didFirst) {
-                        Selection.setSelection((Spannable) mText, max);
+                        Selection.setSelection(mSpannable, max);
                         ((Editable) mText).replace(min, max, paste);
                         didFirst = true;
                     } else {
@@ -11740,7 +11765,7 @@
             selectedText = TextUtils.trimToParcelableSize(selectedText);
             sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, selectedText);
             getContext().startActivity(Intent.createChooser(sharingIntent, null));
-            Selection.setSelection((Spannable) mText, getSelectionEnd());
+            Selection.setSelection(mSpannable, getSelectionEnd());
         }
     }
 
@@ -11815,7 +11840,7 @@
             case DragEvent.ACTION_DRAG_LOCATION:
                 if (mText instanceof Spannable) {
                     final int offset = getOffsetForPosition(event.getX(), event.getY());
-                    Selection.setSelection((Spannable) mText, offset);
+                    Selection.setSelection(mSpannable, offset);
                 }
                 return true;
 
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 66035f4..9467ecc 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -652,7 +652,7 @@
         String args[] = {
             "--setuid=1000",
             "--setgid=1000",
-            "--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,1021,1023,1032,1065,3001,3002,3003,3006,3007,3009,3010",
+            "--setgroups=1001,1002,1003,1004,1005,1006,1007,1008,1009,1010,1018,1021,1023,1024,1032,1065,3001,3002,3003,3006,3007,3009,3010",
             "--capabilities=" + capabilities + "," + capabilities,
             "--nice-name=system_server",
             "--runtime-args",
diff --git a/core/java/com/android/server/NetworkManagementSocketTagger.java b/core/java/com/android/server/NetworkManagementSocketTagger.java
index 03f2bc1..2959667 100644
--- a/core/java/com/android/server/NetworkManagementSocketTagger.java
+++ b/core/java/com/android/server/NetworkManagementSocketTagger.java
@@ -67,6 +67,10 @@
         return old;
     }
 
+    public static int getThreadSocketStatsUid() {
+        return threadSocketTags.get().statsUid;
+    }
+
     @Override
     public void tag(FileDescriptor fd) throws SocketException {
         final SocketTags options = threadSocketTags.get();
diff --git a/core/proto/README.md b/core/proto/README.md
index d2b89a5..78809fa 100644
--- a/core/proto/README.md
+++ b/core/proto/README.md
@@ -8,7 +8,7 @@
 1. If the proto describes the top level output of dumpsys, it should contain
    `Dump`. This makes it easy to understand that the proto is the dumpsys output
    of a certain service, not the data structure of that service, e.g.
-   `WindowManagerServiceDumpProto` vs `WindowManagerServiceDumpProto`.
+   `WindowManagerServiceDumpProto` vs `WindowManagerServiceProto`.
 
    * Inner messages whose containing messages have the `Proto` suffix do not
      need to have a `Proto` suffix. E.g:
diff --git a/core/proto/android/providers/settings.proto b/core/proto/android/providers/settings.proto
index 89665db..7f8bed5 100644
--- a/core/proto/android/providers/settings.proto
+++ b/core/proto/android/providers/settings.proto
@@ -20,6 +20,8 @@
 option java_multiple_files = true;
 option java_outer_classname = "SettingsServiceProto";
 
+import "frameworks/base/core/proto/android/providers/settings/common.proto";
+import "frameworks/base/core/proto/android/providers/settings/global.proto";
 import "frameworks/base/libs/incident/proto/android/privacy.proto";
 
 message SettingsServiceDumpProto {
@@ -47,470 +49,6 @@
 
 // Note: it's a conscious decision to add each setting as a separate field. This
 // allows annotating each setting with its own privacy tag.
-message GlobalSettingsProto {
-    option (android.msg_privacy).dest = DEST_EXPLICIT;
-
-    repeated SettingsOperationProto historical_operations = 1;
-
-    optional SettingProto add_users_when_locked = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enable_accessibility_global_gesture_enabled = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto airplane_mode_on = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto theater_mode_on = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // A comma-separated list of radios that need to be disabled when airplane
-    // mode is on. This overrides wifi_on and bluetooth_on if wifi and bluetooth
-    // are included in the comma-separated list.
-    optional SettingProto airplane_mode_radios = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto airplane_mode_toggleable_radios = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto bluetooth_class_of_device = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto bluetooth_disabled_profiles = 9;
-    optional SettingProto bluetooth_interoperability_list = 10;
-    optional SettingProto wifi_sleep_policy = 11 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto auto_time = 12 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto auto_time_zone = 13 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto car_dock_sound = 14;
-    optional SettingProto car_undock_sound = 15;
-    optional SettingProto desk_dock_sound = 16;
-    optional SettingProto desk_undock_sound = 17;
-    optional SettingProto dock_sounds_enabled = 18 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dock_sounds_enabled_when_accessibility = 19 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto lock_sound = 20;
-    optional SettingProto unlock_sound = 21;
-    optional SettingProto trusted_sound = 22;
-    optional SettingProto low_battery_sound = 23;
-    optional SettingProto power_sounds_enabled = 24 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wireless_charging_started_sound = 25;
-    optional SettingProto charging_sounds_enabled = 26 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto stay_on_while_plugged_in = 27 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto bugreport_in_power_menu = 28 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto adb_enabled = 29 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Whether views are allowed to save their attribute data.
-    optional SettingProto debug_view_attributes = 30 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto assisted_gps_enabled = 31 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto bluetooth_on = 32 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto cdma_cell_broadcast_sms = 33 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto cdma_roaming_mode = 34 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto cdma_subscription_mode = 35 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto data_activity_timeout_mobile = 36 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto data_activity_timeout_wifi = 37 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto data_roaming = 38 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto mdc_initial_max_retry = 39 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto force_allow_on_external = 40 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto euicc_provisioned = 41 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto development_force_resizable_activities = 42 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto development_enable_freeform_windows_support = 43 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto development_settings_enabled = 44 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto device_provisioned = 45 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto device_provisioning_mobile_data_enabled = 46 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto display_size_forced = 47 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto display_scaling_force = 48 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto download_max_bytes_over_mobile = 49 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto download_recommended_max_bytes_over_mobile = 50 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto hdmi_control_enabled = 51 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto hdmi_system_audio_control_enabled = 52 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto hdmi_control_auto_wakeup_enabled = 53 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto hdmi_control_auto_device_off_enabled = 54 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // If true, out-of-the-box execution for priv apps is enabled.
-    optional SettingProto priv_app_oob_enabled = 55 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto location_background_throttle_interval_ms = 56 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto location_background_throttle_proximity_alert_interval_ms = 57 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Packages that are whitelisted for background throttling (throttling will
-    // not be applied).
-    optional SettingProto location_background_throttle_package_whitelist = 58 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_scan_background_throttle_interval_ms = 59 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_scan_background_throttle_package_whitelist = 60 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto mhl_input_switching_enabled = 61 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto mhl_power_charge_enabled = 62 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto mobile_data = 63 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto mobile_data_always_on = 64 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto connectivity_metrics_buffer_size = 65 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_enabled = 66 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_poll_interval = 67 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_time_cache_max_age = 68 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_global_alert_bytes = 69 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_sample_enabled = 70 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_augment_enabled = 71 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_dev_bucket_duration = 72 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_dev_persist_bytes = 73 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_dev_rotate_age = 74 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_dev_delete_age = 75 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_uid_bucket_duration = 76 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_uid_persist_bytes = 77 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_uid_rotate_age = 78 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_uid_delete_age = 79 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_uid_tag_bucket_duration = 80 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_uid_tag_persist_bytes = 81 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_uid_tag_rotate_age = 82 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto netstats_uid_tag_delete_age = 83 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // User preference for which network(s) should be used.
-    optional SettingProto network_preference = 84;
-    optional SettingProto network_scorer_app = 85 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto night_display_forced_auto_mode_available = 86 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto nitz_update_diff = 87 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto nitz_update_spacing = 88 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ntp_server = 89;
-    optional SettingProto ntp_timeout = 90 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto storage_benchmark_interval = 91 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dns_resolver_sample_validity_seconds = 92 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dns_resolver_success_threshold_percent = 93 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dns_resolver_min_samples = 94 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dns_resolver_max_samples = 95 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Whether to disable the automatic scheduling of system updates.
-    optional SettingProto ota_disable_automatic_update = 96 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto package_verifier_enable = 97 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto package_verifier_timeout = 98 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto package_verifier_default_response = 99;
-    optional SettingProto package_verifier_setting_visible = 100 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto package_verifier_include_adb = 101 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto fstrim_mandatory_interval = 102 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto pdp_watchdog_poll_interval_ms = 103 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto pdp_watchdog_long_poll_interval_ms = 104 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto pdp_watchdog_error_poll_interval_ms = 105 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto pdp_watchdog_trigger_packet_count = 106 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto pdp_watchdog_error_poll_count = 107 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto pdp_watchdog_max_pdp_reset_fail_count = 108 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto setup_prepaid_data_service_url = 109;
-    optional SettingProto setup_prepaid_detection_target_url = 110;
-    optional SettingProto setup_prepaid_detection_redir_host = 111;
-    optional SettingProto sms_outgoing_check_interval_ms = 112 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sms_outgoing_check_max_count = 113 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Used to disable SMS short code confirmation. Defaults to true.
-    optional SettingProto sms_short_code_confirmation = 114 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sms_short_code_rule = 115 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto tcp_default_init_rwnd = 116 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto tether_supported = 117 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto tether_dun_required = 118 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto tether_dun_apn = 119;
-    optional SettingProto tether_offload_disabled = 120 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // List of carrier app certificate mapped to carrier app package id which are whitelisted to
-    // prompt the user for install when a SIM card with matching UICC carrier privilege rules is
-    // inserted.
-    optional SettingProto carrier_app_whitelist = 121 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto carrier_app_names = 122 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto usb_mass_storage_enabled = 123 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto use_google_mail = 124 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto webview_data_reduction_proxy_key = 125;
-    optional SettingProto webview_fallback_logic_enabled = 126 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Name of the package used as WebView provider.
-    optional SettingProto webview_provider = 127 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto webview_multiprocess = 128 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_switch_notification_daily_limit = 129 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_switch_notification_rate_limit_millis = 130 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_avoid_bad_wifi = 131 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_metered_multipath_preference = 132 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_watchlist_last_report_time = 133 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_badging_thresholds = 134 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_display_on = 135 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_display_certification_on = 136 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_display_wps_config = 137 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_networks_available_notification_on = 138 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_carrier_networks_available_notification_on = 139 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wimax_networks_available_notification_on = 140 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_networks_available_repeat_delay = 141 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_country_code = 142;
-    optional SettingProto wifi_framework_scan_interval_ms = 143 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_idle_ms = 144 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_num_open_networks_kept = 145 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_on = 146 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_scan_always_available = 147 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto soft_ap_timeout_enabled = 148 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_wakeup_enabled = 149 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_scoring_ui_enabled = 150 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto speed_label_cache_eviction_age_millis = 151 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto recommended_network_evaluator_cache_expiry_ms = 152 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_recommendations_enabled = 153 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_recommendations_package = 154 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto use_open_wifi_package = 155 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_recommendation_request_timeout_ms = 156 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ble_scan_always_available = 157 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ble_scan_low_power_window_ms = 158 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ble_scan_balanced_window_ms = 159 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ble_scan_low_latency_window_ms = 160 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ble_scan_low_power_interval_ms = 161 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ble_scan_balanced_interval_ms = 162 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ble_scan_low_latency_interval_ms = 163 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ble_scan_background_mode = 389 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_saved_state = 164 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_supplicant_scan_interval_ms = 165 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_enhanced_auto_join = 166 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_network_show_rssi = 167 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_scan_interval_when_p2p_connected_ms = 168 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_watchdog_on = 169 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_watchdog_poor_network_test_enabled = 170 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_suspend_optimizations_enabled = 171 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_verbose_logging_enabled = 172 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_connected_mac_randomization_enabled = 173 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_max_dhcp_retry_count = 174 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_mobile_data_transition_wakelock_timeout_ms = 175 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_device_owner_configs_lockdown = 176 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_frequency_band = 177 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_p2p_device_name = 178;
-    optional SettingProto wifi_reenable_delay_ms = 179 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_ephemeral_out_of_range_timeout_ms = 180 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto data_stall_alarm_non_aggressive_delay_in_ms = 181 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto data_stall_alarm_aggressive_delay_in_ms = 182 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto provisioning_apn_alarm_delay_in_ms = 183 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto gprs_register_check_period_ms = 184 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wtf_is_fatal = 185 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Ringer mode. A change in this value will not reflect as a change in the
-    // ringer mode.
-    optional SettingProto mode_ringer = 186 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Overlay display devices setting.
-    // The value is a specially formatted string that describes the size and
-    // density of simulated secondary devices.
-    // Format: {width}x{height}/dpi;...
-    optional SettingProto overlay_display_devices = 187 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto battery_discharge_duration_threshold = 188 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto battery_discharge_threshold = 189 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto send_action_app_error = 190 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dropbox_age_seconds = 191 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dropbox_max_files = 192 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dropbox_quota_kb = 193 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dropbox_quota_percent = 194 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dropbox_reserve_percent = 195 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    repeated SettingProto dropbox_settings = 196;
-    repeated SettingProto error_logcat_lines = 197;
-    optional SettingProto sys_free_storage_log_interval = 198 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto disk_free_change_reporting_threshold = 199 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sys_storage_threshold_percentage = 200 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sys_storage_threshold_max_bytes = 201 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sys_storage_full_threshold_bytes = 202 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sys_storage_cache_percentage = 203 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sys_storage_cache_max_bytes = 204 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sync_max_retry_delay_in_seconds = 205 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto connectivity_change_delay = 206 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto connectivity_sampling_interval_in_seconds = 207 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto pac_change_delay = 208 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto captive_portal_mode = 209 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto captive_portal_detection_enabled = 210 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto captive_portal_server = 211;
-    optional SettingProto captive_portal_https_url = 212;
-    optional SettingProto captive_portal_http_url = 213;
-    optional SettingProto captive_portal_fallback_url = 214;
-    optional SettingProto captive_portal_other_fallback_urls = 215;
-    optional SettingProto captive_portal_use_https = 216 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto captive_portal_user_agent = 217;
-    optional SettingProto nsd_on = 218 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Let user pick default install location.
-    optional SettingProto set_install_location = 219 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto default_install_location = 220 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto inet_condition_debounce_up_delay = 221 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto inet_condition_debounce_down_delay = 222 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto read_external_storage_enforced_default = 223 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto http_proxy = 224;
-    optional SettingProto global_http_proxy_host = 225;
-    optional SettingProto global_http_proxy_port = 226;
-    optional SettingProto global_http_proxy_exclusion_list = 227;
-    optional SettingProto global_http_proxy_pac = 228;
-    // Enables the UI setting to allow the user to specify the global HTTP proxy
-    // and associated exclusion list.
-    optional SettingProto set_global_http_proxy = 229 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto default_dns_server = 230;
-    // The requested Private DNS mode and an accompanying specifier.
-    optional SettingProto private_dns_mode = 231;
-    optional SettingProto private_dns_specifier = 232;
-    repeated SettingProto bluetooth_headset_priorities = 233;
-    repeated SettingProto bluetooth_a2dp_sink_priorities = 234;
-    repeated SettingProto bluetooth_a2dp_src_priorities = 235;
-    repeated SettingProto bluetooth_a2dp_supports_optional_codecs = 236;
-    repeated SettingProto bluetooth_a2dp_optional_codecs_enabled = 237;
-    repeated SettingProto bluetooth_input_device_priorities = 238;
-    repeated SettingProto bluetooth_map_priorities = 239;
-    repeated SettingProto bluetooth_map_client_priorities = 240;
-    repeated SettingProto bluetooth_pbap_client_priorities = 241;
-    repeated SettingProto bluetooth_sap_priorities = 242;
-    repeated SettingProto bluetooth_pan_priorities = 243;
-    repeated SettingProto bluetooth_hearing_aid_priorities = 244;
-    // These are key=value lists, separated by commas.
-    optional SettingProto activity_manager_constants = 245;
-    optional SettingProto device_idle_constants = 246;
-    optional SettingProto battery_saver_constants = 247;
-    optional SettingProto battery_saver_device_specific_constants = 248;
-    optional SettingProto battery_tip_constants = 249;
-    optional SettingProto anomaly_detection_constants = 250;
-    // Version of the anomaly config.
-    optional SettingProto anomaly_config_version = 251 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // A base64-encoded string represents anomaly stats config.
-    optional SettingProto anomaly_config = 252;
-    // This is a key=value list, separated by commas.
-    optional SettingProto always_on_display_constants = 253;
-    // System VDSO global setting. This links to the "sys.vdso" system property.
-    // The following values are supported:
-    // false  -> both 32 and 64 bit vdso disabled
-    // 32     -> 32 bit vdso enabled
-    // 64     -> 64 bit vdso enabled
-    // Any other value defaults to both 32 bit and 64 bit true.
-    optional SettingProto sys_vdso = 254 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // UidCpuPower global setting. This links the sys.uidcpupower system property.
-    // The following values are supported:
-    // 0 -> /proc/uid_cpupower/* are disabled
-    // 1 -> /proc/uid_cpupower/* are enabled
-    // Any other value defaults to enabled.
-    optional SettingProto sys_uidcpupower = 255 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // An integer to reduce the FPS by this factor. Only for experiments.
-    optional SettingProto fps_divisor = 256 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Flag to enable or disable display panel low power mode (lpm)
-    // false -> Display panel power saving mode is disabled.
-    // true  -> Display panel power saving mode is enabled.
-    optional SettingProto display_panel_lpm = 257 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // These are key=value lists, separated by commas.
-    optional SettingProto app_idle_constants = 258;
-    optional SettingProto power_manager_constants = 259;
-    optional SettingProto alarm_manager_constants = 260;
-    optional SettingProto job_scheduler_constants = 261;
-    optional SettingProto shortcut_manager_constants = 262;
-    optional SettingProto device_policy_constants = 263;
-    optional SettingProto text_classifier_constants = 264;
-    optional SettingProto battery_stats_constants = 265;
-    optional SettingProto sync_manager_constants = 266;
-    optional SettingProto app_standby_enabled = 267 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto app_auto_restriction_enabled = 268 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto forced_app_standby_enabled = 269 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto forced_app_standby_for_small_battery_enabled = 270 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto off_body_radios_off_for_small_battery_enabled = 271 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto off_body_radios_off_delay_ms = 272 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_on_when_proxy_disconnected = 273 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto time_only_mode_constants = 274 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_watchlist_enabled = 275 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto keep_profile_in_background = 276 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto window_animation_scale = 277 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto transition_animation_scale = 278 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto animator_duration_scale = 279 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto fancy_ime_animations = 280 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto compatibility_mode = 281 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto emergency_tone = 282 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto call_auto_retry = 283 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto emergency_affordance_needed = 284 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto preferred_network_mode = 285 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Name of an application package to be debugged.
-    optional SettingProto debug_app = 286;
-    optional SettingProto wait_for_debugger = 287 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enable_gpu_debug_layers = 288 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // App allowed to load GPU debug layers.
-    optional SettingProto gpu_debug_app = 289;
-    optional SettingProto gpu_debug_layers = 290 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto low_power_mode = 291 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Battery level [1-100] at which low power mode automatically turns on. If
-    // 0, it will not automatically turn on.
-    optional SettingProto low_power_mode_trigger_level = 292 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // The max value for {@link #LOW_POWER_MODE_TRIGGER_LEVEL}. If this setting
-    // is not set or the value is 0, the default max will be used.
-    optional SettingProto low_power_mode_trigger_level_max = 293 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto always_finish_activities = 294 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto dock_audio_media_enabled = 295 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto encoded_surround_output = 296 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto audio_safe_volume_state = 297 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto tzinfo_update_content_url = 298;
-    optional SettingProto tzinfo_update_metadata_url = 299;
-    optional SettingProto selinux_update_content_url = 300;
-    optional SettingProto selinux_update_metadata_url = 301;
-    optional SettingProto sms_short_codes_update_content_url = 302;
-    optional SettingProto sms_short_codes_update_metadata_url = 303;
-    optional SettingProto apn_db_update_content_url = 304;
-    optional SettingProto apn_db_update_metadata_url = 305;
-    optional SettingProto cert_pin_update_content_url = 306;
-    optional SettingProto cert_pin_update_metadata_url = 307;
-    optional SettingProto intent_firewall_update_content_url = 308;
-    optional SettingProto intent_firewall_update_metadata_url = 309;
-    optional SettingProto lang_id_update_content_url = 310;
-    optional SettingProto lang_id_update_metadata_url = 311;
-    optional SettingProto smart_selection_update_content_url = 312;
-    optional SettingProto smart_selection_update_metadata_url = 313;
-    optional SettingProto selinux_status = 314 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto development_force_rtl = 315 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto low_battery_sound_timeout = 316 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wifi_bounce_delay_override_ms = 317 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto policy_control = 318 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto emulate_display_cutout = 319 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto zen_mode = 320 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto zen_mode_ringer_level = 321 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto zen_mode_config_etag = 322;
-    // If 0, turning on dnd manually will last indefinitely. Else if
-    // non-negative, turning on dnd manually will last for this many minutes.
-    // Else (if negative), turning on dnd manually will surface a dialog that
-    // prompts user to specify a duration.
-    optional SettingProto zen_duration = 323 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto heads_up_notifications_enabled = 324 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto device_name = 325;
-    optional SettingProto network_scoring_provisioned = 326 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto require_password_to_decrypt = 327 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enhanced_4g_mode_enabled = 328 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto vt_ims_enabled = 329 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wfc_ims_enabled = 330 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wfc_ims_mode = 331 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wfc_ims_roaming_mode = 332 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto wfc_ims_roaming_enabled = 333 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto lte_service_forced = 334 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto ephemeral_cookie_max_size_bytes = 335 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enable_ephemeral_feature = 336 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto instant_app_dexopt_enabled = 337 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto installed_instant_app_min_cache_period = 338 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto installed_instant_app_max_cache_period = 339 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto uninstalled_instant_app_min_cache_period = 340 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto uninstalled_instant_app_max_cache_period = 341 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto unused_static_shared_lib_min_cache_period = 342 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto allow_user_switching_when_system_user_locked = 343 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto boot_count = 344 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto safe_boot_disallowed = 345 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto device_demo_mode = 346 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto network_access_timeout_ms = 347 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto database_downgrade_reason = 348;
-    optional SettingProto database_creation_buildid = 349 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto contacts_database_wal_enabled = 350 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto location_settings_link_to_permissions_enabled = 351 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto euicc_factory_reset_timeout_millis = 352 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto storage_settings_clobber_threshold = 353 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // If set to 1, {@link Secure#LOCATION_MODE} will be set to {@link
-    // Secure#LOCATION_MODE_OFF} temporarily for all users.
-    optional SettingProto location_global_kill_switch = 354 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // If set to 1, SettingsProvider's restoreAnyVersion="true" attribute will
-    // be ignored and restoring to lower version of platform API will be
-    // skipped.
-    optional SettingProto override_settings_provider_restore_any_version = 355 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto chained_battery_attribution_enabled = 356 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto autofill_compat_mode_allowed_packages = 357 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto hidden_api_blacklist_exemptions = 358 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto sound_trigger_detection_service_op_timeout = 387  [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto max_sound_trigger_detection_service_ops_per_day = 388  [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Subscription to be used for voice call on a multi sim device. The
-    // supported values are 0 = SUB1, 1 = SUB2 and etc.
-    optional SettingProto multi_sim_voice_call_subscription = 359 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto multi_sim_voice_prompt = 360 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto multi_sim_data_call_subscription = 361 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto multi_sim_sms_subscription = 362 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto multi_sim_sms_prompt = 363 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Whether to enable new contacts aggregator or not.
-    // 1 = enable, 0 = disable.
-    optional SettingProto new_contact_aggregator = 364 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto contact_metadata_sync_enabled = 365 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enable_cellular_on_boot = 366 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto max_notification_enqueue_rate = 367 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto show_notification_channel_warnings = 368 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto cell_on = 369 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto show_temperature_warning = 370 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto warning_temperature = 371 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enable_diskstats_logging = 372 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enable_cache_quota_calculation = 373 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enable_deletion_helper_no_threshold_toggle = 374 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto notification_snooze_options = 375 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    // Configuration flags for SQLite Compatibility WAL. Encoded as a key-value
-    // list, separated by commas.
-    // E.g.: compatibility_wal_supported=true, wal_syncmode=OFF
-    optional SettingProto sqlite_compatibility_wal_flags = 376 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto enable_gnss_raw_meas_full_tracking = 377 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto install_carrier_app_notification_persistent = 378 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto install_carrier_app_notification_sleep_millis = 379 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto zram_enabled = 380 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto smart_replies_in_notifications_flags = 381 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto show_first_crash_dialog = 382 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto show_restart_in_crash_dialog = 383 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingProto show_mute_in_crash_dialog = 384 [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingsProto show_zen_upgrade_notification = 385  [ (android.privacy).dest = DEST_AUTOMATIC ];
-    optional SettingsProto backup_agent_timeout_parameters = 386;
-    // Please insert fields in the same order as in
-    // frameworks/base/core/java/android/provider/Settings.java.
-    // Next tag = 390;
-}
-
 message SecureSettingsProto {
     option (android.msg_privacy).dest = DEST_EXPLICIT;
 
@@ -854,26 +392,6 @@
     // Next tag = 73;
 }
 
-message SettingProto {
-    // ID of the setting
-    optional string id = 1;
-
-    // Name of the setting
-    optional string name = 2;
-
-    // Package name of the setting
-    optional string pkg = 3;
-
-    // Value of this setting
-    optional string value = 4;
-
-    // Default value of this setting
-    optional string default_value = 5;
-
-    // Whether the default is set by the system
-    optional bool default_from_system = 6;
-}
-
 message SettingsProto {
     // Enum values gotten from Settings.java
     enum ScreenBrightnessMode {
@@ -881,14 +399,3 @@
         SCREEN_BRIGHTNESS_MODE_AUTOMATIC = 1;
     }
 }
-
-message SettingsOperationProto {
-    // When the operation happened
-    optional int64 timestamp = 1;
-
-    // Type of the operation
-    optional string operation = 2;
-
-    // Name of the setting that was affected (optional)
-    optional string setting = 3;
-}
diff --git a/core/proto/android/providers/settings/common.proto b/core/proto/android/providers/settings/common.proto
new file mode 100644
index 0000000..64ffefb6
--- /dev/null
+++ b/core/proto/android/providers/settings/common.proto
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2017 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 android.providers.settings;
+
+option java_multiple_files = true;
+
+message SettingProto {
+    // ID of the setting
+    optional string id = 1;
+
+    // Name of the setting
+    optional string name = 2;
+
+    // Package name of the setting
+    optional string pkg = 3;
+
+    // Value of this setting
+    optional string value = 4;
+
+    // Default value of this setting
+    optional string default_value = 5;
+
+    // Whether the default is set by the system
+    optional bool default_from_system = 6;
+}
+
+message SettingsOperationProto {
+    // When the operation happened
+    optional int64 timestamp = 1;
+
+    // Type of the operation
+    optional string operation = 2;
+
+    // Name of the setting that was affected (optional)
+    optional string setting = 3;
+}
diff --git a/core/proto/android/providers/settings/global.proto b/core/proto/android/providers/settings/global.proto
new file mode 100644
index 0000000..c7de947
--- /dev/null
+++ b/core/proto/android/providers/settings/global.proto
@@ -0,0 +1,942 @@
+/*
+ * Copyright (C) 2017 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 android.providers.settings;
+
+option java_multiple_files = true;
+
+import "frameworks/base/core/proto/android/providers/settings/common.proto";
+import "frameworks/base/libs/incident/proto/android/privacy.proto";
+
+// Note: it's a conscious decision to add each setting as a separate field. This
+// allows annotating each setting with its own privacy tag.
+message GlobalSettingsProto {
+    option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+    repeated SettingsOperationProto historical_operations = 1;
+
+    // These are key=value lists, separated by commas.
+    optional SettingProto activity_manager_constants = 2;
+    optional SettingProto adb_enabled = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto add_users_when_locked = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message AirplaneMode {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // "airplane_mode_on" in code.
+        optional SettingProto on = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // A comma-separated list of radios that need to be disabled when airplane
+        // mode is on. This overrides wifi_on and bluetooth_on if wifi and bluetooth
+        // are included in the comma-separated list.
+        optional SettingProto radios = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto toggleable_radios = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional AirplaneMode airplane_mode = 5;
+
+    optional SettingProto alarm_manager_constants = 6;
+    optional SettingProto allow_user_switching_when_system_user_locked = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    // This is a key=value list, separated by commas.
+    optional SettingProto always_on_display_constants = 8;
+    optional SettingProto always_finish_activities = 9 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto animator_duration_scale = 10 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Anomaly {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // "anomaly_detection_constants" in code.
+        optional SettingProto detection_constants = 1;
+        // Version of the anomaly config.
+        optional SettingProto config_version = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // A base64-encoded string represents anomaly stats config.
+        optional SettingProto config = 3;
+    }
+    optional Anomaly anomaly = 11;
+
+    message ApnDb {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto update_content_url = 1;
+        optional SettingProto update_metadata_url = 2;
+    }
+    optional ApnDb apn_db = 12;
+
+    message App {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // These are key=value lists, separated by commas.
+        optional SettingProto idle_constants = 1;
+        optional SettingProto standby_enabled = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto auto_restriction_enabled = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto forced_app_standby_enabled = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto forced_app_standby_for_small_battery_enabled = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional App app = 13;
+
+    optional SettingProto assisted_gps_enabled = 14 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto audio_safe_volume_state = 15 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Auto {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto time = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto time_zone = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Auto auto = 16;
+
+    optional SettingProto autofill_compat_mode_allowed_packages = 17 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto backup_agent_timeout_parameters = 18;
+
+    message Battery {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto discharge_duration_threshold = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto discharge_threshold = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto saver_constants = 3;
+        optional SettingProto saver_device_specific_constants = 4;
+        optional SettingProto stats_constants = 5;
+        optional SettingProto tip_constants = 6;
+    }
+    optional Battery battery = 19;
+
+    message BleScan {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto always_available = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto low_power_window_ms = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto balanced_window_ms = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto low_latency_window_ms = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto low_power_interval_ms = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto balanced_interval_ms = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto low_latency_interval_ms = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto background_mode = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional BleScan ble_scan = 20;
+
+    message Bluetooth {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto class_of_device = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto disabled_profiles = 2;
+        optional SettingProto interoperability_list = 3;
+        optional SettingProto on = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        repeated SettingProto headset_priorities = 5;
+        repeated SettingProto a2dp_sink_priorities = 6;
+        repeated SettingProto a2dp_src_priorities = 7;
+        repeated SettingProto a2dp_supports_optional_codecs = 8;
+        repeated SettingProto a2dp_optional_codecs_enabled = 9;
+        repeated SettingProto input_device_priorities = 10;
+        repeated SettingProto map_priorities = 11;
+        repeated SettingProto map_client_priorities = 12;
+        repeated SettingProto pbap_client_priorities = 13;
+        repeated SettingProto sap_priorities = 14;
+        repeated SettingProto pan_priorities = 15;
+        repeated SettingProto hearing_aid_priorities = 16;
+    }
+    optional Bluetooth bluetooth = 21;
+
+    optional SettingProto boot_count = 22 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto bugreport_in_power_menu = 23 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto call_auto_retry = 24 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message CaptivePortal {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto mode = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto detection_enabled = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto server = 3;
+        optional SettingProto https_url = 4;
+        optional SettingProto http_url = 5;
+        optional SettingProto fallback_url = 6;
+        optional SettingProto other_fallback_urls = 7;
+        optional SettingProto use_https = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto user_agent = 9;
+    }
+    optional CaptivePortal captive_portal = 25;
+
+    message Carrier {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // List of carrier app certificate mapped to carrier app package id which are whitelisted to
+        // prompt the user for install when a SIM card with matching UICC carrier privilege rules is
+        // inserted.
+        optional SettingProto app_whitelist = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto app_names = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto install_carrier_app_notification_persistent = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto install_carrier_app_notification_sleep_millis = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Carrier carrier = 26;
+
+    message Cdma {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto cell_broadcast_sms = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto roaming_mode = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto subscription_mode = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Cdma cdma = 27;
+
+    optional SettingProto cell_on = 28 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message CertPin {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto update_content_url = 1;
+        optional SettingProto update_metadata_url = 2;
+    }
+    optional CertPin cert_pin = 29;
+
+    optional SettingProto chained_battery_attribution_enabled = 30 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto compatibility_mode = 31 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Connectivity {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto metrics_buffer_size = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto change_delay = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto sampling_interval_in_seconds = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Connectivity connectivity = 32;
+
+    optional SettingProto contact_metadata_sync_enabled = 33 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto contacts_database_wal_enabled = 34 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Data {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto activity_timeout_mobile = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto activity_timeout_wifi = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto roaming = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto stall_alarm_non_aggressive_delay_in_ms = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto stall_alarm_aggressive_delay_in_ms = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Data data = 35;
+
+    message Database {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto downgrade_reason = 1;
+        optional SettingProto creation_buildid = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Database database = 36;
+
+    message Debug {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Name of an application package to be debugged.
+        optional SettingProto app = 1;
+        // Whether views are allowed to save their attribute data.
+        optional SettingProto view_attributes = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Debug debug = 37;
+
+    message Default {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto install_location = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto dns_server = 2;
+    }
+    optional Default default = 38;
+
+    message Development {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto settings_enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto force_resizable_activities = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto enable_freeform_windows_support = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto force_rtl = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto emulate_display_cutout = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Development development = 39;
+
+    message Device {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto name = 1;
+        optional SettingProto provisioned = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto provisioning_mobile_data_enabled = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto idle_constants = 4;
+        optional SettingProto policy_constants = 5;
+        optional SettingProto demo_mode = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Device device = 40;
+
+    optional SettingProto disk_free_change_reporting_threshold = 41 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Display {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto size_forced = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto scaling_force = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Flag to enable or disable display panel low power mode (lpm)
+        // false -> Display panel power saving mode is disabled.
+        // true  -> Display panel power saving mode is enabled.
+        optional SettingProto panel_lpm = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Display display = 42;
+
+    message DnsResolver {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto sample_validity_seconds = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto success_threshold_percent = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto min_samples = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto max_samples = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional DnsResolver dns_resolver = 43;
+
+    optional SettingProto dock_audio_media_enabled = 44 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Download {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto max_bytes_over_mobile = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto recommended_max_bytes_over_mobile = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Download download = 45;
+
+    message Dropbox {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto age_seconds = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto max_files = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto quota_kb = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto quota_percent = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto reserve_percent = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        repeated SettingProto settings = 6;
+    }
+    optional Dropbox dropbox = 46;
+
+    message Emergency {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto tone = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto affordance_needed = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Emergency emergency = 47;
+
+    message Enable {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto accessibility_global_gesture_enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto gpu_debug_layers = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto ephemeral_feature = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto cellular_on_boot = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto diskstats_logging = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto cache_quota_calculation = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto deletion_helper_no_threshold_toggle = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto gnss_raw_meas_full_tracking = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Enable enable = 48;
+
+    optional SettingProto encoded_surround_output = 49 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto enhanced_4g_mode_enabled = 50 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    repeated SettingProto error_logcat_lines = 51;
+
+    message Euicc {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto provisioned = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto factory_reset_timeout_millis = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Euicc euicc = 52;
+
+    optional SettingProto fancy_ime_animations = 53 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto force_allow_on_external = 54 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    // An integer to reduce the FPS by this factor. Only for experiments.
+    optional SettingProto fps_divisor = 55 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto fstrim_mandatory_interval = 56 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message GlobalHttpProxy {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Including Global.HTTP_PROXY is redundant since the data is also
+        // encompassed in the host and port fields.
+
+        optional SettingProto host = 1;
+        optional SettingProto port = 2;
+        optional SettingProto exclusion_list = 3;
+        optional SettingProto pac = 4;
+        // Enables the UI setting to allow the user to specify the global HTTP proxy
+        // and associated exclusion list. Simply "set_global_http_proxy".
+        optional SettingProto setting_ui_enabled = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional GlobalHttpProxy global_http_proxy = 57;
+
+    optional SettingProto gprs_register_check_period_ms = 58 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Gpu {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // App allowed to load GPU debug layers.
+        optional SettingProto debug_app = 1;
+        optional SettingProto debug_layers = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Gpu gpu = 59;
+
+    message Hdmi {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto control_enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto system_audio_control_enabled = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto control_auto_wakeup_enabled = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto control_auto_device_off_enabled = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Hdmi hdmi = 60;
+
+    optional SettingProto heads_up_notifications_enabled = 61 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto hidden_api_blacklist_exemptions = 62 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message InetCondition {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto debounce_up_delay = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto debounce_down_delay = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional InetCondition inet_condition = 63;
+
+    message InstantApp {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto dexopt_enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto ephemeral_cookie_max_size_bytes = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto installed_min_cache_period = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto installed_max_cache_period = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uninstalled_min_cache_period = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uninstalled_max_cache_period = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional InstantApp instant_app = 64;
+
+    message IntentFirewall {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto update_content_url = 1;
+        optional SettingProto update_metadata_url = 2;
+    }
+    optional IntentFirewall intent_firewall = 65;
+
+    optional SettingProto job_scheduler_constants = 66;
+    optional SettingProto keep_profile_in_background = 67 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message LangId {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto update_content_url = 1;
+        optional SettingProto update_metadata_url = 2;
+    }
+    optional LangId lang_id = 68;
+
+    message Location {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto background_throttle_interval_ms = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto background_throttle_proximity_alert_interval_ms = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Packages that are whitelisted for background throttling (throttling will
+        // not be applied).
+        optional SettingProto background_throttle_package_whitelist = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto settings_link_to_permissions_enabled = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // If set to 1, {@link Secure#LOCATION_MODE} will be set to {@link
+        // Secure#LOCATION_MODE_OFF} temporarily for all users.
+        optional SettingProto global_kill_switch = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Location location = 69;
+
+    message LowPowerMode {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Simply "low_power_mode" in code.
+        optional SettingProto enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Battery level [1-100] at which low power mode automatically turns on. If
+        // 0, it will not automatically turn on.
+        optional SettingProto trigger_level = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // The max value for {@link #LOW_POWER_MODE_TRIGGER_LEVEL}. If this setting
+        // is not set or the value is 0, the default max will be used.
+        optional SettingProto trigger_level_max = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional LowPowerMode low_power_mode = 70;
+
+    optional SettingProto lte_service_forced = 71 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto mdc_initial_max_retry = 72 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Mhl {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto input_switching_enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto power_charge_enabled = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Mhl mhl = 73;
+
+    message MobileData {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Whether mobile data connections are allowed by the user. Simply
+        // "mobile_data" in code.
+        optional SettingProto allowed = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Whether the mobile data connection should remain active even when higher
+        // priority networks like WiFi are active, to help make network switching
+        // faster.
+        optional SettingProto always_on = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional MobileData mobile_data = 74;
+
+    // Ringer mode. A change in this value will not reflect as a change in the
+    // ringer mode.
+    optional SettingProto mode_ringer = 75 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message MultiSim {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Subscription to be used for voice call on a multi sim device. The
+        // supported values are 0 = SUB1, 1 = SUB2 and etc.
+        optional SettingProto voice_call_subscription = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto voice_prompt = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto data_call_subscription = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto sms_subscription = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto sms_prompt = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional MultiSim multi_sim = 76;
+
+    message Netstats {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto poll_interval = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto time_cache_max_age = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto global_alert_bytes = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto sample_enabled = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto augment_enabled = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto dev_bucket_duration = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto dev_persist_bytes = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto dev_rotate_age = 9 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto dev_delete_age = 10 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uid_bucket_duration = 11 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uid_persist_bytes = 12 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uid_rotate_age = 13 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uid_delete_age = 14 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uid_tag_bucket_duration = 15 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uid_tag_persist_bytes = 16 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uid_tag_rotate_age = 17 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto uid_tag_delete_age = 18 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Netstats netstats = 77;
+
+    message Network {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // User preference for which network(s) should be used.
+        optional SettingProto preference = 1;
+        optional SettingProto preferred_network_mode = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto scorer_app = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto switch_notification_daily_limit = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto switch_notification_rate_limit_millis = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto avoid_bad_wifi = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto metered_multipath_preference = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto watchlist_last_report_time = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto scoring_ui_enabled = 9 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto recommendations_enabled = 10 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto recommendations_package = 11 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto recommendation_request_timeout_ms = 12 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto watchlist_enabled = 13 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto scoring_provisioned = 14 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto access_timeout_ms = 15 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto recommended_network_evaluator_cache_expiry_ms = 16 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Network network = 78;
+
+    // Whether to enable new contacts aggregator or not.
+    // 1 = enable, 0 = disable.
+    optional SettingProto new_contact_aggregator = 79 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto night_display_forced_auto_mode_available = 80 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message NitzUpdate {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // If the NITZ_UPDATE_DIFF time is exceeded then an automatic adjustment to
+        // SystemClock will be allowed even if NITZ_UPDATE_SPACING has not been
+        // exceeded.
+        optional SettingProto diff = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // The length of time in milli-seconds that automatic small adjustments to
+        // SystemClock are ignored if NITZ_UPDATE_DIFF is not exceeded.
+        optional SettingProto spacing = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional NitzUpdate nitz_update = 81;
+
+    message Notification {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto max_notification_enqueue_rate = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto show_notification_channel_warnings = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // The list of snooze options for notifications. This is encoded as a key=value list,
+        // separated by commas.
+        optional SettingProto snooze_options = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto smart_replies_in_notifications_flags = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Notification notification = 82;
+
+    optional SettingProto nsd_on = 83 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Ntp {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Preferred NTP server.
+        optional SettingProto server = 1;
+        // Timeout in milliseconds to wait for NTP server.
+        optional SettingProto timeout_ms = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Ntp ntp = 84;
+
+    // Details about the Off Body, Radios Off feature.
+    message OffBodyRadiosOff {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Whether or not to enable the Off Body, Radios Off feature on small battery devices.
+        optional SettingProto enabled_for_small_battery = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // How long after the device goes off body to disable radios, in milliseconds.
+        optional SettingProto delay_ms = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional OffBodyRadiosOff off_body_radios_off = 85;
+
+    // Whether to disable the automatic scheduling of system updates.
+    optional SettingProto ota_disable_automatic_update = 86 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    // Overlay display devices setting.
+    // The value is a specially formatted string that describes the size and
+    // density of simulated secondary devices.
+    // Format: {width}x{height}/dpi;...
+    optional SettingProto overlay_display_devices = 87 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    // If set to 1, SettingsProvider's restoreAnyVersion="true" attribute will
+    // be ignored and restoring to lower version of platform API will be
+    // skipped.
+    optional SettingProto override_settings_provider_restore_any_version = 88 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    // The series of successively longer delays used in retrying to download PAC file.
+    optional SettingProto pac_change_delay = 89 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message PackageVerifier {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Whether the package manager should send package verification broadcasts
+        // for verifiers to review apps prior to installation.
+        optional SettingProto enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto timeout = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto default_response = 3;
+        optional SettingProto setting_visible = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto include_adb = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional PackageVerifier package_verifier = 90;
+
+    message PdpWatchdog {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto poll_interval_ms = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto long_poll_interval_ms = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto error_poll_interval_ms = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto trigger_packet_count = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto error_poll_count = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto max_pdp_reset_fail_count = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional PdpWatchdog pdp_watchdog = 91;
+
+    // Defines global runtime overrides to window policy.
+    optional SettingProto policy_control = 92;
+    optional SettingProto power_manager_constants = 93;
+    // If true, out-of-the-box execution for priv apps is enabled.
+    optional SettingProto priv_app_oob_enabled = 94 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message PrepaidSetup {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // URL to open browser on to allow user to manage a prepay account.
+        optional SettingProto data_service_url = 1;
+        // URL to attempt a GET on to see if this is a prepay device.
+        optional SettingProto detection_target_url = 2;
+        // Host to check for a redirect to after an attempt to GET
+        // SETUP_PREPAID_DETECTION_TARGET_URL. (If we redirected there, this is a
+        // prepaid device with zero balance.)
+        optional SettingProto detection_redir_host = 3;
+    }
+    optional PrepaidSetup prepaid_setup = 95;
+
+    message Private {
+        option (android.msg_privacy).dest = DEST_LOCAL;
+
+        // The requested Private DNS mode and an accompanying specifier.
+        optional SettingProto dns_mode = 1;
+        optional SettingProto dns_specifier = 2;
+    }
+    optional Private private = 96;
+
+    // The number of milliseconds to allow the provisioning apn to remain active.
+    optional SettingProto provisioning_apn_alarm_delay_in_ms = 97 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto read_external_storage_enforced_default = 98 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto require_password_to_decrypt = 99 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto safe_boot_disallowed = 100 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Selinux {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto update_content_url = 1;
+        optional SettingProto update_metadata_url = 2;
+        optional SettingProto status = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Selinux selinux = 101;
+
+    // Flag for allowing ActivityManagerService to send ACTION_APP_ERROR intents
+    // on application crashes and ANRs. If this is disabled, the crash/ANR
+    // dialog will never display the "Report" button.
+    optional SettingProto send_action_app_error = 102 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    // Let user pick default install location.
+    optional SettingProto set_install_location = 103 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto shortcut_manager_constants = 104;
+    optional SettingProto show_first_crash_dialog = 105 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto show_restart_in_crash_dialog = 106 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto show_mute_in_crash_dialog = 107 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message SmartSelection {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto update_content_url = 1;
+        optional SettingProto update_metadata_url = 2;
+    }
+    optional SmartSelection smart_selection = 108;
+
+    message Sms {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto outgoing_check_interval_ms = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto outgoing_check_max_count = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Used to disable SMS short code confirmation. Defaults to true.
+        optional SettingProto short_code_confirmation = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto short_code_rule = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto short_codes_update_content_url = 5;
+        optional SettingProto short_codes_update_metadata_url = 6;
+    }
+    optional Sms sms = 109;
+
+    message Sounds {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto car_dock = 1;
+        optional SettingProto car_undock = 2;
+        optional SettingProto charging_sounds_enabled = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto charging_started = 4;
+        optional SettingProto desk_dock = 5;
+        optional SettingProto desk_undock = 6;
+        optional SettingProto dock_sounds_enabled = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto dock_sounds_enabled_when_accessibility = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto lock = 9;
+        optional SettingProto low_battery = 10;
+        optional SettingProto low_battery_sound_timeout = 11 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Called "power_sounds_enabled" in code.
+        optional SettingProto low_battery_sounds_enabled = 12 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto trusted = 13;
+        optional SettingProto unlock = 14;
+    }
+    optional Sounds sounds = 110;
+
+    message SoundTrigger {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // Maximum number of SoundTriggerDetectionService operations per day.
+        optional SettingProto max_sound_trigger_detection_service_ops_per_day = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Timeout for a single SoundTriggerDetectionService operation (in ms).
+        optional SettingProto detection_service_op_timeout_ms = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional SoundTrigger sound_trigger = 111;
+
+    // Value to specify how long in milliseconds to retain seen score cache
+    // curves to be used when generating SSID only bases score curves.
+    optional SettingProto speed_label_cache_eviction_age_ms = 112 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    // Configuration flags for SQLite Compatibility WAL. Encoded as a key-value
+    // list, separated by commas.
+    // E.g.: compatibility_wal_supported=true, wal_syncmode=OFF
+    optional SettingProto sqlite_compatibility_wal_flags = 113 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto stay_on_while_plugged_in = 114 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Storage {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto benchmark_interval = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto settings_clobber_threshold = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Storage storage = 115;
+
+    message Sync {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // The maximum reconnect delay for short network outages or when the network is suspended due to phone use.
+        optional SettingProto max_retry_delay_in_seconds = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Simply "sync_manager_constants" in code.
+        optional SettingProto manager_constants = 2;
+    }
+    optional Sync sync = 116;
+
+    message Sys {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        // The interval in minutes after which the amount of free storage left on
+        // the device is logged to the event log.
+        optional SettingProto free_storage_log_interval_mins = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto storage_threshold_percentage = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto storage_threshold_max_bytes = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto storage_full_threshold_bytes = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto storage_cache_percentage = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto storage_cache_max_bytes = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // System VDSO global setting. This links to the "sys.vdso" system property.
+        // The following values are supported:
+        // false  -> both 32 and 64 bit vdso disabled
+        // 32     -> 32 bit vdso enabled
+        // 64     -> 64 bit vdso enabled
+        // Any other value defaults to both 32 bit and 64 bit true.
+        optional SettingProto vdso = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // UidCpuPower global setting. This links the sys.uidcpupower system property.
+        // The following values are supported:
+        // 0 -> /proc/uid_cpupower/* are disabled
+        // 1 -> /proc/uid_cpupower/* are enabled
+        // Any other value defaults to enabled.
+        optional SettingProto uidcpupower = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Sys sys = 117;
+
+    optional SettingProto tcp_default_init_rwnd = 118 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message TemperatureWarning {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto show_temperature_warning = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Temperature at which the high temperature warning notification should
+        // be shown.
+        optional SettingProto warning_temperature_level = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional TemperatureWarning temperature_warning = 119;
+
+    message Tether {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto supported = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto dun_required = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto dun_apn = 3;
+        optional SettingProto offload_disabled = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Simply "soft_ap_timeout_enabled" in code.
+        optional SettingProto timeout_enabled = 112 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Tether tether = 120;
+
+    optional SettingProto text_classifier_constants = 121;
+    optional SettingProto theater_mode_on = 122 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto time_only_mode_constants = 123 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto transition_animation_scale = 124 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Tzinfo {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto update_content_url = 1;
+        optional SettingProto update_metadata_url = 2;
+    }
+    optional Tzinfo tzinfo = 125;
+
+    // The min period for caching unused static shared libs in milliseconds.
+    optional SettingProto unused_static_shared_lib_min_cache_period_ms = 126 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto usb_mass_storage_enabled = 127 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto use_google_mail = 128 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto use_open_wifi_package = 129 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto vt_ims_enabled = 130 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto wait_for_debugger = 131 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Webview {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto data_reduction_proxy_key = 1;
+        optional SettingProto fallback_logic_enabled = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        // Name of the package used as WebView provider.
+        optional SettingProto provider = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto multiprocess = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Webview webview = 132;
+
+    message Wfc {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto ims_enabled = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto ims_mode = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto ims_roaming_mode = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto ims_roaming_enabled = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Wfc wfc = 133;
+
+    message Wifi {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto sleep_policy = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto badging_thresholds = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto display_on = 3 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto display_certification_on = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto display_wps_config = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto networks_available_notification_on = 6 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto carrier_networks_available_notification_on = 7 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto networks_available_repeat_delay = 8 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto country_code = 9;
+        optional SettingProto framework_scan_interval_ms = 10 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto idle_ms = 11 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto num_open_networks_kept = 12 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto on = 13 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto scan_always_available = 14 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto wakeup_enabled = 15 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto saved_state = 16 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto supplicant_scan_interval_ms = 17 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto enhanced_auto_join = 18 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto network_show_rssi = 19 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto scan_interval_when_p2p_connected_ms = 20 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto watchdog_on = 21 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto watchdog_poor_network_test_enabled = 22 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto suspend_optimizations_enabled = 23 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto verbose_logging_enabled = 24 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto connected_mac_randomization_enabled = 25 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto max_dhcp_retry_count = 26 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto mobile_data_transition_wakelock_timeout_ms = 27 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto device_owner_configs_lockdown = 28 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto frequency_band = 29 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto p2p_device_name = 30;
+        optional SettingProto reenable_delay_ms = 31 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto ephemeral_out_of_range_timeout_ms = 32 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto on_when_proxy_disconnected = 33 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto bounce_delay_override_ms = 34 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Wifi wifi = 134;
+
+    optional SettingProto wimax_networks_available_notification_on = 135 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto window_animation_scale = 136 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    optional SettingProto wtf_is_fatal = 137 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    message Zen {
+        option (android.msg_privacy).dest = DEST_EXPLICIT;
+
+        optional SettingProto mode = 1 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto mode_ringer_level = 2 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto mode_config_etag = 3;
+        // If 0, turning on dnd manually will last indefinitely. Else if
+        // non-negative, turning on dnd manually will last for this many minutes.
+        // Else (if negative), turning on dnd manually will surface a dialog that
+        // prompts user to specify a duration.
+        optional SettingProto duration = 4 [ (android.privacy).dest = DEST_AUTOMATIC ];
+        optional SettingProto show_zen_upgrade_notification = 5 [ (android.privacy).dest = DEST_AUTOMATIC ];
+    }
+    optional Zen zen = 138;
+
+    optional SettingProto zram_enabled = 139 [ (android.privacy).dest = DEST_AUTOMATIC ];
+
+    // Please insert fields in alphabetical order and group them into messages
+    // if possible (to avoid reaching the method limit).
+    // Next tag = 140;
+}
diff --git a/core/proto/android/server/jobscheduler.proto b/core/proto/android/server/jobscheduler.proto
index 122e5c4..8d4b56c 100644
--- a/core/proto/android/server/jobscheduler.proto
+++ b/core/proto/android/server/jobscheduler.proto
@@ -514,7 +514,7 @@
         optional int32 uid = 3;
         // Job IDs can technically be negative.
         optional int32 job_id = 4;
-        optional string tag = 5 [ (.android.privacy).dest = DEST_EXPLICIT ];
+        optional string tag = 5;
         // Only valid for STOP_JOB or STOP_PERIODIC_JOB Events.
         optional .android.app.job.StopReasonEnum stop_reason = 6;
     }
@@ -538,7 +538,7 @@
 
     // The UID that scheduled the job.
     optional int32 calling_uid = 1;
-    optional string tag = 2 [ (.android.privacy).dest = DEST_EXPLICIT ];
+    optional string tag = 2;
 
     // The UID for which the job is being run.
     optional int32 source_uid = 3;
diff --git a/core/proto/android/server/powermanagerservice.proto b/core/proto/android/server/powermanagerservice.proto
index c58de56..eb60942 100644
--- a/core/proto/android/server/powermanagerservice.proto
+++ b/core/proto/android/server/powermanagerservice.proto
@@ -118,61 +118,60 @@
     // True if the sandman has just been summoned for the first time since entering
     // the dreaming or dozing state.  Indicates whether a new dream should begin.
     optional bool is_sandman_summoned = 23;
-    // If true, the device is in low power mode.
-    optional bool is_low_power_mode_enabled = 24;
     // True if the battery level is currently considered low.
-    optional bool is_battery_level_low = 25;
+    optional bool is_battery_level_low = 24;
     // True if we are currently in light device idle mode.
-    optional bool is_light_device_idle_mode = 26;
+    optional bool is_light_device_idle_mode = 25;
     // True if we are currently in device idle mode.
-    optional bool is_device_idle_mode = 27;
+    optional bool is_device_idle_mode = 26;
     // Set of app ids that we will always respect the wake locks for.
-    repeated int32 device_idle_whitelist = 28;
+    repeated int32 device_idle_whitelist = 27;
     // Set of app ids that are temporarily allowed to acquire wakelocks due to
     // high-pri message
-    repeated int32 device_idle_temp_whitelist = 29;
+    repeated int32 device_idle_temp_whitelist = 28;
     // Timestamp of the last time the device was awoken.
-    optional int64 last_wake_time_ms = 30;
+    optional int64 last_wake_time_ms = 29;
     // Timestamp of the last time the device was put to sleep.
-    optional int64 last_sleep_time_ms = 31;
+    optional int64 last_sleep_time_ms = 30;
     // Timestamp of the last call to user activity.
-    optional int64 last_user_activity_time_ms = 32;
-    optional int64 last_user_activity_time_no_change_lights_ms = 33;
+    optional int64 last_user_activity_time_ms = 31;
+    optional int64 last_user_activity_time_no_change_lights_ms = 32;
     // Timestamp of last interactive power hint.
-    optional int64 last_interactive_power_hint_time_ms = 34;
+    optional int64 last_interactive_power_hint_time_ms = 33;
     // Timestamp of the last screen brightness boost.
-    optional int64 last_screen_brightness_boost_time_ms = 35;
+    optional int64 last_screen_brightness_boost_time_ms = 34;
     // True if screen brightness boost is in progress.
-    optional bool is_screen_brightness_boost_in_progress = 36;
+    optional bool is_screen_brightness_boost_in_progress = 35;
     // True if the display power state has been fully applied, which means the
     // display is actually on or actually off or whatever was requested.
-    optional bool is_display_ready = 37;
+    optional bool is_display_ready = 36;
     // True if the wake lock suspend blocker has been acquired.
-    optional bool is_holding_wake_lock_suspend_blocker = 38;
+    optional bool is_holding_wake_lock_suspend_blocker = 37;
     // The suspend blocker used to keep the CPU alive when the display is on, the
     // display is getting ready or there is user activity (in which case the
     // display must be on).
-    optional bool is_holding_display_suspend_blocker = 39;
+    optional bool is_holding_display_suspend_blocker = 38;
     // Settings and configuration
-    optional PowerServiceSettingsAndConfigurationDumpProto settings_and_configuration = 40;
+    optional PowerServiceSettingsAndConfigurationDumpProto settings_and_configuration = 39;
     // Sleep timeout in ms. This can be -1.
-    optional sint32 sleep_timeout_ms = 41;
+    optional sint32 sleep_timeout_ms = 40;
     // Screen off timeout in ms
-    optional int32 screen_off_timeout_ms = 42;
+    optional int32 screen_off_timeout_ms = 41;
     // Screen dim duration in ms
-    optional int32 screen_dim_duration_ms = 43;
+    optional int32 screen_dim_duration_ms = 42;
     // We are currently in the middle of a batch change of uids.
-    optional bool are_uids_changing = 44;
+    optional bool are_uids_changing = 43;
     // Some uids have actually changed while mUidsChanging was true.
-    optional bool are_uids_changed = 45;
+    optional bool are_uids_changed = 44;
     // List of UIDs and their states
-    repeated UidStateProto uid_states = 46;
-    optional .android.os.LooperProto looper = 47;
+    repeated UidStateProto uid_states = 45;
+    optional .android.os.LooperProto looper = 46;
     // List of all wake locks acquired by applications.
-    repeated WakeLockProto wake_locks = 48;
+    repeated WakeLockProto wake_locks = 47;
     // List of all suspend blockers.
-    repeated SuspendBlockerProto suspend_blockers = 49;
-    optional WirelessChargerDetectorProto wireless_charger_detector = 50;
+    repeated SuspendBlockerProto suspend_blockers = 48;
+    optional WirelessChargerDetectorProto wireless_charger_detector = 49;
+    optional BatterySaverStateMachineProto battery_saver_state_machine = 50;
 }
 
 // A com.android.server.power.PowerManagerService.SuspendBlockerImpl object.
@@ -270,51 +269,80 @@
     optional bool are_dreams_activate_on_dock_setting = 17;
     // True if doze should not be started until after the screen off transition.
     optional bool is_doze_after_screen_off_config = 18;
-    // If true, the device is in low power mode.
-    optional bool is_low_power_mode_setting = 19;
-    // Current state of whether the settings are allowing auto low power mode.
-    optional bool is_auto_low_power_mode_configured = 20;
-    // The user turned off low power mode below the trigger level
-    optional bool is_auto_low_power_mode_snoozing = 21;
     // The minimum screen off timeout, in milliseconds.
-    optional int32 minimum_screen_off_timeout_config_ms = 22;
+    optional int32 minimum_screen_off_timeout_config_ms = 19;
     // The screen dim duration, in milliseconds.
-    optional int32 maximum_screen_dim_duration_config_ms = 23;
+    optional int32 maximum_screen_dim_duration_config_ms = 20;
     // The maximum screen dim time expressed as a ratio relative to the screen off timeout.
-    optional float maximum_screen_dim_ratio_config = 24;
+    optional float maximum_screen_dim_ratio_config = 21;
     // The screen off timeout setting value in milliseconds.
-    optional int32 screen_off_timeout_setting_ms = 25;
+    optional int32 screen_off_timeout_setting_ms = 22;
     // The sleep timeout setting value in milliseconds. Default value is -1.
-    optional sint32 sleep_timeout_setting_ms = 26;
+    optional sint32 sleep_timeout_setting_ms = 23;
     // The maximum allowable screen off timeout according to the device administration policy.
-    optional int32 maximum_screen_off_timeout_from_device_admin_ms = 27;
-    optional bool is_maximum_screen_off_timeout_from_device_admin_enforced_locked = 28;
+    optional int32 maximum_screen_off_timeout_from_device_admin_ms = 24;
+    optional bool is_maximum_screen_off_timeout_from_device_admin_enforced_locked = 25;
     // The stay on while plugged in setting.
     // A set of battery conditions under which to make the screen stay on.
-    optional StayOnWhilePluggedInProto stay_on_while_plugged_in = 29;
+    optional StayOnWhilePluggedInProto stay_on_while_plugged_in = 26;
     // The screen brightness mode.
-    optional .android.providers.settings.SettingsProto.ScreenBrightnessMode screen_brightness_mode_setting = 30;
+    optional .android.providers.settings.SettingsProto.ScreenBrightnessMode screen_brightness_mode_setting = 27;
     // The screen brightness setting override from the window manager
     // to allow the current foreground activity to override the brightness.
     // Use -1 to disable.
-    optional sint32 screen_brightness_override_from_window_manager = 31;
+    optional sint32 screen_brightness_override_from_window_manager = 28;
     // The user activity timeout override from the window manager
     // to allow the current foreground activity to override the user activity
     // timeout. Use -1 to disable.
-    optional sint64 user_activity_timeout_override_from_window_manager_ms = 32;
+    optional sint64 user_activity_timeout_override_from_window_manager_ms = 29;
     // The window manager has determined the user to be inactive via other means.
     // Set this to false to disable.
-    optional bool is_user_inactive_override_from_window_manager = 33;
+    optional bool is_user_inactive_override_from_window_manager = 30;
     // The screen state to use while dozing.
-    optional .android.view.DisplayStateEnum doze_screen_state_override_from_dream_manager = 34;
+    optional .android.view.DisplayStateEnum doze_screen_state_override_from_dream_manager = 31;
     // The screen brightness to use while dozing.
-    optional float dozed_screen_brightness_override_from_dream_manager = 35;
+    optional float dozed_screen_brightness_override_from_dream_manager = 32;
     // Screen brightness settings limits.
-    optional ScreenBrightnessSettingLimitsProto screen_brightness_setting_limits = 36;
+    optional ScreenBrightnessSettingLimitsProto screen_brightness_setting_limits = 33;
     // True if double tap to wake is enabled
-    optional bool is_double_tap_wake_enabled = 37;
+    optional bool is_double_tap_wake_enabled = 34;
     // True if we are currently in VR Mode.
-    optional bool is_vr_mode_enabled = 38;
+    optional bool is_vr_mode_enabled = 35;
     // True if Sidekick is controlling the display and we shouldn't change its power mode.
-    optional bool draw_wake_lock_override_from_sidekick = 39;
+    optional bool draw_wake_lock_override_from_sidekick = 36;
 }
+
+message BatterySaverStateMachineProto {
+   // Whether battery saver is enabled.
+   optional bool enabled = 1;
+
+   // Whether system has booted.
+   optional bool boot_completed = 2;
+
+   // Whether settings have been loaded already.
+   optional bool settings_loaded = 3;
+
+   // Whether battery status has been set at least once.
+   optional bool battery_status_set = 4;
+
+   // Whether automatic battery saver has been canceled by the user.
+   optional bool battery_saver_snoozing = 5;
+
+   // Whether the device is connected to any power source.
+   optional bool is_powered = 6;
+
+   // Current battery level in %, 0-100.
+   optional int32 battery_level = 7;
+
+   // Whether battery level is low or not.
+   optional bool is_battery_level_low = 8;
+
+   // The value of Global.LOW_POWER_MODE.
+   optional bool setting_battery_saver_enabled = 9;
+
+   // The value of Global.LOW_POWER_MODE_STICKY.
+   optional bool setting_battery_saver_enabled_sticky = 10;
+
+   // The value of Global.LOW_POWER_MODE_TRIGGER_LEVEL.
+   optional int32 setting_battery_saver_trigger_threshold = 11;
+}
\ No newline at end of file
diff --git a/core/tests/coretests/src/android/provider/SettingsBackupTest.java b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
index a504ab9..6ef773a 100644
--- a/core/tests/coretests/src/android/provider/SettingsBackupTest.java
+++ b/core/tests/coretests/src/android/provider/SettingsBackupTest.java
@@ -266,6 +266,7 @@
                     Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
                     Settings.Global.LOW_POWER_MODE,
                     Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL_MAX,
+                    Settings.Global.LOW_POWER_MODE_STICKY,
                     Settings.Global.LTE_SERVICE_FORCED,
                     Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE,
                     Settings.Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY,
diff --git a/core/tests/coretests/src/android/widget/TextViewTest.java b/core/tests/coretests/src/android/widget/TextViewTest.java
index 2b5b27b..4f1efbf 100644
--- a/core/tests/coretests/src/android/widget/TextViewTest.java
+++ b/core/tests/coretests/src/android/widget/TextViewTest.java
@@ -17,6 +17,7 @@
 package android.widget;
 
 import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertFalse;
 import static junit.framework.Assert.assertNotNull;
 import static junit.framework.Assert.assertTrue;
 
@@ -32,9 +33,11 @@
 import android.support.test.runner.AndroidJUnit4;
 import android.text.GetChars;
 import android.text.Layout;
+import android.text.PrecomputedText;
 import android.text.Selection;
 import android.text.Spannable;
 import android.view.View;
+import android.widget.TextView.BufferType;
 
 import org.junit.Before;
 import org.junit.Rule;
@@ -241,6 +244,82 @@
         mTextView.onTextContextMenuItem(TextView.ID_CUT);
     }
 
+    @Test
+    public void testUseDynamicLayout() {
+        mTextView = new TextView(mActivity);
+        mTextView.setTextIsSelectable(true);
+        String text = "HelloWorld";
+        PrecomputedText precomputed =
+                PrecomputedText.create(text, mTextView.getTextMetricsParams());
+
+        mTextView.setTextIsSelectable(false);
+        mTextView.setText(text);
+        assertFalse(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(true);
+        mTextView.setText(text);
+        assertTrue(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(false);
+        mTextView.setText(precomputed);
+        assertFalse(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(true);
+        mTextView.setText(precomputed);
+        assertTrue(mTextView.useDynamicLayout());
+    }
+
+    @Test
+    public void testUseDynamicLayout_SPANNABLE() {
+        mTextView = new TextView(mActivity);
+        mTextView.setTextIsSelectable(true);
+        String text = "HelloWorld";
+        PrecomputedText precomputed =
+                PrecomputedText.create(text, mTextView.getTextMetricsParams());
+
+        mTextView.setTextIsSelectable(false);
+        mTextView.setText(text, BufferType.SPANNABLE);
+        android.util.Log.e("TextViewTest", "Text:" + mTextView.getText().getClass().getName());
+        assertTrue(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(true);
+        mTextView.setText(text, BufferType.SPANNABLE);
+        assertTrue(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(false);
+        mTextView.setText(precomputed, BufferType.SPANNABLE);
+        assertFalse(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(true);
+        mTextView.setText(precomputed, BufferType.SPANNABLE);
+        assertTrue(mTextView.useDynamicLayout());
+    }
+
+    @Test
+    public void testUseDynamicLayout_EDITABLE() {
+        mTextView = new TextView(mActivity);
+        mTextView.setTextIsSelectable(true);
+        String text = "HelloWorld";
+        PrecomputedText precomputed =
+                PrecomputedText.create(text, mTextView.getTextMetricsParams());
+
+        mTextView.setTextIsSelectable(false);
+        mTextView.setText(text, BufferType.EDITABLE);
+        assertTrue(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(true);
+        mTextView.setText(text, BufferType.EDITABLE);
+        assertTrue(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(false);
+        mTextView.setText(precomputed, BufferType.EDITABLE);
+        assertTrue(mTextView.useDynamicLayout());
+
+        mTextView.setTextIsSelectable(true);
+        mTextView.setText(precomputed, BufferType.EDITABLE);
+        assertTrue(mTextView.useDynamicLayout());
+    }
+
     private String createLongText() {
         int size = 600 * 1000;
         final StringBuilder builder = new StringBuilder(size);
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index acab8bb..aaba1e3 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -759,6 +759,7 @@
             case FOR_SYSTEM: return "FOR_SYSTEM";
             case FOR_HDMI_SYSTEM_AUDIO: return "FOR_HDMI_SYSTEM_AUDIO";
             case FOR_ENCODED_SURROUND: return "FOR_ENCODED_SURROUND";
+            case FOR_VIBRATE_RINGING: return "FOR_VIBRATE_RINGING";
             default: return "unknown usage (" + usage + ")" ;
         }
     }
diff --git a/media/java/android/media/MediaMetadata2.java b/media/java/android/media/MediaMetadata2.java
index 1a15962..59dd8cb 100644
--- a/media/java/android/media/MediaMetadata2.java
+++ b/media/java/android/media/MediaMetadata2.java
@@ -357,28 +357,6 @@
     public static final String METADATA_KEY_MEDIA_URI = "android.media.metadata.MEDIA_URI";
 
     /**
-     * The metadata key for a {@link Float} typed value to retrieve the information about the
-     * radio frequency if this metadata represents radio content.
-     *
-     * @see Builder#putFloat(String, float)
-     * @see #getFloat(String)
-     */
-    public static final String METADATA_KEY_RADIO_FREQUENCY =
-            "android.media.metadata.RADIO_FREQUENCY";
-
-    /**
-     * The metadata key for a {@link CharSequence} or {@link String} typed value to retrieve the
-     * information about the radio callsign if this metadata represents radio content.
-     *
-     * @see Builder#putText(String, CharSequence)
-     * @see Builder#putString(String, String)
-     * @see #getText(String)
-     * @see #getString(String)
-     */
-    public static final String METADATA_KEY_RADIO_CALLSIGN =
-            "android.media.metadata.RADIO_CALLSIGN";
-
-    /**
      * The metadata key for a {@link Long} typed value to retrieve the information about the
      * bluetooth folder type of the media specified in the section 6.10.2.2 of the Bluetooth
      * AVRCP 1.5. It should be one of the following:
@@ -502,7 +480,7 @@
             METADATA_KEY_DATE, METADATA_KEY_GENRE, METADATA_KEY_ALBUM_ARTIST, METADATA_KEY_ART_URI,
             METADATA_KEY_ALBUM_ART_URI, METADATA_KEY_DISPLAY_TITLE, METADATA_KEY_DISPLAY_SUBTITLE,
             METADATA_KEY_DISPLAY_DESCRIPTION, METADATA_KEY_DISPLAY_ICON_URI,
-            METADATA_KEY_MEDIA_ID, METADATA_KEY_MEDIA_URI, METADATA_KEY_RADIO_CALLSIGN})
+            METADATA_KEY_MEDIA_ID, METADATA_KEY_MEDIA_URI})
     @Retention(RetentionPolicy.SOURCE)
     public @interface TextKey {}
 
@@ -532,7 +510,7 @@
     /**
      * @hide
      */
-    @StringDef({METADATA_KEY_RADIO_FREQUENCY})
+    // TODO(jaewan): Add predefined float key.
     @Retention(RetentionPolicy.SOURCE)
     public @interface FloatKey {}
 
@@ -741,7 +719,6 @@
          * <li>{@link #METADATA_KEY_DISPLAY_SUBTITLE}</li>
          * <li>{@link #METADATA_KEY_DISPLAY_DESCRIPTION}</li>
          * <li>{@link #METADATA_KEY_DISPLAY_ICON_URI}</li>
-         * <li>{@link #METADATA_KEY_RADIO_CALLSIGN}</li>
          * </ul>
          *
          * @param key The key for referencing this value
@@ -773,7 +750,6 @@
          * <li>{@link #METADATA_KEY_DISPLAY_SUBTITLE}</li>
          * <li>{@link #METADATA_KEY_DISPLAY_DESCRIPTION}</li>
          * <li>{@link #METADATA_KEY_DISPLAY_ICON_URI}</li>
-         * <li>{@link #METADATA_KEY_RADIO_CALLSIGN}</li>
          * </ul>
          *
          * @param key The key for referencing this value
@@ -848,12 +824,7 @@
         }
 
         /**
-         * Put a float value into the metadata. Custom keys may be used, but if
-         * the METADATA_KEYs defined in this class are used they may only be one
-         * of the following:
-         * <ul>
-         * <li>{@link #METADATA_KEY_RADIO_FREQUENCY}</li>
-         * </ul>
+         * Put a float value into the metadata. Custom keys may be used.
          *
          * @param key The key for referencing this value
          * @param value The float value to store
diff --git a/media/java/android/media/MediaSession2.java b/media/java/android/media/MediaSession2.java
index 4437cca..2033c59 100644
--- a/media/java/android/media/MediaSession2.java
+++ b/media/java/android/media/MediaSession2.java
@@ -45,6 +45,7 @@
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.Executor;
 
 /**
@@ -116,18 +117,20 @@
     /**
      * Command code for {@link MediaController2#skipToNextItem()}.
      * <p>
-     * Command would be sent directly to the player if the session doesn't reject the request
-     * through the {@link SessionCallback#onCommandRequest(MediaSession2, ControllerInfo, Command)}.
+     * Command would be sent directly to the playlist agent if the session doesn't reject the
+     * request through the {@link SessionCallback#onCommandRequest(
+     * MediaSession2, ControllerInfo, Command)}.
      */
-    public static final int COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM = 4;
+    public static final int COMMAND_CODE_PLAYLIST_SKIP_NEXT_ITEM = 4;
 
     /**
      * Command code for {@link MediaController2#skipToPreviousItem()}.
      * <p>
-     * Command would be sent directly to the player if the session doesn't reject the request
-     * through the {@link SessionCallback#onCommandRequest(MediaSession2, ControllerInfo, Command)}.
+     * Command would be sent directly to the playlist agent if the session doesn't reject the
+     * request through the {@link SessionCallback#onCommandRequest(
+     * MediaSession2, ControllerInfo, Command)}.
      */
-    public static final int COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM = 5;
+    public static final int COMMAND_CODE_PLAYLIST_SKIP_PREV_ITEM = 5;
 
     /**
      * Command code for {@link MediaController2#prepare()}.
@@ -275,48 +278,60 @@
     /**
      * Command code for {@link MediaController2#playFromMediaId(String, Bundle)}.
      */
-    public static final int COMMAND_CODE_PLAY_FROM_MEDIA_ID = 22;
+    public static final int COMMAND_CODE_SESSION_PLAY_FROM_MEDIA_ID = 22;
 
     /**
      * Command code for {@link MediaController2#playFromUri(Uri, Bundle)}.
      */
-    public static final int COMMAND_CODE_PLAY_FROM_URI = 23;
+    public static final int COMMAND_CODE_SESSION_PLAY_FROM_URI = 23;
 
     /**
      * Command code for {@link MediaController2#playFromSearch(String, Bundle)}.
      */
-    public static final int COMMAND_CODE_PLAY_FROM_SEARCH = 24;
+    public static final int COMMAND_CODE_SESSION_PLAY_FROM_SEARCH = 24;
 
     /**
      * Command code for {@link MediaController2#prepareFromMediaId(String, Bundle)}.
      */
-    public static final int COMMAND_CODE_PREPARE_FROM_MEDIA_ID = 25;
+    public static final int COMMAND_CODE_SESSION_PREPARE_FROM_MEDIA_ID = 25;
 
     /**
      * Command code for {@link MediaController2#prepareFromUri(Uri, Bundle)}.
      */
-    public static final int COMMAND_CODE_PREPARE_FROM_URI = 26;
+    public static final int COMMAND_CODE_SESSION_PREPARE_FROM_URI = 26;
 
     /**
      * Command code for {@link MediaController2#prepareFromSearch(String, Bundle)}.
      */
-    public static final int COMMAND_CODE_PREPARE_FROM_SEARCH = 27;
+    public static final int COMMAND_CODE_SESSION_PREPARE_FROM_SEARCH = 27;
 
     /**
      * Command code for {@link MediaController2#setRating(String, Rating2)}.
      * @hide
      */
-    // TODO(jaewan): Unhide
-    public static final int COMMAND_CODE_SET_RATING = 29;
+    public static final int COMMAND_CODE_SESSION_SET_RATING = 28;
 
     /**
-     * Command code for {@link MediaBrowser2} specific functions that allows navigation and search
-     * from the {@link MediaLibraryService2}. This would be ignored for a {@link MediaSession2},
-     * not {@link android.media.MediaLibraryService2.MediaLibrarySession}.
+     * Command code for {@link android.media.MediaLibraryService2.MediaLibrarySession} specific
+     * functions. With or without this, a {@link MediaSession2} that isn't
+     * {@link android.media.MediaLibraryService2.MediaLibrarySession} would automatically reject
+     * the calls.
      *
+     * @see android.media.MediaLibraryService2.MediaLibrarySession
      * @see MediaBrowser2
+     * @hide
      */
-    public static final int COMMAND_CODE_BROWSER = 28;
+    // TODO(jaewan): Remove
+    public static final int COMMAND_CODE_BROWSER = 29;
+
+    // TODO(jaewan): Add javadoc
+    public static final int COMMAND_CODE_LIBRARY_GET_CHILDREN = 29;
+    public static final int COMMAND_CODE_LIBRARY_GET_ITEM = 30;
+    public static final int COMMAND_CODE_LIBRARY_GET_LIBRARY_ROOT = 31;
+    public static final int COMMAND_CODE_LIBRARY_GET_SEARCH_RESULT = 32;
+    public static final int COMMAND_CODE_LIBRARY_SEARCH = 33;
+    public static final int COMMAND_CODE_LIBRARY_SUBSCRIBE = 34;
+    public static final int COMMAND_CODE_LIBRARY_UNSUBSCRIBE = 35;
 
     /**
      * @hide
@@ -543,7 +558,7 @@
             return mProvider.hasCommand_impl(code);
         }
 
-        public @NonNull List<Command> getCommands() {
+        public @NonNull Set<Command> getCommands() {
             return mProvider.getCommands_impl();
         }
 
@@ -627,8 +642,8 @@
          * @see #COMMAND_CODE_PLAYBACK_PLAY
          * @see #COMMAND_CODE_PLAYBACK_PAUSE
          * @see #COMMAND_CODE_PLAYBACK_STOP
-         * @see #COMMAND_CODE_PLAYBACK_SKIP_NEXT_ITEM
-         * @see #COMMAND_CODE_PLAYBACK_SKIP_PREV_ITEM
+         * @see #COMMAND_CODE_PLAYLIST_SKIP_NEXT_ITEM
+         * @see #COMMAND_CODE_PLAYLIST_SKIP_PREV_ITEM
          * @see #COMMAND_CODE_PLAYBACK_PREPARE
          * @see #COMMAND_CODE_PLAYBACK_FAST_FORWARD
          * @see #COMMAND_CODE_PLAYBACK_REWIND
@@ -683,7 +698,7 @@
          * @param controller controller information
          * @param mediaId media id
          * @param extras optional extra bundle
-         * @see #COMMAND_CODE_PLAY_FROM_MEDIA_ID
+         * @see #COMMAND_CODE_SESSION_PLAY_FROM_MEDIA_ID
          */
         public void onPlayFromMediaId(@NonNull MediaSession2 session,
                 @NonNull ControllerInfo controller, @NonNull String mediaId,
@@ -700,7 +715,7 @@
          * @param controller controller information
          * @param query query string. Can be empty to indicate any suggested media
          * @param extras optional extra bundle
-         * @see #COMMAND_CODE_PLAY_FROM_SEARCH
+         * @see #COMMAND_CODE_SESSION_PLAY_FROM_SEARCH
          */
         public void onPlayFromSearch(@NonNull MediaSession2 session,
                 @NonNull ControllerInfo controller, @NonNull String query,
@@ -714,7 +729,7 @@
          * @param controller controller information
          * @param uri uri
          * @param extras optional extra bundle
-         * @see #COMMAND_CODE_PLAY_FROM_URI
+         * @see #COMMAND_CODE_SESSION_PLAY_FROM_URI
          */
         public void onPlayFromUri(@NonNull MediaSession2 session,
                 @NonNull ControllerInfo controller, @NonNull Uri uri,
@@ -738,7 +753,7 @@
          * @param controller controller information
          * @param mediaId media id to prepare
          * @param extras optional extra bundle
-         * @see #COMMAND_CODE_PREPARE_FROM_MEDIA_ID
+         * @see #COMMAND_CODE_SESSION_PREPARE_FROM_MEDIA_ID
          */
         public void onPrepareFromMediaId(@NonNull MediaSession2 session,
                 @NonNull ControllerInfo controller, @NonNull String mediaId,
@@ -762,7 +777,7 @@
          * @param controller controller information
          * @param query query string. Can be empty to indicate any suggested media
          * @param extras optional extra bundle
-         * @see #COMMAND_CODE_PREPARE_FROM_SEARCH
+         * @see #COMMAND_CODE_SESSION_PREPARE_FROM_SEARCH
          */
         public void onPrepareFromSearch(@NonNull MediaSession2 session,
                 @NonNull ControllerInfo controller, @NonNull String query,
@@ -786,7 +801,7 @@
          * @param controller controller information
          * @param uri uri
          * @param extras optional extra bundle
-         * @see #COMMAND_CODE_PREPARE_FROM_URI
+         * @see #COMMAND_CODE_SESSION_PREPARE_FROM_URI
          */
         public void onPrepareFromUri(@NonNull MediaSession2 session,
                 @NonNull ControllerInfo controller, @NonNull Uri uri, @Nullable Bundle extras) { }
diff --git a/media/java/android/media/Rating2.java b/media/java/android/media/Rating2.java
index 5f7a334..fc733bf 100644
--- a/media/java/android/media/Rating2.java
+++ b/media/java/android/media/Rating2.java
@@ -29,6 +29,7 @@
 import java.lang.annotation.RetentionPolicy;
 
 /**
+ * @hide
  * A class to encapsulate rating information used as content metadata.
  * A rating is defined by its rating style (see {@link #RATING_HEART},
  * {@link #RATING_THUMB_UP_DOWN}, {@link #RATING_3_STARS}, {@link #RATING_4_STARS},
diff --git a/media/java/android/media/update/MediaSession2Provider.java b/media/java/android/media/update/MediaSession2Provider.java
index ed96b6d..5a1db3e 100644
--- a/media/java/android/media/update/MediaSession2Provider.java
+++ b/media/java/android/media/update/MediaSession2Provider.java
@@ -36,6 +36,7 @@
 import android.os.ResultReceiver;
 
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.Executor;
 
 /**
@@ -87,7 +88,7 @@
         void removeCommand_impl(Command command);
         boolean hasCommand_impl(Command command);
         boolean hasCommand_impl(int code);
-        List<Command> getCommands_impl();
+        Set<Command> getCommands_impl();
         Bundle toBundle_impl();
     }
 
diff --git a/media/java/android/mtp/MtpDatabase.java b/media/java/android/mtp/MtpDatabase.java
index 32a00d5..1244d7f 100755
--- a/media/java/android/mtp/MtpDatabase.java
+++ b/media/java/android/mtp/MtpDatabase.java
@@ -243,11 +243,11 @@
         }
     };
 
-    public MtpDatabase(Context context, Context userContext, String volumeName,
+    public MtpDatabase(Context context, String volumeName,
             String[] subDirectories) {
         native_setup();
         mContext = context;
-        mMediaProvider = userContext.getContentResolver()
+        mMediaProvider = context.getContentResolver()
                 .acquireContentProviderClient(MediaStore.AUTHORITY);
         mVolumeName = volumeName;
         mObjectsUri = Files.getMtpObjectsUri(volumeName);
diff --git a/media/java/android/mtp/MtpServer.java b/media/java/android/mtp/MtpServer.java
index f2b1106..8af5ff7 100644
--- a/media/java/android/mtp/MtpServer.java
+++ b/media/java/android/mtp/MtpServer.java
@@ -18,6 +18,8 @@
 
 import com.android.internal.util.Preconditions;
 
+import java.io.FileDescriptor;
+
 /**
  * Java wrapper for MTP/PTP support as USB responder.
  * {@hide}
@@ -34,6 +36,7 @@
 
     public MtpServer(
             MtpDatabase database,
+            FileDescriptor controlFd,
             boolean usePtp,
             Runnable onTerminate,
             String deviceInfoManufacturer,
@@ -44,6 +47,7 @@
         mOnTerminate = Preconditions.checkNotNull(onTerminate);
         native_setup(
                 database,
+                controlFd,
                 usePtp,
                 deviceInfoManufacturer,
                 deviceInfoModel,
@@ -92,6 +96,7 @@
     public static native final void native_configure(boolean usePtp);
     private native final void native_setup(
             MtpDatabase database,
+            FileDescriptor controlFd,
             boolean usePtp,
             String deviceInfoManufacturer,
             String deviceInfoModel,
diff --git a/media/jni/android_mtp_MtpServer.cpp b/media/jni/android_mtp_MtpServer.cpp
index c76cebe..8730e06 100644
--- a/media/jni/android_mtp_MtpServer.cpp
+++ b/media/jni/android_mtp_MtpServer.cpp
@@ -55,22 +55,17 @@
     return (MtpServer*)env->GetLongField(thiz, field_MtpServer_nativeContext);
 }
 
-static void android_mtp_configure(JNIEnv *, jobject, jboolean usePtp) {
-    MtpServer::configure(usePtp);
-}
-
 static void
-android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jboolean usePtp,
-        jstring deviceInfoManufacturer,
-        jstring deviceInfoModel,
-        jstring deviceInfoDeviceVersion,
-        jstring deviceInfoSerialNumber)
+android_mtp_MtpServer_setup(JNIEnv *env, jobject thiz, jobject javaDatabase, jobject jControlFd,
+        jboolean usePtp, jstring deviceInfoManufacturer, jstring deviceInfoModel,
+        jstring deviceInfoDeviceVersion, jstring deviceInfoSerialNumber)
 {
     const char *deviceInfoManufacturerStr = env->GetStringUTFChars(deviceInfoManufacturer, NULL);
     const char *deviceInfoModelStr = env->GetStringUTFChars(deviceInfoModel, NULL);
     const char *deviceInfoDeviceVersionStr = env->GetStringUTFChars(deviceInfoDeviceVersion, NULL);
     const char *deviceInfoSerialNumberStr = env->GetStringUTFChars(deviceInfoSerialNumber, NULL);
-    MtpServer* server = new MtpServer(getMtpDatabase(env, javaDatabase),
+    int controlFd = dup(jniGetFDFromFileDescriptor(env, jControlFd));
+    MtpServer* server = new MtpServer(getMtpDatabase(env, javaDatabase), controlFd,
             usePtp,
             MtpString((deviceInfoManufacturerStr != NULL) ? deviceInfoManufacturerStr : ""),
             MtpString((deviceInfoModelStr != NULL) ? deviceInfoModelStr : ""),
@@ -201,8 +196,7 @@
 // ----------------------------------------------------------------------------
 
 static const JNINativeMethod gMethods[] = {
-    {"native_configure",              "(Z)V",  (void *)android_mtp_configure},
-    {"native_setup",                "(Landroid/mtp/MtpDatabase;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
+    {"native_setup",                "(Landroid/mtp/MtpDatabase;Ljava/io/FileDescriptor;ZLjava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
                                             (void *)android_mtp_MtpServer_setup},
     {"native_run",                  "()V",  (void *)android_mtp_MtpServer_run},
     {"native_cleanup",              "()V",  (void *)android_mtp_MtpServer_cleanup},
diff --git a/packages/Osu2/Android.mk b/packages/Osu2/Android.mk
index 063ac7e..7de8908 100644
--- a/packages/Osu2/Android.mk
+++ b/packages/Osu2/Android.mk
@@ -12,6 +12,7 @@
 LOCAL_PRIVATE_PLATFORM_APIS := true
 LOCAL_CERTIFICATE := platform
 LOCAL_PRIVILEGED_MODULE := true
+LOCAL_COMPATIBILITY_SUITE := device-tests
 
 include $(BUILD_PACKAGE)
 
diff --git a/packages/Osu2/tests/AndroidTest.xml b/packages/Osu2/tests/AndroidTest.xml
new file mode 100644
index 0000000..9514dab
--- /dev/null
+++ b/packages/Osu2/tests/AndroidTest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2018 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.
+-->
+<!-- This test config file is auto-generated. -->
+<configuration description="Runs OSU App Tests.">
+    <option name="test-suite-tag" value="apct" />
+    <option name="test-suite-tag" value="apct-instrumentation" />
+    <target_preparer class="com.android.tradefed.targetprep.suite.SuiteApkInstaller">
+        <option name="cleanup-apks" value="true" />
+        <option name="test-file-name" value="Osu2.apk" />
+        <option name="test-file-name" value="OsuTests.apk" />
+    </target_preparer>
+
+    <test class="com.android.tradefed.testtype.AndroidJUnitTest" >
+        <option name="package" value="com.android.osu.tests" />
+        <option name="runner" value="android.support.test.runner.AndroidJUnitRunner" />
+    </test>
+</configuration>
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
index 2047f58..6d9da9b 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProtoDumpUtil.java
@@ -85,22 +85,23 @@
     private static void dumpProtoGlobalSettingsLocked(
             @NonNull ProtoOutputStream p, long fieldId, @NonNull SettingsState s) {
         final long token = p.start(fieldId);
-
         s.dumpHistoricalOperations(p, GlobalSettingsProto.HISTORICAL_OPERATIONS);
 
-        // This uses the same order as in Settings.Global.
+        // This uses the same order as in GlobalSettingsProto.
+        dumpSetting(s, p,
+                Settings.Global.ACTIVITY_MANAGER_CONSTANTS,
+                GlobalSettingsProto.ACTIVITY_MANAGER_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.ADB_ENABLED,
+                GlobalSettingsProto.ADB_ENABLED);
         dumpSetting(s, p,
                 Settings.Global.ADD_USERS_WHEN_LOCKED,
                 GlobalSettingsProto.ADD_USERS_WHEN_LOCKED);
-        dumpSetting(s, p,
-                Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED,
-                GlobalSettingsProto.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED);
+
+        final long airplaneModeToken = p.start(GlobalSettingsProto.AIRPLANE_MODE);
         dumpSetting(s, p,
                 Settings.Global.AIRPLANE_MODE_ON,
-                GlobalSettingsProto.AIRPLANE_MODE_ON);
-        dumpSetting(s, p,
-                Settings.Global.THEATER_MODE_ON,
-                GlobalSettingsProto.THEATER_MODE_ON);
+                GlobalSettingsProto.AirplaneMode.ON);
         // RADIO_BLUETOOTH is just a constant and not an actual setting.
         // RADIO_WIFI is just a constant and not an actual setting.
         // RADIO_WIMAX is just a constant and not an actual setting.
@@ -108,352 +109,1186 @@
         // RADIO_NFC is just a constant and not an actual setting.
         dumpSetting(s, p,
                 Settings.Global.AIRPLANE_MODE_RADIOS,
-                GlobalSettingsProto.AIRPLANE_MODE_RADIOS);
+                GlobalSettingsProto.AirplaneMode.RADIOS);
         dumpSetting(s, p,
                 Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS,
-                GlobalSettingsProto.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
+                GlobalSettingsProto.AirplaneMode.TOGGLEABLE_RADIOS);
+        p.end(airplaneModeToken);
+
         dumpSetting(s, p,
-                Settings.Global.BLUETOOTH_CLASS_OF_DEVICE,
-                GlobalSettingsProto.BLUETOOTH_CLASS_OF_DEVICE);
+                Settings.Global.ALARM_MANAGER_CONSTANTS,
+                GlobalSettingsProto.ALARM_MANAGER_CONSTANTS);
         dumpSetting(s, p,
-                Settings.Global.BLUETOOTH_DISABLED_PROFILES,
-                GlobalSettingsProto.BLUETOOTH_DISABLED_PROFILES);
+                Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED,
+                GlobalSettingsProto.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED);
         dumpSetting(s, p,
-                Settings.Global.BLUETOOTH_INTEROPERABILITY_LIST,
-                GlobalSettingsProto.BLUETOOTH_INTEROPERABILITY_LIST);
+                Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS,
+                GlobalSettingsProto.ALWAYS_ON_DISPLAY_CONSTANTS);
         dumpSetting(s, p,
-                Settings.Global.WIFI_SLEEP_POLICY,
-                GlobalSettingsProto.WIFI_SLEEP_POLICY);
+                Settings.Global.ALWAYS_FINISH_ACTIVITIES,
+                GlobalSettingsProto.ALWAYS_FINISH_ACTIVITIES);
         dumpSetting(s, p,
-                Settings.Global.AUTO_TIME,
-                GlobalSettingsProto.AUTO_TIME);
+                Settings.Global.ANIMATOR_DURATION_SCALE,
+                GlobalSettingsProto.ANIMATOR_DURATION_SCALE);
+
+        final long anomalyToken = p.start(GlobalSettingsProto.ANOMALY);
         dumpSetting(s, p,
-                Settings.Global.AUTO_TIME_ZONE,
-                GlobalSettingsProto.AUTO_TIME_ZONE);
+                Settings.Global.ANOMALY_DETECTION_CONSTANTS,
+                GlobalSettingsProto.Anomaly.DETECTION_CONSTANTS);
         dumpSetting(s, p,
-                Settings.Global.CAR_DOCK_SOUND,
-                GlobalSettingsProto.CAR_DOCK_SOUND);
+                Settings.Global.ANOMALY_CONFIG_VERSION,
+                GlobalSettingsProto.Anomaly.CONFIG_VERSION);
         dumpSetting(s, p,
-                Settings.Global.CAR_UNDOCK_SOUND,
-                GlobalSettingsProto.CAR_UNDOCK_SOUND);
+                Settings.Global.ANOMALY_CONFIG,
+                GlobalSettingsProto.Anomaly.CONFIG);
+        p.end(anomalyToken);
+
+        final long apnDbToken = p.start(GlobalSettingsProto.APN_DB);
         dumpSetting(s, p,
-                Settings.Global.DESK_DOCK_SOUND,
-                GlobalSettingsProto.DESK_DOCK_SOUND);
+                Settings.Global.APN_DB_UPDATE_CONTENT_URL,
+                GlobalSettingsProto.ApnDb.UPDATE_CONTENT_URL);
         dumpSetting(s, p,
-                Settings.Global.DESK_UNDOCK_SOUND,
-                GlobalSettingsProto.DESK_UNDOCK_SOUND);
+                Settings.Global.APN_DB_UPDATE_METADATA_URL,
+                GlobalSettingsProto.ApnDb.UPDATE_METADATA_URL);
+        p.end(apnDbToken);
+
+        final long appToken = p.start(GlobalSettingsProto.APP);
         dumpSetting(s, p,
-                Settings.Global.DOCK_SOUNDS_ENABLED,
-                GlobalSettingsProto.DOCK_SOUNDS_ENABLED);
+                Settings.Global.APP_IDLE_CONSTANTS,
+                GlobalSettingsProto.App.IDLE_CONSTANTS);
         dumpSetting(s, p,
-                Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY,
-                GlobalSettingsProto.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY);
+                Settings.Global.APP_STANDBY_ENABLED,
+                GlobalSettingsProto.App.STANDBY_ENABLED);
         dumpSetting(s, p,
-                Settings.Global.LOCK_SOUND,
-                GlobalSettingsProto.LOCK_SOUND);
+                Settings.Global.APP_AUTO_RESTRICTION_ENABLED,
+                GlobalSettingsProto.App.AUTO_RESTRICTION_ENABLED);
         dumpSetting(s, p,
-                Settings.Global.UNLOCK_SOUND,
-                GlobalSettingsProto.UNLOCK_SOUND);
+                Settings.Global.FORCED_APP_STANDBY_ENABLED,
+                GlobalSettingsProto.App.FORCED_APP_STANDBY_ENABLED);
         dumpSetting(s, p,
-                Settings.Global.TRUSTED_SOUND,
-                GlobalSettingsProto.TRUSTED_SOUND);
-        dumpSetting(s, p,
-                Settings.Global.LOW_BATTERY_SOUND,
-                GlobalSettingsProto.LOW_BATTERY_SOUND);
-        dumpSetting(s, p,
-                Settings.Global.POWER_SOUNDS_ENABLED,
-                GlobalSettingsProto.POWER_SOUNDS_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.CHARGING_STARTED_SOUND,
-                GlobalSettingsProto.WIRELESS_CHARGING_STARTED_SOUND);
-        dumpSetting(s, p,
-                Settings.Global.CHARGING_SOUNDS_ENABLED,
-                GlobalSettingsProto.CHARGING_SOUNDS_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
-                GlobalSettingsProto.STAY_ON_WHILE_PLUGGED_IN);
-        dumpSetting(s, p,
-                Settings.Global.BUGREPORT_IN_POWER_MENU,
-                GlobalSettingsProto.BUGREPORT_IN_POWER_MENU);
-        dumpSetting(s, p,
-                Settings.Global.ADB_ENABLED,
-                GlobalSettingsProto.ADB_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.DEBUG_VIEW_ATTRIBUTES,
-                GlobalSettingsProto.DEBUG_VIEW_ATTRIBUTES);
+                Settings.Global.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED,
+                GlobalSettingsProto.App.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED);
+        p.end(appToken);
+
         dumpSetting(s, p,
                 Settings.Global.ASSISTED_GPS_ENABLED,
                 GlobalSettingsProto.ASSISTED_GPS_ENABLED);
         dumpSetting(s, p,
+                Settings.Global.AUDIO_SAFE_VOLUME_STATE,
+                GlobalSettingsProto.AUDIO_SAFE_VOLUME_STATE);
+
+        final long autoToken = p.start(GlobalSettingsProto.AUTO);
+        dumpSetting(s, p,
+                Settings.Global.AUTO_TIME,
+                GlobalSettingsProto.Auto.TIME);
+        dumpSetting(s, p,
+                Settings.Global.AUTO_TIME_ZONE,
+                GlobalSettingsProto.Auto.TIME_ZONE);
+        p.end(autoToken);
+
+        dumpSetting(s, p,
+                Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES,
+                GlobalSettingsProto.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES);
+        dumpSetting(s, p,
+                Settings.Global.BACKUP_AGENT_TIMEOUT_PARAMETERS,
+                GlobalSettingsProto.BACKUP_AGENT_TIMEOUT_PARAMETERS);
+
+        final long batteryToken = p.start(GlobalSettingsProto.BATTERY);
+        dumpSetting(s, p,
+                Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD,
+                GlobalSettingsProto.Battery.DISCHARGE_DURATION_THRESHOLD);
+        dumpSetting(s, p,
+                Settings.Global.BATTERY_DISCHARGE_THRESHOLD,
+                GlobalSettingsProto.Battery.DISCHARGE_THRESHOLD);
+        dumpSetting(s, p,
+                Settings.Global.BATTERY_SAVER_CONSTANTS,
+                GlobalSettingsProto.Battery.SAVER_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.BATTERY_SAVER_DEVICE_SPECIFIC_CONSTANTS,
+                GlobalSettingsProto.Battery.SAVER_DEVICE_SPECIFIC_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.BATTERY_STATS_CONSTANTS,
+                GlobalSettingsProto.Battery.STATS_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.BATTERY_TIP_CONSTANTS,
+                GlobalSettingsProto.Battery.TIP_CONSTANTS);
+        p.end(batteryToken);
+
+        final long bleScanToken = p.start(GlobalSettingsProto.BLE_SCAN);
+        dumpSetting(s, p,
+                Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE,
+                GlobalSettingsProto.BleScan.ALWAYS_AVAILABLE);
+        dumpSetting(s, p,
+                Settings.Global.BLE_SCAN_LOW_POWER_WINDOW_MS,
+                GlobalSettingsProto.BleScan.LOW_POWER_WINDOW_MS);
+        dumpSetting(s, p,
+                Settings.Global.BLE_SCAN_BALANCED_WINDOW_MS,
+                GlobalSettingsProto.BleScan.BALANCED_WINDOW_MS);
+        dumpSetting(s, p,
+                Settings.Global.BLE_SCAN_LOW_LATENCY_WINDOW_MS,
+                GlobalSettingsProto.BleScan.LOW_LATENCY_WINDOW_MS);
+        dumpSetting(s, p,
+                Settings.Global.BLE_SCAN_LOW_POWER_INTERVAL_MS,
+                GlobalSettingsProto.BleScan.LOW_POWER_INTERVAL_MS);
+        dumpSetting(s, p,
+                Settings.Global.BLE_SCAN_BALANCED_INTERVAL_MS,
+                GlobalSettingsProto.BleScan.BALANCED_INTERVAL_MS);
+        dumpSetting(s, p,
+                Settings.Global.BLE_SCAN_LOW_LATENCY_INTERVAL_MS,
+                GlobalSettingsProto.BleScan.LOW_LATENCY_INTERVAL_MS);
+        dumpSetting(s, p,
+                Settings.Global.BLE_SCAN_BACKGROUND_MODE,
+                GlobalSettingsProto.BleScan.BACKGROUND_MODE);
+        p.end(bleScanToken);
+
+        final long bluetoothToken = p.start(GlobalSettingsProto.BLUETOOTH);
+        dumpSetting(s, p,
+                Settings.Global.BLUETOOTH_CLASS_OF_DEVICE,
+                GlobalSettingsProto.Bluetooth.CLASS_OF_DEVICE);
+        dumpSetting(s, p,
+                Settings.Global.BLUETOOTH_DISABLED_PROFILES,
+                GlobalSettingsProto.Bluetooth.DISABLED_PROFILES);
+        dumpSetting(s, p,
+                Settings.Global.BLUETOOTH_INTEROPERABILITY_LIST,
+                GlobalSettingsProto.Bluetooth.INTEROPERABILITY_LIST);
+        dumpSetting(s, p,
                 Settings.Global.BLUETOOTH_ON,
-                GlobalSettingsProto.BLUETOOTH_ON);
+                GlobalSettingsProto.Bluetooth.ON);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.HEADSET_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.A2DP_SINK_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.A2DP_SRC_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX,
+                GlobalSettingsProto.Bluetooth.A2DP_SUPPORTS_OPTIONAL_CODECS);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX,
+                GlobalSettingsProto.Bluetooth.A2DP_OPTIONAL_CODECS_ENABLED);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.INPUT_DEVICE_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_MAP_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.MAP_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_MAP_CLIENT_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.MAP_CLIENT_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_PBAP_CLIENT_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.PBAP_CLIENT_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_SAP_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.SAP_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_PAN_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.PAN_PRIORITIES);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.BLUETOOTH_HEARING_AID_PRIORITY_PREFIX,
+                GlobalSettingsProto.Bluetooth.HEARING_AID_PRIORITIES);
+        p.end(bluetoothToken);
+
+        dumpSetting(s, p,
+                Settings.Global.BOOT_COUNT,
+                GlobalSettingsProto.BOOT_COUNT);
+        dumpSetting(s, p,
+                Settings.Global.BUGREPORT_IN_POWER_MENU,
+                GlobalSettingsProto.BUGREPORT_IN_POWER_MENU);
+        dumpSetting(s, p,
+                Settings.Global.CALL_AUTO_RETRY,
+                GlobalSettingsProto.CALL_AUTO_RETRY);
+
+        final long captivePortalToken = p.start(GlobalSettingsProto.CAPTIVE_PORTAL);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_MODE,
+                GlobalSettingsProto.CaptivePortal.MODE);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED,
+                GlobalSettingsProto.CaptivePortal.DETECTION_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_SERVER,
+                GlobalSettingsProto.CaptivePortal.SERVER);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
+                GlobalSettingsProto.CaptivePortal.HTTPS_URL);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
+                GlobalSettingsProto.CaptivePortal.HTTP_URL);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
+                GlobalSettingsProto.CaptivePortal.FALLBACK_URL);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
+                GlobalSettingsProto.CaptivePortal.OTHER_FALLBACK_URLS);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_USE_HTTPS,
+                GlobalSettingsProto.CaptivePortal.USE_HTTPS);
+        dumpSetting(s, p,
+                Settings.Global.CAPTIVE_PORTAL_USER_AGENT,
+                GlobalSettingsProto.CaptivePortal.USER_AGENT);
+        p.end(captivePortalToken);
+
+        final long carrierToken = p.start(GlobalSettingsProto.CARRIER);
+        dumpSetting(s, p,
+                Settings.Global.CARRIER_APP_WHITELIST,
+                GlobalSettingsProto.Carrier.APP_WHITELIST);
+        dumpSetting(s, p,
+                Settings.Global.CARRIER_APP_NAMES,
+                GlobalSettingsProto.Carrier.APP_NAMES);
+        dumpSetting(s, p,
+                Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT,
+                GlobalSettingsProto.Carrier.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT);
+        dumpSetting(s, p,
+                Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,
+                GlobalSettingsProto.Carrier.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS);
+        p.end(carrierToken);
+
+        final long cdmaToken = p.start(GlobalSettingsProto.CDMA);
         dumpSetting(s, p,
                 Settings.Global.CDMA_CELL_BROADCAST_SMS,
-                GlobalSettingsProto.CDMA_CELL_BROADCAST_SMS);
+                GlobalSettingsProto.Cdma.CELL_BROADCAST_SMS);
         dumpSetting(s, p,
                 Settings.Global.CDMA_ROAMING_MODE,
-                GlobalSettingsProto.CDMA_ROAMING_MODE);
+                GlobalSettingsProto.Cdma.ROAMING_MODE);
         dumpSetting(s, p,
                 Settings.Global.CDMA_SUBSCRIPTION_MODE,
-                GlobalSettingsProto.CDMA_SUBSCRIPTION_MODE);
+                GlobalSettingsProto.Cdma.SUBSCRIPTION_MODE);
+        p.end(cdmaToken);
+
+        dumpSetting(s, p,
+                Settings.Global.CELL_ON,
+                GlobalSettingsProto.CELL_ON);
+
+        final long certPinToken = p.start(GlobalSettingsProto.CERT_PIN);
+        dumpSetting(s, p,
+                Settings.Global.CERT_PIN_UPDATE_CONTENT_URL,
+                GlobalSettingsProto.CertPin.UPDATE_CONTENT_URL);
+        dumpSetting(s, p,
+                Settings.Global.CERT_PIN_UPDATE_METADATA_URL,
+                GlobalSettingsProto.CertPin.UPDATE_METADATA_URL);
+        p.end(certPinToken);
+
+        dumpSetting(s, p,
+                Global.CHAINED_BATTERY_ATTRIBUTION_ENABLED,
+                GlobalSettingsProto.CHAINED_BATTERY_ATTRIBUTION_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.COMPATIBILITY_MODE,
+                GlobalSettingsProto.COMPATIBILITY_MODE);
+
+        final long connectivityToken = p.start(GlobalSettingsProto.CONNECTIVITY);
+        dumpSetting(s, p,
+                Settings.Global.CONNECTIVITY_METRICS_BUFFER_SIZE,
+                GlobalSettingsProto.Connectivity.METRICS_BUFFER_SIZE);
+        dumpSetting(s, p,
+                Settings.Global.CONNECTIVITY_CHANGE_DELAY,
+                GlobalSettingsProto.Connectivity.CHANGE_DELAY);
+        dumpSetting(s, p,
+                Settings.Global.CONNECTIVITY_SAMPLING_INTERVAL_IN_SECONDS,
+                GlobalSettingsProto.Connectivity.SAMPLING_INTERVAL_IN_SECONDS);
+        p.end(connectivityToken);
+
+        // Settings.Global.CONTACT_METADATA_SYNC intentionally excluded since it's deprecated.
+        dumpSetting(s, p,
+                Settings.Global.CONTACT_METADATA_SYNC_ENABLED,
+                GlobalSettingsProto.CONTACT_METADATA_SYNC_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.CONTACTS_DATABASE_WAL_ENABLED,
+                GlobalSettingsProto.CONTACTS_DATABASE_WAL_ENABLED);
+
+        final long dataToken = p.start(GlobalSettingsProto.DATA);
         // Settings.Global.DEFAULT_RESTRICT_BACKGROUND_DATA intentionally excluded.
         dumpSetting(s, p,
                 Settings.Global.DATA_ACTIVITY_TIMEOUT_MOBILE,
-                GlobalSettingsProto.DATA_ACTIVITY_TIMEOUT_MOBILE);
+                GlobalSettingsProto.Data.ACTIVITY_TIMEOUT_MOBILE);
         dumpSetting(s, p,
                 Settings.Global.DATA_ACTIVITY_TIMEOUT_WIFI,
-                GlobalSettingsProto.DATA_ACTIVITY_TIMEOUT_WIFI);
+                GlobalSettingsProto.Data.ACTIVITY_TIMEOUT_WIFI);
         dumpSetting(s, p,
                 Settings.Global.DATA_ROAMING,
-                GlobalSettingsProto.DATA_ROAMING);
+                GlobalSettingsProto.Data.ROAMING);
         dumpSetting(s, p,
-                Settings.Global.MDC_INITIAL_MAX_RETRY,
-                GlobalSettingsProto.MDC_INITIAL_MAX_RETRY);
+                Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS,
+                GlobalSettingsProto.Data.STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS);
+        dumpSetting(s, p,
+                Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS,
+                GlobalSettingsProto.Data.STALL_ALARM_AGGRESSIVE_DELAY_IN_MS);
+        p.end(dataToken);
+
+        final long databaseToken = p.start(GlobalSettingsProto.DATABASE);
+        dumpSetting(s, p,
+                Settings.Global.DATABASE_DOWNGRADE_REASON,
+                GlobalSettingsProto.Database.DOWNGRADE_REASON);
+        dumpSetting(s, p,
+                Settings.Global.DATABASE_CREATION_BUILDID,
+                GlobalSettingsProto.Database.CREATION_BUILDID);
+        p.end(databaseToken);
+
+        final long debugToken = p.start(GlobalSettingsProto.DEBUG);
+        dumpSetting(s, p,
+                Settings.Global.DEBUG_APP,
+                GlobalSettingsProto.Debug.APP);
+        dumpSetting(s, p,
+                Settings.Global.DEBUG_VIEW_ATTRIBUTES,
+                GlobalSettingsProto.Debug.VIEW_ATTRIBUTES);
+        p.end(debugToken);
+
+        final long defaultToken = p.start(GlobalSettingsProto.DEFAULT);
+        // Settings.Global.DEFAULT_SM_DP_PLUS intentionally excluded.
+        dumpSetting(s, p,
+                Settings.Global.DEFAULT_INSTALL_LOCATION,
+                GlobalSettingsProto.Default.INSTALL_LOCATION);
+        dumpSetting(s, p,
+                Settings.Global.DEFAULT_DNS_SERVER,
+                GlobalSettingsProto.Default.DNS_SERVER);
+        p.end(defaultToken);
+
+        final long developmentToken = p.start(GlobalSettingsProto.DEVELOPMENT);
+        dumpSetting(s, p,
+                Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES,
+                GlobalSettingsProto.Development.FORCE_RESIZABLE_ACTIVITIES);
+        dumpSetting(s, p,
+                Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT,
+                GlobalSettingsProto.Development.ENABLE_FREEFORM_WINDOWS_SUPPORT);
+        dumpSetting(s, p,
+                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
+                GlobalSettingsProto.Development.SETTINGS_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.DEVELOPMENT_FORCE_RTL,
+                GlobalSettingsProto.Development.FORCE_RTL);
+        dumpSetting(s, p,
+                Settings.Global.EMULATE_DISPLAY_CUTOUT,
+                GlobalSettingsProto.Development.EMULATE_DISPLAY_CUTOUT);
+        p.end(developmentToken);
+
+        final long deviceToken = p.start(GlobalSettingsProto.DEVICE);
+        dumpSetting(s, p,
+                Settings.Global.DEVICE_NAME,
+                GlobalSettingsProto.Device.NAME);
+        dumpSetting(s, p,
+                Settings.Global.DEVICE_PROVISIONED,
+                GlobalSettingsProto.Device.PROVISIONED);
+        dumpSetting(s, p,
+                Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED,
+                GlobalSettingsProto.Device.PROVISIONING_MOBILE_DATA_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.DEVICE_IDLE_CONSTANTS,
+                GlobalSettingsProto.Device.IDLE_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.DEVICE_POLICY_CONSTANTS,
+                GlobalSettingsProto.Device.POLICY_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.DEVICE_DEMO_MODE,
+                GlobalSettingsProto.Device.DEMO_MODE);
+        p.end(deviceToken);
+
+        dumpSetting(s, p,
+                Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
+                GlobalSettingsProto.DISK_FREE_CHANGE_REPORTING_THRESHOLD);
+
+        final long displayToken = p.start(GlobalSettingsProto.DISPLAY);
+        dumpSetting(s, p,
+                Settings.Global.DISPLAY_SIZE_FORCED,
+                GlobalSettingsProto.Display.SIZE_FORCED);
+        dumpSetting(s, p,
+                Settings.Global.DISPLAY_SCALING_FORCE,
+                GlobalSettingsProto.Display.SCALING_FORCE);
+        dumpSetting(s, p,
+                Settings.Global.DISPLAY_PANEL_LPM,
+                GlobalSettingsProto.Display.PANEL_LPM);
+        p.end(displayToken);
+
+        final long dnsResolverToken = p.start(GlobalSettingsProto.DNS_RESOLVER);
+        dumpSetting(s, p,
+                Settings.Global.DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS,
+                GlobalSettingsProto.DnsResolver.SAMPLE_VALIDITY_SECONDS);
+        dumpSetting(s, p,
+                Settings.Global.DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT,
+                GlobalSettingsProto.DnsResolver.SUCCESS_THRESHOLD_PERCENT);
+        dumpSetting(s, p,
+                Settings.Global.DNS_RESOLVER_MIN_SAMPLES,
+                GlobalSettingsProto.DnsResolver.MIN_SAMPLES);
+        dumpSetting(s, p,
+                Settings.Global.DNS_RESOLVER_MAX_SAMPLES,
+                GlobalSettingsProto.DnsResolver.MAX_SAMPLES);
+        p.end(dnsResolverToken);
+
+        dumpSetting(s, p,
+                Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
+                GlobalSettingsProto.DOCK_AUDIO_MEDIA_ENABLED);
+
+        final long downloadToken = p.start(GlobalSettingsProto.DOWNLOAD);
+        dumpSetting(s, p,
+                Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE,
+                GlobalSettingsProto.Download.MAX_BYTES_OVER_MOBILE);
+        dumpSetting(s, p,
+                Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE,
+                GlobalSettingsProto.Download.RECOMMENDED_MAX_BYTES_OVER_MOBILE);
+        p.end(downloadToken);
+
+        final long dropboxToken = p.start(GlobalSettingsProto.DROPBOX);
+        dumpSetting(s, p,
+                Settings.Global.DROPBOX_AGE_SECONDS,
+                GlobalSettingsProto.Dropbox.AGE_SECONDS);
+        dumpSetting(s, p,
+                Settings.Global.DROPBOX_MAX_FILES,
+                GlobalSettingsProto.Dropbox.MAX_FILES);
+        dumpSetting(s, p,
+                Settings.Global.DROPBOX_QUOTA_KB,
+                GlobalSettingsProto.Dropbox.QUOTA_KB);
+        dumpSetting(s, p,
+                Settings.Global.DROPBOX_QUOTA_PERCENT,
+                GlobalSettingsProto.Dropbox.QUOTA_PERCENT);
+        dumpSetting(s, p,
+                Settings.Global.DROPBOX_RESERVE_PERCENT,
+                GlobalSettingsProto.Dropbox.RESERVE_PERCENT);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.DROPBOX_TAG_PREFIX,
+                GlobalSettingsProto.Dropbox.SETTINGS);
+        p.end(dropboxToken);
+
+        final long emergencyToken = p.start(GlobalSettingsProto.EMERGENCY);
+        dumpSetting(s, p,
+                Settings.Global.EMERGENCY_TONE,
+                GlobalSettingsProto.Emergency.TONE);
+        dumpSetting(s, p,
+                Settings.Global.EMERGENCY_AFFORDANCE_NEEDED,
+                GlobalSettingsProto.Emergency.AFFORDANCE_NEEDED);
+        p.end(emergencyToken);
+
+        final long enableToken = p.start(GlobalSettingsProto.ENABLE);
+        dumpSetting(s, p,
+                Settings.Global.ENABLE_ACCESSIBILITY_GLOBAL_GESTURE_ENABLED,
+                GlobalSettingsProto.Enable.ACCESSIBILITY_GLOBAL_GESTURE_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.ENABLE_GPU_DEBUG_LAYERS,
+                GlobalSettingsProto.Enable.GPU_DEBUG_LAYERS);
+        dumpSetting(s, p,
+                Settings.Global.ENABLE_EPHEMERAL_FEATURE,
+                GlobalSettingsProto.Enable.EPHEMERAL_FEATURE);
+        dumpSetting(s, p,
+                Settings.Global.ENABLE_CELLULAR_ON_BOOT,
+                GlobalSettingsProto.Enable.CELLULAR_ON_BOOT);
+        dumpSetting(s, p,
+                Settings.Global.ENABLE_DISKSTATS_LOGGING,
+                GlobalSettingsProto.Enable.DISKSTATS_LOGGING);
+        dumpSetting(s, p,
+                Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION,
+                GlobalSettingsProto.Enable.CACHE_QUOTA_CALCULATION);
+        dumpSetting(s, p,
+                Settings.Global.ENABLE_DELETION_HELPER_NO_THRESHOLD_TOGGLE,
+                GlobalSettingsProto.Enable.DELETION_HELPER_NO_THRESHOLD_TOGGLE);
+        dumpSetting(s, p,
+                Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING,
+                GlobalSettingsProto.Enable.GNSS_RAW_MEAS_FULL_TRACKING);
+        p.end(enableToken);
+
+        dumpSetting(s, p,
+                Settings.Global.ENCODED_SURROUND_OUTPUT,
+                GlobalSettingsProto.ENCODED_SURROUND_OUTPUT);
+        dumpSetting(s, p,
+                Settings.Global.ENHANCED_4G_MODE_ENABLED,
+                GlobalSettingsProto.ENHANCED_4G_MODE_ENABLED);
+        dumpRepeatedSetting(s, p,
+                Settings.Global.ERROR_LOGCAT_PREFIX,
+                GlobalSettingsProto.ERROR_LOGCAT_LINES);
+
+        final long euiccToken = p.start(GlobalSettingsProto.EUICC);
+        dumpSetting(s, p,
+                Settings.Global.EUICC_PROVISIONED,
+                GlobalSettingsProto.Euicc.PROVISIONED);
+        dumpSetting(s, p,
+                Settings.Global.EUICC_FACTORY_RESET_TIMEOUT_MILLIS,
+                GlobalSettingsProto.Euicc.FACTORY_RESET_TIMEOUT_MILLIS);
+        p.end(euiccToken);
+
+        dumpSetting(s, p,
+                Settings.Global.FANCY_IME_ANIMATIONS,
+                GlobalSettingsProto.FANCY_IME_ANIMATIONS);
         dumpSetting(s, p,
                 Settings.Global.FORCE_ALLOW_ON_EXTERNAL,
                 GlobalSettingsProto.FORCE_ALLOW_ON_EXTERNAL);
-        // Settings.Global.DEFAULT_SM_DP_PLUS intentionally excluded.
         dumpSetting(s, p,
-                Settings.Global.EUICC_PROVISIONED,
-                GlobalSettingsProto.EUICC_PROVISIONED);
+                Settings.Global.FPS_DEVISOR,
+                GlobalSettingsProto.FPS_DIVISOR);
         dumpSetting(s, p,
-                Settings.Global.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES,
-                GlobalSettingsProto.DEVELOPMENT_FORCE_RESIZABLE_ACTIVITIES);
+                Settings.Global.FSTRIM_MANDATORY_INTERVAL,
+                GlobalSettingsProto.FSTRIM_MANDATORY_INTERVAL);
+
+        final long ghpToken = p.start(GlobalSettingsProto.GLOBAL_HTTP_PROXY);
         dumpSetting(s, p,
-                Settings.Global.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT,
-                GlobalSettingsProto.DEVELOPMENT_ENABLE_FREEFORM_WINDOWS_SUPPORT);
+                Settings.Global.GLOBAL_HTTP_PROXY_HOST,
+                GlobalSettingsProto.GlobalHttpProxy.HOST);
         dumpSetting(s, p,
-                Settings.Global.DEVELOPMENT_SETTINGS_ENABLED,
-                GlobalSettingsProto.DEVELOPMENT_SETTINGS_ENABLED);
+                Settings.Global.GLOBAL_HTTP_PROXY_PORT,
+                GlobalSettingsProto.GlobalHttpProxy.PORT);
         dumpSetting(s, p,
-                Settings.Global.DEVICE_PROVISIONED,
-                GlobalSettingsProto.DEVICE_PROVISIONED);
+                Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
+                GlobalSettingsProto.GlobalHttpProxy.EXCLUSION_LIST);
         dumpSetting(s, p,
-                Settings.Global.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED,
-                GlobalSettingsProto.DEVICE_PROVISIONING_MOBILE_DATA_ENABLED);
+                Settings.Global.GLOBAL_HTTP_PROXY_PAC,
+                GlobalSettingsProto.GlobalHttpProxy.PAC);
         dumpSetting(s, p,
-                Settings.Global.DISPLAY_SIZE_FORCED,
-                GlobalSettingsProto.DISPLAY_SIZE_FORCED);
+                Settings.Global.SET_GLOBAL_HTTP_PROXY,
+                GlobalSettingsProto.GlobalHttpProxy.SETTING_UI_ENABLED);
+        p.end(ghpToken);
+
         dumpSetting(s, p,
-                Settings.Global.DISPLAY_SCALING_FORCE,
-                GlobalSettingsProto.DISPLAY_SCALING_FORCE);
+                Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS,
+                GlobalSettingsProto.GPRS_REGISTER_CHECK_PERIOD_MS);
+
+        final long gpuToken = p.start(GlobalSettingsProto.GPU);
         dumpSetting(s, p,
-                Settings.Global.DOWNLOAD_MAX_BYTES_OVER_MOBILE,
-                GlobalSettingsProto.DOWNLOAD_MAX_BYTES_OVER_MOBILE);
+                Settings.Global.GPU_DEBUG_APP,
+                GlobalSettingsProto.Gpu.DEBUG_APP);
         dumpSetting(s, p,
-                Settings.Global.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE,
-                GlobalSettingsProto.DOWNLOAD_RECOMMENDED_MAX_BYTES_OVER_MOBILE);
-        // Settings.Global.INSTALL_NON_MARKET_APPS intentionally excluded since it's deprecated.
+                Settings.Global.GPU_DEBUG_LAYERS,
+                GlobalSettingsProto.Gpu.DEBUG_LAYERS);
+        p.end(gpuToken);
+
+        final long hdmiToken = p.start(GlobalSettingsProto.HDMI);
         dumpSetting(s, p,
                 Settings.Global.HDMI_CONTROL_ENABLED,
-                GlobalSettingsProto.HDMI_CONTROL_ENABLED);
+                GlobalSettingsProto.Hdmi.CONTROL_ENABLED);
         dumpSetting(s, p,
                 Settings.Global.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED,
-                GlobalSettingsProto.HDMI_SYSTEM_AUDIO_CONTROL_ENABLED);
+                GlobalSettingsProto.Hdmi.SYSTEM_AUDIO_CONTROL_ENABLED);
         dumpSetting(s, p,
                 Settings.Global.HDMI_CONTROL_AUTO_WAKEUP_ENABLED,
-                GlobalSettingsProto.HDMI_CONTROL_AUTO_WAKEUP_ENABLED);
+                GlobalSettingsProto.Hdmi.CONTROL_AUTO_WAKEUP_ENABLED);
         dumpSetting(s, p,
                 Settings.Global.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED,
-                GlobalSettingsProto.HDMI_CONTROL_AUTO_DEVICE_OFF_ENABLED);
+                GlobalSettingsProto.Hdmi.CONTROL_AUTO_DEVICE_OFF_ENABLED);
+        p.end(hdmiToken);
+
         dumpSetting(s, p,
-                Settings.Global.PRIV_APP_OOB_ENABLED,
-                GlobalSettingsProto.PRIV_APP_OOB_ENABLED);
+                Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED,
+                GlobalSettingsProto.HEADS_UP_NOTIFICATIONS_ENABLED);
+        dumpSetting(s, p,
+                Global.HIDDEN_API_BLACKLIST_EXEMPTIONS,
+                GlobalSettingsProto.HIDDEN_API_BLACKLIST_EXEMPTIONS);
+
+        final long inetCondToken = p.start(GlobalSettingsProto.INET_CONDITION);
+        dumpSetting(s, p,
+                Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY,
+                GlobalSettingsProto.InetCondition.DEBOUNCE_UP_DELAY);
+        dumpSetting(s, p,
+                Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY,
+                GlobalSettingsProto.InetCondition.DEBOUNCE_DOWN_DELAY);
+        p.end(inetCondToken);
+
+        final long instantAppToken = p.start(GlobalSettingsProto.INSTANT_APP);
+        dumpSetting(s, p,
+                Settings.Global.INSTANT_APP_DEXOPT_ENABLED,
+                GlobalSettingsProto.InstantApp.DEXOPT_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
+                GlobalSettingsProto.InstantApp.EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
+        dumpSetting(s, p,
+                Settings.Global.INSTALLED_INSTANT_APP_MIN_CACHE_PERIOD,
+                GlobalSettingsProto.InstantApp.INSTALLED_MIN_CACHE_PERIOD);
+        dumpSetting(s, p,
+                Settings.Global.INSTALLED_INSTANT_APP_MAX_CACHE_PERIOD,
+                GlobalSettingsProto.InstantApp.INSTALLED_MAX_CACHE_PERIOD);
+        dumpSetting(s, p,
+                Settings.Global.UNINSTALLED_INSTANT_APP_MIN_CACHE_PERIOD,
+                GlobalSettingsProto.InstantApp.UNINSTALLED_MIN_CACHE_PERIOD);
+        dumpSetting(s, p,
+                Settings.Global.UNINSTALLED_INSTANT_APP_MAX_CACHE_PERIOD,
+                GlobalSettingsProto.InstantApp.UNINSTALLED_MAX_CACHE_PERIOD);
+        p.end(instantAppToken);
+
+        final long intentFirewallToken = p.start(GlobalSettingsProto.INTENT_FIREWALL);
+        dumpSetting(s, p,
+                Settings.Global.INTENT_FIREWALL_UPDATE_CONTENT_URL,
+                GlobalSettingsProto.IntentFirewall.UPDATE_CONTENT_URL);
+        dumpSetting(s, p,
+                Settings.Global.INTENT_FIREWALL_UPDATE_METADATA_URL,
+                GlobalSettingsProto.IntentFirewall.UPDATE_METADATA_URL);
+        p.end(intentFirewallToken);
+
+        dumpSetting(s, p,
+                Settings.Global.JOB_SCHEDULER_CONSTANTS,
+                GlobalSettingsProto.JOB_SCHEDULER_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.KEEP_PROFILE_IN_BACKGROUND,
+                GlobalSettingsProto.KEEP_PROFILE_IN_BACKGROUND);
+
+        final long langIdToken = p.start(GlobalSettingsProto.LANG_ID);
+        dumpSetting(s, p,
+                Settings.Global.LANG_ID_UPDATE_CONTENT_URL,
+                GlobalSettingsProto.LangId.UPDATE_CONTENT_URL);
+        dumpSetting(s, p,
+                Settings.Global.LANG_ID_UPDATE_METADATA_URL,
+                GlobalSettingsProto.LangId.UPDATE_METADATA_URL);
+        p.end(langIdToken);
+
+        final long locationToken = p.start(GlobalSettingsProto.LOCATION);
         dumpSetting(s, p,
                 Settings.Global.LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS,
-                GlobalSettingsProto.LOCATION_BACKGROUND_THROTTLE_INTERVAL_MS);
+                GlobalSettingsProto.Location.BACKGROUND_THROTTLE_INTERVAL_MS);
         dumpSetting(s, p,
                 Settings.Global.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS,
-                GlobalSettingsProto.LOCATION_BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS);
+                GlobalSettingsProto.Location.BACKGROUND_THROTTLE_PROXIMITY_ALERT_INTERVAL_MS);
         dumpSetting(s, p,
                 Settings.Global.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST,
-                GlobalSettingsProto.LOCATION_BACKGROUND_THROTTLE_PACKAGE_WHITELIST);
+                GlobalSettingsProto.Location.BACKGROUND_THROTTLE_PACKAGE_WHITELIST);
+        dumpSetting(s, p,
+                Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
+                GlobalSettingsProto.Location.SETTINGS_LINK_TO_PERMISSIONS_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.LOCATION_GLOBAL_KILL_SWITCH,
+                GlobalSettingsProto.Location.GLOBAL_KILL_SWITCH);
+        p.end(locationToken);
+
+        final long lpmToken = p.start(GlobalSettingsProto.LOW_POWER_MODE);
+        dumpSetting(s, p,
+                Settings.Global.LOW_POWER_MODE,
+                GlobalSettingsProto.LowPowerMode.ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL,
+                GlobalSettingsProto.LowPowerMode.TRIGGER_LEVEL);
+        dumpSetting(s, p,
+                Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL_MAX,
+                GlobalSettingsProto.LowPowerMode.TRIGGER_LEVEL_MAX);
+        p.end(lpmToken);
+
+        dumpSetting(s, p,
+                Settings.Global.LTE_SERVICE_FORCED,
+                GlobalSettingsProto.LTE_SERVICE_FORCED);
+        dumpSetting(s, p,
+                Settings.Global.MDC_INITIAL_MAX_RETRY,
+                GlobalSettingsProto.MDC_INITIAL_MAX_RETRY);
+
+        final long mhlToken = p.start(GlobalSettingsProto.MHL);
         dumpSetting(s, p,
                 Settings.Global.MHL_INPUT_SWITCHING_ENABLED,
-                GlobalSettingsProto.MHL_INPUT_SWITCHING_ENABLED);
+                GlobalSettingsProto.Mhl.INPUT_SWITCHING_ENABLED);
         dumpSetting(s, p,
                 Settings.Global.MHL_POWER_CHARGE_ENABLED,
-                GlobalSettingsProto.MHL_POWER_CHARGE_ENABLED);
+                GlobalSettingsProto.Mhl.POWER_CHARGE_ENABLED);
+        p.end(mhlToken);
+
+        final long mobileDataToken = p.start(GlobalSettingsProto.MOBILE_DATA);
         dumpSetting(s, p,
                 Settings.Global.MOBILE_DATA,
-                GlobalSettingsProto.MOBILE_DATA);
+                GlobalSettingsProto.MobileData.ALLOWED);
         dumpSetting(s, p,
                 Settings.Global.MOBILE_DATA_ALWAYS_ON,
-                GlobalSettingsProto.MOBILE_DATA_ALWAYS_ON);
+                GlobalSettingsProto.MobileData.ALWAYS_ON);
+        p.end(mobileDataToken);
+
         dumpSetting(s, p,
-                Settings.Global.CONNECTIVITY_METRICS_BUFFER_SIZE,
-                GlobalSettingsProto.CONNECTIVITY_METRICS_BUFFER_SIZE);
+                Settings.Global.MODE_RINGER,
+                GlobalSettingsProto.MODE_RINGER);
+
+        final long multiSimToken = p.start(GlobalSettingsProto.MULTI_SIM);
+        dumpSetting(s, p,
+                Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION,
+                GlobalSettingsProto.MultiSim.VOICE_CALL_SUBSCRIPTION);
+        dumpSetting(s, p,
+                Settings.Global.MULTI_SIM_VOICE_PROMPT,
+                GlobalSettingsProto.MultiSim.VOICE_PROMPT);
+        dumpSetting(s, p,
+                Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION,
+                GlobalSettingsProto.MultiSim.DATA_CALL_SUBSCRIPTION);
+        dumpSetting(s, p,
+                Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION,
+                GlobalSettingsProto.MultiSim.SMS_SUBSCRIPTION);
+        dumpSetting(s, p,
+                Settings.Global.MULTI_SIM_SMS_PROMPT,
+                GlobalSettingsProto.MultiSim.SMS_PROMPT);
+        p.end(multiSimToken);
+
+        final long netstatsToken = p.start(GlobalSettingsProto.NETSTATS);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_ENABLED,
-                GlobalSettingsProto.NETSTATS_ENABLED);
+                GlobalSettingsProto.Netstats.ENABLED);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_POLL_INTERVAL,
-                GlobalSettingsProto.NETSTATS_POLL_INTERVAL);
+                GlobalSettingsProto.Netstats.POLL_INTERVAL);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_TIME_CACHE_MAX_AGE,
-                GlobalSettingsProto.NETSTATS_TIME_CACHE_MAX_AGE);
+                GlobalSettingsProto.Netstats.TIME_CACHE_MAX_AGE);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_GLOBAL_ALERT_BYTES,
-                GlobalSettingsProto.NETSTATS_GLOBAL_ALERT_BYTES);
+                GlobalSettingsProto.Netstats.GLOBAL_ALERT_BYTES);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_SAMPLE_ENABLED,
-                GlobalSettingsProto.NETSTATS_SAMPLE_ENABLED);
+                GlobalSettingsProto.Netstats.SAMPLE_ENABLED);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_AUGMENT_ENABLED,
-                GlobalSettingsProto.NETSTATS_AUGMENT_ENABLED);
+                GlobalSettingsProto.Netstats.AUGMENT_ENABLED);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_DEV_BUCKET_DURATION,
-                GlobalSettingsProto.NETSTATS_DEV_BUCKET_DURATION);
+                GlobalSettingsProto.Netstats.DEV_BUCKET_DURATION);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_DEV_PERSIST_BYTES,
-                GlobalSettingsProto.NETSTATS_DEV_PERSIST_BYTES);
+                GlobalSettingsProto.Netstats.DEV_PERSIST_BYTES);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_DEV_ROTATE_AGE,
-                GlobalSettingsProto.NETSTATS_DEV_ROTATE_AGE);
+                GlobalSettingsProto.Netstats.DEV_ROTATE_AGE);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_DEV_DELETE_AGE,
-                GlobalSettingsProto.NETSTATS_DEV_DELETE_AGE);
+                GlobalSettingsProto.Netstats.DEV_DELETE_AGE);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_UID_BUCKET_DURATION,
-                GlobalSettingsProto.NETSTATS_UID_BUCKET_DURATION);
+                GlobalSettingsProto.Netstats.UID_BUCKET_DURATION);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_UID_PERSIST_BYTES,
-                GlobalSettingsProto.NETSTATS_UID_PERSIST_BYTES);
+                GlobalSettingsProto.Netstats.UID_PERSIST_BYTES);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_UID_ROTATE_AGE,
-                GlobalSettingsProto.NETSTATS_UID_ROTATE_AGE);
+                GlobalSettingsProto.Netstats.UID_ROTATE_AGE);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_UID_DELETE_AGE,
-                GlobalSettingsProto.NETSTATS_UID_DELETE_AGE);
+                GlobalSettingsProto.Netstats.UID_DELETE_AGE);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_UID_TAG_BUCKET_DURATION,
-                GlobalSettingsProto.NETSTATS_UID_TAG_BUCKET_DURATION);
+                GlobalSettingsProto.Netstats.UID_TAG_BUCKET_DURATION);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_UID_TAG_PERSIST_BYTES,
-                GlobalSettingsProto.NETSTATS_UID_TAG_PERSIST_BYTES);
+                GlobalSettingsProto.Netstats.UID_TAG_PERSIST_BYTES);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_UID_TAG_ROTATE_AGE,
-                GlobalSettingsProto.NETSTATS_UID_TAG_ROTATE_AGE);
+                GlobalSettingsProto.Netstats.UID_TAG_ROTATE_AGE);
         dumpSetting(s, p,
                 Settings.Global.NETSTATS_UID_TAG_DELETE_AGE,
-                GlobalSettingsProto.NETSTATS_UID_TAG_DELETE_AGE);
+                GlobalSettingsProto.Netstats.UID_TAG_DELETE_AGE);
+        p.end(netstatsToken);
+
+        final long networkToken = p.start(GlobalSettingsProto.NETWORK);
         dumpSetting(s, p,
                 Settings.Global.NETWORK_PREFERENCE,
-                GlobalSettingsProto.NETWORK_PREFERENCE);
+                GlobalSettingsProto.Network.PREFERENCE);
+        dumpSetting(s, p,
+                Settings.Global.PREFERRED_NETWORK_MODE,
+                GlobalSettingsProto.Network.PREFERRED_NETWORK_MODE);
         dumpSetting(s, p,
                 Settings.Global.NETWORK_SCORER_APP,
-                GlobalSettingsProto.NETWORK_SCORER_APP);
+                GlobalSettingsProto.Network.SCORER_APP);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_SWITCH_NOTIFICATION_DAILY_LIMIT,
+                GlobalSettingsProto.Network.SWITCH_NOTIFICATION_DAILY_LIMIT);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS,
+                GlobalSettingsProto.Network.SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_AVOID_BAD_WIFI,
+                GlobalSettingsProto.Network.AVOID_BAD_WIFI);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_METERED_MULTIPATH_PREFERENCE,
+                GlobalSettingsProto.Network.METERED_MULTIPATH_PREFERENCE);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_WATCHLIST_LAST_REPORT_TIME,
+                GlobalSettingsProto.Network.WATCHLIST_LAST_REPORT_TIME);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_SCORING_UI_ENABLED,
+                GlobalSettingsProto.Network.SCORING_UI_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED,
+                GlobalSettingsProto.Network.RECOMMENDATIONS_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE,
+                GlobalSettingsProto.Network.RECOMMENDATIONS_PACKAGE);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_RECOMMENDATION_REQUEST_TIMEOUT_MS,
+                GlobalSettingsProto.Network.RECOMMENDATION_REQUEST_TIMEOUT_MS);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_WATCHLIST_ENABLED,
+                GlobalSettingsProto.Network.WATCHLIST_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_SCORING_PROVISIONED,
+                GlobalSettingsProto.Network.SCORING_PROVISIONED);
+        dumpSetting(s, p,
+                Settings.Global.NETWORK_ACCESS_TIMEOUT_MS,
+                GlobalSettingsProto.Network.ACCESS_TIMEOUT_MS);
+        dumpSetting(s, p,
+                Settings.Global.RECOMMENDED_NETWORK_EVALUATOR_CACHE_EXPIRY_MS,
+                GlobalSettingsProto.Network.RECOMMENDED_NETWORK_EVALUATOR_CACHE_EXPIRY_MS);
+        p.end(networkToken);
+
+        dumpSetting(s, p,
+                Settings.Global.NEW_CONTACT_AGGREGATOR,
+                GlobalSettingsProto.NEW_CONTACT_AGGREGATOR);
         dumpSetting(s, p,
                 Settings.Global.NIGHT_DISPLAY_FORCED_AUTO_MODE_AVAILABLE,
                 GlobalSettingsProto.NIGHT_DISPLAY_FORCED_AUTO_MODE_AVAILABLE);
+
+        final long nitzUpdateToken = p.start(GlobalSettingsProto.NITZ_UPDATE);
         dumpSetting(s, p,
                 Settings.Global.NITZ_UPDATE_DIFF,
-                GlobalSettingsProto.NITZ_UPDATE_DIFF);
+                GlobalSettingsProto.NitzUpdate.DIFF);
         dumpSetting(s, p,
                 Settings.Global.NITZ_UPDATE_SPACING,
-                GlobalSettingsProto.NITZ_UPDATE_SPACING);
+                GlobalSettingsProto.NitzUpdate.SPACING);
+        p.end(nitzUpdateToken);
+
+        final long notificationToken = p.start(GlobalSettingsProto.NOTIFICATION);
+        dumpSetting(s, p,
+                Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE,
+                GlobalSettingsProto.Notification.MAX_NOTIFICATION_ENQUEUE_RATE);
+        dumpSetting(s, p,
+                Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS,
+                GlobalSettingsProto.Notification.SHOW_NOTIFICATION_CHANNEL_WARNINGS);
+        // The list of snooze options for notifications. This is encoded as a key=value list,
+        // separated by commas.
+        dumpSetting(s, p,
+                Settings.Global.NOTIFICATION_SNOOZE_OPTIONS,
+                GlobalSettingsProto.Notification.SNOOZE_OPTIONS);
+        dumpSetting(s, p,
+                Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS,
+                GlobalSettingsProto.Notification.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS);
+        p.end(notificationToken);
+
+        dumpSetting(s, p,
+                Settings.Global.NSD_ON,
+                GlobalSettingsProto.NSD_ON);
+
+        final long ntpToken = p.start(GlobalSettingsProto.NTP);
         dumpSetting(s, p,
                 Settings.Global.NTP_SERVER,
-                GlobalSettingsProto.NTP_SERVER);
+                GlobalSettingsProto.Ntp.SERVER);
         dumpSetting(s, p,
                 Settings.Global.NTP_TIMEOUT,
-                GlobalSettingsProto.NTP_TIMEOUT);
+                GlobalSettingsProto.Ntp.TIMEOUT_MS);
+        p.end(ntpToken);
+
+        final long obroToken = p.start(GlobalSettingsProto.OFF_BODY_RADIOS_OFF);
         dumpSetting(s, p,
-                Settings.Global.STORAGE_BENCHMARK_INTERVAL,
-                GlobalSettingsProto.STORAGE_BENCHMARK_INTERVAL);
+                Settings.Global.OFF_BODY_RADIOS_OFF_FOR_SMALL_BATTERY_ENABLED,
+                GlobalSettingsProto.OffBodyRadiosOff.ENABLED_FOR_SMALL_BATTERY);
         dumpSetting(s, p,
-                Settings.Global.DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS,
-                GlobalSettingsProto.DNS_RESOLVER_SAMPLE_VALIDITY_SECONDS);
-        dumpSetting(s, p,
-                Settings.Global.DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT,
-                GlobalSettingsProto.DNS_RESOLVER_SUCCESS_THRESHOLD_PERCENT);
-        dumpSetting(s, p,
-                Settings.Global.DNS_RESOLVER_MIN_SAMPLES,
-                GlobalSettingsProto.DNS_RESOLVER_MIN_SAMPLES);
-        dumpSetting(s, p,
-                Settings.Global.DNS_RESOLVER_MAX_SAMPLES,
-                GlobalSettingsProto.DNS_RESOLVER_MAX_SAMPLES);
+                Settings.Global.OFF_BODY_RADIOS_OFF_DELAY_MS,
+                GlobalSettingsProto.OffBodyRadiosOff.DELAY_MS);
+        p.end(obroToken);
+
         dumpSetting(s, p,
                 Settings.Global.OTA_DISABLE_AUTOMATIC_UPDATE,
                 GlobalSettingsProto.OTA_DISABLE_AUTOMATIC_UPDATE);
         dumpSetting(s, p,
+                Settings.Global.OVERLAY_DISPLAY_DEVICES,
+                GlobalSettingsProto.OVERLAY_DISPLAY_DEVICES);
+        dumpSetting(s, p,
+                Settings.Global.OVERRIDE_SETTINGS_PROVIDER_RESTORE_ANY_VERSION,
+                GlobalSettingsProto.OVERRIDE_SETTINGS_PROVIDER_RESTORE_ANY_VERSION);
+        dumpSetting(s, p,
+                Settings.Global.PAC_CHANGE_DELAY,
+                GlobalSettingsProto.PAC_CHANGE_DELAY);
+
+        final long pkgVerifierToken = p.start(GlobalSettingsProto.PACKAGE_VERIFIER);
+        dumpSetting(s, p,
                 Settings.Global.PACKAGE_VERIFIER_ENABLE,
-                GlobalSettingsProto.PACKAGE_VERIFIER_ENABLE);
+                GlobalSettingsProto.PackageVerifier.ENABLED);
         dumpSetting(s, p,
                 Settings.Global.PACKAGE_VERIFIER_TIMEOUT,
-                GlobalSettingsProto.PACKAGE_VERIFIER_TIMEOUT);
+                GlobalSettingsProto.PackageVerifier.TIMEOUT);
         dumpSetting(s, p,
                 Settings.Global.PACKAGE_VERIFIER_DEFAULT_RESPONSE,
-                GlobalSettingsProto.PACKAGE_VERIFIER_DEFAULT_RESPONSE);
+                GlobalSettingsProto.PackageVerifier.DEFAULT_RESPONSE);
         dumpSetting(s, p,
                 Settings.Global.PACKAGE_VERIFIER_SETTING_VISIBLE,
-                GlobalSettingsProto.PACKAGE_VERIFIER_SETTING_VISIBLE);
+                GlobalSettingsProto.PackageVerifier.SETTING_VISIBLE);
         dumpSetting(s, p,
                 Settings.Global.PACKAGE_VERIFIER_INCLUDE_ADB,
-                GlobalSettingsProto.PACKAGE_VERIFIER_INCLUDE_ADB);
-        dumpSetting(s, p,
-                Settings.Global.FSTRIM_MANDATORY_INTERVAL,
-                GlobalSettingsProto.FSTRIM_MANDATORY_INTERVAL);
+                GlobalSettingsProto.PackageVerifier.INCLUDE_ADB);
+        p.end(pkgVerifierToken);
+
+        final long pdpWatchdogToken = p.start(GlobalSettingsProto.PDP_WATCHDOG);
         dumpSetting(s, p,
                 Settings.Global.PDP_WATCHDOG_POLL_INTERVAL_MS,
-                GlobalSettingsProto.PDP_WATCHDOG_POLL_INTERVAL_MS);
+                GlobalSettingsProto.PdpWatchdog.POLL_INTERVAL_MS);
         dumpSetting(s, p,
                 Settings.Global.PDP_WATCHDOG_LONG_POLL_INTERVAL_MS,
-                GlobalSettingsProto.PDP_WATCHDOG_LONG_POLL_INTERVAL_MS);
+                GlobalSettingsProto.PdpWatchdog.LONG_POLL_INTERVAL_MS);
         dumpSetting(s, p,
                 Settings.Global.PDP_WATCHDOG_ERROR_POLL_INTERVAL_MS,
-                GlobalSettingsProto.PDP_WATCHDOG_ERROR_POLL_INTERVAL_MS);
+                GlobalSettingsProto.PdpWatchdog.ERROR_POLL_INTERVAL_MS);
         dumpSetting(s, p,
                 Settings.Global.PDP_WATCHDOG_TRIGGER_PACKET_COUNT,
-                GlobalSettingsProto.PDP_WATCHDOG_TRIGGER_PACKET_COUNT);
+                GlobalSettingsProto.PdpWatchdog.TRIGGER_PACKET_COUNT);
         dumpSetting(s, p,
                 Settings.Global.PDP_WATCHDOG_ERROR_POLL_COUNT,
-                GlobalSettingsProto.PDP_WATCHDOG_ERROR_POLL_COUNT);
+                GlobalSettingsProto.PdpWatchdog.ERROR_POLL_COUNT);
         dumpSetting(s, p,
                 Settings.Global.PDP_WATCHDOG_MAX_PDP_RESET_FAIL_COUNT,
-                GlobalSettingsProto.PDP_WATCHDOG_MAX_PDP_RESET_FAIL_COUNT);
+                GlobalSettingsProto.PdpWatchdog.MAX_PDP_RESET_FAIL_COUNT);
+        p.end(pdpWatchdogToken);
+
+        dumpSetting(s, p,
+                Settings.Global.POLICY_CONTROL,
+                GlobalSettingsProto.POLICY_CONTROL);
+        dumpSetting(s, p,
+                Settings.Global.POWER_MANAGER_CONSTANTS,
+                GlobalSettingsProto.POWER_MANAGER_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.PRIV_APP_OOB_ENABLED,
+                GlobalSettingsProto.PRIV_APP_OOB_ENABLED);
+
+        final long prepaidSetupToken = p.start(GlobalSettingsProto.PREPAID_SETUP);
         dumpSetting(s, p,
                 Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL,
-                GlobalSettingsProto.SETUP_PREPAID_DATA_SERVICE_URL);
+                GlobalSettingsProto.PrepaidSetup.DATA_SERVICE_URL);
         dumpSetting(s, p,
                 Settings.Global.SETUP_PREPAID_DETECTION_TARGET_URL,
-                GlobalSettingsProto.SETUP_PREPAID_DETECTION_TARGET_URL);
+                GlobalSettingsProto.PrepaidSetup.DETECTION_TARGET_URL);
         dumpSetting(s, p,
                 Settings.Global.SETUP_PREPAID_DETECTION_REDIR_HOST,
-                GlobalSettingsProto.SETUP_PREPAID_DETECTION_REDIR_HOST);
+                GlobalSettingsProto.PrepaidSetup.DETECTION_REDIR_HOST);
+        p.end(prepaidSetupToken);
+
+        final long privateToken = p.start(GlobalSettingsProto.PRIVATE);
+        dumpSetting(s, p,
+                Settings.Global.PRIVATE_DNS_MODE,
+                GlobalSettingsProto.Private.DNS_MODE);
+        dumpSetting(s, p,
+                Settings.Global.PRIVATE_DNS_SPECIFIER,
+                GlobalSettingsProto.Private.DNS_SPECIFIER);
+        p.end(privateToken);
+
+        dumpSetting(s, p,
+                Settings.Global.PROVISIONING_APN_ALARM_DELAY_IN_MS,
+                GlobalSettingsProto.PROVISIONING_APN_ALARM_DELAY_IN_MS);
+        dumpSetting(s, p,
+                Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT,
+                GlobalSettingsProto.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT);
+        dumpSetting(s, p,
+                Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT,
+                GlobalSettingsProto.REQUIRE_PASSWORD_TO_DECRYPT);
+        dumpSetting(s, p,
+                Settings.Global.SAFE_BOOT_DISALLOWED,
+                GlobalSettingsProto.SAFE_BOOT_DISALLOWED);
+
+        final long selinuxToken = p.start(GlobalSettingsProto.SELINUX);
+        dumpSetting(s, p,
+                Settings.Global.SELINUX_UPDATE_CONTENT_URL,
+                GlobalSettingsProto.Selinux.UPDATE_CONTENT_URL);
+        dumpSetting(s, p,
+                Settings.Global.SELINUX_UPDATE_METADATA_URL,
+                GlobalSettingsProto.Selinux.UPDATE_METADATA_URL);
+        dumpSetting(s, p,
+                Settings.Global.SELINUX_STATUS,
+                GlobalSettingsProto.Selinux.STATUS);
+        p.end(selinuxToken);
+
+        dumpSetting(s, p,
+                Settings.Global.SEND_ACTION_APP_ERROR,
+                GlobalSettingsProto.SEND_ACTION_APP_ERROR);
+        dumpSetting(s, p,
+                Settings.Global.SET_INSTALL_LOCATION,
+                GlobalSettingsProto.SET_INSTALL_LOCATION);
+        dumpSetting(s, p,
+                Settings.Global.SHORTCUT_MANAGER_CONSTANTS,
+                GlobalSettingsProto.SHORTCUT_MANAGER_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.SHOW_FIRST_CRASH_DIALOG,
+                GlobalSettingsProto.SHOW_FIRST_CRASH_DIALOG);
+        // Settings.Global.SHOW_PROCESSES intentionally excluded since it's deprecated.
+        dumpSetting(s, p,
+                Settings.Global.SHOW_RESTART_IN_CRASH_DIALOG,
+                GlobalSettingsProto.SHOW_RESTART_IN_CRASH_DIALOG);
+        dumpSetting(s, p,
+                Settings.Global.SHOW_MUTE_IN_CRASH_DIALOG,
+                GlobalSettingsProto.SHOW_MUTE_IN_CRASH_DIALOG);
+
+        final long smartSelectToken = p.start(GlobalSettingsProto.SMART_SELECTION);
+        dumpSetting(s, p,
+                Settings.Global.SMART_SELECTION_UPDATE_CONTENT_URL,
+                GlobalSettingsProto.SmartSelection.UPDATE_CONTENT_URL);
+        dumpSetting(s, p,
+                Settings.Global.SMART_SELECTION_UPDATE_METADATA_URL,
+                GlobalSettingsProto.SmartSelection.UPDATE_METADATA_URL);
+        p.end(smartSelectToken);
+
+        final long smsToken = p.start(GlobalSettingsProto.SMS);
         dumpSetting(s, p,
                 Settings.Global.SMS_OUTGOING_CHECK_INTERVAL_MS,
-                GlobalSettingsProto.SMS_OUTGOING_CHECK_INTERVAL_MS);
+                GlobalSettingsProto.Sms.OUTGOING_CHECK_INTERVAL_MS);
         dumpSetting(s, p,
                 Settings.Global.SMS_OUTGOING_CHECK_MAX_COUNT,
-                GlobalSettingsProto.SMS_OUTGOING_CHECK_MAX_COUNT);
+                GlobalSettingsProto.Sms.OUTGOING_CHECK_MAX_COUNT);
         dumpSetting(s, p,
                 Settings.Global.SMS_SHORT_CODE_CONFIRMATION,
-                GlobalSettingsProto.SMS_SHORT_CODE_CONFIRMATION);
+                GlobalSettingsProto.Sms.SHORT_CODE_CONFIRMATION);
         dumpSetting(s, p,
                 Settings.Global.SMS_SHORT_CODE_RULE,
-                GlobalSettingsProto.SMS_SHORT_CODE_RULE);
+                GlobalSettingsProto.Sms.SHORT_CODE_RULE);
+        dumpSetting(s, p,
+                Settings.Global.SMS_SHORT_CODES_UPDATE_CONTENT_URL,
+                GlobalSettingsProto.Sms.SHORT_CODES_UPDATE_CONTENT_URL);
+        dumpSetting(s, p,
+                Settings.Global.SMS_SHORT_CODES_UPDATE_METADATA_URL,
+                GlobalSettingsProto.Sms.SHORT_CODES_UPDATE_METADATA_URL);
+        p.end(smsToken);
+
+        final long soundsToken = p.start(GlobalSettingsProto.SOUNDS);
+        dumpSetting(s, p,
+                Settings.Global.CAR_DOCK_SOUND,
+                GlobalSettingsProto.Sounds.CAR_DOCK);
+        dumpSetting(s, p,
+                Settings.Global.CAR_UNDOCK_SOUND,
+                GlobalSettingsProto.Sounds.CAR_UNDOCK);
+        dumpSetting(s, p,
+                Settings.Global.DESK_DOCK_SOUND,
+                GlobalSettingsProto.Sounds.DESK_DOCK);
+        dumpSetting(s, p,
+                Settings.Global.DESK_UNDOCK_SOUND,
+                GlobalSettingsProto.Sounds.DESK_UNDOCK);
+        dumpSetting(s, p,
+                Settings.Global.DOCK_SOUNDS_ENABLED,
+                GlobalSettingsProto.Sounds.DOCK_SOUNDS_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY,
+                GlobalSettingsProto.Sounds.DOCK_SOUNDS_ENABLED_WHEN_ACCESSIBILITY);
+        dumpSetting(s, p,
+                Settings.Global.LOCK_SOUND,
+                GlobalSettingsProto.Sounds.LOCK);
+        dumpSetting(s, p,
+                Settings.Global.UNLOCK_SOUND,
+                GlobalSettingsProto.Sounds.UNLOCK);
+        dumpSetting(s, p,
+                Settings.Global.TRUSTED_SOUND,
+                GlobalSettingsProto.Sounds.TRUSTED);
+        dumpSetting(s, p,
+                Settings.Global.LOW_BATTERY_SOUND,
+                GlobalSettingsProto.Sounds.LOW_BATTERY);
+        dumpSetting(s, p,
+                Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
+                GlobalSettingsProto.Sounds.LOW_BATTERY_SOUND_TIMEOUT);
+        dumpSetting(s, p,
+                Settings.Global.POWER_SOUNDS_ENABLED,
+                GlobalSettingsProto.Sounds.LOW_BATTERY_SOUNDS_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.CHARGING_STARTED_SOUND,
+                GlobalSettingsProto.Sounds.CHARGING_STARTED);
+        dumpSetting(s, p,
+                Settings.Global.CHARGING_SOUNDS_ENABLED,
+                GlobalSettingsProto.Sounds.CHARGING_SOUNDS_ENABLED);
+        p.end(soundsToken);
+
+        final long soundTriggerToken = p.start(GlobalSettingsProto.SOUND_TRIGGER);
+        dumpSetting(s, p,
+                Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY,
+                GlobalSettingsProto.SoundTrigger.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY);
+        dumpSetting(s, p,
+                Global.SOUND_TRIGGER_DETECTION_SERVICE_OP_TIMEOUT,
+                GlobalSettingsProto.SoundTrigger.DETECTION_SERVICE_OP_TIMEOUT_MS);
+        p.end(soundTriggerToken);
+
+        dumpSetting(s, p,
+                Settings.Global.SPEED_LABEL_CACHE_EVICTION_AGE_MILLIS,
+                GlobalSettingsProto.SPEED_LABEL_CACHE_EVICTION_AGE_MS);
+        dumpSetting(s, p,
+                Settings.Global.SQLITE_COMPATIBILITY_WAL_FLAGS,
+                GlobalSettingsProto.SQLITE_COMPATIBILITY_WAL_FLAGS);
+        dumpSetting(s, p,
+                Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
+                GlobalSettingsProto.STAY_ON_WHILE_PLUGGED_IN);
+
+        final long storageToken = p.start(GlobalSettingsProto.STORAGE);
+        dumpSetting(s, p,
+                Settings.Global.STORAGE_BENCHMARK_INTERVAL,
+                GlobalSettingsProto.Storage.BENCHMARK_INTERVAL);
+        dumpSetting(s, p,
+                Settings.Global.STORAGE_SETTINGS_CLOBBER_THRESHOLD,
+                GlobalSettingsProto.Storage.SETTINGS_CLOBBER_THRESHOLD);
+        p.end(storageToken);
+
+        final long syncToken = p.start(GlobalSettingsProto.SYNC);
+        dumpSetting(s, p,
+                Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS,
+                GlobalSettingsProto.Sync.MAX_RETRY_DELAY_IN_SECONDS);
+        dumpSetting(s, p,
+                Settings.Global.SYNC_MANAGER_CONSTANTS,
+                GlobalSettingsProto.Sync.MANAGER_CONSTANTS);
+        p.end(syncToken);
+
+        final long sysToken = p.start(GlobalSettingsProto.SYS);
+        dumpSetting(s, p,
+                Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
+                GlobalSettingsProto.Sys.FREE_STORAGE_LOG_INTERVAL_MINS);
+        dumpSetting(s, p,
+                Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE,
+                GlobalSettingsProto.Sys.STORAGE_THRESHOLD_PERCENTAGE);
+        dumpSetting(s, p,
+                Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES,
+                GlobalSettingsProto.Sys.STORAGE_THRESHOLD_MAX_BYTES);
+        dumpSetting(s, p,
+                Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES,
+                GlobalSettingsProto.Sys.STORAGE_FULL_THRESHOLD_BYTES);
+        dumpSetting(s, p,
+                Settings.Global.SYS_STORAGE_CACHE_PERCENTAGE,
+                GlobalSettingsProto.Sys.STORAGE_CACHE_PERCENTAGE);
+        dumpSetting(s, p,
+                Settings.Global.SYS_STORAGE_CACHE_MAX_BYTES,
+                GlobalSettingsProto.Sys.STORAGE_CACHE_MAX_BYTES);
+        dumpSetting(s, p,
+                Settings.Global.SYS_VDSO,
+                GlobalSettingsProto.Sys.VDSO);
+        dumpSetting(s, p,
+                Settings.Global.SYS_UIDCPUPOWER,
+                GlobalSettingsProto.Sys.UIDCPUPOWER);
+        p.end(sysToken);
+
         dumpSetting(s, p,
                 Settings.Global.TCP_DEFAULT_INIT_RWND,
                 GlobalSettingsProto.TCP_DEFAULT_INIT_RWND);
+
+        final long tempWarningToken = p.start(GlobalSettingsProto.TEMPERATURE_WARNING);
+        dumpSetting(s, p,
+                Settings.Global.SHOW_TEMPERATURE_WARNING,
+                GlobalSettingsProto.TemperatureWarning.SHOW_TEMPERATURE_WARNING);
+        dumpSetting(s, p,
+                Settings.Global.WARNING_TEMPERATURE,
+                GlobalSettingsProto.TemperatureWarning.WARNING_TEMPERATURE_LEVEL);
+        p.end(tempWarningToken);
+
+        final long tetherToken = p.start(GlobalSettingsProto.TETHER);
         dumpSetting(s, p,
                 Settings.Global.TETHER_SUPPORTED,
-                GlobalSettingsProto.TETHER_SUPPORTED);
+                GlobalSettingsProto.Tether.SUPPORTED);
         dumpSetting(s, p,
                 Settings.Global.TETHER_DUN_REQUIRED,
-                GlobalSettingsProto.TETHER_DUN_REQUIRED);
+                GlobalSettingsProto.Tether.DUN_REQUIRED);
         dumpSetting(s, p,
                 Settings.Global.TETHER_DUN_APN,
-                GlobalSettingsProto.TETHER_DUN_APN);
+                GlobalSettingsProto.Tether.DUN_APN);
         dumpSetting(s, p,
                 Settings.Global.TETHER_OFFLOAD_DISABLED,
-                GlobalSettingsProto.TETHER_OFFLOAD_DISABLED);
+                GlobalSettingsProto.Tether.OFFLOAD_DISABLED);
         dumpSetting(s, p,
-                Settings.Global.CARRIER_APP_WHITELIST,
-                GlobalSettingsProto.CARRIER_APP_WHITELIST);
+                Settings.Global.SOFT_AP_TIMEOUT_ENABLED,
+                GlobalSettingsProto.Tether.TIMEOUT_ENABLED);
+        p.end(tetherToken);
+
         dumpSetting(s, p,
-                Settings.Global.CARRIER_APP_NAMES,
-                GlobalSettingsProto.CARRIER_APP_NAMES);
+                Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
+                GlobalSettingsProto.TEXT_CLASSIFIER_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.THEATER_MODE_ON,
+                GlobalSettingsProto.THEATER_MODE_ON);
+        dumpSetting(s, p,
+                Settings.Global.TIME_ONLY_MODE_CONSTANTS,
+                GlobalSettingsProto.TIME_ONLY_MODE_CONSTANTS);
+        dumpSetting(s, p,
+                Settings.Global.TRANSITION_ANIMATION_SCALE,
+                GlobalSettingsProto.TRANSITION_ANIMATION_SCALE);
+
+        final long tzinfoToken = p.start(GlobalSettingsProto.TZINFO);
+        dumpSetting(s, p,
+                Settings.Global.TZINFO_UPDATE_CONTENT_URL,
+                GlobalSettingsProto.Tzinfo.UPDATE_CONTENT_URL);
+        dumpSetting(s, p,
+                Settings.Global.TZINFO_UPDATE_METADATA_URL,
+                GlobalSettingsProto.Tzinfo.UPDATE_METADATA_URL);
+        p.end(tzinfoToken);
+
+        dumpSetting(s, p,
+                Settings.Global.UNUSED_STATIC_SHARED_LIB_MIN_CACHE_PERIOD,
+                GlobalSettingsProto.UNUSED_STATIC_SHARED_LIB_MIN_CACHE_PERIOD_MS);
         dumpSetting(s, p,
                 Settings.Global.USB_MASS_STORAGE_ENABLED,
                 GlobalSettingsProto.USB_MASS_STORAGE_ENABLED);
@@ -461,807 +1296,186 @@
                 Settings.Global.USE_GOOGLE_MAIL,
                 GlobalSettingsProto.USE_GOOGLE_MAIL);
         dumpSetting(s, p,
-                Settings.Global.WEBVIEW_DATA_REDUCTION_PROXY_KEY,
-                GlobalSettingsProto.WEBVIEW_DATA_REDUCTION_PROXY_KEY);
-        dumpSetting(s, p,
-                Settings.Global.WEBVIEW_FALLBACK_LOGIC_ENABLED,
-                GlobalSettingsProto.WEBVIEW_FALLBACK_LOGIC_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.WEBVIEW_PROVIDER,
-                GlobalSettingsProto.WEBVIEW_PROVIDER);
-        dumpSetting(s, p,
-                Settings.Global.WEBVIEW_MULTIPROCESS,
-                GlobalSettingsProto.WEBVIEW_MULTIPROCESS);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_SWITCH_NOTIFICATION_DAILY_LIMIT,
-                GlobalSettingsProto.NETWORK_SWITCH_NOTIFICATION_DAILY_LIMIT);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS,
-                GlobalSettingsProto.NETWORK_SWITCH_NOTIFICATION_RATE_LIMIT_MILLIS);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_AVOID_BAD_WIFI,
-                GlobalSettingsProto.NETWORK_AVOID_BAD_WIFI);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_METERED_MULTIPATH_PREFERENCE,
-                GlobalSettingsProto.NETWORK_METERED_MULTIPATH_PREFERENCE);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_WATCHLIST_LAST_REPORT_TIME,
-                GlobalSettingsProto.NETWORK_WATCHLIST_LAST_REPORT_TIME);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_BADGING_THRESHOLDS,
-                GlobalSettingsProto.WIFI_BADGING_THRESHOLDS);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_DISPLAY_ON,
-                GlobalSettingsProto.WIFI_DISPLAY_ON);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
-                GlobalSettingsProto.WIFI_DISPLAY_CERTIFICATION_ON);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_DISPLAY_WPS_CONFIG,
-                GlobalSettingsProto.WIFI_DISPLAY_WPS_CONFIG);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
-                GlobalSettingsProto.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_CARRIER_NETWORKS_AVAILABLE_NOTIFICATION_ON,
-                GlobalSettingsProto.WIFI_CARRIER_NETWORKS_AVAILABLE_NOTIFICATION_ON);
-        dumpSetting(s, p,
-                Settings.Global.WIMAX_NETWORKS_AVAILABLE_NOTIFICATION_ON,
-                GlobalSettingsProto.WIMAX_NETWORKS_AVAILABLE_NOTIFICATION_ON);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
-                GlobalSettingsProto.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_COUNTRY_CODE,
-                GlobalSettingsProto.WIFI_COUNTRY_CODE);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_FRAMEWORK_SCAN_INTERVAL_MS,
-                GlobalSettingsProto.WIFI_FRAMEWORK_SCAN_INTERVAL_MS);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_IDLE_MS,
-                GlobalSettingsProto.WIFI_IDLE_MS);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_NUM_OPEN_NETWORKS_KEPT,
-                GlobalSettingsProto.WIFI_NUM_OPEN_NETWORKS_KEPT);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_ON,
-                GlobalSettingsProto.WIFI_ON);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
-                GlobalSettingsProto.WIFI_SCAN_ALWAYS_AVAILABLE);
-        dumpSetting(s, p,
-                Settings.Global.SOFT_AP_TIMEOUT_ENABLED,
-                GlobalSettingsProto.SOFT_AP_TIMEOUT_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_WAKEUP_ENABLED,
-                GlobalSettingsProto.WIFI_WAKEUP_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_SCORING_UI_ENABLED,
-                GlobalSettingsProto.NETWORK_SCORING_UI_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.SPEED_LABEL_CACHE_EVICTION_AGE_MILLIS,
-                GlobalSettingsProto.SPEED_LABEL_CACHE_EVICTION_AGE_MILLIS);
-        dumpSetting(s, p,
-                Settings.Global.RECOMMENDED_NETWORK_EVALUATOR_CACHE_EXPIRY_MS,
-                GlobalSettingsProto.RECOMMENDED_NETWORK_EVALUATOR_CACHE_EXPIRY_MS);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_RECOMMENDATIONS_ENABLED,
-                GlobalSettingsProto.NETWORK_RECOMMENDATIONS_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_RECOMMENDATIONS_PACKAGE,
-                GlobalSettingsProto.NETWORK_RECOMMENDATIONS_PACKAGE);
-        dumpSetting(s, p,
                 Settings.Global.USE_OPEN_WIFI_PACKAGE,
                 GlobalSettingsProto.USE_OPEN_WIFI_PACKAGE);
         dumpSetting(s, p,
-                Settings.Global.NETWORK_RECOMMENDATION_REQUEST_TIMEOUT_MS,
-                GlobalSettingsProto.NETWORK_RECOMMENDATION_REQUEST_TIMEOUT_MS);
-        dumpSetting(s, p,
-                Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE,
-                GlobalSettingsProto.BLE_SCAN_ALWAYS_AVAILABLE);
-        dumpSetting(s, p,
-                Settings.Global.BLE_SCAN_LOW_POWER_WINDOW_MS,
-                GlobalSettingsProto.BLE_SCAN_LOW_POWER_WINDOW_MS);
-        dumpSetting(s, p,
-                Settings.Global.BLE_SCAN_BALANCED_WINDOW_MS,
-                GlobalSettingsProto.BLE_SCAN_BALANCED_WINDOW_MS);
-        dumpSetting(s, p,
-                Settings.Global.BLE_SCAN_LOW_LATENCY_WINDOW_MS,
-                GlobalSettingsProto.BLE_SCAN_LOW_LATENCY_WINDOW_MS);
-        dumpSetting(s, p,
-                Settings.Global.BLE_SCAN_LOW_POWER_INTERVAL_MS,
-                GlobalSettingsProto.BLE_SCAN_LOW_POWER_INTERVAL_MS);
-        dumpSetting(s, p,
-                Settings.Global.BLE_SCAN_BALANCED_INTERVAL_MS,
-                GlobalSettingsProto.BLE_SCAN_BALANCED_INTERVAL_MS);
-        dumpSetting(s, p,
-                Settings.Global.BLE_SCAN_LOW_LATENCY_INTERVAL_MS,
-                GlobalSettingsProto.BLE_SCAN_LOW_LATENCY_INTERVAL_MS);
-        dumpSetting(s, p,
-                Settings.Global.BLE_SCAN_BACKGROUND_MODE,
-                GlobalSettingsProto.BLE_SCAN_BACKGROUND_MODE);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_SAVED_STATE,
-                GlobalSettingsProto.WIFI_SAVED_STATE);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_SUPPLICANT_SCAN_INTERVAL_MS,
-                GlobalSettingsProto.WIFI_SUPPLICANT_SCAN_INTERVAL_MS);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_ENHANCED_AUTO_JOIN,
-                GlobalSettingsProto.WIFI_ENHANCED_AUTO_JOIN);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_NETWORK_SHOW_RSSI,
-                GlobalSettingsProto.WIFI_NETWORK_SHOW_RSSI);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_SCAN_INTERVAL_WHEN_P2P_CONNECTED_MS,
-                GlobalSettingsProto.WIFI_SCAN_INTERVAL_WHEN_P2P_CONNECTED_MS);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_WATCHDOG_ON,
-                GlobalSettingsProto.WIFI_WATCHDOG_ON);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED,
-                GlobalSettingsProto.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED,
-                GlobalSettingsProto.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED,
-                GlobalSettingsProto.WIFI_VERBOSE_LOGGING_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED,
-                GlobalSettingsProto.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT,
-                GlobalSettingsProto.WIFI_MAX_DHCP_RETRY_COUNT);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS,
-                GlobalSettingsProto.WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN,
-                GlobalSettingsProto.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_FREQUENCY_BAND,
-                GlobalSettingsProto.WIFI_FREQUENCY_BAND);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_P2P_DEVICE_NAME,
-                GlobalSettingsProto.WIFI_P2P_DEVICE_NAME);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_REENABLE_DELAY_MS,
-                GlobalSettingsProto.WIFI_REENABLE_DELAY_MS);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_EPHEMERAL_OUT_OF_RANGE_TIMEOUT_MS,
-                GlobalSettingsProto.WIFI_EPHEMERAL_OUT_OF_RANGE_TIMEOUT_MS);
-        dumpSetting(s, p,
-                Settings.Global.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS,
-                GlobalSettingsProto.DATA_STALL_ALARM_NON_AGGRESSIVE_DELAY_IN_MS);
-        dumpSetting(s, p,
-                Settings.Global.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS,
-                GlobalSettingsProto.DATA_STALL_ALARM_AGGRESSIVE_DELAY_IN_MS);
-        dumpSetting(s, p,
-                Settings.Global.PROVISIONING_APN_ALARM_DELAY_IN_MS,
-                GlobalSettingsProto.PROVISIONING_APN_ALARM_DELAY_IN_MS);
-        dumpSetting(s, p,
-                Settings.Global.GPRS_REGISTER_CHECK_PERIOD_MS,
-                GlobalSettingsProto.GPRS_REGISTER_CHECK_PERIOD_MS);
-        dumpSetting(s, p,
-                Settings.Global.WTF_IS_FATAL,
-                GlobalSettingsProto.WTF_IS_FATAL);
-        dumpSetting(s, p,
-                Settings.Global.MODE_RINGER,
-                GlobalSettingsProto.MODE_RINGER);
-        dumpSetting(s, p,
-                Settings.Global.OVERLAY_DISPLAY_DEVICES,
-                GlobalSettingsProto.OVERLAY_DISPLAY_DEVICES);
-        dumpSetting(s, p,
-                Settings.Global.BATTERY_DISCHARGE_DURATION_THRESHOLD,
-                GlobalSettingsProto.BATTERY_DISCHARGE_DURATION_THRESHOLD);
-        dumpSetting(s, p,
-                Settings.Global.BATTERY_DISCHARGE_THRESHOLD,
-                GlobalSettingsProto.BATTERY_DISCHARGE_THRESHOLD);
-        dumpSetting(s, p,
-                Settings.Global.SEND_ACTION_APP_ERROR,
-                GlobalSettingsProto.SEND_ACTION_APP_ERROR);
-        dumpSetting(s, p,
-                Settings.Global.DROPBOX_AGE_SECONDS,
-                GlobalSettingsProto.DROPBOX_AGE_SECONDS);
-        dumpSetting(s, p,
-                Settings.Global.DROPBOX_MAX_FILES,
-                GlobalSettingsProto.DROPBOX_MAX_FILES);
-        dumpSetting(s, p,
-                Settings.Global.DROPBOX_QUOTA_KB,
-                GlobalSettingsProto.DROPBOX_QUOTA_KB);
-        dumpSetting(s, p,
-                Settings.Global.DROPBOX_QUOTA_PERCENT,
-                GlobalSettingsProto.DROPBOX_QUOTA_PERCENT);
-        dumpSetting(s, p,
-                Settings.Global.DROPBOX_RESERVE_PERCENT,
-                GlobalSettingsProto.DROPBOX_RESERVE_PERCENT);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.DROPBOX_TAG_PREFIX,
-                GlobalSettingsProto.DROPBOX_SETTINGS);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.ERROR_LOGCAT_PREFIX,
-                GlobalSettingsProto.ERROR_LOGCAT_LINES);
-        dumpSetting(s, p,
-                Settings.Global.SYS_FREE_STORAGE_LOG_INTERVAL,
-                GlobalSettingsProto.SYS_FREE_STORAGE_LOG_INTERVAL);
-        dumpSetting(s, p,
-                Settings.Global.DISK_FREE_CHANGE_REPORTING_THRESHOLD,
-                GlobalSettingsProto.DISK_FREE_CHANGE_REPORTING_THRESHOLD);
-        dumpSetting(s, p,
-                Settings.Global.SYS_STORAGE_THRESHOLD_PERCENTAGE,
-                GlobalSettingsProto.SYS_STORAGE_THRESHOLD_PERCENTAGE);
-        dumpSetting(s, p,
-                Settings.Global.SYS_STORAGE_THRESHOLD_MAX_BYTES,
-                GlobalSettingsProto.SYS_STORAGE_THRESHOLD_MAX_BYTES);
-        dumpSetting(s, p,
-                Settings.Global.SYS_STORAGE_FULL_THRESHOLD_BYTES,
-                GlobalSettingsProto.SYS_STORAGE_FULL_THRESHOLD_BYTES);
-        dumpSetting(s, p,
-                Settings.Global.SYS_STORAGE_CACHE_PERCENTAGE,
-                GlobalSettingsProto.SYS_STORAGE_CACHE_PERCENTAGE);
-        dumpSetting(s, p,
-                Settings.Global.SYS_STORAGE_CACHE_MAX_BYTES,
-                GlobalSettingsProto.SYS_STORAGE_CACHE_MAX_BYTES);
-        dumpSetting(s, p,
-                Settings.Global.SYNC_MAX_RETRY_DELAY_IN_SECONDS,
-                GlobalSettingsProto.SYNC_MAX_RETRY_DELAY_IN_SECONDS);
-        dumpSetting(s, p,
-                Settings.Global.CONNECTIVITY_CHANGE_DELAY,
-                GlobalSettingsProto.CONNECTIVITY_CHANGE_DELAY);
-        dumpSetting(s, p,
-                Settings.Global.CONNECTIVITY_SAMPLING_INTERVAL_IN_SECONDS,
-                GlobalSettingsProto.CONNECTIVITY_SAMPLING_INTERVAL_IN_SECONDS);
-        dumpSetting(s, p,
-                Settings.Global.PAC_CHANGE_DELAY,
-                GlobalSettingsProto.PAC_CHANGE_DELAY);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_MODE,
-                GlobalSettingsProto.CAPTIVE_PORTAL_MODE);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_DETECTION_ENABLED,
-                GlobalSettingsProto.CAPTIVE_PORTAL_DETECTION_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_SERVER,
-                GlobalSettingsProto.CAPTIVE_PORTAL_SERVER);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_HTTPS_URL,
-                GlobalSettingsProto.CAPTIVE_PORTAL_HTTPS_URL);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_HTTP_URL,
-                GlobalSettingsProto.CAPTIVE_PORTAL_HTTP_URL);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_FALLBACK_URL,
-                GlobalSettingsProto.CAPTIVE_PORTAL_FALLBACK_URL);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS,
-                GlobalSettingsProto.CAPTIVE_PORTAL_OTHER_FALLBACK_URLS);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_USE_HTTPS,
-                GlobalSettingsProto.CAPTIVE_PORTAL_USE_HTTPS);
-        dumpSetting(s, p,
-                Settings.Global.CAPTIVE_PORTAL_USER_AGENT,
-                GlobalSettingsProto.CAPTIVE_PORTAL_USER_AGENT);
-        dumpSetting(s, p,
-                Settings.Global.NSD_ON,
-                GlobalSettingsProto.NSD_ON);
-        dumpSetting(s, p,
-                Settings.Global.SET_INSTALL_LOCATION,
-                GlobalSettingsProto.SET_INSTALL_LOCATION);
-        dumpSetting(s, p,
-                Settings.Global.DEFAULT_INSTALL_LOCATION,
-                GlobalSettingsProto.DEFAULT_INSTALL_LOCATION);
-        dumpSetting(s, p,
-                Settings.Global.INET_CONDITION_DEBOUNCE_UP_DELAY,
-                GlobalSettingsProto.INET_CONDITION_DEBOUNCE_UP_DELAY);
-        dumpSetting(s, p,
-                Settings.Global.INET_CONDITION_DEBOUNCE_DOWN_DELAY,
-                GlobalSettingsProto.INET_CONDITION_DEBOUNCE_DOWN_DELAY);
-        dumpSetting(s, p,
-                Settings.Global.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT,
-                GlobalSettingsProto.READ_EXTERNAL_STORAGE_ENFORCED_DEFAULT);
-        dumpSetting(s, p,
-                Settings.Global.HTTP_PROXY,
-                GlobalSettingsProto.HTTP_PROXY);
-        dumpSetting(s, p,
-                Settings.Global.GLOBAL_HTTP_PROXY_HOST,
-                GlobalSettingsProto.GLOBAL_HTTP_PROXY_HOST);
-        dumpSetting(s, p,
-                Settings.Global.GLOBAL_HTTP_PROXY_PORT,
-                GlobalSettingsProto.GLOBAL_HTTP_PROXY_PORT);
-        dumpSetting(s, p,
-                Settings.Global.GLOBAL_HTTP_PROXY_EXCLUSION_LIST,
-                GlobalSettingsProto.GLOBAL_HTTP_PROXY_EXCLUSION_LIST);
-        dumpSetting(s, p,
-                Settings.Global.GLOBAL_HTTP_PROXY_PAC,
-                GlobalSettingsProto.GLOBAL_HTTP_PROXY_PAC);
-        dumpSetting(s, p,
-                Settings.Global.SET_GLOBAL_HTTP_PROXY,
-                GlobalSettingsProto.SET_GLOBAL_HTTP_PROXY);
-        dumpSetting(s, p,
-                Settings.Global.DEFAULT_DNS_SERVER,
-                GlobalSettingsProto.DEFAULT_DNS_SERVER);
-        dumpSetting(s, p,
-                Settings.Global.PRIVATE_DNS_MODE,
-                GlobalSettingsProto.PRIVATE_DNS_MODE);
-        dumpSetting(s, p,
-                Settings.Global.PRIVATE_DNS_SPECIFIER,
-                GlobalSettingsProto.PRIVATE_DNS_SPECIFIER);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_HEADSET_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_HEADSET_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_A2DP_SINK_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_A2DP_SINK_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_A2DP_SRC_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_A2DP_SRC_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_A2DP_SUPPORTS_OPTIONAL_CODECS);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_A2DP_OPTIONAL_CODECS_ENABLED);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_INPUT_DEVICE_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_INPUT_DEVICE_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_MAP_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_MAP_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_MAP_CLIENT_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_MAP_CLIENT_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_PBAP_CLIENT_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_PBAP_CLIENT_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_SAP_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_SAP_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_PAN_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_PAN_PRIORITIES);
-        dumpRepeatedSetting(s, p,
-                Settings.Global.BLUETOOTH_HEARING_AID_PRIORITY_PREFIX,
-                GlobalSettingsProto.BLUETOOTH_HEARING_AID_PRIORITIES);
-        dumpSetting(s, p,
-                Settings.Global.ACTIVITY_MANAGER_CONSTANTS,
-                GlobalSettingsProto.ACTIVITY_MANAGER_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.DEVICE_IDLE_CONSTANTS,
-                GlobalSettingsProto.DEVICE_IDLE_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.BATTERY_SAVER_CONSTANTS,
-                GlobalSettingsProto.BATTERY_SAVER_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.BATTERY_SAVER_DEVICE_SPECIFIC_CONSTANTS,
-                GlobalSettingsProto.BATTERY_SAVER_DEVICE_SPECIFIC_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.BATTERY_TIP_CONSTANTS,
-                GlobalSettingsProto.BATTERY_TIP_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.ANOMALY_DETECTION_CONSTANTS,
-                GlobalSettingsProto.ANOMALY_DETECTION_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.ANOMALY_CONFIG_VERSION,
-                GlobalSettingsProto.ANOMALY_CONFIG_VERSION);
-        dumpSetting(s, p,
-                Settings.Global.ANOMALY_CONFIG,
-                GlobalSettingsProto.ANOMALY_CONFIG);
-        dumpSetting(s, p,
-                Settings.Global.ALWAYS_ON_DISPLAY_CONSTANTS,
-                GlobalSettingsProto.ALWAYS_ON_DISPLAY_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.SYS_VDSO,
-                GlobalSettingsProto.SYS_VDSO);
-        dumpSetting(s, p,
-                Settings.Global.SYS_UIDCPUPOWER,
-                GlobalSettingsProto.SYS_UIDCPUPOWER);
-        dumpSetting(s, p,
-                Settings.Global.FPS_DEVISOR,
-                GlobalSettingsProto.FPS_DIVISOR);
-        dumpSetting(s, p,
-                Settings.Global.DISPLAY_PANEL_LPM,
-                GlobalSettingsProto.DISPLAY_PANEL_LPM);
-        dumpSetting(s, p,
-                Settings.Global.APP_IDLE_CONSTANTS,
-                GlobalSettingsProto.APP_IDLE_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.POWER_MANAGER_CONSTANTS,
-                GlobalSettingsProto.POWER_MANAGER_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.ALARM_MANAGER_CONSTANTS,
-                GlobalSettingsProto.ALARM_MANAGER_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.JOB_SCHEDULER_CONSTANTS,
-                GlobalSettingsProto.JOB_SCHEDULER_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.SHORTCUT_MANAGER_CONSTANTS,
-                GlobalSettingsProto.SHORTCUT_MANAGER_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.DEVICE_POLICY_CONSTANTS,
-                GlobalSettingsProto.DEVICE_POLICY_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.TEXT_CLASSIFIER_CONSTANTS,
-                GlobalSettingsProto.TEXT_CLASSIFIER_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.BATTERY_STATS_CONSTANTS,
-                GlobalSettingsProto.BATTERY_STATS_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.SYNC_MANAGER_CONSTANTS,
-                GlobalSettingsProto.SYNC_MANAGER_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.APP_STANDBY_ENABLED,
-                GlobalSettingsProto.APP_STANDBY_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.APP_AUTO_RESTRICTION_ENABLED,
-                GlobalSettingsProto.APP_AUTO_RESTRICTION_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.FORCED_APP_STANDBY_ENABLED,
-                GlobalSettingsProto.FORCED_APP_STANDBY_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED,
-                GlobalSettingsProto.FORCED_APP_STANDBY_FOR_SMALL_BATTERY_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.OFF_BODY_RADIOS_OFF_FOR_SMALL_BATTERY_ENABLED,
-                GlobalSettingsProto.OFF_BODY_RADIOS_OFF_FOR_SMALL_BATTERY_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.OFF_BODY_RADIOS_OFF_DELAY_MS,
-                GlobalSettingsProto.OFF_BODY_RADIOS_OFF_DELAY_MS);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_ON_WHEN_PROXY_DISCONNECTED,
-                GlobalSettingsProto.WIFI_ON_WHEN_PROXY_DISCONNECTED);
-        dumpSetting(s, p,
-                Settings.Global.TIME_ONLY_MODE_CONSTANTS,
-                GlobalSettingsProto.TIME_ONLY_MODE_CONSTANTS);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_WATCHLIST_ENABLED,
-                GlobalSettingsProto.NETWORK_WATCHLIST_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.KEEP_PROFILE_IN_BACKGROUND,
-                GlobalSettingsProto.KEEP_PROFILE_IN_BACKGROUND);
-        dumpSetting(s, p,
-                Settings.Global.WINDOW_ANIMATION_SCALE,
-                GlobalSettingsProto.WINDOW_ANIMATION_SCALE);
-        dumpSetting(s, p,
-                Settings.Global.TRANSITION_ANIMATION_SCALE,
-                GlobalSettingsProto.TRANSITION_ANIMATION_SCALE);
-        dumpSetting(s, p,
-                Settings.Global.ANIMATOR_DURATION_SCALE,
-                GlobalSettingsProto.ANIMATOR_DURATION_SCALE);
-        dumpSetting(s, p,
-                Settings.Global.FANCY_IME_ANIMATIONS,
-                GlobalSettingsProto.FANCY_IME_ANIMATIONS);
-        dumpSetting(s, p,
-                Settings.Global.COMPATIBILITY_MODE,
-                GlobalSettingsProto.COMPATIBILITY_MODE);
-        dumpSetting(s, p,
-                Settings.Global.EMERGENCY_TONE,
-                GlobalSettingsProto.EMERGENCY_TONE);
-        dumpSetting(s, p,
-                Settings.Global.CALL_AUTO_RETRY,
-                GlobalSettingsProto.CALL_AUTO_RETRY);
-        dumpSetting(s, p,
-                Settings.Global.EMERGENCY_AFFORDANCE_NEEDED,
-                GlobalSettingsProto.EMERGENCY_AFFORDANCE_NEEDED);
-        dumpSetting(s, p,
-                Settings.Global.PREFERRED_NETWORK_MODE,
-                GlobalSettingsProto.PREFERRED_NETWORK_MODE);
-        dumpSetting(s, p,
-                Settings.Global.DEBUG_APP,
-                GlobalSettingsProto.DEBUG_APP);
-        dumpSetting(s, p,
-                Settings.Global.WAIT_FOR_DEBUGGER,
-                GlobalSettingsProto.WAIT_FOR_DEBUGGER);
-        dumpSetting(s, p,
-                Settings.Global.ENABLE_GPU_DEBUG_LAYERS,
-                GlobalSettingsProto.ENABLE_GPU_DEBUG_LAYERS);
-        dumpSetting(s, p,
-                Settings.Global.GPU_DEBUG_APP,
-                GlobalSettingsProto.GPU_DEBUG_APP);
-        dumpSetting(s, p,
-                Settings.Global.GPU_DEBUG_LAYERS,
-                GlobalSettingsProto.GPU_DEBUG_LAYERS);
-        // Settings.Global.SHOW_PROCESSES intentionally excluded since it's deprecated.
-        dumpSetting(s, p,
-                Settings.Global.LOW_POWER_MODE,
-                GlobalSettingsProto.LOW_POWER_MODE);
-        dumpSetting(s, p,
-                Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL,
-                GlobalSettingsProto.LOW_POWER_MODE_TRIGGER_LEVEL);
-        dumpSetting(s, p,
-                Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL_MAX,
-                GlobalSettingsProto.LOW_POWER_MODE_TRIGGER_LEVEL_MAX);
-        dumpSetting(s, p,
-                Settings.Global.ALWAYS_FINISH_ACTIVITIES,
-                GlobalSettingsProto.ALWAYS_FINISH_ACTIVITIES);
-        dumpSetting(s, p,
-                Settings.Global.DOCK_AUDIO_MEDIA_ENABLED,
-                GlobalSettingsProto.DOCK_AUDIO_MEDIA_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.ENCODED_SURROUND_OUTPUT,
-                GlobalSettingsProto.ENCODED_SURROUND_OUTPUT);
-        dumpSetting(s, p,
-                Settings.Global.AUDIO_SAFE_VOLUME_STATE,
-                GlobalSettingsProto.AUDIO_SAFE_VOLUME_STATE);
-        dumpSetting(s, p,
-                Settings.Global.TZINFO_UPDATE_CONTENT_URL,
-                GlobalSettingsProto.TZINFO_UPDATE_CONTENT_URL);
-        dumpSetting(s, p,
-                Settings.Global.TZINFO_UPDATE_METADATA_URL,
-                GlobalSettingsProto.TZINFO_UPDATE_METADATA_URL);
-        dumpSetting(s, p,
-                Settings.Global.SELINUX_UPDATE_CONTENT_URL,
-                GlobalSettingsProto.SELINUX_UPDATE_CONTENT_URL);
-        dumpSetting(s, p,
-                Settings.Global.SELINUX_UPDATE_METADATA_URL,
-                GlobalSettingsProto.SELINUX_UPDATE_METADATA_URL);
-        dumpSetting(s, p,
-                Settings.Global.SMS_SHORT_CODES_UPDATE_CONTENT_URL,
-                GlobalSettingsProto.SMS_SHORT_CODES_UPDATE_CONTENT_URL);
-        dumpSetting(s, p,
-                Settings.Global.SMS_SHORT_CODES_UPDATE_METADATA_URL,
-                GlobalSettingsProto.SMS_SHORT_CODES_UPDATE_METADATA_URL);
-        dumpSetting(s, p,
-                Settings.Global.APN_DB_UPDATE_CONTENT_URL,
-                GlobalSettingsProto.APN_DB_UPDATE_CONTENT_URL);
-        dumpSetting(s, p,
-                Settings.Global.APN_DB_UPDATE_METADATA_URL,
-                GlobalSettingsProto.APN_DB_UPDATE_METADATA_URL);
-        dumpSetting(s, p,
-                Settings.Global.CERT_PIN_UPDATE_CONTENT_URL,
-                GlobalSettingsProto.CERT_PIN_UPDATE_CONTENT_URL);
-        dumpSetting(s, p,
-                Settings.Global.CERT_PIN_UPDATE_METADATA_URL,
-                GlobalSettingsProto.CERT_PIN_UPDATE_METADATA_URL);
-        dumpSetting(s, p,
-                Settings.Global.INTENT_FIREWALL_UPDATE_CONTENT_URL,
-                GlobalSettingsProto.INTENT_FIREWALL_UPDATE_CONTENT_URL);
-        dumpSetting(s, p,
-                Settings.Global.INTENT_FIREWALL_UPDATE_METADATA_URL,
-                GlobalSettingsProto.INTENT_FIREWALL_UPDATE_METADATA_URL);
-        dumpSetting(s, p,
-                Settings.Global.LANG_ID_UPDATE_CONTENT_URL,
-                GlobalSettingsProto.LANG_ID_UPDATE_CONTENT_URL);
-        dumpSetting(s, p,
-                Settings.Global.LANG_ID_UPDATE_METADATA_URL,
-                GlobalSettingsProto.LANG_ID_UPDATE_METADATA_URL);
-        dumpSetting(s, p,
-                Settings.Global.SMART_SELECTION_UPDATE_CONTENT_URL,
-                GlobalSettingsProto.SMART_SELECTION_UPDATE_CONTENT_URL);
-        dumpSetting(s, p,
-                Settings.Global.SMART_SELECTION_UPDATE_METADATA_URL,
-                GlobalSettingsProto.SMART_SELECTION_UPDATE_METADATA_URL);
-        dumpSetting(s, p,
-                Settings.Global.SELINUX_STATUS,
-                GlobalSettingsProto.SELINUX_STATUS);
-        dumpSetting(s, p,
-                Settings.Global.DEVELOPMENT_FORCE_RTL,
-                GlobalSettingsProto.DEVELOPMENT_FORCE_RTL);
-        dumpSetting(s, p,
-                Settings.Global.LOW_BATTERY_SOUND_TIMEOUT,
-                GlobalSettingsProto.LOW_BATTERY_SOUND_TIMEOUT);
-        dumpSetting(s, p,
-                Settings.Global.WIFI_BOUNCE_DELAY_OVERRIDE_MS,
-                GlobalSettingsProto.WIFI_BOUNCE_DELAY_OVERRIDE_MS);
-        dumpSetting(s, p,
-                Settings.Global.POLICY_CONTROL,
-                GlobalSettingsProto.POLICY_CONTROL);
-        dumpSetting(s, p,
-                Settings.Global.EMULATE_DISPLAY_CUTOUT,
-                GlobalSettingsProto.EMULATE_DISPLAY_CUTOUT);
-        dumpSetting(s, p,
-                Settings.Global.ZEN_MODE,
-                GlobalSettingsProto.ZEN_MODE);
-        dumpSetting(s, p,
-                Settings.Global.ZEN_MODE_RINGER_LEVEL,
-                GlobalSettingsProto.ZEN_MODE_RINGER_LEVEL);
-        dumpSetting(s, p,
-                Settings.Global.ZEN_MODE_CONFIG_ETAG,
-                GlobalSettingsProto.ZEN_MODE_CONFIG_ETAG);
-        dumpSetting(s, p,
-                Settings.Global.ZEN_DURATION,
-                GlobalSettingsProto.ZEN_DURATION);
-        dumpSetting(s, p,
-                Settings.Global.HEADS_UP_NOTIFICATIONS_ENABLED,
-                GlobalSettingsProto.HEADS_UP_NOTIFICATIONS_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.DEVICE_NAME,
-                GlobalSettingsProto.DEVICE_NAME);
-        dumpSetting(s, p,
-                Settings.Global.NETWORK_SCORING_PROVISIONED,
-                GlobalSettingsProto.NETWORK_SCORING_PROVISIONED);
-        dumpSetting(s, p,
-                Settings.Global.REQUIRE_PASSWORD_TO_DECRYPT,
-                GlobalSettingsProto.REQUIRE_PASSWORD_TO_DECRYPT);
-        dumpSetting(s, p,
-                Settings.Global.ENHANCED_4G_MODE_ENABLED,
-                GlobalSettingsProto.ENHANCED_4G_MODE_ENABLED);
-        dumpSetting(s, p,
                 Settings.Global.VT_IMS_ENABLED,
                 GlobalSettingsProto.VT_IMS_ENABLED);
         dumpSetting(s, p,
+                Settings.Global.WAIT_FOR_DEBUGGER,
+                GlobalSettingsProto.WAIT_FOR_DEBUGGER);
+
+        final long webviewToken = p.start(GlobalSettingsProto.WEBVIEW);
+        dumpSetting(s, p,
+                Settings.Global.WEBVIEW_DATA_REDUCTION_PROXY_KEY,
+                GlobalSettingsProto.Webview.DATA_REDUCTION_PROXY_KEY);
+        dumpSetting(s, p,
+                Settings.Global.WEBVIEW_FALLBACK_LOGIC_ENABLED,
+                GlobalSettingsProto.Webview.FALLBACK_LOGIC_ENABLED);
+        dumpSetting(s, p,
+                Settings.Global.WEBVIEW_PROVIDER,
+                GlobalSettingsProto.Webview.PROVIDER);
+        dumpSetting(s, p,
+                Settings.Global.WEBVIEW_MULTIPROCESS,
+                GlobalSettingsProto.Webview.MULTIPROCESS);
+        p.end(webviewToken);
+
+        final long wfcToken = p.start(GlobalSettingsProto.WFC);
+        dumpSetting(s, p,
                 Settings.Global.WFC_IMS_ENABLED,
-                GlobalSettingsProto.WFC_IMS_ENABLED);
+                GlobalSettingsProto.Wfc.IMS_ENABLED);
         dumpSetting(s, p,
                 Settings.Global.WFC_IMS_MODE,
-                GlobalSettingsProto.WFC_IMS_MODE);
+                GlobalSettingsProto.Wfc.IMS_MODE);
         dumpSetting(s, p,
                 Settings.Global.WFC_IMS_ROAMING_MODE,
-                GlobalSettingsProto.WFC_IMS_ROAMING_MODE);
+                GlobalSettingsProto.Wfc.IMS_ROAMING_MODE);
         dumpSetting(s, p,
                 Settings.Global.WFC_IMS_ROAMING_ENABLED,
-                GlobalSettingsProto.WFC_IMS_ROAMING_ENABLED);
+                GlobalSettingsProto.Wfc.IMS_ROAMING_ENABLED);
+        p.end(wfcToken);
+
+        final long wifiToken = p.start(GlobalSettingsProto.WIFI);
         dumpSetting(s, p,
-                Settings.Global.LTE_SERVICE_FORCED,
-                GlobalSettingsProto.LTE_SERVICE_FORCED);
+                Settings.Global.WIFI_SLEEP_POLICY,
+                GlobalSettingsProto.Wifi.SLEEP_POLICY);
         dumpSetting(s, p,
-                Settings.Global.EPHEMERAL_COOKIE_MAX_SIZE_BYTES,
-                GlobalSettingsProto.EPHEMERAL_COOKIE_MAX_SIZE_BYTES);
+                Settings.Global.WIFI_BADGING_THRESHOLDS,
+                GlobalSettingsProto.Wifi.BADGING_THRESHOLDS);
         dumpSetting(s, p,
-                Settings.Global.ENABLE_EPHEMERAL_FEATURE,
-                GlobalSettingsProto.ENABLE_EPHEMERAL_FEATURE);
+                Settings.Global.WIFI_DISPLAY_ON,
+                GlobalSettingsProto.Wifi.DISPLAY_ON);
         dumpSetting(s, p,
-                Settings.Global.INSTANT_APP_DEXOPT_ENABLED,
-                GlobalSettingsProto.INSTANT_APP_DEXOPT_ENABLED);
+                Settings.Global.WIFI_DISPLAY_CERTIFICATION_ON,
+                GlobalSettingsProto.Wifi.DISPLAY_CERTIFICATION_ON);
         dumpSetting(s, p,
-                Settings.Global.INSTALLED_INSTANT_APP_MIN_CACHE_PERIOD,
-                GlobalSettingsProto.INSTALLED_INSTANT_APP_MIN_CACHE_PERIOD);
+                Settings.Global.WIFI_DISPLAY_WPS_CONFIG,
+                GlobalSettingsProto.Wifi.DISPLAY_WPS_CONFIG);
         dumpSetting(s, p,
-                Settings.Global.INSTALLED_INSTANT_APP_MAX_CACHE_PERIOD,
-                GlobalSettingsProto.INSTALLED_INSTANT_APP_MAX_CACHE_PERIOD);
+                Settings.Global.WIFI_NETWORKS_AVAILABLE_NOTIFICATION_ON,
+                GlobalSettingsProto.Wifi.NETWORKS_AVAILABLE_NOTIFICATION_ON);
         dumpSetting(s, p,
-                Settings.Global.UNINSTALLED_INSTANT_APP_MIN_CACHE_PERIOD,
-                GlobalSettingsProto.UNINSTALLED_INSTANT_APP_MIN_CACHE_PERIOD);
+                Settings.Global.WIFI_CARRIER_NETWORKS_AVAILABLE_NOTIFICATION_ON,
+                GlobalSettingsProto.Wifi.CARRIER_NETWORKS_AVAILABLE_NOTIFICATION_ON);
         dumpSetting(s, p,
-                Settings.Global.UNINSTALLED_INSTANT_APP_MAX_CACHE_PERIOD,
-                GlobalSettingsProto.UNINSTALLED_INSTANT_APP_MAX_CACHE_PERIOD);
+                Settings.Global.WIFI_NETWORKS_AVAILABLE_REPEAT_DELAY,
+                GlobalSettingsProto.Wifi.NETWORKS_AVAILABLE_REPEAT_DELAY);
         dumpSetting(s, p,
-                Settings.Global.UNUSED_STATIC_SHARED_LIB_MIN_CACHE_PERIOD,
-                GlobalSettingsProto.UNUSED_STATIC_SHARED_LIB_MIN_CACHE_PERIOD);
+                Settings.Global.WIFI_COUNTRY_CODE,
+                GlobalSettingsProto.Wifi.COUNTRY_CODE);
         dumpSetting(s, p,
-                Settings.Global.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED,
-                GlobalSettingsProto.ALLOW_USER_SWITCHING_WHEN_SYSTEM_USER_LOCKED);
+                Settings.Global.WIFI_FRAMEWORK_SCAN_INTERVAL_MS,
+                GlobalSettingsProto.Wifi.FRAMEWORK_SCAN_INTERVAL_MS);
         dumpSetting(s, p,
-                Settings.Global.BOOT_COUNT,
-                GlobalSettingsProto.BOOT_COUNT);
+                Settings.Global.WIFI_IDLE_MS,
+                GlobalSettingsProto.Wifi.IDLE_MS);
         dumpSetting(s, p,
-                Settings.Global.SAFE_BOOT_DISALLOWED,
-                GlobalSettingsProto.SAFE_BOOT_DISALLOWED);
+                Settings.Global.WIFI_NUM_OPEN_NETWORKS_KEPT,
+                GlobalSettingsProto.Wifi.NUM_OPEN_NETWORKS_KEPT);
         dumpSetting(s, p,
-                Settings.Global.DEVICE_DEMO_MODE,
-                GlobalSettingsProto.DEVICE_DEMO_MODE);
+                Settings.Global.WIFI_ON,
+                GlobalSettingsProto.Wifi.ON);
         dumpSetting(s, p,
-                Settings.Global.NETWORK_ACCESS_TIMEOUT_MS,
-                GlobalSettingsProto.NETWORK_ACCESS_TIMEOUT_MS);
+                Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE,
+                GlobalSettingsProto.Wifi.SCAN_ALWAYS_AVAILABLE);
         dumpSetting(s, p,
-                Settings.Global.DATABASE_DOWNGRADE_REASON,
-                GlobalSettingsProto.DATABASE_DOWNGRADE_REASON);
+                Settings.Global.WIFI_WAKEUP_ENABLED,
+                GlobalSettingsProto.Wifi.WAKEUP_ENABLED);
         dumpSetting(s, p,
-                Settings.Global.DATABASE_CREATION_BUILDID,
-                GlobalSettingsProto.DATABASE_CREATION_BUILDID);
+                Settings.Global.WIFI_SAVED_STATE,
+                GlobalSettingsProto.Wifi.SAVED_STATE);
         dumpSetting(s, p,
-                Settings.Global.CONTACTS_DATABASE_WAL_ENABLED,
-                GlobalSettingsProto.CONTACTS_DATABASE_WAL_ENABLED);
+                Settings.Global.WIFI_SUPPLICANT_SCAN_INTERVAL_MS,
+                GlobalSettingsProto.Wifi.SUPPLICANT_SCAN_INTERVAL_MS);
         dumpSetting(s, p,
-                Settings.Global.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED,
-                GlobalSettingsProto.LOCATION_SETTINGS_LINK_TO_PERMISSIONS_ENABLED);
+                Settings.Global.WIFI_ENHANCED_AUTO_JOIN,
+                GlobalSettingsProto.Wifi.ENHANCED_AUTO_JOIN);
         dumpSetting(s, p,
-                Settings.Global.EUICC_FACTORY_RESET_TIMEOUT_MILLIS,
-                GlobalSettingsProto.EUICC_FACTORY_RESET_TIMEOUT_MILLIS);
+                Settings.Global.WIFI_NETWORK_SHOW_RSSI,
+                GlobalSettingsProto.Wifi.NETWORK_SHOW_RSSI);
         dumpSetting(s, p,
-                Settings.Global.STORAGE_SETTINGS_CLOBBER_THRESHOLD,
-                GlobalSettingsProto.STORAGE_SETTINGS_CLOBBER_THRESHOLD);
+                Settings.Global.WIFI_SCAN_INTERVAL_WHEN_P2P_CONNECTED_MS,
+                GlobalSettingsProto.Wifi.SCAN_INTERVAL_WHEN_P2P_CONNECTED_MS);
         dumpSetting(s, p,
-                Settings.Global.LOCATION_GLOBAL_KILL_SWITCH,
-                GlobalSettingsProto.LOCATION_GLOBAL_KILL_SWITCH);
+                Settings.Global.WIFI_WATCHDOG_ON,
+                GlobalSettingsProto.Wifi.WATCHDOG_ON);
         dumpSetting(s, p,
-                Settings.Global.OVERRIDE_SETTINGS_PROVIDER_RESTORE_ANY_VERSION,
-                GlobalSettingsProto.OVERRIDE_SETTINGS_PROVIDER_RESTORE_ANY_VERSION);
+                Settings.Global.WIFI_WATCHDOG_POOR_NETWORK_TEST_ENABLED,
+                GlobalSettingsProto.Wifi.WATCHDOG_POOR_NETWORK_TEST_ENABLED);
         dumpSetting(s, p,
-                Global.CHAINED_BATTERY_ATTRIBUTION_ENABLED,
-                GlobalSettingsProto.CHAINED_BATTERY_ATTRIBUTION_ENABLED);
+                Settings.Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED,
+                GlobalSettingsProto.Wifi.SUSPEND_OPTIMIZATIONS_ENABLED);
         dumpSetting(s, p,
-                Settings.Global.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES,
-                GlobalSettingsProto.AUTOFILL_COMPAT_MODE_ALLOWED_PACKAGES);
+                Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED,
+                GlobalSettingsProto.Wifi.VERBOSE_LOGGING_ENABLED);
         dumpSetting(s, p,
-                Global.HIDDEN_API_BLACKLIST_EXEMPTIONS,
-                GlobalSettingsProto.HIDDEN_API_BLACKLIST_EXEMPTIONS);
+                Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED,
+                GlobalSettingsProto.Wifi.CONNECTED_MAC_RANDOMIZATION_ENABLED);
         dumpSetting(s, p,
-                Global.SOUND_TRIGGER_DETECTION_SERVICE_OP_TIMEOUT,
-                GlobalSettingsProto.SOUND_TRIGGER_DETECTION_SERVICE_OP_TIMEOUT);
+                Settings.Global.WIFI_MAX_DHCP_RETRY_COUNT,
+                GlobalSettingsProto.Wifi.MAX_DHCP_RETRY_COUNT);
         dumpSetting(s, p,
-                Global.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY,
-                GlobalSettingsProto.MAX_SOUND_TRIGGER_DETECTION_SERVICE_OPS_PER_DAY);
+                Settings.Global.WIFI_MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS,
+                GlobalSettingsProto.Wifi.MOBILE_DATA_TRANSITION_WAKELOCK_TIMEOUT_MS);
         dumpSetting(s, p,
-                Settings.Global.MULTI_SIM_VOICE_CALL_SUBSCRIPTION,
-                GlobalSettingsProto.MULTI_SIM_VOICE_CALL_SUBSCRIPTION);
+                Settings.Global.WIFI_DEVICE_OWNER_CONFIGS_LOCKDOWN,
+                GlobalSettingsProto.Wifi.DEVICE_OWNER_CONFIGS_LOCKDOWN);
         dumpSetting(s, p,
-                Settings.Global.MULTI_SIM_VOICE_PROMPT,
-                GlobalSettingsProto.MULTI_SIM_VOICE_PROMPT);
+                Settings.Global.WIFI_FREQUENCY_BAND,
+                GlobalSettingsProto.Wifi.FREQUENCY_BAND);
         dumpSetting(s, p,
-                Settings.Global.MULTI_SIM_DATA_CALL_SUBSCRIPTION,
-                GlobalSettingsProto.MULTI_SIM_DATA_CALL_SUBSCRIPTION);
+                Settings.Global.WIFI_P2P_DEVICE_NAME,
+                GlobalSettingsProto.Wifi.P2P_DEVICE_NAME);
         dumpSetting(s, p,
-                Settings.Global.MULTI_SIM_SMS_SUBSCRIPTION,
-                GlobalSettingsProto.MULTI_SIM_SMS_SUBSCRIPTION);
+                Settings.Global.WIFI_REENABLE_DELAY_MS,
+                GlobalSettingsProto.Wifi.REENABLE_DELAY_MS);
         dumpSetting(s, p,
-                Settings.Global.MULTI_SIM_SMS_PROMPT,
-                GlobalSettingsProto.MULTI_SIM_SMS_PROMPT);
+                Settings.Global.WIFI_EPHEMERAL_OUT_OF_RANGE_TIMEOUT_MS,
+                GlobalSettingsProto.Wifi.EPHEMERAL_OUT_OF_RANGE_TIMEOUT_MS);
         dumpSetting(s, p,
-                Settings.Global.NEW_CONTACT_AGGREGATOR,
-                GlobalSettingsProto.NEW_CONTACT_AGGREGATOR);
-        // Settings.Global.CONTACT_METADATA_SYNC intentionally excluded since it's deprecated.
+                Settings.Global.WIFI_ON_WHEN_PROXY_DISCONNECTED,
+                GlobalSettingsProto.Wifi.ON_WHEN_PROXY_DISCONNECTED);
         dumpSetting(s, p,
-                Settings.Global.CONTACT_METADATA_SYNC_ENABLED,
-                GlobalSettingsProto.CONTACT_METADATA_SYNC_ENABLED);
+                Settings.Global.WIFI_BOUNCE_DELAY_OVERRIDE_MS,
+                GlobalSettingsProto.Wifi.BOUNCE_DELAY_OVERRIDE_MS);
+        p.end(wifiToken);
+
         dumpSetting(s, p,
-                Settings.Global.ENABLE_CELLULAR_ON_BOOT,
-                GlobalSettingsProto.ENABLE_CELLULAR_ON_BOOT);
+                Settings.Global.WIMAX_NETWORKS_AVAILABLE_NOTIFICATION_ON,
+                GlobalSettingsProto.WIMAX_NETWORKS_AVAILABLE_NOTIFICATION_ON);
         dumpSetting(s, p,
-                Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE,
-                GlobalSettingsProto.MAX_NOTIFICATION_ENQUEUE_RATE);
+                Settings.Global.WINDOW_ANIMATION_SCALE,
+                GlobalSettingsProto.WINDOW_ANIMATION_SCALE);
         dumpSetting(s, p,
-                Settings.Global.SHOW_NOTIFICATION_CHANNEL_WARNINGS,
-                GlobalSettingsProto.SHOW_NOTIFICATION_CHANNEL_WARNINGS);
+                Settings.Global.WTF_IS_FATAL,
+                GlobalSettingsProto.WTF_IS_FATAL);
+
+        final long zenToken = p.start(GlobalSettingsProto.ZEN);
         dumpSetting(s, p,
-                Settings.Global.CELL_ON,
-                GlobalSettingsProto.CELL_ON);
+                Settings.Global.ZEN_MODE,
+                GlobalSettingsProto.Zen.MODE);
         dumpSetting(s, p,
-                Settings.Global.SHOW_TEMPERATURE_WARNING,
-                GlobalSettingsProto.SHOW_TEMPERATURE_WARNING);
+                Settings.Global.ZEN_MODE_RINGER_LEVEL,
+                GlobalSettingsProto.Zen.MODE_RINGER_LEVEL);
         dumpSetting(s, p,
-                Settings.Global.WARNING_TEMPERATURE,
-                GlobalSettingsProto.WARNING_TEMPERATURE);
+                Settings.Global.ZEN_MODE_CONFIG_ETAG,
+                GlobalSettingsProto.Zen.MODE_CONFIG_ETAG);
         dumpSetting(s, p,
-                Settings.Global.ENABLE_DISKSTATS_LOGGING,
-                GlobalSettingsProto.ENABLE_DISKSTATS_LOGGING);
+                Settings.Global.ZEN_DURATION,
+                GlobalSettingsProto.Zen.DURATION);
         dumpSetting(s, p,
-                Settings.Global.ENABLE_CACHE_QUOTA_CALCULATION,
-                GlobalSettingsProto.ENABLE_CACHE_QUOTA_CALCULATION);
-        dumpSetting(s, p,
-                Settings.Global.ENABLE_DELETION_HELPER_NO_THRESHOLD_TOGGLE,
-                GlobalSettingsProto.ENABLE_DELETION_HELPER_NO_THRESHOLD_TOGGLE);
-        // The list of snooze options for notifications. This is encoded as a key=value list,
-        // separated by commas.
-        dumpSetting(s, p,
-                Settings.Global.NOTIFICATION_SNOOZE_OPTIONS,
-                GlobalSettingsProto.NOTIFICATION_SNOOZE_OPTIONS);
-        dumpSetting(s, p,
-                Settings.Global.SQLITE_COMPATIBILITY_WAL_FLAGS,
-                GlobalSettingsProto.SQLITE_COMPATIBILITY_WAL_FLAGS);
-        dumpSetting(s, p,
-                Settings.Global.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING,
-                GlobalSettingsProto.ENABLE_GNSS_RAW_MEAS_FULL_TRACKING);
-        dumpSetting(s, p,
-                Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT,
-                GlobalSettingsProto.INSTALL_CARRIER_APP_NOTIFICATION_PERSISTENT);
-        dumpSetting(s, p,
-                Settings.Global.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS,
-                GlobalSettingsProto.INSTALL_CARRIER_APP_NOTIFICATION_SLEEP_MILLIS);
+                Settings.Global.SHOW_ZEN_UPGRADE_NOTIFICATION,
+                GlobalSettingsProto.Zen.SHOW_ZEN_UPGRADE_NOTIFICATION);
+        p.end(zenToken);
+
         dumpSetting(s, p,
                 Settings.Global.ZRAM_ENABLED,
                 GlobalSettingsProto.ZRAM_ENABLED);
-        dumpSetting(s, p,
-                Settings.Global.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS,
-                GlobalSettingsProto.SMART_REPLIES_IN_NOTIFICATIONS_FLAGS);
-        dumpSetting(s, p,
-                Settings.Global.SHOW_FIRST_CRASH_DIALOG,
-                GlobalSettingsProto.SHOW_FIRST_CRASH_DIALOG);
-        dumpSetting(s, p,
-                Settings.Global.SHOW_RESTART_IN_CRASH_DIALOG,
-                GlobalSettingsProto.SHOW_RESTART_IN_CRASH_DIALOG);
-        dumpSetting(s, p,
-                Settings.Global.SHOW_MUTE_IN_CRASH_DIALOG,
-                GlobalSettingsProto.SHOW_MUTE_IN_CRASH_DIALOG);
-        dumpSetting(s, p,
-                Settings.Global.SHOW_ZEN_UPGRADE_NOTIFICATION,
-                GlobalSettingsProto.SHOW_ZEN_UPGRADE_NOTIFICATION);
-        dumpSetting(s, p,
-                Settings.Global.BACKUP_AGENT_TIMEOUT_PARAMETERS,
-                GlobalSettingsProto.BACKUP_AGENT_TIMEOUT_PARAMETERS);
-        // Please insert new settings using the same order as in Settings.Global.
 
         p.end(token);
+        // Please insert new settings using the same order as in GlobalSettingsProto.
+
+        // Settings.Global.INSTALL_NON_MARKET_APPS intentionally excluded since it's deprecated.
     }
 
     /** Dumps settings that use a common prefix into a repeated field. */
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index 3a2ec06..a6d6250 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -2754,12 +2754,17 @@
             mGenerationRegistry.incrementGeneration(key);
 
             if (isGlobalSettingsKey(key)) {
-                if (Global.LOCATION_GLOBAL_KILL_SWITCH.equals(name)) {
-                    // When the global kill switch is updated, send the
-                    // change notification for the location setting.
-                    notifyLocationChangeForRunningUsers();
+                final long token = Binder.clearCallingIdentity();
+                try {
+                    if (Global.LOCATION_GLOBAL_KILL_SWITCH.equals(name)) {
+                        // When the global kill switch is updated, send the
+                        // change notification for the location setting.
+                        notifyLocationChangeForRunningUsers();
+                    }
+                    notifyGlobalSettingChangeForRunningUsers(key, name);
+                } finally {
+                    Binder.restoreCallingIdentity(token);
                 }
-                notifyGlobalSettingChangeForRunningUsers(key, name);
             } else {
                 final int userId = getUserIdFromKey(key);
                 final Uri uri = getNotificationUriFor(key, name);
diff --git a/packages/SystemUI/res/layout/wireless_charging_layout.xml b/packages/SystemUI/res/layout/wireless_charging_layout.xml
index 85a325a..e848901 100644
--- a/packages/SystemUI/res/layout/wireless_charging_layout.xml
+++ b/packages/SystemUI/res/layout/wireless_charging_layout.xml
@@ -42,7 +42,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_gravity="center"
-            android:textSize="32sp"
+            android:textSize="24sp"
             android:textColor="?attr/wallpaperTextColor"/>
     </LinearLayout>
 
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 4513f14..ff3f696 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -929,14 +929,14 @@
     <dimen name="wireless_charging_dots_radius_start">0dp</dimen>
     <dimen name="wireless_charging_dots_radius_end">4dp</dimen>
     <dimen name="wireless_charging_circle_radius_start">28dp</dimen>
-    <dimen name="wireless_charging_circle_radius_end">92dp</dimen>
+    <dimen name="wireless_charging_circle_radius_end">84dp</dimen>
     <integer name="wireless_charging_angle_offset">20</integer>
     <integer name="wireless_charging_scale_dots_duration">83</integer>
-    <integer name="wireless_charging_num_dots">20</integer>
-    <!-- Starting text size in dp of batteryLevel for wireless charging animation -->
-    <dimen name="wireless_charging_anim_battery_level_text_size_start">0dp</dimen>
-    <!-- Ending text size in dp of batteryLevel for wireless charging animation -->
-    <dimen name="wireless_charging_anim_battery_level_text_size_end">14dp</dimen>
+    <integer name="wireless_charging_num_dots">16</integer>
+    <!-- Starting text size in sp of batteryLevel for wireless charging animation -->
+    <item name="wireless_charging_anim_battery_level_text_size_start" format="float" type="dimen">0</item>
+    <!-- Ending text size in sp of batteryLevel for wireless charging animation -->
+    <item name="wireless_charging_anim_battery_level_text_size_end" format="float" type="dimen">24</item>
     <!-- time until battery info is at full opacity-->
     <integer name="wireless_charging_anim_opacity_offset">80</integer>
     <!-- duration batteryLevel opacity goes from 0 to 1 duration -->
diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index 131b35c..d3a55e8 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1602,7 +1602,7 @@
     <!-- Notification: Menu row: Content description for the snooze icon. [CHAR LIMIT=NONE] -->
     <string name="notification_menu_snooze_description">notification snooze options</string>
 
-    <!-- Notification: Menu row: Content description for the snooze action shown in local context menu. [CHAR LIMIT=NONE] -->
+    <!-- Notification: Menu row: Label for the snooze action shown in local context menu. [CHAR LIMIT=NONE] -->
     <string name="notification_menu_snooze_action">Snooze</string>
 
     <!-- Notification: Snooze panel: Snooze undo button label. [CHAR LIMIT=50]-->
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardHostView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardHostView.java
index 62b5004..5b4d652 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardHostView.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardHostView.java
@@ -137,6 +137,10 @@
         mCancelAction = cancelAction;
     }
 
+    public boolean hasDismissActions() {
+        return mDismissAction != null || mCancelAction != null;
+    }
+
     public void cancelDismissAction() {
         setOnDismissAction(null, null);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingAnimation.java b/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingAnimation.java
index afc9629..e11fe4e 100644
--- a/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingAnimation.java
+++ b/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingAnimation.java
@@ -55,9 +55,9 @@
      * @hide
      */
     public WirelessChargingAnimation(@NonNull Context context, @Nullable Looper looper, int
-            batteryLevel, Callback callback) {
+            batteryLevel, Callback callback, boolean isDozing) {
         mCurrentWirelessChargingView = new WirelessChargingView(context, looper,
-                batteryLevel, callback);
+                batteryLevel, callback, isDozing);
     }
 
     /**
@@ -65,8 +65,8 @@
      * @hide
      */
     public static WirelessChargingAnimation makeWirelessChargingAnimation(@NonNull Context context,
-            @Nullable Looper looper, int batteryLevel, Callback callback) {
-        return new WirelessChargingAnimation(context, looper, batteryLevel, callback);
+            @Nullable Looper looper, int batteryLevel, Callback callback, boolean isDozing) {
+        return new WirelessChargingAnimation(context, looper, batteryLevel, callback, isDozing);
     }
 
     /**
@@ -102,14 +102,14 @@
         private Callback mCallback;
 
         public WirelessChargingView(Context context, @Nullable Looper looper, int batteryLevel,
-                Callback callback) {
+                Callback callback, boolean isDozing) {
             mCallback = callback;
-            mNextView = new WirelessChargingLayout(context, batteryLevel);
+            mNextView = new WirelessChargingLayout(context, batteryLevel, isDozing);
             mGravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER;
 
             final WindowManager.LayoutParams params = mParams;
             params.height = WindowManager.LayoutParams.WRAP_CONTENT;
-            params.width = WindowManager.LayoutParams.WRAP_CONTENT;
+            params.width = WindowManager.LayoutParams.MATCH_PARENT;
             params.format = PixelFormat.TRANSLUCENT;
 
             params.type = WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY;
diff --git a/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingLayout.java b/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingLayout.java
index 9887533..c8e83de 100644
--- a/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingLayout.java
@@ -20,6 +20,7 @@
 import android.animation.ObjectAnimator;
 import android.animation.ValueAnimator;
 import android.content.Context;
+import android.graphics.Color;
 import android.util.AttributeSet;
 import android.view.animation.PathInterpolator;
 import android.widget.FrameLayout;
@@ -38,24 +39,24 @@
 
     public WirelessChargingLayout(Context context) {
         super(context);
-        init(context, null);
+        init(context, null, false);
     }
 
-    public WirelessChargingLayout(Context context, int batterylLevel) {
+    public WirelessChargingLayout(Context context, int batteryLevel, boolean isDozing) {
         super(context);
-        init(context, null, batterylLevel);
+        init(context, null, batteryLevel, isDozing);
     }
 
     public WirelessChargingLayout(Context context, AttributeSet attrs) {
         super(context, attrs);
-        init(context, attrs);
+        init(context, attrs, false);
     }
 
-    private void init(Context c, AttributeSet attrs) {
-        init(c, attrs, -1);
+    private void init(Context c, AttributeSet attrs, boolean isDozing) {
+        init(c, attrs, -1, false);
     }
 
-    private void init(Context context, AttributeSet attrs, int batteryLevel) {
+    private void init(Context context, AttributeSet attrs, int batteryLevel, boolean isDozing) {
         final int mBatteryLevel = batteryLevel;
         inflate(context, R.layout.wireless_charging_layout, this);
 
@@ -65,6 +66,11 @@
         // amount of battery:
         final TextView mPercentage = findViewById(R.id.wireless_charging_percentage);
 
+        if (isDozing) {
+            mChargingView.setPaintColor(Color.WHITE);
+            mPercentage.setTextColor(Color.WHITE);
+        }
+
         if (batteryLevel != UNKNOWN_BATTERY_LEVEL) {
             mPercentage.setText(NumberFormat.getPercentInstance().format(mBatteryLevel / 100f));
             mPercentage.setAlpha(0);
@@ -74,9 +80,9 @@
                 R.integer.wireless_charging_fade_offset);
         final long chargingAnimationFadeDuration = (long) context.getResources().getInteger(
                 R.integer.wireless_charging_fade_duration);
-        final int batteryLevelTextSizeStart = context.getResources().getDimensionPixelSize(
+        final float batteryLevelTextSizeStart = context.getResources().getFloat(
                 R.dimen.wireless_charging_anim_battery_level_text_size_start);
-        final int batteryLevelTextSizeEnd = context.getResources().getDimensionPixelSize(
+        final float batteryLevelTextSizeEnd = context.getResources().getFloat(
                 R.dimen.wireless_charging_anim_battery_level_text_size_end);
 
         // Animation Scale: battery percentage text scales from 0% to 100%
diff --git a/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingView.java b/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingView.java
index 19c6dc1..9c411d6 100644
--- a/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingView.java
+++ b/packages/SystemUI/src/com/android/systemui/charging/WirelessChargingView.java
@@ -98,6 +98,10 @@
         mPaint.setColor(Utils.getColorAttr(mContext, R.attr.wallpaperTextColor));
     }
 
+    public void setPaintColor(int color) {
+        mPaint.setColor(color);
+    }
+
     @Override
     protected void onDraw(final Canvas canvas) {
         super.onDraw(canvas);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
index 6b9567d..24ebc83 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableNotificationRow.java
@@ -1558,6 +1558,11 @@
                 }
             }
             invalidateOutline();
+
+            // In order to keep the shelf in sync with this swiping, we're simply translating
+            // it's icon by the same amount. The translation is already being used for the normal
+            // positioning, so we can use the scrollX instead.
+            getEntry().expandedIcon.setScrollX((int) -translationX);
         }
         if (mMenuRow.getMenuView() != null) {
             mMenuRow.onTranslationUpdate(translationX);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
index 41c7559..a4aa598 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
@@ -85,6 +85,7 @@
     private boolean mAnimationsEnabled = true;
     private boolean mShowNotificationShelf;
     private float mFirstElementRoundness;
+    private Rect mClipRect = new Rect();
 
     public NotificationShelf(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -672,6 +673,11 @@
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
         super.onLayout(changed, left, top, right, bottom);
         updateRelativeOffset();
+
+        // we always want to clip to our sides, such that nothing can draw outside of these bounds
+        int height = getResources().getDisplayMetrics().heightPixels;
+        mClipRect.set(0, -height, getWidth(), height);
+        mShelfIcons.setClipBounds(mClipRect);
     }
 
     private void updateRelativeOffset() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java
index d609ae7..fcd4e8f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBouncer.java
@@ -330,6 +330,10 @@
         }
     }
 
+    public boolean willDismissWithAction() {
+        return mKeyguardView != null && mKeyguardView.hasDismissActions();
+    }
+
     protected void ensureView() {
         // Removal of the view might be deferred to reduce unlock latency,
         // in this case we need to force the removal, otherwise we'll
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
index 8fb0620..88bc6ea 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarView.java
@@ -842,10 +842,17 @@
             buttonBounds.setEmpty();
             return;
         }
+        // Temporarily reset the translation back to origin to get the position in window
+        final float posX = view.getTranslationX();
+        final float posY = view.getTranslationY();
+        view.setTranslationX(0);
+        view.setTranslationY(0);
         view.getLocationInWindow(mTmpPosition);
         buttonBounds.set(mTmpPosition[0], mTmpPosition[1],
                 mTmpPosition[0] + view.getMeasuredWidth(),
                 mTmpPosition[1] + view.getMeasuredHeight());
+        view.setTranslationX(posX);
+        view.setTranslationY(posY);
     }
 
     private void updateRotatedViews() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java
index 6047f8e..a51cd93 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/QuickStepController.java
@@ -303,16 +303,18 @@
 
     @Override
     public void onLayout(boolean changed, int left, int top, int right, int bottom) {
-        final int width = right - left;
-        final int height = bottom - top;
+        final int width = (right - left) - mNavigationBarView.getPaddingEnd()
+                - mNavigationBarView.getPaddingStart();
+        final int height = (bottom - top) - mNavigationBarView.getPaddingBottom()
+                - mNavigationBarView.getPaddingTop();
         final int x1, x2, y1, y2;
         if (mIsVertical) {
-            x1 = (width - mTrackThickness) / 2;
+            x1 = (width - mTrackThickness) / 2 + mNavigationBarView.getPaddingStart();
             x2 = x1 + mTrackThickness;
             y1 = mDragPositive ? height / 2 : mTrackPadding;
             y2 = y1 + height / 2 - mTrackPadding;
         } else {
-            y1 = (height - mTrackThickness) / 2;
+            y1 = (height - mTrackThickness) / 2 + mNavigationBarView.getPaddingTop();
             y2 = y1 + mTrackThickness;
             x1 = mDragPositive ? width / 2 : mTrackPadding;
             x2 = x1 + width / 2 - mTrackPadding;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
index cfc0cc6..7a6e98d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ScrimController.java
@@ -148,7 +148,7 @@
     private float mNotificationDensity;
 
     // Scrim blanking callbacks
-    private Choreographer.FrameCallback mPendingFrameCallback;
+    private Runnable mPendingFrameCallback;
     private Runnable mBlankingTransitionRunnable;
 
     private final WakeLock mWakeLock;
@@ -240,7 +240,7 @@
 
         // Cancel blanking transitions that were pending before we requested a new state
         if (mPendingFrameCallback != null) {
-            Choreographer.getInstance().removeFrameCallback(mPendingFrameCallback);
+            mScrimBehind.removeCallbacks(mPendingFrameCallback);
             mPendingFrameCallback = null;
         }
         if (getHandler().hasCallbacks(mBlankingTransitionRunnable)) {
@@ -278,7 +278,7 @@
             // with too many things at this case, in order to not skip the initial frames.
             mScrimInFront.postOnAnimationDelayed(this::scheduleUpdate, 16);
             mAnimationDelay = StatusBar.FADE_KEYGUARD_START_DELAY;
-        } else if (!mDozeParameters.getAlwaysOn() && oldState == ScrimState.AOD
+        } else if ((!mDozeParameters.getAlwaysOn() && oldState == ScrimState.AOD)
                 || (mState == ScrimState.AOD && !mDozeParameters.getDisplayNeedsBlanking())) {
             // Scheduling a frame isn't enough when:
             //  • Leaving doze and we need to modify scrim color immediately
@@ -727,7 +727,7 @@
 
         // Notify callback that the screen is completely black and we're
         // ready to change the display power mode
-        mPendingFrameCallback = frameTimeNanos -> {
+        mPendingFrameCallback = () -> {
             if (mCallback != null) {
                 mCallback.onDisplayBlanked();
                 mScreenBlankingCallbackCalled = true;
@@ -743,7 +743,7 @@
 
             // Setting power states can happen after we push out the frame. Make sure we
             // stay fully opaque until the power state request reaches the lower levels.
-            final int delay = mScreenOn ? 16 : 500;
+            final int delay = mScreenOn ? 32 : 500;
             if (DEBUG) {
                 Log.d(TAG, "Fading out scrims with delay: " + delay);
             }
@@ -752,9 +752,15 @@
         doOnTheNextFrame(mPendingFrameCallback);
     }
 
+    /**
+     * Executes a callback after the frame has hit the display.
+     * @param callback What to run.
+     */
     @VisibleForTesting
-    protected void doOnTheNextFrame(Choreographer.FrameCallback callback) {
-        Choreographer.getInstance().postFrameCallback(callback);
+    protected void doOnTheNextFrame(Runnable callback) {
+        // Just calling View#postOnAnimation isn't enough because the frame might not have reached
+        // the display yet. A timeout is the safest solution.
+        mScrimBehind.postOnAnimationDelayed(callback, 32 /* delayMillis */);
     }
 
     @VisibleForTesting
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index e6a9b46..8246974 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -2502,11 +2502,11 @@
                         public void onAnimationEnded() {
                             CrossFadeHelper.fadeIn(mNotificationPanel);
                         }
-                    }).show();
+                    }, mDozing).show();
         } else {
             // workspace
             WirelessChargingAnimation.makeWirelessChargingAnimation(mContext, null,
-                    batteryLevel, null).show();
+                    batteryLevel, null, false).show();
         }
     }
 
@@ -4654,9 +4654,12 @@
 
         if (mBouncerShowing) {
             // Bouncer needs the front scrim when it's on top of an activity,
-            // tapping on a notification or editing QS.
-            mScrimController.transitionTo(mIsOccluded || mNotificationPanel.needsScrimming() ?
-                    ScrimState.BOUNCER_SCRIMMED : ScrimState.BOUNCER);
+            // tapping on a notification, editing QS or being dismissed by
+            // FLAG_DISMISS_KEYGUARD_ACTIVITY.
+            ScrimState state = mIsOccluded || mNotificationPanel.needsScrimming()
+                    || mStatusBarKeyguardViewManager.willDismissWithAction() ?
+                    ScrimState.BOUNCER_SCRIMMED : ScrimState.BOUNCER;
+            mScrimController.transitionTo(state);
         } else if (mLaunchCameraOnScreenTurningOn || isInLaunchTransition()) {
             mScrimController.transitionTo(ScrimState.UNLOCKED, mUnlockScrimCallback);
         } else if (mBrightnessMirrorVisible) {
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 56a7b1b..1a64b00 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarKeyguardViewManager.java
@@ -140,11 +140,14 @@
     }
 
     private void onPanelExpansionChanged(float expansion, boolean tracking) {
-        // We don't want to translate the bounce when the keyguard is occluded, because we're in
-        // a FLAG_SHOW_WHEN_LOCKED activity and need to conserve the original animation.
-        // We also don't want to show the bouncer when the user quickly taps on the display.
+        // We don't want to translate the bounce when:
+        // • Keyguard is occluded, because we're in a FLAG_SHOW_WHEN_LOCKED activity and need to
+        //   conserve the original animation.
+        // • The user quickly taps on the display and we show "swipe up to unlock."
+        // • Keyguard will be dismissed by an action. a.k.a: FLAG_DISMISS_KEYGUARD_ACTIVITY
         final boolean noLongerTracking = mLastTracking != tracking && !tracking;
-        if (mOccluded || mNotificationPanelView.isUnlockHintRunning()) {
+        if (mOccluded || mNotificationPanelView.isUnlockHintRunning()
+                || mBouncer.willDismissWithAction()) {
             mBouncer.setExpansion(0);
         } else if (mShowing && mStatusBar.isKeyguardCurrentlySecure() && !mDozing) {
             mBouncer.setExpansion(expansion);
@@ -696,6 +699,10 @@
         }
     }
 
+    public boolean willDismissWithAction() {
+        return mBouncer.willDismissWithAction();
+    }
+
     private static class DismissWithActionRequest {
         final OnDismissAction dismissAction;
         final Runnable cancelAction;
diff --git a/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewTest.java b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewTest.java
new file mode 100644
index 0000000..3f85c9d
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/keyguard/KeyguardHostViewTest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2018 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.keyguard;
+
+import static org.mockito.Mockito.mock;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import android.testing.AndroidTestingRunner;
+import android.testing.TestableLooper;
+
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+@TestableLooper.RunWithLooper
+public class KeyguardHostViewTest extends SysuiTestCase {
+
+    private KeyguardHostView mKeyguardHostView;
+
+    @Before
+    public void setup() {
+        mKeyguardHostView = new KeyguardHostView(getContext());
+    }
+
+    @Test
+    public void testHasDismissActions() {
+        Assert.assertFalse("Action not set yet", mKeyguardHostView.hasDismissActions());
+        mKeyguardHostView.setOnDismissAction(mock(KeyguardHostView.OnDismissAction.class),
+                null /* cancelAction */);
+        Assert.assertTrue("Action should exist", mKeyguardHostView.hasDismissActions());
+    }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
index a37947d..67453d5 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/KeyguardBouncerTest.java
@@ -22,6 +22,7 @@
 import static org.mockito.ArgumentMatchers.anyFloat;
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.reset;
 import static org.mockito.Mockito.spy;
@@ -307,4 +308,12 @@
                     mBouncer.isSecure(), mode != KeyguardSecurityModel.SecurityMode.None);
         }
     }
+
+    @Test
+    public void testWillDismissWithAction() {
+        mBouncer.ensureView();
+        Assert.assertFalse("Action not set yet", mBouncer.willDismissWithAction());
+        when(mKeyguardHostView.hasDismissActions()).thenReturn(true);
+        Assert.assertTrue("Action should exist", mBouncer.willDismissWithAction());
+    }
 }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
index 45845fc..7743c6b 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/phone/ScrimControllerTest.java
@@ -39,10 +39,8 @@
 import android.support.test.filters.SmallTest;
 import android.testing.AndroidTestingRunner;
 import android.testing.TestableLooper;
-import android.view.Choreographer;
 import android.view.View;
 
-import com.android.internal.util.Preconditions;
 import com.android.keyguard.KeyguardUpdateMonitor;
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.statusbar.ScrimView;
@@ -557,8 +555,8 @@
          * @param callback What to execute.
          */
         @Override
-        protected void doOnTheNextFrame(Choreographer.FrameCallback callback) {
-            callback.doFrame(0);
+        protected void doOnTheNextFrame(Runnable callback) {
+            callback.run();
         }
     }
 
diff --git a/proto/src/metrics_constants.proto b/proto/src/metrics_constants.proto
index 9417f04..cfb5c6d 100644
--- a/proto/src/metrics_constants.proto
+++ b/proto/src/metrics_constants.proto
@@ -5547,6 +5547,17 @@
     // OS: P
     ACTION_ANOMALY_TRIGGERED = 1367;
 
+    // ACTION: Settings > Condition > Device muted
+    // CATEGORY: SETTINGS
+    // OS: P
+    SETTINGS_CONDITION_DEVICE_MUTED = 1368;
+
+    // ACTION: Settings > Condition > Device vibrate
+    // CATEGORY: SETTINGS
+    // OS: P
+    SETTINGS_CONDITION_DEVICE_VIBRATE = 1369;
+
+
     // ---- End P Constants, all P constants go above this line ----
     // Add new aosp constants above this line.
     // END OF AOSP CONSTANTS
diff --git a/services/autofill/java/com/android/server/autofill/Helper.java b/services/autofill/java/com/android/server/autofill/Helper.java
index 7bb532e..58f78ec 100644
--- a/services/autofill/java/com/android/server/autofill/Helper.java
+++ b/services/autofill/java/com/android/server/autofill/Helper.java
@@ -180,9 +180,11 @@
      *
      * @param structure Assist structure
      * @param urlBarIds list of ids; only the first id found will be sanitized.
+     *
+     * @return the node containing the URL bar
      */
     @Nullable
-    public static void sanitizeUrlBar(@NonNull AssistStructure structure,
+    public static ViewNode sanitizeUrlBar(@NonNull AssistStructure structure,
             @NonNull String[] urlBarIds) {
         final ViewNode urlBarNode = findViewNode(structure, (node) -> {
             return ArrayUtils.contains(urlBarIds, node.getIdEntry());
@@ -191,7 +193,7 @@
             final String domain = urlBarNode.getText().toString();
             if (domain.isEmpty()) {
                 if (sDebug) Slog.d(TAG, "sanitizeUrlBar(): empty on " + urlBarNode.getIdEntry());
-                return;
+                return null;
             }
             urlBarNode.setWebDomain(domain);
             if (sDebug) {
@@ -199,6 +201,7 @@
                         + urlBarNode.getWebDomain());
             }
         }
+        return urlBarNode;
     }
 
     private interface ViewNodeFilter {
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 1e1de35..bcb0bc4 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -146,6 +146,13 @@
     /** Whether the app being autofilled is running in compat mode. */
     private final boolean mCompatMode;
 
+    /** Node representing the URL bar on compat mode. */
+    @GuardedBy("mLock")
+    private ViewNode mUrlBar;
+
+    @GuardedBy("mLock")
+    private boolean mSaveOnAllViewsInvisible;
+
     @GuardedBy("mLock")
     private final ArrayMap<AutofillId, ViewState> mViewStates = new ArrayMap<>();
 
@@ -280,7 +287,17 @@
                         Slog.d(TAG, "url_bars in compat mode: " + Arrays.toString(urlBarIds));
                     }
                     if (urlBarIds != null) {
-                        Helper.sanitizeUrlBar(structure, urlBarIds);
+                        mUrlBar = Helper.sanitizeUrlBar(structure, urlBarIds);
+                        if (mUrlBar != null) {
+                            final AutofillId urlBarId = mUrlBar.getAutofillId();
+                            if (sDebug) {
+                                Slog.d(TAG, "Setting urlBar as id=" + urlBarId + " and domain "
+                                        + mUrlBar.getWebDomain());
+                            }
+                            final ViewState viewState = new ViewState(Session.this, urlBarId,
+                                    Session.this, ViewState.STATE_URL_BAR);
+                            mViewStates.put(urlBarId, viewState);
+                        }
                     }
                 }
                 structure.sanitizeForParceling(true);
@@ -1878,14 +1895,15 @@
             return;
         }
         if (sVerbose) {
-            Slog.v(TAG, "updateLocked(): id=" + id + ", action=" + action + ", flags=" + flags);
+            Slog.v(TAG, "updateLocked(): id=" + id + ", action=" + actionAsString(action)
+                    + ", flags=" + flags);
         }
         ViewState viewState = mViewStates.get(id);
 
         if (viewState == null) {
             if (action == ACTION_START_SESSION || action == ACTION_VALUE_CHANGED
                     || action == ACTION_VIEW_ENTERED) {
-                if (sVerbose) Slog.v(TAG, "Creating viewState for " + id + " on " + action);
+                if (sVerbose) Slog.v(TAG, "Creating viewState for " + id);
                 boolean isIgnored = isIgnoredLocked(id);
                 viewState = new ViewState(this, id, this,
                         isIgnored ? ViewState.STATE_IGNORED : ViewState.STATE_INITIAL);
@@ -1895,11 +1913,11 @@
                 // detectable, and batch-send them when the session is finished (but that will
                 // require tracking detectable fields on AutofillManager)
                 if (isIgnored) {
-                    if (sDebug) Slog.d(TAG, "updateLocked(): ignoring view " + id);
+                    if (sDebug) Slog.d(TAG, "updateLocked(): ignoring view " + viewState);
                     return;
                 }
             } else {
-                if (sVerbose) Slog.v(TAG, "Ignored action " + action + " for " + id);
+                if (sVerbose) Slog.v(TAG, "Ignoring specific action when viewState=null");
                 return;
             }
         }
@@ -1913,6 +1931,40 @@
                 requestNewFillResponseLocked(flags);
                 break;
             case ACTION_VALUE_CHANGED:
+                if (mCompatMode && (viewState.getState() & ViewState.STATE_URL_BAR) != 0) {
+                    // Must cancel the session if the value of the URL bar changed
+                    final String currentUrl = mUrlBar == null ? null
+                            : mUrlBar.getText().toString().trim();
+                    if (currentUrl == null) {
+                        // Sanity check - shouldn't happen.
+                        wtf(null, "URL bar value changed, but current value is null");
+                        return;
+                    }
+                    if (value == null || ! value.isText()) {
+                        // Sanity check - shouldn't happen.
+                        wtf(null, "URL bar value changed to null or non-text: %s", value);
+                        return;
+                    }
+                    final String newUrl = value.getTextValue().toString();
+                    if (newUrl.equals(currentUrl)) {
+                        if (sDebug) Slog.d(TAG, "Ignoring change on URL bar as it's the same");
+                        return;
+                    }
+                    if (mSaveOnAllViewsInvisible) {
+                        // We cannot cancel the session because it could hinder Save when all views
+                        // are finished, as the URL bar changed callback is usually called before
+                        // the virtual views become invisible.
+                        if (sDebug) {
+                            Slog.d(TAG, "Ignoring change on URL because session will finish when "
+                                    + "views are gone");
+                        }
+                        return;
+                    }
+                    if (sDebug) Slog.d(TAG, "Finishing session because URL bar changed");
+                    forceRemoveSelfLocked(AutofillManager.STATE_UNKNOWN_COMPAT_MODE);
+                    return;
+                }
+
                 if (value != null && !value.equals(viewState.getCurrentValue())) {
                     if (value.isEmpty()
                             && viewState.getCurrentValue() != null
@@ -1953,6 +2005,12 @@
                 if (sVerbose && virtualBounds != null) {
                     Slog.v(TAG, "entered on virtual child " + id + ": " + virtualBounds);
                 }
+
+                if (mCompatMode && (viewState.getState() & ViewState.STATE_URL_BAR) != 0) {
+                    if (sDebug) Slog.d(TAG, "Ignoring VIEW_ENTERED on URL BAR (id=" + id + ")");
+                    return;
+                }
+
                 requestNewFillResponseOnViewEnteredIfNecessaryLocked(id, viewState, flags);
 
                 // Remove the UI if the ViewState has changed.
@@ -2068,7 +2126,7 @@
         if (response == null) return;
 
         ArraySet<AutofillId> trackedViews = null;
-        boolean saveOnAllViewsInvisible = false;
+        mSaveOnAllViewsInvisible = false;
         boolean saveOnFinish = true;
         final SaveInfo saveInfo = response.getSaveInfo();
         final AutofillId saveTriggerId;
@@ -2081,10 +2139,10 @@
             if (mCompatMode) {
                 flags |= SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE;
             }
-            saveOnAllViewsInvisible = (flags & SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE) != 0;
+            mSaveOnAllViewsInvisible = (flags & SaveInfo.FLAG_SAVE_ON_ALL_VIEWS_INVISIBLE) != 0;
 
             // We only need to track views if we want to save once they become invisible.
-            if (saveOnAllViewsInvisible) {
+            if (mSaveOnAllViewsInvisible) {
                 if (trackedViews == null) {
                     trackedViews = new ArraySet<>();
                 }
@@ -2129,7 +2187,7 @@
                 Slog.v(TAG, "updateTrackedIdsLocked(): " + trackedViews + " => " + fillableIds
                         + " triggerId: " + saveTriggerId + " saveOnFinish:" + saveOnFinish);
             }
-            mClient.setTrackedViews(id, toArray(trackedViews), saveOnAllViewsInvisible,
+            mClient.setTrackedViews(id, toArray(trackedViews), mSaveOnAllViewsInvisible,
                     saveOnFinish, toArray(fillableIds), saveTriggerId);
         } catch (RemoteException e) {
             Slog.w(TAG, "Cannot set tracked ids", e);
@@ -2421,6 +2479,16 @@
         pw.print(prefix); pw.print("mClientState: "); pw.println(
                 Helper.bundleToString(mClientState));
         pw.print(prefix); pw.print("mCompatMode: "); pw.println(mCompatMode);
+        pw.print(prefix); pw.print("mUrlBar: ");
+        if (mUrlBar == null) {
+            pw.println("N/A");
+        } else {
+            pw.print("id="); pw.print(mUrlBar.getAutofillId());
+            pw.print(" domain="); pw.print(mUrlBar.getWebDomain());
+            pw.print(" text="); Helper.printlnRedactedText(pw, mUrlBar.getText());
+        }
+        pw.print(prefix); pw.print("mSaveOnAllViewsInvisible: "); pw.println(
+                mSaveOnAllViewsInvisible);
         pw.print(prefix); pw.print("mSelectedDatasetIds: "); pw.println(mSelectedDatasetIds);
         mRemoteFillService.dump(prefix, pw);
     }
@@ -2513,6 +2581,11 @@
      */
     @GuardedBy("mLock")
     void forceRemoveSelfLocked() {
+        forceRemoveSelfLocked(AutofillManager.STATE_UNKNOWN);
+    }
+
+    @GuardedBy("mLock")
+    void forceRemoveSelfLocked(int clientState) {
         if (sVerbose) Slog.v(TAG, "forceRemoveSelfLocked(): " + mPendingSaveUi);
 
         final boolean isPendingSaveUi = isSaveUiPendingLocked();
@@ -2521,7 +2594,7 @@
         mUi.destroyAll(mPendingSaveUi, this, false);
         if (!isPendingSaveUi) {
             try {
-                mClient.setSessionFinished(AutofillManager.STATE_UNKNOWN);
+                mClient.setSessionFinished(clientState);
             } catch (RemoteException e) {
                 Slog.e(TAG, "Error notifying client to finish session", e);
             }
@@ -2624,4 +2697,19 @@
             Slog.wtf(TAG, message);
         }
     }
+
+    private static String actionAsString(int action) {
+        switch (action) {
+            case ACTION_START_SESSION:
+                return "START_SESSION";
+            case ACTION_VIEW_ENTERED:
+                return "VIEW_ENTERED";
+            case ACTION_VIEW_EXITED:
+                return "VIEW_EXITED";
+            case ACTION_VALUE_CHANGED:
+                return "VALUE_CHANGED";
+            default:
+                return "UNKNOWN_" + action;
+        }
+    }
 }
diff --git a/services/autofill/java/com/android/server/autofill/ViewState.java b/services/autofill/java/com/android/server/autofill/ViewState.java
index 03c5850..97ab97b 100644
--- a/services/autofill/java/com/android/server/autofill/ViewState.java
+++ b/services/autofill/java/com/android/server/autofill/ViewState.java
@@ -67,6 +67,8 @@
     public static final int STATE_IGNORED = 0x080;
     /** User manually request autofill in this view, after it was already autofilled. */
     public static final int STATE_RESTARTED_SESSION = 0x100;
+    /** View is the URL bar of a package on compat mode. */
+    public  static final int STATE_URL_BAR = 0x200;
 
     public final AutofillId id;
 
diff --git a/services/core/java/com/android/server/BluetoothManagerService.java b/services/core/java/com/android/server/BluetoothManagerService.java
index 02b1380..8d10cfa 100644
--- a/services/core/java/com/android/server/BluetoothManagerService.java
+++ b/services/core/java/com/android/server/BluetoothManagerService.java
@@ -60,6 +60,7 @@
 import android.provider.Settings;
 import android.provider.Settings.SettingNotFoundException;
 import android.util.Slog;
+import android.util.StatsLog;
 
 import com.android.internal.R;
 import com.android.internal.util.DumpUtils;
@@ -632,23 +633,14 @@
             if (DBG) {
                 Slog.d(TAG, "Binder is dead - unregister " + mPackageName);
             }
-            if (isBleAppPresent()) {
-                // Nothing to do, another app is here.
-                return;
-            }
-            if (DBG) {
-                Slog.d(TAG, "Disabling LE only mode after application crash");
-            }
-            try {
-                mBluetoothLock.readLock().lock();
-                if (mBluetooth != null && mBluetooth.getState() == BluetoothAdapter.STATE_BLE_ON) {
-                    mEnable = false;
-                    mBluetooth.onBrEdrDown();
+
+            for (Map.Entry<IBinder, ClientDeathRecipient> entry : mBleApps.entrySet()) {
+                IBinder token = entry.getKey();
+                ClientDeathRecipient deathRec = entry.getValue();
+                if (deathRec.equals(this)) {
+                    updateBleAppCount(token, false, mPackageName);
+                    break;
                 }
-            } catch (RemoteException e) {
-                Slog.e(TAG, "Unable to call onBrEdrDown", e);
-            } finally {
-                mBluetoothLock.readLock().unlock();
             }
         }
 
@@ -2178,6 +2170,11 @@
             mActiveLogs.add(
                     new ActiveLog(reason, packageName, enable, System.currentTimeMillis()));
         }
+
+        int state = enable ? StatsLog.BLUETOOTH_ENABLED_STATE_CHANGED__STATE__ENABLED :
+                             StatsLog.BLUETOOTH_ENABLED_STATE_CHANGED__STATE__DISABLED;
+        StatsLog.write_non_chained(StatsLog.BLUETOOTH_ENABLED_STATE_CHANGED,
+                Binder.getCallingUid(), null, state, reason, packageName);
     }
 
     private void addCrashLog() {
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 5e99189..91d3afb 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -101,6 +101,8 @@
 import android.os.ResultReceiver;
 import android.os.ServiceManager;
 import android.os.ServiceSpecificException;
+import android.os.ShellCallback;
+import android.os.ShellCommand;
 import android.os.SystemClock;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -5848,4 +5850,61 @@
     private static int encodeBool(boolean b) {
         return b ? 1 : 0;
     }
-}
+
+    @Override
+    public void onShellCommand(FileDescriptor in, FileDescriptor out,
+            FileDescriptor err, String[] args, ShellCallback callback,
+            ResultReceiver resultReceiver) {
+        (new ShellCmd()).exec(this, in, out, err, args, callback, resultReceiver);
+    }
+
+    private class ShellCmd extends ShellCommand {
+
+        @Override
+        public int onCommand(String cmd) {
+            if (cmd == null) {
+                return handleDefaultCommands(cmd);
+            }
+            final PrintWriter pw = getOutPrintWriter();
+            try {
+                switch (cmd) {
+                    case "airplane-mode":
+                        final String action = getNextArg();
+                        if ("enable".equals(action)) {
+                            setAirplaneMode(true);
+                            return 0;
+                        } else if ("disable".equals(action)) {
+                            setAirplaneMode(false);
+                            return 0;
+                        } else if (action == null) {
+                            final ContentResolver cr = mContext.getContentResolver();
+                            final int enabled = Settings.Global.getInt(cr,
+                                    Settings.Global.AIRPLANE_MODE_ON);
+                            pw.println(enabled == 0 ? "disabled" : "enabled");
+                            return 0;
+                        } else {
+                            onHelp();
+                            return -1;
+                        }
+                    default:
+                        return handleDefaultCommands(cmd);
+                }
+            } catch (Exception e) {
+                pw.println(e);
+            }
+            return -1;
+        }
+
+        @Override
+        public void onHelp() {
+            PrintWriter pw = getOutPrintWriter();
+            pw.println("Connectivity service commands:");
+            pw.println("  help");
+            pw.println("    Print this help text.");
+            pw.println("  airplane-mode [enable|disable]");
+            pw.println("    Turn airplane mode on or off.");
+            pw.println("  airplane-mode");
+            pw.println("    Get airplane mode.");
+        }
+    }
+}
\ No newline at end of file
diff --git a/services/core/java/com/android/server/PruneInstantAppsJobService.java b/services/core/java/com/android/server/PruneInstantAppsJobService.java
index a6c3685..48e3a43 100644
--- a/services/core/java/com/android/server/PruneInstantAppsJobService.java
+++ b/services/core/java/com/android/server/PruneInstantAppsJobService.java
@@ -23,6 +23,7 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.PackageManagerInternal;
+import android.os.AsyncTask;
 
 import java.util.concurrent.TimeUnit;
 
@@ -47,10 +48,12 @@
 
     @Override
     public boolean onStartJob(JobParameters params) {
-        PackageManagerInternal packageManagerInternal = LocalServices.getService(
-                PackageManagerInternal.class);
-        packageManagerInternal.pruneInstantApps();
-        jobFinished(params, false);
+        AsyncTask.execute(() -> {
+            PackageManagerInternal packageManagerInternal = LocalServices.getService(
+                    PackageManagerInternal.class);
+            packageManagerInternal.pruneInstantApps();
+            jobFinished(params, false);
+        });
         return true;
     }
 
diff --git a/services/core/java/com/android/server/StorageManagerService.java b/services/core/java/com/android/server/StorageManagerService.java
index 3d7b21d..379658f 100644
--- a/services/core/java/com/android/server/StorageManagerService.java
+++ b/services/core/java/com/android/server/StorageManagerService.java
@@ -2668,6 +2668,9 @@
         final int userId = UserHandle.getUserId(Binder.getCallingUid());
         final UserEnvironment userEnv = new UserEnvironment(userId);
 
+        // Ignore requests to create directories while storage is locked
+        if (!isUserKeyUnlocked(userId)) return;
+
         // Validate that reported package name belongs to caller
         final AppOpsManager appOps = (AppOpsManager) mContext.getSystemService(
                 Context.APP_OPS_SERVICE);
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 4f0acf7..706bbcf 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -1266,6 +1266,8 @@
         }
     }
 
+    boolean mSystemProvidersInstalled;
+
     CoreSettingsObserver mCoreSettingsObserver;
 
     FontScaleSettingObserver mFontScaleSettingObserver;
@@ -12110,6 +12112,14 @@
                             "Attempt to launch content provider before system ready");
                 }
 
+                // If system providers are not installed yet we aggressively crash to avoid
+                // creating multiple instance of these providers and then bad things happen!
+                if (!mSystemProvidersInstalled && cpi.applicationInfo.isSystemApp()
+                        && "system".equals(cpi.processName)) {
+                    throw new IllegalStateException("Cannot access system provider: '"
+                            + cpi.authority + "' before system providers are installed!");
+                }
+
                 // Make sure that the user who owns this provider is running.  If not,
                 // we don't want to allow it to run.
                 if (!mUserController.isUserRunning(userId, 0)) {
@@ -12663,6 +12673,10 @@
             mSystemThread.installSystemProviders(providers);
         }
 
+        synchronized (this) {
+            mSystemProvidersInstalled = true;
+        }
+
         mConstants.start(mContext.getContentResolver());
         mCoreSettingsObserver = new CoreSettingsObserver(this);
         mFontScaleSettingObserver = new FontScaleSettingObserver();
diff --git a/services/core/java/com/android/server/am/RecentTasks.java b/services/core/java/com/android/server/am/RecentTasks.java
index 1335ced..efd8153 100644
--- a/services/core/java/com/android/server/am/RecentTasks.java
+++ b/services/core/java/com/android/server/am/RecentTasks.java
@@ -1243,15 +1243,13 @@
      */
     private int findRemoveIndexForAddTask(TaskRecord task) {
         final int recentsCount = mTasks.size();
-        final int taskActivityType = task.getActivityType();
         final Intent intent = task.intent;
         final boolean document = intent != null && intent.isDocument();
         int maxRecents = task.maxRecents - 1;
         for (int i = 0; i < recentsCount; i++) {
             final TaskRecord tr = mTasks.get(i);
-            final int trActivityType = tr.getActivityType();
             if (task != tr) {
-                if (taskActivityType != trActivityType || task.userId != tr.userId) {
+                if (!task.hasCompatibleActivityType(tr)) {
                     continue;
                 }
                 final Intent trIntent = tr.intent;
diff --git a/services/core/java/com/android/server/clipboard/ClipboardService.java b/services/core/java/com/android/server/clipboard/ClipboardService.java
index 776e93d..3f39f45 100644
--- a/services/core/java/com/android/server/clipboard/ClipboardService.java
+++ b/services/core/java/com/android/server/clipboard/ClipboardService.java
@@ -368,6 +368,19 @@
         return related;
     }
 
+    /** Check if the user has the given restriction set. Default to true if error occured during
+     * calling UserManager, so it fails safe.
+     */
+    private boolean hasRestriction(String restriction, int userId) {
+        try {
+            return mUm.hasUserRestriction(restriction, userId);
+        } catch (RemoteException e) {
+            Slog.e(TAG, "Remote Exception calling UserManager.getUserRestrictions: ", e);
+            // Fails safe
+            return true;
+        }
+    }
+
     void setPrimaryClipInternal(@Nullable ClipData clip, int callingUid) {
         // Push clipboard to host, if any
         if (mHostClipboardMonitor != null) {
@@ -391,13 +404,8 @@
         if (related != null) {
             int size = related.size();
             if (size > 1) { // Related profiles list include the current profile.
-                boolean canCopy = false;
-                try {
-                    canCopy = !mUm.getUserRestrictions(userId).getBoolean(
-                            UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE);
-                } catch (RemoteException e) {
-                    Slog.e(TAG, "Remote Exception calling UserManager: " + e);
-                }
+                final boolean canCopy = !hasRestriction(
+                        UserManager.DISALLOW_CROSS_PROFILE_COPY_PASTE, userId);
                 // Copy clip data to related users if allowed. If disallowed, then remove
                 // primary clip in related users to prevent pasting stale content.
                 if (!canCopy) {
@@ -416,7 +424,11 @@
                 for (int i = 0; i < size; i++) {
                     int id = related.get(i).id;
                     if (id != userId) {
-                        setPrimaryClipInternal(getClipboard(id), clip, callingUid);
+                        final boolean canCopyIntoProfile = !hasRestriction(
+                                UserManager.DISALLOW_SHARE_INTO_MANAGED_PROFILE, id);
+                        if (canCopyIntoProfile) {
+                            setPrimaryClipInternal(getClipboard(id), clip, callingUid);
+                        }
                     }
                 }
             }
diff --git a/services/core/java/com/android/server/connectivity/PermissionMonitor.java b/services/core/java/com/android/server/connectivity/PermissionMonitor.java
index d578e95..e471c7d 100644
--- a/services/core/java/com/android/server/connectivity/PermissionMonitor.java
+++ b/services/core/java/com/android/server/connectivity/PermissionMonitor.java
@@ -202,7 +202,9 @@
             // Only using the first package name. There may be multiple names if multiple
             // apps share the same UID, but in that case they also share permissions so
             // querying with any of the names will return the same results.
-            final PackageInfo app = mPackageManager.getPackageInfo(names[0], GET_PERMISSIONS);
+            int userId = UserHandle.getUserId(uid);
+            final PackageInfo app = mPackageManager.getPackageInfoAsUser(
+                    names[0], GET_PERMISSIONS, userId);
             return hasUseBackgroundNetworksPermission(app);
         } catch (NameNotFoundException e) {
             // App not found.
diff --git a/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java b/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
index 00abb37..f0bcb81 100644
--- a/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
+++ b/services/core/java/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManager.java
@@ -317,14 +317,35 @@
         mListenersStorage.setSnapshotListener(uid, intent);
     }
 
+    /**
+     * Set the server params for the user's key chain. This is used to uniquely identify a key
+     * chain. Along with the counter ID, it is used to uniquely identify an instance of a vault.
+     */
     public void setServerParams(@NonNull byte[] serverParams) throws RemoteException {
         checkRecoverKeyStorePermission();
         int userId = UserHandle.getCallingUserId();
         int uid = Binder.getCallingUid();
-        long updatedRows = mDatabase.setServerParams(userId, uid, serverParams);
-        if (updatedRows > 0) {
-            mDatabase.setShouldCreateSnapshot(userId, uid, true);
+
+        byte[] currentServerParams = mDatabase.getServerParams(userId, uid);
+
+        if (Arrays.equals(serverParams, currentServerParams)) {
+            Log.v(TAG, "Not updating server params - same as old value.");
+            return;
         }
+
+        long updatedRows = mDatabase.setServerParams(userId, uid, serverParams);
+        if (updatedRows < 1) {
+            throw new ServiceSpecificException(
+                    ERROR_SERVICE_INTERNAL_ERROR, "Database failure trying to set server params.");
+        }
+
+        if (currentServerParams == null) {
+            Log.i(TAG, "Initialized server params.");
+            return;
+        }
+
+        Log.i(TAG, "Updated server params. Snapshot pending.");
+        mDatabase.setShouldCreateSnapshot(userId, uid, true);
     }
 
     /**
diff --git a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
index efca159..8febecf 100644
--- a/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
+++ b/services/core/java/com/android/server/net/NetworkPolicyManagerService.java
@@ -1141,7 +1141,7 @@
         // TODO: support shared UIDs
         if (maxBytes > 0 && maxBytes > totalBytes / 2) {
             final String[] packageNames = mContext.getPackageManager().getPackagesForUid(maxUid);
-            if (packageNames.length == 1) {
+            if (packageNames != null && packageNames.length == 1) {
                 try {
                     return mContext.getPackageManager().getApplicationInfo(packageNames[0],
                             MATCH_ANY_USER | MATCH_DISABLED_COMPONENTS | MATCH_DIRECT_BOOT_AWARE
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java
index 27eeb93..59cd561 100644
--- a/services/core/java/com/android/server/notification/NotificationManagerService.java
+++ b/services/core/java/com/android/server/notification/NotificationManagerService.java
@@ -1877,13 +1877,13 @@
         return newSuppressedVisualEffects;
     }
 
-    // TODO: log visual differences, not just audible ones
     @GuardedBy("mNotificationLock")
     protected void maybeRecordInterruptionLocked(NotificationRecord r) {
         if (r.isInterruptive()) {
             mAppUsageStats.reportInterruptiveNotification(r.sbn.getPackageName(),
                     r.getChannel().getId(),
                     getRealUserId(r.sbn.getUserId()));
+            logRecentLocked(r);
         }
     }
 
@@ -4344,10 +4344,6 @@
 
                     mNotificationsByKey.put(n.getKey(), r);
 
-                    if (!r.isUpdate) {
-                        logRecentLocked(r);
-                    }
-
                     // Ensure if this is a foreground service that the proper additional
                     // flags are set.
                     if ((notification.flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) {
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
index bd30c5b..f5b52fc 100644
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
@@ -1505,6 +1505,9 @@
             return EmptyArray.INT;
         }
         for (PackageParser.Package pkg : pkgList) {
+            if (pkg.requestedPermissions == null) {
+                continue;
+            }
             final int requestedPermCount = pkg.requestedPermissions.size();
             for (int j = 0; j < requestedPermCount; j++) {
                 String permission = pkg.requestedPermissions.get(j);
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index dd88cd1..2ffc4e7 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -64,6 +64,7 @@
 import android.os.WorkSource;
 import android.os.WorkSource.WorkChain;
 import android.provider.Settings;
+import android.provider.Settings.Global;
 import android.provider.Settings.SettingNotFoundException;
 import android.service.dreams.DreamManagerInternal;
 import android.service.vr.IVrManager;
@@ -97,6 +98,7 @@
 import com.android.server.lights.LightsManager;
 import com.android.server.policy.WindowManagerPolicy;
 import com.android.server.power.batterysaver.BatterySaverController;
+import com.android.server.power.batterysaver.BatterySaverStateMachine;
 
 import java.io.FileDescriptor;
 import java.io.PrintWriter;
@@ -225,6 +227,7 @@
     private final AmbientDisplayConfiguration mAmbientDisplayConfiguration;
     private final BatterySaverPolicy mBatterySaverPolicy;
     private final BatterySaverController mBatterySaverController;
+    private final BatterySaverStateMachine mBatterySaverStateMachine;
 
     private LightsManager mLightsManager;
     private BatteryManagerInternal mBatteryManagerInternal;
@@ -492,18 +495,6 @@
     // Time when we last logged a warning about calling userActivity() without permission.
     private long mLastWarningAboutUserActivityPermission = Long.MIN_VALUE;
 
-    // If true, the device is in low power mode.
-    private boolean mLowPowerModeEnabled;
-
-    // Current state of the low power mode setting.
-    private boolean mLowPowerModeSetting;
-
-    // Current state of whether the settings are allowing auto low power mode.
-    private boolean mAutoLowPowerModeConfigured;
-
-    // The user turned off low power mode below the trigger level
-    private boolean mAutoLowPowerModeSnoozing;
-
     // True if the battery level is currently considered low.
     private boolean mBatteryLevelLow;
 
@@ -667,6 +658,7 @@
         mBatterySaverPolicy = new BatterySaverPolicy(mHandler);
         mBatterySaverController = new BatterySaverController(mContext,
                 BackgroundThread.get().getLooper(), mBatterySaverPolicy);
+        mBatterySaverStateMachine = new BatterySaverStateMachine(mContext, mBatterySaverController);
 
         synchronized (mLock) {
             mWakeLockSuspendBlocker = createSuspendBlockerLocked("PowerManagerService.WakeLocks");
@@ -704,6 +696,7 @@
         mBatterySaverPolicy = batterySaverPolicy;
         mBatterySaverController = new BatterySaverController(context,
                 BackgroundThread.getHandler().getLooper(), batterySaverPolicy);
+        mBatterySaverStateMachine = new BatterySaverStateMachine(mContext, mBatterySaverController);
     }
 
     @Override
@@ -725,6 +718,8 @@
                 final long now = SystemClock.uptimeMillis();
                 mBootCompleted = true;
                 mDirty |= DIRTY_BOOT_COMPLETED;
+
+                mBatterySaverStateMachine.onBootCompleted();
                 userActivityNoUpdateLocked(
                         now, PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID);
                 updatePowerStateLocked();
@@ -820,12 +815,6 @@
                 Settings.System.SCREEN_AUTO_BRIGHTNESS_ADJ),
                 false, mSettingsObserver, UserHandle.USER_ALL);
         resolver.registerContentObserver(Settings.Global.getUriFor(
-                Settings.Global.LOW_POWER_MODE),
-                false, mSettingsObserver, UserHandle.USER_ALL);
-        resolver.registerContentObserver(Settings.Global.getUriFor(
-                Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL),
-                false, mSettingsObserver, UserHandle.USER_ALL);
-        resolver.registerContentObserver(Settings.Global.getUriFor(
                 Settings.Global.THEATER_MODE_ON),
                 false, mSettingsObserver, UserHandle.USER_ALL);
         resolver.registerContentObserver(Settings.Secure.getUriFor(
@@ -953,17 +942,6 @@
                 Settings.System.SCREEN_BRIGHTNESS_MODE,
                 Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL, UserHandle.USER_CURRENT);
 
-        final boolean lowPowerModeEnabled = Settings.Global.getInt(resolver,
-                Settings.Global.LOW_POWER_MODE, 0) != 0;
-        final boolean autoLowPowerModeConfigured = Settings.Global.getInt(resolver,
-                Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0) != 0;
-        if (lowPowerModeEnabled != mLowPowerModeSetting
-                || autoLowPowerModeConfigured != mAutoLowPowerModeConfigured) {
-            mLowPowerModeSetting = lowPowerModeEnabled;
-            mAutoLowPowerModeConfigured = autoLowPowerModeConfigured;
-            updateLowPowerModeLocked();
-        }
-
         mDirty |= DIRTY_SETTINGS;
     }
 
@@ -977,29 +955,6 @@
         }
     }
 
-    private void updateLowPowerModeLocked() {
-        if ((mIsPowered || !mBatteryLevelLow && !mBootCompleted) && mLowPowerModeSetting) {
-            if (DEBUG_SPEW) {
-                Slog.d(TAG, "updateLowPowerModeLocked: powered or booting with sufficient battery,"
-                        + " turning setting off");
-            }
-            // Turn setting off if powered
-            Settings.Global.putInt(mContext.getContentResolver(),
-                    Settings.Global.LOW_POWER_MODE, 0);
-            mLowPowerModeSetting = false;
-        }
-        final boolean autoLowPowerModeEnabled = !mIsPowered && mAutoLowPowerModeConfigured
-                && !mAutoLowPowerModeSnoozing && mBatteryLevelLow;
-        final boolean lowPowerModeEnabled = mLowPowerModeSetting || autoLowPowerModeEnabled;
-
-        if (mLowPowerModeEnabled != lowPowerModeEnabled) {
-            mLowPowerModeEnabled = lowPowerModeEnabled;
-
-            postAfterBootCompleted(() ->
-                    mBatterySaverController.enableBatterySaver(mLowPowerModeEnabled));
-        }
-    }
-
     private void handleSettingsChangedLocked() {
         updateSettingsLocked();
         updatePowerStateLocked();
@@ -1751,15 +1706,7 @@
                 }
             }
 
-            if (wasPowered != mIsPowered || oldLevelLow != mBatteryLevelLow) {
-                if (oldLevelLow != mBatteryLevelLow && !mBatteryLevelLow) {
-                    if (DEBUG_SPEW) {
-                        Slog.d(TAG, "updateIsPoweredLocked: resetting low power snooze");
-                    }
-                    mAutoLowPowerModeSnoozing = false;
-                }
-                updateLowPowerModeLocked();
-            }
+            mBatterySaverStateMachine.setBatteryStatus(mIsPowered, mBatteryLevel, mBatteryLevelLow);
         }
     }
 
@@ -2733,36 +2680,20 @@
     }
 
     private boolean isLowPowerModeInternal() {
-        synchronized (mLock) {
-            return mLowPowerModeEnabled;
-        }
+        return mBatterySaverController.isEnabled();
     }
 
-    private boolean setLowPowerModeInternal(boolean mode) {
+    private boolean setLowPowerModeInternal(boolean enabled) {
         synchronized (mLock) {
-            if (DEBUG) Slog.d(TAG, "setLowPowerModeInternal " + mode + " mIsPowered=" + mIsPowered);
+            if (DEBUG) {
+                Slog.d(TAG, "setLowPowerModeInternal " + enabled + " mIsPowered=" + mIsPowered);
+            }
             if (mIsPowered) {
                 return false;
             }
-            Settings.Global.putInt(mContext.getContentResolver(),
-                    Settings.Global.LOW_POWER_MODE, mode ? 1 : 0);
-            mLowPowerModeSetting = mode;
 
-            if (mAutoLowPowerModeConfigured && mBatteryLevelLow) {
-                if (mode && mAutoLowPowerModeSnoozing) {
-                    if (DEBUG_SPEW) {
-                        Slog.d(TAG, "setLowPowerModeInternal: clearing low power mode snooze");
-                    }
-                    mAutoLowPowerModeSnoozing = false;
-                } else if (!mode && !mAutoLowPowerModeSnoozing) {
-                    if (DEBUG_SPEW) {
-                        Slog.d(TAG, "setLowPowerModeInternal: snoozing low power mode");
-                    }
-                    mAutoLowPowerModeSnoozing = true;
-                }
-            }
+            mBatterySaverStateMachine.setBatterySaverEnabledManually(enabled);
 
-            updateLowPowerModeLocked();
             return true;
         }
     }
@@ -2848,7 +2779,8 @@
     @VisibleForTesting
     void updatePowerRequestFromBatterySaverPolicy(DisplayPowerRequest displayPowerRequest) {
         PowerSaveState state = mBatterySaverPolicy.
-                getBatterySaverPolicy(ServiceType.SCREEN_BRIGHTNESS, mLowPowerModeEnabled);
+                getBatterySaverPolicy(ServiceType.SCREEN_BRIGHTNESS,
+                        mBatterySaverController.isEnabled());
         displayPowerRequest.lowPowerMode = state.batterySaverEnabled;
         displayPowerRequest.screenLowPowerBrightnessFactor = state.brightnessFactor;
     }
@@ -3325,7 +3257,6 @@
             pw.println("  mRequestWaitForNegativeProximity=" + mRequestWaitForNegativeProximity);
             pw.println("  mSandmanScheduled=" + mSandmanScheduled);
             pw.println("  mSandmanSummoned=" + mSandmanSummoned);
-            pw.println("  mLowPowerModeEnabled=" + mLowPowerModeEnabled);
             pw.println("  mBatteryLevelLow=" + mBatteryLevelLow);
             pw.println("  mLightDeviceIdleMode=" + mLightDeviceIdleMode);
             pw.println("  mDeviceIdleMode=" + mDeviceIdleMode);
@@ -3378,9 +3309,6 @@
             pw.println("  mDreamsActivateOnSleepSetting=" + mDreamsActivateOnSleepSetting);
             pw.println("  mDreamsActivateOnDockSetting=" + mDreamsActivateOnDockSetting);
             pw.println("  mDozeAfterScreenOff=" + mDozeAfterScreenOff);
-            pw.println("  mLowPowerModeSetting=" + mLowPowerModeSetting);
-            pw.println("  mAutoLowPowerModeConfigured=" + mAutoLowPowerModeConfigured);
-            pw.println("  mAutoLowPowerModeSnoozing=" + mAutoLowPowerModeSnoozing);
             pw.println("  mMinimumScreenOffTimeoutConfig=" + mMinimumScreenOffTimeoutConfig);
             pw.println("  mMaximumScreenDimDurationConfig=" + mMaximumScreenDimDurationConfig);
             pw.println("  mMaximumScreenDimRatioConfig=" + mMaximumScreenDimRatioConfig);
@@ -3456,6 +3384,7 @@
             pw.println("Display Power: " + mDisplayPowerCallbacks);
 
             mBatterySaverPolicy.dump(pw);
+            mBatterySaverStateMachine.dump(pw);
 
             pw.println();
             final int numProfiles = mProfilePowerState.size();
@@ -3557,7 +3486,6 @@
                     mRequestWaitForNegativeProximity);
             proto.write(PowerManagerServiceDumpProto.IS_SANDMAN_SCHEDULED, mSandmanScheduled);
             proto.write(PowerManagerServiceDumpProto.IS_SANDMAN_SUMMONED, mSandmanSummoned);
-            proto.write(PowerManagerServiceDumpProto.IS_LOW_POWER_MODE_ENABLED, mLowPowerModeEnabled);
             proto.write(PowerManagerServiceDumpProto.IS_BATTERY_LEVEL_LOW, mBatteryLevelLow);
             proto.write(PowerManagerServiceDumpProto.IS_LIGHT_DEVICE_IDLE_MODE, mLightDeviceIdleMode);
             proto.write(PowerManagerServiceDumpProto.IS_DEVICE_IDLE_MODE, mDeviceIdleMode);
@@ -3663,15 +3591,6 @@
                     PowerServiceSettingsAndConfigurationDumpProto.IS_DOZE_AFTER_SCREEN_OFF_CONFIG,
                     mDozeAfterScreenOff);
             proto.write(
-                    PowerServiceSettingsAndConfigurationDumpProto.IS_LOW_POWER_MODE_SETTING,
-                    mLowPowerModeSetting);
-            proto.write(
-                    PowerServiceSettingsAndConfigurationDumpProto.IS_AUTO_LOW_POWER_MODE_CONFIGURED,
-                    mAutoLowPowerModeConfigured);
-            proto.write(
-                    PowerServiceSettingsAndConfigurationDumpProto.IS_AUTO_LOW_POWER_MODE_SNOOZING,
-                    mAutoLowPowerModeSnoozing);
-            proto.write(
                     PowerServiceSettingsAndConfigurationDumpProto
                             .MINIMUM_SCREEN_OFF_TIMEOUT_CONFIG_MS,
                     mMinimumScreenOffTimeoutConfig);
@@ -3792,6 +3711,9 @@
                 proto.end(uIDToken);
             }
 
+            mBatterySaverStateMachine.dumpProto(proto,
+                    PowerManagerServiceDumpProto.BATTERY_SAVER_STATE_MACHINE);
+
             mHandler.getLooper().writeToProto(proto, PowerManagerServiceDumpProto.LOOPER);
 
             for (WakeLock wl : mWakeLocks) {
@@ -4432,12 +4354,12 @@
         }
 
         @Override // Binder call
-        public boolean setPowerSaveMode(boolean mode) {
+        public boolean setPowerSaveMode(boolean enabled) {
             mContext.enforceCallingOrSelfPermission(
                     android.Manifest.permission.DEVICE_POWER, null);
             final long ident = Binder.clearCallingIdentity();
             try {
-                return setLowPowerModeInternal(mode);
+                return setLowPowerModeInternal(enabled);
             } finally {
                 Binder.restoreCallingIdentity(ident);
             }
@@ -4752,7 +4674,8 @@
         @Override
         public PowerSaveState getLowPowerState(@ServiceType int serviceType) {
             synchronized (mLock) {
-                return mBatterySaverPolicy.getBatterySaverPolicy(serviceType, mLowPowerModeEnabled);
+                return mBatterySaverPolicy.getBatterySaverPolicy(serviceType,
+                        mBatterySaverController.isEnabled());
             }
         }
 
diff --git a/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java b/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java
new file mode 100644
index 0000000..5b3182e
--- /dev/null
+++ b/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java
@@ -0,0 +1,413 @@
+/*
+ * Copyright (C) 2018 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.power.batterysaver;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.ContentObserver;
+import android.os.UserHandle;
+import android.provider.Settings;
+import android.provider.Settings.Global;
+import android.util.Slog;
+import android.util.proto.ProtoOutputStream;
+
+import com.android.internal.annotations.GuardedBy;
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.power.BatterySaverPolicy;
+import com.android.server.power.BatterySaverStateMachineProto;
+
+import java.io.PrintWriter;
+
+/**
+ * Decides when to enable / disable battery saver.
+ *
+ * (n.b. This isn't really implemented as a "state machine" though.)
+ *
+ * Test:
+  atest $ANDROID_BUILD_TOP/frameworks/base/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverStateMachineTest.java
+ */
+public class BatterySaverStateMachine {
+    private static final String TAG = "BatterySaverStateMachine";
+    private final Object mLock = new Object();
+
+    private static final boolean DEBUG = BatterySaverPolicy.DEBUG;
+
+    private final Context mContext;
+    private final BatterySaverController mBatterySaverController;
+
+    /** Whether the system has booted. */
+    @GuardedBy("mLock")
+    private boolean mBootCompleted;
+
+    /** Whether global settings have been loaded already. */
+    @GuardedBy("mLock")
+    private boolean mSettingsLoaded;
+
+    /** Whether the first battery status has arrived. */
+    @GuardedBy("mLock")
+    private boolean mBatteryStatusSet;
+
+    /** Whether the device is connected to any power source. */
+    @GuardedBy("mLock")
+    private boolean mIsPowered;
+
+    /** Current battery level in %, 0-100. (Currently only used in dumpsys.) */
+    @GuardedBy("mLock")
+    private int mBatteryLevel;
+
+    /** Whether the battery level is considered to be "low" or not.*/
+    @GuardedBy("mLock")
+    private boolean mIsBatteryLevelLow;
+
+    /** Previously known value of Global.LOW_POWER_MODE. */
+    @GuardedBy("mLock")
+    private boolean mSettingBatterySaverEnabled;
+
+    /** Previously known value of Global.LOW_POWER_MODE_STICKY. */
+    @GuardedBy("mLock")
+    private boolean mSettingBatterySaverEnabledSticky;
+
+    /**
+     * Previously known value of Global.LOW_POWER_MODE_TRIGGER_LEVEL.
+     * (Currently only used in dumpsys.)
+     */
+    @GuardedBy("mLock")
+    private int mSettingBatterySaverTriggerThreshold;
+
+    /**
+     * Whether BS has been manually disabled while the battery level is low, in which case we
+     * shouldn't auto re-enable it until the battery level is not low.
+     */
+    @GuardedBy("mLock")
+    private boolean mBatterySaverSnoozing;
+
+    private final ContentObserver mSettingsObserver = new ContentObserver(null) {
+        @Override
+        public void onChange(boolean selfChange) {
+            synchronized (mLock) {
+                refreshSettingsLocked();
+            }
+        }
+    };
+
+    public BatterySaverStateMachine(
+            Context context, BatterySaverController batterySaverController) {
+        mContext = context;
+        mBatterySaverController = batterySaverController;
+    }
+
+    private boolean isBatterySaverEnabled() {
+        return mBatterySaverController.isEnabled();
+    }
+
+    private boolean isAutoBatterySaverConfigured() {
+        return mSettingBatterySaverTriggerThreshold > 0;
+    }
+
+    /**
+     * {@link com.android.server.power.PowerManagerService} calls it when the system is booted.
+     */
+    public void onBootCompleted() {
+        if (DEBUG) {
+            Slog.d(TAG, "onBootCompleted");
+        }
+        synchronized (mLock) {
+
+            final ContentResolver cr = mContext.getContentResolver();
+            cr.registerContentObserver(Settings.Global.getUriFor(
+                    Settings.Global.LOW_POWER_MODE),
+                    false, mSettingsObserver, UserHandle.USER_SYSTEM);
+            cr.registerContentObserver(Settings.Global.getUriFor(
+                    Settings.Global.LOW_POWER_MODE_STICKY),
+                    false, mSettingsObserver, UserHandle.USER_SYSTEM);
+            cr.registerContentObserver(Settings.Global.getUriFor(
+                    Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL),
+                    false, mSettingsObserver, UserHandle.USER_SYSTEM);
+
+            mBootCompleted = true;
+
+            refreshSettingsLocked();
+
+            doAutoBatterySaverLocked();
+        }
+    }
+
+    void refreshSettingsLocked() {
+        final ContentResolver cr = mContext.getContentResolver();
+
+        final boolean lowPowerModeEnabled = getGlobalSetting(
+                Settings.Global.LOW_POWER_MODE, 0) != 0;
+        final boolean lowPowerModeEnabledSticky = getGlobalSetting(
+                Settings.Global.LOW_POWER_MODE_STICKY, 0) != 0;
+        final int lowPowerModeTriggerLevel = getGlobalSetting(
+                Settings.Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
+
+        setSettingsLocked(lowPowerModeEnabled, lowPowerModeEnabledSticky,
+                lowPowerModeTriggerLevel);
+    }
+
+    /**
+     * {@link com.android.server.power.PowerManagerService} calls it when relevant global settings
+     * have changed.
+     *
+     * Note this will be called before {@link #onBootCompleted} too.
+     */
+    @VisibleForTesting
+    void setSettingsLocked(boolean batterySaverEnabled, boolean batterySaverEnabledSticky,
+            int batterySaverTriggerThreshold) {
+        if (DEBUG) {
+            Slog.d(TAG, "setSettings: enabled=" + batterySaverEnabled
+                    + " sticky=" + batterySaverEnabledSticky
+                    + " threshold=" + batterySaverTriggerThreshold);
+        }
+
+        mSettingsLoaded = true;
+
+        final boolean enabledChanged = mSettingBatterySaverEnabled != batterySaverEnabled;
+        final boolean stickyChanged =
+                mSettingBatterySaverEnabledSticky != batterySaverEnabledSticky;
+        final boolean thresholdChanged
+                = mSettingBatterySaverTriggerThreshold != batterySaverTriggerThreshold;
+
+        if (!(enabledChanged || stickyChanged || thresholdChanged)) {
+            return;
+        }
+
+        mSettingBatterySaverEnabled = batterySaverEnabled;
+        mSettingBatterySaverEnabledSticky = batterySaverEnabledSticky;
+        mSettingBatterySaverTriggerThreshold = batterySaverTriggerThreshold;
+
+        if (enabledChanged) {
+            final String reason = batterySaverEnabled
+                    ? "Global.low_power changed to 1" : "Global.low_power changed to 0";
+            enableBatterySaverLocked(/*enable=*/ batterySaverEnabled, /*manual=*/ true,
+                    reason);
+        }
+    }
+
+    /**
+     * {@link com.android.server.power.PowerManagerService} calls it when battery state changes.
+     *
+     * Note this may be called before {@link #onBootCompleted} too.
+     */
+    public void setBatteryStatus(boolean newPowered, int newLevel, boolean newBatteryLevelLow) {
+        if (DEBUG) {
+            Slog.d(TAG, "setBatteryStatus: powered=" + newPowered + " level=" + newLevel
+                    + " low=" + newBatteryLevelLow);
+        }
+        synchronized (mLock) {
+            mBatteryStatusSet = true;
+
+            final boolean poweredChanged = mIsPowered != newPowered;
+            final boolean levelChanged = mBatteryLevel != newLevel;
+            final boolean lowChanged = mIsBatteryLevelLow != newBatteryLevelLow;
+
+            if (!(poweredChanged || levelChanged || lowChanged)) {
+                return;
+            }
+
+            mIsPowered = newPowered;
+            mBatteryLevel = newLevel;
+            mIsBatteryLevelLow = newBatteryLevelLow;
+
+            doAutoBatterySaverLocked();
+        }
+    }
+
+    /**
+     * Decide whether to auto-start / stop battery saver.
+     */
+    private void doAutoBatterySaverLocked() {
+        if (DEBUG) {
+            Slog.d(TAG, "doAutoBatterySaverLocked: mBootCompleted=" + mBootCompleted
+                    + " mSettingsLoaded=" + mSettingsLoaded
+                    + " mBatteryStatusSet=" + mBatteryStatusSet
+                    + " mIsBatteryLevelLow=" + mIsBatteryLevelLow
+                    + " mBatterySaverSnoozing=" + mBatterySaverSnoozing
+                    + " mIsPowered=" + mIsPowered
+                    + " mSettingBatterySaverEnabledSticky=" + mSettingBatterySaverEnabledSticky);
+        }
+        if (!(mBootCompleted && mSettingsLoaded && mBatteryStatusSet)) {
+            return; // Not fully initialized yet.
+        }
+        if (!mIsBatteryLevelLow) {
+            updateSnoozingLocked(false, "Battery not low");
+        }
+        if (mIsPowered) {
+            updateSnoozingLocked(false, "Plugged in");
+            enableBatterySaverLocked(/*enable=*/ false, /*manual=*/ false, "Plugged in");
+
+        } else if (mSettingBatterySaverEnabledSticky) {
+            // Re-enable BS.
+            enableBatterySaverLocked(/*enable=*/ true, /*manual=*/ true, "Sticky restore");
+
+        } else if (mIsBatteryLevelLow) {
+            if (!mBatterySaverSnoozing && isAutoBatterySaverConfigured()) {
+                enableBatterySaverLocked(/*enable=*/ true, /*manual=*/ false, "Auto ON");
+            }
+        } else { // Battery not low
+            enableBatterySaverLocked(/*enable=*/ false, /*manual=*/ false, "Auto OFF");
+        }
+    }
+
+    /**
+     * {@link com.android.server.power.PowerManagerService} calls it when
+     * {@link android.os.PowerManager#setPowerSaveMode} is called.
+     *
+     * Note this could? be called before {@link #onBootCompleted} too.
+     */
+    public void setBatterySaverEnabledManually(boolean enabled) {
+        if (DEBUG) {
+            Slog.d(TAG, "setBatterySaverEnabledManually: enabled=" + enabled);
+        }
+        synchronized (mLock) {
+            enableBatterySaverLocked(/*enable=*/ enabled, /*manual=*/ true,
+                    (enabled ? "Manual ON" : "Manual OFF"));
+        }
+    }
+
+    /**
+     * Actually enable / disable battery saver. Write the new state to the global settings
+     * and propagate it to {@link #mBatterySaverController}.
+     */
+    private void enableBatterySaverLocked(boolean enable, boolean manual, String reason) {
+        if (DEBUG) {
+            Slog.d(TAG, "enableBatterySaver: enable=" + enable + " manual=" + manual
+                    + " reason=" + reason);
+        }
+        final boolean wasEnabled = mBatterySaverController.isEnabled();
+
+        if (wasEnabled == enable) {
+            if (DEBUG) {
+                Slog.d(TAG, "Already " + (enable ? "enabled" : "disabled"));
+            }
+            return;
+        }
+        if (enable && mIsPowered) {
+            if (DEBUG) Slog.d(TAG, "Can't enable: isPowered");
+            return;
+        }
+
+        if (manual) {
+            if (enable) {
+                updateSnoozingLocked(false, "Manual snooze OFF");
+            } else {
+                // When battery saver is disabled manually (while battery saver is enabled)
+                // when the battery level is low, we "snooze" BS -- i.e. disable auto battery saver.
+                // We resume auto-BS once the battery level is not low, or the device is plugged in.
+                if (isBatterySaverEnabled() && mIsBatteryLevelLow) {
+                    updateSnoozingLocked(true, "Manual snooze");
+                }
+            }
+        }
+
+        mSettingBatterySaverEnabled = enable;
+        putGlobalSetting(Global.LOW_POWER_MODE, enable ? 1 : 0);
+
+        if (manual) {
+            mSettingBatterySaverEnabledSticky = enable;
+            putGlobalSetting(Global.LOW_POWER_MODE_STICKY, enable ? 1 : 0);
+        }
+        mBatterySaverController.enableBatterySaver(enable);
+
+        if (DEBUG) {
+            Slog.d(TAG, "Battery saver: Enabled=" + enable
+                    + " manual=" + manual
+                    + " reason=" + reason);
+        }
+    }
+
+    private void updateSnoozingLocked(boolean snoozing, String reason) {
+        if (mBatterySaverSnoozing == snoozing) {
+            return;
+        }
+        if (DEBUG) Slog.d(TAG, "Snooze: " + (snoozing ? "start" : "stop")  + " reason=" + reason);
+        mBatterySaverSnoozing = snoozing;
+    }
+
+    @VisibleForTesting
+    protected void putGlobalSetting(String key, int value) {
+        Global.putInt(mContext.getContentResolver(), key, value);
+    }
+
+    @VisibleForTesting
+    protected int getGlobalSetting(String key, int defValue) {
+        return Global.getInt(mContext.getContentResolver(), key, defValue);
+    }
+
+    public void dump(PrintWriter pw) {
+        synchronized (mLock) {
+            pw.println();
+            pw.println("Battery saver state machine:");
+
+            pw.print("  Enabled=");
+            pw.println(mBatterySaverController.isEnabled());
+
+            pw.print("  mBootCompleted=");
+            pw.println(mBootCompleted);
+            pw.print("  mSettingsLoaded=");
+            pw.println(mSettingsLoaded);
+            pw.print("  mBatteryStatusSet=");
+            pw.println(mBatteryStatusSet);
+
+            pw.print("  mBatterySaverSnoozing=");
+            pw.println(mBatterySaverSnoozing);
+
+            pw.print("  mIsPowered=");
+            pw.println(mIsPowered);
+            pw.print("  mBatteryLevel=");
+            pw.println(mBatteryLevel);
+            pw.print("  mIsBatteryLevelLow=");
+            pw.println(mIsBatteryLevelLow);
+
+            pw.print("  mSettingBatterySaverEnabled=");
+            pw.println(mSettingBatterySaverEnabled);
+            pw.print("  mSettingBatterySaverEnabledSticky=");
+            pw.println(mSettingBatterySaverEnabledSticky);
+            pw.print("  mSettingBatterySaverTriggerThreshold=");
+            pw.println(mSettingBatterySaverTriggerThreshold);
+        }
+    }
+
+    public void dumpProto(ProtoOutputStream proto, long tag) {
+        synchronized (mLock) {
+            final long token = proto.start(tag);
+
+            proto.write(BatterySaverStateMachineProto.ENABLED,
+                    mBatterySaverController.isEnabled());
+
+            proto.write(BatterySaverStateMachineProto.BOOT_COMPLETED, mBootCompleted);
+            proto.write(BatterySaverStateMachineProto.SETTINGS_LOADED, mSettingsLoaded);
+            proto.write(BatterySaverStateMachineProto.BATTERY_STATUS_SET, mBatteryStatusSet);
+
+            proto.write(BatterySaverStateMachineProto.BATTERY_SAVER_SNOOZING,
+                    mBatterySaverSnoozing);
+
+            proto.write(BatterySaverStateMachineProto.IS_POWERED, mIsPowered);
+            proto.write(BatterySaverStateMachineProto.BATTERY_LEVEL, mBatteryLevel);
+            proto.write(BatterySaverStateMachineProto.IS_BATTERY_LEVEL_LOW, mIsBatteryLevelLow);
+
+            proto.write(BatterySaverStateMachineProto.SETTING_BATTERY_SAVER_ENABLED,
+                    mSettingBatterySaverEnabled);
+            proto.write(BatterySaverStateMachineProto.SETTING_BATTERY_SAVER_ENABLED_STICKY,
+                    mSettingBatterySaverEnabledSticky);
+            proto.write(BatterySaverStateMachineProto.SETTING_BATTERY_SAVER_TRIGGER_THRESHOLD,
+                    mSettingBatterySaverTriggerThreshold);
+
+            proto.end(token);
+        }
+    }
+}
diff --git a/services/core/java/com/android/server/stats/StatsCompanionService.java b/services/core/java/com/android/server/stats/StatsCompanionService.java
index 74c5ee9..b3d28fc 100644
--- a/services/core/java/com/android/server/stats/StatsCompanionService.java
+++ b/services/core/java/com/android/server/stats/StatsCompanionService.java
@@ -972,10 +972,13 @@
     public void triggerUidSnapshot() {
         enforceCallingPermission();
         synchronized (sStatsdLock) {
+            final long token = Binder.clearCallingIdentity();
             try {
                 informAllUidsLocked(mContext);
             } catch (RemoteException e) {
                 Slog.e(TAG, "Failed to trigger uid snapshot.", e);
+            } finally {
+                restoreCallingIdentity(token);
             }
         }
     }
diff --git a/services/core/jni/Android.bp b/services/core/jni/Android.bp
index 427b9d2..89efe12 100644
--- a/services/core/jni/Android.bp
+++ b/services/core/jni/Android.bp
@@ -86,6 +86,7 @@
         "libhardware_legacy",
         "libhidlbase",
         "libkeystore_binder",
+        "libmtp",
         "libnativehelper",
         "libutils",
         "libui",
diff --git a/services/core/jni/com_android_server_UsbDeviceManager.cpp b/services/core/jni/com_android_server_UsbDeviceManager.cpp
index f37f870..ff1ec04 100644
--- a/services/core/jni/com_android_server_UsbDeviceManager.cpp
+++ b/services/core/jni/com_android_server_UsbDeviceManager.cpp
@@ -21,6 +21,7 @@
 #include <nativehelper/JNIHelp.h>
 #include "android_runtime/AndroidRuntime.h"
 #include "android_runtime/Log.h"
+#include "MtpDescriptors.h"
 
 #include <stdio.h>
 #include <asm/byteorder.h>
@@ -118,6 +119,38 @@
     return result;
 }
 
+static jobject android_server_UsbDeviceManager_openControl(JNIEnv *env, jobject /* thiz */, jstring jFunction) {
+    const char *function = env->GetStringUTFChars(jFunction, NULL);
+    bool ptp = false;
+    int fd = -1;
+    if (!strcmp(function, "ptp")) {
+        ptp = true;
+    }
+    if (!strcmp(function, "mtp") || ptp) {
+        fd = TEMP_FAILURE_RETRY(open(ptp ? FFS_PTP_EP0 : FFS_MTP_EP0, O_RDWR));
+        if (fd < 0) {
+            ALOGE("could not open control for %s %s", function, strerror(errno));
+            goto error;
+        }
+        if (!writeDescriptors(fd, ptp)) {
+            goto error;
+        }
+    }
+
+    if (function != NULL) {
+        env->ReleaseStringUTFChars(jFunction, function);
+    }
+    return jniCreateFileDescriptor(env, fd);
+error:
+    if (fd != -1) {
+        close(fd);
+    }
+    if (function != NULL) {
+        env->ReleaseStringUTFChars(jFunction, function);
+    }
+    return NULL;
+}
+
 static const JNINativeMethod method_table[] = {
     { "nativeGetAccessoryStrings",  "()[Ljava/lang/String;",
                                     (void*)android_server_UsbDeviceManager_getAccessoryStrings },
@@ -127,6 +160,8 @@
                                     (void*)android_server_UsbDeviceManager_isStartRequested },
     { "nativeGetAudioMode",         "()I",
                                     (void*)android_server_UsbDeviceManager_getAudioMode },
+    { "nativeOpenControl",          "(Ljava/lang/String;)Ljava/io/FileDescriptor;",
+                                    (void*)android_server_UsbDeviceManager_openControl },
 };
 
 int register_android_server_UsbDeviceManager(JNIEnv *env)
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 2e07703..56c9807 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -7833,8 +7833,7 @@
             ApplicationInfo appInfo = userContext.getApplicationInfo();
             CharSequence result = null;
             if (appInfo != null) {
-                PackageManager pm = userContext.getPackageManager();
-                result = pm.getApplicationLabel(appInfo);
+                result = appInfo.loadUnsafeLabel(userContext.getPackageManager());
             }
             return result != null ? result.toString() : null;
         } finally {
diff --git a/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java b/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java
index 376f5b1..7765387 100644
--- a/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/RecentTasksTest.java
@@ -42,11 +42,13 @@
 import android.app.ActivityManager;
 import android.app.ActivityManager.RecentTaskInfo;
 import android.app.ActivityManager.RunningTaskInfo;
+import android.app.WindowConfiguration;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.pm.ParceledListSlice;
 import android.content.pm.UserInfo;
+import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.os.Bundle;
 import android.os.Debug;
@@ -101,8 +103,8 @@
     private TestRecentTasks mRecentTasks;
     private TestRunningTasks mRunningTasks;
 
-    private static ArrayList<TaskRecord> mTasks = new ArrayList<>();
-    private static ArrayList<TaskRecord> mSameDocumentTasks = new ArrayList<>();
+    private ArrayList<TaskRecord> mTasks;
+    private ArrayList<TaskRecord> mSameDocumentTasks;
 
     private CallbacksRecorder mCallbacksRecorder;
 
@@ -155,12 +157,14 @@
         mRecentTasks.registerCallback(mCallbacksRecorder);
         QUIET_USER_INFO.flags = UserInfo.FLAG_MANAGED_PROFILE | UserInfo.FLAG_QUIET_MODE;
 
+        mTasks = new ArrayList<>();
         mTasks.add(createTaskBuilder(".Task1").build());
         mTasks.add(createTaskBuilder(".Task2").build());
         mTasks.add(createTaskBuilder(".Task3").build());
         mTasks.add(createTaskBuilder(".Task4").build());
         mTasks.add(createTaskBuilder(".Task5").build());
 
+        mSameDocumentTasks = new ArrayList<>();
         mSameDocumentTasks.add(createDocumentTask(".DocumentTask1"));
         mSameDocumentTasks.add(createDocumentTask(".DocumentTask1"));
     }
@@ -294,7 +298,32 @@
         assertTrue(mCallbacksRecorder.added.contains(task2));
         assertTrue(mCallbacksRecorder.trimmed.isEmpty());
         assertTrue(mCallbacksRecorder.removed.isEmpty());
+    }
 
+    @Test
+    public void testAddTaskCompatibleActivityType_expectRemove() throws Exception {
+        Configuration config1 = new Configuration();
+        config1.windowConfiguration.setActivityType(ACTIVITY_TYPE_UNDEFINED);
+        TaskRecord task1 = createTaskBuilder(".Task1")
+                .setFlags(FLAG_ACTIVITY_NEW_TASK)
+                .setStack(mStack)
+                .build();
+        task1.onConfigurationChanged(config1);
+        assertTrue(task1.getActivityType() == ACTIVITY_TYPE_UNDEFINED);
+        mRecentTasks.add(task1);
+        mCallbacksRecorder.clear();
+
+        TaskRecord task2 = createTaskBuilder(".Task1")
+                .setFlags(FLAG_ACTIVITY_NEW_TASK)
+                .setStack(mStack)
+                .build();
+        assertTrue(task2.getActivityType() == ACTIVITY_TYPE_STANDARD);
+        mRecentTasks.add(task2);
+        assertTrue(mCallbacksRecorder.added.size() == 1);
+        assertTrue(mCallbacksRecorder.added.contains(task2));
+        assertTrue(mCallbacksRecorder.trimmed.isEmpty());
+        assertTrue(mCallbacksRecorder.removed.size() == 1);
+        assertTrue(mCallbacksRecorder.removed.contains(task1));
     }
 
     @Test
diff --git a/services/tests/servicestests/src/com/android/server/am/TaskPersisterTest.java b/services/tests/servicestests/src/com/android/server/am/TaskPersisterTest.java
index ea207f1..9e6055d 100644
--- a/services/tests/servicestests/src/com/android/server/am/TaskPersisterTest.java
+++ b/services/tests/servicestests/src/com/android/server/am/TaskPersisterTest.java
@@ -29,6 +29,9 @@
 import java.io.File;
 import java.util.Random;
 
+/**
+ * atest FrameworksServicesTests:TaskPersisterTest
+ */
 public class TaskPersisterTest extends AndroidTestCase {
     private static final String TEST_USER_NAME = "AM-Test-User";
 
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManagerTest.java b/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManagerTest.java
index fc2da39..b7ce59d 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/RecoverableKeyStoreManagerTest.java
@@ -144,6 +144,13 @@
     private static final String ANDROID_KEY_STORE_PROVIDER = "AndroidKeyStore";
     private static final String WRAPPING_KEY_ALIAS = "RecoverableKeyStoreManagerTest/WrappingKey";
     private static final String TEST_ROOT_CERT_ALIAS = "";
+    private static final KeyChainProtectionParams TEST_PROTECTION_PARAMS =
+    new KeyChainProtectionParams.Builder()
+            .setUserSecretType(TYPE_LOCKSCREEN)
+            .setLockScreenUiFormat(UI_FORMAT_PASSWORD)
+            .setKeyDerivationParams(KeyDerivationParams.createSha256Params(TEST_SALT))
+            .setSecret(TEST_SECRET)
+            .build();
 
     @Mock private Context mMockContext;
     @Mock private RecoverySnapshotListenersStorage mMockListenersStorage;
@@ -459,12 +466,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(
-                        new KeyChainProtectionParams(
-                                TYPE_LOCKSCREEN,
-                                UI_FORMAT_PASSWORD,
-                                KeyDerivationParams.createSha256Params(TEST_SALT),
-                                TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
 
         verify(mMockContext, times(1))
                 .enforceCallingOrSelfPermission(
@@ -481,12 +483,7 @@
                 RecoveryCertPath.createRecoveryCertPath(TestData.CERT_PATH_1),
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(
-                        new KeyChainProtectionParams(
-                                TYPE_LOCKSCREEN,
-                                UI_FORMAT_PASSWORD,
-                                KeyDerivationParams.createSha256Params(TEST_SALT),
-                                TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
 
         assertEquals(1, mRecoverySessionStorage.size());
         RecoverySessionStorage.Entry entry =
@@ -503,12 +500,7 @@
                 RecoveryCertPath.createRecoveryCertPath(TestData.CERT_PATH_1),
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(
-                        new KeyChainProtectionParams(
-                                TYPE_LOCKSCREEN,
-                                UI_FORMAT_PASSWORD,
-                                KeyDerivationParams.createSha256Params(TEST_SALT),
-                                TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
 
         verify(mMockContext, times(2))
                 .enforceCallingOrSelfPermission(
@@ -522,12 +514,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(
-                        new KeyChainProtectionParams(
-                                TYPE_LOCKSCREEN,
-                                UI_FORMAT_PASSWORD,
-                                KeyDerivationParams.createSha256Params(TEST_SALT),
-                                TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
 
         assertEquals(1, mRecoverySessionStorage.size());
         RecoverySessionStorage.Entry entry =
@@ -543,12 +530,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(
-                        new KeyChainProtectionParams(
-                                TYPE_LOCKSCREEN,
-                                UI_FORMAT_PASSWORD,
-                                KeyDerivationParams.createSha256Params(TEST_SALT),
-                                TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
 
         mRecoverableKeyStoreManager.closeSession(TEST_SESSION_ID);
 
@@ -562,12 +544,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(
-                        new KeyChainProtectionParams(
-                                TYPE_LOCKSCREEN,
-                                UI_FORMAT_PASSWORD,
-                                KeyDerivationParams.createSha256Params(TEST_SALT),
-                                TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
 
         mRecoverableKeyStoreManager.closeSession("some random session");
 
@@ -604,18 +581,14 @@
     public void startRecoverySession_throwsIfPublicKeysMismatch() throws Exception {
         byte[] vaultParams = TEST_VAULT_PARAMS.clone();
         vaultParams[1] ^= (byte) 1;  // Flip 1 bit
+
         try {
             mRecoverableKeyStoreManager.startRecoverySession(
                     TEST_SESSION_ID,
                     TEST_PUBLIC_KEY,
                     vaultParams,
                     TEST_VAULT_CHALLENGE,
-                    ImmutableList.of(
-                            new KeyChainProtectionParams(
-                                    TYPE_LOCKSCREEN,
-                                    UI_FORMAT_PASSWORD,
-                                    KeyDerivationParams.createSha256Params(TEST_SALT),
-                                    TEST_SECRET)));
+                    ImmutableList.of(TEST_PROTECTION_PARAMS));
             fail("should have thrown");
         } catch (ServiceSpecificException e) {
             assertThat(e.getMessage()).contains("do not match");
@@ -650,12 +623,7 @@
                     RecoveryCertPath.createRecoveryCertPath(TestData.CERT_PATH_1),
                     vaultParams,
                     TEST_VAULT_CHALLENGE,
-                    ImmutableList.of(
-                            new KeyChainProtectionParams(
-                                    TYPE_LOCKSCREEN,
-                                    UI_FORMAT_PASSWORD,
-                                    KeyDerivationParams.createSha256Params(TEST_SALT),
-                                    TEST_SECRET)));
+                    ImmutableList.of(TEST_PROTECTION_PARAMS));
             fail("should have thrown");
         } catch (ServiceSpecificException e) {
             assertThat(e.getMessage()).contains("do not match");
@@ -673,12 +641,7 @@
                     RecoveryCertPath.createRecoveryCertPath(emptyCertPath),
                     TEST_VAULT_PARAMS,
                     TEST_VAULT_CHALLENGE,
-                    ImmutableList.of(
-                            new KeyChainProtectionParams(
-                                    TYPE_LOCKSCREEN,
-                                    UI_FORMAT_PASSWORD,
-                                    KeyDerivationParams.createSha256Params(TEST_SALT),
-                                    TEST_SECRET)));
+                    ImmutableList.of(TEST_PROTECTION_PARAMS));
             fail("should have thrown");
         } catch (ServiceSpecificException e) {
             assertThat(e.getMessage()).contains("empty");
@@ -698,12 +661,7 @@
                     RecoveryCertPath.createRecoveryCertPath(shortCertPath),
                     TEST_VAULT_PARAMS,
                     TEST_VAULT_CHALLENGE,
-                    ImmutableList.of(
-                            new KeyChainProtectionParams(
-                                    TYPE_LOCKSCREEN,
-                                    UI_FORMAT_PASSWORD,
-                                    KeyDerivationParams.createSha256Params(TEST_SALT),
-                                    TEST_SECRET)));
+                    ImmutableList.of(TEST_PROTECTION_PARAMS));
             fail("should have thrown");
         } catch (ServiceSpecificException e) {
             // expected
@@ -734,11 +692,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(new KeyChainProtectionParams(
-                        TYPE_LOCKSCREEN,
-                        UI_FORMAT_PASSWORD,
-                        KeyDerivationParams.createSha256Params(TEST_SALT),
-                        TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
 
         try {
             mRecoverableKeyStoreManager.recoverKeyChainSnapshot(
@@ -758,11 +712,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(new KeyChainProtectionParams(
-                        TYPE_LOCKSCREEN,
-                        UI_FORMAT_PASSWORD,
-                        KeyDerivationParams.createSha256Params(TEST_SALT),
-                        TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
         byte[] keyClaimant = mRecoverySessionStorage.get(Binder.getCallingUid(), TEST_SESSION_ID)
                 .getKeyClaimant();
         SecretKey recoveryKey = randomRecoveryKey();
@@ -792,11 +742,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(new KeyChainProtectionParams(
-                        TYPE_LOCKSCREEN,
-                        UI_FORMAT_PASSWORD,
-                        KeyDerivationParams.createSha256Params(TEST_SALT),
-                        TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
         byte[] keyClaimant = mRecoverySessionStorage.get(Binder.getCallingUid(), TEST_SESSION_ID)
                 .getKeyClaimant();
         SecretKey recoveryKey = randomRecoveryKey();
@@ -816,11 +762,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(new KeyChainProtectionParams(
-                        TYPE_LOCKSCREEN,
-                        UI_FORMAT_PASSWORD,
-                        KeyDerivationParams.createSha256Params(TEST_SALT),
-                        TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
         byte[] keyClaimant = mRecoverySessionStorage.get(Binder.getCallingUid(), TEST_SESSION_ID)
                 .getKeyClaimant();
         SecretKey recoveryKey = randomRecoveryKey();
@@ -850,11 +792,7 @@
                 TEST_PUBLIC_KEY,
                 TEST_VAULT_PARAMS,
                 TEST_VAULT_CHALLENGE,
-                ImmutableList.of(new KeyChainProtectionParams(
-                        TYPE_LOCKSCREEN,
-                        UI_FORMAT_PASSWORD,
-                        KeyDerivationParams.createSha256Params(TEST_SALT),
-                        TEST_SECRET)));
+                ImmutableList.of(TEST_PROTECTION_PARAMS));
         byte[] keyClaimant = mRecoverySessionStorage.get(Binder.getCallingUid(), TEST_SESSION_ID)
                 .getKeyClaimant();
         SecretKey recoveryKey = randomRecoveryKey();
@@ -896,6 +834,51 @@
     }
 
     @Test
+    public void setServerParams_updatesServerParams() throws Exception {
+        int uid = Binder.getCallingUid();
+        int userId = UserHandle.getCallingUserId();
+        byte[] serverParams = new byte[] { 1 };
+
+        mRecoverableKeyStoreManager.setServerParams(serverParams);
+
+        assertThat(mRecoverableKeyStoreDb.getServerParams(userId, uid)).isEqualTo(serverParams);
+    }
+
+    @Test
+    public void setServerParams_doesNotSetSnapshotPendingIfInitializing() throws Exception {
+        int uid = Binder.getCallingUid();
+        int userId = UserHandle.getCallingUserId();
+        byte[] serverParams = new byte[] { 1 };
+
+        mRecoverableKeyStoreManager.setServerParams(serverParams);
+
+        assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isFalse();
+    }
+
+    @Test
+    public void setServerParams_doesNotSetSnapshotPendingIfSettingSameValue() throws Exception {
+        int uid = Binder.getCallingUid();
+        int userId = UserHandle.getCallingUserId();
+        byte[] serverParams = new byte[] { 1 };
+
+        mRecoverableKeyStoreManager.setServerParams(serverParams);
+        mRecoverableKeyStoreManager.setServerParams(serverParams);
+
+        assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isFalse();
+    }
+
+    @Test
+    public void setServerParams_setsSnapshotPendingIfUpdatingValue() throws Exception {
+        int uid = Binder.getCallingUid();
+        int userId = UserHandle.getCallingUserId();
+
+        mRecoverableKeyStoreManager.setServerParams(new byte[] { 1 });
+        mRecoverableKeyStoreManager.setServerParams(new byte[] { 2 });
+
+        assertThat(mRecoverableKeyStoreDb.getShouldCreateSnapshot(userId, uid)).isTrue();
+    }
+
+    @Test
     public void setRecoverySecretTypes() throws Exception {
         int[] types1 = new int[]{11, 2000};
         int[] types2 = new int[]{1, 2, 3};
diff --git a/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/storage/RecoverySnapshotStorageTest.java b/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/storage/RecoverySnapshotStorageTest.java
index d61a294..ead817a 100644
--- a/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/storage/RecoverySnapshotStorageTest.java
+++ b/services/tests/servicestests/src/com/android/server/locksettings/recoverablekeystore/storage/RecoverySnapshotStorageTest.java
@@ -15,6 +15,15 @@
 @SmallTest
 @RunWith(AndroidJUnit4.class)
 public class RecoverySnapshotStorageTest {
+    private static final KeyChainSnapshot MINIMAL_KEYCHAIN_SNAPSHOT = new KeyChainSnapshot.Builder()
+            .setCounterId(1)
+            .setSnapshotVersion(1)
+            .setServerParams(new byte[0])
+            .setMaxAttempts(10)
+            .setEncryptedRecoveryKeyBlob(new byte[0])
+            .setKeyChainProtectionParams(new ArrayList<>())
+            .setWrappedApplicationKeys(new ArrayList<>())
+            .build();
 
     private final RecoverySnapshotStorage mRecoverySnapshotStorage = new RecoverySnapshotStorage();
 
@@ -26,26 +35,17 @@
     @Test
     public void get_returnsSetSnapshot() {
         int userId = 1000;
-        KeyChainSnapshot keyChainSnapshot = new KeyChainSnapshot(
-                /*snapshotVersion=*/ 1,
-                new ArrayList<>(),
-                new ArrayList<>(),
-                new byte[0]);
-        mRecoverySnapshotStorage.put(userId, keyChainSnapshot);
 
-        assertEquals(keyChainSnapshot, mRecoverySnapshotStorage.get(userId));
+        mRecoverySnapshotStorage.put(userId, MINIMAL_KEYCHAIN_SNAPSHOT);
+
+        assertEquals(MINIMAL_KEYCHAIN_SNAPSHOT, mRecoverySnapshotStorage.get(userId));
     }
 
     @Test
     public void remove_removesSnapshots() {
         int userId = 1000;
-        KeyChainSnapshot keyChainSnapshot = new KeyChainSnapshot(
-                /*snapshotVersion=*/ 1,
-                new ArrayList<>(),
-                new ArrayList<>(),
-                new byte[0]);
-        mRecoverySnapshotStorage.put(userId, keyChainSnapshot);
 
+        mRecoverySnapshotStorage.put(userId, MINIMAL_KEYCHAIN_SNAPSHOT);
         mRecoverySnapshotStorage.remove(userId);
 
         assertNull(mRecoverySnapshotStorage.get(1000));
diff --git a/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverStateMachineTest.java b/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverStateMachineTest.java
new file mode 100644
index 0000000..ab640d6
--- /dev/null
+++ b/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverStateMachineTest.java
@@ -0,0 +1,532 @@
+/*
+ * Copyright (C) 2018 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.power.batterysaver;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.Mockito.doAnswer;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import android.content.ContentResolver;
+import android.provider.Settings.Global;
+import android.support.test.filters.SmallTest;
+import android.support.test.runner.AndroidJUnit4;
+import android.test.mock.MockContext;
+
+import com.google.common.base.Objects;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.HashMap;
+
+/**
+ atest $ANDROID_BUILD_TOP/frameworks/base/services/tests/servicestests/src/com/android/server/power/batterysaver/BatterySaverStateMachineTest.java
+ */
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class BatterySaverStateMachineTest {
+
+    private MyMockContext mMockContext;
+    private ContentResolver mMockContextResolver;
+    private BatterySaverController mMockBatterySaverController;
+    private Device mDevice;
+    private TestableBatterySaverStateMachine mTarget;
+
+    private class MyMockContext extends MockContext {
+        @Override
+        public ContentResolver getContentResolver() {
+            return mMockContextResolver;
+        }
+    }
+
+    private DevicePersistedState mPersistedState;
+
+    private class DevicePersistedState {
+        // Current battery level.
+        public int batteryLevel = 100;
+
+        // Whether battery level is currently low or not.
+        public boolean batteryLow = false;
+
+        // Whether the device is plugged in or not.
+        public boolean powered = false;
+
+        // Global settings.
+        public final HashMap<String, Integer> global = new HashMap<>();
+    }
+
+    /**
+     * This class simulates a device's volatile status that will be reset by {@link #initDevice()}.
+     */
+    private class Device {
+        public boolean batterySaverEnabled = false;
+
+        public int getLowPowerModeTriggerLevel() {
+            return mPersistedState.global.getOrDefault(Global.LOW_POWER_MODE_TRIGGER_LEVEL, 0);
+        }
+
+        public void setBatteryLevel(int level) {
+            mPersistedState.batteryLevel = level;
+            if (mPersistedState.batteryLevel <= Math.max(15, getLowPowerModeTriggerLevel())) {
+                mPersistedState.batteryLow = true;
+            } else if (mPersistedState.batteryLow
+                    && (mPersistedState.batteryLevel >= (getLowPowerModeTriggerLevel() + 5))) {
+                mPersistedState.batteryLow = false;
+            }
+            pushBatteryStatus();
+        }
+
+        public void setPowered(boolean newPowered) {
+            mPersistedState.powered = newPowered;
+            pushBatteryStatus();
+        }
+
+        public void pushBatteryStatus() {
+            mTarget.setBatteryStatus(mPersistedState.powered, mPersistedState.batteryLevel,
+                    mPersistedState.batteryLow);
+        }
+
+        public void pushGlobalSettings() {
+            mTarget.setSettingsLocked(
+                    mPersistedState.global.getOrDefault(Global.LOW_POWER_MODE, 0) != 0,
+                    mPersistedState.global.getOrDefault(Global.LOW_POWER_MODE_STICKY, 0) != 0,
+                    mDevice.getLowPowerModeTriggerLevel());
+        }
+
+        public void putGlobalSetting(String key, int value) {
+            mPersistedState.global.put(key, value);
+            pushGlobalSettings();
+        }
+
+        public int getGlobalSetting(String key, int defValue) {
+            return mPersistedState.global.getOrDefault(key, defValue);
+        }
+    }
+
+    /**
+     * Test target class.
+     */
+    private class TestableBatterySaverStateMachine extends BatterySaverStateMachine {
+        public TestableBatterySaverStateMachine() {
+            super(mMockContext, mMockBatterySaverController);
+        }
+
+        @Override
+        protected void putGlobalSetting(String key, int value) {
+            if (Objects.equal(mPersistedState.global.get(key), value)) {
+                return;
+            }
+            mDevice.putGlobalSetting(key, value);
+        }
+
+        @Override
+        protected int getGlobalSetting(String key, int defValue) {
+            return mDevice.getGlobalSetting(key, defValue);
+        }
+    }
+
+    @Before
+    public void setUp() {
+        mMockContext = new MyMockContext();
+        mMockContextResolver = mock(ContentResolver.class);
+        mMockBatterySaverController = mock(BatterySaverController.class);
+
+        doAnswer((inv) -> mDevice.batterySaverEnabled = inv.getArgument(0))
+                .when(mMockBatterySaverController).enableBatterySaver(anyBoolean());
+        when(mMockBatterySaverController.isEnabled())
+                .thenAnswer((inv) -> mDevice.batterySaverEnabled);
+
+        mPersistedState = new DevicePersistedState();
+        initDevice();
+    }
+
+    private void initDevice() {
+        mDevice = new Device();
+
+        mTarget = new TestableBatterySaverStateMachine();
+
+        mDevice.pushBatteryStatus();
+        mDevice.pushGlobalSettings();
+        mTarget.onBootCompleted();
+    }
+
+    @Test
+    public void testNoAutoBatterySaver() {
+        assertEquals(0, mDevice.getLowPowerModeTriggerLevel());
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(100, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(90);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(50);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(50, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(16);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(16, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // When LOW_POWER_MODE_TRIGGER_LEVEL is 0, 15% will still trigger low-battery, but
+        // BS wont be enabled.
+        mDevice.setBatteryLevel(15);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(15, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(10);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(10, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        // Manually enable BS.
+        mTarget.setBatterySaverEnabledManually(true);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(10, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(50);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(50, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Start charging. It'll disable BS.
+        mDevice.setPowered(true);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(50, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(60);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(60, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Unplug.
+        mDevice.setPowered(false);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(60, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(10);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(10, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(80);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(80, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Reboot the device.
+        initDevice();
+
+        assertEquals(true, mDevice.batterySaverEnabled); // Sticky.
+        assertEquals(80, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(30);
+        initDevice();
+
+        assertEquals(true, mDevice.batterySaverEnabled); // Still sticky.
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mTarget.setBatterySaverEnabledManually(false);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        initDevice(); // reboot.
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+    }
+
+    @Test
+    public void testAutoBatterySaver() {
+        mDevice.putGlobalSetting(Global.LOW_POWER_MODE_TRIGGER_LEVEL, 50);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(100, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(90);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(51);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(51, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Hit the threshold. BS should be enabled.
+        mDevice.setBatteryLevel(50);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(50, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        // Battery goes up, but until it hits 55%, we still keep BS on.
+        mDevice.setBatteryLevel(54);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(54, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        // 50% + 5%, now BS will be off.
+        mDevice.setBatteryLevel(55);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(55, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(40);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(40, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setPowered(true);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(40, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setPowered(false);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(40, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mTarget.setBatterySaverEnabledManually(false); // Manually disable -> snooze.
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(40, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(30);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        // Plug in and out, snooze will reset.
+        mDevice.setPowered(true);
+        mDevice.setPowered(false);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setPowered(true);
+        mDevice.setBatteryLevel(60);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(60, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setPowered(false);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(60, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(50);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(50, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(70);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(70, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Bump ump the threshold.
+        mDevice.putGlobalSetting(Global.LOW_POWER_MODE_TRIGGER_LEVEL, 70);
+        mDevice.setBatteryLevel(mPersistedState.batteryLevel);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(70, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        // Then down.
+        mDevice.putGlobalSetting(Global.LOW_POWER_MODE_TRIGGER_LEVEL, 60);
+        mDevice.setBatteryLevel(mPersistedState.batteryLevel);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(70, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Reboot in low state -> automatically enable BS.
+        mDevice.setPowered(false);
+        mDevice.setBatteryLevel(30);
+        mTarget.setBatterySaverEnabledManually(false);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        initDevice();
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+    }
+
+    @Test
+    public void testAutoBatterySaver_withSticky() {
+        mDevice.putGlobalSetting(Global.LOW_POWER_MODE_TRIGGER_LEVEL, 50);
+
+        mTarget.setBatterySaverEnabledManually(true);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(100, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(30);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(80);
+
+        assertEquals(true, mDevice.batterySaverEnabled); // Still enabled.
+        assertEquals(80, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setPowered(true);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(80, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(30);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setPowered(false);
+
+        assertEquals(true, mDevice.batterySaverEnabled); // Restores BS.
+        assertEquals(30, mPersistedState.batteryLevel);
+        assertEquals(true, mPersistedState.batteryLow);
+
+        mDevice.setPowered(true);
+        mDevice.setBatteryLevel(90);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        initDevice();
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setPowered(false);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mTarget.setBatterySaverEnabledManually(false);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        initDevice();
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+    }
+
+    @Test
+    public void testNoAutoBatterySaver_fromAdb() {
+
+        assertEquals(0, mDevice.getLowPowerModeTriggerLevel());
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(100, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        mDevice.setBatteryLevel(90);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Enable
+        mDevice.putGlobalSetting(Global.LOW_POWER_MODE, 1);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Disable
+        mDevice.putGlobalSetting(Global.LOW_POWER_MODE, 0);
+
+        assertEquals(false, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Enable again
+        mDevice.putGlobalSetting(Global.LOW_POWER_MODE, 1);
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+
+        // Reboot -- setting BS from adb is also sticky.
+        initDevice();
+
+        assertEquals(true, mDevice.batterySaverEnabled);
+        assertEquals(90, mPersistedState.batteryLevel);
+        assertEquals(false, mPersistedState.batteryLow);
+    }
+}
diff --git a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
index 552c915..601999d 100644
--- a/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
+++ b/services/tests/servicestests/src/com/android/server/usage/AppStandbyControllerTests.java
@@ -19,6 +19,7 @@
 import static android.app.usage.UsageEvents.Event.NOTIFICATION_SEEN;
 import static android.app.usage.UsageEvents.Event.SLICE_PINNED;
 import static android.app.usage.UsageEvents.Event.SLICE_PINNED_PRIV;
+import static android.app.usage.UsageEvents.Event.SYSTEM_INTERACTION;
 import static android.app.usage.UsageEvents.Event.USER_INTERACTION;
 import static android.app.usage.UsageStatsManager.REASON_MAIN_DEFAULT;
 import static android.app.usage.UsageStatsManager.REASON_MAIN_FORCED;
@@ -569,6 +570,31 @@
     }
 
     @Test
+    public void testSystemInteractionTimeout() throws Exception {
+        setChargingState(mController, false);
+
+        reportEvent(mController, USER_INTERACTION, 0);
+        // Fast forward to RARE
+        mInjector.mElapsedRealtime = RARE_THRESHOLD + 100;
+        mController.checkIdleStates(USER_ID);
+        assertBucket(STANDBY_BUCKET_RARE);
+
+        // Trigger a SYSTEM_INTERACTION and verify bucket
+        reportEvent(mController, SYSTEM_INTERACTION, mInjector.mElapsedRealtime);
+        assertBucket(STANDBY_BUCKET_ACTIVE);
+
+        // Verify it's still in ACTIVE close to end of timeout
+        mInjector.mElapsedRealtime += mController.mSystemInteractionTimeoutMillis - 100;
+        mController.checkIdleStates(USER_ID);
+        assertBucket(STANDBY_BUCKET_ACTIVE);
+
+        // Verify bucket moves to RARE after timeout
+        mInjector.mElapsedRealtime += 200;
+        mController.checkIdleStates(USER_ID);
+        assertBucket(STANDBY_BUCKET_RARE);
+    }
+
+    @Test
     public void testPredictionNotOverridden() throws Exception {
         setChargingState(mController, false);
 
diff --git a/services/usage/java/com/android/server/usage/AppStandbyController.java b/services/usage/java/com/android/server/usage/AppStandbyController.java
index 1af5f46..9139a4c 100644
--- a/services/usage/java/com/android/server/usage/AppStandbyController.java
+++ b/services/usage/java/com/android/server/usage/AppStandbyController.java
@@ -198,6 +198,10 @@
     long mSystemUpdateUsageTimeoutMillis;
     /** Maximum time to wait for a prediction before using simple timeouts to downgrade buckets. */
     long mPredictionTimeoutMillis;
+    /** Maximum time a sync adapter associated with a CP should keep the buckets elevated. */
+    long mSyncAdapterTimeoutMillis;
+    /** Maximum time a system interaction should keep the buckets elevated. */
+    long mSystemInteractionTimeoutMillis;
 
     volatile boolean mAppIdleEnabled;
     boolean mAppIdleTempParoled;
@@ -357,8 +361,8 @@
                     synchronized (mAppIdleLock) {
                         AppUsageHistory appUsage = mAppIdleHistory.reportUsage(packageName, userId,
                                 STANDBY_BUCKET_ACTIVE, REASON_SUB_USAGE_SYNC_ADAPTER,
-                                elapsedRealtime,
-                                elapsedRealtime + mStrongUsageTimeoutMillis);
+                                0,
+                                elapsedRealtime + mSyncAdapterTimeoutMillis);
                         maybeInformListeners(packageName, userId, elapsedRealtime,
                                 appUsage.currentBucket, appUsage.bucketingReason, false);
                     }
@@ -708,7 +712,11 @@
                             STANDBY_BUCKET_WORKING_SET, subReason,
                             0, elapsedRealtime + mNotificationSeenTimeoutMillis);
                     nextCheckTime = mNotificationSeenTimeoutMillis;
-
+                } else if (event.mEventType == UsageEvents.Event.SYSTEM_INTERACTION) {
+                    mAppIdleHistory.reportUsage(appHistory, event.mPackage,
+                            STANDBY_BUCKET_ACTIVE, subReason,
+                            0, elapsedRealtime + mSystemInteractionTimeoutMillis);
+                    nextCheckTime = mSystemInteractionTimeoutMillis;
                 } else {
                     mAppIdleHistory.reportUsage(appHistory, event.mPackage,
                             STANDBY_BUCKET_ACTIVE, subReason,
@@ -1523,6 +1531,14 @@
         private static final String KEY_SYSTEM_UPDATE_HOLD_DURATION =
                 "system_update_usage_duration";
         private static final String KEY_PREDICTION_TIMEOUT = "prediction_timeout";
+        private static final String KEY_SYNC_ADAPTER_HOLD_DURATION = "sync_adapter_duration";
+        private static final String KEY_SYSTEM_INTERACTION_HOLD_DURATION =
+                "system_interaction_duration";
+        public static final long DEFAULT_STRONG_USAGE_TIMEOUT = 1 * ONE_HOUR;
+        public static final long DEFAULT_NOTIFICATION_TIMEOUT = 12 * ONE_HOUR;
+        public static final long DEFAULT_SYSTEM_UPDATE_TIMEOUT = 2 * ONE_HOUR;
+        public static final long DEFAULT_SYSTEM_INTERACTION_TIMEOUT = 10 * ONE_MINUTE;
+        public static final long DEFAULT_SYNC_ADAPTER_TIMEOUT = 10 * ONE_MINUTE;
 
         private final KeyValueListParser mParser = new KeyValueListParser(',');
 
@@ -1585,16 +1601,22 @@
                         COMPRESS_TIME ? ONE_MINUTE : 4 * 60 * ONE_MINUTE); // 4 hours
                 mStrongUsageTimeoutMillis = mParser.getDurationMillis
                         (KEY_STRONG_USAGE_HOLD_DURATION,
-                                COMPRESS_TIME ? ONE_MINUTE : 1 * ONE_HOUR);
+                                COMPRESS_TIME ? ONE_MINUTE : DEFAULT_STRONG_USAGE_TIMEOUT);
                 mNotificationSeenTimeoutMillis = mParser.getDurationMillis
                         (KEY_NOTIFICATION_SEEN_HOLD_DURATION,
-                                COMPRESS_TIME ? 12 * ONE_MINUTE : 12 * ONE_HOUR);
+                                COMPRESS_TIME ? 12 * ONE_MINUTE : DEFAULT_NOTIFICATION_TIMEOUT);
                 mSystemUpdateUsageTimeoutMillis = mParser.getDurationMillis
                         (KEY_SYSTEM_UPDATE_HOLD_DURATION,
-                                COMPRESS_TIME ? 2 * ONE_MINUTE : 2 * ONE_HOUR);
+                                COMPRESS_TIME ? 2 * ONE_MINUTE : DEFAULT_SYSTEM_UPDATE_TIMEOUT);
                 mPredictionTimeoutMillis = mParser.getDurationMillis
                         (KEY_PREDICTION_TIMEOUT,
                                 COMPRESS_TIME ? 10 * ONE_MINUTE : DEFAULT_PREDICTION_TIMEOUT);
+                mSyncAdapterTimeoutMillis = mParser.getDurationMillis
+                        (KEY_SYNC_ADAPTER_HOLD_DURATION,
+                                COMPRESS_TIME ? ONE_MINUTE : DEFAULT_SYNC_ADAPTER_TIMEOUT);
+                mSystemInteractionTimeoutMillis = mParser.getDurationMillis
+                        (KEY_SYSTEM_INTERACTION_HOLD_DURATION,
+                                COMPRESS_TIME ? ONE_MINUTE : DEFAULT_SYSTEM_INTERACTION_TIMEOUT);
             }
         }
 
diff --git a/services/usb/java/com/android/server/usb/UsbDeviceManager.java b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
index ef0780a..9f8042c 100644
--- a/services/usb/java/com/android/server/usb/UsbDeviceManager.java
+++ b/services/usb/java/com/android/server/usb/UsbDeviceManager.java
@@ -83,6 +83,7 @@
 import com.android.server.LocalServices;
 
 import java.io.File;
+import java.io.FileDescriptor;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.HashMap;
@@ -181,6 +182,7 @@
     private final UEventObserver mUEventObserver;
 
     private static Set<Integer> sBlackListedInterfaces;
+    private HashMap<Long, FileDescriptor> mControlFds;
 
     static {
         sBlackListedInterfaces = new HashSet<>();
@@ -270,6 +272,18 @@
             Slog.i(TAG, "USB GADGET HAL not present in the device", e);
         }
 
+        mControlFds = new HashMap<>();
+        FileDescriptor mtpFd = nativeOpenControl(UsbManager.USB_FUNCTION_MTP);
+        if (mtpFd == null) {
+            Slog.e(TAG, "Failed to open control for mtp");
+        }
+        mControlFds.put(UsbManager.FUNCTION_MTP, mtpFd);
+        FileDescriptor ptpFd = nativeOpenControl(UsbManager.USB_FUNCTION_PTP);
+        if (mtpFd == null) {
+            Slog.e(TAG, "Failed to open control for mtp");
+        }
+        mControlFds.put(UsbManager.FUNCTION_PTP, ptpFd);
+
         boolean secureAdbEnabled = SystemProperties.getBoolean("ro.adb.secure", false);
         boolean dataEncrypted = "1".equals(SystemProperties.get("vold.decrypt"));
         if (secureAdbEnabled && !dataEncrypted) {
@@ -704,8 +718,7 @@
             return false;
         }
 
-        protected void updateUsbStateBroadcastIfNeeded(long functions,
-                boolean configChanged) {
+        protected void updateUsbStateBroadcastIfNeeded(long functions) {
             // send a sticky broadcast containing current USB state
             Intent intent = new Intent(UsbManager.ACTION_USB_STATE);
             intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING
@@ -716,7 +729,6 @@
             intent.putExtra(UsbManager.USB_CONFIGURED, mConfigured);
             intent.putExtra(UsbManager.USB_DATA_UNLOCKED,
                     isUsbTransferAllowed() && isUsbDataTransferActive(mCurrentFunctions));
-            intent.putExtra(UsbManager.USB_CONFIG_CHANGED, configChanged);
 
             long remainingFunctions = functions;
             while (remainingFunctions != 0) {
@@ -726,7 +738,7 @@
             }
 
             // send broadcast intent only if the USB state has changed
-            if (!isUsbStateChanged(intent) && !configChanged) {
+            if (!isUsbStateChanged(intent)) {
                 if (DEBUG) {
                     Slog.d(TAG, "skip broadcasting " + intent + " extras: " + intent.getExtras());
                 }
@@ -798,8 +810,7 @@
                     updateUsbNotification(false);
                     updateAdbNotification(false);
                     if (mBootCompleted) {
-                        updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions),
-                                false);
+                        updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions));
                     }
                     if ((mCurrentFunctions & UsbManager.FUNCTION_ACCESSORY) != 0) {
                         updateCurrentAccessory();
@@ -812,7 +823,7 @@
                                     && mScreenUnlockedFunctions != UsbManager.FUNCTION_NONE) {
                                 setScreenUnlockedFunctions();
                             } else {
-                                setEnabledFunctions(UsbManager.FUNCTION_NONE, !mAdbEnabled);
+                                setEnabledFunctions(UsbManager.FUNCTION_NONE, false);
                             }
                         }
                         updateUsbFunctions();
@@ -847,8 +858,7 @@
                     updateUsbNotification(false);
                     if (mBootCompleted) {
                         if (mHostConnected || prevHostConnected) {
-                            updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions),
-                                    false);
+                            updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions));
                         }
                     } else {
                         mPendingBootBroadcast = true;
@@ -994,7 +1004,7 @@
         protected void finishBoot() {
             if (mBootCompleted && mCurrentUsbFunctionsReceived && mSystemReady) {
                 if (mPendingBootBroadcast) {
-                    updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions), false);
+                    updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions));
                     mPendingBootBroadcast = false;
                 }
                 if (!mScreenLocked
@@ -1597,7 +1607,7 @@
                     /**
                      * Start up dependent services.
                      */
-                    updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions), true);
+                    updateUsbStateBroadcastIfNeeded(getAppliedFunctions(mCurrentFunctions));
                 }
 
                 if (!waitForState(oemFunctions)) {
@@ -1943,7 +1953,7 @@
 
                 if (mBootCompleted && isUsbDataTransferActive(functions)) {
                     // Start up dependent services.
-                    updateUsbStateBroadcastIfNeeded(functions, true);
+                    updateUsbStateBroadcastIfNeeded(functions);
                 }
             }
         }
@@ -1979,6 +1989,22 @@
         return mHandler.getEnabledFunctions();
     }
 
+    /**
+     * Returns a dup of the control file descriptor for the given function.
+     */
+    public ParcelFileDescriptor getControlFd(long usbFunction) {
+        FileDescriptor fd = mControlFds.get(usbFunction);
+        if (fd == null) {
+            return null;
+        }
+        try {
+            return ParcelFileDescriptor.dup(fd);
+        } catch (IOException e) {
+            Slog.e(TAG, "Could not dup fd for " + usbFunction);
+            return null;
+        }
+    }
+
     public long getScreenUnlockedFunctions() {
         return mHandler.getScreenUnlockedFunctions();
     }
@@ -2063,6 +2089,8 @@
 
     private native ParcelFileDescriptor nativeOpenAccessory();
 
+    private native FileDescriptor nativeOpenControl(String usbFunction);
+
     private native boolean nativeIsStartRequested();
 
     private native int nativeGetAudioMode();
diff --git a/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java
index 0fcd075..67ad090 100644
--- a/services/usb/java/com/android/server/usb/UsbHostManager.java
+++ b/services/usb/java/com/android/server/usb/UsbHostManager.java
@@ -54,6 +54,7 @@
 public class UsbHostManager {
     private static final String TAG = UsbHostManager.class.getSimpleName();
     private static final boolean DEBUG = false;
+    private static final int LINUX_FOUNDATION_VID = 0x1d6b;
 
     private final Context mContext;
 
@@ -267,7 +268,6 @@
     }
 
     private boolean isBlackListed(String deviceAddress) {
-        Slog.i(TAG, "isBlackListed(" + deviceAddress + ")");
         int count = mHostBlacklist.length;
         for (int i = 0; i < count; i++) {
             if (deviceAddress.startsWith(mHostBlacklist[i])) {
@@ -279,7 +279,6 @@
 
     /* returns true if the USB device should not be accessible by applications */
     private boolean isBlackListed(int clazz, int subClass) {
-        Slog.i(TAG, "isBlackListed(" + clazz + ", " + subClass + ")");
         // blacklist hubs
         if (clazz == UsbConstants.USB_CLASS_HUB) return true;
 
@@ -302,6 +301,40 @@
         }
     }
 
+    private void logUsbDevice(UsbDescriptorParser descriptorParser) {
+        int vid = 0;
+        int pid = 0;
+        String mfg = "<unknown>";
+        String product = "<unknown>";
+        String version = "<unknown>";
+        String serial = "<unknown>";
+
+        UsbDeviceDescriptor deviceDescriptor = descriptorParser.getDeviceDescriptor();
+        if (deviceDescriptor != null) {
+            vid = deviceDescriptor.getVendorID();
+            pid = deviceDescriptor.getProductID();
+            mfg = deviceDescriptor.getMfgString(descriptorParser);
+            product = deviceDescriptor.getProductString(descriptorParser);
+            version = deviceDescriptor.getDeviceReleaseString();
+            serial = deviceDescriptor.getSerialString(descriptorParser);
+        }
+
+        if (vid == LINUX_FOUNDATION_VID) {
+            return;  // don't care about OS-constructed virtual USB devices.
+        }
+        boolean hasAudio = descriptorParser.hasAudioInterface();
+        boolean hasHid = descriptorParser.hasHIDInterface();
+        boolean hasStorage = descriptorParser.hasStorageInterface();
+
+        String attachedString = "USB device attached: ";
+        attachedString += String.format("vidpid %04x:%04x", vid, pid);
+        attachedString += String.format(" mfg/product/ver/serial %s/%s/%s/%s",
+                                        mfg, product, version, serial);
+        attachedString += String.format(" hasAudio/HID/Storage: %b/%b/%b",
+                                        hasAudio, hasHid, hasStorage);
+        Slog.d(TAG, attachedString);
+    }
+
     /* Called from JNI in monitorUsbHostBus() to report new USB devices
        Returns true if successful, i.e. the USB Audio device descriptors are
        correctly parsed and the unique device is added to the audio device list.
@@ -313,10 +346,18 @@
             Slog.d(TAG, "usbDeviceAdded(" + deviceAddress + ") - start");
         }
 
-        // check class/subclass first as it is more likely to be blacklisted
-        if (isBlackListed(deviceClass, deviceSubclass) || isBlackListed(deviceAddress)) {
+        if (isBlackListed(deviceAddress)) {
             if (DEBUG) {
-                Slog.d(TAG, "device is black listed");
+                Slog.d(TAG, "device address is black listed");
+            }
+            return false;
+        }
+        UsbDescriptorParser parser = new UsbDescriptorParser(deviceAddress, descriptors);
+        logUsbDevice(parser);
+
+        if (isBlackListed(deviceClass, deviceSubclass)) {
+            if (DEBUG) {
+                Slog.d(TAG, "device class is black listed");
             }
             return false;
         }
@@ -329,40 +370,31 @@
                 return false;
             }
 
-            UsbDescriptorParser parser = new UsbDescriptorParser(deviceAddress);
-            if (parser.parseDescriptors(descriptors)) {
-
-                UsbDevice newDevice = parser.toAndroidUsbDevice();
-                if (newDevice == null) {
-                    Slog.e(TAG, "Couldn't create UsbDevice object.");
-                    // Tracking
-                    addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT_BADDEVICE,
-                            parser.getRawDescriptors());
-                } else {
-                    mDevices.put(deviceAddress, newDevice);
-
-                    // It is fine to call this only for the current user as all broadcasts are
-                    // sent to all profiles of the user and the dialogs should only show once.
-                    ComponentName usbDeviceConnectionHandler = getUsbDeviceConnectionHandler();
-                    if (usbDeviceConnectionHandler == null) {
-                        getCurrentUserSettings().deviceAttached(newDevice);
-                    } else {
-                        getCurrentUserSettings().deviceAttachedForFixedHandler(newDevice,
-                                usbDeviceConnectionHandler);
-                    }
-
-                    mUsbAlsaManager.usbDeviceAdded(deviceAddress, newDevice, parser);
-
-                    // Tracking
-                    addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT,
-                            parser.getRawDescriptors());
-                }
-            } else {
-                Slog.e(TAG, "Error parsing USB device descriptors for " + deviceAddress);
+            UsbDevice newDevice = parser.toAndroidUsbDevice();
+            if (newDevice == null) {
+                Slog.e(TAG, "Couldn't create UsbDevice object.");
                 // Tracking
-                addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT_BADPARSE,
+                addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT_BADDEVICE,
                         parser.getRawDescriptors());
-                return false;
+            } else {
+                mDevices.put(deviceAddress, newDevice);
+                Slog.d(TAG, "Added device " + newDevice);
+
+                // It is fine to call this only for the current user as all broadcasts are
+                // sent to all profiles of the user and the dialogs should only show once.
+                ComponentName usbDeviceConnectionHandler = getUsbDeviceConnectionHandler();
+                if (usbDeviceConnectionHandler == null) {
+                    getCurrentUserSettings().deviceAttached(newDevice);
+                } else {
+                    getCurrentUserSettings().deviceAttachedForFixedHandler(newDevice,
+                            usbDeviceConnectionHandler);
+                }
+
+                mUsbAlsaManager.usbDeviceAdded(deviceAddress, newDevice, parser);
+
+                // Tracking
+                addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT,
+                        parser.getRawDescriptors());
             }
         }
 
@@ -376,18 +408,18 @@
     /* Called from JNI in monitorUsbHostBus to report USB device removal */
     @SuppressWarnings("unused")
     private void usbDeviceRemoved(String deviceAddress) {
-        if (DEBUG) {
-            Slog.d(TAG, "usbDeviceRemoved(" + deviceAddress + ") - start");
-        }
         synchronized (mLock) {
             UsbDevice device = mDevices.remove(deviceAddress);
             if (device != null) {
+                Slog.d(TAG, "Removed device at " + deviceAddress + ": " + device.getProductName());
                 mUsbAlsaManager.usbDeviceRemoved(deviceAddress/*device*/);
                 mSettingsManager.usbDeviceRemoved(device);
                 getCurrentUserSettings().usbDeviceRemoved(device);
 
                 // Tracking
                 addConnectionRecord(deviceAddress, ConnectionRecord.DISCONNECT, null);
+            } else {
+                Slog.d(TAG, "Removed device at " + deviceAddress + " was already gone");
             }
         }
     }
diff --git a/services/usb/java/com/android/server/usb/UsbService.java b/services/usb/java/com/android/server/usb/UsbService.java
index c1a7591..e92bd74 100644
--- a/services/usb/java/com/android/server/usb/UsbService.java
+++ b/services/usb/java/com/android/server/usb/UsbService.java
@@ -304,6 +304,13 @@
         return null;
     }
 
+    /* Returns a dup of the control file descriptor for the given function. */
+    @Override
+    public ParcelFileDescriptor getControlFd(long function) {
+        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_MTP, null);
+        return mDeviceManager.getControlFd(function);
+    }
+
     @Override
     public void setDevicePackage(UsbDevice device, String packageName, int userId) {
         device = Preconditions.checkNotNull(device);
diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java
index 956efc0..e615428 100644
--- a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java
+++ b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java
@@ -43,11 +43,6 @@
     // Obtained from the first AudioClass Header descriptor.
     private int mACInterfacesSpec = UsbDeviceDescriptor.USBSPEC_1_0;
 
-    public UsbDescriptorParser(String deviceAddr) {
-        mDeviceAddr = deviceAddr;
-        mDescriptors = new ArrayList<UsbDescriptor>(DESCRIPTORS_ALLOC_SIZE);
-    }
-
     /**
      * Connect this parser to an existing set of already parsed descriptors.
      * This is useful for reporting.
@@ -214,7 +209,7 @@
     /**
      * @hide
      */
-    public boolean parseDescriptors(byte[] descriptors) {
+    public void parseDescriptors(byte[] descriptors) {
         if (DEBUG) {
             Log.d(TAG, "parseDescriptors() - start");
         }
@@ -248,17 +243,6 @@
         if (DEBUG) {
             Log.d(TAG, "parseDescriptors() - end " + mDescriptors.size() + " descriptors.");
         }
-        return true;
-    }
-
-    /**
-     * @hide
-     */
-    public boolean parseDevice() {
-        byte[] rawDescriptors = getRawDescriptors();
-
-        return rawDescriptors != null
-            ? parseDescriptors(rawDescriptors) : false;
     }
 
     public byte[] getRawDescriptors() {
@@ -491,9 +475,18 @@
     }
 
     /**
+     *@ hide
+     */
+    public boolean hasAudioInterface() {
+        ArrayList<UsbDescriptor> descriptors =
+                getInterfaceDescriptorsForClass(UsbDescriptor.CLASSID_AUDIO);
+        return !descriptors.isEmpty();
+    }
+
+    /**
      * @hide
      */
-    public boolean hasHIDDescriptor() {
+    public boolean hasHIDInterface() {
         ArrayList<UsbDescriptor> descriptors =
                 getInterfaceDescriptorsForClass(UsbDescriptor.CLASSID_HID);
         return !descriptors.isEmpty();
@@ -502,6 +495,15 @@
     /**
      * @hide
      */
+    public boolean hasStorageInterface() {
+        ArrayList<UsbDescriptor> descriptors =
+                getInterfaceDescriptorsForClass(UsbDescriptor.CLASSID_STORAGE);
+        return !descriptors.isEmpty();
+    }
+
+    /**
+     * @hide
+     */
     public boolean hasMIDIInterface() {
         ArrayList<UsbDescriptor> descriptors =
                 getInterfaceDescriptorsForClass(UsbDescriptor.CLASSID_AUDIO);
@@ -540,7 +542,7 @@
             probability += 0.75f;
         }
 
-        if (hasMic && hasHIDDescriptor()) {
+        if (hasMic && hasHIDInterface()) {
             probability += 0.25f;
         }
 
@@ -593,7 +595,7 @@
             probability += 0.75f;
         }
 
-        if (hasSpeaker && hasHIDDescriptor()) {
+        if (hasSpeaker && hasHIDInterface()) {
             probability += 0.25f;
         }
 
diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbDeviceDescriptor.java b/services/usb/java/com/android/server/usb/descriptors/UsbDeviceDescriptor.java
index e31e3a3..fae594a 100644
--- a/services/usb/java/com/android/server/usb/descriptors/UsbDeviceDescriptor.java
+++ b/services/usb/java/com/android/server/usb/descriptors/UsbDeviceDescriptor.java
@@ -48,7 +48,7 @@
     private int mDeviceRelease; // 12:2 Device Release number - BCD
     private byte mMfgIndex;     // 14:1 Index of Manufacturer String Descriptor
     private byte mProductIndex; // 15:1 Index of Product String Descriptor
-    private byte mSerialNum;    // 16:1 Index of Serial Number String Descriptor
+    private byte mSerialIndex;  // 16:1 Index of Serial Number String Descriptor
     private byte mNumConfigs;   // 17:1 Number of Possible Configurations
 
     private ArrayList<UsbConfigDescriptor> mConfigDescriptors =
@@ -91,16 +91,37 @@
         return mDeviceRelease;
     }
 
+    // mDeviceRelease is binary-coded decimal, format DD.DD
+    public String getDeviceReleaseString() {
+        int hundredths = mDeviceRelease & 0xF;
+        int tenths = (mDeviceRelease & 0xF0) >> 4;
+        int ones = (mDeviceRelease & 0xF00) >> 8;
+        int tens = (mDeviceRelease & 0xF000) >> 12;
+        return String.format("%d.%d%d", tens * 10 + ones, tenths, hundredths);
+    }
+
     public byte getMfgIndex() {
         return mMfgIndex;
     }
 
+    public String getMfgString(UsbDescriptorParser p) {
+        return p.getDescriptorString(mMfgIndex);
+    }
+
     public byte getProductIndex() {
         return mProductIndex;
     }
 
-    public byte getSerialNum() {
-        return mSerialNum;
+    public String getProductString(UsbDescriptorParser p) {
+        return p.getDescriptorString(mProductIndex);
+    }
+
+    public byte getSerialIndex() {
+        return mSerialIndex;
+    }
+
+    public String getSerialString(UsbDescriptorParser p) {
+        return p.getDescriptorString(mSerialIndex);
     }
 
     public byte getNumConfigs() {
@@ -119,16 +140,14 @@
             Log.d(TAG, "toAndroid()");
         }
 
-        String mfgName = parser.getDescriptorString(mMfgIndex);
-        String prodName = parser.getDescriptorString(mProductIndex);
+        String mfgName = getMfgString(parser);
+        String prodName = getProductString(parser);
         if (DEBUG) {
             Log.d(TAG, "  mfgName:" + mfgName + " prodName:" + prodName);
         }
 
-        // Create version string in "%.%" format
-        String versionString =
-                Integer.toString(mDeviceRelease >> 8) + "." + (mDeviceRelease & 0xFF);
-        String serialStr = parser.getDescriptorString(mSerialNum);
+        String versionString = getDeviceReleaseString();
+        String serialStr = getSerialString(parser);
         if (DEBUG) {
             Log.d(TAG, "  versionString:" + versionString + " serialStr:" + serialStr);
         }
@@ -159,7 +178,7 @@
         mDeviceRelease = stream.unpackUsbShort();
         mMfgIndex = stream.getByte();
         mProductIndex = stream.getByte();
-        mSerialNum = stream.getByte();
+        mSerialIndex = stream.getByte();
         mNumConfigs = stream.getByte();
 
         return mLength;
diff --git a/telephony/java/android/telephony/LocationAccessPolicy.java b/telephony/java/android/telephony/LocationAccessPolicy.java
index 26ffe32..6480aab 100644
--- a/telephony/java/android/telephony/LocationAccessPolicy.java
+++ b/telephony/java/android/telephony/LocationAccessPolicy.java
@@ -21,31 +21,25 @@
 import android.annotation.UserIdInt;
 import android.app.ActivityManager;
 import android.app.AppOpsManager;
-import android.content.BroadcastReceiver;
 import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
 import android.content.pm.PackageManager;
 import android.content.pm.UserInfo;
 import android.location.LocationManager;
 import android.os.Binder;
-import android.os.Build;
 import android.os.Process;
 import android.os.Trace;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.provider.Settings;
-import android.util.SparseBooleanArray;
+import android.util.Log;
 
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 /**
  * Helper for performing location access checks.
  * @hide
  */
 public final class LocationAccessPolicy {
+    private static final String LOG_TAG = LocationAccessPolicy.class.getSimpleName();
     /**
      * API to determine if the caller has permissions to get cell location.
      *
@@ -94,10 +88,12 @@
     }
 
     private static boolean isLocationModeEnabled(@NonNull Context context, @UserIdInt int userId) {
-        int locationMode = Settings.Secure.getIntForUser(context.getContentResolver(),
-                Settings.Secure.LOCATION_MODE, Settings.Secure.LOCATION_MODE_OFF, userId);
-        return locationMode != Settings.Secure.LOCATION_MODE_OFF
-                && locationMode != Settings.Secure.LOCATION_MODE_SENSORS_ONLY;
+        LocationManager locationManager = context.getSystemService(LocationManager.class);
+        if (locationManager == null) {
+            Log.w(LOG_TAG, "Couldn't get location manager, denying location access");
+            return false;
+        }
+        return locationManager.isLocationEnabledForUser(UserHandle.of(userId));
     }
 
     private static boolean checkInteractAcrossUsersFull(@NonNull Context context) {
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index c5386ef..a12a7a0 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -40,6 +40,7 @@
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.PersistableBundle;
+import android.os.Process;
 import android.os.RemoteException;
 import android.os.ResultReceiver;
 import android.os.ServiceManager;
@@ -214,6 +215,10 @@
         return ActivityThread.currentOpPackageName();
     }
 
+    private boolean isSystemProcess() {
+        return Process.myUid() == Process.SYSTEM_UID;
+    }
+
     /**
      * Returns the multi SIM variant
      * Returns DSDS for Dual SIM Dual Standby
@@ -2866,15 +2871,18 @@
             IPhoneSubInfo info = getSubscriberInfo();
             if (info == null) {
                 Rlog.e(TAG, "IMSI error: Subscriber Info is null");
+                if (!isSystemProcess()) {
+                    throw new RuntimeException("IMSI error: Subscriber Info is null");
+                }
                 return;
             }
             int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId());
             info.resetCarrierKeysForImsiEncryption(subId, mContext.getOpPackageName());
         } catch (RemoteException ex) {
             Rlog.e(TAG, "getCarrierInfoForImsiEncryption RemoteException" + ex);
-        } catch (NullPointerException ex) {
-            // This could happen before phone restarts due to crashing
-            Rlog.e(TAG, "getCarrierInfoForImsiEncryption NullPointerException" + ex);
+            if (!isSystemProcess()) {
+                ex.rethrowAsRuntimeException();
+            }
         }
     }
 
@@ -3863,11 +3871,18 @@
     public void sendDialerSpecialCode(String inputCode) {
         try {
             final ITelephony telephony = getITelephony();
+            if (telephony == null) {
+                if (!isSystemProcess()) {
+                    throw new RuntimeException("Telephony service unavailable");
+                }
+                return;
+            }
             telephony.sendDialerSpecialCode(mContext.getOpPackageName(), inputCode);
         } catch (RemoteException ex) {
             // This could happen if binder process crashes.
-        } catch (NullPointerException ex) {
-            // This could happen before phone restarts due to crashing
+            if (!isSystemProcess()) {
+                ex.rethrowAsRuntimeException();
+            }
         }
     }
 
@@ -7836,6 +7851,9 @@
             }
         } catch (RemoteException ex) {
             // This could happen if binder process crashes.
+            if (!isSystemProcess()) {
+                ex.rethrowAsRuntimeException();
+            }
         }
     }
 }
diff --git a/tests/UsbTests/res/raw/usbdescriptors_massstorage.bin b/tests/UsbTests/res/raw/usbdescriptors_massstorage.bin
new file mode 100644
index 0000000..1790369
--- /dev/null
+++ b/tests/UsbTests/res/raw/usbdescriptors_massstorage.bin
Binary files differ
diff --git a/tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java b/tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java
index f323952..ea027d7 100644
--- a/tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java
+++ b/tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java
@@ -18,6 +18,7 @@
 
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
 import android.content.Context;
@@ -28,6 +29,7 @@
 import android.support.test.runner.AndroidJUnit4;
 
 import com.android.server.usb.descriptors.UsbDescriptorParser;
+import com.android.server.usb.descriptors.UsbDeviceDescriptor;
 import com.google.common.io.ByteStreams;
 
 import java.io.InputStream;
@@ -61,14 +63,24 @@
         }
 
         // Testing same codepath as UsbHostManager.java:usbDeviceAdded
-        UsbDescriptorParser parser = new UsbDescriptorParser("test-usb-addr");
-        if (!parser.parseDescriptors(descriptors)) {
-            fail("failed to parse descriptors.");
-        }
+        UsbDescriptorParser parser = new UsbDescriptorParser("test-usb-addr", descriptors);
         return parser;
     }
 
-    // A Headset has a microphone and a speaker and is a headset.
+    /** A Headset has a microphone and a speaker and is a headset.
+     * Descriptors for this example show up on lsusb -v with:
+     *   bcdDevice           22.80
+     * and a UAC1 audio device with the following control interface:
+     *       bInterfaceClass         1 Audio
+     * ...
+     *       bDescriptorSubtype      2 (INPUT_TERMINAL)
+     *       bTerminalID             1
+     *       wTerminalType      0x0201 Microphone
+     * ...
+     *       bDescriptorSubtype      3 (OUTPUT_TERMINAL)
+     *       bTerminalID            15
+     *       wTerminalType      0x0302 Headphones
+     */
     @Test
     @SmallTest
     public void testHeadsetDescriptorParser() {
@@ -77,9 +89,24 @@
         assertTrue(parser.hasOutput());
         assertTrue(parser.isInputHeadset());
         assertTrue(parser.isOutputHeadset());
+
+        assertTrue(parser.hasAudioInterface());
+        assertTrue(parser.hasHIDInterface());
+        assertFalse(parser.hasStorageInterface());
+
+        assertEquals(parser.getDeviceDescriptor().getDeviceReleaseString(), "22.80");
     }
 
-    // Headphones have no microphones but are considered a headset.
+    /** Headphones have no microphones but are considered a headset.
+     * Descriptors for this example show up on lsusb -v with:
+     *   bcdDevice           22.80
+     * and a UAC1 audio device with the following control interface:
+     *       bInterfaceClass         1 Audio
+     * ...
+     *       bDescriptorSubtype      3 (OUTPUT_TERMINAL)
+     *       bTerminalID            15
+     *       wTerminalType      0x0302 Headphones
+     */
     @Test
     @SmallTest
     public void testHeadphoneDescriptorParser() {
@@ -88,9 +115,24 @@
         assertTrue(parser.hasOutput());
         assertFalse(parser.isInputHeadset());
         assertTrue(parser.isOutputHeadset());
+
+        assertTrue(parser.hasAudioInterface());
+        assertTrue(parser.hasHIDInterface());
+        assertFalse(parser.hasStorageInterface());
+
+        assertEquals(parser.getDeviceDescriptor().getDeviceReleaseString(), "22.80");
     }
 
-    // Line out has no microphones and aren't considered a headset.
+    /** Line out with no microphones aren't considered a headset.
+     * Descriptors for this example show up on lsusb -v with:
+     *     bcdDevice           22.80
+     * and the following UAC1 audio control interface
+     *  bInterfaceClass         1 Audio
+     *  ...
+     *   bDescriptorSubtype      3 (OUTPUT_TERMINAL)
+     *   bTerminalID            15
+     *   wTerminalType      0x0603 Line Connector
+     */
     @Test
     @SmallTest
     public void testLineoutDescriptorParser() {
@@ -99,9 +141,20 @@
         assertTrue(parser.hasOutput());
         assertFalse(parser.isInputHeadset());
         assertFalse(parser.isOutputHeadset());
+
+        assertTrue(parser.hasAudioInterface());
+        assertTrue(parser.hasHIDInterface());
+        assertFalse(parser.hasStorageInterface());
+
+        assertEquals(parser.getDeviceDescriptor().getDeviceReleaseString(), "22.80");
     }
 
-    // An HID-only device shouldn't be considered anything at all.
+    /** An HID-only device shouldn't be considered anything at all.
+    /* Descriptors show up on lsusb -v with:
+     *   bcdDevice           22.80
+     * and a single HID interface,
+     *   bInterfaceClass         3 Human Interface Device
+     */
     @Test
     @SmallTest
     public void testNothingDescriptorParser() {
@@ -110,6 +163,34 @@
         assertFalse(parser.hasOutput());
         assertFalse(parser.isInputHeadset());
         assertFalse(parser.isOutputHeadset());
+
+        assertFalse(parser.hasAudioInterface());
+        assertTrue(parser.hasHIDInterface());
+        assertFalse(parser.hasStorageInterface());
+
+        assertEquals(parser.getDeviceDescriptor().getDeviceReleaseString(), "22.80");
+    }
+
+    /** A USB mass-storage device.
+     * Shows up on lsusb -v with:
+     *    bcdDevice            2.08
+     * and a single interface descriptor,
+     *    bInterfaceClass         8 Mass Storage
+     */
+    @Test
+    @SmallTest
+    public void testMassStorageDescriptorParser() {
+        UsbDescriptorParser parser = loadParser(R.raw.usbdescriptors_massstorage);
+        assertFalse(parser.hasInput());
+        assertFalse(parser.hasOutput());
+        assertFalse(parser.isInputHeadset());
+        assertFalse(parser.isOutputHeadset());
+
+        assertFalse(parser.hasAudioInterface());
+        assertFalse(parser.hasHIDInterface());
+        assertTrue(parser.hasStorageInterface());
+
+        assertEquals(parser.getDeviceDescriptor().getDeviceReleaseString(), "2.08");
     }
 
 }
diff --git a/tools/stringslint/stringslint.py b/tools/stringslint/stringslint.py
new file mode 100644
index 0000000..d637ff3
--- /dev/null
+++ b/tools/stringslint/stringslint.py
@@ -0,0 +1,162 @@
+#!/usr/bin/env python
+
+# Copyright (C) 2018 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.
+
+"""
+Enforces common Android string best-practices.  It ignores lint messages from
+a previous strings file, if provided.
+
+Usage: stringslint.py strings.xml
+Usage: stringslint.py strings.xml old_strings.xml
+"""
+
+import re, sys
+import lxml.etree as ET
+
+BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
+
+def format(fg=None, bg=None, bright=False, bold=False, dim=False, reset=False):
+    # manually derived from http://en.wikipedia.org/wiki/ANSI_escape_code#Codes
+    codes = []
+    if reset: codes.append("0")
+    else:
+        if not fg is None: codes.append("3%d" % (fg))
+        if not bg is None:
+            if not bright: codes.append("4%d" % (bg))
+            else: codes.append("10%d" % (bg))
+        if bold: codes.append("1")
+        elif dim: codes.append("2")
+        else: codes.append("22")
+    return "\033[%sm" % (";".join(codes))
+
+warnings = None
+
+def warn(tag, msg, actual, expected):
+    global warnings
+    key = "%s:%d" % (tag.attrib["name"], hash(msg))
+    value = "%sLine %d: '%s':%s %s" % (format(fg=YELLOW, bold=True),
+                                       tag.sourceline,
+                                       tag.attrib["name"],
+                                       format(reset=True),
+                                       msg)
+    if not actual is None: value += "\n\tActual: %s%s%s" % (format(dim=True),
+                                                            actual,
+                                                            format(reset=True))
+    if not expected is None: value += "\n\tExample: %s%s%s" % (format(dim=True),
+                                                               expected,
+                                                               format(reset=True))
+    warnings[key] = value
+
+def lint(path):
+    global warnings
+    warnings = {}
+
+    with open(path) as f:
+        raw = f.read()
+        if len(raw.strip()) == 0:
+            return warnings
+        tree = ET.fromstring(raw)
+        root = tree #tree.getroot()
+
+    last_comment = None
+    for child in root:
+        # TODO: handle plurals
+        if isinstance(child, ET._Comment):
+            last_comment = child
+        elif child.tag == "string":
+            # We always consume comment
+            comment = last_comment
+            last_comment = None
+
+            # Validate comment
+            if comment is None:
+                warn(child, "Missing string comment to aid translation",
+                     None, None)
+                continue
+            if "do not translate" in comment.text.lower():
+                continue
+            if "translatable" in child.attrib and child.attrib["translatable"].lower() == "false":
+                continue
+            if re.search("CHAR[ _-]LIMIT=(\d+|NONE|none)", comment.text) is None:
+                warn(child, "Missing CHAR LIMIT to aid translation",
+                     repr(comment), "<!-- Description of string [CHAR LIMIT=32] -->")
+
+            # Look for common mistakes/substitutions
+            text = "".join(child.itertext()).strip()
+            if "'" in text:
+                warn(child, "Turned quotation mark glyphs are more polished",
+                     text, "This doesn\u2019t need to \u2018happen\u2019 today")
+            if '"' in text and not text.startswith('"') and text.endswith('"'):
+                warn(child, "Turned quotation mark glyphs are more polished",
+                     text, "This needs to \u201chappen\u201d today")
+            if "..." in text:
+                warn(child, "Ellipsis glyph is more polished",
+                     text, "Loading\u2026")
+            if "wi-fi" in text.lower():
+                warn(child, "Non-breaking glyph is more polished",
+                     text, "Wi\u2011Fi")
+            if "wifi" in text.lower():
+                warn(child, "Using non-standard spelling",
+                     text, "Wi\u2011Fi")
+            if re.search("\d-\d", text):
+                warn(child, "Ranges should use en dash glyph",
+                     text, "You will find this material in chapters 8\u201312")
+            if "--" in text:
+                warn(child, "Phrases should use em dash glyph",
+                     text, "Upon discovering errors\u2014all 124 of them\u2014they recalled.")
+            if ".  " in text:
+                warn(child, "Only use single space between sentences",
+                     text, "First idea. Second idea.")
+
+            # When more than one substitution, require indexes
+            if len(re.findall("%[^%]", text)) > 1:
+                if len(re.findall("%[^\d]", text)) > 0:
+                    warn(child, "Substitutions must be indexed",
+                         text, "Add %1$s to %2$s")
+
+            # Require xliff substitutions
+            for gc in child.iter():
+                badsub = False
+                if gc.tail and re.search("%[^%]", gc.tail): badsub = True
+                if re.match("{.*xliff.*}g", gc.tag):
+                    if "id" not in gc.attrib:
+                        warn(child, "Substitutions must define id attribute",
+                             None, "<xliff:g id=\"domain\" example=\"example.com\">%1$s</xliff:g>")
+                    if "example" not in gc.attrib:
+                        warn(child, "Substitutions must define example attribute",
+                             None, "<xliff:g id=\"domain\" example=\"example.com\">%1$s</xliff:g>")
+                else:
+                    if gc.text and re.search("%[^%]", gc.text): badsub = True
+                if badsub:
+                    warn(child, "Substitutions must be inside xliff tags",
+                         text, "<xliff:g id=\"domain\" example=\"example.com\">%1$s</xliff:g>")
+
+    return warnings
+
+if len(sys.argv) > 2:
+    before = lint(sys.argv[2])
+else:
+    before = {}
+after = lint(sys.argv[1])
+
+for b in before:
+    if b in after:
+        del after[b]
+
+if len(after) > 0:
+    for a in sorted(after.keys()):
+        print after[a]
+        print
+    sys.exit(1)
diff --git a/tools/stringslint/stringslint_sha.sh b/tools/stringslint/stringslint_sha.sh
new file mode 100755
index 0000000..c79ba04
--- /dev/null
+++ b/tools/stringslint/stringslint_sha.sh
@@ -0,0 +1,4 @@
+#!/bin/bash
+git show --name-only --pretty=format: $1 | grep values/strings.xml | while read file; do
+    python $ANDROID_BUILD_TOP/frameworks/base/tools/stringslint/stringslint.py <(git show $1:$file) <(git show $1^:$file)
+done