Merge "Making install session seal+verification non blocking."
diff --git a/core/java/android/app/StatsManager.java b/core/java/android/app/StatsManager.java
index 38ae5da..11d6528a 100644
--- a/core/java/android/app/StatsManager.java
+++ b/core/java/android/app/StatsManager.java
@@ -101,6 +101,9 @@
      */
     public static final String ACTION_STATSD_STARTED = "android.app.action.STATSD_STARTED";
 
+    private static final long DEFAULT_COOL_DOWN_NS = 1_000_000_000L; // 1 second.
+    private static final long DEFAULT_TIMEOUT_NS = 10_000_000_000L; // 10 seconds.
+
     /**
      * Constructor for StatsManagerClient.
      *
@@ -495,20 +498,23 @@
      * pulled.
      *
      * @param atomTag           The tag of the atom for this puller callback.
-     * @param coolDownNs        The minimum time between successive pulls. A cache of the previous
-     *                          pull will be used if the time between pulls is less than coolDownNs.
-     * @param timeoutNs         The maximum time a pull should take. Statsd will wait timeoutNs for
-     *                          the pull to complete before timing out and marking the pull as
-     *                          failed.
-     * @param additiveFields    Fields that are added when mapping isolated uids to host uids.
+     * @param metadata          Optional metadata specifying the timeout, cool down time, and
+     *                          additive fields for mapping isolated to host uids.
      * @param callback          The callback to be invoked when the stats service pulls the atom.
+     * @param executor          The executor in which to run the callback
      * @throws RemoteException  if unsuccessful due to failing to connect to system server.
      *
      * @hide
      */
-    public void registerPullAtomCallback(int atomTag, long coolDownNs, long timeoutNs,
-            int[] additiveFields, @NonNull StatsPullAtomCallback callback,
-            @NonNull Executor executor) throws RemoteException, SecurityException {
+    public void registerPullAtomCallback(int atomTag, @Nullable PullAtomMetadata metadata,
+            @NonNull StatsPullAtomCallback callback, @NonNull Executor executor)
+            throws RemoteException, SecurityException {
+        long coolDownNs = metadata == null ? DEFAULT_COOL_DOWN_NS : metadata.mCoolDownNs;
+        long timeoutNs = metadata == null ? DEFAULT_TIMEOUT_NS : metadata.mTimeoutNs;
+        int[] additiveFields = metadata == null ? new int[0] : metadata.mAdditiveFields;
+        if (additiveFields == null) {
+            additiveFields = new int[0];
+        }
         synchronized (this) {
             IStatsCompanionService service = getIStatsCompanionServiceLocked();
             PullAtomCallbackInternal rec =
@@ -545,6 +551,89 @@
     }
 
     /**
+     * Metadata required for registering a StatsPullAtomCallback.
+     * All fields are optional, and defaults will be used for fields that are unspecified.
+     *
+     * @hide
+     */
+    public static class PullAtomMetadata {
+        private final long mCoolDownNs;
+        private final long mTimeoutNs;
+        private final int[] mAdditiveFields;
+
+        // Private Constructor for builder
+        private PullAtomMetadata(long coolDownNs, long timeoutNs, int[] additiveFields) {
+            mCoolDownNs = coolDownNs;
+            mTimeoutNs = timeoutNs;
+            mAdditiveFields = additiveFields;
+        }
+
+        /**
+         * Returns a new PullAtomMetadata.Builder object for constructing PullAtomMetadata for
+         * StatsManager#registerPullAtomCallback
+         */
+        public static PullAtomMetadata.Builder newBuilder() {
+            return new PullAtomMetadata.Builder();
+        }
+
+        /**
+         * Builder for PullAtomMetadata.
+         */
+        public static class Builder {
+            private long mCoolDownNs;
+            private long mTimeoutNs;
+            private int[] mAdditiveFields;
+
+            private Builder() {
+                mCoolDownNs = DEFAULT_COOL_DOWN_NS;
+                mTimeoutNs = DEFAULT_TIMEOUT_NS;
+                mAdditiveFields = null;
+            }
+
+            /**
+             * Set the cool down time of the pull in nanoseconds. If two successive pulls are issued
+             * within the cool down, a cached version of the first will be used for the second.
+             */
+            @NonNull
+            public Builder setCoolDownNs(long coolDownNs) {
+                mCoolDownNs = coolDownNs;
+                return this;
+            }
+
+            /**
+             * Set the maximum time the pull can take in nanoseconds.
+             */
+            @NonNull
+            public Builder setTimeoutNs(long timeoutNs) {
+                mTimeoutNs = timeoutNs;
+                return this;
+            }
+
+            /**
+             * Set the additive fields of this pulled atom.
+             *
+             * This is only applicable for atoms which have a uid field. When tasks are run in
+             * isolated processes, the data will be attributed to the host uid. Additive fields
+             * will be combined when the non-additive fields are the same.
+             */
+            @NonNull
+            public Builder setAdditiveFields(int[] additiveFields) {
+                mAdditiveFields = additiveFields;
+                return this;
+            }
+
+            /**
+             * Builds and returns a PullAtomMetadata object with the values set in the builder and
+             * defaults for unset fields.
+             */
+            @NonNull
+            public PullAtomMetadata build() {
+                return new PullAtomMetadata(mCoolDownNs, mTimeoutNs, mAdditiveFields);
+            }
+        }
+    }
+
+    /**
      * Callback interface for pulling atoms requested by the stats service.
      *
      * @hide
diff --git a/core/java/android/content/pm/UserInfo.java b/core/java/android/content/pm/UserInfo.java
index 5fb17ee..a83c3da 100644
--- a/core/java/android/content/pm/UserInfo.java
+++ b/core/java/android/content/pm/UserInfo.java
@@ -26,8 +26,6 @@
 import android.os.UserManager;
 import android.util.DebugUtils;
 
-import com.android.server.pm.UserTypeDetails;
-
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
@@ -181,7 +179,7 @@
 
     /**
      * Type of user, such as {@link UserManager#USER_TYPE_PROFILE_MANAGED}, corresponding to
-     * {@link UserTypeDetails#getName()}.
+     * {@link com.android.server.pm.UserTypeDetails#getName()}.
      */
     public String userType;
 
@@ -195,9 +193,10 @@
     public int restrictedProfileParentId;
 
     /**
-     * Which badge color/label to use within a particular {@link UserTypeDetails}, i.e.
-     * the badgeIndex.
-     * This is an index for distinguishing different profiles with the same parent and user type.
+     * Index for distinguishing different profiles with the same parent and user type for the
+     * purpose of badging.
+     * It is used for determining which badge color/label to use (if applicable) from
+     * the options available for a particular user type.
      */
     public int profileBadge;
 
diff --git a/core/java/com/android/internal/app/LocaleHelper.java b/core/java/com/android/internal/app/LocaleHelper.java
index aef4dbf..e3d07aa 100644
--- a/core/java/com/android/internal/app/LocaleHelper.java
+++ b/core/java/com/android/internal/app/LocaleHelper.java
@@ -208,7 +208,7 @@
      * @return the maximized Locale instance.
      */
     public static Locale addLikelySubtags(Locale locale) {
-        return libcore.icu.ICU.addLikelySubtags(locale);
+        return ULocale.addLikelySubtags(ULocale.forLocale(locale)).toLocale();
     }
 
     /**
diff --git a/core/proto/android/os/incident.proto b/core/proto/android/os/incident.proto
index 898e2f0..6cf9424 100644
--- a/core/proto/android/os/incident.proto
+++ b/core/proto/android/os/incident.proto
@@ -369,7 +369,7 @@
     ];
 
     // Dropbox entries split by tags.
-    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_crashes = 3027 [
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_crash = 3027 [
         (section).type = SECTION_DUMPSYS,
         (section).args = "dropbox --proto data_app_crash"
     ];
@@ -384,6 +384,91 @@
         (section).args = "dropbox --proto data_app_native_crash"
     ];
 
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_strictmode = 3030 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto data_app_strictmode"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_data_app_wtf = 3031 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto data_app_wtf"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_crash = 3032 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_app_crash"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_anr = 3033 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_app_anr"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_native_crash = 3034 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_app_native_crash"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_strictmode = 3035 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_app_strictmode"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_app_wtf = 3036 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_app_wtf"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_crashes = 3037 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_server_crash"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_anr = 3038 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_server_anr"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_native_crash = 3039 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_server_native_crash"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_lowmem= 3040 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_server_lowmem"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_strictmode = 3041 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_server_strictmode"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_watchdog = 3042 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_server_watchdog"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_server_wtf = 3043 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto system_server_wtf"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_recovery_log = 3044 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto SYSTEM_RECOVERY_LOG"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_system_tombstone = 3045 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto SYSTEM_TOMBSTONE"
+    ];
+
+    optional android.service.dropbox.DropBoxManagerServiceDumpProto dropbox_subsystem_restart = 3046 [
+        (section).type = SECTION_DUMPSYS,
+        (section).args = "dropbox --proto SubsystemRestart"
+    ];
+
     // Reserved for OEMs.
     extensions 50000 to 100000;
 }
diff --git a/core/java/com/android/server/pm/UserTypeDetails.java b/services/core/java/com/android/server/pm/UserTypeDetails.java
similarity index 100%
rename from core/java/com/android/server/pm/UserTypeDetails.java
rename to services/core/java/com/android/server/pm/UserTypeDetails.java
diff --git a/core/java/com/android/server/pm/UserTypeFactory.java b/services/core/java/com/android/server/pm/UserTypeFactory.java
similarity index 100%
rename from core/java/com/android/server/pm/UserTypeFactory.java
rename to services/core/java/com/android/server/pm/UserTypeFactory.java
diff --git a/services/core/java/com/android/server/RecoverySystemService.java b/services/core/java/com/android/server/recoverysystem/RecoverySystemService.java
similarity index 99%
rename from services/core/java/com/android/server/RecoverySystemService.java
rename to services/core/java/com/android/server/recoverysystem/RecoverySystemService.java
index 997178e..d78aaa5 100644
--- a/services/core/java/com/android/server/RecoverySystemService.java
+++ b/services/core/java/com/android/server/recoverysystem/RecoverySystemService.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package com.android.server;
+package com.android.server.recoverysystem;
 
 import android.content.Context;
 import android.net.LocalSocket;
@@ -27,6 +27,8 @@
 import android.os.SystemProperties;
 import android.util.Slog;
 
+import com.android.server.SystemService;
+
 import libcore.io.IoUtils;
 
 import java.io.DataInputStream;
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index 3043b6f..f1ed1d9 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -137,6 +137,7 @@
 import com.android.server.power.PowerManagerService;
 import com.android.server.power.ShutdownThread;
 import com.android.server.power.ThermalManagerService;
+import com.android.server.recoverysystem.RecoverySystemService;
 import com.android.server.restrictions.RestrictionsManagerService;
 import com.android.server.role.RoleManagerService;
 import com.android.server.rollback.RollbackManagerService;
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 3d63e4a..43d9c11 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -58,6 +58,7 @@
 import android.telephony.ims.ImsMmTelManager;
 import android.util.DisplayMetrics;
 import android.util.Log;
+import android.util.Pair;
 
 import com.android.internal.telephony.ISetOpportunisticDataCallback;
 import com.android.internal.telephony.ISub;
@@ -73,6 +74,7 @@
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.Executor;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Consumer;
@@ -908,6 +910,11 @@
     private final Context mContext;
     private volatile INetworkPolicyManager mNetworkPolicy;
 
+    // Cache of Resource that has been created in getResourcesForSubId. Key is a Pair containing
+    // the Context and subId.
+    private static final Map<Pair<Context, Integer>, Resources> sResourcesCache =
+            new ConcurrentHashMap<>();
+
     /**
      * A listener class for monitoring changes to {@link SubscriptionInfo} records.
      * <p>
@@ -2329,8 +2336,20 @@
      * @return Resources associated with Subscription.
      * @hide
      */
+    @NonNull
     public static Resources getResourcesForSubId(Context context, int subId,
             boolean useRootLocale) {
+        // Check if resources for this context and subId already exist in the resource cache.
+        // Resources that use the root locale are not cached.
+        Pair<Context, Integer> cacheKey = null;
+        if (isValidSubscriptionId(subId) && !useRootLocale) {
+            cacheKey = Pair.create(context, subId);
+            if (sResourcesCache.containsKey(cacheKey)) {
+                // Cache hit. Use cached Resources.
+                return sResourcesCache.get(cacheKey);
+            }
+        }
+
         final SubscriptionInfo subInfo =
                 SubscriptionManager.from(context).getActiveSubscriptionInfo(subId);
 
@@ -2350,7 +2369,13 @@
         DisplayMetrics metrics = context.getResources().getDisplayMetrics();
         DisplayMetrics newMetrics = new DisplayMetrics();
         newMetrics.setTo(metrics);
-        return new Resources(context.getResources().getAssets(), newMetrics, newConfig);
+        Resources res = new Resources(context.getResources().getAssets(), newMetrics, newConfig);
+
+        if (cacheKey != null) {
+            // Save the newly created Resources in the resource cache.
+            sResourcesCache.put(cacheKey, res);
+        }
+        return res;
     }
 
     /**