Merge "Fix end-to-end value metrics tests."
diff --git a/Android.bp b/Android.bp
index f4e8b63..87388d4 100644
--- a/Android.bp
+++ b/Android.bp
@@ -903,14 +903,8 @@
         "core/java/android/net/INetworkStackConnector.aidl",
         "core/java/android/net/INetworkStackStatusCallback.aidl",
         "core/java/android/net/InitialConfigurationParcelable.aidl",
-        "core/java/android/net/IpPrefixParcelable.aidl",
-        "core/java/android/net/LinkAddressParcelable.aidl",
-        "core/java/android/net/LinkPropertiesParcelable.aidl",
-        "core/java/android/net/NetworkParcelable.aidl",
         "core/java/android/net/PrivateDnsConfigParcel.aidl",
         "core/java/android/net/ProvisioningConfigurationParcelable.aidl",
-        "core/java/android/net/ProxyInfoParcelable.aidl",
-        "core/java/android/net/RouteInfoParcelable.aidl",
         "core/java/android/net/StaticIpConfigurationParcelable.aidl",
         "core/java/android/net/TcpKeepalivePacketDataParcelable.aidl",
         "core/java/android/net/dhcp/DhcpServingParamsParcel.aidl",
@@ -919,6 +913,14 @@
         "core/java/android/net/ip/IIpClient.aidl",
         "core/java/android/net/ip/IIpClientCallbacks.aidl",
     ],
+    backend: {
+        ndk: {
+            enabled: false,
+        },
+        cpp: {
+            enabled: false,
+        },
+    },
     api_dir: "aidl/networkstack",
 }
 
diff --git a/api/current.txt b/api/current.txt
index a499de4..d1b77f2 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -4263,24 +4263,24 @@
   }
 
   public class AppOpsManager {
-    method @Deprecated public int checkOp(String, int, String);
-    method @Deprecated public int checkOpNoThrow(String, int, String);
-    method public void checkPackage(int, String);
-    method public void finishOp(String, int, String);
-    method public int noteOp(String, int, String);
-    method public int noteOpNoThrow(String, int, String);
-    method public int noteProxyOp(String, String);
-    method public int noteProxyOpNoThrow(String, String);
+    method @Deprecated public int checkOp(@NonNull String, int, @NonNull String);
+    method @Deprecated public int checkOpNoThrow(@NonNull String, int, @NonNull String);
+    method public void checkPackage(int, @NonNull String);
+    method public void finishOp(@NonNull String, int, @NonNull String);
+    method public int noteOp(@NonNull String, int, @NonNull String);
+    method public int noteOpNoThrow(@NonNull String, int, @NonNull String);
+    method public int noteProxyOp(@NonNull String, @NonNull String);
+    method public int noteProxyOpNoThrow(@NonNull String, @NonNull String);
     method public int noteProxyOpNoThrow(@NonNull String, @Nullable String, int);
     method public static String permissionToOp(String);
-    method public int startOp(String, int, String);
-    method public int startOpNoThrow(String, int, String);
-    method public void startWatchingMode(String, String, android.app.AppOpsManager.OnOpChangedListener);
-    method public void startWatchingMode(String, String, int, android.app.AppOpsManager.OnOpChangedListener);
-    method public void stopWatchingMode(android.app.AppOpsManager.OnOpChangedListener);
-    method public int unsafeCheckOp(String, int, String);
-    method public int unsafeCheckOpNoThrow(String, int, String);
-    method public int unsafeCheckOpRaw(@NonNull String, int, String);
+    method public int startOp(@NonNull String, int, @NonNull String);
+    method public int startOpNoThrow(@NonNull String, int, @NonNull String);
+    method public void startWatchingMode(@NonNull String, @Nullable String, @NonNull android.app.AppOpsManager.OnOpChangedListener);
+    method public void startWatchingMode(@NonNull String, @Nullable String, int, @NonNull android.app.AppOpsManager.OnOpChangedListener);
+    method public void stopWatchingMode(@NonNull android.app.AppOpsManager.OnOpChangedListener);
+    method public int unsafeCheckOp(@NonNull String, int, @NonNull String);
+    method public int unsafeCheckOpNoThrow(@NonNull String, int, @NonNull String);
+    method public int unsafeCheckOpRaw(@NonNull String, int, @NonNull String);
     method public int unsafeCheckOpRawNoThrow(@NonNull String, int, @NonNull String);
     field public static final int MODE_ALLOWED = 0; // 0x0
     field public static final int MODE_DEFAULT = 3; // 0x3
@@ -23005,7 +23005,7 @@
     method protected abstract String onGetSummary();
     method public final void onStart(android.content.Intent, int);
     method public final int onStartCommand(android.content.Intent, int, int);
-    method public static final void refreshSettings(android.content.Context);
+    method public static final void refreshSettings(@NonNull android.content.Context);
     field public static final String ACTION_INJECTED_SETTING_CHANGED = "android.location.InjectedSettingChanged";
     field public static final String ACTION_SERVICE_INTENT = "android.location.SettingInjectorService";
     field public static final String ATTRIBUTES_NAME = "injected-location-setting";
@@ -24846,7 +24846,7 @@
     method public boolean verify(@NonNull byte[], @NonNull byte[], @NonNull byte[]);
   }
 
-  @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @IntDef({android.media.MediaDrm.HDCP_LEVEL_UNKNOWN, android.media.MediaDrm.HDCP_NONE, android.media.MediaDrm.HDCP_V1, android.media.MediaDrm.HDCP_V2, android.media.MediaDrm.HDCP_V2_1, android.media.MediaDrm.HDCP_V2_2, android.media.MediaDrm.HDCP_V2_3, android.media.MediaDrm.HDCP_NO_DIGITAL_OUTPUT}) public static @interface MediaDrm.HdcpLevel {
+  @Deprecated @IntDef({android.media.MediaDrm.HDCP_LEVEL_UNKNOWN, android.media.MediaDrm.HDCP_NONE, android.media.MediaDrm.HDCP_V1, android.media.MediaDrm.HDCP_V2, android.media.MediaDrm.HDCP_V2_1, android.media.MediaDrm.HDCP_V2_2, android.media.MediaDrm.HDCP_V2_3, android.media.MediaDrm.HDCP_NO_DIGITAL_OUTPUT}) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) public static @interface MediaDrm.HdcpLevel {
   }
 
   public static final class MediaDrm.KeyRequest {
@@ -24933,7 +24933,7 @@
     method @NonNull public String getDefaultUrl();
   }
 
-  @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) @IntDef({android.media.MediaDrm.SECURITY_LEVEL_UNKNOWN, android.media.MediaDrm.SECURITY_LEVEL_SW_SECURE_CRYPTO, android.media.MediaDrm.SECURITY_LEVEL_SW_SECURE_DECODE, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_CRYPTO, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_DECODE, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_ALL}) public static @interface MediaDrm.SecurityLevel {
+  @Deprecated @IntDef({android.media.MediaDrm.SECURITY_LEVEL_UNKNOWN, android.media.MediaDrm.SECURITY_LEVEL_SW_SECURE_CRYPTO, android.media.MediaDrm.SECURITY_LEVEL_SW_SECURE_DECODE, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_CRYPTO, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_DECODE, android.media.MediaDrm.SECURITY_LEVEL_HW_SECURE_ALL}) @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE) public static @interface MediaDrm.SecurityLevel {
   }
 
   public static final class MediaDrm.SessionException extends java.lang.RuntimeException {
@@ -43347,9 +43347,9 @@
   public abstract class CallRedirectionService extends android.app.Service {
     ctor public CallRedirectionService();
     method public final void cancelCall();
-    method public final android.os.IBinder onBind(android.content.Intent);
+    method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
     method public abstract void onPlaceCall(@NonNull android.net.Uri, @NonNull android.telecom.PhoneAccountHandle, boolean);
-    method public final boolean onUnbind(android.content.Intent);
+    method public final boolean onUnbind(@NonNull android.content.Intent);
     method public final void placeCallUnmodified();
     method public final void redirectCall(@NonNull android.net.Uri, @NonNull android.telecom.PhoneAccountHandle, boolean);
     field public static final String SERVICE_INTERFACE = "android.telecom.CallRedirectionService";
@@ -45554,7 +45554,7 @@
     method public boolean isEnabled();
     method public void startResolutionActivity(android.app.Activity, int, android.content.Intent, android.app.PendingIntent) throws android.content.IntentSender.SendIntentException;
     method @RequiresPermission("android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS") public void switchToSubscription(int, android.app.PendingIntent);
-    method @RequiresPermission("android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS") public void updateSubscriptionNickname(int, String, android.app.PendingIntent);
+    method @RequiresPermission("android.permission.WRITE_EMBEDDED_SUBSCRIPTIONS") public void updateSubscriptionNickname(int, @Nullable String, @NonNull android.app.PendingIntent);
     field public static final String ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS = "android.telephony.euicc.action.MANAGE_EMBEDDED_SUBSCRIPTIONS";
     field public static final String ACTION_NOTIFY_CARRIER_SETUP_INCOMPLETE = "android.telephony.euicc.action.NOTIFY_CARRIER_SETUP_INCOMPLETE";
     field public static final int EMBEDDED_SUBSCRIPTION_RESULT_ERROR = 2; // 0x2
@@ -53491,27 +53491,12 @@
     method @Nullable public <T> android.view.inspector.InspectionCompanion<T> provide(@NonNull Class<T>);
   }
 
-  public final class IntEnumMapping {
-    method @Nullable public String get(int);
-  }
-
-  public static final class IntEnumMapping.Builder {
-    ctor public IntEnumMapping.Builder();
-    method @NonNull public android.view.inspector.IntEnumMapping.Builder addValue(@NonNull String, int);
-    method @NonNull public android.view.inspector.IntEnumMapping build();
-  }
-
   public final class IntFlagMapping {
+    ctor public IntFlagMapping();
+    method public void add(int, int, @NonNull String);
     method @NonNull public java.util.Set<java.lang.String> get(int);
   }
 
-  public static final class IntFlagMapping.Builder {
-    ctor public IntFlagMapping.Builder();
-    method @NonNull public android.view.inspector.IntFlagMapping.Builder addFlag(@NonNull String, int);
-    method @NonNull public android.view.inspector.IntFlagMapping.Builder addFlag(@NonNull String, int, int);
-    method @NonNull public android.view.inspector.IntFlagMapping build();
-  }
-
   public interface PropertyMapper {
     method public int mapBoolean(@NonNull String, @AttrRes int);
     method public int mapByte(@NonNull String, @AttrRes int);
@@ -53521,8 +53506,8 @@
     method public int mapFloat(@NonNull String, @AttrRes int);
     method public int mapGravity(@NonNull String, @AttrRes int);
     method public int mapInt(@NonNull String, @AttrRes int);
-    method public int mapIntEnum(@NonNull String, @AttrRes int, @NonNull android.view.inspector.IntEnumMapping);
-    method public int mapIntFlag(@NonNull String, @AttrRes int, @NonNull android.view.inspector.IntFlagMapping);
+    method public int mapIntEnum(@NonNull String, @AttrRes int, @NonNull java.util.function.IntFunction<java.lang.String>);
+    method public int mapIntFlag(@NonNull String, @AttrRes int, @NonNull java.util.function.IntFunction<java.util.Set<java.lang.String>>);
     method public int mapLong(@NonNull String, @AttrRes int);
     method public int mapObject(@NonNull String, @AttrRes int);
     method public int mapResourceId(@NonNull String, @AttrRes int);
diff --git a/api/system-current.txt b/api/system-current.txt
index ed68bad..61a7f58 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -312,7 +312,7 @@
   public class AppOpsManager {
     method @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) public void getHistoricalOps(@NonNull android.app.AppOpsManager.HistoricalOpsRequest, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<android.app.AppOpsManager.HistoricalOps>);
     method public static String[] getOpStrs();
-    method @Deprecated @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) public java.util.List<android.app.AppOpsManager.PackageOps> getOpsForPackage(int, String, int[]);
+    method @Deprecated @NonNull @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) public java.util.List<android.app.AppOpsManager.PackageOps> getOpsForPackage(int, @NonNull String, @Nullable int[]);
     method @NonNull @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) public java.util.List<android.app.AppOpsManager.PackageOps> getOpsForPackage(int, @NonNull String, @Nullable java.lang.String...);
     method @NonNull @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS) public java.util.List<android.app.AppOpsManager.PackageOps> getPackagesForOps(@Nullable String[]);
     method public static int opToDefaultMode(@NonNull String);
@@ -465,7 +465,7 @@
 
   public static final class AppOpsManager.PackageOps implements android.os.Parcelable {
     method public int describeContents();
-    method public java.util.List<android.app.AppOpsManager.OpEntry> getOps();
+    method @NonNull public java.util.List<android.app.AppOpsManager.OpEntry> getOps();
     method @NonNull public String getPackageName();
     method public int getUid();
     method public void writeToParcel(android.os.Parcel, int);
@@ -546,10 +546,8 @@
 
   public class NotificationManager {
     method @Nullable public android.content.ComponentName getAllowedNotificationAssistant();
-    method @Nullable public android.content.ComponentName getAllowedNotificationAssistantForUser(@NonNull android.os.UserHandle);
     method public boolean isNotificationAssistantAccessGranted(@NonNull android.content.ComponentName);
     method public void setNotificationAssistantAccessGranted(@Nullable android.content.ComponentName, boolean);
-    method public void setNotificationAssistantAccessGrantedForUser(@Nullable android.content.ComponentName, @NonNull android.os.UserHandle, boolean);
   }
 
   public final class StatsManager {
@@ -985,6 +983,7 @@
 
   public final class ContentSuggestionsManager {
     method public void classifyContentSelections(@NonNull android.app.contentsuggestions.ClassificationsRequest, @NonNull java.util.concurrent.Executor, @NonNull android.app.contentsuggestions.ContentSuggestionsManager.ClassificationsCallback);
+    method public boolean isEnabled();
     method public void notifyInteraction(@NonNull String, @NonNull android.os.Bundle);
     method public void provideContextImage(int, @NonNull android.os.Bundle);
     method public void suggestContentSelections(@NonNull android.app.contentsuggestions.SelectionsRequest, @NonNull java.util.concurrent.Executor, @NonNull android.app.contentsuggestions.ContentSuggestionsManager.SelectionsCallback);
@@ -1198,6 +1197,7 @@
     method public int getUsageSource();
     method @RequiresPermission(allOf={android.Manifest.permission.SUSPEND_APPS, android.Manifest.permission.OBSERVE_APP_USAGE}) public void registerAppUsageLimitObserver(int, @NonNull String[], @NonNull java.time.Duration, @NonNull java.time.Duration, @Nullable android.app.PendingIntent);
     method @RequiresPermission(android.Manifest.permission.OBSERVE_APP_USAGE) public void registerAppUsageObserver(int, @NonNull String[], long, @NonNull java.util.concurrent.TimeUnit, @NonNull android.app.PendingIntent);
+    method @Deprecated @RequiresPermission(android.Manifest.permission.OBSERVE_APP_USAGE) public void registerUsageSessionObserver(int, @NonNull String[], long, @NonNull java.util.concurrent.TimeUnit, long, @NonNull java.util.concurrent.TimeUnit, @NonNull android.app.PendingIntent, @Nullable android.app.PendingIntent);
     method @RequiresPermission(android.Manifest.permission.OBSERVE_APP_USAGE) public void registerUsageSessionObserver(int, @NonNull String[], @NonNull java.time.Duration, @NonNull java.time.Duration, @NonNull android.app.PendingIntent, @Nullable android.app.PendingIntent);
     method public void reportUsageStart(@NonNull android.app.Activity, @NonNull String);
     method public void reportUsageStart(@NonNull android.app.Activity, @NonNull String, long);
@@ -1603,7 +1603,6 @@
     method @RequiresPermission("android.permission.OBSERVE_GRANT_REVOKE_PERMISSIONS") public abstract void addOnPermissionsChangeListener(android.content.pm.PackageManager.OnPermissionsChangedListener);
     method public abstract boolean arePermissionsIndividuallyControlled();
     method public abstract java.util.List<android.content.IntentFilter> getAllIntentFilters(String);
-    method public boolean getAppDetailsActivityEnabled(@NonNull String);
     method @NonNull @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS) public android.content.pm.ApplicationInfo getApplicationInfoAsUser(@NonNull String, int, @NonNull android.os.UserHandle) throws android.content.pm.PackageManager.NameNotFoundException;
     method @NonNull public android.content.pm.dex.ArtManager getArtManager();
     method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public abstract String getDefaultBrowserPackageNameAsUser(int);
@@ -1617,6 +1616,7 @@
     method public abstract java.util.List<android.content.pm.IntentFilterVerificationInfo> getIntentFilterVerifications(String);
     method @RequiresPermission(android.Manifest.permission.INTERACT_ACROSS_USERS_FULL) public abstract int getIntentVerificationStatusAsUser(String, int);
     method @android.content.pm.PackageManager.PermissionFlags @RequiresPermission(anyOf={android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS, android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS, android.Manifest.permission.GET_RUNTIME_PERMISSIONS}) public abstract int getPermissionFlags(String, String, @NonNull android.os.UserHandle);
+    method public boolean getSyntheticAppDetailsActivityEnabled(@NonNull String);
     method @NonNull @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] getUnsuspendablePackages(@NonNull String[]);
     method @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS) public abstract void grantRuntimePermission(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
     method @Deprecated public abstract int installExistingPackage(String) throws android.content.pm.PackageManager.NameNotFoundException;
@@ -1630,12 +1630,12 @@
     method @Deprecated public void replacePreferredActivity(@NonNull android.content.IntentFilter, int, @NonNull java.util.List<android.content.ComponentName>, @NonNull android.content.ComponentName);
     method @RequiresPermission(android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS) public abstract void revokeRuntimePermission(@NonNull String, @NonNull String, @NonNull android.os.UserHandle);
     method public void sendDeviceCustomizationReadyBroadcast();
-    method @RequiresPermission(value=android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE, conditional=true) public void setAppDetailsActivityEnabled(@NonNull String, boolean);
     method @RequiresPermission(allOf={android.Manifest.permission.SET_PREFERRED_APPLICATIONS, android.Manifest.permission.INTERACT_ACROSS_USERS_FULL}) public abstract boolean setDefaultBrowserPackageNameAsUser(String, int);
     method @NonNull @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] setDistractingPackageRestrictions(@NonNull String[], int);
     method @RequiresPermission(android.Manifest.permission.SET_HARMFUL_APP_WARNINGS) public void setHarmfulAppWarning(@NonNull String, @Nullable CharSequence);
     method @Deprecated @Nullable @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] setPackagesSuspended(@Nullable String[], boolean, @Nullable android.os.PersistableBundle, @Nullable android.os.PersistableBundle, @Nullable String);
     method @Nullable @RequiresPermission(android.Manifest.permission.SUSPEND_APPS) public String[] setPackagesSuspended(@Nullable String[], boolean, @Nullable android.os.PersistableBundle, @Nullable android.os.PersistableBundle, @Nullable android.content.pm.SuspendDialogInfo);
+    method @RequiresPermission(value=android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE, conditional=true) public void setSyntheticAppDetailsActivityEnabled(@NonNull String, boolean);
     method @RequiresPermission(android.Manifest.permission.INSTALL_PACKAGES) public abstract void setUpdateAvailable(String, boolean);
     method @RequiresPermission(android.Manifest.permission.SET_PREFERRED_APPLICATIONS) public abstract boolean updateIntentVerificationStatusAsUser(String, int, int);
     method @RequiresPermission(anyOf={android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS, android.Manifest.permission.REVOKE_RUNTIME_PERMISSIONS}) public abstract void updatePermissionFlags(String, String, @android.content.pm.PackageManager.PermissionFlags int, @android.content.pm.PackageManager.PermissionFlags int, @NonNull android.os.UserHandle);
@@ -5448,7 +5448,7 @@
     method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setAdaptivePowerSaveEnabled(boolean);
     method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setAdaptivePowerSavePolicy(@NonNull android.os.BatterySaverPolicyConfig);
     method @RequiresPermission(android.Manifest.permission.POWER_SAVER) public boolean setDynamicPowerSavings(boolean, int);
-    method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setPowerSaveMode(boolean);
+    method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.POWER_SAVER}) public boolean setPowerSaveModeEnabled(boolean);
     method @RequiresPermission(anyOf={android.Manifest.permission.DEVICE_POWER, android.Manifest.permission.USER_ACTIVITY}) public void userActivity(long, int, int);
     field public static final int POWER_SAVER_MODE_DYNAMIC = 1; // 0x1
     field public static final int POWER_SAVER_MODE_PERCENTAGE = 0; // 0x0
@@ -6428,6 +6428,7 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.service.contentcapture.ActivityEvent> CREATOR;
     field public static final int TYPE_ACTIVITY_PAUSED = 2; // 0x2
     field public static final int TYPE_ACTIVITY_RESUMED = 1; // 0x1
+    field public static final int TYPE_ACTIVITY_STOPPED = 23; // 0x17
   }
 
   public abstract class ContentCaptureService extends android.app.Service {
@@ -7155,9 +7156,10 @@
 
 package android.telephony {
 
-  public static final class AccessNetworkConstants.TransportType {
-    field public static final int WLAN = 2; // 0x2
-    field public static final int WWAN = 1; // 0x1
+  public final class AccessNetworkConstants {
+    field public static final int TRANSPORT_TYPE_INVALID = -1; // 0xffffffff
+    field public static final int TRANSPORT_TYPE_WLAN = 2; // 0x2
+    field public static final int TRANSPORT_TYPE_WWAN = 1; // 0x1
   }
 
   public final class CallAttributes implements android.os.Parcelable {
@@ -8029,7 +8031,7 @@
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean getEmergencyCallbackMode();
     method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getIsimDomain();
     method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getIsimIst();
-    method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.List<android.util.Pair<java.lang.Integer,java.lang.Integer>> getLogicalToPhysicalSlotMapping();
+    method @NonNull @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public java.util.Map<java.lang.Integer,java.lang.Integer> getLogicalToPhysicalSlotMapping();
     method public static long getMaxNumberVerificationTimeoutMillis();
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public long getPreferredNetworkTypeBitmask();
     method @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public int getRadioPowerState();
diff --git a/api/system-removed.txt b/api/system-removed.txt
index 2c65029..18d0ec0 100644
--- a/api/system-removed.txt
+++ b/api/system-removed.txt
@@ -28,14 +28,6 @@
 
 }
 
-package android.app.usage {
-
-  public final class UsageStatsManager {
-    method @Deprecated @RequiresPermission(android.Manifest.permission.OBSERVE_APP_USAGE) public void registerUsageSessionObserver(int, @NonNull String[], long, @NonNull java.util.concurrent.TimeUnit, long, @NonNull java.util.concurrent.TimeUnit, @NonNull android.app.PendingIntent, @Nullable android.app.PendingIntent);
-  }
-
-}
-
 package android.content {
 
   public class Intent implements java.lang.Cloneable android.os.Parcelable {
diff --git a/api/test-current.txt b/api/test-current.txt
index b392a50..4ccfa1c 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -146,7 +146,7 @@
     method @RequiresPermission("android.permission.MANAGE_APP_OPS_MODES") public void setUidMode(String, int, int);
     method public void startWatchingActive(@NonNull int[], @NonNull android.app.AppOpsManager.OnOpActiveChangedListener);
     method public void stopWatchingActive(@NonNull android.app.AppOpsManager.OnOpActiveChangedListener);
-    method public static int strOpToOp(String);
+    method public static int strOpToOp(@NonNull String);
     field public static final int HISTORICAL_MODE_DISABLED = 0; // 0x0
     field public static final int HISTORICAL_MODE_ENABLED_ACTIVE = 1; // 0x1
     field public static final int HISTORICAL_MODE_ENABLED_PASSIVE = 2; // 0x2
@@ -1762,7 +1762,7 @@
   public final class PowerManager {
     method @RequiresPermission("android.permission.POWER_SAVER") public int getPowerSaveMode();
     method @RequiresPermission("android.permission.POWER_SAVER") public boolean setDynamicPowerSavings(boolean, int);
-    method @RequiresPermission(anyOf={"android.permission.DEVICE_POWER", "android.permission.POWER_SAVER"}) public boolean setPowerSaveMode(boolean);
+    method @RequiresPermission(anyOf={"android.permission.DEVICE_POWER", "android.permission.POWER_SAVER"}) public boolean setPowerSaveModeEnabled(boolean);
     field public static final int POWER_SAVER_MODE_DYNAMIC = 1; // 0x1
     field public static final int POWER_SAVER_MODE_PERCENTAGE = 0; // 0x0
   }
@@ -2396,6 +2396,7 @@
     field @NonNull public static final android.os.Parcelable.Creator<android.service.contentcapture.ActivityEvent> CREATOR;
     field public static final int TYPE_ACTIVITY_PAUSED = 2; // 0x2
     field public static final int TYPE_ACTIVITY_RESUMED = 1; // 0x1
+    field public static final int TYPE_ACTIVITY_STOPPED = 23; // 0x17
   }
 
   public abstract class ContentCaptureService extends android.app.Service {
diff --git a/cmds/statsd/src/StatsService.cpp b/cmds/statsd/src/StatsService.cpp
index 1526d66..f78ae38 100644
--- a/cmds/statsd/src/StatsService.cpp
+++ b/cmds/statsd/src/StatsService.cpp
@@ -1198,30 +1198,48 @@
     }
     // TODO: add verifier permission
 
-    userid_t userId = multiuser_get_user_id(uid);
+    bool readTrainInfoSuccess = false;
+    InstallTrainInfo trainInfo;
+    if (trainVersionCode == -1 || experimentIds.empty() || trainName.size() == 0) {
+        readTrainInfoSuccess = StorageManager::readTrainInfo(trainInfo);
+    }
 
-    bool requiresStaging = options & IStatsManager::FLAG_REQUIRE_STAGING;
-    bool rollbackEnabled = options & IStatsManager::FLAG_ROLLBACK_ENABLED;
-    bool requiresLowLatencyMonitor = options & IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR;
-
-    ProtoOutputStream proto;
-    for (const auto& expId : experimentIds) {
-        proto.write(FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_EXPERIMENT_ID,
-                    (long long)expId);
+    if (trainVersionCode == -1 && readTrainInfoSuccess) {
+        trainVersionCode = trainInfo.trainVersionCode;
     }
 
     vector<uint8_t> experimentIdsProtoBuffer;
-    experimentIdsProtoBuffer.resize(proto.size());
-    size_t pos = 0;
-    auto iter = proto.data();
-    while (iter.readBuffer() != NULL) {
-        size_t toRead = iter.currentToRead();
-        std::memcpy(&(experimentIdsProtoBuffer[pos]), iter.readBuffer(), toRead);
-        pos += toRead;
-        iter.rp()->move(toRead);
+    if (readTrainInfoSuccess && experimentIds.empty()) {
+        experimentIdsProtoBuffer = trainInfo.experimentIds;
+    } else {
+        ProtoOutputStream proto;
+        for (const auto& expId : experimentIds) {
+            proto.write(FIELD_TYPE_INT64 | FIELD_COUNT_REPEATED | FIELD_ID_EXPERIMENT_ID,
+                        (long long)expId);
+        }
+
+        experimentIdsProtoBuffer.resize(proto.size());
+        size_t pos = 0;
+        auto iter = proto.data();
+        while (iter.readBuffer() != NULL) {
+            size_t toRead = iter.currentToRead();
+            std::memcpy(&(experimentIdsProtoBuffer[pos]), iter.readBuffer(), toRead);
+            pos += toRead;
+            iter.rp()->move(toRead);
+        }
     }
 
-    std::string trainNameUtf8 = std::string(String8(trainName).string());
+    std::string trainNameUtf8;
+    if (readTrainInfoSuccess && trainName.size() == 0) {
+        trainNameUtf8 = trainInfo.trainName;
+    } else {
+        trainNameUtf8 = std::string(String8(trainName).string());
+    }
+
+    userid_t userId = multiuser_get_user_id(uid);
+    bool requiresStaging = options & IStatsManager::FLAG_REQUIRE_STAGING;
+    bool rollbackEnabled = options & IStatsManager::FLAG_ROLLBACK_ENABLED;
+    bool requiresLowLatencyMonitor = options & IStatsManager::FLAG_REQUIRE_LOW_LATENCY_MONITOR;
     LogEvent event(trainNameUtf8, trainVersionCode, requiresStaging, rollbackEnabled,
                    requiresLowLatencyMonitor, state, experimentIdsProtoBuffer, userId);
     mProcessor->OnLogEvent(&event);
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 3246d19..b8e8fdc 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -4913,7 +4913,7 @@
   // since boot, not including sleep (see SystemClock.uptimeMillis()).
   optional int64 last_compact_timestamp_ms_since_boot = 14;
 
-  // The oom_score_adj at the time of compaction.
+  // The "setAdj" (i.e. previous) oom_score_adj at the time of compaction.
   optional int32 oom_score_adj = 15;
 
   // The process state at the time of compaction.
diff --git a/core/java/android/app/ActivityOptions.java b/core/java/android/app/ActivityOptions.java
index e2d868f..da9ea83 100644
--- a/core/java/android/app/ActivityOptions.java
+++ b/core/java/android/app/ActivityOptions.java
@@ -222,6 +222,13 @@
     private static final String KEY_AVOID_MOVE_TO_FRONT = "android.activity.avoidMoveToFront";
 
     /**
+     * See {@link #setFreezeRecentTasksReordering()}.
+     * @hide
+     */
+    private static final String KEY_FREEZE_RECENT_TASKS_REORDERING =
+            "android.activity.freezeRecentTasksReordering";
+
+    /**
      * Where the split-screen-primary stack should be positioned.
      * @hide
      */
@@ -324,6 +331,7 @@
     private boolean mTaskOverlay;
     private boolean mTaskOverlayCanResume;
     private boolean mAvoidMoveToFront;
+    private boolean mFreezeRecentTasksReordering;
     private AppTransitionAnimationSpec mAnimSpecs[];
     private int mRotationAnimationHint = -1;
     private Bundle mAppVerificationBundle;
@@ -946,6 +954,7 @@
         mTaskOverlay = opts.getBoolean(KEY_TASK_OVERLAY, false);
         mTaskOverlayCanResume = opts.getBoolean(KEY_TASK_OVERLAY_CAN_RESUME, false);
         mAvoidMoveToFront = opts.getBoolean(KEY_AVOID_MOVE_TO_FRONT, false);
+        mFreezeRecentTasksReordering = opts.getBoolean(KEY_FREEZE_RECENT_TASKS_REORDERING, false);
         mSplitScreenCreateMode = opts.getInt(KEY_SPLIT_SCREEN_CREATE_MODE,
                 SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT);
         mDisallowEnterPictureInPictureWhileLaunching = opts.getBoolean(
@@ -1304,6 +1313,24 @@
         return mAvoidMoveToFront;
     }
 
+    /**
+     * Sets whether the launch of this activity should freeze the recent task list reordering until
+     * the next user interaction or timeout. This flag is only applied when starting an activity
+     * in recents.
+     * @hide
+     */
+    public void setFreezeRecentTasksReordering() {
+        mFreezeRecentTasksReordering = true;
+    }
+
+    /**
+     * @return whether the launch of this activity should freeze the recent task list reordering
+     * @hide
+     */
+    public boolean freezeRecentTasksReordering() {
+        return mFreezeRecentTasksReordering;
+    }
+
     /** @hide */
     public int getSplitScreenCreateMode() {
         return mSplitScreenCreateMode;
@@ -1502,6 +1529,9 @@
         if (mAvoidMoveToFront) {
             b.putBoolean(KEY_AVOID_MOVE_TO_FRONT, mAvoidMoveToFront);
         }
+        if (mFreezeRecentTasksReordering) {
+            b.putBoolean(KEY_FREEZE_RECENT_TASKS_REORDERING, mFreezeRecentTasksReordering);
+        }
         if (mSplitScreenCreateMode != SPLIT_SCREEN_CREATE_MODE_TOP_OR_LEFT) {
             b.putInt(KEY_SPLIT_SCREEN_CREATE_MODE, mSplitScreenCreateMode);
         }
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 08239a1..c0a702f 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -3115,10 +3115,6 @@
         if (!r.stopped) {
             throw new IllegalStateException("Can't start activity that is not stopped.");
         }
-        if (r.activity.mFinished) {
-            // TODO(lifecycler): How can this happen?
-            return;
-        }
 
         // Start
         activity.performStart("handleStartActivity");
@@ -3241,6 +3237,8 @@
             if (!r.activity.mFinished && pendingActions != null) {
                 pendingActions.setOldState(r.state);
                 pendingActions.setRestoreInstanceState(true);
+            }
+            if (pendingActions != null) {
                 pendingActions.setCallOnPostCreate(true);
             }
         } else {
@@ -3942,7 +3940,7 @@
         if (localLOGV) {
             Slog.v(TAG, "Performing resume of " + r + " finished=" + r.activity.mFinished);
         }
-        if (r == null || r.activity.mFinished) {
+        if (r == null) {
             return null;
         }
         if (r.getLifecycleState() == ON_RESUME) {
@@ -4212,12 +4210,6 @@
     private Bundle performPauseActivity(ActivityClientRecord r, boolean finished, String reason,
             PendingTransactionActions pendingActions) {
         if (r.paused) {
-            if (r.activity.mFinished) {
-                // If we are finishing, we won't call onResume() in certain cases.
-                // So here we likewise don't want to call onPause() if the activity
-                // isn't resumed.
-                return null;
-            }
             RuntimeException e = new RuntimeException(
                     "Performing pause of activity that is not resumed: "
                     + r.intent.getComponent().toShortString());
@@ -4337,20 +4329,13 @@
             boolean saveState, boolean finalStateRequest, String reason) {
         if (localLOGV) Slog.v(TAG, "Performing stop of " + r);
         if (r != null) {
-            if (!keepShown && r.stopped) {
-                if (r.activity.mFinished) {
-                    // If we are finishing, we won't call onResume() in certain
-                    // cases.  So here we likewise don't want to call onStop()
-                    // if the activity isn't resumed.
-                    return;
-                }
-                if (!finalStateRequest) {
-                    final RuntimeException e = new RuntimeException(
-                            "Performing stop of activity that is already stopped: "
-                                    + r.intent.getComponent().toShortString());
-                    Slog.e(TAG, e.getMessage(), e);
-                    Slog.e(TAG, r.getStateString());
-                }
+            if (!keepShown && r.stopped && !finalStateRequest) {
+                // Double stop request is possible if activity receives 'sleep' followed by 'stop'.
+                final RuntimeException e = new RuntimeException(
+                        "Performing stop of activity that is already stopped: "
+                                + r.intent.getComponent().toShortString());
+                Slog.e(TAG, e.getMessage(), e);
+                Slog.e(TAG, r.getStateString());
             }
 
             // One must first be paused before stopped...
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index 91df05f..1066fc7 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -2214,7 +2214,7 @@
         /**
          * @return The ops of the package.
          */
-        public List<OpEntry> getOps() {
+        public @NonNull List<OpEntry> getOps() {
             return mEntries;
         }
 
@@ -4371,7 +4371,8 @@
     @Deprecated
     @SystemApi
     @RequiresPermission(android.Manifest.permission.GET_APP_OPS_STATS)
-    public List<PackageOps> getOpsForPackage(int uid, String packageName, int[] ops) {
+    public @NonNull List<PackageOps> getOpsForPackage(int uid, @NonNull String packageName,
+            @Nullable int[] ops) {
         try {
             return mService.getOpsForPackage(uid, packageName, ops);
         } catch (RemoteException e) {
@@ -4639,8 +4640,8 @@
      * @param packageName The name of the application to monitor.
      * @param callback Where to report changes.
      */
-    public void startWatchingMode(String op, String packageName,
-            final OnOpChangedListener callback) {
+    public void startWatchingMode(@NonNull String op, @Nullable String packageName,
+            @NonNull final OnOpChangedListener callback) {
         startWatchingMode(strOpToOp(op), packageName, callback);
     }
 
@@ -4653,8 +4654,8 @@
      * @param flags Option flags: any combination of {@link #WATCH_FOREGROUND_CHANGES} or 0.
      * @param callback Where to report changes.
      */
-    public void startWatchingMode(String op, String packageName, int flags,
-            final OnOpChangedListener callback) {
+    public void startWatchingMode(@NonNull String op, @Nullable String packageName, int flags,
+            @NonNull final OnOpChangedListener callback) {
         startWatchingMode(strOpToOp(op), packageName, flags, callback);
     }
 
@@ -4716,7 +4717,7 @@
      * Stop monitoring that was previously started with {@link #startWatchingMode}.  All
      * monitoring associated with this callback will be removed.
      */
-    public void stopWatchingMode(OnOpChangedListener callback) {
+    public void stopWatchingMode(@NonNull OnOpChangedListener callback) {
         synchronized (mModeWatchers) {
             IAppOpsCallback cb = mModeWatchers.remove(callback);
             if (cb != null) {
@@ -4875,7 +4876,7 @@
      * {@hide}
      */
     @TestApi
-    public static int strOpToOp(String op) {
+    public static int strOpToOp(@NonNull String op) {
         Integer val = sOpStrToOp.get(op);
         if (val == null) {
             throw new IllegalArgumentException("Unknown operation string: " + op);
@@ -4910,7 +4911,7 @@
      * causing the app to crash).
      * @throws SecurityException If the app has been configured to crash on this op.
      */
-    public int unsafeCheckOp(String op, int uid, String packageName) {
+    public int unsafeCheckOp(@NonNull String op, int uid, @NonNull String packageName) {
         return checkOp(strOpToOp(op), uid, packageName);
     }
 
@@ -4918,7 +4919,7 @@
      * @deprecated Renamed to {@link #unsafeCheckOp(String, int, String)}.
      */
     @Deprecated
-    public int checkOp(String op, int uid, String packageName) {
+    public int checkOp(@NonNull String op, int uid, @NonNull String packageName) {
         return checkOp(strOpToOp(op), uid, packageName);
     }
 
@@ -4926,7 +4927,7 @@
      * Like {@link #checkOp} but instead of throwing a {@link SecurityException} it
      * returns {@link #MODE_ERRORED}.
      */
-    public int unsafeCheckOpNoThrow(String op, int uid, String packageName) {
+    public int unsafeCheckOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
         return checkOpNoThrow(strOpToOp(op), uid, packageName);
     }
 
@@ -4934,7 +4935,7 @@
      * @deprecated Renamed to {@link #unsafeCheckOpNoThrow(String, int, String)}.
      */
     @Deprecated
-    public int checkOpNoThrow(String op, int uid, String packageName) {
+    public int checkOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
         return checkOpNoThrow(strOpToOp(op), uid, packageName);
     }
 
@@ -4942,7 +4943,7 @@
      * Like {@link #checkOp} but returns the <em>raw</em> mode associated with the op.
      * Does not throw a security exception, does not translate {@link #MODE_FOREGROUND}.
      */
-    public int unsafeCheckOpRaw(@NonNull String op, int uid, String packageName) {
+    public int unsafeCheckOpRaw(@NonNull String op, int uid, @NonNull String packageName) {
         try {
             return mService.checkOperationRaw(strOpToOp(op), uid, packageName);
         } catch (RemoteException e) {
@@ -4977,7 +4978,7 @@
      * causing the app to crash).
      * @throws SecurityException If the app has been configured to crash on this op.
      */
-    public int noteOp(String op, int uid, String packageName) {
+    public int noteOp(@NonNull String op, int uid, @NonNull String packageName) {
         return noteOp(strOpToOp(op), uid, packageName);
     }
 
@@ -4985,7 +4986,7 @@
      * Like {@link #noteOp} but instead of throwing a {@link SecurityException} it
      * returns {@link #MODE_ERRORED}.
      */
-    public int noteOpNoThrow(String op, int uid, String packageName) {
+    public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
         return noteOpNoThrow(strOpToOp(op), uid, packageName);
     }
 
@@ -5004,7 +5005,7 @@
      * causing the app to crash).
      * @throws SecurityException If the app has been configured to crash on this op.
      */
-    public int noteProxyOp(String op, String proxiedPackageName) {
+    public int noteProxyOp(@NonNull String op, @NonNull String proxiedPackageName) {
         return noteProxyOp(strOpToOp(op), proxiedPackageName);
     }
 
@@ -5015,7 +5016,7 @@
      * <p>This API requires the package with the {@code proxiedPackageName} to belongs to
      * {@link Binder#getCallingUid()}.
      */
-    public int noteProxyOpNoThrow(String op, String proxiedPackageName) {
+    public int noteProxyOpNoThrow(@NonNull String op, @NonNull String proxiedPackageName) {
         return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName);
     }
 
@@ -5051,7 +5052,7 @@
      * causing the app to crash).
      * @throws SecurityException If the app has been configured to crash on this op.
      */
-    public int startOp(String op, int uid, String packageName) {
+    public int startOp(@NonNull String op, int uid, @NonNull String packageName) {
         return startOp(strOpToOp(op), uid, packageName);
     }
 
@@ -5059,7 +5060,7 @@
      * Like {@link #startOp} but instead of throwing a {@link SecurityException} it
      * returns {@link #MODE_ERRORED}.
      */
-    public int startOpNoThrow(String op, int uid, String packageName) {
+    public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName) {
         return startOpNoThrow(strOpToOp(op), uid, packageName);
     }
 
@@ -5069,7 +5070,7 @@
      * or result; the parameters supplied here must be the exact same ones previously passed
      * in when starting the operation.
      */
-    public void finishOp(String op, int uid, String packageName) {
+    public void finishOp(@NonNull String op, int uid, @NonNull String packageName) {
         finishOp(strOpToOp(op), uid, packageName);
     }
 
@@ -5135,7 +5136,7 @@
      * @throws SecurityException if the package name doesn't belong to the given
      *             UID, or if ownership cannot be verified.
      */
-    public void checkPackage(int uid, String packageName) {
+    public void checkPackage(int uid, @NonNull String packageName) {
         try {
             if (mService.checkPackage(uid, packageName) != MODE_ALLOWED) {
                 throw new SecurityException(
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index bd47c9e..a226062 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -2468,7 +2468,7 @@
     }
 
     @Override
-    public void setAppDetailsActivityEnabled(String packageName, boolean enabled) {
+    public void setSyntheticAppDetailsActivityEnabled(String packageName, boolean enabled) {
         try {
             ComponentName componentName = new ComponentName(packageName,
                     PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME);
@@ -2482,7 +2482,7 @@
     }
 
     @Override
-    public boolean getAppDetailsActivityEnabled(String packageName) {
+    public boolean getSyntheticAppDetailsActivityEnabled(String packageName) {
         try {
             ComponentName componentName = new ComponentName(packageName,
                     PackageManager.APP_DETAILS_ACTIVITY_CLASS_NAME);
diff --git a/core/java/android/app/NotificationManager.java b/core/java/android/app/NotificationManager.java
index 204fb6a..11b40c2 100644
--- a/core/java/android/app/NotificationManager.java
+++ b/core/java/android/app/NotificationManager.java
@@ -1270,6 +1270,8 @@
 
     /**
      * Grants/revokes Notification Assistant access to {@code assistant} for current user.
+     * To grant access for a particular user, obtain this service by using the {@link Context}
+     * provided by {@link Context#createPackageContextAsUser}
      *
      * @param assistant Name of component to grant/revoke access or {@code null} to revoke access to
      *                  current assistant
@@ -1287,27 +1289,6 @@
         }
     }
 
-    /**
-     * Grants/revokes Notification Assistant access to {@code assistant} for given user.
-     *
-     * @param assistant Name of component to grant/revoke access or {@code null} to revoke access to
-     *                  current assistant
-     * @param user handle to associate assistant with
-     * @param granted Grant/revoke access
-     * @hide
-     */
-    @SystemApi
-    public void setNotificationAssistantAccessGrantedForUser(@Nullable ComponentName assistant,
-            @NonNull UserHandle user, boolean granted) {
-        INotificationManager service = getService();
-        try {
-            service.setNotificationAssistantAccessGrantedForUser(assistant, user.getIdentifier(),
-                    granted);
-        } catch (RemoteException e) {
-            throw e.rethrowFromSystemServer();
-        }
-    }
-
     /** @hide */
     public List<ComponentName> getEnabledNotificationListeners(int userId) {
         INotificationManager service = getService();
@@ -1320,18 +1301,6 @@
 
     /** @hide */
     @SystemApi
-    public @Nullable ComponentName getAllowedNotificationAssistantForUser(
-            @NonNull UserHandle user) {
-        INotificationManager service = getService();
-        try {
-            return service.getAllowedNotificationAssistantForUser(user.getIdentifier());
-        } catch (RemoteException e) {
-            throw e.rethrowFromSystemServer();
-        }
-    }
-
-    /** @hide */
-    @SystemApi
     public @Nullable ComponentName getAllowedNotificationAssistant() {
         INotificationManager service = getService();
         try {
diff --git a/core/java/android/app/SystemServiceRegistry.java b/core/java/android/app/SystemServiceRegistry.java
index 6103818..08e0880 100644
--- a/core/java/android/app/SystemServiceRegistry.java
+++ b/core/java/android/app/SystemServiceRegistry.java
@@ -1188,7 +1188,7 @@
                                 Context.CONTENT_SUGGESTIONS_SERVICE);
                         IContentSuggestionsManager service =
                                 IContentSuggestionsManager.Stub.asInterface(b);
-                        return new ContentSuggestionsManager(service);
+                        return new ContentSuggestionsManager(ctx.getUserId(), service);
                     }
                 });
 
diff --git a/core/java/android/app/admin/DevicePolicyEventLogger.java b/core/java/android/app/admin/DevicePolicyEventLogger.java
index c89d868..44ea218 100644
--- a/core/java/android/app/admin/DevicePolicyEventLogger.java
+++ b/core/java/android/app/admin/DevicePolicyEventLogger.java
@@ -178,7 +178,7 @@
     }
 
     /**
-     * Retrieves the package name of the admin application from the {@link ComponentName}.
+     * Sets the package name of the admin application from the {@link ComponentName}.
      */
     public DevicePolicyEventLogger setAdmin(@Nullable ComponentName componentName) {
         mAdminPackageName = (componentName != null ? componentName.getPackageName() : null);
diff --git a/core/java/android/app/contentsuggestions/ContentSuggestionsManager.java b/core/java/android/app/contentsuggestions/ContentSuggestionsManager.java
index b4d8977..1bb81b1 100644
--- a/core/java/android/app/contentsuggestions/ContentSuggestionsManager.java
+++ b/core/java/android/app/contentsuggestions/ContentSuggestionsManager.java
@@ -20,11 +20,14 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
+import android.annotation.UserIdInt;
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.util.Log;
 
+import com.android.internal.util.SyncResultReceiver;
+
 import java.util.List;
 import java.util.concurrent.Executor;
 
@@ -44,12 +47,22 @@
 public final class ContentSuggestionsManager {
     private static final String TAG = ContentSuggestionsManager.class.getSimpleName();
 
+    /**
+     * Timeout for calls to system_server.
+     */
+    private static final int SYNC_CALLS_TIMEOUT_MS = 5000;
+
     @Nullable
     private final IContentSuggestionsManager mService;
 
+    @NonNull
+    private final int mUser;
+
     /** @hide */
-    public ContentSuggestionsManager(@Nullable IContentSuggestionsManager service) {
+    public ContentSuggestionsManager(
+            @UserIdInt int userId, @Nullable IContentSuggestionsManager service) {
         mService = service;
+        mUser = userId;
     }
 
     /**
@@ -60,14 +73,15 @@
      * @param imageContextRequestExtras sent with with request to provide implementation specific
      *                                  extra information.
      */
-    public void provideContextImage(int taskId, @NonNull Bundle imageContextRequestExtras) {
+    public void provideContextImage(
+            int taskId, @NonNull Bundle imageContextRequestExtras) {
         if (mService == null) {
             Log.e(TAG, "provideContextImage called, but no ContentSuggestionsManager configured");
             return;
         }
 
         try {
-            mService.provideContextImage(taskId, imageContextRequestExtras);
+            mService.provideContextImage(mUser, taskId, imageContextRequestExtras);
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
         }
@@ -96,7 +110,7 @@
 
         try {
             mService.suggestContentSelections(
-                    request, new SelectionsCallbackWrapper(callback, callbackExecutor));
+                    mUser, request, new SelectionsCallbackWrapper(callback, callbackExecutor));
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
         }
@@ -123,7 +137,7 @@
 
         try {
             mService.classifyContentSelections(
-                    request, new ClassificationsCallbackWrapper(callback, callbackExecutor));
+                    mUser, request, new ClassificationsCallbackWrapper(callback, callbackExecutor));
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
         }
@@ -135,20 +149,42 @@
      * @param requestId the id for the associated interaction
      * @param interaction to report back to the system content suggestions service.
      */
-    public void notifyInteraction(@NonNull String requestId, @NonNull Bundle interaction) {
+    public void notifyInteraction(
+            @NonNull String requestId, @NonNull Bundle interaction) {
         if (mService == null) {
             Log.e(TAG, "notifyInteraction called, but no ContentSuggestionsManager configured");
             return;
         }
 
         try {
-            mService.notifyInteraction(requestId, interaction);
+            mService.notifyInteraction(mUser, requestId, interaction);
         } catch (RemoteException e) {
             e.rethrowFromSystemServer();
         }
     }
 
     /**
+     * Indicates that Content Suggestions is available and enabled for the provided user. That is,
+     * has an implementation and not disabled through device management.
+     *
+     * @return {@code true} if Content Suggestions is enabled and available for the provided user.
+     */
+    public boolean isEnabled() {
+        if (mService == null) {
+            return false;
+        }
+
+        SyncResultReceiver receiver = new SyncResultReceiver(SYNC_CALLS_TIMEOUT_MS);
+        try {
+            mService.isEnabled(mUser, receiver);
+            return receiver.getIntResult() != 0;
+        } catch (RemoteException e) {
+            e.rethrowFromSystemServer();
+        }
+        return false;
+    }
+
+    /**
      * Callback to receive content selections from
      *  {@link #suggestContentSelections(SelectionsRequest, Executor, SelectionsCallback)}.
      */
diff --git a/core/java/android/app/contentsuggestions/IContentSuggestionsManager.aidl b/core/java/android/app/contentsuggestions/IContentSuggestionsManager.aidl
index 24f5ad8..b18a758 100644
--- a/core/java/android/app/contentsuggestions/IContentSuggestionsManager.aidl
+++ b/core/java/android/app/contentsuggestions/IContentSuggestionsManager.aidl
@@ -21,17 +21,23 @@
 import android.app.contentsuggestions.ClassificationsRequest;
 import android.app.contentsuggestions.SelectionsRequest;
 import android.os.Bundle;
+import android.os.UserHandle;
+import com.android.internal.os.IResultReceiver;
 
 /** @hide */
 oneway interface IContentSuggestionsManager {
     void provideContextImage(
+            int userId,
             int taskId,
             in Bundle imageContextRequestExtras);
     void suggestContentSelections(
+            int userId,
             in SelectionsRequest request,
             in ISelectionsCallback callback);
     void classifyContentSelections(
+            int userId,
             in ClassificationsRequest request,
             in IClassificationsCallback callback);
-    void notifyInteraction(in String requestId, in Bundle interaction);
+    void notifyInteraction(int userId, in String requestId, in Bundle interaction);
+    void isEnabled(int userId, in IResultReceiver receiver);
 }
diff --git a/core/java/android/app/usage/UsageStatsManager.java b/core/java/android/app/usage/UsageStatsManager.java
index b5224c7..a6ceeb1 100644
--- a/core/java/android/app/usage/UsageStatsManager.java
+++ b/core/java/android/app/usage/UsageStatsManager.java
@@ -665,7 +665,6 @@
      * @deprecated use {@link #registerUsageSessionObserver(int, String[], Duration, Duration,
      *                                                      PendingIntent, PendingIntent)}.
      *
-     * @removed
      * @hide
      */
     @Deprecated
diff --git a/core/java/android/content/LoggingContentInterface.java b/core/java/android/content/LoggingContentInterface.java
index 26d01b9..6e12a57 100644
--- a/core/java/android/content/LoggingContentInterface.java
+++ b/core/java/android/content/LoggingContentInterface.java
@@ -66,7 +66,12 @@
         } else {
             sb.append(" = ").append(deepToString(res));
         }
-        Log.v(tag, sb.toString());
+
+        if (res instanceof Exception) {
+            Log.e(tag, sb.toString());
+        } else {
+            Log.v(tag, sb.toString());
+        }
     }
 
     private String deepToString(Object value) {
@@ -81,119 +86,194 @@
     public @Nullable Cursor query(@NonNull Uri uri, @Nullable String[] projection,
             @Nullable Bundle queryArgs, @Nullable CancellationSignal cancellationSignal)
             throws RemoteException {
-        final Cursor res = delegate.query(uri, projection, queryArgs, cancellationSignal);
-        log("query", res, uri, projection, queryArgs, cancellationSignal);
-        return res;
+        try {
+            final Cursor res = delegate.query(uri, projection, queryArgs, cancellationSignal);
+            log("query", res, uri, projection, queryArgs, cancellationSignal);
+            return res;
+        } catch (Exception res) {
+            log("query", res, uri, projection, queryArgs, cancellationSignal);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable String getType(@NonNull Uri uri) throws RemoteException {
-        final String res = delegate.getType(uri);
-        log("getType", res, uri);
-        return res;
+        try {
+            final String res = delegate.getType(uri);
+            log("getType", res, uri);
+            return res;
+        } catch (Exception res) {
+            log("getType", res, uri);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable String[] getStreamTypes(@NonNull Uri uri, @NonNull String mimeTypeFilter)
             throws RemoteException {
-        final String[] res = delegate.getStreamTypes(uri, mimeTypeFilter);
-        log("getStreamTypes", res, uri, mimeTypeFilter);
-        return res;
+        try {
+            final String[] res = delegate.getStreamTypes(uri, mimeTypeFilter);
+            log("getStreamTypes", res, uri, mimeTypeFilter);
+            return res;
+        } catch (Exception res) {
+            log("getStreamTypes", res, uri, mimeTypeFilter);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable Uri canonicalize(@NonNull Uri uri) throws RemoteException {
-        final Uri res = delegate.canonicalize(uri);
-        log("canonicalize", res, uri);
-        return res;
+        try {
+            final Uri res = delegate.canonicalize(uri);
+            log("canonicalize", res, uri);
+            return res;
+        } catch (Exception res) {
+            log("canonicalize", res, uri);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable Uri uncanonicalize(@NonNull Uri uri) throws RemoteException {
-        final Uri res = delegate.uncanonicalize(uri);
-        log("uncanonicalize", res, uri);
-        return res;
+        try {
+            final Uri res = delegate.uncanonicalize(uri);
+            log("uncanonicalize", res, uri);
+            return res;
+        } catch (Exception res) {
+            log("uncanonicalize", res, uri);
+            throw res;
+        }
     }
 
     @Override
     public boolean refresh(@NonNull Uri uri, @Nullable Bundle args,
             @Nullable CancellationSignal cancellationSignal) throws RemoteException {
-        final boolean res = delegate.refresh(uri, args, cancellationSignal);
-        log("refresh", res, uri, args, cancellationSignal);
-        return res;
+        try {
+            final boolean res = delegate.refresh(uri, args, cancellationSignal);
+            log("refresh", res, uri, args, cancellationSignal);
+            return res;
+        } catch (Exception res) {
+            log("refresh", res, uri, args, cancellationSignal);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable Uri insert(@NonNull Uri uri, @Nullable ContentValues initialValues)
             throws RemoteException {
-        final Uri res = delegate.insert(uri, initialValues);
-        log("insert", res, uri, initialValues);
-        return res;
+        try {
+            final Uri res = delegate.insert(uri, initialValues);
+            log("insert", res, uri, initialValues);
+            return res;
+        } catch (Exception res) {
+            log("insert", res, uri, initialValues);
+            throw res;
+        }
     }
 
     @Override
     public int bulkInsert(@NonNull Uri uri, @NonNull ContentValues[] initialValues)
             throws RemoteException {
-        final int res = delegate.bulkInsert(uri, initialValues);
-        log("bulkInsert", res, uri, initialValues);
-        return res;
+        try {
+            final int res = delegate.bulkInsert(uri, initialValues);
+            log("bulkInsert", res, uri, initialValues);
+            return res;
+        } catch (Exception res) {
+            log("bulkInsert", res, uri, initialValues);
+            throw res;
+        }
     }
 
     @Override
     public int delete(@NonNull Uri uri, @Nullable String selection,
             @Nullable String[] selectionArgs) throws RemoteException {
-        final int res = delegate.delete(uri, selection, selectionArgs);
-        log("delete", res, uri, selection, selectionArgs);
-        return res;
+        try {
+            final int res = delegate.delete(uri, selection, selectionArgs);
+            log("delete", res, uri, selection, selectionArgs);
+            return res;
+        } catch (Exception res) {
+            log("delete", res, uri, selection, selectionArgs);
+            throw res;
+        }
     }
 
     @Override
     public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection,
             @Nullable String[] selectionArgs) throws RemoteException {
-        final int res = delegate.update(uri, values, selection, selectionArgs);
-        log("update", res, uri, values, selection, selectionArgs);
-        return res;
+        try {
+            final int res = delegate.update(uri, values, selection, selectionArgs);
+            log("update", res, uri, values, selection, selectionArgs);
+            return res;
+        } catch (Exception res) {
+            log("update", res, uri, values, selection, selectionArgs);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode,
             @Nullable CancellationSignal signal) throws RemoteException, FileNotFoundException {
-        final ParcelFileDescriptor res = delegate.openFile(uri, mode, signal);
-        log("openFile", res, uri, mode, signal);
-        return res;
+        try {
+            final ParcelFileDescriptor res = delegate.openFile(uri, mode, signal);
+            log("openFile", res, uri, mode, signal);
+            return res;
+        } catch (Exception res) {
+            log("openFile", res, uri, mode, signal);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable AssetFileDescriptor openAssetFile(@NonNull Uri uri, @NonNull String mode,
             @Nullable CancellationSignal signal) throws RemoteException, FileNotFoundException {
-        final AssetFileDescriptor res = delegate.openAssetFile(uri, mode, signal);
-        log("openAssetFile", res, uri, mode, signal);
-        return res;
+        try {
+            final AssetFileDescriptor res = delegate.openAssetFile(uri, mode, signal);
+            log("openAssetFile", res, uri, mode, signal);
+            return res;
+        } catch (Exception res) {
+            log("openAssetFile", res, uri, mode, signal);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable AssetFileDescriptor openTypedAssetFile(@NonNull Uri uri,
             @NonNull String mimeTypeFilter, @Nullable Bundle opts,
             @Nullable CancellationSignal signal) throws RemoteException, FileNotFoundException {
-        final AssetFileDescriptor res = delegate.openTypedAssetFile(uri, mimeTypeFilter, opts, signal);
-        log("openTypedAssetFile", res, uri, mimeTypeFilter, opts, signal);
-        return res;
+        try {
+            final AssetFileDescriptor res = delegate.openTypedAssetFile(uri, mimeTypeFilter, opts, signal);
+            log("openTypedAssetFile", res, uri, mimeTypeFilter, opts, signal);
+            return res;
+        } catch (Exception res) {
+            log("openTypedAssetFile", res, uri, mimeTypeFilter, opts, signal);
+            throw res;
+        }
     }
 
     @Override
     public @NonNull ContentProviderResult[] applyBatch(@NonNull String authority,
             @NonNull ArrayList<ContentProviderOperation> operations)
             throws RemoteException, OperationApplicationException {
-        final ContentProviderResult[] res = delegate.applyBatch(authority, operations);
-        log("applyBatch", res, authority, operations);
-        return res;
+        try {
+            final ContentProviderResult[] res = delegate.applyBatch(authority, operations);
+            log("applyBatch", res, authority, operations);
+            return res;
+        } catch (Exception res) {
+            log("applyBatch", res, authority, operations);
+            throw res;
+        }
     }
 
     @Override
     public @Nullable Bundle call(@NonNull String authority, @NonNull String method,
             @Nullable String arg, @Nullable Bundle extras) throws RemoteException {
-        final Bundle res = delegate.call(authority, method, arg, extras);
-        log("call", res, authority, method, arg, extras);
-        return res;
+        try {
+            final Bundle res = delegate.call(authority, method, arg, extras);
+            log("call", res, authority, method, arg, extras);
+            return res;
+        } catch (Exception res) {
+            log("call", res, authority, method, arg, extras);
+            throw res;
+        }
     }
 }
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 9037759..99324ba 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -5874,34 +5874,37 @@
             @NonNull ComponentName componentName);
 
     /**
-     * Set the enabled setting for a package app settings activity.
+     * Set whether a synthetic app details activity will be generated if the app has no enabled
+     * launcher activity. Disabling this allows the app to have no launcher icon.
      *
      * @param packageName The package name of the app
-     * @param enabled The new enabled state for app details activity
+     * @param enabled The new enabled state for the synthetic app details activity.
      *
      * @hide
      */
     @RequiresPermission(value = android.Manifest.permission.CHANGE_COMPONENT_ENABLED_STATE,
             conditional = true)
     @SystemApi
-    public void setAppDetailsActivityEnabled(@NonNull String packageName, boolean enabled) {
+    public void setSyntheticAppDetailsActivityEnabled(@NonNull String packageName,
+            boolean enabled) {
         throw new UnsupportedOperationException(
-                "setAppDetailsActivityEnabled not implemented");
+                "setSyntheticAppDetailsActivityEnabled not implemented");
     }
 
 
     /**
-     * Return the enabled setting for a package app settings activity.
+     * Return whether a synthetic app details activity will be generated if the app has no enabled
+     * launcher activity.
      *
      * @param packageName The package name of the app
-     * @return Returns the current enabled state for app settings activity.
+     * @return Returns the enabled state for the synthetic app details activity.
      *
      * @hide
      */
     @SystemApi
-    public boolean getAppDetailsActivityEnabled(@NonNull String packageName) {
+    public boolean getSyntheticAppDetailsActivityEnabled(@NonNull String packageName) {
         throw new UnsupportedOperationException(
-                "getAppDetailsActivityEnabled not implemented");
+                "getSyntheticAppDetailsActivityEnabled not implemented");
     }
 
     /**
diff --git a/core/java/android/content/pm/TEST_MAPPING b/core/java/android/content/pm/TEST_MAPPING
index a2e98cc..df4ae09 100644
--- a/core/java/android/content/pm/TEST_MAPPING
+++ b/core/java/android/content/pm/TEST_MAPPING
@@ -1,6 +1,12 @@
 {
   "imports": [
     {
+      "path": "cts/tests/tests/packageinstaller"
+    },
+    {
+      "path": "cts/hostsidetests/stagedinstall"
+    },
+    {
       "path": "system/apex/tests"
     }
   ]
diff --git a/core/java/android/net/INetworkStackConnector.aidl b/core/java/android/net/INetworkStackConnector.aidl
index e052488..edb9df6 100644
--- a/core/java/android/net/INetworkStackConnector.aidl
+++ b/core/java/android/net/INetworkStackConnector.aidl
@@ -16,7 +16,7 @@
 package android.net;
 
 import android.net.INetworkMonitorCallbacks;
-import android.net.NetworkParcelable;
+import android.net.Network;
 import android.net.dhcp.DhcpServingParamsParcel;
 import android.net.dhcp.IDhcpServerCallbacks;
 import android.net.ip.IIpClientCallbacks;
@@ -25,7 +25,6 @@
 oneway interface INetworkStackConnector {
     void makeDhcpServer(in String ifName, in DhcpServingParamsParcel params,
         in IDhcpServerCallbacks cb);
-    void makeNetworkMonitor(in NetworkParcelable network, String name,
-        in INetworkMonitorCallbacks cb);
+    void makeNetworkMonitor(in Network network, String name, in INetworkMonitorCallbacks cb);
     void makeIpClient(in String ifName, in IIpClientCallbacks callbacks);
 }
\ No newline at end of file
diff --git a/core/java/android/net/InitialConfigurationParcelable.aidl b/core/java/android/net/InitialConfigurationParcelable.aidl
index bdda3559..3fa88c3 100644
--- a/core/java/android/net/InitialConfigurationParcelable.aidl
+++ b/core/java/android/net/InitialConfigurationParcelable.aidl
@@ -16,12 +16,12 @@
 
 package android.net;
 
-import android.net.IpPrefixParcelable;
-import android.net.LinkAddressParcelable;
+import android.net.IpPrefix;
+import android.net.LinkAddress;
 
 parcelable InitialConfigurationParcelable {
-    LinkAddressParcelable[] ipAddresses;
-    IpPrefixParcelable[] directlyConnectedRoutes;
+    LinkAddress[] ipAddresses;
+    IpPrefix[] directlyConnectedRoutes;
     String[] dnsServers;
     String gateway;
 }
\ No newline at end of file
diff --git a/core/java/android/net/IpPrefix.aidl b/core/java/android/net/IpPrefix.aidl
index 837db5f..0d70f2a 100644
--- a/core/java/android/net/IpPrefix.aidl
+++ b/core/java/android/net/IpPrefix.aidl
@@ -17,4 +17,6 @@
 
 package android.net;
 
-parcelable IpPrefix cpp_header "binder/IpPrefix.h";
+// @JavaOnlyStableParcelable only affects the parcelable when built as stable aidl (aidl_interface
+// build rule). IpPrefix is also used in cpp but only as non-stable aidl.
+@JavaOnlyStableParcelable parcelable IpPrefix cpp_header "binder/IpPrefix.h";
diff --git a/core/java/android/net/IpPrefixParcelable.aidl b/core/java/android/net/IpPrefixParcelable.aidl
deleted file mode 100644
index 93a8d41..0000000
--- a/core/java/android/net/IpPrefixParcelable.aidl
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package android.net;
-
-parcelable IpPrefixParcelable {
-    String address;
-    int prefixLength;
-}
\ No newline at end of file
diff --git a/core/java/android/net/LinkAddress.aidl b/core/java/android/net/LinkAddress.aidl
index e7d8646..9c804db 100644
--- a/core/java/android/net/LinkAddress.aidl
+++ b/core/java/android/net/LinkAddress.aidl
@@ -17,5 +17,5 @@
 
 package android.net;
 
-parcelable LinkAddress;
+@JavaOnlyStableParcelable parcelable LinkAddress;
 
diff --git a/core/java/android/net/LinkAddressParcelable.aidl b/core/java/android/net/LinkAddressParcelable.aidl
deleted file mode 100644
index af8e79b..0000000
--- a/core/java/android/net/LinkAddressParcelable.aidl
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package android.net;
-
-parcelable LinkAddressParcelable {
-    String address;
-    int prefixLength;
-    int flags;
-    int scope;
-}
\ No newline at end of file
diff --git a/core/java/android/net/LinkProperties.aidl b/core/java/android/net/LinkProperties.aidl
index 3cb9525..a8b3c7b 100644
--- a/core/java/android/net/LinkProperties.aidl
+++ b/core/java/android/net/LinkProperties.aidl
@@ -17,4 +17,4 @@
 
 package android.net;
 
-parcelable LinkProperties;
+@JavaOnlyStableParcelable parcelable LinkProperties;
diff --git a/core/java/android/net/LinkPropertiesParcelable.aidl b/core/java/android/net/LinkPropertiesParcelable.aidl
deleted file mode 100644
index 6b52239..0000000
--- a/core/java/android/net/LinkPropertiesParcelable.aidl
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package android.net;
-
-import android.net.IpPrefixParcelable;
-import android.net.LinkAddressParcelable;
-import android.net.ProxyInfoParcelable;
-import android.net.RouteInfoParcelable;
-
-parcelable LinkPropertiesParcelable {
-    String ifaceName;
-    LinkAddressParcelable[] linkAddresses;
-    String[] dnses;
-    String[] pcscfs;
-    String[] validatedPrivateDnses;
-    boolean usePrivateDns;
-    String privateDnsServerName;
-    String domains;
-    RouteInfoParcelable[] routes;
-    ProxyInfoParcelable httpProxy;
-    int mtu;
-    String tcpBufferSizes;
-    IpPrefixParcelable nat64Prefix;
-}
\ No newline at end of file
diff --git a/core/java/android/net/Network.aidl b/core/java/android/net/Network.aidl
index 73ba1af..05622025b 100644
--- a/core/java/android/net/Network.aidl
+++ b/core/java/android/net/Network.aidl
@@ -17,4 +17,4 @@
 
 package android.net;
 
-parcelable Network;
+@JavaOnlyStableParcelable parcelable Network;
diff --git a/core/java/android/net/NetworkParcelable.aidl b/core/java/android/net/NetworkParcelable.aidl
deleted file mode 100644
index c26352e..0000000
--- a/core/java/android/net/NetworkParcelable.aidl
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
-**
-** Copyright (C) 2019 The Android Open Source Project
-**
-** Licensed under the Apache License, Version 2.0 (the "License");
-** you may not use this file except in compliance with the License.
-** You may obtain a copy of the License at
-**
-**     http://www.apache.org/licenses/LICENSE-2.0
-**
-** Unless required by applicable law or agreed to in writing, software
-** distributed under the License is distributed on an "AS IS" BASIS,
-** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-** See the License for the specific language governing permissions and
-** limitations under the License.
-*/
-
-package android.net;
-
-parcelable NetworkParcelable {
-    long networkHandle;
-}
diff --git a/core/java/android/net/ProvisioningConfigurationParcelable.aidl b/core/java/android/net/ProvisioningConfigurationParcelable.aidl
index 2a144f2..5b46d7f 100644
--- a/core/java/android/net/ProvisioningConfigurationParcelable.aidl
+++ b/core/java/android/net/ProvisioningConfigurationParcelable.aidl
@@ -19,7 +19,7 @@
 
 import android.net.ApfCapabilitiesParcelable;
 import android.net.InitialConfigurationParcelable;
-import android.net.NetworkParcelable;
+import android.net.Network;
 import android.net.StaticIpConfigurationParcelable;
 
 parcelable ProvisioningConfigurationParcelable {
@@ -33,6 +33,6 @@
     ApfCapabilitiesParcelable apfCapabilities;
     int provisioningTimeoutMs;
     int ipv6AddrGenMode;
-    NetworkParcelable network;
+    Network network;
     String displayName;
 }
diff --git a/core/java/android/net/ProxyInfo.aidl b/core/java/android/net/ProxyInfo.aidl
index 2c91960..a5d0c12 100644
--- a/core/java/android/net/ProxyInfo.aidl
+++ b/core/java/android/net/ProxyInfo.aidl
@@ -17,5 +17,5 @@
 
 package android.net;
 
-parcelable ProxyInfo;
+@JavaOnlyStableParcelable parcelable ProxyInfo;
 
diff --git a/core/java/android/net/ProxyInfoParcelable.aidl b/core/java/android/net/ProxyInfoParcelable.aidl
deleted file mode 100644
index 59fd846..0000000
--- a/core/java/android/net/ProxyInfoParcelable.aidl
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package android.net;
-
-parcelable ProxyInfoParcelable {
-    String host;
-    int port;
-    String[] exclusionList;
-    String pacFileUrl;
-}
diff --git a/core/java/android/net/RouteInfo.aidl b/core/java/android/net/RouteInfo.aidl
index 2296a57..7af9fda 100644
--- a/core/java/android/net/RouteInfo.aidl
+++ b/core/java/android/net/RouteInfo.aidl
@@ -16,4 +16,4 @@
 
 package android.net;
 
-parcelable RouteInfo;
+@JavaOnlyStableParcelable parcelable RouteInfo;
diff --git a/core/java/android/net/RouteInfoParcelable.aidl b/core/java/android/net/RouteInfoParcelable.aidl
deleted file mode 100644
index 15bcdcf..0000000
--- a/core/java/android/net/RouteInfoParcelable.aidl
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
-*/
-
-package android.net;
-
-import android.net.IpPrefixParcelable;
-
-parcelable RouteInfoParcelable {
-    IpPrefixParcelable destination;
-    String gatewayAddr;
-    String ifaceName;
-    int type;
-}
diff --git a/core/java/android/net/StaticIpConfigurationParcelable.aidl b/core/java/android/net/StaticIpConfigurationParcelable.aidl
index 45dc021..6fffb42 100644
--- a/core/java/android/net/StaticIpConfigurationParcelable.aidl
+++ b/core/java/android/net/StaticIpConfigurationParcelable.aidl
@@ -17,10 +17,10 @@
 
 package android.net;
 
-import android.net.LinkAddressParcelable;
+import android.net.LinkAddress;
 
 parcelable StaticIpConfigurationParcelable {
-    LinkAddressParcelable ipAddress;
+    LinkAddress ipAddress;
     String gateway;
     String[] dnsServers;
     String domains;
diff --git a/core/java/android/net/ip/IIpClient.aidl b/core/java/android/net/ip/IIpClient.aidl
index a4a80e1..b834e45 100644
--- a/core/java/android/net/ip/IIpClient.aidl
+++ b/core/java/android/net/ip/IIpClient.aidl
@@ -15,7 +15,7 @@
  */
 package android.net.ip;
 
-import android.net.ProxyInfoParcelable;
+import android.net.ProxyInfo;
 import android.net.ProvisioningConfigurationParcelable;
 import android.net.TcpKeepalivePacketDataParcelable;
 
@@ -28,7 +28,7 @@
     void startProvisioning(in ProvisioningConfigurationParcelable req);
     void stop();
     void setTcpBufferSizes(in String tcpBufferSizes);
-    void setHttpProxy(in ProxyInfoParcelable proxyInfo);
+    void setHttpProxy(in ProxyInfo proxyInfo);
     void setMulticastFilter(boolean enabled);
     void addKeepalivePacketFilter(int slot, in TcpKeepalivePacketDataParcelable pkt);
     void removeKeepalivePacketFilter(int slot);
diff --git a/core/java/android/net/ip/IIpClientCallbacks.aidl b/core/java/android/net/ip/IIpClientCallbacks.aidl
index f077e3b..3681416 100644
--- a/core/java/android/net/ip/IIpClientCallbacks.aidl
+++ b/core/java/android/net/ip/IIpClientCallbacks.aidl
@@ -15,7 +15,7 @@
  */
 package android.net.ip;
 
-import android.net.LinkPropertiesParcelable;
+import android.net.LinkProperties;
 import android.net.ip.IIpClient;
 import android.net.DhcpResultsParcelable;
 
@@ -34,11 +34,11 @@
     // null or not.
     void onNewDhcpResults(in DhcpResultsParcelable dhcpResults);
 
-    void onProvisioningSuccess(in LinkPropertiesParcelable newLp);
-    void onProvisioningFailure(in LinkPropertiesParcelable newLp);
+    void onProvisioningSuccess(in LinkProperties newLp);
+    void onProvisioningFailure(in LinkProperties newLp);
 
     // Invoked on LinkProperties changes.
-    void onLinkPropertiesChange(in LinkPropertiesParcelable newLp);
+    void onLinkPropertiesChange(in LinkProperties newLp);
 
     // Called when the internal IpReachabilityMonitor (if enabled) has
     // detected the loss of a critical number of required neighbors.
diff --git a/core/java/android/os/BugreportManager.java b/core/java/android/os/BugreportManager.java
index 672624c..f87abde 100644
--- a/core/java/android/os/BugreportManager.java
+++ b/core/java/android/os/BugreportManager.java
@@ -28,6 +28,8 @@
 
 import com.android.internal.util.Preconditions;
 
+import libcore.io.IoUtils;
+
 import java.io.FileDescriptor;
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
@@ -124,6 +126,8 @@
      * <p>The bugreport artifacts will be copied over to the given file descriptors only if the
      * user consents to sharing with the calling app.
      *
+     * <p>{@link BugreportManager} takes ownership of {@code bugreportFd} and {@code screenshotFd}.
+     *
      * @param bugreportFd file to write the bugreport. This should be opened in write-only,
      *     append mode.
      * @param screenshotFd file to write the screenshot, if necessary. This should be opened
@@ -137,12 +141,13 @@
             @NonNull BugreportParams params,
             @NonNull @CallbackExecutor Executor executor,
             @NonNull BugreportCallback callback) {
-        Preconditions.checkNotNull(bugreportFd);
-        Preconditions.checkNotNull(params);
-        Preconditions.checkNotNull(executor);
-        Preconditions.checkNotNull(callback);
-        DumpstateListener dsListener = new DumpstateListener(executor, callback);
         try {
+            Preconditions.checkNotNull(bugreportFd);
+            Preconditions.checkNotNull(params);
+            Preconditions.checkNotNull(executor);
+            Preconditions.checkNotNull(callback);
+
+            DumpstateListener dsListener = new DumpstateListener(executor, callback);
             // Note: mBinder can get callingUid from the binder transaction.
             mBinder.startBugreport(-1 /* callingUid */,
                     mContext.getOpPackageName(),
@@ -152,6 +157,12 @@
                     params.getMode(), dsListener);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
+        } finally {
+            // We can close the file descriptors here because binder would have duped them.
+            IoUtils.closeQuietly(bugreportFd);
+            if (screenshotFd != null) {
+                IoUtils.closeQuietly(screenshotFd);
+            }
         }
     }
 
@@ -171,7 +182,7 @@
         private final Executor mExecutor;
         private final BugreportCallback mCallback;
 
-        DumpstateListener(Executor executor, @Nullable BugreportCallback callback) {
+        DumpstateListener(Executor executor, BugreportCallback callback) {
             mExecutor = executor;
             mCallback = callback;
         }
@@ -209,8 +220,6 @@
                 });
             } finally {
                 Binder.restoreCallingIdentity(identity);
-                // The bugreport has finished. Let's shutdown the service to minimize its footprint.
-                cancelBugreport();
             }
         }
 
diff --git a/core/java/android/os/IPowerManager.aidl b/core/java/android/os/IPowerManager.aidl
index 483c41a..a0d88ee 100644
--- a/core/java/android/os/IPowerManager.aidl
+++ b/core/java/android/os/IPowerManager.aidl
@@ -48,7 +48,7 @@
     boolean isInteractive();
     boolean isPowerSaveMode();
     PowerSaveState getPowerSaveState(int serviceType);
-    boolean setPowerSaveMode(boolean mode);
+    boolean setPowerSaveModeEnabled(boolean mode);
     boolean setDynamicPowerSavings(boolean dynamicPowerSavingsEnabled, int disableThreshold);
     boolean setAdaptivePowerSavePolicy(in BatterySaverPolicyConfig config);
     boolean setAdaptivePowerSaveEnabled(boolean enabled);
diff --git a/core/java/android/os/ParcelFileDescriptor.java b/core/java/android/os/ParcelFileDescriptor.java
index 7a8727c..ed1d8a5 100644
--- a/core/java/android/os/ParcelFileDescriptor.java
+++ b/core/java/android/os/ParcelFileDescriptor.java
@@ -372,7 +372,11 @@
     /**
      * Take ownership of a raw native fd in to a new ParcelFileDescriptor.
      * The returned ParcelFileDescriptor now owns the given fd, and will be
-     * responsible for closing it.  You must not close the fd yourself.
+     * responsible for closing it.
+     * <p>
+     * <strong>WARNING:</strong> You must not close the fd yourself after
+     * this call, and ownership of the file descriptor must have been
+     * released prior to the call to this function.
      *
      * @param fd The native fd that the ParcelFileDescriptor should adopt.
      *
@@ -391,6 +395,16 @@
      * ParcelFileDescriptor holds a dup of the original FileDescriptor in
      * the Socket, so you must still close the Socket as well as the new
      * ParcelFileDescriptor.
+     * <p>
+     * <strong>WARNING:</strong> Prior to API level 29, this function would not
+     * actually dup the Socket's FileDescriptor, and would take a
+     * reference to the its internal FileDescriptor instead. If the Socket
+     * gets garbage collected before the ParcelFileDescriptor, this may
+     * lead to the ParcelFileDescriptor being unexpectedly closed. To avoid
+     * this, the following pattern can be used:
+     * <pre>{@code
+     *    ParcelFileDescriptor pfd = ParcelFileDescriptor.fromSocket(socket).dup();
+     * }</pre>
      *
      * @param socket The Socket whose FileDescriptor is used to create
      *               a new ParcelFileDescriptor.
@@ -414,6 +428,16 @@
      * new ParcelFileDescriptor holds a dup of the original FileDescriptor in
      * the DatagramSocket, so you must still close the DatagramSocket as well
      * as the new ParcelFileDescriptor.
+     * <p>
+     * <strong>WARNING:</strong> Prior to API level 29, this function would not
+     * actually dup the DatagramSocket's FileDescriptor, and would take a
+     * reference to the its internal FileDescriptor instead. If the DatagramSocket
+     * gets garbage collected before the ParcelFileDescriptor, this may
+     * lead to the ParcelFileDescriptor being unexpectedly closed. To avoid
+     * this, the following pattern can be used:
+     * <pre>{@code
+     *    ParcelFileDescriptor pfd = ParcelFileDescriptor.fromDatagramSocket(socket).dup();
+     * }</pre>
      *
      * @param datagramSocket The DatagramSocket whose FileDescriptor is used
      *               to create a new ParcelFileDescriptor.
@@ -651,6 +675,9 @@
      * Return the native fd int for this ParcelFileDescriptor.  The
      * ParcelFileDescriptor still owns the fd, and it still must be closed
      * through this API.
+     * <p>
+     * <strong>WARNING:</strong> Do not call close on the return value of this
+     * function or pass it to a function that assumes ownership of the fd.
      */
     public int getFd() {
         if (mWrapped != null) {
diff --git a/core/java/android/os/PowerManager.java b/core/java/android/os/PowerManager.java
index 728b215..fdc5157 100644
--- a/core/java/android/os/PowerManager.java
+++ b/core/java/android/os/PowerManager.java
@@ -1419,9 +1419,9 @@
             android.Manifest.permission.DEVICE_POWER,
             android.Manifest.permission.POWER_SAVER
     })
-    public boolean setPowerSaveMode(boolean mode) {
+    public boolean setPowerSaveModeEnabled(boolean mode) {
         try {
-            return mService.setPowerSaveMode(mode);
+            return mService.setPowerSaveModeEnabled(mode);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java
index 27e3914..3e60d51 100644
--- a/core/java/android/os/storage/StorageManager.java
+++ b/core/java/android/os/storage/StorageManager.java
@@ -16,6 +16,8 @@
 
 package android.os.storage;
 
+import static android.content.ContentResolver.DEPRECATE_DATA_PREFIX;
+
 import android.annotation.BytesLong;
 import android.annotation.IntDef;
 import android.annotation.NonNull;
@@ -30,6 +32,7 @@
 import android.annotation.WorkerThread;
 import android.app.Activity;
 import android.app.ActivityThread;
+import android.app.AppGlobals;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
@@ -1139,6 +1142,12 @@
         if (file == null) {
             return null;
         }
+        final String path = file.getAbsolutePath();
+        if (path.startsWith(DEPRECATE_DATA_PREFIX)) {
+            final Uri uri = ContentResolver.translateDeprecatedDataPath(path);
+            return AppGlobals.getInitialApplication().getSystemService(StorageManager.class)
+                    .getStorageVolume(uri);
+        }
         try {
             file = file.getCanonicalFile();
         } catch (IOException ignored) {
diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java
index 046ed2f..6d32f8c 100644
--- a/core/java/android/provider/DeviceConfig.java
+++ b/core/java/android/provider/DeviceConfig.java
@@ -163,7 +163,8 @@
     public static final String NAMESPACE_NETD_NATIVE = "netd_native";
 
     /**
-     * Namespace for all runtime related features.
+     * Namespace for all runtime related features that don't require a reboot to become active.
+     * There are no feature flags using NAMESPACE_RUNTIME.
      *
      * @hide
      */
@@ -171,7 +172,9 @@
     public static final String NAMESPACE_RUNTIME = "runtime";
 
     /**
-     * Namespace for all runtime native related features.
+     * Namespace for all runtime related features that require system properties for accessing
+     * the feature flags from C++ or Java language code. One example is the app image startup
+     * cache feature use_app_image_startup_cache.
      *
      * @hide
      */
diff --git a/core/java/android/provider/FontsContract.java b/core/java/android/provider/FontsContract.java
index 2814474..e931826 100644
--- a/core/java/android/provider/FontsContract.java
+++ b/core/java/android/provider/FontsContract.java
@@ -34,6 +34,7 @@
 import android.graphics.fonts.FontStyle;
 import android.graphics.fonts.FontVariationAxis;
 import android.net.Uri;
+import android.os.Build.VERSION_CODES;
 import android.os.CancellationSignal;
 import android.os.Handler;
 import android.os.HandlerThread;
@@ -641,35 +642,25 @@
                 continue;
             }
             try {
-                Font font = null;
-                try {
-                    font = new Font.Builder(buffer)
+                final Font font = new Font.Builder(buffer)
                         .setWeight(fontInfo.getWeight())
                         .setSlant(fontInfo.isItalic()
                                 ? FontStyle.FONT_SLANT_ITALIC : FontStyle.FONT_SLANT_UPRIGHT)
                         .setTtcIndex(fontInfo.getTtcIndex())
                         .setFontVariationSettings(fontInfo.getAxes())
                         .build();
-                } catch (IllegalArgumentException e) {
-                    // The exception happens if the unsupported font is passed. We suppress this
-                    // exception and just ignore this font here since there is no way of
-                    // resolving this issue by users during inflating layout.
-                    Log.w(TAG, "Ignoring font file since failed to create font object."
-                            + " The font file is not supported on this platform.");
-                    continue;
-                }
                 if (familyBuilder == null) {
                     familyBuilder = new FontFamily.Builder(font);
                 } else {
                     try {
                         familyBuilder.addFont(font);
                     } catch (IllegalArgumentException e) {
-                        // The exception happens if the same style font is added to the family.
-                        // We suppress this exception and just ignore this font here since there is
-                        // no way of resolving this issue by users during inflating layout.
-                        Log.w(TAG,
-                                "Ignoring font file since the same style font is already added.");
-                        continue;
+                        if (context.getApplicationInfo().targetSdkVersion <= VERSION_CODES.P) {
+                            // Surpress the IllegalArgumentException for keeping the backward
+                            // compatibility.
+                            continue;
+                        }
+                        throw e;
                     }
                 }
             } catch (IOException e) {
diff --git a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
index cd54930..19e216a 100644
--- a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
+++ b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
@@ -405,7 +405,6 @@
         private void update(@NonNull AutofillId focusedId, @NonNull AutofillValue focusedValue,
                 @NonNull IFillCallback callback) {
             synchronized (mLock) {
-                // TODO(b/123099468): should we close the popupwindow if the focused id changed?
                 mFocusedId = focusedId;
                 mFocusedValue = focusedValue;
                 if (mCallback != null) {
diff --git a/core/java/android/service/contentcapture/ActivityEvent.java b/core/java/android/service/contentcapture/ActivityEvent.java
index 7ac380d..5407c1d 100644
--- a/core/java/android/service/contentcapture/ActivityEvent.java
+++ b/core/java/android/service/contentcapture/ActivityEvent.java
@@ -47,10 +47,16 @@
      */
     public static final int TYPE_ACTIVITY_PAUSED = Event.ACTIVITY_PAUSED;
 
+    /**
+     * The activity stopped.
+     */
+    public static final int TYPE_ACTIVITY_STOPPED = Event.ACTIVITY_STOPPED;
+
     /** @hide */
     @IntDef(prefix = { "TYPE_" }, value = {
             TYPE_ACTIVITY_RESUMED,
-            TYPE_ACTIVITY_PAUSED
+            TYPE_ACTIVITY_PAUSED,
+            TYPE_ACTIVITY_STOPPED
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface ActivityEventType{}
@@ -89,6 +95,8 @@
                 return "ACTIVITY_RESUMED";
             case TYPE_ACTIVITY_PAUSED:
                 return "ACTIVITY_PAUSED";
+            case TYPE_ACTIVITY_STOPPED:
+                return "ACTIVITY_STOPPED";
             default:
                 return "UKNOWN_TYPE: " + type;
         }
diff --git a/core/java/android/service/euicc/EuiccService.java b/core/java/android/service/euicc/EuiccService.java
index a46d047..2288106 100644
--- a/core/java/android/service/euicc/EuiccService.java
+++ b/core/java/android/service/euicc/EuiccService.java
@@ -113,15 +113,27 @@
     public static final String ACTION_PROVISION_EMBEDDED_SUBSCRIPTION =
             "android.service.euicc.action.PROVISION_EMBEDDED_SUBSCRIPTION";
 
-    /** @see android.telephony.euicc.EuiccManager#ACTION_TOGGLE_SUBSCRIPTION_PRIVILEGED */
+    /**
+     * @see android.telephony.euicc.EuiccManager#ACTION_TOGGLE_SUBSCRIPTION_PRIVILEGED. This is
+     * a protected intent that can only be sent by the system, and requires the
+     * {@link android.Manifest.permission#BIND_EUICC_SERVICE} permission.
+     */
     public static final String ACTION_TOGGLE_SUBSCRIPTION_PRIVILEGED =
             "android.service.euicc.action.TOGGLE_SUBSCRIPTION_PRIVILEGED";
 
-    /** @see android.telephony.euicc.EuiccManager#ACTION_DELETE_SUBSCRIPTION_PRIVILEGED */
+    /**
+     * @see android.telephony.euicc.EuiccManager#ACTION_DELETE_SUBSCRIPTION_PRIVILEGED. This is
+     * a protected intent that can only be sent by the system, and requires the
+     * {@link android.Manifest.permission#BIND_EUICC_SERVICE} permission.
+     */
     public static final String ACTION_DELETE_SUBSCRIPTION_PRIVILEGED =
             "android.service.euicc.action.DELETE_SUBSCRIPTION_PRIVILEGED";
 
-    /** @see android.telephony.euicc.EuiccManager#ACTION_RENAME_SUBSCRIPTION_PRIVILEGED */
+    /**
+     * @see android.telephony.euicc.EuiccManager#ACTION_RENAME_SUBSCRIPTION_PRIVILEGED. This is
+     * a protected intent that can only be sent by the system, and requires the
+     * {@link android.Manifest.permission#BIND_EUICC_SERVICE} permission.
+     */
     public static final String ACTION_RENAME_SUBSCRIPTION_PRIVILEGED =
             "android.service.euicc.action.RENAME_SUBSCRIPTION_PRIVILEGED";
 
diff --git a/core/java/android/util/OWNERS b/core/java/android/util/OWNERS
index 86ed122..98297fb 100644
--- a/core/java/android/util/OWNERS
+++ b/core/java/android/util/OWNERS
@@ -1,2 +1,3 @@
 per-file FeatureFlagUtils.java = sbasi@google.com
 per-file FeatureFlagUtils.java = zhfan@google.com
+per-file FeatureFlagUtils.java = asapperstein@google.com
diff --git a/core/java/android/view/InputWindowHandle.java b/core/java/android/view/InputWindowHandle.java
index ec79eea..16a6412 100644
--- a/core/java/android/view/InputWindowHandle.java
+++ b/core/java/android/view/InputWindowHandle.java
@@ -18,9 +18,12 @@
 
 import static android.view.Display.INVALID_DISPLAY;
 
+import android.annotation.Nullable;
 import android.graphics.Region;
 import android.os.IBinder;
 
+import java.lang.ref.WeakReference;
+
 /**
  * Functions as a handle for a window that can receive input.
  * Enables the native input dispatcher to refer indirectly to the window manager's window state.
@@ -38,7 +41,7 @@
     // The client window.
     public final IWindow clientWindow;
 
-    // The token assosciated with the window.
+    // The token associated with the window.
     public IBinder token;
 
     // The window name.
@@ -98,6 +101,23 @@
     // transports the touch of this window to the display indicated by portalToDisplayId.
     public int portalToDisplayId = INVALID_DISPLAY;
 
+    /**
+     * Crops the touchable region to the bounds of the surface provided.
+     *
+     * This can be used in cases where the window is not
+     * {@link android.view.WindowManager#FLAG_NOT_TOUCH_MODAL} but should be constrained to the
+     * bounds of a parent window. That is the window should receive touch events outside its
+     * window but be limited to its stack bounds, such as in the case of split screen.
+     */
+    public WeakReference<IBinder> touchableRegionCropHandle = new WeakReference<>(null);
+
+    /**
+     * Replace {@link touchableRegion} with the bounds of {@link touchableRegionCropHandle}. If
+     * the handle is {@code null}, the bounds of the surface associated with this window is used
+     * as the touchable region.
+     */
+    public boolean replaceTouchableRegionWithCrop;
+
     private native void nativeDispose();
 
     public InputWindowHandle(InputApplicationHandle inputApplicationHandle,
@@ -127,4 +147,25 @@
             super.finalize();
         }
     }
+
+    /**
+     * Set the window touchable region to the bounds of {@link touchableRegionBounds} ignoring any
+     * touchable region provided.
+     *
+     * @param bounds surface to set the touchable region to. Set to {@code null} to set the bounds
+     * to the current surface.
+     */
+    public void replaceTouchableRegionWithCrop(@Nullable SurfaceControl bounds) {
+        setTouchableRegionCrop(bounds);
+        replaceTouchableRegionWithCrop = true;
+    }
+
+    /**
+     * Crop the window touchable region to the bounds of the surface provided.
+     */
+    public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) {
+        if (bounds != null) {
+            touchableRegionCropHandle = new WeakReference<>(bounds.getHandle());
+        }
+    }
 }
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 9222bd6..a28d662 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -1213,15 +1213,12 @@
 
         boolean useAutoDark = getNightMode() == Configuration.UI_MODE_NIGHT_YES;
 
-        // Allow debug.hwui.force_dark to override the target SDK check
-        if (useAutoDark && !SystemProperties.getBoolean("debug.hwui.force_dark", false)) {
-            useAutoDark = mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q;
-        }
-
         if (useAutoDark) {
+            boolean forceDarkAllowedDefault =
+                    SystemProperties.getBoolean("debug.hwui.force_dark", false);
             TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme);
             useAutoDark = a.getBoolean(R.styleable.Theme_isLightTheme, true)
-                    && a.getBoolean(R.styleable.Theme_forceDarkAllowed, true);
+                    && a.getBoolean(R.styleable.Theme_forceDarkAllowed, forceDarkAllowedDefault);
             a.recycle();
         }
 
diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java
index 13efeaf..604cce5 100644
--- a/core/java/android/view/autofill/AutofillManager.java
+++ b/core/java/android/view/autofill/AutofillManager.java
@@ -20,6 +20,7 @@
 import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
 import static android.view.autofill.Helper.sDebug;
 import static android.view.autofill.Helper.sVerbose;
+import static android.view.autofill.Helper.toList;
 
 import android.accessibilityservice.AccessibilityServiceInfo;
 import android.annotation.IntDef;
@@ -1872,10 +1873,6 @@
         }
     }
 
-    private <T> ArrayList<T> toList(@Nullable Set<T> set) {
-        return set == null ? null : new ArrayList<T>(set);
-    }
-
     /**
      * Notifies that a non-autofillable view was entered because the activity is whitelisted for
      * augmented autofill.
diff --git a/core/java/android/view/autofill/Helper.java b/core/java/android/view/autofill/Helper.java
index 48d0dbb..2f12bb2 100644
--- a/core/java/android/view/autofill/Helper.java
+++ b/core/java/android/view/autofill/Helper.java
@@ -19,7 +19,9 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Set;
 
 /** @hide */
 public final class Helper {
@@ -62,7 +64,8 @@
     }
 
     /**
-     * Convers a collaction of {@link AutofillId AutofillIds} to an array.
+     * Converts a collaction of {@link AutofillId AutofillIds} to an array.
+     *
      * @param collection The collection.
      * @return The array.
      */
@@ -75,6 +78,14 @@
         return array;
     }
 
+    /**
+     * Converts a Set to a List.
+     */
+    @Nullable
+    public static <T> ArrayList<T> toList(@Nullable Set<T> set) {
+        return set == null ? null : new ArrayList<T>(set);
+    }
+
     private Helper() {
         throw new UnsupportedOperationException("contains static members only");
     }
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java
index 4129e52..6d41b28 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSession.java
@@ -153,6 +153,8 @@
     public static final int FLUSH_REASON_SESSION_FINISHED = 4;
     /** @hide */
     public static final int FLUSH_REASON_IDLE_TIMEOUT = 5;
+    /** @hide */
+    public static final int FLUSH_REASON_TEXT_CHANGE_TIMEOUT = 6;
 
     /** @hide */
     @IntDef(prefix = { "FLUSH_REASON_" }, value = {
@@ -160,7 +162,8 @@
             FLUSH_REASON_VIEW_ROOT_ENTERED,
             FLUSH_REASON_SESSION_STARTED,
             FLUSH_REASON_SESSION_FINISHED,
-            FLUSH_REASON_IDLE_TIMEOUT
+            FLUSH_REASON_IDLE_TIMEOUT,
+            FLUSH_REASON_TEXT_CHANGE_TIMEOUT
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface FlushReason{}
@@ -525,6 +528,8 @@
                 return "FINISHED";
             case FLUSH_REASON_IDLE_TIMEOUT:
                 return "IDLE";
+            case FLUSH_REASON_TEXT_CHANGE_TIMEOUT:
+                return "TEXT_CHANGE";
             default:
                 return "UNKOWN-" + reason;
         }
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index f9fd0c6..666af59 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -125,6 +125,11 @@
     // Used just for debugging purposes (on dump)
     private long mNextFlush;
 
+    /**
+     * Whether the next buffer flush is queued by a text changed event.
+     */
+    private boolean mNextFlushForTextChanged = false;
+
     @Nullable
     private final LocalLog mFlushHistory;
 
@@ -331,7 +336,21 @@
         final boolean bufferEvent = numberEvents < maxBufferSize;
 
         if (bufferEvent && !forceFlush) {
-            scheduleFlush(FLUSH_REASON_IDLE_TIMEOUT, /* checkExisting= */ true);
+            final int flushReason;
+            if (eventType == TYPE_VIEW_TEXT_CHANGED) {
+                mNextFlushForTextChanged = true;
+                flushReason = FLUSH_REASON_TEXT_CHANGE_TIMEOUT;
+            } else {
+                if (mNextFlushForTextChanged) {
+                    if (sVerbose) {
+                        Log.i(TAG, "Not scheduling flush because next flush is for text changed");
+                    }
+                    return;
+                }
+
+                flushReason = FLUSH_REASON_IDLE_TIMEOUT;
+            }
+            scheduleFlush(flushReason, /* checkExisting= */ true);
             return;
         }
 
@@ -392,14 +411,25 @@
             // "Renew" the flush message by removing the previous one
             mHandler.removeMessages(MSG_FLUSH);
         }
-        final int idleFlushingFrequencyMs = mManager.mOptions.idleFlushingFrequencyMs;
-        mNextFlush = System.currentTimeMillis() + idleFlushingFrequencyMs;
+
+        final int flushFrequencyMs;
+        if (reason == FLUSH_REASON_IDLE_TIMEOUT) {
+            flushFrequencyMs = mManager.mOptions.idleFlushingFrequencyMs;
+        } else if (reason == FLUSH_REASON_TEXT_CHANGE_TIMEOUT) {
+            flushFrequencyMs = mManager.mOptions.textChangeFlushingFrequencyMs;
+        } else {
+            Log.e(TAG, "handleScheduleFlush(" + getDebugState(reason) + "): not called with a "
+                    + "timeout reason.");
+            return;
+        }
+
+        mNextFlush = System.currentTimeMillis() + flushFrequencyMs;
         if (sVerbose) {
             Log.v(TAG, "handleScheduleFlush(): scheduled to flush in "
-                    + idleFlushingFrequencyMs + "ms: " + TimeUtils.logTimeOfDay(mNextFlush));
+                    + flushFrequencyMs + "ms: " + TimeUtils.logTimeOfDay(mNextFlush));
         }
         // Post using a Runnable directly to trim a few μs from PooledLambda.obtainMessage()
-        mHandler.postDelayed(() -> flushIfNeeded(reason), MSG_FLUSH, idleFlushingFrequencyMs);
+        mHandler.postDelayed(() -> flushIfNeeded(reason), MSG_FLUSH, flushFrequencyMs);
     }
 
     @UiThread
@@ -448,6 +478,10 @@
         try {
             mHandler.removeMessages(MSG_FLUSH);
 
+            if (reason == FLUSH_REASON_TEXT_CHANGE_TIMEOUT) {
+                mNextFlushForTextChanged = false;
+            }
+
             final ParceledListSlice<ContentCaptureEvent> events = clearEvents();
             mDirectServiceInterface.sendEvents(events);
         } catch (RemoteException e) {
@@ -625,8 +659,14 @@
                     pw.println();
                 }
             }
+            pw.print(prefix); pw.print("mNextFlushForTextChanged: ");
+            pw.println(mNextFlushForTextChanged);
             pw.print(prefix); pw.print("flush frequency: ");
-            pw.println(mManager.mOptions.idleFlushingFrequencyMs);
+            if (mNextFlushForTextChanged) {
+                pw.println(mManager.mOptions.textChangeFlushingFrequencyMs);
+            } else {
+                pw.println(mManager.mOptions.idleFlushingFrequencyMs);
+            }
             pw.print(prefix); pw.print("next flush: ");
             TimeUtils.formatDuration(mNextFlush - System.currentTimeMillis(), pw);
             pw.print(" ("); pw.print(TimeUtils.logTimeOfDay(mNextFlush)); pw.println(")");
diff --git a/core/java/android/view/inspector/IntEnumMapping.java b/core/java/android/view/inspector/IntEnumMapping.java
deleted file mode 100644
index 147bb46..0000000
--- a/core/java/android/view/inspector/IntEnumMapping.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.view.inspector;
-
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.util.SparseArray;
-
-import java.util.Objects;
-
-/**
- * Maps the values of an {@code int} property to strings for properties that encode an enumeration.
- *
- * An {@link InspectionCompanion} may provide an instance of this class to a {@link PropertyMapper}
- * for flag values packed into primitive {@code int} properties.
- *
- * This class is an immutable wrapper for {@link SparseArray}, and must be constructed by a
- * {@link Builder}.
- *
- * @see PropertyMapper#mapIntEnum(String, int, IntEnumMapping)
- */
-public final class IntEnumMapping {
-    private final SparseArray<String> mValues;
-
-    /**
-     * Get the name for the given property value
-     *
-     * @param value The value of the property
-     * @return The name of the value in the enumeration, or null if no value is defined
-     */
-    @Nullable
-    public String get(int value) {
-        return mValues.get(value);
-    }
-
-    /**
-     * Create a new instance from a builder.
-     *
-     * This constructor is private, use {@link Builder#build()} instead.
-     *
-     * @param builder A builder to create from
-     */
-    private IntEnumMapping(Builder builder) {
-        mValues = builder.mValues.clone();
-    }
-
-    /**
-     * A builder for {@link IntEnumMapping}.
-     */
-    public static final class Builder {
-        @NonNull
-        private SparseArray<String> mValues;
-        private boolean mMustCloneValues = false;
-
-        public Builder() {
-            mValues = new SparseArray<>();
-        }
-
-        /**
-         * Add a new enumerated value.
-         *
-         * @param name The string name of the enumeration value
-         * @param value The {@code int} value of the enumeration value
-         * @return This builder
-         */
-        @NonNull
-        public Builder addValue(@NonNull String name, int value) {
-            // Save an allocation, only re-clone if the builder is used again after building
-            if (mMustCloneValues) {
-                mValues = mValues.clone();
-            }
-
-            mValues.put(value, Objects.requireNonNull(name));
-            return this;
-        }
-
-        /**
-         * Build a new {@link IntEnumMapping} from this builder.
-         *
-         * @return A new mapping
-         */
-        @NonNull
-        public IntEnumMapping build() {
-            mMustCloneValues = true;
-            return new IntEnumMapping(this);
-        }
-    }
-}
diff --git a/core/java/android/view/inspector/IntFlagMapping.java b/core/java/android/view/inspector/IntFlagMapping.java
index 2409081..f501329 100644
--- a/core/java/android/view/inspector/IntFlagMapping.java
+++ b/core/java/android/view/inspector/IntFlagMapping.java
@@ -21,6 +21,7 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Objects;
 import java.util.Set;
 
@@ -35,22 +36,20 @@
  * it by bitwise anding it with the mask and comparing the result against the target, that is,
  * {@code (value & mask) == target}.
  *
- * This class is immutable, and must be constructed by a {@link Builder}.
- *
- * @see PropertyMapper#mapIntFlag(String, int, IntFlagMapping)
+ * @see PropertyMapper#mapIntFlag(String, int, java.util.function.IntFunction)
  */
 public final class IntFlagMapping {
-    private final Flag[] mFlags;
+    private final List<Flag> mFlags = new ArrayList<>();
 
     /**
-     * Get an array of the names of enabled flags for a given property value.
+     * Get a set of the names of enabled flags for a given property value.
      *
      * @param value The value of the property
      * @return The names of the enabled flags, empty if no flags enabled
      */
     @NonNull
     public Set<String> get(int value) {
-        final Set<String> enabledFlagNames = new HashSet<>(mFlags.length);
+        final Set<String> enabledFlagNames = new HashSet<>(mFlags.size());
 
         for (Flag flag : mFlags) {
             if (flag.isEnabledFor(value)) {
@@ -62,70 +61,14 @@
     }
 
     /**
-     * Create a new instance from a builder.
+     * Add a mutually exclusive flag to the map.
      *
-     * This constructor is private, use {@link Builder#build()} instead.
-     *
-     * @param builder A builder to create from
+     * @param mask The bit mask to compare to and with a value
+     * @param target The target value to compare the masked value with
+     * @param name The name of the flag to include if enabled
      */
-    private IntFlagMapping(Builder builder) {
-        mFlags = builder.mFlags.toArray(new Flag[builder.mFlags.size()]);
-    }
-
-    /**
-     * A builder for {@link IntFlagMapping}.
-     */
-    public static final class Builder {
-        private ArrayList<Flag> mFlags;
-
-        public Builder() {
-            mFlags = new ArrayList<>();
-        }
-
-        /**
-         * Add a new flag without a mask.
-         *
-         * The target value will be used as a mask, to handle the common case where flag values
-         * are not mutually exclusive. The flag will be considered enabled for a property value if
-         * the result of bitwise anding the target and the value equals the target, that is:
-         * {@code (value & target) == target}.
-         *
-         * @param name The name of the flag
-         * @param target The value to compare against
-         * @return This builder
-         */
-        @NonNull
-        public Builder addFlag(@NonNull String name, int target) {
-            mFlags.add(new Flag(name, target, target));
-            return this;
-        }
-
-        /**
-         * Add a new flag with a mask.
-         *
-         * The flag will be considered enabled for a property value if the result of bitwise anding
-         * the value and the mask equals the target, that is: {@code (value & mask) == target}.
-         *
-         * @param name The name of the flag
-         * @param target The value to compare against
-         * @param mask A bit mask
-         * @return This builder
-         */
-        @NonNull
-        public Builder addFlag(@NonNull String name, int target, int mask) {
-            mFlags.add(new Flag(name, target, mask));
-            return this;
-        }
-
-        /**
-         * Build a new {@link IntFlagMapping} from this builder.
-         *
-         * @return A new mapping
-         */
-        @NonNull
-        public IntFlagMapping build() {
-            return new IntFlagMapping(this);
-        }
+    public void add(int mask, int target, @NonNull String name) {
+        mFlags.add(new Flag(mask, target, name));
     }
 
     /**
@@ -136,10 +79,10 @@
         private final int mTarget;
         private final int mMask;
 
-        private Flag(@NonNull String name, int target, int mask) {
-            mName = Objects.requireNonNull(name);
+        private Flag(int mask, int target, @NonNull String name) {
             mTarget = target;
             mMask = mask;
+            mName = Objects.requireNonNull(name);
         }
 
         /**
diff --git a/core/java/android/view/inspector/PropertyMapper.java b/core/java/android/view/inspector/PropertyMapper.java
index 54d99df..cbc690e 100644
--- a/core/java/android/view/inspector/PropertyMapper.java
+++ b/core/java/android/view/inspector/PropertyMapper.java
@@ -19,6 +19,9 @@
 import android.annotation.AttrRes;
 import android.annotation.NonNull;
 
+import java.util.Set;
+import java.util.function.IntFunction;
+
 /**
  * An interface for mapping the string names of inspectable properties to integer identifiers.
  *
@@ -154,7 +157,7 @@
     int mapIntEnum(
             @NonNull String name,
             @AttrRes int attributeId,
-            @NonNull IntEnumMapping mapping);
+            @NonNull IntFunction<String> mapping);
 
     /**
      * Map a string name to an integer ID for an attribute that contains resource IDs.
@@ -178,7 +181,7 @@
     int mapIntFlag(
             @NonNull String name,
             @AttrRes int attributeId,
-            @NonNull IntFlagMapping mapping);
+            @NonNull IntFunction<Set<String>> mapping);
     /**
      * Thrown from a map method if a property name is already mapped as different type.
      */
diff --git a/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java b/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
index 17edf5c..9c268f2 100644
--- a/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
+++ b/core/java/android/view/textclassifier/ActionsSuggestionsHelper.java
@@ -23,10 +23,13 @@
 import android.text.TextUtils;
 import android.util.ArrayMap;
 import android.util.Pair;
+import android.view.textclassifier.intent.LabeledIntent;
+import android.view.textclassifier.intent.TemplateIntentFactory;
 
 import com.android.internal.annotations.VisibleForTesting;
 
 import com.google.android.textclassifier.ActionsSuggestionsModel;
+import com.google.android.textclassifier.RemoteActionTemplate;
 
 import java.util.ArrayDeque;
 import java.util.ArrayList;
@@ -46,6 +49,7 @@
  */
 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
 public final class ActionsSuggestionsHelper {
+    private static final String TAG = "ActionsSuggestions";
     private static final int USER_LOCAL = 0;
     private static final int FIRST_NON_LOCAL_USER = 1;
 
@@ -117,8 +121,33 @@
     }
 
     /**
-     * Returns a {@link android.view.textclassifier.LabeledIntent.TitleChooser} for
-     * conversation actions use case.
+     * Generated labeled intent from an action suggestion and return the resolved result.
+     */
+    @Nullable
+    public static LabeledIntent.Result createLabeledIntentResult(
+            Context context,
+            TemplateIntentFactory templateIntentFactory,
+            ActionsSuggestionsModel.ActionSuggestion nativeSuggestion) {
+        RemoteActionTemplate[] remoteActionTemplates =
+                nativeSuggestion.getRemoteActionTemplates();
+        if (remoteActionTemplates == null) {
+            Log.w(TAG, "createRemoteAction: Missing template for type "
+                    + nativeSuggestion.getActionType());
+            return null;
+        }
+        List<LabeledIntent> labeledIntents = templateIntentFactory.create(remoteActionTemplates);
+        if (labeledIntents.isEmpty()) {
+            return null;
+        }
+        // Given that we only support implicit intent here, we should expect there is just one
+        // intent for each action type.
+        LabeledIntent.TitleChooser titleChooser =
+                ActionsSuggestionsHelper.createTitleChooser(nativeSuggestion.getActionType());
+        return labeledIntents.get(0).resolve(context, titleChooser, null);
+    }
+
+    /**
+     * Returns a {@link LabeledIntent.TitleChooser} for conversation actions use case.
      */
     @Nullable
     public static LabeledIntent.TitleChooser createTitleChooser(String actionType) {
diff --git a/core/java/android/view/textclassifier/ConversationAction.java b/core/java/android/view/textclassifier/ConversationAction.java
index 2b952a3..f2d878a 100644
--- a/core/java/android/view/textclassifier/ConversationAction.java
+++ b/core/java/android/view/textclassifier/ConversationAction.java
@@ -92,10 +92,15 @@
      */
     public static final String TYPE_SHARE_LOCATION = "share_location";
 
+    // TODO: Make this public API
     /** @hide **/
     public static final String TYPE_ADD_CONTACT = "add_contact";
 
-    public static final @android.annotation.NonNull Creator<ConversationAction> CREATOR =
+    // TODO: Make this public API
+    /** @hide **/
+    public static final String TYPE_COPY = "copy";
+
+    public static final @NonNull Creator<ConversationAction> CREATOR =
             new Creator<ConversationAction>() {
                 @Override
                 public ConversationAction createFromParcel(Parcel in) {
diff --git a/core/java/android/view/textclassifier/ExtrasUtils.java b/core/java/android/view/textclassifier/ExtrasUtils.java
index df548ae..eadad28 100644
--- a/core/java/android/view/textclassifier/ExtrasUtils.java
+++ b/core/java/android/view/textclassifier/ExtrasUtils.java
@@ -19,6 +19,7 @@
 import android.annotation.Nullable;
 import android.app.RemoteAction;
 import android.content.Intent;
+import android.icu.util.ULocale;
 import android.os.Bundle;
 
 import java.util.ArrayList;
@@ -27,8 +28,10 @@
  * Utility class for inserting and retrieving data in TextClassifier request/response extras.
  * @hide
  */
+// TODO: Make this a TestApi for CTS testing.
 public final class ExtrasUtils {
 
+    private static final String ENTITIES_EXTRAS = "entities-extras";
     private static final String ACTION_INTENT = "action-intent";
     private static final String ACTIONS_INTENTS = "actions-intents";
     private static final String FOREIGN_LANGUAGE = "foreign-language";
@@ -36,6 +39,7 @@
     private static final String SCORE = "score";
     private static final String MODEL_VERSION = "model-version";
     private static final String MODEL_NAME = "model-name";
+    private static final String TEXT_LANGUAGES = "text-languages";
 
     private ExtrasUtils() {}
 
@@ -55,6 +59,8 @@
     /**
      * Stores {@code extra} as foreign language information in TextClassifier response object's
      * extras {@code container}.
+     *
+     * @see #getForeignLanguageExtra(TextClassification)
      */
     static void putForeignLanguageExtra(Bundle container, Bundle extra) {
         container.putParcelable(FOREIGN_LANGUAGE, extra);
@@ -63,13 +69,68 @@
     /**
      * Returns foreign language detection information contained in the TextClassification object.
      * responses.
+     *
+     * @see #putForeignLanguageExtra(Bundle, Bundle)
      */
     @Nullable
-    public static Bundle getForeignLanguageExtra(TextClassification classification) {
+    public static Bundle getForeignLanguageExtra(@Nullable TextClassification classification) {
+        if (classification == null) {
+            return null;
+        }
         return classification.getExtras().getBundle(FOREIGN_LANGUAGE);
     }
 
     /**
+     * @see #getTopLanguage(Intent)
+     */
+    static void putTopLanguageScores(Bundle container, EntityConfidence languageScores) {
+        final int maxSize = Math.min(3, languageScores.getEntities().size());
+        final String[] languages = languageScores.getEntities().subList(0, maxSize)
+                .toArray(new String[0]);
+        final float[] scores = new float[languages.length];
+        for (int i = 0; i < languages.length; i++) {
+            scores[i] = languageScores.getConfidenceScore(languages[i]);
+        }
+        container.putStringArray(ENTITY_TYPE, languages);
+        container.putFloatArray(SCORE, scores);
+    }
+
+    /**
+     * @see #putTopLanguageScores(Bundle, EntityConfidence)
+     */
+    @Nullable
+    public static ULocale getTopLanguage(@Nullable Intent intent) {
+        if (intent == null) {
+            return null;
+        }
+        final Bundle tcBundle = intent.getBundleExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER);
+        if (tcBundle == null) {
+            return null;
+        }
+        final Bundle textLanguagesExtra = tcBundle.getBundle(TEXT_LANGUAGES);
+        if (textLanguagesExtra == null) {
+            return null;
+        }
+        final String[] languages = textLanguagesExtra.getStringArray(ENTITY_TYPE);
+        final float[] scores = textLanguagesExtra.getFloatArray(SCORE);
+        if (languages == null || scores == null
+                || languages.length == 0 || languages.length != scores.length) {
+            return null;
+        }
+        int highestScoringIndex = 0;
+        for (int i = 1; i < languages.length; i++) {
+            if (scores[highestScoringIndex] < scores[i]) {
+                highestScoringIndex = i;
+            }
+        }
+        return ULocale.forLanguageTag(languages[highestScoringIndex]);
+    }
+
+    public static void putTextLanguagesExtra(Bundle container, Bundle extra) {
+        container.putBundle(TEXT_LANGUAGES, extra);
+    }
+
+    /**
      * Stores {@code actionIntents} information in TextClassifier response object's extras
      * {@code container}.
      */
@@ -94,10 +155,37 @@
     }
 
     /**
+     * Stores {@code entities} information in TextClassifier response object's extras
+     * {@code container}.
+     *
+     * @see {@link #getCopyText(Bundle)}
+     */
+    public static void putEntitiesExtras(Bundle container, @Nullable Bundle entitiesExtras) {
+        container.putParcelable(ENTITIES_EXTRAS, entitiesExtras);
+    }
+
+    /**
+     * Returns {@code entities} information contained in a TextClassifier response object.
+     *
+     * @see {@link #putEntitiesExtras(Bundle, Bundle)}
+     */
+    @Nullable
+    public static String getCopyText(Bundle container) {
+        Bundle entitiesExtras = container.getParcelable(ENTITIES_EXTRAS);
+        if (entitiesExtras == null) {
+            return null;
+        }
+        return entitiesExtras.getString("text");
+    }
+
+    /**
      * Returns {@code actionIntents} information contained in the TextClassification object.
      */
     @Nullable
-    public static ArrayList<Intent> getActionsIntents(TextClassification classification) {
+    public static ArrayList<Intent> getActionsIntents(@Nullable TextClassification classification) {
+        if (classification == null) {
+            return null;
+        }
         return classification.getExtras().getParcelableArrayList(ACTIONS_INTENTS);
     }
 
@@ -106,7 +194,11 @@
      * action string, {@code intentAction}.
      */
     @Nullable
-    public static RemoteAction findAction(TextClassification classification, String intentAction) {
+    public static RemoteAction findAction(
+            @Nullable TextClassification classification, @Nullable String intentAction) {
+        if (classification == null || intentAction == null) {
+            return null;
+        }
         final ArrayList<Intent> actionIntents = getActionsIntents(classification);
         if (actionIntents != null) {
             final int size = actionIntents.size();
@@ -124,7 +216,7 @@
      * Returns the first "translate" action found in the {@code classification} object.
      */
     @Nullable
-    public static RemoteAction findTranslateAction(TextClassification classification) {
+    public static RemoteAction findTranslateAction(@Nullable TextClassification classification) {
         return findAction(classification, Intent.ACTION_TRANSLATE);
     }
 
@@ -132,7 +224,10 @@
      * Returns the entity type contained in the {@code extra}.
      */
     @Nullable
-    public static String getEntityType(Bundle extra) {
+    public static String getEntityType(@Nullable Bundle extra) {
+        if (extra == null) {
+            return null;
+        }
         return extra.getString(ENTITY_TYPE);
     }
 
@@ -141,14 +236,21 @@
      */
     @Nullable
     public static float getScore(Bundle extra) {
-        return extra.getFloat(SCORE, -1);
+        final int defaultValue = -1;
+        if (extra == null) {
+            return defaultValue;
+        }
+        return extra.getFloat(SCORE, defaultValue);
     }
 
     /**
      * Returns the model name contained in the {@code extra}.
      */
     @Nullable
-    public static String getModelName(Bundle extra) {
+    public static String getModelName(@Nullable Bundle extra) {
+        if (extra == null) {
+            return null;
+        }
         return extra.getString(MODEL_NAME);
     }
 }
diff --git a/core/java/android/view/textclassifier/Log.java b/core/java/android/view/textclassifier/Log.java
index 5c60c09..03ed496 100644
--- a/core/java/android/view/textclassifier/Log.java
+++ b/core/java/android/view/textclassifier/Log.java
@@ -22,8 +22,10 @@
  * To enable full log:
  * 1. adb shell setprop log.tag.androidtc VERBOSE
  * 2. adb shell stop && adb shell start
+ *
+ * @hide
  */
-final class Log {
+public final class Log {
 
     /**
      * true: Enables full logging.
diff --git a/core/java/android/view/textclassifier/TextClassificationConstants.java b/core/java/android/view/textclassifier/TextClassificationConstants.java
index 38e72e3..876e5cc 100644
--- a/core/java/android/view/textclassifier/TextClassificationConstants.java
+++ b/core/java/android/view/textclassifier/TextClassificationConstants.java
@@ -50,6 +50,7 @@
  * template_intent_factory_enabled                  (boolean)
  * translate_in_classification_enabled              (boolean)
  * detect_languages_from_text_enabled               (boolean)
+ * lang_id_context_settings                         (float[])
  * </pre>
  *
  * <p>
@@ -58,12 +59,14 @@
  *
  * Example of setting the values for testing.
  * adb shell settings put global text_classifier_constants \
- *      model_dark_launch_enabled=true,smart_selection_enabled=true,\
- *      entity_list_default=phone:address
+ *      model_dark_launch_enabled=true,smart_selection_enabled=true, \
+ *      entity_list_default=phone:address, \
+ *      lang_id_context_settings=20:1.0:0.4
  * @hide
  */
 public final class TextClassificationConstants {
-    private static final String LOG_TAG = "TextClassificationConstants";
+
+    private static final String LOG_TAG = TextClassifier.DEFAULT_LOG_TAG;
 
     /**
      * Whether the smart linkify feature is enabled.
@@ -148,7 +151,6 @@
      * Whether to enable {@link android.view.textclassifier.TemplateIntentFactory}.
      */
     private static final String TEMPLATE_INTENT_FACTORY_ENABLED = "template_intent_factory_enabled";
-
     /**
      * Whether to enable "translate" action in classifyText.
      */
@@ -160,6 +162,20 @@
      */
     private static final String DETECT_LANGUAGES_FROM_TEXT_ENABLED =
             "detect_languages_from_text_enabled";
+    /**
+     * A colon(:) separated string that specifies the configuration to use when including
+     * surrounding context text in language detection queries.
+     * <p>
+     * Format= minimumTextSize<int>:penalizeRatio<float>:textScoreRatio<float>
+     * <p>
+     * e.g. 20:1.0:0.4
+     * <p>
+     * Accept all text lengths with minimumTextSize=0
+     * <p>
+     * Reject all text less than minimumTextSize with penalizeRatio=0
+     * @see {@code TextClassifierImpl#detectLanguages(String, int, int)} for reference.
+     */
+    private static final String LANG_ID_CONTEXT_SETTINGS = "lang_id_context_settings";
 
     private static final boolean LOCAL_TEXT_CLASSIFIER_ENABLED_DEFAULT = true;
     private static final boolean SYSTEM_TEXT_CLASSIFIER_ENABLED_DEFAULT = true;
@@ -193,6 +209,7 @@
                     .add(ConversationAction.TYPE_VIEW_CALENDAR)
                     .add(ConversationAction.TYPE_VIEW_MAP)
                     .add(ConversationAction.TYPE_ADD_CONTACT)
+                    .add(ConversationAction.TYPE_COPY)
                     .toString();
     /**
      * < 0  : Not set. Use value from LangId model.
@@ -204,6 +221,8 @@
     private static final boolean TEMPLATE_INTENT_FACTORY_ENABLED_DEFAULT = true;
     private static final boolean TRANSLATE_IN_CLASSIFICATION_ENABLED_DEFAULT = true;
     private static final boolean DETECT_LANGUAGES_FROM_TEXT_ENABLED_DEFAULT = true;
+    private static final String LANG_ID_CONTEXT_SETTINGS_DEFAULT =
+            new StringJoiner(STRING_LIST_DELIMITER).add("20").add("1.0").add("0.4").toString();
 
     private final boolean mSystemTextClassifierEnabled;
     private final boolean mLocalTextClassifierEnabled;
@@ -225,6 +244,7 @@
     private final boolean mTemplateIntentFactoryEnabled;
     private final boolean mTranslateInClassificationEnabled;
     private final boolean mDetectLanguagesFromTextEnabled;
+    private final float[] mLangIdContextSettings;
 
     private TextClassificationConstants(@Nullable String settings) {
         ConfigParser configParser = new ConfigParser(settings);
@@ -272,9 +292,10 @@
                 configParser.getInt(
                         GENERATE_LINKS_LOG_SAMPLE_RATE,
                         GENERATE_LINKS_LOG_SAMPLE_RATE_DEFAULT);
-        mEntityListDefault = parseStringList(configParser.getString(
-                ENTITY_LIST_DEFAULT,
-                ENTITY_LIST_DEFAULT_VALUE));
+        mEntityListDefault = parseStringList(
+                configParser.getString(
+                        ENTITY_LIST_DEFAULT,
+                        ENTITY_LIST_DEFAULT_VALUE));
         mEntityListNotEditable = parseStringList(
                 configParser.getString(
                         ENTITY_LIST_NOT_EDITABLE,
@@ -295,13 +316,22 @@
                 configParser.getFloat(
                         LANG_ID_THRESHOLD_OVERRIDE,
                         LANG_ID_THRESHOLD_OVERRIDE_DEFAULT);
-        mTemplateIntentFactoryEnabled = configParser.getBoolean(
-                TEMPLATE_INTENT_FACTORY_ENABLED,
-                TEMPLATE_INTENT_FACTORY_ENABLED_DEFAULT);
-        mTranslateInClassificationEnabled = configParser.getBoolean(
-                TRANSLATE_IN_CLASSIFICATION_ENABLED, TRANSLATE_IN_CLASSIFICATION_ENABLED_DEFAULT);
-        mDetectLanguagesFromTextEnabled = configParser.getBoolean(
-                DETECT_LANGUAGES_FROM_TEXT_ENABLED, DETECT_LANGUAGES_FROM_TEXT_ENABLED_DEFAULT);
+        mTemplateIntentFactoryEnabled =
+                configParser.getBoolean(
+                        TEMPLATE_INTENT_FACTORY_ENABLED,
+                        TEMPLATE_INTENT_FACTORY_ENABLED_DEFAULT);
+        mTranslateInClassificationEnabled =
+                configParser.getBoolean(
+                        TRANSLATE_IN_CLASSIFICATION_ENABLED,
+                        TRANSLATE_IN_CLASSIFICATION_ENABLED_DEFAULT);
+        mDetectLanguagesFromTextEnabled =
+                configParser.getBoolean(
+                        DETECT_LANGUAGES_FROM_TEXT_ENABLED,
+                        DETECT_LANGUAGES_FROM_TEXT_ENABLED_DEFAULT);
+        mLangIdContextSettings = parseFloatArray(
+                configParser,
+                LANG_ID_CONTEXT_SETTINGS,
+                LANG_ID_CONTEXT_SETTINGS_DEFAULT);
     }
 
     /** Load from a settings string. */
@@ -389,10 +419,35 @@
         return mDetectLanguagesFromTextEnabled;
     }
 
+    public float[] getLangIdContextSettings() {
+        return mLangIdContextSettings;
+    }
+
     private static List<String> parseStringList(String listStr) {
         return Collections.unmodifiableList(Arrays.asList(listStr.split(STRING_LIST_DELIMITER)));
     }
 
+    private static float[] parseFloatArray(
+            ConfigParser configParser, String key, String defaultStr) {
+        final String str = configParser.getString(key, defaultStr);
+        final String[] defaultSplit = defaultStr.split(STRING_LIST_DELIMITER);
+        String[] split = str.split(STRING_LIST_DELIMITER);
+        if (split.length != defaultSplit.length) {
+            Log.v(LOG_TAG, "Error parsing " + key + " flag. Using defaults.");
+            split = defaultSplit;
+        }
+        final float[] result = new float[split.length];
+        for (int i = 0; i < split.length; i++) {
+            try {
+                result[i] = Float.parseFloat(split[i]);
+            } catch (NumberFormatException e) {
+                Log.v(LOG_TAG, "Error parsing part of " + key + " flag. Using defaults.");
+                result[i] = Float.parseFloat(defaultSplit[i]);
+            }
+        }
+        return result;
+    }
+
     void dump(IndentingPrintWriter pw) {
         pw.println("TextClassificationConstants:");
         pw.increaseIndent();
@@ -417,6 +472,7 @@
         pw.printPair("isTemplateIntentFactoryEnabled", mTemplateIntentFactoryEnabled);
         pw.printPair("isTranslateInClassificationEnabled", mTranslateInClassificationEnabled);
         pw.printPair("isDetectLanguageFromTextEnabled", mDetectLanguagesFromTextEnabled);
+        pw.printPair("getLangIdContextSettings", Arrays.toString(mLangIdContextSettings));
         pw.decreaseIndent();
         pw.println();
     }
diff --git a/core/java/android/view/textclassifier/TextClassifier.java b/core/java/android/view/textclassifier/TextClassifier.java
index a4e5502..ac8a429 100644
--- a/core/java/android/view/textclassifier/TextClassifier.java
+++ b/core/java/android/view/textclassifier/TextClassifier.java
@@ -33,11 +33,13 @@
 import android.text.util.Linkify.LinkifyMask;
 import android.util.ArrayMap;
 
+import com.android.internal.annotations.GuardedBy;
 import com.android.internal.util.IndentingPrintWriter;
 import com.android.internal.util.Preconditions;
 
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
+import java.text.BreakIterator;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -644,11 +646,14 @@
      *  <li>Provides validation of input parameters to TextClassifier methods
      * </ul>
      *
-     * Intended to be used only in this package.
+     * Intended to be used only for TextClassifier purposes.
      * @hide
      */
     final class Utils {
 
+        @GuardedBy("WORD_ITERATOR")
+        private static final BreakIterator WORD_ITERATOR = BreakIterator.getWordInstance();
+
         /**
          * @throws IllegalArgumentException if text is null; startIndex is negative;
          *      endIndex is greater than text.length() or is not greater than startIndex;
@@ -666,6 +671,47 @@
         }
 
         /**
+         * Returns the substring of {@code text} that contains at least text from index
+         * {@code start} <i>(inclusive)</i> to index {@code end} <i><(exclusive)/i> with the goal of
+         * returning text that is at least {@code minimumLength}. If {@code text} is not long
+         * enough, this will return {@code text}. This method returns text at word boundaries.
+         *
+         * @param text the source text
+         * @param start the start index of text that must be included
+         * @param end the end index of text that must be included
+         * @param minimumLength minimum length of text to return if {@code text} is long enough
+         */
+        public static String getSubString(
+                String text, int start, int end, int minimumLength) {
+            Preconditions.checkArgument(start >= 0);
+            Preconditions.checkArgument(end <= text.length());
+            Preconditions.checkArgument(start <= end);
+
+            if (text.length() < minimumLength) {
+                return text;
+            }
+
+            final int length = end - start;
+            if (length >= minimumLength) {
+                return text.substring(start, end);
+            }
+
+            final int offset = (minimumLength - length) / 2;
+            int iterStart = Math.max(0, Math.min(start - offset, text.length() - minimumLength));
+            int iterEnd = Math.min(text.length(), iterStart + minimumLength);
+
+            synchronized (WORD_ITERATOR) {
+                WORD_ITERATOR.setText(text);
+                iterStart = WORD_ITERATOR.isBoundary(iterStart)
+                        ? iterStart : Math.max(0, WORD_ITERATOR.preceding(iterStart));
+                iterEnd = WORD_ITERATOR.isBoundary(iterEnd)
+                        ? iterEnd : Math.max(iterEnd, WORD_ITERATOR.following(iterEnd));
+                WORD_ITERATOR.setText("");
+                return text.substring(iterStart, iterEnd);
+            }
+        }
+
+        /**
          * Generates links using legacy {@link Linkify}.
          */
         public static TextLinks generateLegacyLinks(@NonNull TextLinks.Request request) {
diff --git a/core/java/android/view/textclassifier/TextClassifierImpl.java b/core/java/android/view/textclassifier/TextClassifierImpl.java
index 0f3a8cf..8f5f0a37 100644
--- a/core/java/android/view/textclassifier/TextClassifierImpl.java
+++ b/core/java/android/view/textclassifier/TextClassifierImpl.java
@@ -21,10 +21,19 @@
 import android.annotation.WorkerThread;
 import android.app.RemoteAction;
 import android.content.Context;
+import android.content.Intent;
 import android.icu.util.ULocale;
 import android.os.Bundle;
 import android.os.LocaleList;
 import android.os.ParcelFileDescriptor;
+import android.util.ArrayMap;
+import android.util.ArraySet;
+import android.util.Pair;
+import android.view.textclassifier.intent.ClassificationIntentFactory;
+import android.view.textclassifier.intent.LabeledIntent;
+import android.view.textclassifier.intent.LegacyClassificationIntentFactory;
+import android.view.textclassifier.intent.TemplateClassificationIntentFactory;
+import android.view.textclassifier.intent.TemplateIntentFactory;
 
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.util.IndentingPrintWriter;
@@ -33,6 +42,7 @@
 import com.google.android.textclassifier.ActionsSuggestionsModel;
 import com.google.android.textclassifier.AnnotatorModel;
 import com.google.android.textclassifier.LangIdModel;
+import com.google.android.textclassifier.LangIdModel.LanguageResult;
 
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -41,11 +51,12 @@
 import java.time.ZonedDateTime;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.HashMap;
+import java.util.Collections;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
+import java.util.Set;
 
 /**
  * Default implementation of the {@link TextClassifier} interface.
@@ -85,19 +96,19 @@
 
     private final Object mLock = new Object();
 
-    @GuardedBy("mLock") // Do not access outside this lock.
+    @GuardedBy("mLock")
     private ModelFileManager.ModelFile mAnnotatorModelInUse;
-    @GuardedBy("mLock") // Do not access outside this lock.
+    @GuardedBy("mLock")
     private AnnotatorModel mAnnotatorImpl;
 
-    @GuardedBy("mLock") // Do not access outside this lock.
+    @GuardedBy("mLock")
     private ModelFileManager.ModelFile mLangIdModelInUse;
-    @GuardedBy("mLock") // Do not access outside this lock.
+    @GuardedBy("mLock")
     private LangIdModel mLangIdImpl;
 
-    @GuardedBy("mLock") // Do not access outside this lock.
+    @GuardedBy("mLock")
     private ModelFileManager.ModelFile mActionModelInUse;
-    @GuardedBy("mLock") // Do not access outside this lock.
+    @GuardedBy("mLock")
     private ActionsSuggestionsModel mActionsImpl;
 
     private final SelectionSessionLogger mSessionLogger = new SelectionSessionLogger();
@@ -110,7 +121,7 @@
     private final ModelFileManager mLangIdModelFileManager;
     private final ModelFileManager mActionsModelFileManager;
 
-    private final IntentFactory mIntentFactory;
+    private final ClassificationIntentFactory mClassificationIntentFactory;
     private final TemplateIntentFactory mTemplateIntentFactory;
 
     public TextClassifierImpl(
@@ -142,10 +153,10 @@
                         ActionsSuggestionsModel::getLocales));
 
         mTemplateIntentFactory = new TemplateIntentFactory();
-        mIntentFactory = mSettings.isTemplateIntentFactoryEnabled()
+        mClassificationIntentFactory = mSettings.isTemplateIntentFactoryEnabled()
                 ? new TemplateClassificationIntentFactory(
-                mTemplateIntentFactory, new LegacyIntentFactory())
-                : new LegacyIntentFactory();
+                mTemplateIntentFactory, new LegacyClassificationIntentFactory())
+                : new LegacyClassificationIntentFactory();
     }
 
     public TextClassifierImpl(Context context, TextClassificationConstants settings) {
@@ -278,7 +289,7 @@
             final ZonedDateTime refTime = ZonedDateTime.now();
             final Collection<String> entitiesToIdentify = request.getEntityConfig() != null
                     ? request.getEntityConfig().resolveEntityListModifications(
-                    getEntitiesForHints(request.getEntityConfig().getHints()))
+                            getEntitiesForHints(request.getEntityConfig().getHints()))
                     : mSettings.getEntityListDefault();
             final String localesString = concatenateLocales(request.getDefaultLocales());
             final String detectLanguageTags = detectLanguageTagsFromText(request.getText());
@@ -299,7 +310,7 @@
                         || !entitiesToIdentify.contains(results[0].getCollection())) {
                     continue;
                 }
-                final Map<String, Float> entityScores = new HashMap<>();
+                final Map<String, Float> entityScores = new ArrayMap<>();
                 for (int i = 0; i < results.length; i++) {
                     entityScores.put(results[i].getCollection(), results[i].getScore());
                 }
@@ -435,21 +446,20 @@
             if (!expectedTypes.contains(actionType)) {
                 continue;
             }
-            List<LabeledIntent> labeledIntents =
-                    mTemplateIntentFactory.create(nativeSuggestion.getRemoteActionTemplates());
-            Bundle extras = new Bundle();
+            LabeledIntent.Result labeledIntentResult =
+                    ActionsSuggestionsHelper.createLabeledIntentResult(
+                            mContext,
+                            mTemplateIntentFactory,
+                            nativeSuggestion);
             RemoteAction remoteAction = null;
-            // Given that we only support implicit intent here, we should expect there is just one
-            // intent for each action type.
-            if (!labeledIntents.isEmpty()) {
-                LabeledIntent.TitleChooser titleChooser =
-                        ActionsSuggestionsHelper.createTitleChooser(actionType);
-                LabeledIntent.Result result = labeledIntents.get(0).resolve(mContext, titleChooser);
-                if (result != null) {
-                    remoteAction = result.remoteAction;
-                    ExtrasUtils.putActionIntent(extras, result.resolvedIntent);
-                }
+            Bundle extras = new Bundle();
+            if (labeledIntentResult != null) {
+                remoteAction = labeledIntentResult.remoteAction;
+                ExtrasUtils.putActionIntent(extras, labeledIntentResult.resolvedIntent);
             }
+            ExtrasUtils.putEntitiesExtras(
+                    extras,
+                    TemplateIntentFactory.nameVariantsToBundle(nativeSuggestion.getEntityData()));
             conversationActions.add(
                     new ConversationAction.Builder(actionType)
                             .setConfidenceScore(nativeSuggestion.getScore())
@@ -616,50 +626,67 @@
             }
         }
 
-        final Bundle foreignLanguageBundle = detectForeignLanguage(classifiedText);
+        final Pair<Bundle, Bundle> languagesBundles = generateLanguageBundles(text, start, end);
+        final Bundle textLanguagesBundle = languagesBundles.first;
+        final Bundle foreignLanguageBundle = languagesBundles.second;
         builder.setForeignLanguageExtra(foreignLanguageBundle);
 
         boolean isPrimaryAction = true;
-        List<LabeledIntent> labeledIntents = mIntentFactory.create(
+        final List<LabeledIntent> labeledIntents = mClassificationIntentFactory.create(
                 mContext,
                 classifiedText,
                 foreignLanguageBundle != null,
                 referenceTime,
                 highestScoringResult);
-        LabeledIntent.TitleChooser titleChooser =
+        final LabeledIntent.TitleChooser titleChooser =
                 (labeledIntent, resolveInfo) -> labeledIntent.titleWithoutEntity;
+
         for (LabeledIntent labeledIntent : labeledIntents) {
-            LabeledIntent.Result result = labeledIntent.resolve(mContext, titleChooser);
+            final LabeledIntent.Result result =
+                    labeledIntent.resolve(mContext, titleChooser, textLanguagesBundle);
             if (result == null) {
                 continue;
             }
+
+            final Intent intent = result.resolvedIntent;
             final RemoteAction action = result.remoteAction;
             if (isPrimaryAction) {
                 // For O backwards compatibility, the first RemoteAction is also written to the
                 // legacy API fields.
                 builder.setIcon(action.getIcon().loadDrawable(mContext));
                 builder.setLabel(action.getTitle().toString());
-                builder.setIntent(result.resolvedIntent);
+                builder.setIntent(intent);
                 builder.setOnClickListener(TextClassification.createIntentOnClickListener(
-                        TextClassification.createPendingIntent(mContext,
-                                result.resolvedIntent, labeledIntent.requestCode)));
+                        TextClassification.createPendingIntent(
+                                mContext, intent, labeledIntent.requestCode)));
                 isPrimaryAction = false;
             }
-            builder.addAction(action, result.resolvedIntent);
+            builder.addAction(action, intent);
         }
 
         return builder.setId(createId(text, start, end)).build();
     }
 
     /**
-     * Returns a bundle with the language and confidence score if it finds the text to be
-     * in a foreign language. Otherwise returns null. This algorithm defines what the system thinks
-     * is a foreign language.
+     * Returns a bundle pair with language detection information for extras.
+     * <p>
+     * Pair.first = textLanguagesBundle - A bundle containing information about all detected
+     * languages in the text. May be null if language detection fails or is disabled. This is
+     * typically expected to be added to a textClassifier generated remote action intent.
+     * See {@link ExtrasUtils#putTextLanguagesExtra(Bundle, Bundle)}.
+     * See {@link ExtrasUtils#getTopLanguage(Intent)}.
+     * <p>
+     * Pair.second = foreignLanguageBundle - A bundle with the language and confidence score if the
+     * system finds the text to be in a foreign language. Otherwise is null.
+     * See {@link TextClassification.Builder#setForeignLanguageExtra(Bundle)}.
+     *
+     * @param context the context of the text to detect languages for
+     * @param start the start index of the text
+     * @param end the end index of the text
      */
     // TODO: Revisit this algorithm.
     // TODO: Consider making this public API.
-    @Nullable
-    private Bundle detectForeignLanguage(String text) {
+    private Pair<Bundle, Bundle> generateLanguageBundles(String context, int start, int end) {
         if (!mSettings.isTranslateInClassificationEnabled()) {
             return null;
         }
@@ -668,42 +695,118 @@
             if (threshold < 0 || threshold > 1) {
                 Log.w(LOG_TAG,
                         "[detectForeignLanguage] unexpected threshold is found: " + threshold);
-                return null;
+                return Pair.create(null, null);
             }
 
-            final LangIdModel langId = getLangIdImpl();
-            final LangIdModel.LanguageResult[] langResults = langId.detectLanguages(text);
-            if (langResults.length <= 0) {
-                return null;
+            final EntityConfidence languageScores = detectLanguages(context, start, end);
+            if (languageScores.getEntities().isEmpty()) {
+                return Pair.create(null, null);
             }
 
-            LangIdModel.LanguageResult highestScoringResult = langResults[0];
-            for (int i = 1; i < langResults.length; i++) {
-                if (langResults[i].getScore() > highestScoringResult.getScore()) {
-                    highestScoringResult = langResults[i];
-                }
-            }
-            if (highestScoringResult.getScore() < threshold) {
-                return null;
+            final Bundle textLanguagesBundle = new Bundle();
+            ExtrasUtils.putTopLanguageScores(textLanguagesBundle, languageScores);
+
+            final String language = languageScores.getEntities().get(0);
+            final float score = languageScores.getConfidenceScore(language);
+            if (score < threshold) {
+                return Pair.create(textLanguagesBundle, null);
             }
 
-            Log.v(LOG_TAG, String.format("Language detected: <%s:%s>",
-                    highestScoringResult.getLanguage(), highestScoringResult.getScore()));
+            Log.v(LOG_TAG, String.format(
+                    Locale.US, "Language detected: <%s:%.2f>", language, score));
 
-            final Locale detected = new Locale(highestScoringResult.getLanguage());
+            final Locale detected = new Locale(language);
             final LocaleList deviceLocales = LocaleList.getDefault();
             final int size = deviceLocales.size();
             for (int i = 0; i < size; i++) {
                 if (deviceLocales.get(i).getLanguage().equals(detected.getLanguage())) {
-                    return null;
+                    return Pair.create(textLanguagesBundle, null);
                 }
             }
-            return ExtrasUtils.createForeignLanguageExtra(
-                    detected.getLanguage(), highestScoringResult.getScore(), langId.getVersion());
+            final Bundle foreignLanguageBundle = ExtrasUtils.createForeignLanguageExtra(
+                    detected.getLanguage(), score, getLangIdImpl().getVersion());
+            return Pair.create(textLanguagesBundle, foreignLanguageBundle);
         } catch (Throwable t) {
-            Log.e(LOG_TAG, "Error detecting foreign text. Ignored.", t);
+            Log.e(LOG_TAG, "Error generating language bundles.", t);
         }
-        return null;
+        return Pair.create(null, null);
+    }
+
+    /**
+     * Detect the language of a piece of text by taking surrounding text into consideration.
+     *
+     * @param text text providing context for the text for which its language is to be detected
+     * @param start the start index of the text to detect its language
+     * @param end the end index of the text to detect its language
+     */
+    // TODO: Revisit this algorithm.
+    private EntityConfidence detectLanguages(String text, int start, int end)
+            throws FileNotFoundException {
+        Preconditions.checkArgument(start >= 0);
+        Preconditions.checkArgument(end <= text.length());
+        Preconditions.checkArgument(start <= end);
+
+        final float[] langIdContextSettings = mSettings.getLangIdContextSettings();
+        // The minimum size of text to prefer for detection.
+        final int minimumTextSize = (int) langIdContextSettings[0];
+        // For reducing the score when text is less than the preferred size.
+        final float penalizeRatio = langIdContextSettings[1];
+        // Original detection score to surrounding text detection score ratios.
+        final float subjectTextScoreRatio = langIdContextSettings[2];
+        final float moreTextScoreRatio = 1f - subjectTextScoreRatio;
+        Log.v(LOG_TAG,
+                String.format(Locale.US, "LangIdContextSettings: "
+                        + "minimumTextSize=%d, penalizeRatio=%.2f, "
+                        + "subjectTextScoreRatio=%.2f, moreTextScoreRatio=%.2f",
+                        minimumTextSize, penalizeRatio, subjectTextScoreRatio, moreTextScoreRatio));
+
+        if (end - start < minimumTextSize && penalizeRatio <= 0) {
+            return new EntityConfidence(Collections.emptyMap());
+        }
+
+        final String subject = text.substring(start, end);
+        final EntityConfidence scores = detectLanguages(subject);
+
+        if (subject.length() >= minimumTextSize
+                || subject.length() == text.length()
+                || subjectTextScoreRatio * penalizeRatio >= 1) {
+            return scores;
+        }
+
+        final EntityConfidence moreTextScores;
+        if (moreTextScoreRatio >= 0) {
+            // Attempt to grow the detection text to be at least minimumTextSize long.
+            final String moreText = Utils.getSubString(text, start, end, minimumTextSize);
+            moreTextScores = detectLanguages(moreText);
+        } else {
+            moreTextScores = new EntityConfidence(Collections.emptyMap());
+        }
+
+        // Combine the original detection scores with the those returned after including more text.
+        final Map<String, Float> newScores = new ArrayMap<>();
+        final Set<String> languages = new ArraySet<>();
+        languages.addAll(scores.getEntities());
+        languages.addAll(moreTextScores.getEntities());
+        for (String language : languages) {
+            final float score = (subjectTextScoreRatio * scores.getConfidenceScore(language)
+                    + moreTextScoreRatio * moreTextScores.getConfidenceScore(language))
+                    * penalizeRatio;
+            newScores.put(language, score);
+        }
+        return new EntityConfidence(newScores);
+    }
+
+    /**
+     * Detect languages for the specified text.
+     */
+    private EntityConfidence detectLanguages(String text) throws FileNotFoundException {
+        final LangIdModel langId = getLangIdImpl();
+        final LangIdModel.LanguageResult[] langResults = langId.detectLanguages(text);
+        final Map<String, Float> languagesMap = new ArrayMap<>();
+        for (LanguageResult langResult : langResults) {
+            languagesMap.put(langResult.getLanguage(), langResult.getScore());
+        }
+        return new EntityConfidence(languagesMap);
     }
 
     private float getLangIdThreshold() {
diff --git a/core/java/android/view/textclassifier/IntentFactory.java b/core/java/android/view/textclassifier/intent/ClassificationIntentFactory.java
similarity index 89%
rename from core/java/android/view/textclassifier/IntentFactory.java
rename to core/java/android/view/textclassifier/intent/ClassificationIntentFactory.java
index 722c812..b034846 100644
--- a/core/java/android/view/textclassifier/IntentFactory.java
+++ b/core/java/android/view/textclassifier/intent/ClassificationIntentFactory.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import android.annotation.Nullable;
 import android.content.Context;
@@ -27,7 +27,7 @@
 /**
  * @hide
  */
-public interface IntentFactory {
+public interface ClassificationIntentFactory {
 
     /**
      * Return a list of LabeledIntent from the classification result.
@@ -51,8 +51,7 @@
                 new Intent(Intent.ACTION_TRANSLATE)
                         // TODO: Probably better to introduce a "translate" scheme instead of
                         // using EXTRA_TEXT.
-                        .putExtra(Intent.EXTRA_TEXT, text)
-                        .putExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER, true),
+                        .putExtra(Intent.EXTRA_TEXT, text),
                 text.hashCode()));
     }
 }
diff --git a/core/java/android/view/textclassifier/LabeledIntent.java b/core/java/android/view/textclassifier/intent/LabeledIntent.java
similarity index 81%
rename from core/java/android/view/textclassifier/LabeledIntent.java
rename to core/java/android/view/textclassifier/intent/LabeledIntent.java
index d2897b2..11d64f1 100644
--- a/core/java/android/view/textclassifier/LabeledIntent.java
+++ b/core/java/android/view/textclassifier/intent/LabeledIntent.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import android.annotation.Nullable;
 import android.app.PendingIntent;
@@ -24,7 +24,12 @@
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
 import android.graphics.drawable.Icon;
+import android.os.Bundle;
 import android.text.TextUtils;
+import android.view.textclassifier.ExtrasUtils;
+import android.view.textclassifier.Log;
+import android.view.textclassifier.TextClassification;
+import android.view.textclassifier.TextClassifier;
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.Preconditions;
@@ -85,10 +90,16 @@
 
     /**
      * Return the resolved result.
+     *
+     * @param context the context to resolve the result's intent and action
+     * @param titleChooser for choosing an action title
+     * @param textLanguagesBundle containing language detection information
      */
     @Nullable
     public Result resolve(
-            Context context, @Nullable TitleChooser titleChooser) {
+            Context context,
+            @Nullable TitleChooser titleChooser,
+            @Nullable Bundle textLanguagesBundle) {
         final PackageManager pm = context.getPackageManager();
         final ResolveInfo resolveInfo = pm.resolveActivity(intent, 0);
 
@@ -104,6 +115,10 @@
         }
         Intent resolvedIntent = new Intent(intent);
         resolvedIntent.setComponent(new ComponentName(packageName, className));
+        resolvedIntent.putExtra(
+                TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER,
+                getFromTextClassifierExtra(textLanguagesBundle));
+
         boolean shouldShowIcon = false;
         Icon icon = null;
         if (!"android".equals(packageName)) {
@@ -115,25 +130,32 @@
         }
         if (icon == null) {
             // RemoteAction requires that there be an icon.
-            icon = Icon.createWithResource("android",
-                    com.android.internal.R.drawable.ic_more_items);
+            icon = Icon.createWithResource(
+                    "android", com.android.internal.R.drawable.ic_more_items);
         }
         final PendingIntent pendingIntent =
                 TextClassification.createPendingIntent(context, resolvedIntent, requestCode);
-        if (titleChooser == null) {
-            titleChooser = DEFAULT_TITLE_CHOOSER;
-        }
+        titleChooser = titleChooser == null ? DEFAULT_TITLE_CHOOSER : titleChooser;
         CharSequence title = titleChooser.chooseTitle(this, resolveInfo);
         if (TextUtils.isEmpty(title)) {
             Log.w(TAG, "Custom titleChooser return null, fallback to the default titleChooser");
             title = DEFAULT_TITLE_CHOOSER.chooseTitle(this, resolveInfo);
         }
-        final RemoteAction action =
-                new RemoteAction(icon, title, description, pendingIntent);
+        final RemoteAction action = new RemoteAction(icon, title, description, pendingIntent);
         action.setShouldShowIcon(shouldShowIcon);
         return new Result(resolvedIntent, action);
     }
 
+    private Bundle getFromTextClassifierExtra(@Nullable Bundle textLanguagesBundle) {
+        if (textLanguagesBundle != null) {
+            final Bundle bundle = new Bundle();
+            ExtrasUtils.putTextLanguagesExtra(bundle, textLanguagesBundle);
+            return bundle;
+        } else {
+            return Bundle.EMPTY;
+        }
+    }
+
     /**
      * Data class that holds the result.
      */
diff --git a/core/java/android/view/textclassifier/LegacyIntentFactory.java b/core/java/android/view/textclassifier/intent/LegacyClassificationIntentFactory.java
similarity index 96%
rename from core/java/android/view/textclassifier/LegacyIntentFactory.java
rename to core/java/android/view/textclassifier/intent/LegacyClassificationIntentFactory.java
index ea9229d..7916791 100644
--- a/core/java/android/view/textclassifier/LegacyIntentFactory.java
+++ b/core/java/android/view/textclassifier/intent/LegacyClassificationIntentFactory.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import static java.time.temporal.ChronoUnit.MILLIS;
 
@@ -29,6 +29,8 @@
 import android.provider.Browser;
 import android.provider.CalendarContract;
 import android.provider.ContactsContract;
+import android.view.textclassifier.Log;
+import android.view.textclassifier.TextClassifier;
 
 import com.google.android.textclassifier.AnnotatorModel;
 
@@ -44,14 +46,12 @@
  * Creates intents based on the classification type.
  * @hide
  */
-public final class LegacyIntentFactory implements IntentFactory {
+public final class LegacyClassificationIntentFactory implements ClassificationIntentFactory {
 
-    private static final String TAG = "LegacyIntentFactory";
+    private static final String TAG = "LegacyClassificationIntentFactory";
     private static final long MIN_EVENT_FUTURE_MILLIS = TimeUnit.MINUTES.toMillis(5);
     private static final long DEFAULT_EVENT_DURATION = TimeUnit.HOURS.toMillis(1);
 
-    public LegacyIntentFactory() {}
-
     @NonNull
     @Override
     public List<LabeledIntent> create(Context context, String text, boolean foreignText,
@@ -96,10 +96,8 @@
                 break;
         }
         if (foreignText) {
-            IntentFactory.insertTranslateAction(actions, context, text);
+            ClassificationIntentFactory.insertTranslateAction(actions, context, text);
         }
-        actions.forEach(
-                action -> action.intent.putExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER, true));
         return actions;
     }
 
diff --git a/core/java/android/view/textclassifier/TemplateClassificationIntentFactory.java b/core/java/android/view/textclassifier/intent/TemplateClassificationIntentFactory.java
similarity index 82%
rename from core/java/android/view/textclassifier/TemplateClassificationIntentFactory.java
rename to core/java/android/view/textclassifier/intent/TemplateClassificationIntentFactory.java
index ed0259f..111fc6a 100644
--- a/core/java/android/view/textclassifier/TemplateClassificationIntentFactory.java
+++ b/core/java/android/view/textclassifier/intent/TemplateClassificationIntentFactory.java
@@ -13,14 +13,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.content.Context;
+import android.view.textclassifier.Log;
+import android.view.textclassifier.TextClassifier;
 
 import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.ArrayUtils;
 import com.android.internal.util.Preconditions;
 
 import com.google.android.textclassifier.AnnotatorModel;
@@ -36,19 +37,19 @@
  * @hide
  */
 @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
-public final class TemplateClassificationIntentFactory implements IntentFactory {
+public final class TemplateClassificationIntentFactory implements ClassificationIntentFactory {
     private static final String TAG = TextClassifier.DEFAULT_LOG_TAG;
     private final TemplateIntentFactory mTemplateIntentFactory;
-    private final IntentFactory mFallback;
+    private final ClassificationIntentFactory mFallback;
 
     public TemplateClassificationIntentFactory(TemplateIntentFactory templateIntentFactory,
-            IntentFactory fallback) {
+            ClassificationIntentFactory fallback) {
         mTemplateIntentFactory = Preconditions.checkNotNull(templateIntentFactory);
         mFallback = Preconditions.checkNotNull(fallback);
     }
 
     /**
-     * Returns a list of {@link android.view.textclassifier.LabeledIntent}
+     * Returns a list of {@link LabeledIntent}
      * that are constructed from the classification result.
      */
     @NonNull
@@ -63,15 +64,16 @@
             return Collections.emptyList();
         }
         RemoteActionTemplate[] remoteActionTemplates = classification.getRemoteActionTemplates();
-        if (ArrayUtils.isEmpty(remoteActionTemplates)) {
+        if (remoteActionTemplates == null) {
             // RemoteActionTemplate is missing, fallback.
-            Log.w(TAG, "RemoteActionTemplate is missing, fallback to LegacyIntentFactory.");
+            Log.w(TAG, "RemoteActionTemplate is missing, fallback to"
+                    + " LegacyClassificationIntentFactory.");
             return mFallback.create(context, text, foreignText, referenceTime, classification);
         }
         final List<LabeledIntent> labeledIntents =
                 mTemplateIntentFactory.create(remoteActionTemplates);
         if (foreignText) {
-            IntentFactory.insertTranslateAction(labeledIntents, context, text.trim());
+            ClassificationIntentFactory.insertTranslateAction(labeledIntents, context, text.trim());
         }
         return labeledIntents;
     }
diff --git a/core/java/android/view/textclassifier/TemplateIntentFactory.java b/core/java/android/view/textclassifier/intent/TemplateIntentFactory.java
similarity index 87%
rename from core/java/android/view/textclassifier/TemplateIntentFactory.java
rename to core/java/android/view/textclassifier/intent/TemplateIntentFactory.java
index 0696d98..59cd7ab 100644
--- a/core/java/android/view/textclassifier/TemplateIntentFactory.java
+++ b/core/java/android/view/textclassifier/intent/TemplateIntentFactory.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -21,15 +21,15 @@
 import android.net.Uri;
 import android.os.Bundle;
 import android.text.TextUtils;
+import android.view.textclassifier.Log;
+import android.view.textclassifier.TextClassifier;
 
 import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.util.ArrayUtils;
 
 import com.google.android.textclassifier.NamedVariant;
 import com.google.android.textclassifier.RemoteActionTemplate;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
 /**
@@ -41,11 +41,14 @@
 public final class TemplateIntentFactory {
     private static final String TAG = TextClassifier.DEFAULT_LOG_TAG;
 
-    @NonNull
+    /**
+     * Constructs and returns a list of {@link LabeledIntent} based on the given templates.
+     */
+    @Nullable
     public List<LabeledIntent> create(
-            @Nullable RemoteActionTemplate[] remoteActionTemplates) {
-        if (ArrayUtils.isEmpty(remoteActionTemplates)) {
-            return Collections.emptyList();
+            @NonNull RemoteActionTemplate[] remoteActionTemplates) {
+        if (remoteActionTemplates.length == 0) {
+            return new ArrayList<>();
         }
         final List<LabeledIntent> labeledIntents = new ArrayList<>();
         for (RemoteActionTemplate remoteActionTemplate : remoteActionTemplates) {
@@ -63,8 +66,6 @@
                                     ? LabeledIntent.DEFAULT_REQUEST_CODE
                                     : remoteActionTemplate.requestCode));
         }
-        labeledIntents.forEach(
-                action -> action.intent.putExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER, true));
         return labeledIntents;
     }
 
@@ -108,11 +109,14 @@
                 }
             }
         }
-        intent.putExtras(createExtras(remoteActionTemplate.extras));
+        intent.putExtras(nameVariantsToBundle(remoteActionTemplate.extras));
         return intent;
     }
 
-    private static Bundle createExtras(NamedVariant[] namedVariants) {
+    /**
+     * Converts an array of {@link NamedVariant} to a Bundle and returns it.
+     */
+    public static Bundle nameVariantsToBundle(@Nullable NamedVariant[] namedVariants) {
         if (namedVariants == null) {
             return Bundle.EMPTY;
         }
@@ -142,7 +146,8 @@
                     break;
                 default:
                     Log.w(TAG,
-                            "Unsupported type found in createExtras : " + namedVariant.getType());
+                            "Unsupported type found in nameVariantsToBundle : "
+                                    + namedVariant.getType());
             }
         }
         return bundle;
diff --git a/core/jni/android/graphics/BitmapFactory.cpp b/core/jni/android/graphics/BitmapFactory.cpp
index 4ba4540..47b1548 100644
--- a/core/jni/android/graphics/BitmapFactory.cpp
+++ b/core/jni/android/graphics/BitmapFactory.cpp
@@ -507,18 +507,9 @@
                 ninePatchChunk, ninePatchInsets, -1);
     }
 
-    // Speculative fix for b/112551574. It doesn't seem like |b| can be null. If it is, print some
-    // info that might be helpful to diagnose.
-    Bitmap* b = defaultAllocator.getStorageObjAndReset();
-    if (!b) {
-        ALOGW("defaultAllocator has no storage object!");
-        ALOGW("\tjavaBitmap: %s", (javaBitmap == nullptr ? "null" : "present"));
-        ALOGW("\tisHardware: %s", (isHardware ? "true" : "false"));
-        ALOGW("\twillScale: %s", (willScale ? "true" : "false"));
-        return nullptr;
-    }
     // now create the java bitmap
-    return bitmap::createBitmap(env, b, bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1);
+    return bitmap::createBitmap(env, defaultAllocator.getStorageObjAndReset(),
+            bitmapCreateFlags, ninePatchChunk, ninePatchInsets, -1);
 }
 
 static jobject nativeDecodeStream(JNIEnv* env, jobject clazz, jobject is, jbyteArray storage,
diff --git a/core/jni/android/graphics/Paint.cpp b/core/jni/android/graphics/Paint.cpp
index cd7346e..cd5c734 100644
--- a/core/jni/android/graphics/Paint.cpp
+++ b/core/jni/android/graphics/Paint.cpp
@@ -723,13 +723,17 @@
         obj->setStyle(style);
     }
 
-    static void setColor(jlong paintHandle, jlong colorSpaceHandle,
-            jfloat r, jfloat g, jfloat b, jfloat a) {
+    static void setColorLong(jlong paintHandle, jlong colorSpaceHandle,
+            jlong colorLong) {
+        SkColor4f color = GraphicsJNI::convertColorLong(colorLong);
         sk_sp<SkColorSpace> cs = GraphicsJNI::getNativeColorSpace(colorSpaceHandle);
-        SkColor4f color = SkColor4f{r, g, b, a};
         reinterpret_cast<Paint*>(paintHandle)->setColor4f(color, cs.get());
     }
 
+    static void setColor(jlong paintHandle, jint color) {
+        reinterpret_cast<Paint*>(paintHandle)->setColor(color);
+    }
+
     static void setAlpha(jlong paintHandle, jint a) {
         reinterpret_cast<Paint*>(paintHandle)->setAlpha(a);
     }
@@ -991,9 +995,9 @@
 
     static void setShadowLayer(jlong paintHandle, jfloat radius,
                                jfloat dx, jfloat dy, jlong colorSpaceHandle,
-                               jfloat r, jfloat g, jfloat b, jfloat a) {
+                               jlong colorLong) {
+        SkColor4f color = GraphicsJNI::convertColorLong(colorLong);
         sk_sp<SkColorSpace> cs = GraphicsJNI::getNativeColorSpace(colorSpaceHandle);
-        SkColor4f color = SkColor4f{r, g, b, a};
 
         Paint* paint = reinterpret_cast<Paint*>(paintHandle);
         if (radius <= 0) {
@@ -1082,7 +1086,8 @@
     {"nSetDither","(JZ)V", (void*) PaintGlue::setDither},
     {"nGetStyle","(J)I", (void*) PaintGlue::getStyle},
     {"nSetStyle","(JI)V", (void*) PaintGlue::setStyle},
-    {"nSetColor","(JJFFFF)V", (void*) PaintGlue::setColor},
+    {"nSetColor","(JI)V", (void*) PaintGlue::setColor},
+    {"nSetColor","(JJJ)V", (void*) PaintGlue::setColorLong},
     {"nSetAlpha","(JI)V", (void*) PaintGlue::setAlpha},
     {"nGetStrokeWidth","(J)F", (void*) PaintGlue::getStrokeWidth},
     {"nSetStrokeWidth","(JF)V", (void*) PaintGlue::setStrokeWidth},
@@ -1125,7 +1130,7 @@
     {"nGetUnderlineThickness","(J)F", (void*) PaintGlue::getUnderlineThickness},
     {"nGetStrikeThruPosition","(J)F", (void*) PaintGlue::getStrikeThruPosition},
     {"nGetStrikeThruThickness","(J)F", (void*) PaintGlue::getStrikeThruThickness},
-    {"nSetShadowLayer", "(JFFFJFFFF)V", (void*)PaintGlue::setShadowLayer},
+    {"nSetShadowLayer", "(JFFFJJ)V", (void*)PaintGlue::setShadowLayer},
     {"nHasShadowLayer", "(J)Z", (void*)PaintGlue::hasShadowLayer},
     {"nEqualsForTextMeasurement", "(JJ)Z", (void*)PaintGlue::equalsForTextMeasurement},
 };
diff --git a/core/jni/android_hardware_input_InputWindowHandle.cpp b/core/jni/android_hardware_input_InputWindowHandle.cpp
index eb71052..a1d1d4f 100644
--- a/core/jni/android_hardware_input_InputWindowHandle.cpp
+++ b/core/jni/android_hardware_input_InputWindowHandle.cpp
@@ -31,6 +31,11 @@
 
 namespace android {
 
+struct WeakRefHandleField {
+    jfieldID handle;
+    jmethodID get;
+};
+
 static struct {
     jfieldID ptr;
     jfieldID inputApplicationHandle;
@@ -57,6 +62,8 @@
     jfieldID inputFeatures;
     jfieldID displayId;
     jfieldID portalToDisplayId;
+    jfieldID replaceTouchableRegionWithCrop;
+    WeakRefHandleField touchableRegionCropHandle;
 } gInputWindowHandleClassInfo;
 
 static Mutex gHandleMutex;
@@ -90,6 +97,7 @@
     jobject tokenObj = env->GetObjectField(obj, gInputWindowHandleClassInfo.token);
     if (tokenObj) {
         mInfo.token = ibinderForJavaObject(env, tokenObj);
+        env->DeleteLocalRef(tokenObj);
     } else {
         mInfo.token.clear();
     }
@@ -161,6 +169,24 @@
         env->DeleteLocalRef(inputApplicationHandleObj);
     }
 
+    mInfo.replaceTouchableRegionWithCrop = env->GetBooleanField(obj,
+            gInputWindowHandleClassInfo.replaceTouchableRegionWithCrop);
+
+    jobject handleObj = env->GetObjectField(obj,
+            gInputWindowHandleClassInfo.touchableRegionCropHandle.handle);
+    if (handleObj) {
+        // Promote java weak reference.
+        jobject strongHandleObj = env->CallObjectMethod(handleObj,
+                gInputWindowHandleClassInfo.touchableRegionCropHandle.get);
+        if (strongHandleObj) {
+            mInfo.touchableRegionCropHandle = ibinderForJavaObject(env, strongHandleObj);
+            env->DeleteLocalRef(strongHandleObj);
+        } else {
+            mInfo.touchableRegionCropHandle.clear();
+        }
+        env->DeleteLocalRef(handleObj);
+    }
+
     env->DeleteLocalRef(obj);
     return true;
 }
@@ -220,6 +246,10 @@
         var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \
         LOG_FATAL_IF(! (var), "Unable to find field " fieldName);
 
+#define GET_METHOD_ID(var, clazz, methodName, methodSignature) \
+        var = env->GetMethodID(clazz, methodName, methodSignature); \
+        LOG_FATAL_IF(! (var), "Unable to find method " methodName);
+
 int register_android_view_InputWindowHandle(JNIEnv* env) {
     int res = jniRegisterNativeMethods(env, "android/view/InputWindowHandle",
             gInputWindowHandleMethods, NELEM(gInputWindowHandleMethods));
@@ -303,6 +333,18 @@
 
     GET_FIELD_ID(gInputWindowHandleClassInfo.portalToDisplayId, clazz,
             "portalToDisplayId", "I");
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.replaceTouchableRegionWithCrop, clazz,
+            "replaceTouchableRegionWithCrop", "Z");
+
+    jclass weakRefClazz;
+    FIND_CLASS(weakRefClazz, "java/lang/ref/Reference");
+
+    GET_METHOD_ID(gInputWindowHandleClassInfo.touchableRegionCropHandle.get, weakRefClazz,
+             "get", "()Ljava/lang/Object;")
+
+    GET_FIELD_ID(gInputWindowHandleClassInfo.touchableRegionCropHandle.handle, clazz,
+            "touchableRegionCropHandle", "Ljava/lang/ref/WeakReference;");
     return 0;
 }
 
diff --git a/core/proto/android/stats/devicepolicy/device_policy_enums.proto b/core/proto/android/stats/devicepolicy/device_policy_enums.proto
index 49221b4..589a6a7 100644
--- a/core/proto/android/stats/devicepolicy/device_policy_enums.proto
+++ b/core/proto/android/stats/devicepolicy/device_policy_enums.proto
@@ -136,11 +136,13 @@
 
   SEPARATE_PROFILE_CHALLENGE_CHANGED = 110;
   SET_GLOBAL_SETTING = 111;
-  PM_IS_INSTALLER_DEVICE_OWNER_OR_AFFILIATED_PROFILE_OWNER = 112;
-  PM_UNINSTALL = 113;
+  INSTALL_PACKAGE = 112;
+  UNINSTALL_PACKAGE = 113;
   WIFI_SERVICE_ADD_NETWORK_SUGGESTIONS = 114;
   WIFI_SERVICE_ADD_OR_UPDATE_NETWORK = 115;
   QUERY_SUMMARY_FOR_DEVICE = 116;
   REMOVE_CROSS_PROFILE_WIDGET_PROVIDER = 117;
   ESTABLISH_VPN = 118;
+  SET_NETWORK_LOGGING_ENABLED = 119;
+  RETRIEVE_NETWORK_LOGS = 120;
 }
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 97593ff..e5fc104 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3681,6 +3681,7 @@
   <java-symbol type="array" name="config_displayWhiteBalanceAmbientColorTemperatures" />
   <java-symbol type="array" name="config_displayWhiteBalanceDisplayColorTemperatures" />
   <java-symbol type="drawable" name="ic_action_open" />
+  <java-symbol type="drawable" name="ic_menu_copy_material" />
 
   <!-- MIME types -->
   <java-symbol type="string" name="mime_type_folder" />
diff --git a/core/tests/coretests/src/android/view/textclassifier/ActionsSuggestionsHelperTest.java b/core/tests/coretests/src/android/view/textclassifier/ActionsSuggestionsHelperTest.java
index 7150d81..5c7287f 100644
--- a/core/tests/coretests/src/android/view/textclassifier/ActionsSuggestionsHelperTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/ActionsSuggestionsHelperTest.java
@@ -27,13 +27,17 @@
 import android.content.ComponentName;
 import android.content.Intent;
 import android.graphics.drawable.Icon;
+import android.net.Uri;
 import android.os.Bundle;
+import android.view.textclassifier.intent.LabeledIntent;
+import android.view.textclassifier.intent.TemplateIntentFactory;
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.SmallTest;
 import androidx.test.runner.AndroidJUnit4;
 
 import com.google.android.textclassifier.ActionsSuggestionsModel;
+import com.google.android.textclassifier.RemoteActionTemplate;
 
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -204,6 +208,77 @@
         assertThat(conversationActions.get(2).getAction()).isNull();
     }
 
+    public void createLabeledIntentResult_null() {
+        ActionsSuggestionsModel.ActionSuggestion nativeSuggestion =
+                new ActionsSuggestionsModel.ActionSuggestion(
+                        "text",
+                        ConversationAction.TYPE_OPEN_URL,
+                        1.0f,
+                        null,
+                        null
+                );
+
+        LabeledIntent.Result labeledIntentResult =
+                ActionsSuggestionsHelper.createLabeledIntentResult(
+                        InstrumentationRegistry.getTargetContext(),
+                        new TemplateIntentFactory(),
+                        nativeSuggestion);
+
+        assertThat(labeledIntentResult).isNull();
+    }
+
+    @Test
+    public void createLabeledIntentResult_emptyList() {
+        ActionsSuggestionsModel.ActionSuggestion nativeSuggestion =
+                new ActionsSuggestionsModel.ActionSuggestion(
+                        "text",
+                        ConversationAction.TYPE_OPEN_URL,
+                        1.0f,
+                        null,
+                        new RemoteActionTemplate[0]
+                );
+
+        LabeledIntent.Result labeledIntentResult =
+                ActionsSuggestionsHelper.createLabeledIntentResult(
+                        InstrumentationRegistry.getTargetContext(),
+                        new TemplateIntentFactory(),
+                        nativeSuggestion);
+
+        assertThat(labeledIntentResult).isNull();
+    }
+
+    @Test
+    public void createLabeledIntentResult() {
+        ActionsSuggestionsModel.ActionSuggestion nativeSuggestion =
+                new ActionsSuggestionsModel.ActionSuggestion(
+                        "text",
+                        ConversationAction.TYPE_OPEN_URL,
+                        1.0f,
+                        null,
+                        new RemoteActionTemplate[]{
+                                new RemoteActionTemplate(
+                                        "title",
+                                        null,
+                                        "description",
+                                        Intent.ACTION_VIEW,
+                                        Uri.parse("http://www.android.com").toString(),
+                                        null,
+                                        0,
+                                        null,
+                                        null,
+                                        null,
+                                        0)});
+
+        LabeledIntent.Result labeledIntentResult =
+                ActionsSuggestionsHelper.createLabeledIntentResult(
+                        InstrumentationRegistry.getTargetContext(),
+                        new TemplateIntentFactory(),
+                        nativeSuggestion);
+
+        assertThat(labeledIntentResult.remoteAction.getTitle()).isEqualTo("title");
+        assertThat(labeledIntentResult.resolvedIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
+    }
+
     private ZonedDateTime createZonedDateTimeFromMsUtc(long msUtc) {
         return ZonedDateTime.ofInstant(Instant.ofEpochMilli(msUtc), ZoneId.of("UTC"));
     }
diff --git a/core/tests/coretests/src/android/view/textclassifier/FakeContextBuilder.java b/core/tests/coretests/src/android/view/textclassifier/FakeContextBuilder.java
index fef6583..2674e37 100644
--- a/core/tests/coretests/src/android/view/textclassifier/FakeContextBuilder.java
+++ b/core/tests/coretests/src/android/view/textclassifier/FakeContextBuilder.java
@@ -44,8 +44,7 @@
 /**
  * A builder used to build a fake context for testing.
  */
-// TODO: Consider making public.
-final class FakeContextBuilder {
+public final class FakeContextBuilder {
 
     /**
      * A component name that can be used for tests.
@@ -57,7 +56,7 @@
     private final Map<String, ComponentName> mComponents = new HashMap<>();
     private @Nullable ComponentName mAllIntentComponent;
 
-    FakeContextBuilder() {
+    public FakeContextBuilder() {
         mPackageManager = mock(PackageManager.class);
         when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(null);
         mContext = new ContextWrapper(InstrumentationRegistry.getTargetContext()) {
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassificationConstantsTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassificationConstantsTest.java
index fe2a660..f6bb1bf 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextClassificationConstantsTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextClassificationConstantsTest.java
@@ -21,6 +21,7 @@
 import androidx.test.filters.SmallTest;
 import androidx.test.runner.AndroidJUnit4;
 
+import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -48,7 +49,8 @@
                 + "entity_list_editable=date:datetime,"
                 + "in_app_conversation_action_types_default=text_reply,"
                 + "notification_conversation_action_types_default=send_email:call_phone,"
-                + "lang_id_threshold_override=0.3";
+                + "lang_id_threshold_override=0.3,"
+                + "lang_id_context_settings=10:1:0.5";
         final TextClassificationConstants constants =
                 TextClassificationConstants.loadFromString(s);
 
@@ -91,6 +93,8 @@
                 .containsExactly("send_email", "call_phone");
         assertWithMessage("lang_id_threshold_override")
                 .that(constants.getLangIdThresholdOverride()).isWithin(EPSILON).of(0.3f);
+        Assert.assertArrayEquals("lang_id_context_settings",
+                constants.getLangIdContextSettings(), new float[]{10, 1, 0.5f}, EPSILON);
     }
 
     @Test
@@ -111,7 +115,8 @@
                 + "entity_list_editable=flight,"
                 + "in_app_conversation_action_types_default=view_map:track_flight,"
                 + "notification_conversation_action_types_default=share_location,"
-                + "lang_id_threshold_override=2";
+                + "lang_id_threshold_override=2,"
+                + "lang_id_context_settings=30:0.5:0.3";
         final TextClassificationConstants constants =
                 TextClassificationConstants.loadFromString(s);
 
@@ -154,6 +159,8 @@
                 .containsExactly("share_location");
         assertWithMessage("lang_id_threshold_override")
                 .that(constants.getLangIdThresholdOverride()).isWithin(EPSILON).of(2f);
+        Assert.assertArrayEquals("lang_id_context_settings",
+                constants.getLangIdContextSettings(), new float[]{30, 0.5f, 0.3f}, EPSILON);
     }
 
     @Test
@@ -196,13 +203,15 @@
                 .that(constants.getInAppConversationActionTypes())
                 .containsExactly("text_reply", "create_reminder", "call_phone", "open_url",
                         "send_email", "send_sms", "track_flight", "view_calendar", "view_map",
-                        "add_contact");
+                        "add_contact", "copy");
         assertWithMessage("notification_conversation_action_types_default")
                 .that(constants.getNotificationConversationActionTypes())
                 .containsExactly("text_reply", "create_reminder", "call_phone", "open_url",
                         "send_email", "send_sms", "track_flight", "view_calendar", "view_map",
-                        "add_contact");
+                        "add_contact", "copy");
         assertWithMessage("lang_id_threshold_override")
                 .that(constants.getLangIdThresholdOverride()).isWithin(EPSILON).of(-1f);
+        Assert.assertArrayEquals("lang_id_context_settings",
+                constants.getLangIdContextSettings(), new float[]{20, 1, 0.4f}, EPSILON);
     }
 }
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
index bcaf663..8de5f13 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextClassifierTest.java
@@ -32,6 +32,7 @@
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
 
 import com.google.common.truth.Truth;
 
@@ -41,7 +42,6 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
 
 import java.util.Arrays;
 import java.util.Collections;
@@ -53,22 +53,10 @@
  * Tests are skipped if such a textclassifier does not exist.
  */
 @SmallTest
-@RunWith(Parameterized.class)
+@RunWith(AndroidJUnit4.class)
 public class TextClassifierTest {
-    private static final String LOCAL = "local";
-    private static final String SYSTEM = "system";
 
-    @Parameterized.Parameters(name = "{0}")
-    public static Iterable<Object> textClassifierTypes() {
-        return Arrays.asList(LOCAL);
-
-        // TODO: The following will fail on any device that specifies a no-op TextClassifierService.
-        // Enable when we can set a specified TextClassifierService for testing.
-        // return Arrays.asList(LOCAL, SYSTEM);
-    }
-
-    @Parameterized.Parameter
-    public String mTextClassifierType;
+    // TODO: Implement TextClassifierService testing.
 
     private static final TextClassificationConstants TC_CONSTANTS =
             TextClassificationConstants.loadFromString("");
@@ -83,8 +71,7 @@
     public void setup() {
         mContext = InstrumentationRegistry.getTargetContext();
         mTcm = mContext.getSystemService(TextClassificationManager.class);
-        mClassifier = mTcm.getTextClassifier(
-                mTextClassifierType.equals(LOCAL) ? TextClassifier.LOCAL : TextClassifier.SYSTEM);
+        mClassifier = mTcm.getTextClassifier(TextClassifier.LOCAL);
     }
 
     @Test
@@ -278,6 +265,8 @@
         assertEquals("ja", ExtrasUtils.getEntityType(foreignLanguageInfo));
         assertTrue(ExtrasUtils.getScore(foreignLanguageInfo) >= 0);
         assertTrue(ExtrasUtils.getScore(foreignLanguageInfo) <= 1);
+        assertTrue(intent.hasExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER));
+        assertEquals("ja", ExtrasUtils.getTopLanguage(intent).getLanguage());
 
         LocaleList.setDefault(originalLocales);
     }
@@ -468,6 +457,34 @@
         Truth.assertThat(actionIntent.getData()).isEqualTo(Uri.parse("https://www.android.com"));
     }
 
+    @Test
+    public void testSuggestConversationActions_copy() {
+        if (isTextClassifierDisabled()) return;
+        ConversationActions.Message message =
+                new ConversationActions.Message.Builder(
+                        ConversationActions.Message.PERSON_USER_OTHERS)
+                        .setText("Authentication code: 12345")
+                        .build();
+        TextClassifier.EntityConfig typeConfig =
+                new TextClassifier.EntityConfig.Builder().includeTypesFromTextClassifier(false)
+                        .setIncludedTypes(
+                                Collections.singletonList(ConversationAction.TYPE_COPY))
+                        .build();
+        ConversationActions.Request request =
+                new ConversationActions.Request.Builder(Collections.singletonList(message))
+                        .setMaxSuggestions(1)
+                        .setTypeConfig(typeConfig)
+                        .build();
+
+        ConversationActions conversationActions = mClassifier.suggestConversationActions(request);
+        Truth.assertThat(conversationActions.getConversationActions()).hasSize(1);
+        ConversationAction conversationAction = conversationActions.getConversationActions().get(0);
+        Truth.assertThat(conversationAction.getType()).isEqualTo(ConversationAction.TYPE_COPY);
+        Truth.assertThat(conversationAction.getTextReply()).isAnyOf(null, "");
+        Truth.assertThat(conversationAction.getAction()).isNull();
+        String code = ExtrasUtils.getCopyText(conversationAction.getExtras());
+        Truth.assertThat(code).isEqualTo("12345");
+    }
 
     private boolean isTextClassifierDisabled() {
         return mClassifier == null || mClassifier == TextClassifier.NO_OP;
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassifierUtilsTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassifierUtilsTest.java
new file mode 100644
index 0000000..011866d
--- /dev/null
+++ b/core/tests/coretests/src/android/view/textclassifier/TextClassifierUtilsTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.textclassifier;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.testng.Assert.assertThrows;
+
+import androidx.test.filters.SmallTest;
+import androidx.test.runner.AndroidJUnit4;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SmallTest
+@RunWith(AndroidJUnit4.class)
+public class TextClassifierUtilsTest {
+
+    @Test
+    public void testGetSubString() {
+        final String text = "Yakuza call themselves 任侠団体";
+        int start;
+        int end;
+        int minimumLength;
+
+        // End index at end of text.
+        start = text.indexOf("任侠団体");
+        end = text.length();
+        minimumLength = 20;
+        assertThat(TextClassifier.Utils.getSubString(text, start, end, minimumLength))
+                .isEqualTo("call themselves 任侠団体");
+
+        // Start index at beginning of text.
+        start = 0;
+        end = "Yakuza".length();
+        minimumLength = 15;
+        assertThat(TextClassifier.Utils.getSubString(text, start, end, minimumLength))
+                .isEqualTo("Yakuza call themselves");
+
+        // Text in the middle
+        start = text.indexOf("all");
+        end = start + 1;
+        minimumLength = 10;
+        assertThat(TextClassifier.Utils.getSubString(text, start, end, minimumLength))
+                .isEqualTo("Yakuza call themselves");
+
+        // Selection >= minimumLength.
+        start = text.indexOf("themselves");
+        end = start + "themselves".length();
+        minimumLength = end - start;
+        assertThat(TextClassifier.Utils.getSubString(text, start, end, minimumLength))
+                .isEqualTo("themselves");
+
+        // text.length < minimumLength.
+        minimumLength = text.length() + 1;
+        assertThat(TextClassifier.Utils.getSubString(text, start, end, minimumLength))
+                .isEqualTo(text);
+    }
+
+    @Test
+    public void testGetSubString_invalidParams() {
+        final String text = "The Yoruba regard Olodumare as the principal agent of creation";
+        final int length = text.length();
+        final int minimumLength = 10;
+
+        // Null text
+        assertThrows(() -> TextClassifier.Utils.getSubString(null, 0, 1, minimumLength));
+        // start > end
+        assertThrows(() -> TextClassifier.Utils.getSubString(text, 6, 5, minimumLength));
+        // start < 0
+        assertThrows(() -> TextClassifier.Utils.getSubString(text, -1, 5, minimumLength));
+        // end > text.length
+        assertThrows(() -> TextClassifier.Utils.getSubString(text, 6, length + 1, minimumLength));
+    }
+}
diff --git a/core/tests/coretests/src/android/view/textclassifier/LabeledIntentTest.java b/core/tests/coretests/src/android/view/textclassifier/intent/LabeledIntentTest.java
similarity index 79%
rename from core/tests/coretests/src/android/view/textclassifier/LabeledIntentTest.java
rename to core/tests/coretests/src/android/view/textclassifier/intent/LabeledIntentTest.java
index 6520c8f..857408f 100644
--- a/core/tests/coretests/src/android/view/textclassifier/LabeledIntentTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/intent/LabeledIntentTest.java
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -23,8 +23,10 @@
 import android.content.Context;
 import android.content.Intent;
 import android.net.Uri;
+import android.os.Bundle;
+import android.view.textclassifier.FakeContextBuilder;
+import android.view.textclassifier.TextClassifier;
 
-import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.SmallTest;
 import androidx.test.runner.AndroidJUnit4;
 
@@ -41,11 +43,15 @@
     private static final Intent INTENT =
             new Intent(Intent.ACTION_VIEW).setDataAndNormalize(Uri.parse("http://www.android.com"));
     private static final int REQUEST_CODE = 42;
+    private static final Bundle TEXT_LANGUAGES_BUNDLE = Bundle.EMPTY;
+
     private Context mContext;
 
     @Before
     public void setup() {
-        mContext = InstrumentationRegistry.getTargetContext();
+        mContext = new FakeContextBuilder()
+                .setIntentComponent(Intent.ACTION_VIEW, FakeContextBuilder.DEFAULT_COMPONENT)
+                .build();
     }
 
     @Test
@@ -58,8 +64,8 @@
                 REQUEST_CODE
         );
 
-        LabeledIntent.Result result =
-                labeledIntent.resolve(mContext, /*titleChooser*/ null);
+        LabeledIntent.Result result = labeledIntent.resolve(
+                mContext, /*titleChooser*/ null, TEXT_LANGUAGES_BUNDLE);
 
         assertThat(result).isNotNull();
         assertThat(result.remoteAction.getTitle()).isEqualTo(TITLE_WITH_ENTITY);
@@ -67,6 +73,7 @@
         Intent intent = result.resolvedIntent;
         assertThat(intent.getAction()).isEqualTo(intent.getAction());
         assertThat(intent.getComponent()).isNotNull();
+        assertThat(intent.hasExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER)).isTrue();
     }
 
     @Test
@@ -79,8 +86,8 @@
                 REQUEST_CODE
         );
 
-        LabeledIntent.Result result =
-                labeledIntent.resolve(mContext, /*titleChooser*/ null);
+        LabeledIntent.Result result = labeledIntent.resolve(
+                mContext, /*titleChooser*/ null, TEXT_LANGUAGES_BUNDLE);
 
         assertThat(result).isNotNull();
         assertThat(result.remoteAction.getTitle()).isEqualTo(TITLE_WITHOUT_ENTITY);
@@ -100,8 +107,8 @@
                 REQUEST_CODE
         );
 
-        LabeledIntent.Result result =
-                labeledIntent.resolve(mContext, (labeledIntent1, resolveInfo) -> "chooser");
+        LabeledIntent.Result result = labeledIntent.resolve(
+                mContext, (labeledIntent1, resolveInfo) -> "chooser", TEXT_LANGUAGES_BUNDLE);
 
         assertThat(result).isNotNull();
         assertThat(result.remoteAction.getTitle()).isEqualTo("chooser");
@@ -121,8 +128,8 @@
                 REQUEST_CODE
         );
 
-        LabeledIntent.Result result =
-                labeledIntent.resolve(mContext, (labeledIntent1, resolveInfo) -> null);
+        LabeledIntent.Result result = labeledIntent.resolve(
+                mContext, (labeledIntent1, resolveInfo) -> null, TEXT_LANGUAGES_BUNDLE);
 
         assertThat(result).isNotNull();
         assertThat(result.remoteAction.getTitle()).isEqualTo(TITLE_WITHOUT_ENTITY);
@@ -148,15 +155,16 @@
 
     @Test
     public void resolve_noIntentHandler() {
-        Intent intent = new Intent("some.thing.does.not.exist");
+        // See setup(). mContext can only resolve Intent.ACTION_VIEW.
+        Intent unresolvableIntent = new Intent(Intent.ACTION_TRANSLATE);
         LabeledIntent labeledIntent = new LabeledIntent(
                 TITLE_WITHOUT_ENTITY,
                 null,
                 DESCRIPTION,
-                intent,
+                unresolvableIntent,
                 REQUEST_CODE);
 
-        LabeledIntent.Result result = labeledIntent.resolve(mContext, null);
+        LabeledIntent.Result result = labeledIntent.resolve(mContext, null, null);
 
         assertThat(result).isNull();
     }
diff --git a/core/tests/coretests/src/android/view/textclassifier/LegacyIntentFactoryTest.java b/core/tests/coretests/src/android/view/textclassifier/intent/LegacyIntentClassificationFactoryTest.java
similarity index 85%
rename from core/tests/coretests/src/android/view/textclassifier/LegacyIntentFactoryTest.java
rename to core/tests/coretests/src/android/view/textclassifier/intent/LegacyIntentClassificationFactoryTest.java
index 2a79c1c..19e5b0a 100644
--- a/core/tests/coretests/src/android/view/textclassifier/LegacyIntentFactoryTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/intent/LegacyIntentClassificationFactoryTest.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2018 The Android Open Source Project
+ * Copyright (C) 2019 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.
@@ -14,11 +14,12 @@
  * limitations under the License.
  */
 
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import static com.google.common.truth.Truth.assertThat;
 
 import android.content.Intent;
+import android.view.textclassifier.TextClassifier;
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.SmallTest;
@@ -34,15 +35,15 @@
 
 @SmallTest
 @RunWith(AndroidJUnit4.class)
-public class LegacyIntentFactoryTest {
+public class LegacyIntentClassificationFactoryTest {
 
     private static final String TEXT = "text";
 
-    private LegacyIntentFactory mLegacyIntentFactory;
+    private LegacyClassificationIntentFactory mLegacyIntentClassificationFactory;
 
     @Before
     public void setup() {
-        mLegacyIntentFactory = new LegacyIntentFactory();
+        mLegacyIntentClassificationFactory = new LegacyClassificationIntentFactory();
     }
 
     @Test
@@ -64,7 +65,7 @@
                         null,
                         null);
 
-        List<LabeledIntent> intents = mLegacyIntentFactory.create(
+        List<LabeledIntent> intents = mLegacyIntentClassificationFactory.create(
                 InstrumentationRegistry.getContext(),
                 TEXT,
                 /* foreignText */ false,
@@ -76,8 +77,6 @@
         Intent intent = labeledIntent.intent;
         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_DEFINE);
         assertThat(intent.getStringExtra(Intent.EXTRA_TEXT)).isEqualTo(TEXT);
-        assertThat(
-                intent.getBooleanExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER, false)).isTrue();
     }
 
     @Test
@@ -99,7 +98,7 @@
                         null,
                         null);
 
-        List<LabeledIntent> intents = mLegacyIntentFactory.create(
+        List<LabeledIntent> intents = mLegacyIntentClassificationFactory.create(
                 InstrumentationRegistry.getContext(),
                 TEXT,
                 /* foreignText */ true,
diff --git a/core/tests/coretests/src/android/view/textclassifier/TemplateClassificationIntentFactoryTest.java b/core/tests/coretests/src/android/view/textclassifier/intent/TemplateClassificationIntentFactoryTest.java
similarity index 66%
rename from core/tests/coretests/src/android/view/textclassifier/TemplateClassificationIntentFactoryTest.java
rename to core/tests/coretests/src/android/view/textclassifier/intent/TemplateClassificationIntentFactoryTest.java
index fac58f8..eaef0a0 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TemplateClassificationIntentFactoryTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/intent/TemplateClassificationIntentFactoryTest.java
@@ -14,11 +14,19 @@
  * limitations under the License.
  */
 
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import static com.google.common.truth.Truth.assertThat;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.ArgumentMatchers.same;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
 import android.content.Intent;
+import android.view.textclassifier.TextClassifier;
 
 import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.SmallTest;
@@ -45,7 +53,7 @@
     private static final String ACTION = Intent.ACTION_VIEW;
 
     @Mock
-    private IntentFactory mFallback;
+    private ClassificationIntentFactory mFallback;
     private TemplateClassificationIntentFactory mTemplateClassificationIntentFactory;
 
     @Before
@@ -88,12 +96,10 @@
         assertThat(labeledIntent.titleWithoutEntity).isEqualTo(TITLE_WITHOUT_ENTITY);
         Intent intent = labeledIntent.intent;
         assertThat(intent.getAction()).isEqualTo(ACTION);
-        assertThat(intent.hasExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER)).isTrue();
 
         labeledIntent = intents.get(1);
         intent = labeledIntent.intent;
         assertThat(intent.getAction()).isEqualTo(Intent.ACTION_TRANSLATE);
-        assertThat(intent.hasExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER)).isTrue();
     }
 
     @Test
@@ -128,9 +134,73 @@
         assertThat(labeledIntent.titleWithoutEntity).isEqualTo(TITLE_WITHOUT_ENTITY);
         Intent intent = labeledIntent.intent;
         assertThat(intent.getAction()).isEqualTo(ACTION);
-        assertThat(intent.hasExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER)).isTrue();
     }
 
+    @Test
+    public void create_nullTemplate() {
+        AnnotatorModel.ClassificationResult classificationResult =
+                new AnnotatorModel.ClassificationResult(
+                        TextClassifier.TYPE_ADDRESS,
+                        1.0f,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null);
+
+        mTemplateClassificationIntentFactory.create(
+                InstrumentationRegistry.getContext(),
+                TEXT,
+                /* foreignText */ false,
+                null,
+                classificationResult);
+
+
+        verify(mFallback).create(
+                same(InstrumentationRegistry.getContext()), eq(TEXT), eq(false), eq(null),
+                same(classificationResult));
+    }
+
+    @Test
+    public void create_emptyResult() {
+        AnnotatorModel.ClassificationResult classificationResult =
+                new AnnotatorModel.ClassificationResult(
+                        TextClassifier.TYPE_ADDRESS,
+                        1.0f,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        null,
+                        new RemoteActionTemplate[0]);
+
+        mTemplateClassificationIntentFactory.create(
+                InstrumentationRegistry.getContext(),
+                TEXT,
+                /* foreignText */ false,
+                null,
+                classificationResult);
+
+
+        verify(mFallback, never()).create(
+                any(Context.class), eq(TEXT), eq(false), eq(null),
+                any(AnnotatorModel.ClassificationResult.class));
+    }
+
+
     private static RemoteActionTemplate[] createRemoteActionTemplates() {
         return new RemoteActionTemplate[]{
                 new RemoteActionTemplate(
diff --git a/core/tests/coretests/src/android/view/textclassifier/TemplateIntentFactoryTest.java b/core/tests/coretests/src/android/view/textclassifier/intent/TemplateIntentFactoryTest.java
similarity index 97%
rename from core/tests/coretests/src/android/view/textclassifier/TemplateIntentFactoryTest.java
rename to core/tests/coretests/src/android/view/textclassifier/intent/TemplateIntentFactoryTest.java
index 1860734..6e3de2d 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TemplateIntentFactoryTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/intent/TemplateIntentFactoryTest.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package android.view.textclassifier;
+package android.view.textclassifier.intent;
 
 import static com.google.common.truth.Truth.assertThat;
 
@@ -101,7 +101,6 @@
         assertThat(intent.getPackage()).isNull();
         assertThat(intent.getStringExtra(KEY_ONE)).isEqualTo(VALUE_ONE);
         assertThat(intent.getIntExtra(KEY_TWO, 0)).isEqualTo(VALUE_TWO);
-        assertThat(intent.hasExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER)).isTrue();
     }
 
     @Test
@@ -160,7 +159,6 @@
         assertThat(intent.getFlags()).isEqualTo(0);
         assertThat(intent.getCategories()).isNull();
         assertThat(intent.getPackage()).isNull();
-        assertThat(intent.hasExtra(TextClassifier.EXTRA_FROM_TEXT_CLASSIFIER)).isTrue();
     }
 
     @Test
diff --git a/graphics/java/android/graphics/Paint.java b/graphics/java/android/graphics/Paint.java
index 79ee4a9..346c7ab 100644
--- a/graphics/java/android/graphics/Paint.java
+++ b/graphics/java/android/graphics/Paint.java
@@ -1046,7 +1046,8 @@
      * @param color The new color (including alpha) to set in the paint.
      */
     public void setColor(@ColorInt int color) {
-        setColor(Color.pack(color));
+        nSetColor(mNativePaint, color);
+        mColor = Color.pack(color);
     }
 
     /**
@@ -1063,12 +1064,8 @@
      */
     public void setColor(@ColorLong long color) {
         ColorSpace cs = Color.colorSpace(color);
-        float r = Color.red(color);
-        float g = Color.green(color);
-        float b = Color.blue(color);
-        float a = Color.alpha(color);
 
-        nSetColor(mNativePaint, cs.getNativeInstance(), r, g, b, a);
+        nSetColor(mNativePaint, cs.getNativeInstance(), color);
         mColor = color;
     }
 
@@ -1498,11 +1495,7 @@
      */
     public void setShadowLayer(float radius, float dx, float dy, @ColorLong long shadowColor) {
         ColorSpace cs = Color.colorSpace(shadowColor);
-        float r = Color.red(shadowColor);
-        float g = Color.green(shadowColor);
-        float b = Color.blue(shadowColor);
-        float a = Color.alpha(shadowColor);
-        nSetShadowLayer(mNativePaint, radius, dx, dy, cs.getNativeInstance(), r, g, b, a);
+        nSetShadowLayer(mNativePaint, radius, dx, dy, cs.getNativeInstance(), shadowColor);
 
         mShadowLayerRadius = radius;
         mShadowLayerDx = dx;
@@ -1530,6 +1523,7 @@
     /**
      * Returns the blur radius of the shadow layer.
      * @see #setShadowLayer(float,float,float,int)
+     * @see #setShadowLayer(float,float,float,long)
      */
     public float getShadowLayerRadius() {
         return mShadowLayerRadius;
@@ -1538,6 +1532,7 @@
     /**
      * Returns the x offset of the shadow layer.
      * @see #setShadowLayer(float,float,float,int)
+     * @see #setShadowLayer(float,float,float,long)
      */
     public float getShadowLayerDx() {
         return mShadowLayerDx;
@@ -1546,6 +1541,7 @@
     /**
      * Returns the y offset of the shadow layer.
      * @see #setShadowLayer(float,float,float,int)
+     * @see #setShadowLayer(float,float,float,long)
      */
     public float getShadowLayerDy() {
         return mShadowLayerDy;
@@ -3135,7 +3131,7 @@
     @CriticalNative
     private static native void nSetShadowLayer(long paintPtr,
             float radius, float dx, float dy, long colorSpaceHandle,
-            float r, float g, float b, float a);
+            @ColorLong long shadowColor);
     @CriticalNative
     private static native boolean nHasShadowLayer(long paintPtr);
     @CriticalNative
@@ -3188,7 +3184,9 @@
     private static native void nSetFilterBitmap(long paintPtr, boolean filter);
     @CriticalNative
     private static native void nSetColor(long paintPtr, long colorSpaceHandle,
-            float r, float g, float b, float a);
+            @ColorLong long color);
+    @CriticalNative
+    private static native void nSetColor(long paintPtr, @ColorInt int color);
     @CriticalNative
     private static native void nSetStrikeThruText(long paintPtr, boolean strikeThruText);
     @CriticalNative
diff --git a/graphics/java/android/graphics/Typeface.java b/graphics/java/android/graphics/Typeface.java
index 64f7591..9995f1e 100644
--- a/graphics/java/android/graphics/Typeface.java
+++ b/graphics/java/android/graphics/Typeface.java
@@ -33,12 +33,12 @@
 import android.graphics.fonts.FontVariationAxis;
 import android.graphics.fonts.SystemFonts;
 import android.os.Build;
+import android.os.Build.VERSION_CODES;
 import android.os.ParcelFileDescriptor;
 import android.provider.FontRequest;
 import android.provider.FontsContract;
 import android.text.FontConfig;
 import android.util.Base64;
-import android.util.Log;
 import android.util.LongSparseArray;
 import android.util.LruCache;
 import android.util.SparseArray;
@@ -48,6 +48,7 @@
 import com.android.internal.util.Preconditions;
 
 import dalvik.annotation.optimization.CriticalNative;
+import dalvik.system.VMRuntime;
 
 import libcore.util.NativeAllocationRegistry;
 
@@ -262,29 +263,18 @@
                             ?  FontStyle.FONT_SLANT_ITALIC : FontStyle.FONT_SLANT_UPRIGHT);
                 }
 
-                Font font = null;
-                try {
-                    font = fontBuilder.build();
-                } catch (IllegalArgumentException e) {
-                    // The exception happens if the unsupported font is passed. We suppress this
-                    // exception and just ignore this font here since there is no way of
-                    // resolving this issue by users during inflating layout.
-                    Log.w(TAG, "Ignoring font file since failed to create font object."
-                            + " The font file is not supported on this platform.");
-                    continue;
-                }
                 if (familyBuilder == null) {
-                    familyBuilder = new FontFamily.Builder(font);
+                    familyBuilder = new FontFamily.Builder(fontBuilder.build());
                 } else {
                     try {
-                        familyBuilder.addFont(font);
+                        familyBuilder.addFont(fontBuilder.build());
                     } catch (IllegalArgumentException e) {
-                        // The exception happens if the same style is added to the family.
-                        // We suppress this exception and just ignore this font here since there is
-                        // no way of resolving this issue by users during inflating layout.
-                        Log.w(TAG,
-                                "Ignoring font file since the same style font is already added.");
-                        continue;
+                        if (VMRuntime.getRuntime().getTargetSdkVersion() <= VERSION_CODES.P) {
+                            // Surpress the IllegalArgumentException for keeping the backward
+                            // compatibility.
+                            continue;
+                        }
+                        throw e;
                     }
                 }
             }
diff --git a/graphics/java/android/graphics/fonts/Font.java b/graphics/java/android/graphics/fonts/Font.java
index b857465..552088f 100644
--- a/graphics/java/android/graphics/fonts/Font.java
+++ b/graphics/java/android/graphics/fonts/Font.java
@@ -354,10 +354,6 @@
 
         /**
          * Creates the font based on the configured values.
-         *
-         * If the font is not supported by the platform, this function will fail with
-         * {@link IllegalArgumentException}.
-         *
          * @return the Font object
          */
         public @NonNull Font build() throws IOException {
diff --git a/libs/hwui/FrameInfoVisualizer.cpp b/libs/hwui/FrameInfoVisualizer.cpp
index b04c774..3a8e559 100644
--- a/libs/hwui/FrameInfoVisualizer.cpp
+++ b/libs/hwui/FrameInfoVisualizer.cpp
@@ -17,6 +17,7 @@
 
 #include "IProfileRenderer.h"
 #include "utils/Color.h"
+#include "utils/TimeUtils.h"
 
 #include <cutils/compiler.h>
 #include <array>
@@ -26,22 +27,24 @@
 #define RETURN_IF_DISABLED() \
     if (CC_LIKELY(mType == ProfileType::None && !mShowDirtyRegions)) return
 
-#define PROFILE_DRAW_WIDTH 3
-#define PROFILE_DRAW_THRESHOLD_STROKE_WIDTH 2
-#define PROFILE_DRAW_DP_PER_MS 7
-
 namespace android {
 namespace uirenderer {
 
-// Must be NUM_ELEMENTS in size
-static const SkColor THRESHOLD_COLOR = Color::Green_500;
-static const SkColor BAR_FAST_MASK = 0x8FFFFFFF;
-static const SkColor BAR_JANKY_MASK = 0xDFFFFFFF;
+static constexpr auto PROFILE_DRAW_THRESHOLD_STROKE_WIDTH = 2;
+static constexpr auto PROFILE_DRAW_DP_PER_MS = 7;
 
-// We could get this from TimeLord and use the actual frame interval, but
-// this is good enough
-#define FRAME_THRESHOLD 16
-#define FRAME_THRESHOLD_NS 16000000
+struct Threshold {
+    SkColor color;
+    float percentFrametime;
+};
+
+static constexpr std::array<Threshold, 3> THRESHOLDS{
+        Threshold{.color = Color::Green_500, .percentFrametime = 0.8f},
+        Threshold{.color = Color::Lime_500, .percentFrametime = 1.0f},
+        Threshold{.color = Color::Red_500, .percentFrametime = 1.5f},
+};
+static constexpr SkColor BAR_FAST_MASK = 0x8FFFFFFF;
+static constexpr SkColor BAR_JANKY_MASK = 0xDFFFFFFF;
 
 struct BarSegment {
     FrameInfoIndex start;
@@ -64,7 +67,8 @@
     return (int)(dp * density + 0.5f);
 }
 
-FrameInfoVisualizer::FrameInfoVisualizer(FrameInfoSource& source) : mFrameSource(source) {
+FrameInfoVisualizer::FrameInfoVisualizer(FrameInfoSource& source, nsecs_t frameInterval)
+        : mFrameSource(source), mFrameInterval(frameInterval) {
     setDensity(1);
     consumeProperties();
 }
@@ -76,7 +80,10 @@
 void FrameInfoVisualizer::setDensity(float density) {
     if (CC_UNLIKELY(mDensity != density)) {
         mDensity = density;
-        mVerticalUnit = dpToPx(PROFILE_DRAW_DP_PER_MS, density);
+        // We want the vertical units to scale height relative to a baseline 16ms.
+        // This keeps the threshold lines consistent across varying refresh rates
+        mVerticalUnit = static_cast<int>(dpToPx(PROFILE_DRAW_DP_PER_MS, density) * (float)16_ms /
+                                         (float)mFrameInterval);
         mThresholdStroke = dpToPx(PROFILE_DRAW_THRESHOLD_STROKE_WIDTH, density);
     }
 }
@@ -148,7 +155,7 @@
         float* rect;
         int ri;
         // Rects are LTRB
-        if (mFrameSource[fi].totalDuration() <= FRAME_THRESHOLD_NS) {
+        if (mFrameSource[fi].totalDuration() <= mFrameInterval) {
             rect = mFastRects.get();
             ri = fast_i;
             fast_i += 4;
@@ -181,7 +188,7 @@
         float* rect;
         int ri;
         // Rects are LTRB
-        if (mFrameSource[fi].totalDuration() <= FRAME_THRESHOLD_NS) {
+        if (mFrameSource[fi].totalDuration() <= mFrameInterval) {
             rect = mFastRects.get();
             ri = fast_i;
             fast_i -= 4;
@@ -211,10 +218,13 @@
 
 void FrameInfoVisualizer::drawThreshold(IProfileRenderer& renderer) {
     SkPaint paint;
-    paint.setColor(THRESHOLD_COLOR);
-    float yLocation = renderer.getViewportHeight() - (FRAME_THRESHOLD * mVerticalUnit);
-    renderer.drawRect(0.0f, yLocation - mThresholdStroke / 2, renderer.getViewportWidth(),
-                      yLocation + mThresholdStroke / 2, paint);
+    for (auto& t : THRESHOLDS) {
+        paint.setColor(t.color);
+        float yLocation = renderer.getViewportHeight() -
+                          (ns2ms(mFrameInterval) * t.percentFrametime * mVerticalUnit);
+        renderer.drawRect(0.0f, yLocation - mThresholdStroke / 2, renderer.getViewportWidth(),
+                          yLocation + mThresholdStroke / 2, paint);
+    }
 }
 
 bool FrameInfoVisualizer::consumeProperties() {
diff --git a/libs/hwui/FrameInfoVisualizer.h b/libs/hwui/FrameInfoVisualizer.h
index b98f501..3040a77 100644
--- a/libs/hwui/FrameInfoVisualizer.h
+++ b/libs/hwui/FrameInfoVisualizer.h
@@ -39,7 +39,7 @@
 
 class FrameInfoVisualizer {
 public:
-    explicit FrameInfoVisualizer(FrameInfoSource& source);
+    explicit FrameInfoVisualizer(FrameInfoSource& source, nsecs_t frameInterval);
     ~FrameInfoVisualizer();
 
     bool consumeProperties();
@@ -71,6 +71,7 @@
 
     FrameInfoSource& mFrameSource;
 
+    nsecs_t mFrameInterval;
     int mVerticalUnit = 0;
     int mThresholdStroke = 0;
 
diff --git a/libs/hwui/renderthread/CanvasContext.cpp b/libs/hwui/renderthread/CanvasContext.cpp
index 091775dbe7..f5b4d93 100644
--- a/libs/hwui/renderthread/CanvasContext.cpp
+++ b/libs/hwui/renderthread/CanvasContext.cpp
@@ -103,7 +103,7 @@
         , mOpaque(!translucent)
         , mAnimationContext(contextFactory->createAnimationContext(mRenderThread.timeLord()))
         , mJankTracker(&thread.globalProfileData(), thread.mainDisplayInfo())
-        , mProfiler(mJankTracker.frames())
+        , mProfiler(mJankTracker.frames(), thread.timeLord().frameIntervalNanos())
         , mContentDrawBounds(0, 0, 0, 0)
         , mRenderPipeline(std::move(renderPipeline)) {
     rootRenderNode->makeRoot();
diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp
index 08edd20..c784d64 100644
--- a/libs/hwui/renderthread/RenderThread.cpp
+++ b/libs/hwui/renderthread/RenderThread.cpp
@@ -52,9 +52,6 @@
 // using just a few large reads.
 static const size_t EVENT_BUFFER_SIZE = 100;
 
-// Slight delay to give the UI time to push us a new frame before we replay
-static const nsecs_t DISPATCH_FRAME_CALLBACKS_DELAY = milliseconds_to_nanoseconds(4);
-
 static bool gHasRenderThreadInstance = false;
 
 static JVMAttachHook gOnStartHook = nullptr;
@@ -171,6 +168,7 @@
     mDisplayInfo = DeviceInfo::get()->displayInfo();
     nsecs_t frameIntervalNanos = static_cast<nsecs_t>(1000000000 / mDisplayInfo.fps);
     mTimeLord.setFrameInterval(frameIntervalNanos);
+    mDispatchFrameDelay = static_cast<nsecs_t>(frameIntervalNanos * .25f);
     initializeDisplayEventReceiver();
     mEglManager = new EglManager();
     mRenderState = new RenderState(*this);
@@ -311,7 +309,7 @@
         if (mTimeLord.vsyncReceived(vsyncEvent) && !mFrameCallbackTaskPending) {
             ATRACE_NAME("queue mFrameCallbackTask");
             mFrameCallbackTaskPending = true;
-            nsecs_t runAt = (vsyncEvent + DISPATCH_FRAME_CALLBACKS_DELAY);
+            nsecs_t runAt = (vsyncEvent + mDispatchFrameDelay);
             queue().postAt(runAt, [this]() { dispatchFrameCallbacks(); });
         }
     }
diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h
index 329b4b9..9298be6 100644
--- a/libs/hwui/renderthread/RenderThread.h
+++ b/libs/hwui/renderthread/RenderThread.h
@@ -24,6 +24,7 @@
 #include "TimeLord.h"
 #include "thread/ThreadBase.h"
 #include "WebViewFunctorManager.h"
+#include "utils/TimeUtils.h"
 
 #include <GrContext.h>
 #include <SkBitmap.h>
@@ -164,6 +165,7 @@
     bool mFrameCallbackTaskPending;
 
     TimeLord mTimeLord;
+    nsecs_t mDispatchFrameDelay = 4_ms;
     RenderState* mRenderState;
     EglManager* mEglManager;
     WebViewFunctorManager& mFunctorManager;
diff --git a/location/java/android/location/SettingInjectorService.java b/location/java/android/location/SettingInjectorService.java
index c201770..d6f8a7c 100644
--- a/location/java/android/location/SettingInjectorService.java
+++ b/location/java/android/location/SettingInjectorService.java
@@ -16,6 +16,7 @@
 
 package android.location;
 
+import android.annotation.NonNull;
 import android.app.Service;
 import android.content.Context;
 import android.content.Intent;
@@ -58,17 +59,17 @@
  * </pre>
  * Here:
  * <ul>
- *     <li>title: The {@link android.preference.Preference#getTitle()} value. The title should make
- *     it clear which apps are affected by the setting, typically by including the name of the
- *     developer. For example, "Acme Corp. ads preferences." </li>
+ * <li>title: The {@link android.preference.Preference#getTitle()} value. The title should make
+ * it clear which apps are affected by the setting, typically by including the name of the
+ * developer. For example, "Acme Corp. ads preferences." </li>
  *
- *     <li>icon: The {@link android.preference.Preference#getIcon()} value. Typically this will be a
- *     generic icon for the developer rather than the icon for an individual app.</li>
+ * <li>icon: The {@link android.preference.Preference#getIcon()} value. Typically this will be a
+ * generic icon for the developer rather than the icon for an individual app.</li>
  *
- *     <li>settingsActivity: the activity which is launched to allow the user to modify the setting
- *     value.  The activity must be in the same package as the subclass of
- *     {@link SettingInjectorService}. The activity should use your own branding to help emphasize
- *     to the user that it is not part of the system settings.</li>
+ * <li>settingsActivity: the activity which is launched to allow the user to modify the setting
+ * value.  The activity must be in the same package as the subclass of
+ * {@link SettingInjectorService}. The activity should use your own branding to help emphasize
+ * to the user that it is not part of the system settings.</li>
  * </ul>
  *
  * To ensure a good user experience, your {@link android.app.Application#onCreate()},
@@ -206,6 +207,8 @@
      * Returns the {@link android.preference.Preference#getSummary()} value (allowed to be null or
      * empty). Should not perform unpredictably-long operations such as network access--see the
      * running-time comments in the class-level javadoc.
+     * <p/>
+     * This method is called on KitKat, and Q+ devices.
      *
      * @return the {@link android.preference.Preference#getSummary()} value
      */
@@ -234,7 +237,7 @@
     /**
      * Sends a broadcast to refresh the injected settings on location settings page.
      */
-    public static final void refreshSettings(Context context) {
+    public static final void refreshSettings(@NonNull Context context) {
         Intent intent = new Intent(ACTION_INJECTED_SETTING_CHANGED);
         context.sendBroadcast(intent);
     }
diff --git a/media/java/android/media/ExifInterface.java b/media/java/android/media/ExifInterface.java
index 4cd8971..23db27d 100644
--- a/media/java/android/media/ExifInterface.java
+++ b/media/java/android/media/ExifInterface.java
@@ -1359,7 +1359,7 @@
         if (file == null) {
             throw new NullPointerException("file cannot be null");
         }
-        initForFilename(file.getName());
+        initForFilename(file.getAbsolutePath());
     }
 
     /**
diff --git a/media/java/android/media/ExternalRingtonesCursorWrapper.java b/media/java/android/media/ExternalRingtonesCursorWrapper.java
index dd4c77a..ea63a3a 100644
--- a/media/java/android/media/ExternalRingtonesCursorWrapper.java
+++ b/media/java/android/media/ExternalRingtonesCursorWrapper.java
@@ -16,7 +16,6 @@
 
 package android.media;
 
-import android.content.ContentProvider;
 import android.database.Cursor;
 import android.database.CursorWrapper;
 import android.net.Uri;
@@ -28,19 +27,18 @@
  * @hide
  */
 public class ExternalRingtonesCursorWrapper extends CursorWrapper {
+    private Uri mUri;
 
-    private int mUserId;
-
-    public ExternalRingtonesCursorWrapper(Cursor cursor, int userId) {
+    public ExternalRingtonesCursorWrapper(Cursor cursor, Uri uri) {
         super(cursor);
-        mUserId = userId;
+        mUri = uri;
     }
 
     public String getString(int index) {
-        String result = super.getString(index);
         if (index == RingtoneManager.URI_COLUMN_INDEX) {
-            result = ContentProvider.maybeAddUserId(Uri.parse(result), mUserId).toString();
+            return mUri.toString();
+        } else {
+            return super.getString(index);
         }
-        return result;
     }
 }
diff --git a/media/java/android/media/MediaDrm.java b/media/java/android/media/MediaDrm.java
index f5abb24..579ee8d 100644
--- a/media/java/android/media/MediaDrm.java
+++ b/media/java/android/media/MediaDrm.java
@@ -1363,6 +1363,18 @@
         removeAllSecureStops();;
     }
 
+    /**
+     * @deprecated Not of any use for application development;
+     * please note that the related integer constants remain supported:
+     * {@link #HDCP_LEVEL_UNKNOWN},
+     * {@link #HDCP_NONE},
+     * {@link #HDCP_V1},
+     * {@link #HDCP_V2},
+     * {@link #HDCP_V2_1},
+     * {@link #HDCP_V2_2},
+     * {@link #HDCP_V2_3}
+     */
+    @Deprecated
     @Retention(RetentionPolicy.SOURCE)
     @IntDef({HDCP_LEVEL_UNKNOWN, HDCP_NONE, HDCP_V1, HDCP_V2,
                         HDCP_V2_1, HDCP_V2_2, HDCP_V2_3, HDCP_NO_DIGITAL_OUTPUT})
@@ -1455,7 +1467,17 @@
     /**
      * Security level indicates the robustness of the device's DRM
      * implementation.
+     *
+     * @deprecated Not of any use for application development;
+     * please note that the related integer constants remain supported:
+     * {@link #SECURITY_LEVEL_UNKNOWN},
+     * {@link #SECURITY_LEVEL_SW_SECURE_CRYPTO},
+     * {@link #SECURITY_LEVEL_SW_SECURE_DECODE},
+     * {@link #SECURITY_LEVEL_HW_SECURE_CRYPTO},
+     * {@link #SECURITY_LEVEL_HW_SECURE_DECODE},
+     * {@link #SECURITY_LEVEL_HW_SECURE_ALL}
      */
+    @Deprecated
     @Retention(RetentionPolicy.SOURCE)
     @IntDef({SECURITY_LEVEL_UNKNOWN, SECURITY_LEVEL_SW_SECURE_CRYPTO,
             SECURITY_LEVEL_SW_SECURE_DECODE, SECURITY_LEVEL_HW_SECURE_CRYPTO,
diff --git a/media/java/android/media/MediaPlayer.java b/media/java/android/media/MediaPlayer.java
index abbfa88..040152a 100644
--- a/media/java/android/media/MediaPlayer.java
+++ b/media/java/android/media/MediaPlayer.java
@@ -2645,7 +2645,7 @@
      */
     private synchronized void setSubtitleAnchor() {
         if ((mSubtitleController == null) && (ActivityThread.currentApplication() != null)) {
-            getMediaTimeProvider();
+            final TimeProvider timeProvider = (TimeProvider) getMediaTimeProvider();
             final HandlerThread thread = new HandlerThread("SetSubtitleAnchorThread");
             thread.start();
             Handler handler = new Handler(thread.getLooper());
@@ -2653,7 +2653,8 @@
                 @Override
                 public void run() {
                     Context context = ActivityThread.currentApplication();
-                    mSubtitleController = new SubtitleController(context, mTimeProvider, MediaPlayer.this);
+                    mSubtitleController =
+                            new SubtitleController(context, timeProvider, MediaPlayer.this);
                     mSubtitleController.setAnchor(new Anchor() {
                         @Override
                         public void setSubtitleWidget(RenderingWidget subtitleWidget) {
@@ -2661,7 +2662,7 @@
 
                         @Override
                         public Looper getSubtitleLooper() {
-                            return mTimeProvider.mEventHandler.getLooper();
+                            return timeProvider.mEventHandler.getLooper();
                         }
                     });
                     thread.getLooper().quitSafely();
diff --git a/media/java/android/media/RingtoneManager.java b/media/java/android/media/RingtoneManager.java
index 0679e8e9..9a60923 100644
--- a/media/java/android/media/RingtoneManager.java
+++ b/media/java/android/media/RingtoneManager.java
@@ -215,17 +215,19 @@
     // Make sure the column ordering and then ..._COLUMN_INDEX are in sync
     
     private static final String[] INTERNAL_COLUMNS = new String[] {
-        MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE,
-        "\"" + MediaStore.Audio.Media.INTERNAL_CONTENT_URI + "\"",
-        MediaStore.Audio.Media.TITLE_KEY
+        MediaStore.Audio.Media._ID,
+        MediaStore.Audio.Media.TITLE,
+        MediaStore.Audio.Media.TITLE,
+        MediaStore.Audio.Media.TITLE_KEY,
     };
 
     private static final String[] MEDIA_COLUMNS = new String[] {
-        MediaStore.Audio.Media._ID, MediaStore.Audio.Media.TITLE,
-        "\"" + MediaStore.Audio.Media.EXTERNAL_CONTENT_URI + "\"",
-        MediaStore.Audio.Media.TITLE_KEY
+        MediaStore.Audio.Media._ID,
+        MediaStore.Audio.Media.TITLE,
+        MediaStore.Audio.Media.TITLE,
+        MediaStore.Audio.Media.TITLE_KEY,
     };
-    
+
     /**
      * The column index (in the cursor returned by {@link #getCursor()} for the
      * row ID.
@@ -459,8 +461,9 @@
                 // We don't need to re-add the internal ringtones for the work profile since
                 // they are the same as the personal profile. We just need the external
                 // ringtones.
-                return new ExternalRingtonesCursorWrapper(getMediaRingtones(parentContext),
-                        parentInfo.id);
+                final Cursor res = getMediaRingtones(parentContext);
+                return new ExternalRingtonesCursorWrapper(res, ContentProvider.maybeAddUserId(
+                        MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, parentInfo.id));
             }
         }
         return null;
@@ -580,14 +583,16 @@
 
     @UnsupportedAppUsage
     private Cursor getInternalRingtones() {
-        return query(
+        final Cursor res = query(
                 MediaStore.Audio.Media.INTERNAL_CONTENT_URI, INTERNAL_COLUMNS,
                 constructBooleanTrueWhereClause(mFilterColumns),
                 null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
+        return new ExternalRingtonesCursorWrapper(res, MediaStore.Audio.Media.INTERNAL_CONTENT_URI);
     }
 
     private Cursor getMediaRingtones() {
-        return getMediaRingtones(mContext);
+        final Cursor res = getMediaRingtones(mContext);
+        return new ExternalRingtonesCursorWrapper(res, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
     }
 
     @UnsupportedAppUsage
diff --git a/media/java/android/media/SRTRenderer.java b/media/java/android/media/SRTRenderer.java
index a3e2abd..505f996 100644
--- a/media/java/android/media/SRTRenderer.java
+++ b/media/java/android/media/SRTRenderer.java
@@ -125,6 +125,7 @@
                 String[] startEnd = header.split("-->");
                 cue.mStartTimeMs = parseMs(startEnd[0]);
                 cue.mEndTimeMs = parseMs(startEnd[1]);
+                cue.mRunID = runID;
 
                 String s;
                 List<String> paragraph = new ArrayList<String>();
diff --git a/media/java/android/media/SubtitleTrack.java b/media/java/android/media/SubtitleTrack.java
index 5596c32..0705d97 100644
--- a/media/java/android/media/SubtitleTrack.java
+++ b/media/java/android/media/SubtitleTrack.java
@@ -263,7 +263,9 @@
         }
         updateView(mActiveCues);
         mNextScheduledTimeMs = -1;
-        mTimeProvider.notifyAt(MediaTimeProvider.NO_TIME, this);
+        if (mTimeProvider != null) {
+            mTimeProvider.notifyAt(MediaTimeProvider.NO_TIME, this);
+        }
     }
 
     /** @hide */
diff --git a/media/java/android/media/session/ControllerLink.aidl b/media/java/android/media/session/ControllerLink.aidl
deleted file mode 100644
index 532df59..0000000
--- a/media/java/android/media/session/ControllerLink.aidl
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.media.session;
-
-parcelable ControllerLink;
diff --git a/media/java/android/media/session/ControllerLink.java b/media/java/android/media/session/ControllerLink.java
deleted file mode 100644
index d4ea2a3..0000000
--- a/media/java/android/media/session/ControllerLink.java
+++ /dev/null
@@ -1,1042 +0,0 @@
-/*
- * Copyright 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.media.session;
-
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.app.PendingIntent;
-import android.media.MediaMetadata;
-import android.media.MediaParceledListSlice;
-import android.media.Rating;
-import android.media.session.MediaController.PlaybackInfo;
-import android.net.Uri;
-import android.os.Bundle;
-import android.os.IBinder;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.os.RemoteException;
-import android.os.ResultReceiver;
-import android.view.KeyEvent;
-
-import java.util.List;
-import java.util.Objects;
-
-/**
- * Handles incoming commands from {@link MediaController}.
- * @hide
- */
-public final class ControllerLink implements Parcelable {
-    public static final @android.annotation.NonNull Parcelable.Creator<ControllerLink> CREATOR =
-            new Parcelable.Creator<ControllerLink>() {
-                @Override
-                public ControllerLink createFromParcel(Parcel in) {
-                    return new ControllerLink(in.readStrongBinder());
-                }
-
-                @Override
-                public ControllerLink[] newArray(int size) {
-                    return new ControllerLink[size];
-                }
-            };
-
-    final ControllerStub mControllerStub;
-    final ISessionController mISessionController;
-
-    /**
-     * Constructor for stub (Callee)
-     */
-    public ControllerLink(@NonNull ControllerStub controllerStub) {
-        mControllerStub = controllerStub;
-        mISessionController = new StubProxy();
-    }
-
-    /**
-     * Constructor for interface (Caller)
-     */
-    public ControllerLink(IBinder binder) {
-        mControllerStub = null;
-        mISessionController = ISessionController.Stub.asInterface(binder);
-    }
-
-    /**
-     * Tell system that a controller sends a command.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param command the name of the command
-     * @param args the arguments included with the command
-     * @param cb the result receiver for getting the result of the command
-     */
-    void sendCommand(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            @NonNull String command, @Nullable Bundle args, @Nullable ResultReceiver cb) {
-        try {
-            mISessionController.sendCommand(packageName, caller, command, args, cb);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller sends a media button event.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param mediaButton the media button key event
-     */
-    boolean sendMediaButton(@NonNull String packageName,
-            @NonNull ControllerCallbackLink caller, @NonNull KeyEvent mediaButton) {
-        try {
-            return mISessionController.sendMediaButton(packageName, caller, mediaButton);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Registers a controller callback link to the system.
-     *
-     * @param packageName the package name of the controller
-     * @param cb the controller callback link to register
-     */
-    void registerCallback(@NonNull String packageName, @NonNull ControllerCallbackLink cb) {
-        try {
-            mISessionController.registerCallback(packageName, cb);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Unregisters a controller callback link from the system.
-     *
-     * @param cb the controller callback link to register
-     */
-    void unregisterCallback(@NonNull ControllerCallbackLink cb) {
-        try {
-            mISessionController.unregisterCallback(cb);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the package name of the connected session.
-     */
-    @NonNull
-    String getPackageName() {
-        try {
-            return mISessionController.getPackageName();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the tag of the connected session.
-     */
-    @NonNull
-    String getTag() {
-        try {
-            return mISessionController.getTag();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the session info of the connected session.
-     */
-    @Nullable
-    Bundle getSessionInfo() {
-        try {
-            return mISessionController.getSessionInfo();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the {@link PendingIntent} for launching UI of the connected session.
-     */
-    @Nullable
-    PendingIntent getLaunchPendingIntent() {
-        try {
-            return mISessionController.getLaunchPendingIntent();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the flags of the connected session.
-     */
-    long getFlags() {
-        try {
-            return mISessionController.getFlags();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the volume attributes of the connected session.
-     */
-    @NonNull
-    PlaybackInfo getVolumeAttributes() {
-        try {
-            return mISessionController.getVolumeAttributes();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests adjusting the volume.
-     *
-     * @param packageName the package name of the controller
-     * @param opPackageName the op package name of this request
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param direction the direction to adjust the volume in
-     * @param flags the flags with this volume change request
-     */
-    void adjustVolume(@NonNull String packageName, @NonNull String opPackageName,
-            @NonNull ControllerCallbackLink caller, int direction,
-            int flags) {
-        try {
-            mISessionController.adjustVolume(packageName, opPackageName, caller, direction, flags);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests setting the volume.
-     *
-     * @param packageName the package name of the controller
-     * @param opPackageName the op package name of this request
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param flags the flags with this volume change request
-     */
-    void setVolumeTo(@NonNull String packageName, @NonNull String opPackageName,
-            @NonNull ControllerCallbackLink caller, int value, int flags) {
-        try {
-            mISessionController.setVolumeTo(packageName, opPackageName, caller, value, flags);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests preparing media.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     */
-    void prepare(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        try {
-            mISessionController.prepare(packageName, caller);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests preparing media from given media ID.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param mediaId the ID of the media
-     * @param extras the extras included with this request.
-     */
-    void prepareFromMediaId(@NonNull String packageName,
-            @NonNull ControllerCallbackLink caller, @NonNull String mediaId,
-            @Nullable Bundle extras) {
-        try {
-            mISessionController.prepareFromMediaId(packageName, caller, mediaId, extras);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests preparing media from given search query.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param query the search query
-     * @param extras the extras included with this request.
-     */
-    void prepareFromSearch(@NonNull String packageName,
-            @NonNull ControllerCallbackLink caller, @NonNull String query,
-            @Nullable Bundle extras) {
-        try {
-            mISessionController.prepareFromSearch(packageName, caller, query, extras);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests preparing media from given uri.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param uri the uri of the media
-     * @param extras the extras included with this request.
-     */
-    void prepareFromUri(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            @NonNull Uri uri, @Nullable Bundle extras) {
-        try {
-            mISessionController.prepareFromUri(packageName, caller, uri, extras);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests playing media.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     */
-    void play(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        try {
-            mISessionController.play(packageName, caller);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests playing media from given media ID.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param mediaId the ID of the media
-     * @param extras the extras included with this request.
-     */
-    void playFromMediaId(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            @NonNull String mediaId, @Nullable Bundle extras) {
-        try {
-            mISessionController.playFromMediaId(packageName, caller, mediaId, extras);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests playing media from given search query.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param query the search query
-     * @param extras the extras included with this request.
-     */
-    void playFromSearch(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            @NonNull String query, @Nullable Bundle extras) {
-        try {
-            mISessionController.playFromSearch(packageName, caller, query, extras);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests playing media from given uri.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param uri the uri of the media
-     * @param extras the extras included with this request.
-     */
-    void playFromUri(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            @NonNull Uri uri, @Nullable Bundle extras) {
-        try {
-            mISessionController.playFromUri(packageName, caller, uri, extras);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests skipping to the queue item with given ID.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param id the queue id of the item
-     */
-    void skipToQueueItem(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            long id) {
-        try {
-            mISessionController.skipToQueueItem(packageName, caller, id);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests pausing media.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     */
-    void pause(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        try {
-            mISessionController.pause(packageName, caller);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests stopping media.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     */
-    void stop(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        try {
-            mISessionController.stop(packageName, caller);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests skipping to the next queue item.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     */
-    void next(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        try {
-            mISessionController.next(packageName, caller);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests skipping to the previous queue item.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     */
-    void previous(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        try {
-            mISessionController.previous(packageName, caller);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests fast-forwarding.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     */
-    void fastForward(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        try {
-            mISessionController.fastForward(packageName, caller);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests rewinding.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     */
-    void rewind(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        try {
-            mISessionController.rewind(packageName, caller);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests seeking to the specific position.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param pos the position to move to, in milliseconds
-     */
-    void seekTo(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            long pos) {
-        try {
-            mISessionController.seekTo(packageName, caller, pos);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests rating of the current media.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param rating the rating of the current media
-     */
-    void rate(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            @NonNull Rating rating) {
-        try {
-            mISessionController.rate(packageName, caller, rating);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller requests changing the playback speed.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param speed the playback speed
-     */
-    void setPlaybackSpeed(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-            float speed) {
-        try {
-            mISessionController.setPlaybackSpeed(packageName, caller, speed);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Tell system that a controller sends a custom action.
-     *
-     * @param packageName the package name of the controller
-     * @param caller the {@link ControllerCallbackLink} of the controller
-     * @param action the name of the action
-     * @param args the arguments included with this action
-     */
-    void sendCustomAction(@NonNull String packageName,
-            @NonNull ControllerCallbackLink caller, @NonNull String action, @Nullable Bundle args) {
-        try {
-            mISessionController.sendCustomAction(packageName, caller, action, args);
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the current metadata of the connected session.
-     */
-    @Nullable
-    public MediaMetadata getMetadata() {
-        try {
-            return mISessionController.getMetadata();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the current playback state of the connected session.
-     */
-    @Nullable
-    public PlaybackState getPlaybackState() {
-        try {
-            return mISessionController.getPlaybackState();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the current queue of the connected session.
-     */
-    @Nullable
-    public List<MediaSession.QueueItem> getQueue() {
-        try {
-            MediaParceledListSlice queue = mISessionController.getQueue();
-            return queue == null ? null : queue.getList();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the current queue title of the connected session.
-     */
-    @Nullable
-    public CharSequence getQueueTitle() {
-        try {
-            return mISessionController.getQueueTitle();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the current extras of the connected session.
-     */
-    @Nullable
-    public Bundle getExtras() {
-        try {
-            return mISessionController.getExtras();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /**
-     * Gets the current rating type of the connected session.
-     */
-    public int getRatingType() {
-        try {
-            return mISessionController.getRatingType();
-        } catch (RemoteException e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    /** Gets the binder */
-    @NonNull
-    public IBinder getBinder() {
-        return mISessionController.asBinder();
-    }
-
-    @Override
-    public int describeContents() {
-        return 0;
-    }
-
-    @Override
-    public void writeToParcel(Parcel dest, int flags) {
-        dest.writeStrongBinder(mISessionController.asBinder());
-    }
-
-    @Override
-    public int hashCode() {
-        return mISessionController.asBinder().hashCode();
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (this == obj) {
-            return true;
-        }
-        if (!(obj instanceof ControllerLink)) {
-            return false;
-        }
-        ControllerLink other = (ControllerLink) obj;
-        return Objects.equals(getBinder(), other.getBinder());
-    }
-
-    /**
-     * Class for Stub implementation
-     */
-    public abstract static class ControllerStub {
-        /** Stub method for ISessionController.sendCommand */
-        public void sendCommand(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-                @NonNull String command, @Nullable Bundle args, @Nullable ResultReceiver cb) {
-        }
-
-        /** Stub method for ISessionController.sendMediaButton */
-        public boolean sendMediaButton(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, @NonNull KeyEvent mediaButton) {
-            return false;
-        }
-
-        /** Stub method for ISessionController.registerCallback */
-        public void registerCallback(@NonNull String packageName,
-                @NonNull ControllerCallbackLink cb) {
-        }
-
-        /** Stub method for ISessionController.unregisterCallback */
-        public void unregisterCallback(@NonNull ControllerCallbackLink cb) {
-        }
-
-        /** Stub method for ISessionController.getPackageName */
-        @NonNull
-        public String getPackageName() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getTag */
-        @NonNull
-        public String getTag() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getSessionInfo */
-        @Nullable
-        public Bundle getSessionInfo() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getLaunchPendingIntent */
-        @Nullable
-        public PendingIntent getLaunchPendingIntent() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getFlags */
-        public long getFlags() {
-            return 0;
-        }
-
-        /** Stub method for ISessionController.getVolumeAttributes */
-        @NonNull
-        public PlaybackInfo getVolumeAttributes() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.adjustVolume */
-        public void adjustVolume(@NonNull String packageName, @NonNull String opPackageName,
-                @NonNull ControllerCallbackLink caller, int direction, int flags) {
-        }
-
-        /** Stub method for ISessionController.setVolumeTo */
-        public void setVolumeTo(@NonNull String packageName, @NonNull String opPackageName,
-                @NonNull ControllerCallbackLink caller, int value, int flags) {
-        }
-
-        /** Stub method for ISessionController.prepare */
-        public void prepare(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        }
-
-        /** Stub method for ISessionController.prepareFromMediaId */
-        public void prepareFromMediaId(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, @NonNull String mediaId,
-                @Nullable Bundle extras) {
-        }
-
-        /** Stub method for ISessionController.prepareFromSearch */
-        public void prepareFromSearch(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, @NonNull String query,
-                @Nullable Bundle extras) {
-        }
-
-        /** Stub method for ISessionController.prepareFromUri */
-        public void prepareFromUri(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, @NonNull Uri uri, @Nullable Bundle extras) {
-        }
-
-        /** Stub method for ISessionController.play */
-        public void play(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        }
-
-        /** Stub method for ISessionController.playFromMediaId */
-        public void playFromMediaId(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, @NonNull String mediaId,
-                @Nullable Bundle extras) {
-        }
-
-        /** Stub method for ISessionController.playFromSearch */
-        public void playFromSearch(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, @NonNull String query,
-                @Nullable Bundle extras) {
-        }
-
-        /** Stub method for ISessionController.playFromUri */
-        public void playFromUri(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-                @NonNull Uri uri, @Nullable Bundle extras) {
-        }
-
-        /** Stub method for ISessionController.skipToQueueItem */
-        public void skipToQueueItem(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, long id) {
-        }
-
-        /** Stub method for ISessionController.pause */
-        public void pause(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        }
-
-        /** Stub method for ISessionController.stop */
-        public void stop(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        }
-
-        /** Stub method for ISessionController.next */
-        public void next(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        }
-
-        /** Stub method for ISessionController.previous */
-        public void previous(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        }
-
-        /** Stub method for ISessionController.fastForward */
-        public void fastForward(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller) {
-        }
-
-        /** Stub method for ISessionController.rewind */
-        public void rewind(@NonNull String packageName, @NonNull ControllerCallbackLink caller) {
-        }
-
-        /** Stub method for ISessionController.seekTo */
-        public void seekTo(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-                long pos) {
-        }
-
-        /** Stub method for ISessionController.rate */
-        public void rate(@NonNull String packageName, @NonNull ControllerCallbackLink caller,
-                @NonNull Rating rating) {
-        }
-
-        /** Stub method for ISessionController.setPlaybackSpeed */
-        public void setPlaybackSpeed(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, float speed) {
-        }
-
-        /** Stub method for ISessionController.sendCustomAction */
-        public void sendCustomAction(@NonNull String packageName,
-                @NonNull ControllerCallbackLink caller, @NonNull String action,
-                @Nullable Bundle args) {
-        }
-
-        /** Stub method for ISessionController.getMetadata */
-        @Nullable
-        public MediaMetadata getMetadata() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getPlaybackState */
-        @Nullable
-        public PlaybackState getPlaybackState() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getQueue */
-        @Nullable
-        public List<MediaSession.QueueItem> getQueue() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getQueueTitle */
-        @Nullable
-        public CharSequence getQueueTitle() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getExtras */
-        @Nullable
-        public Bundle getExtras() {
-            return null;
-        }
-
-        /** Stub method for ISessionController.getRatingType */
-        public int getRatingType() {
-            return Rating.RATING_NONE;
-        }
-    }
-
-    private class StubProxy extends ISessionController.Stub {
-        @Override
-        public void sendCommand(String packageName, ControllerCallbackLink caller,
-                String command, Bundle args, ResultReceiver cb) {
-            mControllerStub.sendCommand(packageName, caller, command, args, cb);
-        }
-
-        @Override
-        public boolean sendMediaButton(String packageName, ControllerCallbackLink caller,
-                KeyEvent mediaButton) {
-            return mControllerStub.sendMediaButton(packageName, caller, mediaButton);
-        }
-
-        @Override
-        public void registerCallback(String packageName, ControllerCallbackLink cb) {
-            mControllerStub.registerCallback(packageName, cb);
-        }
-
-        @Override
-        public void unregisterCallback(ControllerCallbackLink cb) {
-            mControllerStub.unregisterCallback(cb);
-        }
-
-        @Override
-        public String getPackageName() {
-            return mControllerStub.getPackageName();
-        }
-
-        @Override
-        public String getTag() {
-            return mControllerStub.getTag();
-        }
-
-        @Override
-        public Bundle getSessionInfo() {
-            return mControllerStub.getSessionInfo();
-        }
-
-        @Override
-        public PendingIntent getLaunchPendingIntent() {
-            return mControllerStub.getLaunchPendingIntent();
-        }
-
-        @Override
-        public long getFlags() {
-            return mControllerStub.getFlags();
-        }
-
-        @Override
-        public PlaybackInfo getVolumeAttributes() {
-            return mControllerStub.getVolumeAttributes();
-        }
-
-        @Override
-        public void adjustVolume(String packageName, String opPackageName,
-                ControllerCallbackLink caller, int direction, int flags) {
-            mControllerStub.adjustVolume(packageName, opPackageName, caller, direction, flags);
-        }
-
-        @Override
-        public void setVolumeTo(String packageName, String opPackageName,
-                ControllerCallbackLink caller, int value, int flags) {
-            mControllerStub.setVolumeTo(packageName, opPackageName, caller, value, flags);
-        }
-
-        @Override
-        public void prepare(String packageName, ControllerCallbackLink caller) {
-            mControllerStub.prepare(packageName, caller);
-        }
-
-        @Override
-        public void prepareFromMediaId(String packageName, ControllerCallbackLink caller,
-                String mediaId, Bundle extras) {
-            mControllerStub.prepareFromMediaId(packageName, caller, mediaId, extras);
-        }
-
-        @Override
-        public void prepareFromSearch(String packageName, ControllerCallbackLink caller,
-                String query, Bundle extras) {
-            mControllerStub.prepareFromSearch(packageName, caller, query, extras);
-        }
-
-        @Override
-        public void prepareFromUri(String packageName, ControllerCallbackLink caller,
-                Uri uri, Bundle extras) {
-            mControllerStub.prepareFromUri(packageName, caller, uri, extras);
-        }
-
-        @Override
-        public void play(String packageName, ControllerCallbackLink caller) {
-            mControllerStub.play(packageName, caller);
-        }
-
-        @Override
-        public void playFromMediaId(String packageName, ControllerCallbackLink caller,
-                String mediaId, Bundle extras) {
-            mControllerStub.playFromMediaId(packageName, caller, mediaId, extras);
-        }
-
-        @Override
-        public void playFromSearch(String packageName, ControllerCallbackLink caller,
-                String query, Bundle extras) {
-            mControllerStub.playFromSearch(packageName, caller, query, extras);
-        }
-
-        @Override
-        public void playFromUri(String packageName, ControllerCallbackLink caller,
-                Uri uri, Bundle extras) {
-            mControllerStub.playFromUri(packageName, caller, uri, extras);
-        }
-
-        @Override
-        public void skipToQueueItem(String packageName, ControllerCallbackLink caller, long id) {
-            mControllerStub.skipToQueueItem(packageName, caller, id);
-        }
-
-        @Override
-        public void pause(String packageName, ControllerCallbackLink caller) {
-            mControllerStub.pause(packageName, caller);
-        }
-
-        @Override
-        public void stop(String packageName, ControllerCallbackLink caller) {
-            mControllerStub.stop(packageName, caller);
-        }
-
-        @Override
-        public void next(String packageName, ControllerCallbackLink caller) {
-            mControllerStub.next(packageName, caller);
-        }
-
-        @Override
-        public void previous(String packageName, ControllerCallbackLink caller) {
-            mControllerStub.previous(packageName, caller);
-        }
-
-        @Override
-        public void fastForward(String packageName, ControllerCallbackLink caller) {
-            mControllerStub.fastForward(packageName, caller);
-        }
-
-        @Override
-        public void rewind(String packageName, ControllerCallbackLink caller) {
-            mControllerStub.rewind(packageName, caller);
-        }
-
-        @Override
-        public void seekTo(String packageName, ControllerCallbackLink caller, long pos) {
-            mControllerStub.seekTo(packageName, caller, pos);
-        }
-
-        @Override
-        public void rate(String packageName, ControllerCallbackLink caller, Rating rating) {
-            mControllerStub.rate(packageName, caller, rating);
-        }
-
-        @Override
-        public void setPlaybackSpeed(String packageName, ControllerCallbackLink caller,
-                float speed) {
-            mControllerStub.setPlaybackSpeed(packageName, caller, speed);
-        }
-
-        @Override
-        public void sendCustomAction(String packageName, ControllerCallbackLink caller,
-                String action, Bundle args) {
-            mControllerStub.sendCustomAction(packageName, caller, action, args);
-        }
-
-        @Override
-        public MediaMetadata getMetadata() {
-            return mControllerStub.getMetadata();
-        }
-
-        @Override
-        public PlaybackState getPlaybackState() {
-            return mControllerStub.getPlaybackState();
-        }
-
-        @Override
-        public MediaParceledListSlice getQueue() {
-            List<MediaSession.QueueItem> queue = mControllerStub.getQueue();
-            return queue == null ? null : new MediaParceledListSlice(queue);
-        }
-
-        @Override
-        public CharSequence getQueueTitle() {
-            return mControllerStub.getQueueTitle();
-        }
-
-        @Override
-        public Bundle getExtras() {
-            return mControllerStub.getExtras();
-        }
-
-        @Override
-        public int getRatingType() {
-            return mControllerStub.getRatingType();
-        }
-    }
-}
diff --git a/media/java/android/media/session/ISession.aidl b/media/java/android/media/session/ISession.aidl
index 9b1ad7b..fcde95a 100644
--- a/media/java/android/media/session/ISession.aidl
+++ b/media/java/android/media/session/ISession.aidl
@@ -19,7 +19,7 @@
 import android.media.AudioAttributes;
 import android.media.MediaMetadata;
 import android.media.MediaParceledListSlice;
-import android.media.session.ControllerLink;
+import android.media.session.ISessionController;
 import android.media.session.PlaybackState;
 import android.media.session.MediaSession;
 import android.os.Bundle;
@@ -31,7 +31,7 @@
  */
 interface ISession {
     void sendEvent(String event, in Bundle data);
-    ControllerLink getController();
+    ISessionController getController();
     void setFlags(int flags);
     void setActive(boolean active);
     void setMediaButtonReceiver(in PendingIntent mbr);
diff --git a/media/java/android/media/session/MediaController.java b/media/java/android/media/session/MediaController.java
index 7334044..036cd78 100644
--- a/media/java/android/media/session/MediaController.java
+++ b/media/java/android/media/session/MediaController.java
@@ -24,6 +24,7 @@
 import android.media.AudioAttributes;
 import android.media.AudioManager;
 import android.media.MediaMetadata;
+import android.media.MediaParceledListSlice;
 import android.media.Rating;
 import android.media.VolumeProvider;
 import android.media.session.MediaSession.QueueItem;
@@ -34,6 +35,7 @@
 import android.os.Message;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.os.RemoteException;
 import android.os.ResultReceiver;
 import android.text.TextUtils;
 import android.util.Log;
@@ -67,7 +69,7 @@
     private static final int MSG_UPDATE_EXTRAS = 7;
     private static final int MSG_DESTROYED = 8;
 
-    private final ControllerLink mSessionBinder;
+    private final ISessionController mSessionBinder;
 
     private final MediaSession.Token mToken;
     private final Context mContext;
@@ -95,10 +97,10 @@
         if (token == null) {
             throw new IllegalArgumentException("token shouldn't be null");
         }
-        if (token.getControllerLink() == null) {
-            throw new IllegalArgumentException("token.getControllerLink() shouldn't be null");
+        if (token.getBinder() == null) {
+            throw new IllegalArgumentException("token.getBinder() shouldn't be null");
         }
-        mSessionBinder = token.getControllerLink();
+        mSessionBinder = token.getBinder();
         mTransportControls = new TransportControls();
         mToken = token;
         mContext = context;
@@ -131,7 +133,7 @@
         }
         try {
             return mSessionBinder.sendMediaButton(mContext.getPackageName(), mCbStub, keyEvent);
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             // System is dead. =(
         }
         return false;
@@ -145,7 +147,7 @@
     public @Nullable PlaybackState getPlaybackState() {
         try {
             return mSessionBinder.getPlaybackState();
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getPlaybackState.", e);
             return null;
         }
@@ -159,7 +161,7 @@
     public @Nullable MediaMetadata getMetadata() {
         try {
             return mSessionBinder.getMetadata();
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getMetadata.", e);
             return null;
         }
@@ -173,8 +175,9 @@
      */
     public @Nullable List<MediaSession.QueueItem> getQueue() {
         try {
-            return mSessionBinder.getQueue();
-        } catch (RuntimeException e) {
+            MediaParceledListSlice list = mSessionBinder.getQueue();
+            return list == null ? null : list.getList();
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getQueue.", e);
         }
         return null;
@@ -186,7 +189,7 @@
     public @Nullable CharSequence getQueueTitle() {
         try {
             return mSessionBinder.getQueueTitle();
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getQueueTitle", e);
         }
         return null;
@@ -198,7 +201,7 @@
     public @Nullable Bundle getExtras() {
         try {
             return mSessionBinder.getExtras();
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getExtras", e);
         }
         return null;
@@ -221,7 +224,7 @@
     public int getRatingType() {
         try {
             return mSessionBinder.getRatingType();
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getRatingType.", e);
             return Rating.RATING_NONE;
         }
@@ -235,7 +238,7 @@
     public long getFlags() {
         try {
             return mSessionBinder.getFlags();
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getFlags.", e);
         }
         return 0;
@@ -249,7 +252,7 @@
     public @Nullable PlaybackInfo getPlaybackInfo() {
         try {
             return mSessionBinder.getVolumeAttributes();
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getAudioInfo.", e);
         }
         return null;
@@ -264,7 +267,7 @@
     public @Nullable PendingIntent getSessionActivity() {
         try {
             return mSessionBinder.getLaunchPendingIntent();
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling getPendingIntent.", e);
         }
         return null;
@@ -297,7 +300,7 @@
             //       AppOpsManager usages.
             mSessionBinder.setVolumeTo(mContext.getPackageName(), mContext.getOpPackageName(),
                     mCbStub, value, flags);
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling setVolumeTo.", e);
         }
     }
@@ -322,7 +325,7 @@
             //       AppOpsManager usages.
             mSessionBinder.adjustVolume(mContext.getPackageName(), mContext.getOpPackageName(),
                     mCbStub, direction, flags);
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.wtf(TAG, "Error calling adjustVolumeBy.", e);
         }
     }
@@ -388,7 +391,7 @@
         }
         try {
             mSessionBinder.sendCommand(mContext.getPackageName(), mCbStub, command, args, cb);
-        } catch (RuntimeException e) {
+        } catch (RemoteException e) {
             Log.d(TAG, "Dead object in sendCommand.", e);
         }
     }
@@ -402,7 +405,7 @@
         if (mPackageName == null) {
             try {
                 mPackageName = mSessionBinder.getPackageName();
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.d(TAG, "Dead object in getPackageName.", e);
             }
         }
@@ -419,7 +422,7 @@
         if (mSessionInfo == null) {
             try {
                 mSessionInfo = mSessionBinder.getSessionInfo();
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.d(TAG, "Dead object in getSessionInfo.", e);
             }
         }
@@ -436,7 +439,7 @@
         if (mTag == null) {
             try {
                 mTag = mSessionBinder.getTag();
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.d(TAG, "Dead object in getTag.", e);
             }
         }
@@ -446,7 +449,7 @@
     /*
      * @hide
      */
-    ControllerLink getSessionBinder() {
+    ISessionController getSessionBinder() {
         return mSessionBinder;
     }
 
@@ -456,7 +459,7 @@
     @UnsupportedAppUsage
     public boolean controlsSameSession(MediaController other) {
         if (other == null) return false;
-        return mSessionBinder.getBinder() == other.getSessionBinder().getBinder();
+        return mSessionBinder.asBinder() == other.getSessionBinder().asBinder();
     }
 
     private void addCallbackLocked(Callback cb, Handler handler) {
@@ -472,7 +475,7 @@
             try {
                 mSessionBinder.registerCallback(mContext.getPackageName(), mCbStub);
                 mCbRegistered = true;
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.e(TAG, "Dead object in registerCallback", e);
             }
         }
@@ -491,7 +494,7 @@
         if (mCbRegistered && mCallbacks.size() == 0) {
             try {
                 mSessionBinder.unregisterCallback(mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.e(TAG, "Dead object in removeCallbackLocked");
             }
             mCbRegistered = false;
@@ -618,7 +621,7 @@
         public void prepare() {
             try {
                 mSessionBinder.prepare(mContext.getPackageName(), mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling prepare.", e);
             }
         }
@@ -643,7 +646,7 @@
             try {
                 mSessionBinder.prepareFromMediaId(mContext.getPackageName(), mCbStub, mediaId,
                         extras);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling prepare(" + mediaId + ").", e);
             }
         }
@@ -670,7 +673,7 @@
             try {
                 mSessionBinder.prepareFromSearch(mContext.getPackageName(), mCbStub, query,
                         extras);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling prepare(" + query + ").", e);
             }
         }
@@ -694,7 +697,7 @@
             }
             try {
                 mSessionBinder.prepareFromUri(mContext.getPackageName(), mCbStub, uri, extras);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling prepare(" + uri + ").", e);
             }
         }
@@ -705,7 +708,7 @@
         public void play() {
             try {
                 mSessionBinder.play(mContext.getPackageName(), mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling play.", e);
             }
         }
@@ -725,7 +728,7 @@
             try {
                 mSessionBinder.playFromMediaId(mContext.getPackageName(), mCbStub, mediaId,
                         extras);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling play(" + mediaId + ").", e);
             }
         }
@@ -747,7 +750,7 @@
             }
             try {
                 mSessionBinder.playFromSearch(mContext.getPackageName(), mCbStub, query, extras);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling play(" + query + ").", e);
             }
         }
@@ -766,7 +769,7 @@
             }
             try {
                 mSessionBinder.playFromUri(mContext.getPackageName(), mCbStub, uri, extras);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling play(" + uri + ").", e);
             }
         }
@@ -778,7 +781,7 @@
         public void skipToQueueItem(long id) {
             try {
                 mSessionBinder.skipToQueueItem(mContext.getPackageName(), mCbStub, id);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling skipToItem(" + id + ").", e);
             }
         }
@@ -790,7 +793,7 @@
         public void pause() {
             try {
                 mSessionBinder.pause(mContext.getPackageName(), mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling pause.", e);
             }
         }
@@ -802,7 +805,7 @@
         public void stop() {
             try {
                 mSessionBinder.stop(mContext.getPackageName(), mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling stop.", e);
             }
         }
@@ -815,7 +818,7 @@
         public void seekTo(long pos) {
             try {
                 mSessionBinder.seekTo(mContext.getPackageName(), mCbStub, pos);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling seekTo.", e);
             }
         }
@@ -827,7 +830,7 @@
         public void fastForward() {
             try {
                 mSessionBinder.fastForward(mContext.getPackageName(), mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling fastForward.", e);
             }
         }
@@ -838,7 +841,7 @@
         public void skipToNext() {
             try {
                 mSessionBinder.next(mContext.getPackageName(), mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling next.", e);
             }
         }
@@ -850,7 +853,7 @@
         public void rewind() {
             try {
                 mSessionBinder.rewind(mContext.getPackageName(), mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling rewind.", e);
             }
         }
@@ -861,7 +864,7 @@
         public void skipToPrevious() {
             try {
                 mSessionBinder.previous(mContext.getPackageName(), mCbStub);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling previous.", e);
             }
         }
@@ -876,7 +879,7 @@
         public void setRating(Rating rating) {
             try {
                 mSessionBinder.rate(mContext.getPackageName(), mCbStub, rating);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling rate.", e);
             }
         }
@@ -889,7 +892,7 @@
         public void setPlaybackSpeed(float speed) {
             try {
                 mSessionBinder.setPlaybackSpeed(mContext.getPackageName(), mCbStub, speed);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.wtf(TAG, "Error calling setPlaybackSpeed.", e);
             }
         }
@@ -924,7 +927,7 @@
             }
             try {
                 mSessionBinder.sendCustomAction(mContext.getPackageName(), mCbStub, action, args);
-            } catch (RuntimeException e) {
+            } catch (RemoteException e) {
                 Log.d(TAG, "Dead object in sendCustomAction.", e);
             }
         }
diff --git a/media/java/android/media/session/MediaSession.java b/media/java/android/media/session/MediaSession.java
index c4f8b79..4fc436c 100644
--- a/media/java/android/media/session/MediaSession.java
+++ b/media/java/android/media/session/MediaSession.java
@@ -445,19 +445,19 @@
     public static final class Token implements Parcelable {
 
         private final int mUid;
-        private final ControllerLink mControllerLink;
+        private final ISessionController mBinder;
 
         /**
          * @hide
          */
-        public Token(ControllerLink controllerLink) {
+        public Token(ISessionController binder) {
             mUid = Process.myUid();
-            mControllerLink = controllerLink;
+            mBinder = binder;
         }
 
         Token(Parcel in) {
             mUid = in.readInt();
-            mControllerLink = in.readParcelable(null);
+            mBinder = ISessionController.Stub.asInterface(in.readStrongBinder());
         }
 
         @Override
@@ -468,15 +468,14 @@
         @Override
         public void writeToParcel(Parcel dest, int flags) {
             dest.writeInt(mUid);
-            dest.writeParcelable(mControllerLink, flags);
+            dest.writeStrongBinder(mBinder.asBinder());
         }
 
         @Override
         public int hashCode() {
             final int prime = 31;
             int result = mUid;
-            result = prime * result + ((mControllerLink == null)
-                    ? 0 : mControllerLink.getBinder().hashCode());
+            result = prime * result + (mBinder == null ? 0 : mBinder.asBinder().hashCode());
             return result;
         }
 
@@ -492,7 +491,10 @@
             if (mUid != other.mUid) {
                 return false;
             }
-            return Objects.equals(mControllerLink, other.mControllerLink);
+            if (mBinder == null || other.mBinder == null) {
+                return mBinder == other.mBinder;
+            }
+            return Objects.equals(mBinder.asBinder(), other.mBinder.asBinder());
         }
 
         /**
@@ -504,11 +506,11 @@
         }
 
         /**
-         * Gets the controller link in this token.
+         * Gets the controller binder in this token.
          * @hide
          */
-        public ControllerLink getControllerLink() {
-            return mControllerLink;
+        public ISessionController getBinder() {
+            return mBinder;
         }
 
         public static final @android.annotation.NonNull Parcelable.Creator<Token> CREATOR =
diff --git a/media/java/android/media/session/SessionLink.java b/media/java/android/media/session/SessionLink.java
index 2b42a2d6..a47c262 100644
--- a/media/java/android/media/session/SessionLink.java
+++ b/media/java/android/media/session/SessionLink.java
@@ -83,10 +83,10 @@
     }
 
     /**
-     * Gets the controller link from the system.
+     * Gets the controller binder from the system.
      */
     @NonNull
-    ControllerLink getController() {
+    ISessionController getController() {
         try {
             return mISession.getController();
         } catch (RemoteException e) {
@@ -304,7 +304,7 @@
 
         /** Stub method for ISession.getController */
         @NonNull
-        public ControllerLink getController() {
+        public ISessionController getController() {
             return null;
         }
 
@@ -373,7 +373,7 @@
         }
 
         @Override
-        public ControllerLink getController() {
+        public ISessionController getController() {
             return mSessionStub.getController();
         }
 
diff --git a/media/mca/Android.mk b/media/mca/Android.mk
deleted file mode 100644
index b1ce91e..0000000
--- a/media/mca/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# 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.
-#
-
-#
-# Build all native libraries
-#
-include $(call all-subdir-makefiles)
-
-
diff --git a/media/mca/samples/Android.mk b/media/mca/samples/Android.mk
deleted file mode 100644
index b1ce91e..0000000
--- a/media/mca/samples/Android.mk
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# 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.
-#
-
-#
-# Build all native libraries
-#
-include $(call all-subdir-makefiles)
-
-
diff --git a/media/mca/samples/CameraEffectsRecordingSample/Android.bp b/media/mca/samples/CameraEffectsRecordingSample/Android.bp
new file mode 100644
index 0000000..96e81ab
--- /dev/null
+++ b/media/mca/samples/CameraEffectsRecordingSample/Android.bp
@@ -0,0 +1,26 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// 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.
+//
+
+// Build activity
+
+android_test {
+    name: "CameraEffectsRecordingSample",
+    srcs: ["**/*.java"],
+    platform_apis: true,
+    optimize: {
+        enabled: false,
+    },
+}
+
diff --git a/media/mca/samples/CameraEffectsRecordingSample/Android.mk b/media/mca/samples/CameraEffectsRecordingSample/Android.mk
deleted file mode 100644
index c81f2fc..0000000
--- a/media/mca/samples/CameraEffectsRecordingSample/Android.mk
+++ /dev/null
@@ -1,35 +0,0 @@
-# Copyright (C) 2011 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# 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.
-#
-
-# Build activity
-
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-
-LOCAL_PACKAGE_NAME := CameraEffectsRecordingSample
-LOCAL_PRIVATE_PLATFORM_APIS := true
-
-LOCAL_PROGUARD_ENABLED := disabled
-
-include $(BUILD_PACKAGE)
-
-# ============================================================
-
-# Also build all of the sub-targets under this one: the shared library.
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/mca/tests/Android.bp b/media/mca/tests/Android.bp
new file mode 100644
index 0000000..6b11dd9
--- /dev/null
+++ b/media/mca/tests/Android.bp
@@ -0,0 +1,12 @@
+android_test {
+    name: "CameraEffectsTests",
+    libs: [
+        "android.test.runner",
+        "android.test.base",
+    ],
+    static_libs: ["junit"],
+    // Include all test java files.
+    srcs: ["src/**/*.java"],
+    platform_apis: true,
+    instrumentation_for: "CameraEffectsRecordingSample",
+}
diff --git a/media/mca/tests/Android.mk b/media/mca/tests/Android.mk
deleted file mode 100644
index 648af4e..0000000
--- a/media/mca/tests/Android.mk
+++ /dev/null
@@ -1,20 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-# We only want this apk build for tests.
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_JAVA_LIBRARIES := android.test.runner android.test.base
-LOCAL_STATIC_JAVA_LIBRARIES := junit
-
-# Include all test java files.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := CameraEffectsTests
-LOCAL_PRIVATE_PLATFORM_APIS := true
-
-LOCAL_INSTRUMENTATION_FOR := CameraEffectsRecordingSample
-
-include $(BUILD_PACKAGE)
-
-
diff --git a/media/packages/BluetoothMidiService/Android.bp b/media/packages/BluetoothMidiService/Android.bp
new file mode 100644
index 0000000..f45114a
--- /dev/null
+++ b/media/packages/BluetoothMidiService/Android.bp
@@ -0,0 +1,6 @@
+android_app {
+    name: "BluetoothMidiService",
+    srcs: ["src/**/*.java"],
+    platform_apis: true,
+    certificate: "platform",
+}
diff --git a/media/packages/BluetoothMidiService/Android.mk b/media/packages/BluetoothMidiService/Android.mk
deleted file mode 100644
index 6f262bf..0000000
--- a/media/packages/BluetoothMidiService/Android.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-
-LOCAL_SRC_FILES += \
-      $(call all-java-files-under,src)
-
-LOCAL_PACKAGE_NAME := BluetoothMidiService
-LOCAL_PRIVATE_PLATFORM_APIS := true
-LOCAL_CERTIFICATE := platform
-
-include $(BUILD_PACKAGE)
diff --git a/media/tests/CameraBrowser/Android.bp b/media/tests/CameraBrowser/Android.bp
new file mode 100644
index 0000000..8e3ca19
--- /dev/null
+++ b/media/tests/CameraBrowser/Android.bp
@@ -0,0 +1,5 @@
+android_test {
+    name: "CameraBrowser",
+    srcs: ["**/*.java"],
+    sdk_version: "current",
+}
diff --git a/media/tests/CameraBrowser/Android.mk b/media/tests/CameraBrowser/Android.mk
deleted file mode 100644
index 46596a7..0000000
--- a/media/tests/CameraBrowser/Android.mk
+++ /dev/null
@@ -1,12 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-
-LOCAL_PACKAGE_NAME := CameraBrowser
-
-LOCAL_SDK_VERSION := current
-
-include $(BUILD_PACKAGE)
diff --git a/media/tests/EffectsTest/Android.bp b/media/tests/EffectsTest/Android.bp
new file mode 100644
index 0000000..214e8c0
--- /dev/null
+++ b/media/tests/EffectsTest/Android.bp
@@ -0,0 +1,5 @@
+android_test {
+    name: "EffectsTest",
+    srcs: ["**/*.java"],
+    platform_apis: true,
+}
diff --git a/media/tests/EffectsTest/Android.mk b/media/tests/EffectsTest/Android.mk
deleted file mode 100644
index a066950..0000000
--- a/media/tests/EffectsTest/Android.mk
+++ /dev/null
@@ -1,11 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-
-LOCAL_PACKAGE_NAME := EffectsTest
-LOCAL_PRIVATE_PLATFORM_APIS := true
-
-include $(BUILD_PACKAGE)
diff --git a/media/tests/MediaDump/Android.bp b/media/tests/MediaDump/Android.bp
new file mode 100644
index 0000000..0eba8b2
--- /dev/null
+++ b/media/tests/MediaDump/Android.bp
@@ -0,0 +1,6 @@
+android_app {
+    name: "MediaDump",
+    // Only compile source java files in this apk.
+    srcs: ["src/**/*.java"],
+    sdk_version: "current",
+}
diff --git a/media/tests/MediaDump/Android.mk b/media/tests/MediaDump/Android.mk
deleted file mode 100644
index 74afdd0..0000000
--- a/media/tests/MediaDump/Android.mk
+++ /dev/null
@@ -1,16 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := optional
-
-# Only compile source java files in this apk.
-LOCAL_SRC_FILES := $(call all-java-files-under, src)
-
-LOCAL_PACKAGE_NAME := MediaDump
-
-LOCAL_SDK_VERSION := current
-
-include $(BUILD_PACKAGE)
-
-# Use the following include to make our test apk.
-include $(call all-makefiles-under,$(LOCAL_PATH))
diff --git a/media/tests/ScoAudioTest/Android.bp b/media/tests/ScoAudioTest/Android.bp
new file mode 100644
index 0000000..ad2b9171
--- /dev/null
+++ b/media/tests/ScoAudioTest/Android.bp
@@ -0,0 +1,5 @@
+android_test {
+    name: "scoaudiotest",
+    platform_apis: true,
+    srcs: ["**/*.java"],
+}
diff --git a/media/tests/ScoAudioTest/Android.mk b/media/tests/ScoAudioTest/Android.mk
deleted file mode 100644
index 2ad91a4..0000000
--- a/media/tests/ScoAudioTest/Android.mk
+++ /dev/null
@@ -1,13 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-#LOCAL_SDK_VERSION := current
-LOCAL_PRIVATE_PLATFORM_APIS := true
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-
-LOCAL_PACKAGE_NAME := scoaudiotest
-
-include $(BUILD_PACKAGE)
diff --git a/media/tests/SoundPoolTest/Android.bp b/media/tests/SoundPoolTest/Android.bp
new file mode 100644
index 0000000..473f531
--- /dev/null
+++ b/media/tests/SoundPoolTest/Android.bp
@@ -0,0 +1,5 @@
+android_test {
+    name: "SoundPoolTest",
+    srcs: ["**/*.java"],
+    platform_apis: true,
+}
diff --git a/media/tests/SoundPoolTest/Android.mk b/media/tests/SoundPoolTest/Android.mk
deleted file mode 100644
index 9ca33c8..0000000
--- a/media/tests/SoundPoolTest/Android.mk
+++ /dev/null
@@ -1,11 +0,0 @@
-LOCAL_PATH:= $(call my-dir)
-include $(CLEAR_VARS)
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_SRC_FILES := $(call all-subdir-java-files)
-
-LOCAL_PACKAGE_NAME := SoundPoolTest
-LOCAL_PRIVATE_PLATFORM_APIS := true
-
-include $(BUILD_PACKAGE)
diff --git a/media/tests/players/Android.bp b/media/tests/players/Android.bp
new file mode 100644
index 0000000..23c5f04
--- /dev/null
+++ b/media/tests/players/Android.bp
@@ -0,0 +1,31 @@
+// Copyright (C) 2009 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.
+
+cc_test_library {
+    name: "invoke_mock_media_player",
+    srcs: ["invoke_mock_media_player.cpp"],
+    shared_libs: [
+        "libbinder",
+        "libmedia",
+        "libutils",
+        "liblog",
+    ],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wunused",
+        "-Wunreachable-code",
+    ],
+    gtest: false,
+}
diff --git a/media/tests/players/Android.mk b/media/tests/players/Android.mk
deleted file mode 100644
index ee9d850..0000000
--- a/media/tests/players/Android.mk
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright (C) 2009 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-LOCAL_PATH:= $(call my-dir)
-
-include $(CLEAR_VARS)
-
-LOCAL_SRC_FILES:= invoke_mock_media_player.cpp
-
-LOCAL_SHARED_LIBRARIES:= \
-    libbinder \
-    libmedia \
-    libutils \
-    liblog
-
-LOCAL_MODULE:= invoke_mock_media_player
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_CFLAGS += -Wall -Werror -Wunused -Wunreachable-code
-
-include $(BUILD_SHARED_LIBRARY)
diff --git a/packages/ExtServices/Android.mk b/packages/ExtServices/Android.mk
index 1133499..a06dd86 100644
--- a/packages/ExtServices/Android.mk
+++ b/packages/ExtServices/Android.mk
@@ -25,10 +25,6 @@
 
 LOCAL_CERTIFICATE := platform
 
-LOCAL_AAPT_FLAGS := --shared-lib
-
-LOCAL_EXPORT_PACKAGE_RESOURCES := true
-
 LOCAL_PROGUARD_FLAG_FILES := proguard.proguard
 
 LOCAL_PRIVILEGED_MODULE := true
diff --git a/packages/ExtServices/AndroidManifest.xml b/packages/ExtServices/AndroidManifest.xml
index e47d53c..76e2fe7 100644
--- a/packages/ExtServices/AndroidManifest.xml
+++ b/packages/ExtServices/AndroidManifest.xml
@@ -78,6 +78,10 @@
             </intent-filter>
         </service>
 
+        <activity android:name=".notification.CopyCodeActivity"
+                  android:exported="false"
+                  android:theme="@android:style/Theme.NoDisplay"/>
+
         <library android:name="android.ext.services"/>
     </application>
 
diff --git a/packages/ExtServices/res/values/strings.xml b/packages/ExtServices/res/values/strings.xml
index a9a5450..de35441 100644
--- a/packages/ExtServices/res/values/strings.xml
+++ b/packages/ExtServices/res/values/strings.xml
@@ -24,4 +24,10 @@
         <item>EDIT_DISTANCE</item>
         <item>EXACT_MATCH</item>
     </string-array>
+
+    <!-- Action chip to copy a one time code to the user's clipboard [CHAR LIMIT=NONE]-->
+    <string name="copy_code_desc">Copy \u201c<xliff:g id="code" example="12345">%1$s</xliff:g>\u201c</string>
+    <!-- Toast to display when text is copied to the device clipboard [CHAR LIMIT=64]-->
+    <string name="code_copied_to_clipboard">Code copied</string>
+
 </resources>
diff --git a/packages/ExtServices/src/android/ext/services/notification/CopyCodeActivity.java b/packages/ExtServices/src/android/ext/services/notification/CopyCodeActivity.java
new file mode 100644
index 0000000..6708d4d
--- /dev/null
+++ b/packages/ExtServices/src/android/ext/services/notification/CopyCodeActivity.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.ext.services.notification;
+
+import android.app.Activity;
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Intent;
+import android.ext.services.R;
+import android.os.Bundle;
+import android.text.TextUtils;
+import android.util.Log;
+import android.widget.Toast;
+
+/**
+ * An activity that copies text in the Bundle.
+ */
+public class CopyCodeActivity extends Activity {
+    private static final String TAG = "CopyCodeActivity";
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        handleIntent();
+        finish();
+    }
+
+    private void handleIntent() {
+        String code = getIntent().getStringExtra(Intent.EXTRA_TEXT);
+        if (TextUtils.isEmpty(code)) {
+            Log.w(TAG, "handleIntent: empty code");
+            return;
+        }
+        ClipboardManager clipboardManager = getSystemService(ClipboardManager.class);
+        ClipData clipData = ClipData.newPlainText(null, code);
+        clipboardManager.setPrimaryClip(clipData);
+        Toast.makeText(getApplicationContext(), R.string.code_copied_to_clipboard,
+                Toast.LENGTH_SHORT).show();
+    }
+}
diff --git a/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java b/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java
index 24fa87a..bf8a3fa 100644
--- a/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java
+++ b/packages/ExtServices/src/android/ext/services/notification/SmartActionsHelper.java
@@ -15,11 +15,15 @@
  */
 package android.ext.services.notification;
 
+import android.annotation.Nullable;
 import android.app.Notification;
+import android.app.PendingIntent;
 import android.app.Person;
 import android.app.RemoteAction;
 import android.app.RemoteInput;
 import android.content.Context;
+import android.content.Intent;
+import android.ext.services.R;
 import android.graphics.drawable.Icon;
 import android.os.Bundle;
 import android.os.Parcelable;
@@ -48,11 +52,12 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Objects;
-import java.util.stream.Collectors;
 
 public class SmartActionsHelper {
-    private static final String KEY_ACTION_TYPE = "action_type";
-    private static final String KEY_ACTION_SCORE = "action_score";
+    static final String ENTITIES_EXTRAS = "entities-extras";
+    static final String KEY_ACTION_TYPE = "action_type";
+    static final String KEY_ACTION_SCORE = "action_score";
+    static final String KEY_TEXT = "text";
     // If a notification has any of these flags set, it's inelgibile for actions being added.
     private static final int FLAG_MASK_INELGIBILE_FOR_ACTIONS =
             Notification.FLAG_ONGOING_EVENT
@@ -109,11 +114,25 @@
             repliesScore.put(textReply, conversationAction.getConfidenceScore());
         }
 
-        ArrayList<Notification.Action> actions = conversationActions.stream()
-                .filter(conversationAction -> conversationAction.getAction() != null)
-                .map(action -> createNotificationAction(
-                        action.getAction(), action.getType(), action.getConfidenceScore()))
-                .collect(Collectors.toCollection(ArrayList::new));
+        ArrayList<Notification.Action> actions = new ArrayList<>();
+        for (ConversationAction conversationAction : conversationActions) {
+            if (!TextUtils.isEmpty(conversationAction.getTextReply())) {
+                continue;
+            }
+            Notification.Action notificationAction;
+            if (conversationAction.getAction() == null) {
+                notificationAction =
+                        createNotificationActionWithoutRemoteAction(conversationAction);
+            } else {
+                notificationAction = createNotificationActionFromRemoteAction(
+                        conversationAction.getAction(),
+                        conversationAction.getType(),
+                        conversationAction.getConfidenceScore());
+            }
+            if (notificationAction != null) {
+                actions.add(notificationAction);
+            }
+        }
 
         // Start a new session for logging if necessary.
         if (!TextUtils.isEmpty(resultId)
@@ -127,6 +146,55 @@
     }
 
     /**
+     * Creates notification action from ConversationAction that does not come up a RemoteAction.
+     * It could happen because we don't have common intents for some actions, like copying text.
+     */
+    @Nullable
+    private Notification.Action createNotificationActionWithoutRemoteAction(
+            ConversationAction conversationAction) {
+        if (ConversationAction.TYPE_COPY.equals(conversationAction.getType())) {
+            return createCopyCodeAction(conversationAction);
+        }
+        return null;
+    }
+
+    @Nullable
+    private Notification.Action createCopyCodeAction(ConversationAction conversationAction) {
+        Bundle extras = conversationAction.getExtras();
+        if (extras == null) {
+            return null;
+        }
+        Bundle entitiesExtas = extras.getParcelable(ENTITIES_EXTRAS);
+        if (entitiesExtas == null) {
+            return null;
+        }
+        String code = entitiesExtas.getString(KEY_TEXT);
+        if (TextUtils.isEmpty(code)) {
+            return null;
+        }
+        String contentDescription = mContext.getString(R.string.copy_code_desc, code);
+        Intent intent = new Intent(mContext, CopyCodeActivity.class);
+        intent.putExtra(Intent.EXTRA_TEXT, code);
+
+        RemoteAction remoteAction = new RemoteAction(Icon.createWithResource(
+                mContext.getResources(),
+                com.android.internal.R.drawable.ic_menu_copy_material),
+                code,
+                contentDescription,
+                PendingIntent.getActivity(
+                        mContext,
+                        code.hashCode(),
+                        intent,
+                        PendingIntent.FLAG_UPDATE_CURRENT
+                ));
+
+        return createNotificationActionFromRemoteAction(
+                remoteAction,
+                ConversationAction.TYPE_COPY,
+                conversationAction.getConfidenceScore());
+    }
+
+    /**
      * Returns whether the suggestion might be used in the notifications in SysUI.
      * <p>
      * Currently, NAS has no idea if suggestions will actually be used in the notification, and thus
@@ -292,7 +360,7 @@
         mTextClassifier.onTextClassifierEvent(textClassifierEvent);
     }
 
-    private Notification.Action createNotificationAction(
+    private Notification.Action createNotificationActionFromRemoteAction(
             RemoteAction remoteAction, String actionType, float score) {
         Icon icon = remoteAction.shouldShowIcon()
                 ? remoteAction.getIcon()
diff --git a/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionsHelperTest.java b/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionsHelperTest.java
index a1fbc7b..3a7d799 100644
--- a/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionsHelperTest.java
+++ b/packages/ExtServices/tests/src/android/ext/services/notification/SmartActionsHelperTest.java
@@ -36,6 +36,7 @@
 import android.content.Intent;
 import android.content.pm.IPackageManager;
 import android.graphics.drawable.Icon;
+import android.os.Bundle;
 import android.os.Process;
 import android.service.notification.NotificationAssistantService;
 import android.service.notification.StatusBarNotification;
@@ -419,6 +420,31 @@
         assertTextClassifierEvent(events.get(1), TextClassifierEvent.TYPE_ACTIONS_SHOWN);
     }
 
+    @Test
+    public void testCopyAction() {
+        Bundle extras = new Bundle();
+        Bundle entitiesExtras = new Bundle();
+        entitiesExtras.putString(SmartActionsHelper.KEY_TEXT, "12345");
+        extras.putParcelable(SmartActionsHelper.ENTITIES_EXTRAS, entitiesExtras);
+        ConversationAction conversationAction =
+                new ConversationAction.Builder(ConversationAction.TYPE_COPY)
+                        .setExtras(extras)
+                        .build();
+        when(mTextClassifier.suggestConversationActions(any(ConversationActions.Request.class)))
+                .thenReturn(
+                        new ConversationActions(
+                                Collections.singletonList(conversationAction), null));
+
+        Notification notification = createMessageNotification();
+        when(mStatusBarNotification.getNotification()).thenReturn(notification);
+        SmartActionsHelper.SmartSuggestions suggestions =
+                mSmartActionsHelper.suggest(createNotificationEntry());
+
+        assertThat(suggestions.actions).hasSize(1);
+        Notification.Action action = suggestions.actions.get(0);
+        assertThat(action.title).isEqualTo("12345");
+    }
+
     private ZonedDateTime createZonedDateTimeFromMsUtc(long msUtc) {
         return ZonedDateTime.ofInstant(Instant.ofEpochMilli(msUtc), ZoneOffset.systemDefault());
     }
diff --git a/packages/NetworkStack/src/android/net/ip/IpClient.java b/packages/NetworkStack/src/android/net/ip/IpClient.java
index b1f6d24..7c7cdbd 100644
--- a/packages/NetworkStack/src/android/net/ip/IpClient.java
+++ b/packages/NetworkStack/src/android/net/ip/IpClient.java
@@ -18,8 +18,6 @@
 
 import static android.net.RouteInfo.RTN_UNICAST;
 import static android.net.shared.IpConfigurationParcelableUtil.toStableParcelable;
-import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
-import static android.net.shared.LinkPropertiesParcelableUtil.toStableParcelable;
 
 import static com.android.server.util.PermissionUtil.checkNetworkStackCallingPermission;
 
@@ -33,7 +31,6 @@
 import android.net.LinkProperties;
 import android.net.ProvisioningConfigurationParcelable;
 import android.net.ProxyInfo;
-import android.net.ProxyInfoParcelable;
 import android.net.RouteInfo;
 import android.net.TcpKeepalivePacketDataParcelable;
 import android.net.apf.ApfCapabilities;
@@ -201,7 +198,7 @@
         public void onProvisioningSuccess(LinkProperties newLp) {
             log("onProvisioningSuccess({" + newLp + "})");
             try {
-                mCallback.onProvisioningSuccess(toStableParcelable(newLp));
+                mCallback.onProvisioningSuccess(newLp);
             } catch (RemoteException e) {
                 log("Failed to call onProvisioningSuccess", e);
             }
@@ -210,7 +207,7 @@
         public void onProvisioningFailure(LinkProperties newLp) {
             log("onProvisioningFailure({" + newLp + "})");
             try {
-                mCallback.onProvisioningFailure(toStableParcelable(newLp));
+                mCallback.onProvisioningFailure(newLp);
             } catch (RemoteException e) {
                 log("Failed to call onProvisioningFailure", e);
             }
@@ -219,7 +216,7 @@
         public void onLinkPropertiesChange(LinkProperties newLp) {
             log("onLinkPropertiesChange({" + newLp + "})");
             try {
-                mCallback.onLinkPropertiesChange(toStableParcelable(newLp));
+                mCallback.onLinkPropertiesChange(newLp);
             } catch (RemoteException e) {
                 log("Failed to call onLinkPropertiesChange", e);
             }
@@ -525,9 +522,9 @@
             IpClient.this.setTcpBufferSizes(tcpBufferSizes);
         }
         @Override
-        public void setHttpProxy(ProxyInfoParcelable proxyInfo) {
+        public void setHttpProxy(ProxyInfo proxyInfo) {
             checkNetworkStackCallingPermission();
-            IpClient.this.setHttpProxy(fromStableParcelable(proxyInfo));
+            IpClient.this.setHttpProxy(proxyInfo);
         }
         @Override
         public void setMulticastFilter(boolean enabled) {
diff --git a/packages/NetworkStack/src/com/android/server/NetworkStackService.java b/packages/NetworkStack/src/com/android/server/NetworkStackService.java
index 72955bb..e7c8e85 100644
--- a/packages/NetworkStack/src/com/android/server/NetworkStackService.java
+++ b/packages/NetworkStack/src/com/android/server/NetworkStackService.java
@@ -19,7 +19,6 @@
 import static android.net.dhcp.IDhcpServer.STATUS_INVALID_ARGUMENT;
 import static android.net.dhcp.IDhcpServer.STATUS_SUCCESS;
 import static android.net.dhcp.IDhcpServer.STATUS_UNKNOWN_ERROR;
-import static android.net.shared.NetworkParcelableUtil.fromStableParcelable;
 
 import static com.android.server.util.PermissionUtil.checkDumpPermission;
 import static com.android.server.util.PermissionUtil.checkNetworkStackCallingPermission;
@@ -35,7 +34,6 @@
 import android.net.INetworkMonitorCallbacks;
 import android.net.INetworkStackConnector;
 import android.net.Network;
-import android.net.NetworkParcelable;
 import android.net.PrivateDnsConfigParcel;
 import android.net.dhcp.DhcpServer;
 import android.net.dhcp.DhcpServingParams;
@@ -152,12 +150,10 @@
         }
 
         @Override
-        public void makeNetworkMonitor(
-                NetworkParcelable network, String name, INetworkMonitorCallbacks cb)
+        public void makeNetworkMonitor(Network network, String name, INetworkMonitorCallbacks cb)
                 throws RemoteException {
-            final Network parsedNetwork = fromStableParcelable(network);
-            final SharedLog log = addValidationLogs(parsedNetwork, name);
-            final NetworkMonitor nm = new NetworkMonitor(mContext, cb, parsedNetwork, log);
+            final SharedLog log = addValidationLogs(network, name);
+            final NetworkMonitor nm = new NetworkMonitor(mContext, cb, network, log);
             cb.onNetworkMonitorCreated(new NetworkMonitorImpl(nm));
         }
 
diff --git a/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java b/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
index fc56da7..bcfc412 100644
--- a/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
+++ b/packages/NetworkStack/src/com/android/server/connectivity/NetworkMonitor.java
@@ -1617,7 +1617,7 @@
             // See if the data sub is registered for PS services on cell.
             final NetworkRegistrationState nrs = dataSs.getNetworkRegistrationState(
                     NetworkRegistrationState.DOMAIN_PS,
-                    AccessNetworkConstants.TransportType.WWAN);
+                    AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
             latencyBroadcast.putExtra(
                     NetworkMonitorUtils.EXTRA_CELL_ID,
                     nrs == null ? null : nrs.getCellIdentity());
diff --git a/packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java b/packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java
index bd488ea..4536c47 100644
--- a/packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java
+++ b/packages/NetworkStack/tests/src/android/net/ip/IpClientTest.java
@@ -16,13 +16,10 @@
 
 package android.net.ip;
 
-import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
-
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.anyString;
 import static org.mockito.Mockito.eq;
@@ -207,8 +204,7 @@
         verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false);
         verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(iface);
         verify(mCb, timeout(TEST_TIMEOUT_MS).times(1))
-                .onLinkPropertiesChange(argThat(
-                        lp -> fromStableParcelable(lp).equals(makeEmptyLinkProperties(iface))));
+                .onLinkPropertiesChange(makeEmptyLinkProperties(iface));
     }
 
     @Test
@@ -253,15 +249,13 @@
         mObserver.onInterfaceAddressUpdated(new LinkAddress(addresses[lastAddr]), iface);
         LinkProperties want = linkproperties(links(addresses), routes(prefixes));
         want.setInterfaceName(iface);
-        verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningSuccess(argThat(
-                lp -> fromStableParcelable(lp).equals(want)));
+        verify(mCb, timeout(TEST_TIMEOUT_MS).times(1)).onProvisioningSuccess(want);
 
         ipc.shutdown();
         verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceSetEnableIPv6(iface, false);
         verify(mNetd, timeout(TEST_TIMEOUT_MS).times(1)).interfaceClearAddrs(iface);
         verify(mCb, timeout(TEST_TIMEOUT_MS).times(1))
-                .onLinkPropertiesChange(argThat(
-                        lp -> fromStableParcelable(lp).equals(makeEmptyLinkProperties(iface))));
+                .onLinkPropertiesChange(makeEmptyLinkProperties(iface));
     }
 
     @Test
diff --git a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
index c8c05a0..b34f445 100644
--- a/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
+++ b/packages/SettingsLib/src/com/android/settingslib/fuelgauge/BatterySaverUtils.java
@@ -103,7 +103,7 @@
             setBatterySaverConfirmationAcknowledged(context);
         }
 
-        if (context.getSystemService(PowerManager.class).setPowerSaveMode(enable)) {
+        if (context.getSystemService(PowerManager.class).setPowerSaveModeEnabled(enable)) {
             if (enable) {
                 final int count =
                         Secure.getInt(cr, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, 0) + 1;
diff --git a/packages/SettingsLib/src/com/android/settingslib/utils/StringUtil.java b/packages/SettingsLib/src/com/android/settingslib/utils/StringUtil.java
index 3e3c039..83ef4f9 100644
--- a/packages/SettingsLib/src/com/android/settingslib/utils/StringUtil.java
+++ b/packages/SettingsLib/src/com/android/settingslib/utils/StringUtil.java
@@ -107,20 +107,22 @@
     }
 
     /**
-     * Returns relative time for the given millis in the past, in a short format such as "2 days
-     * ago", "5 hr. ago", "40 min. ago", or "29 sec. ago".
+     * Returns relative time for the given millis in the past with different format style.
+     * In a short format such as "2 days ago", "5 hr. ago", "40 min. ago", or "29 sec. ago".
+     * In a long format such as "2 days ago", "5 hours ago",  "40 minutes ago" or "29 seconds ago".
      *
      * <p>The unit is chosen to have good information value while only using one unit. So 27 hours
      * and 50 minutes would be formatted as "28 hr. ago", while 50 hours would be formatted as
      * "2 days ago".
      *
-     * @param context the application context
-     * @param millis the elapsed time in milli seconds
+     * @param context     the application context
+     * @param millis      the elapsed time in milli seconds
      * @param withSeconds include seconds?
+     * @param formatStyle format style
      * @return the formatted elapsed time
      */
     public static CharSequence formatRelativeTime(Context context, double millis,
-            boolean withSeconds) {
+            boolean withSeconds, RelativeDateTimeFormatter.Style formatStyle) {
         final int seconds = (int) Math.floor(millis / 1000);
         final RelativeUnit unit;
         final int value;
@@ -144,9 +146,31 @@
         final RelativeDateTimeFormatter formatter = RelativeDateTimeFormatter.getInstance(
                 ULocale.forLocale(locale),
                 null /* default NumberFormat */,
-                RelativeDateTimeFormatter.Style.LONG,
+                formatStyle,
                 android.icu.text.DisplayContext.CAPITALIZATION_FOR_MIDDLE_OF_SENTENCE);
 
         return formatter.format(value, RelativeDateTimeFormatter.Direction.LAST, unit);
     }
+
+    /**
+     * Returns relative time for the given millis in the past, in a long format such as "2 days
+     * ago", "5 hours ago",  "40 minutes ago" or "29 seconds ago".
+     *
+     * <p>The unit is chosen to have good information value while only using one unit. So 27 hours
+     * and 50 minutes would be formatted as "28 hr. ago", while 50 hours would be formatted as
+     * "2 days ago".
+     *
+     * @param context     the application context
+     * @param millis      the elapsed time in milli seconds
+     * @param withSeconds include seconds?
+     * @return the formatted elapsed time
+     * @deprecated use {@link #formatRelativeTime(Context, double, boolean,
+     * RelativeDateTimeFormatter.Style)} instead.
+     */
+    @Deprecated
+    public static CharSequence formatRelativeTime(Context context, double millis,
+            boolean withSeconds) {
+        return formatRelativeTime(context, millis, withSeconds,
+                RelativeDateTimeFormatter.Style.LONG);
+    }
 }
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/fuelgauge/BatterySaverUtilsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/fuelgauge/BatterySaverUtilsTest.java
index 2988905..2bb3c2a 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/fuelgauge/BatterySaverUtilsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/fuelgauge/BatterySaverUtilsTest.java
@@ -60,7 +60,7 @@
 
         when(mMockContext.getContentResolver()).thenReturn(mMockResolver);
         when(mMockContext.getSystemService(eq(PowerManager.class))).thenReturn(mMockPowerManager);
-        when(mMockPowerManager.setPowerSaveMode(anyBoolean())).thenReturn(true);
+        when(mMockPowerManager.setPowerSaveModeEnabled(anyBoolean())).thenReturn(true);
     }
 
     @Test
@@ -71,7 +71,7 @@
         assertThat(BatterySaverUtils.setPowerSaveMode(mMockContext, true, true)).isFalse();
 
         verify(mMockContext, times(1)).sendBroadcast(any(Intent.class));
-        verify(mMockPowerManager, times(0)).setPowerSaveMode(anyBoolean());
+        verify(mMockPowerManager, times(0)).setPowerSaveModeEnabled(anyBoolean());
 
         // They shouldn't have changed.
         assertEquals(-1,
@@ -88,7 +88,7 @@
         assertThat(BatterySaverUtils.setPowerSaveMode(mMockContext, true, true)).isTrue();
 
         verify(mMockContext, times(0)).sendBroadcast(any(Intent.class));
-        verify(mMockPowerManager, times(1)).setPowerSaveMode(eq(true));
+        verify(mMockPowerManager, times(1)).setPowerSaveModeEnabled(eq(true));
 
         assertEquals(1, Secure.getInt(mMockResolver, Secure.LOW_POWER_WARNING_ACKNOWLEDGED, -1));
         assertEquals(1, Secure.getInt(mMockResolver, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, -2));
@@ -102,7 +102,7 @@
         assertThat(BatterySaverUtils.setPowerSaveMode(mMockContext, true, true)).isTrue();
 
         verify(mMockContext, times(0)).sendBroadcast(any(Intent.class));
-        verify(mMockPowerManager, times(1)).setPowerSaveMode(eq(true));
+        verify(mMockPowerManager, times(1)).setPowerSaveModeEnabled(eq(true));
 
         assertEquals(1, Secure.getInt(mMockResolver, Secure.LOW_POWER_WARNING_ACKNOWLEDGED, -1));
         assertEquals(2, Secure.getInt(mMockResolver, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, -2));
@@ -116,7 +116,7 @@
         assertThat(BatterySaverUtils.setPowerSaveMode(mMockContext, true, false)).isTrue();
 
         verify(mMockContext, times(0)).sendBroadcast(any(Intent.class));
-        verify(mMockPowerManager, times(1)).setPowerSaveMode(eq(true));
+        verify(mMockPowerManager, times(1)).setPowerSaveModeEnabled(eq(true));
 
         assertEquals(1, Secure.getInt(mMockResolver, Secure.LOW_POWER_WARNING_ACKNOWLEDGED, -1));
         assertEquals(1, Secure.getInt(mMockResolver, Secure.LOW_POWER_MANUAL_ACTIVATION_COUNT, -2));
@@ -131,7 +131,7 @@
         assertThat(BatterySaverUtils.setPowerSaveMode(mMockContext, false, false)).isTrue();
 
         verify(mMockContext, times(0)).sendBroadcast(any(Intent.class));
-        verify(mMockPowerManager, times(1)).setPowerSaveMode(eq(false));
+        verify(mMockPowerManager, times(1)).setPowerSaveModeEnabled(eq(false));
 
         assertEquals(-1, Secure.getInt(mMockResolver, Secure.LOW_POWER_WARNING_ACKNOWLEDGED, -1));
         assertEquals(-2,
@@ -147,7 +147,7 @@
         assertThat(BatterySaverUtils.setPowerSaveMode(mMockContext, false, true)).isTrue();
 
         verify(mMockContext, times(0)).sendBroadcast(any(Intent.class));
-        verify(mMockPowerManager, times(1)).setPowerSaveMode(eq(false));
+        verify(mMockPowerManager, times(1)).setPowerSaveModeEnabled(eq(false));
 
         assertEquals(-1, Secure.getInt(mMockResolver, Secure.LOW_POWER_WARNING_ACKNOWLEDGED, -1));
         assertEquals(-2,
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/StringUtilTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/StringUtilTest.java
index 8fbbfbb..b503972 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/StringUtilTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/utils/StringUtilTest.java
@@ -21,6 +21,7 @@
 import static org.mockito.Mockito.spy;
 
 import android.content.Context;
+import android.icu.text.RelativeDateTimeFormatter;
 import android.text.SpannableStringBuilder;
 import android.text.format.DateUtils;
 import android.text.style.TtsSpan;
@@ -116,8 +117,8 @@
         final double testMillis = 40 * DateUtils.SECOND_IN_MILLIS;
         final String expectedTime = "Just now";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -125,8 +126,8 @@
         final double testMillis = 40 * DateUtils.SECOND_IN_MILLIS;
         final String expectedTime = "1 minute ago";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, false).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, false,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -134,8 +135,8 @@
         final double testMillis = 119 * DateUtils.SECOND_IN_MILLIS;
         final String expectedTime = "Just now";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -143,8 +144,8 @@
         final double testMillis = 119 * DateUtils.SECOND_IN_MILLIS;
         final String expectedTime = "2 minutes ago";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, false).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, false,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -152,8 +153,8 @@
         final double testMillis = 2 * DateUtils.MINUTE_IN_MILLIS;
         final String expectedTime = "2 minutes ago";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -161,8 +162,8 @@
         final double testMillis = 119 * DateUtils.MINUTE_IN_MILLIS;
         final String expectedTime = "119 minutes ago";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -170,8 +171,8 @@
         final double testMillis = 2 * DateUtils.HOUR_IN_MILLIS;
         final String expectedTime = "2 hours ago";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -179,8 +180,8 @@
         final double testMillis = 47 * DateUtils.HOUR_IN_MILLIS;
         final String expectedTime = "47 hours ago";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -188,8 +189,8 @@
         final double testMillis = 2 * DateUtils.DAY_IN_MILLIS;
         final String expectedTime = "2 days ago";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -197,8 +198,8 @@
         final double testMillis = 0;
         final String expectedTime = "Just now";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, true,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 
     @Test
@@ -206,7 +207,7 @@
         final double testMillis = 0;
         final String expectedTime = "0 minutes ago";
 
-        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, false).toString()).isEqualTo(
-                expectedTime);
+        assertThat(StringUtil.formatRelativeTime(mContext, testMillis, false,
+                RelativeDateTimeFormatter.Style.LONG).toString()).isEqualTo(expectedTime);
     }
 }
diff --git a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
index 2c2987c..ff25ad9 100644
--- a/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
+++ b/packages/SettingsProvider/src/com/android/providers/settings/SettingsProvider.java
@@ -1103,9 +1103,7 @@
 
     private boolean mutateConfigSetting(String name, String value, String prefix,
             boolean makeDefault, int operation, int mode) {
-
-        // TODO(b/117663715): Ensure the caller can access the setting.
-        // enforceReadPermission(WRITE_DEVICE_CONFIG);
+        enforceWritePermission(Manifest.permission.WRITE_DEVICE_CONFIG);
 
         // Perform the mutation.
         synchronized (mLock) {
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityOptionsCompat.java b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityOptionsCompat.java
index ea6fb48..7b39ba3 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityOptionsCompat.java
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityOptionsCompat.java
@@ -78,4 +78,12 @@
                     }
                 });
     }
+
+    /**
+     * Sets the flag to freeze the recents task list reordering as a part of launching the activity.
+     */
+    public static ActivityOptions setFreezeRecentTasksList(ActivityOptions opts) {
+        opts.setFreezeRecentTasksReordering();
+        return opts;
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
index aa972e3..8e77851 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSAnimator.java
@@ -127,12 +127,12 @@
     @Override
     public void onTuningChanged(String key, String newValue) {
         if (ALLOW_FANCY_ANIMATION.equals(key)) {
-            mAllowFancy = newValue == null || Integer.parseInt(newValue) != 0;
+            mAllowFancy = TunerService.parseIntegerSwitch(newValue, true);
             if (!mAllowFancy) {
                 clearAnimationState();
             }
         } else if (MOVE_FULL_ROWS.equals(key)) {
-            mFullRows = newValue == null || Integer.parseInt(newValue) != 0;
+            mFullRows = TunerService.parseIntegerSwitch(newValue, true);
         } else if (QuickQSPanel.NUM_QUICK_TILES.equals(key)) {
             mNumQuickTiles = mQuickQsPanel.getNumQuickTiles(mQs.getContext());
             clearAnimationState();
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index 3c3dfb1..b93f8d04 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -183,7 +183,7 @@
     }
 
     private void updateViewVisibilityForTuningValue(View view, @Nullable String newValue) {
-        view.setVisibility(newValue == null || Integer.parseInt(newValue) != 0 ? VISIBLE : GONE);
+        view.setVisibility(TunerService.parseIntegerSwitch(newValue, true) ? VISIBLE : GONE);
     }
 
     public void openDetails(String subPanel) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java
index 4299af7..c2c3f81 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/Clock.java
@@ -288,7 +288,7 @@
     @Override
     public void onTuningChanged(String key, String newValue) {
         if (CLOCK_SECONDS.equals(key)) {
-            mShowSeconds = newValue != null && Integer.parseInt(newValue) != 0;
+            mShowSeconds = TunerService.parseIntegerSwitch(newValue, false);
             updateShowSeconds();
         } else {
             setClockVisibleByUser(!StatusBarIconController.getIconBlacklist(newValue)
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
index 3bccdab..338e178 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerService.java
@@ -107,4 +107,12 @@
         });
         dialog.show();
     }
+
+    public static boolean parseIntegerSwitch(String value, boolean defaultValue) {
+        try {
+            return value != null ? Integer.parseInt(value) != 0 : defaultValue;
+        } catch (NumberFormatException e) {
+            return defaultValue;
+        }
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java b/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java
index 2df9000..52b58d4 100644
--- a/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java
+++ b/packages/SystemUI/src/com/android/systemui/tuner/TunerSwitch.java
@@ -39,7 +39,7 @@
 
     @Override
     public void onTuningChanged(String key, String newValue) {
-        setChecked(newValue != null ? Integer.parseInt(newValue) != 0 : mDefault);
+        setChecked(TunerService.parseIntegerSwitch(newValue, mDefault));
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java
index 0805677..d2f185a 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java
+++ b/packages/SystemUI/src/com/android/systemui/volume/VolumeDialogComponent.java
@@ -101,28 +101,23 @@
 
     @Override
     public void onTuningChanged(String key, String newValue) {
+        boolean volumeDownToEnterSilent = mVolumePolicy.volumeDownToEnterSilent;
+        boolean volumeUpToExitSilent = mVolumePolicy.volumeUpToExitSilent;
+        boolean doNotDisturbWhenSilent = mVolumePolicy.doNotDisturbWhenSilent;
+
         if (VOLUME_DOWN_SILENT.equals(key)) {
-            final boolean volumeDownToEnterSilent = newValue != null
-                    ? Integer.parseInt(newValue) != 0
-                    : DEFAULT_VOLUME_DOWN_TO_ENTER_SILENT;
-            setVolumePolicy(volumeDownToEnterSilent,
-                    mVolumePolicy.volumeUpToExitSilent, mVolumePolicy.doNotDisturbWhenSilent,
-                    mVolumePolicy.vibrateToSilentDebounce);
+            volumeDownToEnterSilent =
+                TunerService.parseIntegerSwitch(newValue, DEFAULT_VOLUME_DOWN_TO_ENTER_SILENT);
         } else if (VOLUME_UP_SILENT.equals(key)) {
-            final boolean volumeUpToExitSilent = newValue != null
-                    ? Integer.parseInt(newValue) != 0
-                    : DEFAULT_VOLUME_UP_TO_EXIT_SILENT;
-            setVolumePolicy(mVolumePolicy.volumeDownToEnterSilent,
-                    volumeUpToExitSilent, mVolumePolicy.doNotDisturbWhenSilent,
-                    mVolumePolicy.vibrateToSilentDebounce);
+            volumeUpToExitSilent =
+                TunerService.parseIntegerSwitch(newValue, DEFAULT_VOLUME_UP_TO_EXIT_SILENT);
         } else if (VOLUME_SILENT_DO_NOT_DISTURB.equals(key)) {
-            final boolean doNotDisturbWhenSilent = newValue != null
-                    ? Integer.parseInt(newValue) != 0
-                    : DEFAULT_DO_NOT_DISTURB_WHEN_SILENT;
-            setVolumePolicy(mVolumePolicy.volumeDownToEnterSilent,
-                    mVolumePolicy.volumeUpToExitSilent, doNotDisturbWhenSilent,
-                    mVolumePolicy.vibrateToSilentDebounce);
+            doNotDisturbWhenSilent =
+                TunerService.parseIntegerSwitch(newValue, DEFAULT_DO_NOT_DISTURB_WHEN_SILENT);
         }
+
+        setVolumePolicy(volumeDownToEnterSilent, volumeUpToExitSilent, doNotDisturbWhenSilent,
+                mVolumePolicy.vibrateToSilentDebounce);
     }
 
     private void setVolumePolicy(boolean volumeDownToEnterSilent, boolean volumeUpToExitSilent,
diff --git a/services/autofill/java/com/android/server/autofill/Helper.java b/services/autofill/java/com/android/server/autofill/Helper.java
index b715637..3d392c7 100644
--- a/services/autofill/java/com/android/server/autofill/Helper.java
+++ b/services/autofill/java/com/android/server/autofill/Helper.java
@@ -211,8 +211,8 @@
      * Gets the {@link AutofillId} of the autofillable nodes in the {@code structure}.
      */
     @NonNull
-    static ArrayList<AutofillId> getAutofillableIds(@NonNull AssistStructure structure) {
-        final ArrayList<AutofillId> ids = new ArrayList<>();
+    static ArraySet<AutofillId> getAutofillableIds(@NonNull AssistStructure structure) {
+        final ArraySet<AutofillId> ids = new ArraySet<>();
         final int size = structure.getWindowNodeCount();
         for (int i = 0; i < size; i++) {
             final WindowNode node = structure.getWindowNodeAt(i);
@@ -222,7 +222,7 @@
     }
 
     private static void addAutofillableIds(@NonNull ViewNode node,
-            @NonNull ArrayList<AutofillId> ids) {
+            @NonNull ArraySet<AutofillId> ids) {
         if (node.getAutofillType() != View.AUTOFILL_TYPE_NONE) {
             ids.add(node.getAutofillId());
         }
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 8793341..ea47033 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -26,6 +26,7 @@
 import static android.view.autofill.AutofillManager.ACTION_VIEW_EXITED;
 import static android.view.autofill.AutofillManager.FLAG_SMART_SUGGESTION_SYSTEM;
 import static android.view.autofill.AutofillManager.getSmartSuggestionModeToString;
+import static android.view.autofill.Helper.toList;
 
 import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;
 import static com.android.server.autofill.Helper.getNumericValue;
@@ -266,6 +267,15 @@
     @GuardedBy("mLock")
     private ArrayList<LogMaker> mAugmentedRequestsLogs;
 
+
+    /**
+     * List of autofill ids of autofillable fields present in the AssistStructure that can be used
+     * to trigger new augmented autofill requests (because the "standard" service was not interested
+     * on autofilling the app.
+     */
+    @GuardedBy("mLock")
+    private ArraySet<AutofillId> mAugmentedAutofillableIds;
+
     /**
      * Receiver of assist data from the app's {@link Activity}.
      */
@@ -2327,12 +2337,28 @@
                     return;
                 }
 
+                if (mAugmentedAutofillableIds != null && mAugmentedAutofillableIds.contains(id)) {
+                    // View was already reported when server could not handle a response, but it
+                    // triggered augmented autofill
+
+                    if (sDebug) Slog.d(TAG, "updateLocked(" + id + "): augmented-autofillable");
+
+                    // Update the view states first...
+                    mCurrentViewId = viewState.id;
+                    viewState.setCurrentValue(value);
+
+                    // ...then trigger the augmented autofill UI
+                    triggerAugmentedAutofillLocked();
+                    return;
+                }
+
                 requestNewFillResponseOnViewEnteredIfNecessaryLocked(id, viewState, flags);
 
                 // Remove the UI if the ViewState has changed.
                 if (!Objects.equals(mCurrentViewId, viewState.id)) {
                     mUi.hideFillUi(this);
                     mCurrentViewId = viewState.id;
+                    hideAugmentedAutofillLocked(viewState);
                 }
 
                 // If the ViewState is ready to be displayed, onReady() will be called.
@@ -2340,8 +2366,9 @@
                 break;
             case ACTION_VIEW_EXITED:
                 if (Objects.equals(mCurrentViewId, viewState.id)) {
-                    if (sVerbose) Slog.d(TAG, "Exiting view " + id);
+                    if (sVerbose) Slog.v(TAG, "Exiting view " + id);
                     mUi.hideFillUi(this);
+                    hideAugmentedAutofillLocked(viewState);
                     mCurrentViewId = null;
                 }
                 break;
@@ -2350,6 +2377,15 @@
         }
     }
 
+    @GuardedBy("mLock")
+    private void hideAugmentedAutofillLocked(@NonNull ViewState viewState) {
+        if ((viewState.getState()
+                & ViewState.STATE_TRIGGERED_AUGMENTED_AUTOFILL) != 0) {
+            viewState.resetState(ViewState.STATE_TRIGGERED_AUGMENTED_AUTOFILL);
+            cancelAugmentedAutofillLocked();
+        }
+    }
+
     /**
      * Checks whether a view should be ignored.
      */
@@ -2430,14 +2466,14 @@
     }
 
     private void notifyUnavailableToClient(int sessionFinishedState,
-            @Nullable ArrayList<AutofillId> autofillableIds) {
+            @Nullable ArraySet<AutofillId> autofillableIds) {
         synchronized (mLock) {
             if (mCurrentViewId == null) return;
             try {
                 if (mHasCallback) {
                     mClient.notifyNoFillUi(id, mCurrentViewId, sessionFinishedState);
                 } else if (sessionFinishedState != 0) {
-                    mClient.setSessionFinished(sessionFinishedState, autofillableIds);
+                    mClient.setSessionFinished(sessionFinishedState, toList(autofillableIds));
                 }
             } catch (RemoteException e) {
                 Slog.e(TAG, "Error notifying client no fill UI: id=" + mCurrentViewId, e);
@@ -2560,7 +2596,7 @@
 
         final FillContext context = getFillContextByRequestIdLocked(requestId);
 
-        final ArrayList<AutofillId> autofillableIds;
+        final ArraySet<AutofillId> autofillableIds;
         if (context != null) {
             final AssistStructure structure = context.getStructure();
             autofillableIds = Helper.getAutofillableIds(structure);
@@ -2583,16 +2619,12 @@
             notifyUnavailableToClient(AutofillManager.STATE_FINISHED, autofillableIds);
             removeSelf();
         } else {
-            // TODO(b/123099468, b/119638958): must set internal state so when user focus other
-            // fields it does not generate a new call to the standard autofill service (right now
-            // it does). In other words, must also pass the autofillableIds - we'll be handled in
-            // a separate change (with new CTS tests to exercise this scenario).
-
             if (sVerbose) {
                 Slog.v(TAG, "keeping session " + id + " when server returned null but "
                         + "there is an AugmentedAutofill for user. AutofillableIds: "
                         + autofillableIds);
             }
+            mAugmentedAutofillableIds = autofillableIds;
         }
     }
 
@@ -2660,7 +2692,9 @@
             return null;
         }
 
-        final AutofillValue currentValue = mViewStates.get(mCurrentViewId).getCurrentValue();
+        final ViewState viewState = mViewStates.get(mCurrentViewId);
+        viewState.setState(ViewState.STATE_TRIGGERED_AUGMENTED_AUTOFILL);
+        final AutofillValue currentValue = viewState.getCurrentValue();
 
         // TODO(b/111330312): we might need to add a new state in the AutofillManager to optimize
         // further AFM -> AFMS calls.
@@ -2682,6 +2716,18 @@
     }
 
     @GuardedBy("mLock")
+    private void cancelAugmentedAutofillLocked() {
+        final RemoteAugmentedAutofillService remoteService = mService
+                .getRemoteAugmentedAutofillServiceLocked();
+        if (remoteService == null) {
+            Slog.w(TAG, "cancelAugmentedAutofillLocked(): no service for user");
+            return;
+        }
+        if (sVerbose) Slog.v(TAG, "cancelAugmentedAutofillLocked() on " + mCurrentViewId);
+        remoteService.onDestroyAutofillWindowsRequest();
+    }
+
+    @GuardedBy("mLock")
     private void processResponseLocked(@NonNull FillResponse newResponse,
             @Nullable Bundle newClientState, int flags) {
         // Make sure we are hiding the UI which will be shown
@@ -2967,6 +3013,10 @@
             pw.println(mAugmentedRequestsLogs.size());
         }
 
+        if (mAugmentedAutofillableIds != null) {
+            pw.print(prefix); pw.print("mAugmentedAutofillableIds: ");
+            pw.println(mAugmentedAutofillableIds);
+        }
         mRemoteFillService.dump(prefix, pw);
     }
 
diff --git a/services/autofill/java/com/android/server/autofill/ViewState.java b/services/autofill/java/com/android/server/autofill/ViewState.java
index 2cc6d20..33a2e50 100644
--- a/services/autofill/java/com/android/server/autofill/ViewState.java
+++ b/services/autofill/java/com/android/server/autofill/ViewState.java
@@ -17,6 +17,7 @@
 package com.android.server.autofill;
 
 import static android.service.autofill.FillRequest.FLAG_MANUAL_REQUEST;
+
 import static com.android.server.autofill.Helper.sDebug;
 
 import android.annotation.NonNull;
@@ -47,8 +48,6 @@
 
     private static final String TAG = "ViewState";
 
-    // NOTE: state constants must be public because of flagstoString().
-    public static final int STATE_UNKNOWN = 0x000;
     /** Initial state. */
     public static final int STATE_INITIAL = 0x001;
     /** View id is present in a dataset returned by the service. */
@@ -73,6 +72,8 @@
     public static final int STATE_AUTOFILL_FAILED = 0x400;
     /** View has been autofilled at least once. */
     public static final int STATE_AUTOFILLED_ONCE = 0x800;
+    /** View triggered the latest augmented autofill request. */
+    public static final int STATE_TRIGGERED_AUGMENTED_AUTOFILL = 0x1000;
 
     public final AutofillId id;
 
diff --git a/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java b/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
index 836a5e8..56eacc0 100644
--- a/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
+++ b/services/backup/java/com/android/server/backup/restore/FullRestoreEngine.java
@@ -41,6 +41,7 @@
 import android.text.TextUtils;
 import android.util.Slog;
 
+import com.android.internal.annotations.GuardedBy;
 import com.android.internal.util.Preconditions;
 import com.android.server.LocalServices;
 import com.android.server.backup.BackupAgentTimeoutParameters;
@@ -120,6 +121,7 @@
 
     // Pipes for moving data
     private ParcelFileDescriptor[] mPipes = null;
+    private final Object mPipesLock = new Object();
 
     // Widget blob to be restored out-of-band
     private byte[] mWidgetData = null;
@@ -129,6 +131,8 @@
 
     private final BackupAgentTimeoutParameters mAgentTimeoutParameters;
     final boolean mIsAdbRestore;
+    @GuardedBy("mPipesLock")
+    private boolean mPipesClosed;
 
     public FullRestoreEngine(UserBackupManagerService backupManagerService,
             BackupRestoreTask monitorTask, IFullBackupRestoreObserver observer,
@@ -578,24 +582,26 @@
     }
 
     private void setUpPipes() throws IOException {
-        mPipes = ParcelFileDescriptor.createPipe();
+        synchronized (mPipesLock) {
+            mPipes = ParcelFileDescriptor.createPipe();
+            mPipesClosed = false;
+        }
     }
 
     private void tearDownPipes() {
         // Teardown might arise from the inline restore processing or from the asynchronous
         // timeout mechanism, and these might race.  Make sure we don't try to close and
         // null out the pipes twice.
-        synchronized (this) {
-            if (mPipes != null) {
+        synchronized (mPipesLock) {
+            if (!mPipesClosed && mPipes != null) {
                 try {
                     mPipes[0].close();
-                    mPipes[0] = null;
                     mPipes[1].close();
-                    mPipes[1] = null;
+
+                    mPipesClosed = true;
                 } catch (IOException e) {
                     Slog.w(TAG, "Couldn't close agent pipes", e);
                 }
-                mPipes = null;
             }
         }
     }
diff --git a/services/contentsuggestions/java/com/android/server/contentsuggestions/ContentSuggestionsManagerService.java b/services/contentsuggestions/java/com/android/server/contentsuggestions/ContentSuggestionsManagerService.java
index 69b4672..55a0621 100644
--- a/services/contentsuggestions/java/com/android/server/contentsuggestions/ContentSuggestionsManagerService.java
+++ b/services/contentsuggestions/java/com/android/server/contentsuggestions/ContentSuggestionsManagerService.java
@@ -35,6 +35,7 @@
 import android.os.UserManager;
 import android.util.Slog;
 
+import com.android.internal.os.IResultReceiver;
 import com.android.server.LocalServices;
 import com.android.server.infra.AbstractMasterSystemService;
 import com.android.server.infra.FrameworkResourcesServiceNameResolver;
@@ -114,13 +115,14 @@
 
     private class ContentSuggestionsManagerStub extends IContentSuggestionsManager.Stub {
         @Override
-        public void provideContextImage(int taskId, @NonNull Bundle imageContextRequestExtras) {
+        public void provideContextImage(
+                int userId,
+                int taskId,
+                @NonNull Bundle imageContextRequestExtras) {
             if (imageContextRequestExtras == null) {
                 throw new IllegalArgumentException("Expected non-null imageContextRequestExtras");
             }
-
-            final int userId = UserHandle.getCallingUserId();
-            enforceCallerIsRecents(userId, "provideContextImage");
+            enforceCallerIsRecents(UserHandle.getCallingUserId(), "provideContextImage");
 
             synchronized (mLock) {
                 final ContentSuggestionsPerUserService service = getServiceForUserLocked(userId);
@@ -136,10 +138,10 @@
 
         @Override
         public void suggestContentSelections(
+                int userId,
                 @NonNull SelectionsRequest selectionsRequest,
                 @NonNull ISelectionsCallback selectionsCallback) {
-            final int userId = UserHandle.getCallingUserId();
-            enforceCallerIsRecents(userId, "suggestContentSelections");
+            enforceCallerIsRecents(UserHandle.getCallingUserId(), "suggestContentSelections");
 
             synchronized (mLock) {
                 final ContentSuggestionsPerUserService service = getServiceForUserLocked(userId);
@@ -155,10 +157,10 @@
 
         @Override
         public void classifyContentSelections(
+                int userId,
                 @NonNull ClassificationsRequest classificationsRequest,
                 @NonNull IClassificationsCallback callback) {
-            final int userId = UserHandle.getCallingUserId();
-            enforceCallerIsRecents(userId, "classifyContentSelections");
+            enforceCallerIsRecents(UserHandle.getCallingUserId(), "classifyContentSelections");
 
             synchronized (mLock) {
                 final ContentSuggestionsPerUserService service = getServiceForUserLocked(userId);
@@ -173,9 +175,9 @@
         }
 
         @Override
-        public void notifyInteraction(@NonNull String requestId, @NonNull Bundle bundle) {
-            final int userId = UserHandle.getCallingUserId();
-            enforceCallerIsRecents(userId, "notifyInteraction");
+        public void notifyInteraction(
+                int userId, @NonNull String requestId, @NonNull Bundle bundle) {
+            enforceCallerIsRecents(UserHandle.getCallingUserId(), "notifyInteraction");
 
             synchronized (mLock) {
                 final ContentSuggestionsPerUserService service = getServiceForUserLocked(userId);
@@ -189,6 +191,18 @@
             }
         }
 
+        @Override
+        public void isEnabled(int userId, @NonNull IResultReceiver receiver)
+                throws RemoteException {
+            enforceCallerIsRecents(UserHandle.getCallingUserId(), "isEnabled");
+
+            boolean isDisabled;
+            synchronized (mLock) {
+                isDisabled = isDisabledLocked(userId);
+            }
+            receiver.send(isDisabled ? 0 : 1, null);
+        }
+
         public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out,
                 @Nullable FileDescriptor err,
                 @NonNull String[] args, @Nullable ShellCallback callback,
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 343cee1..b2ee686 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -41,7 +41,6 @@
 import static android.net.NetworkPolicyManager.RULE_NONE;
 import static android.net.NetworkPolicyManager.uidRulesToString;
 import static android.net.shared.NetworkMonitorUtils.isValidationRequired;
-import static android.net.shared.NetworkParcelableUtil.toStableParcelable;
 import static android.os.Process.INVALID_UID;
 import static android.system.OsConstants.IPPROTO_TCP;
 import static android.system.OsConstants.IPPROTO_UDP;
@@ -5390,7 +5389,7 @@
         final long token = Binder.clearCallingIdentity();
         try {
             getNetworkStack().makeNetworkMonitor(
-                    toStableParcelable(nai.network), name, new NetworkMonitorCallbacks(nai));
+                    nai.network, name, new NetworkMonitorCallbacks(nai));
         } finally {
             Binder.restoreCallingIdentity(token);
         }
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 178a55b..7c6049c 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -2934,8 +2934,8 @@
                         taskRoot);
             }
         }
-        if (mContentCaptureService != null
-                && (event == Event.ACTIVITY_PAUSED || event == Event.ACTIVITY_RESUMED)) {
+        if (mContentCaptureService != null && (event == Event.ACTIVITY_PAUSED
+                || event == Event.ACTIVITY_RESUMED || event == Event.ACTIVITY_STOPPED)) {
             mContentCaptureService.notifyActivityEvent(userId, activity, event);
         }
     }
diff --git a/services/core/java/com/android/server/am/AppCompactor.java b/services/core/java/com/android/server/am/AppCompactor.java
index 1f21160..438538f 100644
--- a/services/core/java/com/android/server/am/AppCompactor.java
+++ b/services/core/java/com/android/server/am/AppCompactor.java
@@ -211,7 +211,7 @@
         mPendingCompactionProcesses.add(app);
         mCompactionHandler.sendMessage(
             mCompactionHandler.obtainMessage(
-                COMPACT_PROCESS_MSG, app.curAdj, app.setProcState));
+                COMPACT_PROCESS_MSG, app.setAdj, app.setProcState));
     }
 
     @GuardedBy("mAm")
@@ -220,7 +220,7 @@
         mPendingCompactionProcesses.add(app);
         mCompactionHandler.sendMessage(
             mCompactionHandler.obtainMessage(
-                COMPACT_PROCESS_MSG, app.curAdj, app.setProcState));
+                COMPACT_PROCESS_MSG, app.setAdj, app.setProcState));
 
     }
 
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 435fa88..68f76ab 100644
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -5953,6 +5953,14 @@
         pw.print("  mVolumePolicy="); pw.println(mVolumePolicy);
         pw.print("  mAvrcpAbsVolSupported=");
         pw.println(mDeviceBroker.isAvrcpAbsoluteVolumeSupported());
+        pw.print("  mIsSingleVolume="); pw.println(mIsSingleVolume);
+        pw.print("  mUseFixedVolume="); pw.println(mUseFixedVolume);
+        pw.print("  mFixedVolumeDevices=0x"); pw.println(Integer.toHexString(mFixedVolumeDevices));
+        pw.print("  mHdmiCecSink="); pw.println(mHdmiCecSink);
+        pw.print("  mHdmiAudioSystemClient="); pw.println(mHdmiAudioSystemClient);
+        pw.print("  mHdmiPlaybackClient="); pw.println(mHdmiPlaybackClient);
+        pw.print("  mHdmiTvClient="); pw.println(mHdmiTvClient);
+        pw.print("  mHdmiSystemAudioSupported="); pw.println(mHdmiSystemAudioSupported);
 
         dumpAudioPolicies(pw);
         mDynPolicyLogger.dump(pw);
diff --git a/services/core/java/com/android/server/audio/MediaFocusControl.java b/services/core/java/com/android/server/audio/MediaFocusControl.java
index b4bbbc7..d028e88 100644
--- a/services/core/java/com/android/server/audio/MediaFocusControl.java
+++ b/services/core/java/com/android/server/audio/MediaFocusControl.java
@@ -543,16 +543,17 @@
     }
 
     /**
-     * Called synchronized on mAudioFocusLock
+     * Called synchronized on mAudioFocusLock.
+     * Can only be called with an external focus policy installed (mFocusPolicy != null)
      * @param afi
-     * @param requestResult
-     * @return true if the external audio focus policy (if any) is handling the focus request
+     * @param fd
+     * @param cb binder of the focus requester
+     * @return true if the external audio focus policy (if any) can handle the focus request,
+     *     and false if there was any error handling the request (e.g. error talking to policy,
+     *     focus requester is already dead)
      */
     boolean notifyExtFocusPolicyFocusRequest_syncAf(AudioFocusInfo afi,
-            IAudioFocusDispatcher fd, IBinder cb) {
-        if (mFocusPolicy == null) {
-            return false;
-        }
+            IAudioFocusDispatcher fd, @NonNull IBinder cb) {
         if (DEBUG) {
             Log.v(TAG, "notifyExtFocusPolicyFocusRequest client="+afi.getClientId()
             + " dispatcher=" + fd);
@@ -561,19 +562,28 @@
             afi.setGen(mExtFocusChangeCounter++);
         }
         final FocusRequester existingFr = mFocusOwnersForFocusPolicy.get(afi.getClientId());
+        boolean keepTrack = false;
         if (existingFr != null) {
             if (!existingFr.hasSameDispatcher(fd)) {
                 existingFr.release();
-                final AudioFocusDeathHandler hdlr = new AudioFocusDeathHandler(cb);
-                mFocusOwnersForFocusPolicy.put(afi.getClientId(),
-                        new FocusRequester(afi, fd, cb, hdlr, this));
+                keepTrack = true;
             }
         } else {
-            // new focus (future) focus owner to keep track of
+            keepTrack = true;
+        }
+        if (keepTrack) {
             final AudioFocusDeathHandler hdlr = new AudioFocusDeathHandler(cb);
+            try {
+                cb.linkToDeath(hdlr, 0);
+            } catch (RemoteException e) {
+                // client has already died!
+                return false;
+            }
+            // new focus (future) focus owner to keep track of
             mFocusOwnersForFocusPolicy.put(afi.getClientId(),
                     new FocusRequester(afi, fd, cb, hdlr, this));
         }
+
         try {
             //oneway
             mFocusPolicy.notifyAudioFocusRequest(afi, AudioManager.AUDIOFOCUS_REQUEST_GRANTED);
@@ -600,7 +610,6 @@
     /**
      * Called synchronized on mAudioFocusLock
      * @param afi
-     * @param requestResult
      * @return true if the external audio focus policy (if any) is handling the focus request
      */
     boolean notifyExtFocusPolicyFocusAbandon_syncAf(AudioFocusInfo afi) {
@@ -767,10 +776,15 @@
             }
 
             // external focus policy?
-            if (notifyExtFocusPolicyFocusRequest_syncAf(
-                    afiForExtPolicy, fd, cb)) {
-                // stop handling focus request here as it is handled by external audio focus policy
-                return AudioManager.AUDIOFOCUS_REQUEST_WAITING_FOR_EXT_POLICY;
+            if (mFocusPolicy != null) {
+                if (notifyExtFocusPolicyFocusRequest_syncAf(afiForExtPolicy, fd, cb)) {
+                    // stop handling focus request here as it is handled by external audio
+                    // focus policy (return code will be handled in AudioManager)
+                    return AudioManager.AUDIOFOCUS_REQUEST_WAITING_FOR_EXT_POLICY;
+                } else {
+                    // an error occured, client already dead, bail early
+                    return AudioManager.AUDIOFOCUS_REQUEST_FAILED;
+                }
             }
 
             // handle the potential premature death of the new holder of the focus
diff --git a/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java b/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java
index 053da0d..828a1e5 100644
--- a/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java
+++ b/services/core/java/com/android/server/connectivity/NetworkNotificationManager.java
@@ -28,6 +28,7 @@
 import android.content.res.Resources;
 import android.net.wifi.WifiInfo;
 import android.os.UserHandle;
+import android.telephony.AccessNetworkConstants.TransportType;
 import android.telephony.TelephonyManager;
 import android.text.TextUtils;
 import android.util.Slog;
@@ -92,7 +93,7 @@
         return -1;
     }
 
-    private static String getTransportName(int transportType) {
+    private static String getTransportName(@TransportType int transportType) {
         Resources r = Resources.getSystem();
         String[] networkTypes = r.getStringArray(R.array.network_switch_type_name);
         try {
diff --git a/services/core/java/com/android/server/locksettings/LockSettingsStorage.java b/services/core/java/com/android/server/locksettings/LockSettingsStorage.java
index 98f1740..2ede384 100644
--- a/services/core/java/com/android/server/locksettings/LockSettingsStorage.java
+++ b/services/core/java/com/android/server/locksettings/LockSettingsStorage.java
@@ -29,7 +29,6 @@
 import android.os.Environment;
 import android.os.UserHandle;
 import android.os.UserManager;
-import android.os.storage.StorageManager;
 import android.util.ArrayMap;
 import android.util.Log;
 import android.util.Slog;
@@ -49,6 +48,7 @@
 import java.io.IOException;
 import java.io.RandomAccessFile;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 
@@ -808,7 +808,7 @@
         }
 
         byte[] peekFile(String fileName) {
-            return (byte[]) peek(CacheKey.TYPE_FILE, fileName, -1 /* userId */);
+            return copyOf((byte[]) peek(CacheKey.TYPE_FILE, fileName, -1 /* userId */));
         }
 
         boolean hasFile(String fileName) {
@@ -816,11 +816,11 @@
         }
 
         void putFile(String key, byte[] value) {
-            put(CacheKey.TYPE_FILE, key, value, -1 /* userId */);
+            put(CacheKey.TYPE_FILE, key, copyOf(value), -1 /* userId */);
         }
 
         void putFileIfUnchanged(String key, byte[] value, int version) {
-            putIfUnchanged(CacheKey.TYPE_FILE, key, value, -1 /* userId */, version);
+            putIfUnchanged(CacheKey.TYPE_FILE, key, copyOf(value), -1 /* userId */, version);
         }
 
         void setFetched(int userId) {
@@ -868,6 +868,10 @@
             mVersion++;
         }
 
+        private byte[] copyOf(byte[] data) {
+            return data != null ? Arrays.copyOf(data, data.length) : null;
+        }
+
         synchronized void purgePath(String path) {
             for (int i = mCache.size() - 1; i >= 0; i--) {
                 CacheKey entry = mCache.keyAt(i);
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java
index 152cf7f..192ad6d 100644
--- a/services/core/java/com/android/server/media/MediaSessionRecord.java
+++ b/services/core/java/com/android/server/media/MediaSessionRecord.java
@@ -24,10 +24,11 @@
 import android.media.AudioManagerInternal;
 import android.media.AudioSystem;
 import android.media.MediaMetadata;
+import android.media.MediaParceledListSlice;
 import android.media.Rating;
 import android.media.VolumeProvider;
 import android.media.session.ControllerCallbackLink;
-import android.media.session.ControllerLink;
+import android.media.session.ISessionController;
 import android.media.session.MediaController;
 import android.media.session.MediaController.PlaybackInfo;
 import android.media.session.MediaSession;
@@ -78,7 +79,7 @@
     private final String mPackageName;
     private final String mTag;
     private final Bundle mSessionInfo;
-    private final ControllerLink mController;
+    private final ControllerStub mController;
     private final MediaSession.Token mSessionToken;
     private final SessionLink mSession;
     private final SessionCb mSessionCb;
@@ -130,7 +131,7 @@
         mPackageName = ownerPackageName;
         mTag = tag;
         mSessionInfo = sessionInfo;
-        mController = new ControllerLink(new ControllerStub());
+        mController = new ControllerStub();
         mSessionToken = new MediaSession.Token(mController);
         mSession = new SessionLink(new SessionStub());
         mSessionCb = new SessionCb(cb);
@@ -152,11 +153,11 @@
     }
 
     /**
-     * Get the controller link for the {@link MediaController}.
+     * Get the controller binder for the {@link MediaController}.
      *
-     * @return The controller link apps talk to.
+     * @return The controller binder apps talk to.
      */
-    public ControllerLink getControllerLink() {
+    public ISessionController getControllerBinder() {
         return mController;
     }
 
@@ -835,7 +836,7 @@
         }
 
         @Override
-        public ControllerLink getController() {
+        public ISessionController getController() {
             return mController;
         }
 
@@ -1248,7 +1249,7 @@
         }
     }
 
-    class ControllerStub extends ControllerLink.ControllerStub {
+    class ControllerStub extends ISessionController.Stub {
         @Override
         public void sendCommand(String packageName, ControllerCallbackLink caller,
                 String command, Bundle args, ResultReceiver cb) {
@@ -1488,9 +1489,9 @@
         }
 
         @Override
-        public List<QueueItem> getQueue() {
+        public MediaParceledListSlice getQueue() {
             synchronized (mLock) {
-                return mQueue;
+                return mQueue == null ? null : new MediaParceledListSlice<>(mQueue);
             }
         }
 
diff --git a/services/core/java/com/android/server/media/MediaSessionStack.java b/services/core/java/com/android/server/media/MediaSessionStack.java
index 9ba50ee..a5e7d8e 100644
--- a/services/core/java/com/android/server/media/MediaSessionStack.java
+++ b/services/core/java/com/android/server/media/MediaSessionStack.java
@@ -144,7 +144,7 @@
      */
     public MediaSessionRecord getMediaSessionRecord(MediaSession.Token sessionToken) {
         for (MediaSessionRecord record : mSessions) {
-            if (Objects.equals(record.getControllerLink(), sessionToken.getControllerLink())) {
+            if (Objects.equals(record.getControllerBinder(), sessionToken.getBinder())) {
                 return record;
             }
         }
diff --git a/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java b/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java
index 64f31cd..5c0874d 100644
--- a/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java
+++ b/services/core/java/com/android/server/os/BugreportManagerServiceImpl.java
@@ -40,10 +40,6 @@
 
 import java.io.FileDescriptor;
 
-// TODO(b/111441001):
-// Intercept onFinished() & implement death recipient here and shutdown
-// bugreportd service.
-
 /**
  * Implementation of the service that provides a privileged API to capture and consume bugreports.
  *
@@ -171,9 +167,12 @@
             reportError(listener, IDumpstateListener.BUGREPORT_ERROR_RUNTIME_ERROR);
             return;
         }
+
+        // Wrap the listener so we can intercept binder events directly.
+        IDumpstateListener myListener = new DumpstateListener(listener, ds);
         try {
             ds.startBugreport(callingUid, callingPackage,
-                    bugreportFd, screenshotFd, bugreportMode, listener);
+                    bugreportFd, screenshotFd, bugreportMode, myListener);
         } catch (RemoteException e) {
             reportError(listener, IDumpstateListener.BUGREPORT_ERROR_RUNTIME_ERROR);
         }
@@ -240,4 +239,73 @@
         Slog.w(TAG, message);
         throw new IllegalArgumentException(message);
     }
+
+
+    private final class DumpstateListener extends IDumpstateListener.Stub
+            implements DeathRecipient {
+        private final IDumpstateListener mListener;
+        private final IDumpstate mDs;
+        private boolean mDone = false;
+
+        DumpstateListener(IDumpstateListener listener, IDumpstate ds) {
+            mListener = listener;
+            mDs = ds;
+            try {
+                mDs.asBinder().linkToDeath(this, 0);
+            } catch (RemoteException e) {
+                Slog.e(TAG, "Unable to register Death Recipient for IDumpstate", e);
+            }
+        }
+
+        @Override
+        public void onProgress(int progress) throws RemoteException {
+            mListener.onProgress(progress);
+        }
+
+        @Override
+        public void onError(int errorCode) throws RemoteException {
+            synchronized (mLock) {
+                mDone = true;
+            }
+            mListener.onError(errorCode);
+        }
+
+        @Override
+        public void onFinished() throws RemoteException {
+            synchronized (mLock) {
+                mDone = true;
+            }
+            mListener.onFinished();
+        }
+
+        @Override
+        public void binderDied() {
+            synchronized (mLock) {
+                if (!mDone) {
+                    // If we have not gotten a "done" callback this must be a crash.
+                    Slog.e(TAG, "IDumpstate likely crashed. Notifying listener");
+                    try {
+                        mListener.onError(IDumpstateListener.BUGREPORT_ERROR_RUNTIME_ERROR);
+                    } catch (RemoteException ignored) {
+                        // If listener is not around, there isn't anything to do here.
+                    }
+                }
+            }
+            mDs.asBinder().unlinkToDeath(this, 0);
+        }
+
+        // Old methods; unused in the API flow.
+        @Override
+        public void onProgressUpdated(int progress) throws RemoteException {
+        }
+
+        @Override
+        public void onMaxProgressUpdated(int maxProgress) throws RemoteException {
+        }
+
+        @Override
+        public void onSectionComplete(String title, int status, int size, int durationMs)
+                throws RemoteException {
+        }
+    }
 }
diff --git a/services/core/java/com/android/server/pm/LauncherAppsService.java b/services/core/java/com/android/server/pm/LauncherAppsService.java
index 05af13a..7f057f0 100644
--- a/services/core/java/com/android/server/pm/LauncherAppsService.java
+++ b/services/core/java/com/android/server/pm/LauncherAppsService.java
@@ -432,7 +432,7 @@
                     }
                     ApplicationInfo appInfo = pmInt.getApplicationInfo(packageName, /*flags*/ 0,
                             callingUid, user.getIdentifier());
-                    if (shouldShowHiddenApp(user, appInfo)) {
+                    if (shouldShowSyntheticActivity(user, appInfo)) {
                         ResolveInfo info = getHiddenAppActivityInfo(packageName, callingUid, user);
                         if (info != null) {
                             result.add(info);
@@ -448,7 +448,7 @@
                         user.getIdentifier(), callingUid);
                 for (ApplicationInfo applicationInfo : installedPackages) {
                     if (!visiblePackages.contains(applicationInfo.packageName)) {
-                        if (!shouldShowHiddenApp(user, applicationInfo)) {
+                        if (!shouldShowSyntheticActivity(user, applicationInfo)) {
                             continue;
                         }
                         ResolveInfo info = getHiddenAppActivityInfo(applicationInfo.packageName,
@@ -464,7 +464,7 @@
             }
         }
 
-        private boolean shouldShowHiddenApp(UserHandle user, ApplicationInfo appInfo) {
+        private boolean shouldShowSyntheticActivity(UserHandle user, ApplicationInfo appInfo) {
             if (appInfo == null || appInfo.isSystemApp() || appInfo.isUpdatedSystemApp()) {
                 return false;
             }
diff --git a/services/core/java/com/android/server/pm/PackageInstallerService.java b/services/core/java/com/android/server/pm/PackageInstallerService.java
index d249b97..181b7a2 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerService.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerService.java
@@ -27,6 +27,7 @@
 import android.app.NotificationManager;
 import android.app.PackageDeleteObserver;
 import android.app.PackageInstallObserver;
+import android.app.admin.DevicePolicyEventLogger;
 import android.app.admin.DevicePolicyManagerInternal;
 import android.content.Context;
 import android.content.Intent;
@@ -59,6 +60,7 @@
 import android.os.SELinux;
 import android.os.UserManager;
 import android.os.storage.StorageManager;
+import android.stats.devicepolicy.DevicePolicyEnums;
 import android.system.ErrnoException;
 import android.system.Os;
 import android.text.TextUtils;
@@ -810,6 +812,10 @@
             } finally {
                 Binder.restoreCallingIdentity(ident);
             }
+            DevicePolicyEventLogger
+                    .createEvent(DevicePolicyEnums.UNINSTALL_PACKAGE)
+                    .setAdmin(callerPackageName)
+                    .write();
         } else {
             ApplicationInfo appInfo = mPm.getApplicationInfo(callerPackageName, 0, userId);
             if (appInfo.targetSdkVersion >= Build.VERSION_CODES.P) {
diff --git a/services/core/java/com/android/server/pm/PackageInstallerSession.java b/services/core/java/com/android/server/pm/PackageInstallerSession.java
index 81c0a97..6451b56 100644
--- a/services/core/java/com/android/server/pm/PackageInstallerSession.java
+++ b/services/core/java/com/android/server/pm/PackageInstallerSession.java
@@ -44,6 +44,7 @@
 import android.Manifest;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.app.admin.DevicePolicyEventLogger;
 import android.app.admin.DevicePolicyManagerInternal;
 import android.content.Context;
 import android.content.IIntentReceiver;
@@ -82,6 +83,7 @@
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.os.storage.StorageManager;
+import android.stats.devicepolicy.DevicePolicyEnums;
 import android.system.ErrnoException;
 import android.system.Int64Ref;
 import android.system.Os;
@@ -993,6 +995,19 @@
 
         mSealed = true;
 
+        if (params.isStaged) {
+            final PackageInstallerSession activeSession = mStagingManager.getActiveSession();
+            final boolean anotherSessionAlreadyInProgress =
+                    activeSession != null && sessionId != activeSession.sessionId
+                            && mParentSessionId != activeSession.sessionId;
+            if (anotherSessionAlreadyInProgress) {
+                throw new PackageManagerException(
+                        PackageManager.INSTALL_FAILED_OTHER_STAGED_SESSION_IN_PROGRESS,
+                        "There is already in-progress committed staged session "
+                                + activeSession.sessionId, null);
+            }
+        }
+
         // Read transfers from the original owner stay open, but as the session's data
         // cannot be modified anymore, there is no leak of information. For staged sessions,
         // further validation is performed by the staging manager.
@@ -1072,14 +1087,14 @@
     }
 
     private void handleCommit() {
+        if (isInstallerDeviceOwnerOrAffiliatedProfileOwnerLocked()) {
+            DevicePolicyEventLogger
+                    .createEvent(DevicePolicyEnums.INSTALL_PACKAGE)
+                    .setAdmin(mInstallerPackageName)
+                    .write();
+        }
         if (params.isStaged) {
-            try {
-                mStagingManager.commitSession(this);
-            } catch (StagingManager.AlreadyInProgressStagedSessionException e) {
-                dispatchSessionFinished(
-                        PackageManager.INSTALL_FAILED_OTHER_STAGED_SESSION_IN_PROGRESS,
-                        e.getMessage(), null);
-            }
+            mStagingManager.commitSession(this);
             destroyInternal();
             dispatchSessionFinished(PackageManager.INSTALL_SUCCEEDED, "Session staged", null);
             return;
diff --git a/services/core/java/com/android/server/pm/StagingManager.java b/services/core/java/com/android/server/pm/StagingManager.java
index fce9bb1..39c731c 100644
--- a/services/core/java/com/android/server/pm/StagingManager.java
+++ b/services/core/java/com/android/server/pm/StagingManager.java
@@ -477,23 +477,13 @@
         return true;
     }
 
-    void commitSession(@NonNull PackageInstallerSession session)
-            throws AlreadyInProgressStagedSessionException {
-        PackageInstallerSession activeSession = getActiveSession();
-        boolean anotherSessionAlreadyInProgress =
-                activeSession != null && session.sessionId != activeSession.sessionId;
+    void commitSession(@NonNull PackageInstallerSession session) {
         updateStoredSession(session);
-        if (anotherSessionAlreadyInProgress) {
-            session.setStagedSessionFailed(SessionInfo.STAGED_SESSION_VERIFICATION_FAILED,
-                    "There is already in-progress committed staged session "
-                            + activeSession.sessionId);
-            throw new AlreadyInProgressStagedSessionException(activeSession.sessionId);
-        }
         mBgHandler.post(() -> preRebootVerification(session));
     }
 
     @Nullable
-    private PackageInstallerSession getActiveSession() {
+    PackageInstallerSession getActiveSession() {
         synchronized (mStagedSessions) {
             for (int i = 0; i < mStagedSessions.size(); i++) {
                 final PackageInstallerSession session = mStagedSessions.valueAt(i);
@@ -651,12 +641,4 @@
             }
         }
     }
-
-    static final class AlreadyInProgressStagedSessionException extends Exception {
-
-        AlreadyInProgressStagedSessionException(int sessionId) {
-            super("There is already in-progress committed staged session "
-                    + sessionId);
-        }
-    }
 }
diff --git a/services/core/java/com/android/server/pm/TEST_MAPPING b/services/core/java/com/android/server/pm/TEST_MAPPING
index 24b38e7..15dc6ae 100644
--- a/services/core/java/com/android/server/pm/TEST_MAPPING
+++ b/services/core/java/com/android/server/pm/TEST_MAPPING
@@ -12,7 +12,7 @@
   ],
   "imports": [
     {
-      "path": "system/apex/tests"
+      "path": "frameworks/base/core/java/android/content/pm"
     }
   ]
 }
diff --git a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
index f97dd3b..e9077a9 100644
--- a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
+++ b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
@@ -704,6 +704,12 @@
                         TelephonyManager.ACTION_EMERGENCY_ASSISTANCE, userId),
                 userId, CONTACTS_PERMISSIONS, PHONE_PERMISSIONS);
 
+        // STOPSHIP(b/128289173): remove once EmergencyInfo app was replaced.
+        grantSystemFixedPermissionsToSystemPackage(
+                getDefaultSystemHandlerActivityPackage(
+                        "com.android.emergency.action.EMERGENCY_ASSISTANCE", userId),
+                userId, CONTACTS_PERMISSIONS, PHONE_PERMISSIONS);
+
         // NFC Tag viewer
         Intent nfcTagIntent = new Intent(Intent.ACTION_VIEW)
                 .setType("vnd.android.cursor.item/ndef_msg");
diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java
index bb23bc0..9b427f5 100644
--- a/services/core/java/com/android/server/power/PowerManagerService.java
+++ b/services/core/java/com/android/server/power/PowerManagerService.java
@@ -4474,7 +4474,7 @@
         }
 
         @Override // Binder call
-        public boolean setPowerSaveMode(boolean enabled) {
+        public boolean setPowerSaveModeEnabled(boolean enabled) {
             if (mContext.checkCallingOrSelfPermission(android.Manifest.permission.POWER_SAVER)
                     != PackageManager.PERMISSION_GRANTED) {
                 mContext.enforceCallingOrSelfPermission(
diff --git a/services/core/java/com/android/server/power/PowerManagerShellCommand.java b/services/core/java/com/android/server/power/PowerManagerShellCommand.java
index 18b8f0e..edaa6d9 100644
--- a/services/core/java/com/android/server/power/PowerManagerShellCommand.java
+++ b/services/core/java/com/android/server/power/PowerManagerShellCommand.java
@@ -68,7 +68,7 @@
             pw.println("Error: " + ex.toString());
             return -1;
         }
-        mInterface.setPowerSaveMode(mode == LOW_POWER_MODE_ON);
+        mInterface.setPowerSaveModeEnabled(mode == LOW_POWER_MODE_ON);
         return 0;
     }
 
diff --git a/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java b/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java
index af78995..af5d40bf 100644
--- a/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java
+++ b/services/core/java/com/android/server/power/batterysaver/BatterySaverStateMachine.java
@@ -524,7 +524,7 @@
 
     /**
      * {@link com.android.server.power.PowerManagerService} calls it when
-     * {@link android.os.PowerManager#setPowerSaveMode} is called.
+     * {@link android.os.PowerManager#setPowerSaveModeEnabled} is called.
      *
      * Note this could? be called before {@link #onBootCompleted} too.
      */
diff --git a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
index 9a5ec2a..d7c9bc7 100644
--- a/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/wm/ActivityStackSupervisor.java
@@ -2453,46 +2453,43 @@
                 mService.getTaskChangeNotificationController()
                         .notifyActivityLaunchOnSecondaryDisplayFailed(task.getTaskInfo(),
                                 preferredDisplayId);
-                return;
-            } else if (!forceNonResizable && handleForcedResizableTask(task,
-                    FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY)) {
-                return;
+            } else if (!forceNonResizable) {
+                handleForcedResizableTaskIfNeeded(task, FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY);
             }
+            // The information about not support secondary display should already be notified, we
+            // don't want to show another message on default display about split-screen. And it may
+            // be the case that a resizable activity is launched on a non-resizable task.
+            return;
         }
 
         if (!task.supportsSplitScreenWindowingMode() || forceNonResizable) {
-            // Display a warning toast that we tried to put an app that doesn't support split-screen
-            // in split-screen.
-            mService.getTaskChangeNotificationController().notifyActivityDismissingDockedStack();
-
             // Dismiss docked stack. If task appeared to be in docked stack but is not resizable -
             // we need to move it to top of fullscreen stack, otherwise it will be covered.
 
             final ActivityStack dockedStack =
                     task.getStack().getDisplay().getSplitScreenPrimaryStack();
             if (dockedStack != null) {
+                // Display a warning toast that we tried to put an app that doesn't support
+                // split-screen in split-screen.
+                mService.getTaskChangeNotificationController()
+                        .notifyActivityDismissingDockedStack();
                 moveTasksToFullscreenStackLocked(dockedStack, actualStack == dockedStack);
             }
             return;
         }
 
-        handleForcedResizableTask(task, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN);
+        handleForcedResizableTaskIfNeeded(task, FORCED_RESIZEABLE_REASON_SPLIT_SCREEN);
     }
 
-    /**
-     * @return {@code true} if the top activity of the task is forced to be resizable and the user
-     *         was notified about activity being forced resized.
-     */
-    private boolean handleForcedResizableTask(TaskRecord task, int reason) {
+    /** Notifies that the top activity of the task is forced to be resizeable. */
+    private void handleForcedResizableTaskIfNeeded(TaskRecord task, int reason) {
         final ActivityRecord topActivity = task.getTopActivity();
-        if (topActivity != null && topActivity.isNonResizableOrForcedResizable()
-                && !topActivity.noDisplay) {
-            final String packageName = topActivity.appInfo.packageName;
-            mService.getTaskChangeNotificationController().notifyActivityForcedResizable(
-                    task.taskId, reason, packageName);
-            return true;
+        if (topActivity == null || topActivity.noDisplay
+                || !topActivity.isNonResizableOrForcedResizable()) {
+            return;
         }
-        return false;
+        mService.getTaskChangeNotificationController().notifyActivityForcedResizable(
+                task.taskId, reason, topActivity.appInfo.packageName);
     }
 
     void activityRelaunchedLocked(IBinder token) {
@@ -2736,6 +2733,9 @@
         if (activityOptions != null) {
             activityType = activityOptions.getLaunchActivityType();
             windowingMode = activityOptions.getLaunchWindowingMode();
+            if (activityOptions.freezeRecentTasksReordering()) {
+                mRecentTasks.setFreezeTaskListReordering();
+            }
         }
         if (activityType == ACTIVITY_TYPE_HOME || activityType == ACTIVITY_TYPE_RECENTS) {
             throw new IllegalArgumentException("startActivityFromRecents: Task "
diff --git a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
index 794a4b8..a1dbbab 100644
--- a/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
+++ b/services/core/java/com/android/server/wm/ActivityTaskManagerService.java
@@ -748,6 +748,7 @@
             mWindowManager.setSupportsPictureInPicture(mSupportsPictureInPicture);
             mWindowManager.setSupportsFreeformWindowManagement(mSupportsFreeformWindowManagement);
             mWindowManager.setIsPc(isPc);
+            mWindowManager.mRoot.onSettingsRetrieved();
             // This happens before any activities are started, so we can change global configuration
             // in-place.
             updateConfigurationLocked(configuration, null, true);
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index 3357393..bcfbefe 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -41,12 +41,14 @@
 import static android.view.WindowManager.DOCKED_BOTTOM;
 import static android.view.WindowManager.DOCKED_INVALID;
 import static android.view.WindowManager.DOCKED_TOP;
+import static android.view.WindowManager.LayoutParams.FIRST_APPLICATION_WINDOW;
 import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
 import static android.view.WindowManager.LayoutParams.FLAG_SECURE;
 import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
 import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
+import static android.view.WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
 import static android.view.WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE;
 import static android.view.WindowManager.LayoutParams.NEEDS_MENU_UNSET;
 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
@@ -182,6 +184,8 @@
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.internal.util.ToBooleanFunction;
 import com.android.internal.util.function.TriConsumer;
+import com.android.internal.util.function.pooled.PooledConsumer;
+import com.android.internal.util.function.pooled.PooledLambda;
 import com.android.server.AnimationThread;
 import com.android.server.policy.WindowManagerPolicy;
 import com.android.server.wm.utils.DisplayRotationUtil;
@@ -887,6 +891,10 @@
         mTapDetector = new TaskTapPointerEventListener(mWmService, this);
         registerPointerEventListener(mTapDetector);
         registerPointerEventListener(mWmService.mMousePositionTracker);
+        if (mWmService.mAtmService.getRecentTasks() != null) {
+            registerPointerEventListener(
+                    mWmService.mAtmService.getRecentTasks().getInputListener());
+        }
 
         mDisplayPolicy = new DisplayPolicy(service, this);
         mDisplayRotation = new DisplayRotation(service, this);
@@ -2381,6 +2389,27 @@
     }
 
     /**
+     * Returns true if the input point is within an app window.
+     */
+    boolean pointWithinAppWindow(int x, int y) {
+        final int[] targetWindowType = {-1};
+        final Consumer fn = PooledLambda.obtainConsumer((w, nonArg) -> {
+            if (targetWindowType[0] != -1) {
+                return;
+            }
+
+            if (w.isOnScreen() && w.isVisibleLw() && w.getFrameLw().contains(x, y)) {
+                targetWindowType[0] = w.mAttrs.type;
+                return;
+            }
+        }, PooledLambda.__(WindowState.class), mTmpRect);
+        forAllWindows(fn, true /* traverseTopToBottom */);
+        ((PooledConsumer) fn).recycle();
+        return FIRST_APPLICATION_WINDOW <= targetWindowType[0]
+                        && targetWindowType[0] <= LAST_APPLICATION_WINDOW;
+    }
+
+    /**
      * Find the task whose outside touch area (for resizing) (x, y) falls within.
      * Returns null if the touch doesn't fall into a resizing area.
      */
diff --git a/services/core/java/com/android/server/wm/DisplayWindowSettings.java b/services/core/java/com/android/server/wm/DisplayWindowSettings.java
index 4617890..db96847 100644
--- a/services/core/java/com/android/server/wm/DisplayWindowSettings.java
+++ b/services/core/java/com/android/server/wm/DisplayWindowSettings.java
@@ -352,6 +352,24 @@
         dc.mDisplayScalingDisabled = entry.mForcedScalingMode == FORCE_SCALING_MODE_DISABLED;
     }
 
+    /**
+     * Updates settings for the given display after system features are loaded into window manager
+     * service, e.g. if this device is PC and if this device supports freeform.
+     *
+     * @param dc the given display.
+     * @return {@code true} if any settings for this display has changed; {@code false} if nothing
+     * changed.
+     */
+    boolean updateSettingsForDisplay(DisplayContent dc) {
+        if (dc.getWindowingMode() != getWindowingModeLocked(dc)) {
+            // For the time being the only thing that may change is windowing mode, so just update
+            // that.
+            dc.setWindowingMode(getWindowingModeLocked(dc));
+            return true;
+        }
+        return false;
+    }
+
     private void readSettings() {
         FileInputStream stream;
         try {
diff --git a/services/core/java/com/android/server/wm/DragDropController.java b/services/core/java/com/android/server/wm/DragDropController.java
index a667d67..716e4ef 100644
--- a/services/core/java/com/android/server/wm/DragDropController.java
+++ b/services/core/java/com/android/server/wm/DragDropController.java
@@ -73,17 +73,6 @@
         return mDragState != null && !mDragState.isClosing();
     }
 
-    void showInputSurface(SurfaceControl.Transaction t, int displayId) {
-        mDragState.showInputSurface(t, displayId);
-    }
-
-    void hideInputSurface(SurfaceControl.Transaction t, int displayId) {
-        if (mDragState != null) {
-            // TODO: Are we guaranteed to get here?
-            mDragState.hideInputSurface(t, displayId);
-        }
-    }
-
     void registerCallback(IDragDropCallback callback) {
         Preconditions.checkNotNull(callback);
         mCallback.set(callback);
diff --git a/services/core/java/com/android/server/wm/DragState.java b/services/core/java/com/android/server/wm/DragState.java
index 2b2231a..c438966 100644
--- a/services/core/java/com/android/server/wm/DragState.java
+++ b/services/core/java/com/android/server/wm/DragState.java
@@ -120,7 +120,7 @@
     // A surface used to catch input events for the drag-and-drop operation.
     SurfaceControl mInputSurface;
 
-    private final SurfaceControl.Transaction mTransaction = new SurfaceControl.Transaction();
+    private final SurfaceControl.Transaction mTransaction;
 
     private final Rect mTmpClipRect = new Rect();
 
@@ -140,31 +140,24 @@
         mFlags = flags;
         mLocalWin = localWin;
         mNotifiedWindows = new ArrayList<WindowState>();
-
+        mTransaction = service.mTransactionFactory.make();
     }
 
     boolean isClosing() {
         return mIsClosing;
     }
 
-    void hideInputSurface(SurfaceControl.Transaction t, int displayId) {
-        if (displayId != mDisplayContent.getDisplayId()) {
-            return;
-        }
-
+    private void hideInputSurface() {
         if (mInputSurface != null) {
-            t.hide(mInputSurface);
+            mTransaction.hide(mInputSurface).apply();
         }
     }
 
-    void showInputSurface(SurfaceControl.Transaction t, int displayId) {
-        if (displayId != mDisplayContent.getDisplayId()) {
-            return;
-        }
-
+    private void showInputSurface() {
         if (mInputSurface == null) {
-            mInputSurface = mService.makeSurfaceBuilder(mService.mRoot.getDisplayContent(displayId)
-                    .getSession()).setContainerLayer()
+            mInputSurface = mService.makeSurfaceBuilder(
+                    mService.mRoot.getDisplayContent(mDisplayContent.getDisplayId()).getSession())
+                    .setContainerLayer()
                     .setName("Drag and Drop Input Consumer").build();
         }
         final InputWindowHandle h = getInputWindowHandle();
@@ -174,14 +167,16 @@
             return;
         }
 
-        t.show(mInputSurface);
-        t.setInputWindowInfo(mInputSurface, h);
-        t.setLayer(mInputSurface, Integer.MAX_VALUE);
+        mTransaction.show(mInputSurface);
+        mTransaction.setInputWindowInfo(mInputSurface, h);
+        mTransaction.setLayer(mInputSurface, Integer.MAX_VALUE);
 
         mTmpClipRect.set(0, 0, mDisplaySize.x, mDisplaySize.y);
-        t.setWindowCrop(mInputSurface, mTmpClipRect);
-        t.transferTouchFocus(mTransferTouchFromToken, h.token);
+        mTransaction.setWindowCrop(mInputSurface, mTmpClipRect);
+        mTransaction.transferTouchFocus(mTransferTouchFromToken, h.token);
         mTransferTouchFromToken = null;
+
+        mTransaction.apply();
     }
 
     /**
@@ -199,9 +194,10 @@
             mDragDropController.sendHandlerMessage(
                     MSG_TEAR_DOWN_DRAG_AND_DROP_INPUT, mInputInterceptor);
             mInputInterceptor = null;
-            mDisplayContent.getInputMonitor().updateInputWindowsLw(true /*force*/);
         }
 
+        hideInputSurface();
+
         // Send drag end broadcast if drag start has been sent.
         if (mDragInProgress) {
             final int myPid = Process.myPid();
@@ -352,7 +348,7 @@
             Slog.e(TAG_WM, "Duplicate register of drag input channel");
         } else {
             mInputInterceptor = new InputInterceptor(display);
-            mDisplayContent.getInputMonitor().updateInputWindowsLw(true /*force*/);
+            showInputSurface();
         }
     }
 
diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java
index 2a9c2b0..5669451 100644
--- a/services/core/java/com/android/server/wm/InputMonitor.java
+++ b/services/core/java/com/android/server/wm/InputMonitor.java
@@ -25,7 +25,6 @@
 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_KEYGUARD;
 import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;
 
-import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_DRAG;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_FOCUS_LIGHT;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT;
 import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_TASK_POSITIONING;
@@ -129,15 +128,6 @@
 
                 // If there's a drag in flight, provide a pseudo-window to catch drag input
                 final boolean inDrag = mService.mDragDropController.dragDropActiveLocked();
-                if (inDrag) {
-                    if (DEBUG_DRAG) {
-                        Log.d(TAG_WM, "Inserting drag window");
-                    }
-                    mService.mDragDropController.showInputSurface(mInputTransaction, mDisplayId);
-                } else {
-                    mService.mDragDropController.hideInputSurface(mInputTransaction, mDisplayId);
-                }
-
                 final boolean inPositioning =
                         mService.mTaskPositioningController.isPositioningLocked();
                 if (inPositioning) {
diff --git a/services/core/java/com/android/server/wm/RecentTasks.java b/services/core/java/com/android/server/wm/RecentTasks.java
index 0480d43..d69ae3d 100644
--- a/services/core/java/com/android/server/wm/RecentTasks.java
+++ b/services/core/java/com/android/server/wm/RecentTasks.java
@@ -60,6 +60,7 @@
 import android.os.Environment;
 import android.os.IBinder;
 import android.os.RemoteException;
+import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.os.UserHandle;
 import android.text.TextUtils;
@@ -67,8 +68,11 @@
 import android.util.Slog;
 import android.util.SparseArray;
 import android.util.SparseBooleanArray;
+import android.view.MotionEvent;
+import android.view.WindowManagerPolicyConstants.PointerEventListener;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.util.function.pooled.PooledLambda;
 import com.android.server.am.ActivityManagerService;
 
 import com.google.android.collect.Sets;
@@ -109,8 +113,11 @@
 
     private static final int DEFAULT_INITIAL_CAPACITY = 5;
 
-    // Whether or not to move all affiliated tasks to the front when one of the tasks is launched
-    private static final boolean MOVE_AFFILIATED_TASKS_TO_FRONT = false;
+    // The duration of time after freezing the recent tasks list where getRecentTasks() will return
+    // a stable ordering of the tasks. Upon the next call to getRecentTasks() beyond this duration,
+    // the task list will be unfrozen and committed (the current top task will be moved to the
+    // front of the list)
+    private static final long FREEZE_TASK_LIST_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(5);
 
     // Comparator to sort by taskId
     private static final Comparator<TaskRecord> TASK_ID_COMPARATOR =
@@ -174,12 +181,45 @@
     private int mMaxNumVisibleTasks;
     private long mActiveTasksSessionDurationMs;
 
+    // When set, the task list will not be reordered as tasks within the list are moved to the
+    // front. Newly created tasks, or tasks that are removed from the list will continue to change
+    // the list.  This does not affect affiliated tasks.
+    private boolean mFreezeTaskListReordering;
+    private long mFreezeTaskListReorderingTime;
+    private long mFreezeTaskListTimeoutMs = FREEZE_TASK_LIST_TIMEOUT_MS;
+
     // Mainly to avoid object recreation on multiple calls.
     private final ArrayList<TaskRecord> mTmpRecents = new ArrayList<>();
     private final HashMap<ComponentName, ActivityInfo> mTmpAvailActCache = new HashMap<>();
     private final HashMap<String, ApplicationInfo> mTmpAvailAppCache = new HashMap<>();
     private final SparseBooleanArray mTmpQuietProfileUserIds = new SparseBooleanArray();
 
+    // TODO(b/127498985): This is currently a rough heuristic for interaction inside an app
+    private final PointerEventListener mListener = new PointerEventListener() {
+        @Override
+        public void onPointerEvent(MotionEvent ev) {
+            if (!mFreezeTaskListReordering || ev.getAction() != MotionEvent.ACTION_DOWN) {
+                // Skip if we aren't freezing or starting a gesture
+                return;
+            }
+            int displayId = ev.getDisplayId();
+            int x = (int) ev.getX();
+            int y = (int) ev.getY();
+            mService.mH.post(PooledLambda.obtainRunnable((nonArg) -> {
+                synchronized (mService.mGlobalLock) {
+                    // Unfreeze the task list once we touch down in a task
+                    final RootActivityContainer rac = mService.mRootActivityContainer;
+                    final DisplayContent dc = rac.getActivityDisplay(displayId).mDisplayContent;
+                    if (dc.pointWithinAppWindow(x, y)) {
+                        final ActivityStack stack = mService.getTopDisplayFocusedStack();
+                        final TaskRecord topTask = stack != null ? stack.topTask() : null;
+                        resetFreezeTaskListReordering(topTask);
+                    }
+                }
+            }, null).recycleOnUse());
+        }
+    };
+
     @VisibleForTesting
     RecentTasks(ActivityTaskManagerService service, TaskPersister taskPersister) {
         mService = service;
@@ -214,6 +254,73 @@
         mGlobalMaxNumTasks = globalMaxNumTasks;
     }
 
+    @VisibleForTesting
+    void setFreezeTaskListTimeoutParams(long reorderingTime, long timeoutMs) {
+        mFreezeTaskListReorderingTime = reorderingTime;
+        mFreezeTaskListTimeoutMs = timeoutMs;
+    }
+
+    PointerEventListener getInputListener() {
+        return mListener;
+    }
+
+    /**
+     * Freezes the current recent task list order until either a user interaction with the current
+     * app, or a timeout occurs.
+     */
+    void setFreezeTaskListReordering() {
+        // Always update the reordering time when this is called to ensure that the timeout
+        // is reset
+        mFreezeTaskListReordering = true;
+        mFreezeTaskListReorderingTime = SystemClock.elapsedRealtime();
+    }
+
+    /**
+     * Commits the frozen recent task list order, moving the provided {@param topTask} to the
+     * front of the list.
+     */
+    void resetFreezeTaskListReordering(TaskRecord topTask) {
+        if (!mFreezeTaskListReordering) {
+            return;
+        }
+
+        // Once we end freezing the task list, reset the existing task order to the stable state
+        mFreezeTaskListReordering = false;
+
+        // If the top task is provided, then restore the top task to the front of the list
+        if (topTask != null) {
+            mTasks.remove(topTask);
+            mTasks.add(0, topTask);
+        }
+
+        // Resume trimming tasks
+        trimInactiveRecentTasks();
+    }
+
+    /**
+     * Resets the frozen recent task list order if the timeout has passed. This should be called
+     * before we need to iterate the task list in order (either for purposes of returning the list
+     * to SystemUI or if we need to trim tasks in order)
+     */
+    void resetFreezeTaskListReorderingOnTimeout() {
+        // Unfreeze the recent task list if the time heuristic has passed
+        if (mFreezeTaskListReorderingTime
+                > (SystemClock.elapsedRealtime() - mFreezeTaskListTimeoutMs)) {
+            return;
+        }
+
+        final ActivityStack focusedStack = mService.getTopDisplayFocusedStack();
+        final TaskRecord topTask = focusedStack != null
+                ? focusedStack.topTask()
+                : null;
+        resetFreezeTaskListReordering(topTask);
+    }
+
+    @VisibleForTesting
+    boolean isFreezeTaskListReorderingSet() {
+        return mFreezeTaskListReordering;
+    }
+
     /**
      * Loads the parameters from the system resources.
      */
@@ -351,7 +458,8 @@
         }
 
         Slog.i(TAG, "Loading recents for user " + userId + " into memory.");
-        mTasks.addAll(mTaskPersister.restoreTasksForUserLocked(userId, preaddedTasks));
+        List<TaskRecord> tasks = mTaskPersister.restoreTasksForUserLocked(userId, preaddedTasks);
+        mTasks.addAll(tasks);
         cleanupLocked(userId);
         mUsersWithRecentsLoaded.put(userId, true);
 
@@ -746,11 +854,10 @@
                 getDetailedTasks, userId, callingUid));
     }
 
-
     /**
      * @return the list of recent tasks for presentation.
      */
-    ArrayList<ActivityManager.RecentTaskInfo> getRecentTasksImpl(int maxNum, int flags,
+    private ArrayList<ActivityManager.RecentTaskInfo> getRecentTasksImpl(int maxNum, int flags,
             boolean getTasksAllowed, boolean getDetailedTasks, int userId, int callingUid) {
         final boolean withExcluded = (flags & RECENT_WITH_EXCLUDED) != 0;
 
@@ -763,6 +870,9 @@
         final Set<Integer> includedUsers = getProfileIds(userId);
         includedUsers.add(Integer.valueOf(userId));
 
+        // Check if the frozen task list has timed out
+        resetFreezeTaskListReorderingOnTimeout();
+
         final ArrayList<ActivityManager.RecentTaskInfo> res = new ArrayList<>();
         final int size = mTasks.size();
         int numVisibleTasks = 0;
@@ -946,24 +1056,20 @@
         if (task.inRecents) {
             int taskIndex = mTasks.indexOf(task);
             if (taskIndex >= 0) {
-                if (!isAffiliated || !MOVE_AFFILIATED_TASKS_TO_FRONT) {
-                    // Simple case: this is not an affiliated task, so we just move it to the front.
-                    mTasks.remove(taskIndex);
-                    mTasks.add(0, task);
-                    notifyTaskPersisterLocked(task, false);
-                    if (DEBUG_RECENTS) Slog.d(TAG_RECENTS, "addRecent: moving to top " + task
-                            + " from " + taskIndex);
-                    return;
-                } else {
-                    // More complicated: need to keep all affiliated tasks together.
-                    if (moveAffiliatedTasksToFront(task, taskIndex)) {
-                        // All went well.
-                        return;
-                    }
+                if (!isAffiliated) {
+                    if (!mFreezeTaskListReordering) {
+                        // Simple case: this is not an affiliated task, so we just move it to the
+                        // front unless overridden by the provided activity options
+                        mTasks.remove(taskIndex);
+                        mTasks.add(0, task);
 
-                    // Uh oh...  something bad in the affiliation chain, try to rebuild
-                    // everything and then go through our general path of adding a new task.
-                    needAffiliationFix = true;
+                        if (DEBUG_RECENTS) {
+                            Slog.d(TAG_RECENTS, "addRecent: moving to top " + task
+                                    + " from " + taskIndex);
+                        }
+                    }
+                    notifyTaskPersisterLocked(task, false);
+                    return;
                 }
             } else {
                 Slog.wtf(TAG, "Task with inRecent not in recents: " + task);
@@ -1063,6 +1169,11 @@
      * Trims the recents task list to the global max number of recents.
      */
     private void trimInactiveRecentTasks() {
+        if (mFreezeTaskListReordering) {
+            // Defer trimming inactive recent tasks until we are unfrozen
+            return;
+        }
+
         int recentsCount = mTasks.size();
 
         // Remove from the end of the list until we reach the max number of recents
@@ -1086,7 +1197,7 @@
                     + " quiet=" + mTmpQuietProfileUserIds.get(userId));
         }
 
-        // Remove any inactive tasks, calculate the latest set of visible tasks
+        // Remove any inactive tasks, calculate the latest set of visible tasks.
         int numVisibleTasks = 0;
         for (int i = 0; i < mTasks.size();) {
             final TaskRecord task = mTasks.get(i);
@@ -1300,6 +1411,11 @@
      * list (if any).
      */
     private int findRemoveIndexForAddTask(TaskRecord task) {
+        if (mFreezeTaskListReordering) {
+            // Defer removing tasks due to the addition of new tasks until the task list is unfrozen
+            return -1;
+        }
+
         final int recentsCount = mTasks.size();
         final Intent intent = task.intent;
         final boolean document = intent != null && intent.isDocument();
@@ -1536,6 +1652,9 @@
         pw.println("ACTIVITY MANAGER RECENT TASKS (dumpsys activity recents)");
         pw.println("mRecentsUid=" + mRecentsUid);
         pw.println("mRecentsComponent=" + mRecentsComponent);
+        pw.println("mFreezeTaskListReordering=" + mFreezeTaskListReordering);
+        pw.println("mFreezeTaskListReorderingTime (time since)="
+                + (SystemClock.elapsedRealtime() - mFreezeTaskListReorderingTime) + "ms");
         if (mTasks.isEmpty()) {
             return;
         }
diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java
index db7613a..8f4e842 100644
--- a/services/core/java/com/android/server/wm/RootWindowContainer.java
+++ b/services/core/java/com/android/server/wm/RootWindowContainer.java
@@ -245,6 +245,34 @@
         return dc;
     }
 
+    /**
+     * Called when DisplayWindowSettings values may change.
+     */
+    void onSettingsRetrieved() {
+        final int numDisplays = mChildren.size();
+        for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
+            final DisplayContent displayContent = mChildren.get(displayNdx);
+            final boolean changed = mWmService.mDisplayWindowSettings.updateSettingsForDisplay(
+                    displayContent);
+            if (!changed) {
+                continue;
+            }
+
+            displayContent.initializeDisplayOverrideConfiguration();
+            mWmService.reconfigureDisplayLocked(displayContent);
+
+            // We need to update global configuration as well if config of default display has
+            // changed. Do it inline because ATMS#retrieveSettings() will soon update the
+            // configuration inline, which will overwrite the new windowing mode.
+            if (displayContent.isDefaultDisplay) {
+                final Configuration newConfig = mWmService.computeNewConfiguration(
+                        displayContent.getDisplayId());
+                mWmService.mAtmService.updateConfigurationLocked(newConfig, null /* starting */,
+                        false /* initLocale */);
+            }
+        }
+    }
+
     boolean isLayoutNeeded() {
         final int numDisplays = mChildren.size();
         for (int displayNdx = 0; displayNdx < numDisplays; ++displayNdx) {
diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
index 7c236e1..caba3af 100644
--- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
+++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
@@ -336,7 +336,7 @@
 template<>
 const char *const JavaMethodHelper<bool>::signature_ = "(Z)V";
 template<>
-const char *const JavaMethodHelper<jstring>::signature_ = "(Ljava/lang/String)V";
+const char *const JavaMethodHelper<jstring>::signature_ = "(Ljava/lang/String;)V";
 
 #define SET(setter, value) object.callSetter("set" # setter, (value))
 
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 3999edd..f6de82d 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -5912,10 +5912,13 @@
         delegateReceiver = resolveDelegateReceiver(DELEGATION_CERT_SELECTION,
                 DeviceAdminReceiver.ACTION_CHOOSE_PRIVATE_KEY_ALIAS, caller.getIdentifier());
 
+        final boolean isDelegate;
         if (delegateReceiver != null) {
             intent.setComponent(delegateReceiver);
+            isDelegate = true;
         } else {
             intent.setComponent(aliasChooser);
+            isDelegate = false;
         }
 
         final long id = mInjector.binderClearCallingIdentity();
@@ -5927,11 +5930,10 @@
                     sendPrivateKeyAliasResponse(chosenAlias, response);
                 }
             }, null, Activity.RESULT_OK, null, null);
-            final String adminPackageName =
-                    (aliasChooser != null ? aliasChooser.getPackageName() : null);
             DevicePolicyEventLogger
                     .createEvent(DevicePolicyEnums.CHOOSE_PRIVATE_KEY_ALIAS)
-                    .setAdmin(adminPackageName)
+                    .setAdmin(intent.getComponent())
+                    .setBoolean(isDelegate)
                     .write();
         } finally {
             mInjector.binderRestoreCallingIdentity(id);
@@ -13091,6 +13093,14 @@
             saveSettingsLocked(mInjector.userHandleGetCallingUserId());
 
             setNetworkLoggingActiveInternal(enabled);
+
+            final boolean isDelegate = (admin == null);
+            DevicePolicyEventLogger
+                    .createEvent(DevicePolicyEnums.SET_NETWORK_LOGGING_ENABLED)
+                    .setAdmin(packageName)
+                    .setBoolean(isDelegate)
+                    .setInt(enabled ? 1 : 0)
+                    .write();
         }
     }
 
@@ -13222,6 +13232,12 @@
                     || !isNetworkLoggingEnabledInternalLocked()) {
                 return null;
             }
+            final boolean isDelegate = (admin == null);
+            DevicePolicyEventLogger
+                    .createEvent(DevicePolicyEnums.RETRIEVE_NETWORK_LOGS)
+                    .setAdmin(packageName)
+                    .setBoolean(isDelegate)
+                    .write();
 
             final long currentTime = System.currentTimeMillis();
             DevicePolicyData policyData = getUserData(UserHandle.USER_SYSTEM);
diff --git a/services/net/java/android/net/NetworkStackClient.java b/services/net/java/android/net/NetworkStackClient.java
index fe447fc..cc09fe3 100644
--- a/services/net/java/android/net/NetworkStackClient.java
+++ b/services/net/java/android/net/NetworkStackClient.java
@@ -120,8 +120,7 @@
      *
      * <p>The INetworkMonitor will be returned asynchronously through the provided callbacks.
      */
-    public void makeNetworkMonitor(
-            NetworkParcelable network, String name, INetworkMonitorCallbacks cb) {
+    public void makeNetworkMonitor(Network network, String name, INetworkMonitorCallbacks cb) {
         requestConnector(connector -> {
             try {
                 connector.makeNetworkMonitor(network, name, cb);
diff --git a/services/net/java/android/net/ip/IpClientUtil.java b/services/net/java/android/net/ip/IpClientUtil.java
index bf917bf..90624e0 100644
--- a/services/net/java/android/net/ip/IpClientUtil.java
+++ b/services/net/java/android/net/ip/IpClientUtil.java
@@ -17,12 +17,10 @@
 package android.net.ip;
 
 import static android.net.shared.IpConfigurationParcelableUtil.fromStableParcelable;
-import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
 
 import android.content.Context;
 import android.net.DhcpResultsParcelable;
 import android.net.LinkProperties;
-import android.net.LinkPropertiesParcelable;
 import android.net.NetworkStackClient;
 import android.os.ConditionVariable;
 
@@ -122,18 +120,18 @@
         }
 
         @Override
-        public void onProvisioningSuccess(LinkPropertiesParcelable newLp) {
-            mCb.onProvisioningSuccess(fromStableParcelable(newLp));
+        public void onProvisioningSuccess(LinkProperties newLp) {
+            mCb.onProvisioningSuccess(newLp);
         }
         @Override
-        public void onProvisioningFailure(LinkPropertiesParcelable newLp) {
-            mCb.onProvisioningFailure(fromStableParcelable(newLp));
+        public void onProvisioningFailure(LinkProperties newLp) {
+            mCb.onProvisioningFailure(newLp);
         }
 
         // Invoked on LinkProperties changes.
         @Override
-        public void onLinkPropertiesChange(LinkPropertiesParcelable newLp) {
-            mCb.onLinkPropertiesChange(fromStableParcelable(newLp));
+        public void onLinkPropertiesChange(LinkProperties newLp) {
+            mCb.onLinkPropertiesChange(newLp);
         }
 
         // Called when the internal IpReachabilityMonitor (if enabled) has
diff --git a/services/net/java/android/net/shared/InitialConfiguration.java b/services/net/java/android/net/shared/InitialConfiguration.java
index 4ad7138..e423d62 100644
--- a/services/net/java/android/net/shared/InitialConfiguration.java
+++ b/services/net/java/android/net/shared/InitialConfiguration.java
@@ -23,13 +23,12 @@
 import android.net.InetAddresses;
 import android.net.InitialConfigurationParcelable;
 import android.net.IpPrefix;
-import android.net.IpPrefixParcelable;
 import android.net.LinkAddress;
-import android.net.LinkAddressParcelable;
 import android.net.RouteInfo;
 
 import java.net.Inet4Address;
 import java.net.InetAddress;
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -148,10 +147,8 @@
      */
     public InitialConfigurationParcelable toStableParcelable() {
         final InitialConfigurationParcelable p = new InitialConfigurationParcelable();
-        p.ipAddresses = toParcelableArray(ipAddresses,
-                LinkPropertiesParcelableUtil::toStableParcelable, LinkAddressParcelable.class);
-        p.directlyConnectedRoutes = toParcelableArray(directlyConnectedRoutes,
-                LinkPropertiesParcelableUtil::toStableParcelable, IpPrefixParcelable.class);
+        p.ipAddresses = ipAddresses.toArray(new LinkAddress[0]);
+        p.directlyConnectedRoutes = directlyConnectedRoutes.toArray(new IpPrefix[0]);
         p.dnsServers = toParcelableArray(
                 dnsServers, IpConfigurationParcelableUtil::parcelAddress, String.class);
         return p;
@@ -164,10 +161,8 @@
     public static InitialConfiguration fromStableParcelable(InitialConfigurationParcelable p) {
         if (p == null) return null;
         final InitialConfiguration config = new InitialConfiguration();
-        config.ipAddresses.addAll(fromParcelableArray(
-                p.ipAddresses, LinkPropertiesParcelableUtil::fromStableParcelable));
-        config.directlyConnectedRoutes.addAll(fromParcelableArray(
-                p.directlyConnectedRoutes, LinkPropertiesParcelableUtil::fromStableParcelable));
+        config.ipAddresses.addAll(Arrays.asList(p.ipAddresses));
+        config.directlyConnectedRoutes.addAll(Arrays.asList(p.directlyConnectedRoutes));
         config.dnsServers.addAll(
                 fromParcelableArray(p.dnsServers, IpConfigurationParcelableUtil::unparcelAddress));
         return config;
diff --git a/services/net/java/android/net/shared/IpConfigurationParcelableUtil.java b/services/net/java/android/net/shared/IpConfigurationParcelableUtil.java
index 1f0525e..6b5826f 100644
--- a/services/net/java/android/net/shared/IpConfigurationParcelableUtil.java
+++ b/services/net/java/android/net/shared/IpConfigurationParcelableUtil.java
@@ -44,7 +44,7 @@
             @Nullable StaticIpConfiguration config) {
         if (config == null) return null;
         final StaticIpConfigurationParcelable p = new StaticIpConfigurationParcelable();
-        p.ipAddress = LinkPropertiesParcelableUtil.toStableParcelable(config.getIpAddress());
+        p.ipAddress = config.getIpAddress();
         p.gateway = parcelAddress(config.getGateway());
         p.dnsServers = toParcelableArray(
                 config.getDnsServers(), IpConfigurationParcelableUtil::parcelAddress, String.class);
@@ -59,7 +59,7 @@
             @Nullable StaticIpConfigurationParcelable p) {
         if (p == null) return null;
         final StaticIpConfiguration config = new StaticIpConfiguration();
-        config.setIpAddress(LinkPropertiesParcelableUtil.fromStableParcelable(p.ipAddress));
+        config.setIpAddress(p.ipAddress);
         config.setGateway(unparcelAddress(p.gateway));
         for (InetAddress addr : fromParcelableArray(
                 p.dnsServers, IpConfigurationParcelableUtil::unparcelAddress)) {
diff --git a/services/net/java/android/net/shared/LinkPropertiesParcelableUtil.java b/services/net/java/android/net/shared/LinkPropertiesParcelableUtil.java
index 51d955d..1729da6 100644
--- a/services/net/java/android/net/shared/LinkPropertiesParcelableUtil.java
+++ b/services/net/java/android/net/shared/LinkPropertiesParcelableUtil.java
@@ -16,25 +16,9 @@
 
 package android.net.shared;
 
-import static android.net.shared.IpConfigurationParcelableUtil.parcelAddress;
-import static android.net.shared.IpConfigurationParcelableUtil.unparcelAddress;
-import static android.net.shared.ParcelableUtil.fromParcelableArray;
-import static android.net.shared.ParcelableUtil.toParcelableArray;
-
 import android.annotation.Nullable;
-import android.net.IpPrefix;
-import android.net.IpPrefixParcelable;
-import android.net.LinkAddress;
-import android.net.LinkAddressParcelable;
 import android.net.LinkProperties;
-import android.net.LinkPropertiesParcelable;
 import android.net.ProxyInfo;
-import android.net.ProxyInfoParcelable;
-import android.net.RouteInfo;
-import android.net.RouteInfoParcelable;
-import android.net.Uri;
-
-import java.util.Arrays;
 
 /**
  * Collection of utility methods to convert to and from stable AIDL parcelables for LinkProperties
@@ -42,177 +26,22 @@
  * @hide
  */
 public final class LinkPropertiesParcelableUtil {
+    // Temporary methods to facilitate migrating clients away from LinkPropertiesParcelable
+    // TODO: remove the following methods after migrating clients.
 
     /**
-     * Convert a ProxyInfo to a ProxyInfoParcelable
+     * @deprecated conversion to stable parcelable is no longer necessary.
      */
-    public static ProxyInfoParcelable toStableParcelable(@Nullable ProxyInfo proxyInfo) {
-        if (proxyInfo == null) {
-            return null;
-        }
-        final ProxyInfoParcelable parcel = new ProxyInfoParcelable();
-        parcel.host = proxyInfo.getHost();
-        parcel.port = proxyInfo.getPort();
-        parcel.exclusionList = proxyInfo.getExclusionList();
-        parcel.pacFileUrl = proxyInfo.getPacFileUrl().toString();
-        return parcel;
-    }
-
-    /**
-     * Convert a ProxyInfoParcelable to a ProxyInfo
-     */
-    public static ProxyInfo fromStableParcelable(@Nullable ProxyInfoParcelable parcel) {
-        if (parcel == null) {
-            return null;
-        }
-        if (Uri.EMPTY.toString().equals(parcel.pacFileUrl)) {
-            return ProxyInfo.buildDirectProxy(
-                    parcel.host, parcel.port, Arrays.asList(parcel.exclusionList));
-        } else {
-            return ProxyInfo.buildPacProxy(Uri.parse(parcel.pacFileUrl));
-        }
-    }
-
-    /**
-     * Convert an IpPrefixParcelable to an IpPrefix
-     */
-    public static IpPrefixParcelable toStableParcelable(@Nullable IpPrefix ipPrefix) {
-        if (ipPrefix == null) {
-            return null;
-        }
-        final IpPrefixParcelable parcel = new IpPrefixParcelable();
-        parcel.address = parcelAddress(ipPrefix.getAddress());
-        parcel.prefixLength = ipPrefix.getPrefixLength();
-        return parcel;
-    }
-
-    /**
-     * Convert an IpPrefix to an IpPrefixParcelable
-     */
-    public static IpPrefix fromStableParcelable(@Nullable IpPrefixParcelable parcel) {
-        if (parcel == null) {
-            return null;
-        }
-        return new IpPrefix(unparcelAddress(parcel.address), parcel.prefixLength);
-    }
-
-    /**
-     * Convert a RouteInfoParcelable to a RouteInfo
-     */
-    public static RouteInfoParcelable toStableParcelable(@Nullable RouteInfo routeInfo) {
-        if (routeInfo == null) {
-            return null;
-        }
-        final RouteInfoParcelable parcel = new RouteInfoParcelable();
-        parcel.destination = toStableParcelable(routeInfo.getDestination());
-        parcel.gatewayAddr = parcelAddress(routeInfo.getGateway());
-        parcel.ifaceName = routeInfo.getInterface();
-        parcel.type = routeInfo.getType();
-        return parcel;
-    }
-
-    /**
-     * Convert a RouteInfo to a RouteInfoParcelable
-     */
-    public static RouteInfo fromStableParcelable(@Nullable RouteInfoParcelable parcel) {
-        if (parcel == null) {
-            return null;
-        }
-        final IpPrefix destination = fromStableParcelable(parcel.destination);
-        return new RouteInfo(
-                destination, unparcelAddress(parcel.gatewayAddr),
-                parcel.ifaceName, parcel.type);
-    }
-
-    /**
-     * Convert a LinkAddressParcelable to a LinkAddress
-     */
-    public static LinkAddressParcelable toStableParcelable(@Nullable LinkAddress la) {
-        if (la == null) {
-            return null;
-        }
-        final LinkAddressParcelable parcel = new LinkAddressParcelable();
-        parcel.address = parcelAddress(la.getAddress());
-        parcel.prefixLength = la.getPrefixLength();
-        parcel.flags = la.getFlags();
-        parcel.scope = la.getScope();
-        return parcel;
-    }
-
-    /**
-     * Convert a LinkAddress to a LinkAddressParcelable
-     */
-    public static LinkAddress fromStableParcelable(@Nullable LinkAddressParcelable parcel) {
-        if (parcel == null) {
-            return null;
-        }
-        return new LinkAddress(
-                unparcelAddress(parcel.address),
-                parcel.prefixLength,
-                parcel.flags,
-                parcel.scope);
-    }
-
-    /**
-     * Convert a LinkProperties to a LinkPropertiesParcelable
-     */
-    public static LinkPropertiesParcelable toStableParcelable(@Nullable LinkProperties lp) {
-        if (lp == null) {
-            return null;
-        }
-        final LinkPropertiesParcelable parcel = new LinkPropertiesParcelable();
-        parcel.ifaceName = lp.getInterfaceName();
-        parcel.linkAddresses = toParcelableArray(
-                lp.getLinkAddresses(),
-                LinkPropertiesParcelableUtil::toStableParcelable,
-                LinkAddressParcelable.class);
-        parcel.dnses = toParcelableArray(
-                lp.getDnsServers(), IpConfigurationParcelableUtil::parcelAddress, String.class);
-        parcel.pcscfs = toParcelableArray(
-                lp.getPcscfServers(), IpConfigurationParcelableUtil::parcelAddress, String.class);
-        parcel.validatedPrivateDnses = toParcelableArray(lp.getValidatedPrivateDnsServers(),
-                IpConfigurationParcelableUtil::parcelAddress, String.class);
-        parcel.usePrivateDns = lp.isPrivateDnsActive();
-        parcel.privateDnsServerName = lp.getPrivateDnsServerName();
-        parcel.domains = lp.getDomains();
-        parcel.routes = toParcelableArray(
-                lp.getRoutes(), LinkPropertiesParcelableUtil::toStableParcelable,
-                RouteInfoParcelable.class);
-        parcel.httpProxy = toStableParcelable(lp.getHttpProxy());
-        parcel.mtu = lp.getMtu();
-        parcel.tcpBufferSizes = lp.getTcpBufferSizes();
-        parcel.nat64Prefix = toStableParcelable(lp.getNat64Prefix());
-        return parcel;
-    }
-
-    /**
-     * Convert a LinkPropertiesParcelable to a LinkProperties
-     */
-    public static LinkProperties fromStableParcelable(@Nullable LinkPropertiesParcelable parcel) {
-        if (parcel == null) {
-            return null;
-        }
-        final LinkProperties lp = new LinkProperties();
-        lp.setInterfaceName(parcel.ifaceName);
-        lp.setLinkAddresses(fromParcelableArray(parcel.linkAddresses,
-                LinkPropertiesParcelableUtil::fromStableParcelable));
-        lp.setDnsServers(fromParcelableArray(
-                parcel.dnses, IpConfigurationParcelableUtil::unparcelAddress));
-        lp.setPcscfServers(fromParcelableArray(
-                parcel.pcscfs, IpConfigurationParcelableUtil::unparcelAddress));
-        lp.setValidatedPrivateDnsServers(
-                fromParcelableArray(parcel.validatedPrivateDnses,
-                IpConfigurationParcelableUtil::unparcelAddress));
-        lp.setUsePrivateDns(parcel.usePrivateDns);
-        lp.setPrivateDnsServerName(parcel.privateDnsServerName);
-        lp.setDomains(parcel.domains);
-        for (RouteInfoParcelable route : parcel.routes) {
-            lp.addRoute(fromStableParcelable(route));
-        }
-        lp.setHttpProxy(fromStableParcelable(parcel.httpProxy));
-        lp.setMtu(parcel.mtu);
-        lp.setTcpBufferSizes(parcel.tcpBufferSizes);
-        lp.setNat64Prefix(fromStableParcelable(parcel.nat64Prefix));
+    @Deprecated
+    public static LinkProperties toStableParcelable(@Nullable LinkProperties lp) {
         return lp;
     }
+
+    /**
+     * @deprecated conversion to stable parcelable is no longer necessary.
+     */
+    @Deprecated
+    public static ProxyInfo toStableParcelable(@Nullable ProxyInfo info) {
+        return info;
+    }
 }
diff --git a/services/net/java/android/net/shared/NetworkParcelableUtil.java b/services/net/java/android/net/shared/NetworkParcelableUtil.java
deleted file mode 100644
index d0b54b8..0000000
--- a/services/net/java/android/net/shared/NetworkParcelableUtil.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.shared;
-
-import android.annotation.Nullable;
-import android.net.Network;
-import android.net.NetworkParcelable;
-
-/**
- * Utility methods to convert to/from stable AIDL parcelables for network attribute classes.
- * @hide
- */
-public final class NetworkParcelableUtil {
-    /**
-     * Convert from a Network to a NetworkParcelable.
-     */
-    public static NetworkParcelable toStableParcelable(@Nullable Network network) {
-        if (network == null) {
-            return null;
-        }
-        final NetworkParcelable p = new NetworkParcelable();
-        p.networkHandle = network.getNetworkHandle();
-
-        return p;
-    }
-
-    /**
-     * Convert from a NetworkParcelable to a Network.
-     */
-    public static Network fromStableParcelable(@Nullable NetworkParcelable p) {
-        if (p == null) {
-            return null;
-        }
-        return Network.fromNetworkHandle(p.networkHandle);
-    }
-}
diff --git a/services/net/java/android/net/shared/ProvisioningConfiguration.java b/services/net/java/android/net/shared/ProvisioningConfiguration.java
index f937065..0aceb22 100644
--- a/services/net/java/android/net/shared/ProvisioningConfiguration.java
+++ b/services/net/java/android/net/shared/ProvisioningConfiguration.java
@@ -239,7 +239,7 @@
         p.apfCapabilities = IpConfigurationParcelableUtil.toStableParcelable(mApfCapabilities);
         p.provisioningTimeoutMs = mProvisioningTimeoutMs;
         p.ipv6AddrGenMode = mIPv6AddrGenMode;
-        p.network = NetworkParcelableUtil.toStableParcelable(mNetwork);
+        p.network = mNetwork;
         p.displayName = mDisplayName;
         return p;
     }
@@ -263,7 +263,7 @@
                 p.apfCapabilities);
         config.mProvisioningTimeoutMs = p.provisioningTimeoutMs;
         config.mIPv6AddrGenMode = p.ipv6AddrGenMode;
-        config.mNetwork = NetworkParcelableUtil.fromStableParcelable(p.network);
+        config.mNetwork = p.network;
         config.mDisplayName = p.displayName;
         return config;
     }
diff --git a/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java b/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java
index 59e71c4..9583b8ac 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ActivityStackSupervisorTests.java
@@ -18,32 +18,26 @@
 
 import static android.app.ActivityManager.START_DELIVERED_TO_TOP;
 import static android.app.ActivityManager.START_TASK_TO_FRONT;
+import static android.app.ITaskStackListener.FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY;
 import static android.app.WindowConfiguration.ACTIVITY_TYPE_STANDARD;
 import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
 
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.doAnswer;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.never;
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy;
-import static com.android.dx.mockito.inline.extended.ExtendedMockito.times;
+import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
 import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
 
 import static com.google.common.truth.Truth.assertThat;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyBoolean;
 import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.contains;
+import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.ArgumentMatchers.eq;
 
 import android.app.WaitResult;
+import android.content.pm.ActivityInfo;
 import android.platform.test.annotations.Presubmit;
 
 import androidx.test.filters.MediumTest;
@@ -112,4 +106,44 @@
             assertEquals(deliverToTopWait.who, firstActivity.mActivityComponent);
         }
     }
+
+    /**
+     * Ensures that {@link TaskChangeNotificationController} notifies only when an activity is
+     * forced to resize on secondary display.
+     */
+    @Test
+    public void testHandleNonResizableTaskOnSecondaryDisplay() {
+        // Create an unresizable task on secondary display.
+        final ActivityDisplay newDisplay = addNewActivityDisplayAt(ActivityDisplay.POSITION_TOP);
+        final ActivityStack stack = new StackBuilder(mRootActivityContainer)
+                .setDisplay(newDisplay).build();
+        final ActivityRecord unresizableActivity = stack.getTopActivity();
+        final TaskRecord task = unresizableActivity.getTaskRecord();
+        unresizableActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_UNRESIZEABLE;
+        task.setResizeMode(unresizableActivity.info.resizeMode);
+
+        final TaskChangeNotificationController taskChangeNotifier =
+                mService.getTaskChangeNotificationController();
+        spyOn(taskChangeNotifier);
+
+        mSupervisor.handleNonResizableTaskIfNeeded(task, newDisplay.getWindowingMode(),
+                newDisplay.mDisplayId, stack);
+        // The top activity is unresizable, so it should notify the activity is forced resizing.
+        verify(taskChangeNotifier).notifyActivityForcedResizable(eq(task.taskId),
+                eq(FORCED_RESIZEABLE_REASON_SECONDARY_DISPLAY),
+                eq(unresizableActivity.packageName));
+        reset(taskChangeNotifier);
+
+        // Put a resizable activity on top of the unresizable task.
+        final ActivityRecord resizableActivity = new ActivityBuilder(mService)
+                .setTask(task).build();
+        resizableActivity.info.resizeMode = ActivityInfo.RESIZE_MODE_RESIZEABLE;
+
+        mSupervisor.handleNonResizableTaskIfNeeded(task, newDisplay.getWindowingMode(),
+                newDisplay.mDisplayId, stack);
+        // For the resizable activity, it is no need to force resizing or dismiss the docked stack.
+        verify(taskChangeNotifier, never()).notifyActivityForcedResizable(anyInt() /* taskId */,
+                anyInt() /* reason */, anyString() /* packageName */);
+        verify(taskChangeNotifier, never()).notifyActivityDismissingDockedStack();
+    }
 }
diff --git a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsTests.java b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsTests.java
index 2dad187..9a8a732 100644
--- a/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/DisplayWindowSettingsTests.java
@@ -148,6 +148,19 @@
     }
 
     @Test
+    public void testPrimaryDisplayUpdateToFreeform_HasFreeformSupport_IsPc() {
+        mTarget.applySettingsToDisplayLocked(mPrimaryDisplay);
+
+        mWm.setSupportsFreeformWindowManagement(true);
+        mWm.setIsPc(true);
+
+        mTarget.updateSettingsForDisplay(mPrimaryDisplay);
+
+        assertEquals(WindowConfiguration.WINDOWING_MODE_FREEFORM,
+                mPrimaryDisplay.getWindowingMode());
+    }
+
+    @Test
     public void testSecondaryDisplayDefaultToFullscreen_NoFreeformSupport() {
         mTarget.applySettingsToDisplayLocked(mSecondaryDisplay);
 
diff --git a/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java b/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
index fc1eb1c..68e7470 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RecentTasksTest.java
@@ -583,6 +583,114 @@
     }
 
     @Test
+    public void testFreezeTaskListOrder_reorderExistingTask() {
+        // Add some tasks
+        mRecentTasks.add(mTasks.get(0));
+        mRecentTasks.add(mTasks.get(1));
+        mRecentTasks.add(mTasks.get(2));
+        mRecentTasks.add(mTasks.get(3));
+        mRecentTasks.add(mTasks.get(4));
+        mCallbacksRecorder.clear();
+
+        // Freeze the list
+        mRecentTasks.setFreezeTaskListReordering();
+        assertTrue(mRecentTasks.isFreezeTaskListReorderingSet());
+
+        // Relaunch a few tasks
+        mRecentTasks.add(mTasks.get(3));
+        mRecentTasks.add(mTasks.get(2));
+
+        // Commit the task ordering with a specific task focused
+        mRecentTasks.resetFreezeTaskListReordering(mTasks.get(2));
+        assertFalse(mRecentTasks.isFreezeTaskListReorderingSet());
+
+        // Ensure that the order of the task list is the same as before, but with the focused task
+        // at the front
+        assertRecentTasksOrder(mTasks.get(2),
+                mTasks.get(4),
+                mTasks.get(3),
+                mTasks.get(1),
+                mTasks.get(0));
+
+        assertThat(mCallbacksRecorder.mAdded).isEmpty();
+        assertThat(mCallbacksRecorder.mTrimmed).isEmpty();
+        assertThat(mCallbacksRecorder.mRemoved).isEmpty();
+    }
+
+    @Test
+    public void testFreezeTaskListOrder_addRemoveTasks() {
+        // Add some tasks
+        mRecentTasks.add(mTasks.get(0));
+        mRecentTasks.add(mTasks.get(1));
+        mRecentTasks.add(mTasks.get(2));
+        mCallbacksRecorder.clear();
+
+        // Freeze the list
+        mRecentTasks.setFreezeTaskListReordering();
+        assertTrue(mRecentTasks.isFreezeTaskListReorderingSet());
+
+        // Add and remove some tasks
+        mRecentTasks.add(mTasks.get(3));
+        mRecentTasks.add(mTasks.get(4));
+        mRecentTasks.remove(mTasks.get(0));
+        mRecentTasks.remove(mTasks.get(1));
+
+        // Unfreeze the list
+        mRecentTasks.resetFreezeTaskListReordering(null);
+        assertFalse(mRecentTasks.isFreezeTaskListReorderingSet());
+
+        // Ensure that the order of the task list accounts for the added and removed tasks (added
+        // at the end)
+        assertRecentTasksOrder(mTasks.get(4),
+                mTasks.get(3),
+                mTasks.get(2));
+
+        assertThat(mCallbacksRecorder.mAdded).hasSize(2);
+        assertThat(mCallbacksRecorder.mAdded).contains(mTasks.get(3));
+        assertThat(mCallbacksRecorder.mAdded).contains(mTasks.get(4));
+        assertThat(mCallbacksRecorder.mRemoved).hasSize(2);
+        assertThat(mCallbacksRecorder.mRemoved).contains(mTasks.get(0));
+        assertThat(mCallbacksRecorder.mRemoved).contains(mTasks.get(1));
+    }
+
+    @Test
+    public void testFreezeTaskListOrder_timeout() {
+        // Add some tasks
+        mRecentTasks.add(mTasks.get(0));
+        mRecentTasks.add(mTasks.get(1));
+        mRecentTasks.add(mTasks.get(2));
+        mRecentTasks.add(mTasks.get(3));
+        mRecentTasks.add(mTasks.get(4));
+
+        // Freeze the list
+        long freezeTime = SystemClock.elapsedRealtime();
+        mRecentTasks.setFreezeTaskListReordering();
+        assertTrue(mRecentTasks.isFreezeTaskListReorderingSet());
+
+        // Relaunch a few tasks
+        mRecentTasks.add(mTasks.get(2));
+        mRecentTasks.add(mTasks.get(1));
+
+        // Override the freeze timeout params to simulate the timeout (simulate the freeze at 100ms
+        // ago with a timeout of 1ms)
+        mRecentTasks.setFreezeTaskListTimeoutParams(freezeTime - 100, 1);
+
+        ActivityStack stack = mTasks.get(2).getStack();
+        stack.moveToFront("", mTasks.get(2));
+        doReturn(stack).when(mTestService.mRootActivityContainer).getTopDisplayFocusedStack();
+        mRecentTasks.resetFreezeTaskListReorderingOnTimeout();
+        assertFalse(mRecentTasks.isFreezeTaskListReorderingSet());
+
+        // Ensure that the order of the task list is the same as before, but with the focused task
+        // at the front
+        assertRecentTasksOrder(mTasks.get(2),
+                mTasks.get(4),
+                mTasks.get(3),
+                mTasks.get(1),
+                mTasks.get(0));
+    }
+
+    @Test
     public void testBackStackTasks_expectNoTrim() {
         mRecentTasks.setParameters(-1 /* min */, 1 /* max */, -1 /* ms */);
 
@@ -721,6 +829,18 @@
                         true /* showRecents */));
     }
 
+    /**
+     * Ensures that the recent tasks list is in the provided order. Note that the expected tasks
+     * should be ordered from least to most recent.
+     */
+    private void assertRecentTasksOrder(TaskRecord... expectedTasks) {
+        ArrayList<TaskRecord> tasks = mRecentTasks.getRawTasks();
+        assertTrue(expectedTasks.length == tasks.size());
+        for (int i = 0; i < tasks.size(); i++)  {
+            assertTrue(expectedTasks[i] == tasks.get(i));
+        }
+    }
+
     private void assertNotRestoreTask(Runnable action) {
         // Verify stack count doesn't change because task with fullscreen mode and standard type
         // would have its own stack.
diff --git a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
index 45fe5d2..35a8ec3 100644
--- a/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/RootWindowContainerTests.java
@@ -20,9 +20,11 @@
 import static android.view.WindowManager.LayoutParams.TYPE_STATUS_BAR;
 import static android.view.WindowManager.LayoutParams.TYPE_TOAST;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
+import android.app.WindowConfiguration;
 import android.platform.test.annotations.Presubmit;
 
 import androidx.test.filters.SmallTest;
@@ -71,5 +73,21 @@
         assertFalse(app.isVisible());
         assertFalse(mWm.mRoot.isAnyNonToastWindowVisibleForUid(FAKE_CALLING_UID));
     }
+
+    @Test
+    public void testUpdateDefaultDisplayWindowingModeOnSettingsRetrieved() {
+        synchronized (mWm.mGlobalLock) {
+            assertEquals(WindowConfiguration.WINDOWING_MODE_FULLSCREEN,
+                    mWm.getDefaultDisplayContentLocked().getWindowingMode());
+
+            mWm.mIsPc = true;
+            mWm.mSupportsFreeformWindowManagement = true;
+
+            mWm.mRoot.onSettingsRetrieved();
+
+            assertEquals(WindowConfiguration.WINDOWING_MODE_FREEFORM,
+                    mWm.getDefaultDisplayContentLocked().getWindowingMode());
+        }
+    }
 }
 
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
index 1b396f5..00e479fc 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskPositioningControllerTests.java
@@ -32,7 +32,6 @@
 import android.platform.test.annotations.Presubmit;
 import android.view.InputChannel;
 
-import androidx.test.filters.FlakyTest;
 import androidx.test.filters.SmallTest;
 
 import org.junit.Before;
@@ -89,7 +88,6 @@
         assertNull(mTarget.getDragWindowHandleLocked());
     }
 
-    @FlakyTest(bugId = 69229402)
     @Test
     public void testHandleTapOutsideTask() {
         synchronized (mWm.mGlobalLock) {
diff --git a/services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java b/services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java
index 2fc6efa..7d7c3985 100644
--- a/services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/ZOrderingTests.java
@@ -43,7 +43,6 @@
 import android.view.SurfaceControl;
 import android.view.SurfaceSession;
 
-import androidx.test.filters.FlakyTest;
 import androidx.test.filters.SmallTest;
 
 import org.junit.After;
@@ -212,7 +211,6 @@
         return createWindow(null, TYPE_BASE_APPLICATION, mDisplayContent, name);
     }
 
-    @FlakyTest(bugId = 124088319)
     @Test
     public void testAssignWindowLayers_ForImeWithNoTarget() {
         mDisplayContent.mInputMethodTarget = null;
@@ -230,7 +228,6 @@
         assertWindowHigher(mImeDialogWindow, mImeWindow);
     }
 
-    @FlakyTest(bugId = 124088319)
     @Test
     public void testAssignWindowLayers_ForImeWithAppTarget() {
         final WindowState imeAppTarget = createWindow("imeAppTarget");
@@ -250,7 +247,6 @@
         assertWindowHigher(mImeDialogWindow, mImeWindow);
     }
 
-    @FlakyTest(bugId = 124088319)
     @Test
     public void testAssignWindowLayers_ForImeWithAppTargetWithChildWindows() {
         final WindowState imeAppTarget = createWindow("imeAppTarget");
@@ -277,7 +273,6 @@
         assertWindowHigher(mImeDialogWindow, mImeWindow);
     }
 
-    @FlakyTest(bugId = 124088319)
     @Test
     public void testAssignWindowLayers_ForImeWithAppTargetAndAppAbove() {
         final WindowState appBelowImeTarget = createWindow("appBelowImeTarget");
@@ -301,7 +296,6 @@
         assertWindowHigher(mImeDialogWindow, mImeWindow);
     }
 
-    @FlakyTest(bugId = 124088319)
     @Test
     public void testAssignWindowLayers_ForImeNonAppImeTarget() {
         final WindowState imeSystemOverlayTarget = createWindow(null, TYPE_SYSTEM_OVERLAY,
@@ -329,7 +323,6 @@
         assertWindowHigher(mImeDialogWindow, mImeWindow);
     }
 
-    @FlakyTest(bugId = 124088319)
     @Test
     public void testAssignWindowLayers_ForStatusBarImeTarget() {
         mDisplayContent.mInputMethodTarget = mStatusBarWindow;
@@ -344,7 +337,6 @@
         assertWindowHigher(mImeDialogWindow, mImeWindow);
     }
 
-    @FlakyTest(bugId = 124088319)
     @Test
     public void testStackLayers() {
         final WindowState anyWindow1 = createWindow("anyWindow");
@@ -432,7 +424,6 @@
         }
     }
 
-    @FlakyTest(bugId = 124088319)
     @Test
     public void testDockedDividerPosition() {
         final WindowState pinnedStackWindow = createWindowOnStack(null, WINDOWING_MODE_PINNED,
diff --git a/telecomm/java/android/telecom/AudioState.java b/telecomm/java/android/telecom/AudioState.java
index 4e74395..6b9b83d 100644
--- a/telecomm/java/android/telecom/AudioState.java
+++ b/telecomm/java/android/telecom/AudioState.java
@@ -18,6 +18,7 @@
 
 import android.annotation.SystemApi;
 import android.annotation.UnsupportedAppUsage;
+import android.os.Build;
 import android.os.Parcel;
 import android.os.Parcelable;
 
@@ -54,11 +55,11 @@
     private static final int ROUTE_ALL = ROUTE_EARPIECE | ROUTE_BLUETOOTH | ROUTE_WIRED_HEADSET |
             ROUTE_SPEAKER;
 
-    @UnsupportedAppUsage
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
     private final boolean isMuted;
-    @UnsupportedAppUsage
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
     private final int route;
-    @UnsupportedAppUsage
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
     private final int supportedRouteMask;
 
     public AudioState(boolean muted, int route, int supportedRouteMask) {
diff --git a/telecomm/java/android/telecom/CallRedirectionService.java b/telecomm/java/android/telecom/CallRedirectionService.java
index d521e30..d01c889 100644
--- a/telecomm/java/android/telecom/CallRedirectionService.java
+++ b/telecomm/java/android/telecom/CallRedirectionService.java
@@ -17,6 +17,7 @@
 package android.telecom;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.annotation.SdkConstant;
 import android.app.Service;
 import android.content.Intent;
@@ -206,12 +207,12 @@
     }
 
     @Override
-    public final IBinder onBind(Intent intent) {
+    public final @Nullable IBinder onBind(@NonNull Intent intent) {
         return new CallRedirectionBinder();
     }
 
     @Override
-    public final boolean onUnbind(Intent intent) {
+    public final boolean onUnbind(@NonNull Intent intent) {
         return false;
     }
 }
diff --git a/telecomm/java/android/telecom/Phone.java b/telecomm/java/android/telecom/Phone.java
index d3ccd2c..0cc052e 100644
--- a/telecomm/java/android/telecom/Phone.java
+++ b/telecomm/java/android/telecom/Phone.java
@@ -19,6 +19,7 @@
 import android.annotation.SystemApi;
 import android.annotation.UnsupportedAppUsage;
 import android.bluetooth.BluetoothDevice;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.RemoteException;
 import android.util.ArrayMap;
@@ -328,10 +329,12 @@
      * become active, and the touch screen and display will be turned off when the user's face
      * is detected to be in close proximity to the screen. This operation is a no-op on devices
      * that do not have a proximity sensor.
-     *
+     * <p>
+     * This API does not actually turn on the proximity sensor; apps should do this on their own if
+     * required.
      * @hide
      */
-    @UnsupportedAppUsage
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
     public final void setProximitySensorOn() {
         mInCallAdapter.turnProximitySensorOn();
     }
@@ -344,10 +347,12 @@
      * @param screenOnImmediately If true, the screen will be turned on immediately if it was
      * previously off. Otherwise, the screen will only be turned on after the proximity sensor
      * is no longer triggered.
-     *
+     * <p>
+     * This API does not actually turn of the proximity sensor; apps should do this on their own if
+     * required.
      * @hide
      */
-    @UnsupportedAppUsage
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
     public final void setProximitySensorOff(boolean screenOnImmediately) {
         mInCallAdapter.turnProximitySensorOff(screenOnImmediately);
     }
diff --git a/telecomm/java/android/telecom/PhoneAccountHandle.java b/telecomm/java/android/telecom/PhoneAccountHandle.java
index a84ce55..71a28b5 100644
--- a/telecomm/java/android/telecom/PhoneAccountHandle.java
+++ b/telecomm/java/android/telecom/PhoneAccountHandle.java
@@ -42,7 +42,7 @@
  * See {@link PhoneAccount}, {@link TelecomManager}.
  */
 public final class PhoneAccountHandle implements Parcelable {
-    @UnsupportedAppUsage
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
     private final ComponentName mComponentName;
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
     private final String mId;
diff --git a/telecomm/java/android/telecom/VideoCallImpl.java b/telecomm/java/android/telecom/VideoCallImpl.java
index 2c7fecb..cb74012 100644
--- a/telecomm/java/android/telecom/VideoCallImpl.java
+++ b/telecomm/java/android/telecom/VideoCallImpl.java
@@ -18,6 +18,7 @@
 
 import android.annotation.UnsupportedAppUsage;
 import android.net.Uri;
+import android.os.Build;
 import android.os.Handler;
 import android.os.IBinder;
 import android.os.Looper;
@@ -218,7 +219,7 @@
         mTargetSdkVersion = sdkVersion;
     }
 
-    @UnsupportedAppUsage
+    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 127403196)
     public void destroy() {
         unregisterCallback(mCallback);
     }
diff --git a/telephony/java/android/telephony/AccessNetworkConstants.java b/telephony/java/android/telephony/AccessNetworkConstants.java
index 75165af..81553a3 100644
--- a/telephony/java/android/telephony/AccessNetworkConstants.java
+++ b/telephony/java/android/telephony/AccessNetworkConstants.java
@@ -16,13 +16,59 @@
 
 package android.telephony;
 
+import android.annotation.IntDef;
 import android.annotation.SystemApi;
 
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
 /**
  * Contains access network related constants.
  */
 public final class AccessNetworkConstants {
 
+    /**
+     * Wireless transportation type
+     *
+     * @hide */
+    @Retention(RetentionPolicy.SOURCE)
+    @IntDef(prefix = {"TRANSPORT_TYPE_"},
+            value = {
+                    TRANSPORT_TYPE_INVALID,
+                    TRANSPORT_TYPE_WWAN,
+                    TRANSPORT_TYPE_WLAN})
+    public @interface TransportType {}
+
+    /**
+     * Invalid transport type
+     * @hide
+     */
+    @SystemApi
+    public static final int TRANSPORT_TYPE_INVALID = -1;
+
+    /**
+     * Transport type for Wireless Wide Area Networks (i.e. Cellular)
+     * @hide
+     */
+    @SystemApi
+    public static final int TRANSPORT_TYPE_WWAN = 1;
+
+    /**
+     * Transport type for Wireless Local Area Networks (i.e. Wifi)
+     * @hide
+     */
+    @SystemApi
+    public static final int TRANSPORT_TYPE_WLAN = 2;
+
+    /** @hide */
+    public static String transportTypeToString(@TransportType int transportType) {
+        switch (transportType) {
+            case TRANSPORT_TYPE_WWAN: return "WWAN";
+            case TRANSPORT_TYPE_WLAN: return "WLAN";
+            default: return Integer.toString(transportType);
+        }
+    }
+
     public static final class AccessNetworkType {
         public static final int UNKNOWN = 0;
         public static final int GERAN = 1;
@@ -49,39 +95,7 @@
     }
 
     /**
-     * Wireless transportation type
-     * @hide
-     */
-    @SystemApi
-    public static final class TransportType {
-        /**
-         * Invalid transport type.
-         * @hide
-         */
-        public static final int INVALID = -1;
-
-        /** Wireless Wide Area Networks (i.e. Cellular) */
-        public static final int WWAN = 1;
-
-        /** Wireless Local Area Networks (i.e. Wifi) */
-        public static final int WLAN = 2;
-
-        /** @hide */
-        private TransportType() {}
-
-        /** @hide */
-        public static String toString(int type) {
-            switch (type) {
-                case INVALID: return "INVALID";
-                case WWAN: return "WWAN";
-                case WLAN: return "WLAN";
-                default: return Integer.toString(type);
-            }
-        }
-    }
-
-    /**
-     * Frenquency bands for GERAN.
+     * Frequency bands for GERAN.
      * http://www.etsi.org/deliver/etsi_ts/145000_145099/145005/14.00.00_60/ts_145005v140000p.pdf
      */
     public static final class GeranBand {
diff --git a/telephony/java/android/telephony/NetworkRegistrationState.java b/telephony/java/android/telephony/NetworkRegistrationState.java
index a6c81db..eff3285 100644
--- a/telephony/java/android/telephony/NetworkRegistrationState.java
+++ b/telephony/java/android/telephony/NetworkRegistrationState.java
@@ -129,7 +129,6 @@
     @Domain
     private final int mDomain;
 
-    /** {@link TransportType} */
     private final int mTransportType;
 
     @RegState
@@ -165,14 +164,15 @@
     private DataSpecificRegistrationStates mDataSpecificStates;
 
     /**
-     * @param domain Network domain. Must be a {@link Domain}. For {@link TransportType#WLAN}
-     * transport, this must set to {@link #DOMAIN_PS}.
-     * @param transportType Transport type. Must be one of the{@link TransportType}.
+     * @param domain Network domain. Must be a {@link Domain}. For transport type
+     * {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN}, this must set to {@link #DOMAIN_PS}.
+     * @param transportType Transport type.
      * @param regState Network registration state. Must be one of the {@link RegState}. For
-     * {@link TransportType#WLAN} transport, only {@link #REG_STATE_HOME} and
-     * {@link #REG_STATE_NOT_REG_NOT_SEARCHING} are valid states.
-     * @param accessNetworkTechnology Access network technology.For {@link TransportType#WLAN}
-     * transport, set to {@link TelephonyManager#NETWORK_TYPE_IWLAN}.
+     * transport type {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN}, only
+     * {@link #REG_STATE_HOME} and {@link #REG_STATE_NOT_REG_NOT_SEARCHING} are valid states.
+     * @param accessNetworkTechnology Access network technology.For transport type
+     * {@link AccessNetworkConstants#TRANSPORT_TYPE_WLAN}, set to
+     * {@link TelephonyManager#NETWORK_TYPE_IWLAN}.
      * @param rejectCause Reason for denial if the registration state is {@link #REG_STATE_DENIED}.
      * Depending on {@code accessNetworkTechnology}, the values are defined in 3GPP TS 24.008
      * 10.5.3.6 for UMTS, 3GPP TS 24.301 9.9.3.9 for LTE, and 3GPP2 A.S0001 6.2.2.44 for CDMA. If
@@ -184,7 +184,8 @@
      * @param cellIdentity The identity representing a unique cell or wifi AP. Set to null if the
      * information is not available.
      */
-    public NetworkRegistrationState(@Domain int domain, int transportType, @RegState int regState,
+    public NetworkRegistrationState(@Domain int domain, @TransportType int transportType,
+                                    @RegState int regState,
                                     @NetworkType int accessNetworkTechnology, int rejectCause,
                                     boolean emergencyOnly,
                                     @NonNull @ServiceType int[] availableServices,
@@ -206,7 +207,7 @@
      * Constructor for voice network registration states.
      * @hide
      */
-    public NetworkRegistrationState(int domain, int transportType, int regState,
+    public NetworkRegistrationState(int domain, @TransportType int transportType, int regState,
             int accessNetworkTechnology, int rejectCause, boolean emergencyOnly,
             int[] availableServices, @Nullable CellIdentity cellIdentity, boolean cssSupported,
             int roamingIndicator, int systemIsInPrl, int defaultRoamingIndicator) {
@@ -221,7 +222,7 @@
      * Constructor for data network registration states.
      * @hide
      */
-    public NetworkRegistrationState(int domain, int transportType, int regState,
+    public NetworkRegistrationState(int domain, @TransportType int transportType, int regState,
             int accessNetworkTechnology, int rejectCause, boolean emergencyOnly,
             int[] availableServices, @Nullable CellIdentity cellIdentity, int maxDataCalls,
             boolean isDcNrRestricted, boolean isNrAvailable, boolean isEndcAvailable,
@@ -434,7 +435,8 @@
     public String toString() {
         return new StringBuilder("NetworkRegistrationState{")
                 .append(" domain=").append((mDomain == DOMAIN_CS) ? "CS" : "PS")
-                .append(" transportType=").append(TransportType.toString(mTransportType))
+                .append(" transportType=").append(
+                        AccessNetworkConstants.transportTypeToString(mTransportType))
                 .append(" regState=").append(regStateToString(mRegState))
                 .append(" roamingType=").append(ServiceState.roamingTypeToString(mRoamingType))
                 .append(" accessNetworkTechnology=")
@@ -627,7 +629,7 @@
          *
          * @return The same instance of the builder.
          */
-        public @NonNull Builder setTransportType(int transportType) {
+        public @NonNull Builder setTransportType(@TransportType int transportType) {
             mTransportType = transportType;
             return this;
         }
diff --git a/telephony/java/android/telephony/ServiceState.java b/telephony/java/android/telephony/ServiceState.java
index bddf978..687c6f4 100644
--- a/telephony/java/android/telephony/ServiceState.java
+++ b/telephony/java/android/telephony/ServiceState.java
@@ -28,6 +28,7 @@
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.telephony.AccessNetworkConstants.AccessNetworkType;
+import android.telephony.AccessNetworkConstants.TransportType;
 import android.telephony.NetworkRegistrationState.Domain;
 import android.telephony.NetworkRegistrationState.NRStatus;
 import android.text.TextUtils;
@@ -620,7 +621,7 @@
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public @RoamingType int getVoiceRoamingType() {
         final NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState != null) {
             return regState.getRoamingType();
         }
@@ -644,7 +645,7 @@
      */
     public boolean getDataRoamingFromRegistration() {
         final NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState != null) {
             return (regState.getRegState() == NetworkRegistrationState.REG_STATE_ROAMING);
         }
@@ -659,7 +660,7 @@
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public @RoamingType int getDataRoamingType() {
         final NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState != null) {
             return regState.getRoamingType();
         }
@@ -837,7 +838,7 @@
                 mVoiceRegState,
                 mDataRegState,
                 mChannelNumber,
-                mCellBandwidths,
+                Arrays.hashCode(mCellBandwidths),
                 mVoiceOperatorAlphaLong,
                 mVoiceOperatorAlphaShort,
                 mVoiceOperatorNumeric,
@@ -1130,10 +1131,10 @@
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
     public void setVoiceRoamingType(@RoamingType int type) {
         NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState == null) {
             regState = new NetworkRegistrationState(
-                    NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TransportType.WWAN,
+                    NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                     ServiceState.ROAMING_TYPE_NOT_ROAMING, TelephonyManager.NETWORK_TYPE_UNKNOWN, 0,
                     false, null, null);
             addNetworkRegistrationState(regState);
@@ -1151,10 +1152,10 @@
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
     public void setDataRoamingType(@RoamingType int type) {
         NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState == null) {
             regState = new NetworkRegistrationState(
-                    NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WWAN,
+                    NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                     ServiceState.ROAMING_TYPE_NOT_ROAMING, TelephonyManager.NETWORK_TYPE_UNKNOWN, 0,
                     false, null, null);
             addNetworkRegistrationState(regState);
@@ -1326,10 +1327,10 @@
 
         // sync to network registration state
         NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState == null) {
             regState = new NetworkRegistrationState(
-                    NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TransportType.WWAN,
+                    NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                     ServiceState.ROAMING_TYPE_NOT_ROAMING, TelephonyManager.NETWORK_TYPE_UNKNOWN,
                     0, false, null, null);
             addNetworkRegistrationState(regState);
@@ -1353,11 +1354,11 @@
 
         // sync to network registration state
         NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
 
         if (regState == null) {
             regState = new NetworkRegistrationState(
-                    NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WWAN,
+                    NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN,
                     ServiceState.ROAMING_TYPE_NOT_ROAMING, TelephonyManager.NETWORK_TYPE_UNKNOWN,
                     0, false, null, null);
             addNetworkRegistrationState(regState);
@@ -1391,7 +1392,7 @@
      */
     public @NRStatus int getNrStatus() {
         final NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState == null) return NetworkRegistrationState.NR_STATUS_NONE;
         return regState.getNrStatus();
     }
@@ -1576,7 +1577,7 @@
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public @TelephonyManager.NetworkType int getDataNetworkType() {
         final NetworkRegistrationState iwlanRegState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WLAN);
+                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
         if (iwlanRegState != null
                 && iwlanRegState.getRegState() == NetworkRegistrationState.REG_STATE_HOME) {
             // If the device is on IWLAN, return IWLAN as the network type. This is to simulate the
@@ -1587,7 +1588,7 @@
         }
 
         final NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_PS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState != null) {
             return regState.getAccessNetworkTechnology();
         }
@@ -1598,7 +1599,7 @@
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
     public @TelephonyManager.NetworkType int getVoiceNetworkType() {
         final NetworkRegistrationState regState = getNetworkRegistrationState(
-                NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TransportType.WWAN);
+                NetworkRegistrationState.DOMAIN_CS, AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
         if (regState != null) {
             return regState.getAccessNetworkTechnology();
         }
@@ -1777,11 +1778,11 @@
     /**
      * Get the network registration states for the transport type.
      *
-     * @param transportType The {@link AccessNetworkConstants.TransportType transport type}
+     * @param transportType The transport type
      * @return List of {@link NetworkRegistrationState}
      * @hide
      *
-     * @deprecated Use {@link #getNetworkRegistrationStatesFromTransportType(int)}
+     * @deprecated Use {@link #getNetworkRegistrationStatesForTransportType(int)}
      */
     @NonNull
     @Deprecated
@@ -1793,14 +1794,14 @@
     /**
      * Get the network registration states for the transport type.
      *
-     * @param transportType The {@link AccessNetworkConstants.TransportType transport type}
+     * @param transportType The transport type
      * @return List of {@link NetworkRegistrationState}
      * @hide
      */
     @NonNull
     @SystemApi
     public List<NetworkRegistrationState> getNetworkRegistrationStatesForTransportType(
-            int transportType) {
+            @TransportType int transportType) {
         List<NetworkRegistrationState> list = new ArrayList<>();
 
         synchronized (mNetworkRegistrationStates) {
@@ -1842,7 +1843,7 @@
      * Get the network registration state for the transport type and network domain.
      *
      * @param domain The network {@link NetworkRegistrationState.Domain domain}
-     * @param transportType The {@link AccessNetworkConstants.TransportType transport type}
+     * @param transportType The transport type
      * @return The matching {@link NetworkRegistrationState}
      * @hide
      *
@@ -1852,7 +1853,7 @@
     @Deprecated
     @SystemApi
     public NetworkRegistrationState getNetworkRegistrationStates(@Domain int domain,
-                                                                 int transportType) {
+                                                                 @TransportType int transportType) {
         return getNetworkRegistrationState(domain, transportType);
     }
 
@@ -1860,7 +1861,7 @@
      * Get the network registration state for the transport type and network domain.
      *
      * @param domain The network {@link NetworkRegistrationState.Domain domain}
-     * @param transportType The {@link AccessNetworkConstants.TransportType transport type}
+     * @param transportType The transport type
      * @return The matching {@link NetworkRegistrationState}
      * @hide
      *
@@ -1868,7 +1869,7 @@
     @Nullable
     @SystemApi
     public NetworkRegistrationState getNetworkRegistrationState(@Domain int domain,
-                                                                int transportType) {
+                                                                @TransportType int transportType) {
         synchronized (mNetworkRegistrationStates) {
             for (NetworkRegistrationState networkRegistrationState : mNetworkRegistrationStates) {
                 if (networkRegistrationState.getTransportType() == transportType
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index 3dee114..f7ab921 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -3346,26 +3346,25 @@
     }
 
     /**
-     * Get the mapping from logical slots to physical slots. The mapping represent by a pair list.
-     * The key of the piar is the logical slot id and the value of the pair is the physical
-     * slots id mapped to this logical slot id.
+     * Get the mapping from logical slots to physical slots. The key of the map is the logical slot
+     * id and the value is the physical slots id mapped to this logical slot id.
      *
-     * @return an pair list indicates the mapping from logical slots to physical slots. The size of
-     * the list should be {@link #getPhoneCount()} if success, otherwise return an empty list.
+     * @return a map indicates the mapping from logical slots to physical slots. The size of the map
+     * should be {@link #getPhoneCount()} if success, otherwise return an empty map.
      *
      * @hide
      */
     @SystemApi
     @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
     @NonNull
-    public List<Pair<Integer, Integer>> getLogicalToPhysicalSlotMapping() {
-        List<Pair<Integer, Integer>> slotMapping = new ArrayList<>();
+    public Map<Integer, Integer> getLogicalToPhysicalSlotMapping() {
+        Map<Integer, Integer> slotMapping = new HashMap<>();
         try {
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 int[] slotMappingArray = telephony.getSlotsMapping();
                 for (int i = 0; i < slotMappingArray.length; i++) {
-                    slotMapping.add(new Pair(i, slotMappingArray[i]));
+                    slotMapping.put(i, slotMappingArray[i]);
                 }
             }
         } catch (RemoteException e) {
@@ -10256,15 +10255,20 @@
     }
 
     /**
-     * Checks if the supplied number is an emergency number based on current locale, sim, default,
-     * modem and network.
+     * Identifies if the supplied phone number is an emergency number that matches a known
+     * emergency number based on current locale, SIM card(s), Android database, modem, network,
+     * or defaults.
+     *
+     * <p>This method assumes that only dialable phone numbers are passed in; non-dialable
+     * numbers are not considered emergency numbers. A dialable phone number consists only
+     * of characters/digits identified by {@link PhoneNumberUtils#isDialable(char)}.
      *
      * <p>The subscriptions which the identification would be based on, are all the active
      * subscriptions, no matter which subscription could be used to create TelephonyManager.
      *
      * @param number - the number to look up
      * @return {@code true} if the given number is an emergency number based on current locale,
-     * sim, modem and network; {@code false} otherwise.
+     * SIM card(s), Android database, modem, network or defaults; {@code false} otherwise.
      */
     public boolean isEmergencyNumber(@NonNull String number) {
         try {
diff --git a/telephony/java/android/telephony/emergency/EmergencyNumber.java b/telephony/java/android/telephony/emergency/EmergencyNumber.java
index 173f4ed..fa6cfcb 100644
--- a/telephony/java/android/telephony/emergency/EmergencyNumber.java
+++ b/telephony/java/android/telephony/emergency/EmergencyNumber.java
@@ -22,6 +22,7 @@
 import android.hardware.radio.V1_4.EmergencyServiceCategory;
 import android.os.Parcel;
 import android.os.Parcelable;
+import android.telephony.PhoneNumberUtils;
 import android.telephony.Rlog;
 
 import java.lang.annotation.Retention;
@@ -673,11 +674,20 @@
     }
 
     /**
-     * Validate Emergency Number address that only allows '0'-'9', '*', or '#'
+     * Validate Emergency Number address that only contains the dialable character
+     * {@link PhoneNumberUtils#isDialable(char)}
      *
      * @hide
      */
     public static boolean validateEmergencyNumberAddress(String address) {
-        return address.matches("[0-9*#]+");
+        if (address == null) {
+            return false;
+        }
+        for (char c : address.toCharArray()) {
+            if (!PhoneNumberUtils.isDialable(c)) {
+                return false;
+            }
+        }
+        return true;
     }
 }
diff --git a/telephony/java/android/telephony/euicc/EuiccManager.java b/telephony/java/android/telephony/euicc/EuiccManager.java
index bac8c03..e651783 100644
--- a/telephony/java/android/telephony/euicc/EuiccManager.java
+++ b/telephony/java/android/telephony/euicc/EuiccManager.java
@@ -120,6 +120,10 @@
      * enable or disable a subscription. Must be accompanied with {@link #EXTRA_SUBSCRIPTION_ID} and
      * {@link #EXTRA_ENABLE_SUBSCRIPTION}.
      *
+     * Requires the caller to be a privileged process with the
+     * {@link android.permission#CALL_PRIVILEGED} permission for the intent to reach the Telephony
+     * stack.
+     *
      * <p>Unlike {@link #switchToSubscription(int, PendingIntent)}, using this action allows the
      * underlying eUICC service (i.e. the LPA app) to control the UI experience during this
      * operation. The action is received by the Telephony framework, which in turn selects and
@@ -139,6 +143,10 @@
      * Intent action sent by system apps (such as the Settings app) to the Telephony framework to
      * delete a subscription. Must be accompanied with {@link #EXTRA_SUBSCRIPTION_ID}.
      *
+     * Requires the caller to be a privileged process with the
+     * {@link android.permission#CALL_PRIVILEGED} permission for the intent to reach the Telephony
+     * stack.
+     *
      * <p>Unlike {@link #deleteSubscription(int, PendingIntent)}, using this action allows the
      * underlying eUICC service (i.e. the LPA app) to control the UI experience during this
      * operation. The action is received by the Telephony framework, which in turn selects and
@@ -159,6 +167,10 @@
      * rename a subscription. Must be accompanied with {@link #EXTRA_SUBSCRIPTION_ID} and
      * {@link #EXTRA_SUBSCRIPTION_NICKNAME}.
      *
+     * Requires the caller to be a privileged process with the
+     * {@link android.permission#CALL_PRIVILEGED} permission for the intent to reach the Telephony
+     * stack.
+     *
      * <p>Unlike {@link #updateSubscriptionNickname(int, String, PendingIntent)}, using this action
      * allows the the underlying eUICC service (i.e. the LPA app) to control the UI experience
      * during this operation. The action is received by the Telephony framework, which in turn
@@ -761,7 +773,7 @@
      */
     @RequiresPermission(Manifest.permission.WRITE_EMBEDDED_SUBSCRIPTIONS)
     public void updateSubscriptionNickname(
-            int subscriptionId, String nickname, PendingIntent callbackIntent) {
+            int subscriptionId, @Nullable String nickname, @NonNull PendingIntent callbackIntent) {
         if (!refreshCardIdIfUninitialized()) {
             sendUnavailableError(callbackIntent);
             return;
diff --git a/telephony/java/android/telephony/ims/ImsMmTelManager.java b/telephony/java/android/telephony/ims/ImsMmTelManager.java
index 12e8006..e9aede7 100644
--- a/telephony/java/android/telephony/ims/ImsMmTelManager.java
+++ b/telephony/java/android/telephony/ims/ImsMmTelManager.java
@@ -109,9 +109,9 @@
                         // case, since it is defined.
                         put(ImsRegistrationImplBase.REGISTRATION_TECH_NONE, -1);
                         put(ImsRegistrationImplBase.REGISTRATION_TECH_LTE,
-                                AccessNetworkConstants.TransportType.WWAN);
+                                AccessNetworkConstants.TRANSPORT_TYPE_WWAN);
                         put(ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN,
-                                AccessNetworkConstants.TransportType.WLAN);
+                                AccessNetworkConstants.TRANSPORT_TYPE_WLAN);
                     }};
 
             private final RegistrationCallback mLocalCallback;
diff --git a/tests/net/java/android/net/shared/LinkPropertiesParcelableUtilTest.java b/tests/net/java/android/net/shared/LinkPropertiesParcelableUtilTest.java
deleted file mode 100644
index 2d0e03d..0000000
--- a/tests/net/java/android/net/shared/LinkPropertiesParcelableUtilTest.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Copyright (C) 2019 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.net.shared;
-
-import static android.net.shared.LinkPropertiesParcelableUtil.fromStableParcelable;
-import static android.net.shared.LinkPropertiesParcelableUtil.toStableParcelable;
-import static android.net.shared.ParcelableTestUtil.assertFieldCountEquals;
-
-import static org.junit.Assert.assertEquals;
-
-import android.net.InetAddresses;
-import android.net.IpPrefix;
-import android.net.LinkAddress;
-import android.net.LinkProperties;
-import android.net.ProxyInfo;
-import android.net.RouteInfo;
-import android.net.Uri;
-
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.util.Arrays;
-import java.util.Collections;
-
-/**
- * Tests for {@link LinkPropertiesParcelableUtil}
- */
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class LinkPropertiesParcelableUtilTest {
-    private LinkProperties mLinkProperties;
-
-    private static final String TEST_LINKPROPS_IFACE = "TEST_IFACE";
-
-    @Before
-    public void setUp() {
-        mLinkProperties = new LinkProperties();
-        mLinkProperties.setInterfaceName(TEST_LINKPROPS_IFACE);
-        mLinkProperties.setLinkAddresses(Arrays.asList(
-                new LinkAddress(InetAddresses.parseNumericAddress("192.168.0.42"), 16),
-                new LinkAddress(InetAddresses.parseNumericAddress("2001:db8::7"), 42)));
-        mLinkProperties.setDnsServers(Arrays.asList(
-                InetAddresses.parseNumericAddress("2001:db8::42"),
-                InetAddresses.parseNumericAddress("192.168.1.1")
-        ));
-        mLinkProperties.setValidatedPrivateDnsServers(Arrays.asList(
-                InetAddresses.parseNumericAddress("2001:db8::43"),
-                InetAddresses.parseNumericAddress("192.168.42.43")
-        ));
-        mLinkProperties.setPcscfServers(Arrays.asList(
-                InetAddresses.parseNumericAddress("2001:db8::47"),
-                InetAddresses.parseNumericAddress("192.168.42.47")
-        ));
-        mLinkProperties.setUsePrivateDns(true);
-        mLinkProperties.setPrivateDnsServerName("test.example.com");
-        mLinkProperties.setDomains("test1.example.com,test2.example.com");
-        mLinkProperties.addRoute(new RouteInfo(
-                new IpPrefix(InetAddresses.parseNumericAddress("2001:db8::44"), 45),
-                InetAddresses.parseNumericAddress("2001:db8::45"),
-                TEST_LINKPROPS_IFACE,
-                RouteInfo.RTN_UNICAST
-        ));
-        mLinkProperties.addRoute(new RouteInfo(
-                new IpPrefix(InetAddresses.parseNumericAddress("192.168.44.45"), 16),
-                InetAddresses.parseNumericAddress("192.168.45.1"),
-                TEST_LINKPROPS_IFACE,
-                RouteInfo.RTN_THROW
-        ));
-        mLinkProperties.setHttpProxy(new ProxyInfo("test3.example.com", 8000,
-                "excl1.example.com,excl2.example.com"));
-        mLinkProperties.setMtu(5000);
-        mLinkProperties.setTcpBufferSizes("1,2,3,4,5,6");
-        mLinkProperties.setNat64Prefix(
-                new IpPrefix(InetAddresses.parseNumericAddress("2001:db8::48"), 96));
-
-        // Verify that this test does not miss any new field added later.
-        // If any added field is not included in LinkProperties#equals, assertLinkPropertiesEquals
-        // must also be updated.
-        assertFieldCountEquals(14, LinkProperties.class);
-    }
-
-    @Test
-    public void testParcelUnparcel() {
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_NullInterface() {
-        mLinkProperties.setInterfaceName(null);
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_NullPrivateDnsServer() {
-        mLinkProperties.setPrivateDnsServerName(null);
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_NullDomains() {
-        mLinkProperties.setDomains(null);
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_NullProxy() {
-        mLinkProperties.setHttpProxy(null);
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_NullTcpBufferSizes() {
-        mLinkProperties.setTcpBufferSizes(null);
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_EmptyLinkAddresses() {
-        mLinkProperties.setLinkAddresses(Collections.emptyList());
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_EmptyDnses() {
-        mLinkProperties.setDnsServers(Collections.emptyList());
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_EmptyValidatedPrivateDnses() {
-        mLinkProperties.setValidatedPrivateDnsServers(Collections.emptyList());
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_EmptyRoutes() {
-        for (RouteInfo r : mLinkProperties.getAllRoutes()) {
-            mLinkProperties.removeRoute(r);
-        }
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_PacFileProxyInfo() {
-        mLinkProperties.setHttpProxy(new ProxyInfo(Uri.parse("http://pacfile.example.com")));
-        doParcelUnparcelTest();
-    }
-
-    @Test
-    public void testParcelUnparcel_NullNat64Prefix() {
-        mLinkProperties.setNat64Prefix(null);
-        doParcelUnparcelTest();
-    }
-
-    private void doParcelUnparcelTest() {
-        final LinkProperties unparceled = fromStableParcelable(toStableParcelable(mLinkProperties));
-        assertLinkPropertiesEquals(mLinkProperties, unparceled);
-    }
-
-    private static void assertLinkPropertiesEquals(LinkProperties expected, LinkProperties actual) {
-        assertEquals(expected, actual);
-
-        // Equality on stacked links is not tested as they should not be passed to processes using
-        // LinkPropertiesParcelable.
-    }
-}
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index 0633322..3263ef9 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -60,7 +60,6 @@
 import static android.net.NetworkPolicyManager.RULE_NONE;
 import static android.net.NetworkPolicyManager.RULE_REJECT_ALL;
 import static android.net.NetworkPolicyManager.RULE_REJECT_METERED;
-import static android.net.shared.NetworkParcelableUtil.fromStableParcelable;
 
 import static com.android.internal.util.TestUtils.waitForIdleHandler;
 import static com.android.internal.util.TestUtils.waitForIdleLooper;
@@ -125,7 +124,6 @@
 import android.net.NetworkInfo;
 import android.net.NetworkInfo.DetailedState;
 import android.net.NetworkMisc;
-import android.net.NetworkParcelable;
 import android.net.NetworkRequest;
 import android.net.NetworkSpecifier;
 import android.net.NetworkStackClient;
@@ -502,8 +500,7 @@
                 fail(e.getMessage());
             }
 
-            final ArgumentCaptor<NetworkParcelable> nmNetworkCaptor =
-                    ArgumentCaptor.forClass(NetworkParcelable.class);
+            final ArgumentCaptor<Network> nmNetworkCaptor = ArgumentCaptor.forClass(Network.class);
             final ArgumentCaptor<INetworkMonitorCallbacks> nmCbCaptor =
                     ArgumentCaptor.forClass(INetworkMonitorCallbacks.class);
             doNothing().when(mNetworkStack).makeNetworkMonitor(
@@ -543,8 +540,7 @@
                 }
             };
 
-            assertEquals(
-                    mNetworkAgent.netId, fromStableParcelable(nmNetworkCaptor.getValue()).netId);
+            assertEquals(mNetworkAgent.netId, nmNetworkCaptor.getValue().netId);
             mNmCallbacks = nmCbCaptor.getValue();
 
             try {
diff --git a/tools/processors/view_inspector/Android.bp b/tools/processors/view_inspector/Android.bp
index 06ff05e..069e61f 100644
--- a/tools/processors/view_inspector/Android.bp
+++ b/tools/processors/view_inspector/Android.bp
@@ -8,6 +8,7 @@
 
     static_libs: [
         "javapoet",
+        "stub-annotations",
     ],
 
     use_tools_jar: true,
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/AnnotationUtils.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/AnnotationUtils.java
index 2690ee8..c833e47 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/AnnotationUtils.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/AnnotationUtils.java
@@ -16,6 +16,8 @@
 
 package android.processor.view.inspector;
 
+import androidx.annotation.NonNull;
+
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -40,7 +42,7 @@
     private final Elements mElementUtils;
     private final Types mTypeUtils;
 
-    AnnotationUtils(ProcessingEnvironment processingEnv) {
+    AnnotationUtils(@NonNull ProcessingEnvironment processingEnv) {
         mElementUtils = processingEnv.getElementUtils();
         mTypeUtils = processingEnv.getTypeUtils();
     }
@@ -53,7 +55,8 @@
      * @return The mirror of the requested annotation
      * @throws ProcessingException If there is not exactly one of the requested annotation.
      */
-    AnnotationMirror exactlyOneMirror(String qualifiedName, Element element) {
+    @NonNull
+    AnnotationMirror exactlyOneMirror(@NonNull String qualifiedName, @NonNull Element element) {
         final Element targetTypeElment = mElementUtils.getTypeElement(qualifiedName);
         final TypeMirror targetType = targetTypeElment.asType();
         AnnotationMirror result = null;
@@ -89,7 +92,7 @@
      * @param annotationQualifiedName The name of the annotation to check for
      * @return True if the annotation is present, false otherwise
      */
-    boolean hasAnnotation(Element element, String annotationQualifiedName) {
+    boolean hasAnnotation(@NonNull Element element, @NonNull String annotationQualifiedName) {
         final TypeElement namedElement = mElementUtils.getTypeElement(annotationQualifiedName);
 
         if (namedElement != null) {
@@ -118,10 +121,10 @@
      * @return A list containing the requested types
      */
     <T> List<T> typedArrayValuesByName(
-            String propertyName,
-            Class<T> valueClass,
-            Element element,
-            AnnotationMirror annotationMirror) {
+            @NonNull String propertyName,
+            @NonNull Class<T> valueClass,
+            @NonNull Element element,
+            @NonNull AnnotationMirror annotationMirror) {
         return untypedArrayValuesByName(propertyName, element, annotationMirror)
                 .stream()
                 .map(annotationValue -> {
@@ -159,10 +162,11 @@
      * @param annotationMirror An annotation mirror to search for the property
      * @return A list of annotation values, empty list if none found
      */
+    @NonNull
     List<AnnotationValue> untypedArrayValuesByName(
-            String propertyName,
-            Element element,
-            AnnotationMirror annotationMirror) {
+            @NonNull String propertyName,
+            @NonNull Element element,
+            @NonNull AnnotationMirror annotationMirror) {
         return typedValueByName(propertyName, List.class, element, annotationMirror)
                 .map(untypedValues -> {
                     List<AnnotationValue> typedValues = new ArrayList<>(untypedValues.size());
@@ -195,6 +199,7 @@
      * @param <T> The type of the value
      * @return An optional containing the typed value of the named property
      */
+    @NonNull
     <T> Optional<T> typedValueByName(
             String propertyName,
             Class<T> valueClass,
@@ -241,10 +246,11 @@
      * @return An optional containing the untyped value of the named property
      * @see AnnotationValue#getValue()
      */
+    @NonNull
     Optional<Object> untypedValueByName(
-            String propertyName,
-            Element element,
-            AnnotationMirror annotationMirror) {
+            @NonNull String propertyName,
+            @NonNull Element element,
+            @NonNull AnnotationMirror annotationMirror) {
         return valueByName(propertyName, annotationMirror).map(annotationValue -> {
             final Object value = annotationValue.getValue();
 
@@ -269,7 +275,10 @@
      * @param annotationMirror The mirror to search for the property
      * @return The value of the property
      */
-    Optional<AnnotationValue> valueByName(String propertyName, AnnotationMirror annotationMirror) {
+    @NonNull
+    Optional<AnnotationValue> valueByName(
+            @NonNull String propertyName,
+            @NonNull AnnotationMirror annotationMirror) {
         final Map<? extends ExecutableElement, ? extends AnnotationValue> valueMap =
                 annotationMirror.getElementValues();
 
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java
index 1ad7ada..147f054 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableClassModel.java
@@ -16,6 +16,9 @@
 
 package android.processor.view.inspector;
 
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
 import com.squareup.javapoet.ClassName;
 
 import java.util.Collection;
@@ -34,27 +37,29 @@
  * testing {@link InspectionCompanionGenerator}.
  */
 public final class InspectableClassModel {
-    private final ClassName mClassName;
-    private final Map<String, Property> mPropertyMap;
-    private Optional<String> mNodeName = Optional.empty();
+    private final @NonNull ClassName mClassName;
+    private final @NonNull Map<String, Property> mPropertyMap;
+    private @NonNull Optional<String> mNodeName = Optional.empty();
 
     /**
      * @param className The name of the modeled class
      */
-    public InspectableClassModel(ClassName className) {
+    public InspectableClassModel(@NonNull ClassName className) {
         mClassName = className;
         mPropertyMap = new HashMap<>();
     }
 
+    @NonNull
     public ClassName getClassName() {
         return mClassName;
     }
 
+    @NonNull
     public Optional<String> getNodeName() {
         return mNodeName;
     }
 
-    public void setNodeName(Optional<String> nodeName) {
+    public void setNodeName(@NonNull Optional<String> nodeName) {
         mNodeName = nodeName;
     }
 
@@ -63,7 +68,7 @@
      *
      * @param property The property to add or replace
      */
-    public void putProperty(Property property) {
+    public void putProperty(@NonNull Property property) {
         mPropertyMap.put(property.getName(), property);
     }
 
@@ -73,7 +78,8 @@
      * @param name The name of the property
      * @return The property or an empty optional
      */
-    public Optional<Property> getProperty(String name) {
+    @NonNull
+    public Optional<Property> getProperty(@NonNull String name) {
         return Optional.ofNullable(mPropertyMap.get(name));
     }
 
@@ -82,6 +88,7 @@
      *
      * @return An un-ordered collection of properties
      */
+    @NonNull
     public Collection<Property> getAllProperties() {
         return mPropertyMap.values();
     }
@@ -90,8 +97,8 @@
      * Represents a way to access a property, either a getter or a field.
      */
     public static final class Accessor {
-        private final String mName;
-        private final Type mType;
+        private final @NonNull String mName;
+        private final @NonNull Type mType;
 
         /**
          * Construct an accessor for a field.
@@ -100,7 +107,8 @@
          * @return The new accessor
          * @see Type#FIELD
          */
-        static Accessor ofField(String name) {
+        @NonNull
+        static Accessor ofField(@NonNull String name) {
             return new Accessor(name, Type.FIELD);
         }
 
@@ -111,19 +119,22 @@
          * @return The new accessor
          * @see Type#GETTER
          */
-        static Accessor ofGetter(String name) {
+        @NonNull
+        static Accessor ofGetter(@NonNull String name) {
             return new Accessor(name, Type.GETTER);
         }
 
-        public Accessor(String name, Type type) {
+        public Accessor(@NonNull String name, @NonNull Type type) {
             mName = Objects.requireNonNull(name, "Accessor name must not be null");
             mType = Objects.requireNonNull(type, "Accessor type must not be null");
         }
 
+        @NonNull
         public String getName() {
             return mName;
         }
 
+        @NonNull
         public Type getType() {
             return mType;
         }
@@ -135,6 +146,7 @@
          *
          * @return A string representing the invocation of this accessor
          */
+        @NonNull
         public String invocation() {
             switch (mType) {
                 case FIELD:
@@ -168,15 +180,15 @@
      * Model an inspectable property
      */
     public static final class Property {
-        private final String mName;
-        private final Accessor mAccessor;
-        private final Type mType;
+        private final @NonNull String mName;
+        private final @NonNull Accessor mAccessor;
+        private final @NonNull Type mType;
         private boolean mAttributeIdInferrableFromR = true;
         private int mAttributeId = 0;
-        private List<IntEnumEntry> mIntEnumEntries;
-        private List<IntFlagEntry> mIntFlagEntries;
+        private @Nullable List<IntEnumEntry> mIntEnumEntries;
+        private @Nullable List<IntFlagEntry> mIntFlagEntries;
 
-        public Property(String name, Accessor accessor, Type type) {
+        public Property(@NonNull String name, @NonNull Accessor accessor, @NonNull Type type) {
             mName = Objects.requireNonNull(name, "Name must not be null");
             mAccessor = Objects.requireNonNull(accessor, "Accessor must not be null");
             mType = Objects.requireNonNull(type, "Type must not be null");
@@ -204,14 +216,17 @@
             mAttributeIdInferrableFromR = attributeIdInferrableFromR;
         }
 
+        @NonNull
         public String getName() {
             return mName;
         }
 
+        @NonNull
         public Accessor getAccessor() {
             return mAccessor;
         }
 
+        @NonNull
         public Type getType() {
             return mType;
         }
@@ -221,6 +236,7 @@
          *
          * @return A list of mapping entries, empty if absent
          */
+        @NonNull
         public List<IntEnumEntry> getIntEnumEntries() {
             if (mIntEnumEntries != null) {
                 return mIntEnumEntries;
@@ -229,7 +245,7 @@
             }
         }
 
-        public void setIntEnumEntries(List<IntEnumEntry> intEnumEntries) {
+        public void setIntEnumEntries(@NonNull List<IntEnumEntry> intEnumEntries) {
             mIntEnumEntries = intEnumEntries;
         }
 
@@ -238,6 +254,7 @@
          *
          * @return A list of mapping entries, empty if absent
          */
+        @NonNull
         public List<IntFlagEntry> getIntFlagEntries() {
             if (mIntFlagEntries != null) {
                 return mIntFlagEntries;
@@ -246,7 +263,7 @@
             }
         }
 
-        public void setIntFlagEntries(List<IntFlagEntry> intFlagEntries) {
+        public void setIntFlagEntries(@NonNull List<IntFlagEntry> intFlagEntries) {
             mIntFlagEntries = intFlagEntries;
         }
 
@@ -321,14 +338,15 @@
      * @see android.view.inspector.IntEnumMapping
      */
     public static final class IntEnumEntry {
-        private final String mName;
+        private final @NonNull String mName;
         private final int mValue;
 
-        public IntEnumEntry(String name, int value) {
+        public IntEnumEntry(int value, @NonNull String name) {
             mName = Objects.requireNonNull(name, "Name must not be null");
             mValue = value;
         }
 
+        @NonNull
         public String getName() {
             return mName;
         }
@@ -344,29 +362,21 @@
      * @see android.view.inspector.IntFlagMapping
      */
     public static final class IntFlagEntry {
-        private final String mName;
+        private final @NonNull String mName;
         private final int mTarget;
         private final int mMask;
 
-        public IntFlagEntry(String name, int target, int mask) {
+        public IntFlagEntry(int mask, int target, @NonNull String name) {
             mName = Objects.requireNonNull(name, "Name must not be null");
             mTarget = target;
             mMask = mask;
         }
 
-        public IntFlagEntry(String name, int target) {
-            this(name, target, target);
+        public IntFlagEntry(int target, String name) {
+            this(target, target, name);
         }
 
-        /**
-         * Determine if this entry has a bitmask.
-         *
-         * @return True if the bitmask and target are different, false otherwise
-         */
-        public boolean hasMask() {
-            return mTarget != mMask;
-        }
-
+        @NonNull
         public String getName() {
             return mName;
         }
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableNodeNameProcessor.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableNodeNameProcessor.java
index 46819b2..64a60fb 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableNodeNameProcessor.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectableNodeNameProcessor.java
@@ -16,6 +16,8 @@
 
 package android.processor.view.inspector;
 
+import androidx.annotation.NonNull;
+
 import java.util.Optional;
 
 import javax.annotation.processing.ProcessingEnvironment;
@@ -28,17 +30,17 @@
  * @see android.view.inspector.InspectableNodeName
  */
 public final class InspectableNodeNameProcessor implements ModelProcessor {
-    private final String mQualifiedName;
-    private final ProcessingEnvironment mProcessingEnv;
-    private final AnnotationUtils mAnnotationUtils;
+    private final @NonNull String mQualifiedName;
+    private final @NonNull ProcessingEnvironment mProcessingEnv;
+    private final @NonNull AnnotationUtils mAnnotationUtils;
 
     /**
      * @param annotationQualifiedName The qualified name of the annotation to process
      * @param processingEnv The processing environment from the parent processor
      */
     public InspectableNodeNameProcessor(
-            String annotationQualifiedName,
-            ProcessingEnvironment processingEnv) {
+            @NonNull String annotationQualifiedName,
+            @NonNull ProcessingEnvironment processingEnv) {
         mQualifiedName = annotationQualifiedName;
         mProcessingEnv = processingEnv;
         mAnnotationUtils = new AnnotationUtils(processingEnv);
@@ -54,7 +56,7 @@
      * @param model The model this element should be merged into
      */
     @Override
-    public void process(Element element, InspectableClassModel model) {
+    public void process(@NonNull Element element, @NonNull InspectableClassModel model) {
         try {
             final AnnotationMirror mirror =
                     mAnnotationUtils.exactlyOneMirror(mQualifiedName, element);
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java
index 20de90d..2042a68 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectablePropertyProcessor.java
@@ -21,6 +21,8 @@
 import android.processor.view.inspector.InspectableClassModel.IntFlagEntry;
 import android.processor.view.inspector.InspectableClassModel.Property;
 
+import androidx.annotation.NonNull;
+
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Optional;
@@ -45,9 +47,9 @@
  * @see android.view.inspector.InspectableProperty
  */
 public final class InspectablePropertyProcessor implements ModelProcessor {
-    private final String mQualifiedName;
-    private final ProcessingEnvironment mProcessingEnv;
-    private final AnnotationUtils mAnnotationUtils;
+    private final @NonNull String mQualifiedName;
+    private final @NonNull ProcessingEnvironment mProcessingEnv;
+    private final @NonNull AnnotationUtils mAnnotationUtils;
 
     /**
      * Regex that matches methods names of the form {@code #getValue()}.
@@ -130,15 +132,15 @@
      * @param processingEnv           The processing environment from the parent processor
      */
     public InspectablePropertyProcessor(
-            String annotationQualifiedName,
-            ProcessingEnvironment processingEnv) {
+            @NonNull String annotationQualifiedName,
+            @NonNull ProcessingEnvironment processingEnv) {
         mQualifiedName = annotationQualifiedName;
         mProcessingEnv = processingEnv;
         mAnnotationUtils = new AnnotationUtils(processingEnv);
     }
 
     @Override
-    public void process(Element element, InspectableClassModel model) {
+    public void process(@NonNull Element element, @NonNull InspectableClassModel model) {
         try {
             final AnnotationMirror annotation =
                     mAnnotationUtils.exactlyOneMirror(mQualifiedName, element);
@@ -169,7 +171,10 @@
      * @return A property for the getter and annotation
      * @throws ProcessingException If the supplied data is invalid and a property cannot be modeled
      */
-    private Property buildProperty(Element accessor, AnnotationMirror annotation) {
+    @NonNull
+    private Property buildProperty(
+            @NonNull Element accessor,
+            @NonNull AnnotationMirror annotation) {
         final Property property;
         final Optional<String> nameFromAnnotation = mAnnotationUtils
                 .typedValueByName("name", String.class, accessor, annotation);
@@ -227,7 +232,7 @@
      * @param element The element to check
      * @throws ProcessingException If the element's modifiers are invalid
      */
-    private void validateModifiers(Element element) {
+    private void validateModifiers(@NonNull Element element) {
         final Set<Modifier> modifiers = element.getModifiers();
 
         if (!modifiers.contains(Modifier.PUBLIC)) {
@@ -256,7 +261,8 @@
      * @return An {@link ExecutableElement} that represents a getter method.
      * @throws ProcessingException if the element isn't a getter
      */
-    private ExecutableElement ensureGetter(Element element) {
+    @NonNull
+    private ExecutableElement ensureGetter(@NonNull Element element) {
         if (element.getKind() != ElementKind.METHOD) {
             throw new ProcessingException(
                     String.format("Expected a method, got a %s", element.getKind()),
@@ -300,10 +306,10 @@
      * @throws ProcessingException If the property type cannot be resolved or is invalid
      * @see android.view.inspector.InspectableProperty#valueType()
      */
+    @NonNull
     private Property.Type determinePropertyType(
-            Element accessor,
-            AnnotationMirror annotation) {
-
+            @NonNull Element accessor,
+            @NonNull AnnotationMirror annotation) {
         final String valueType = mAnnotationUtils
                 .untypedValueByName("valueType", accessor, annotation)
                 .map(Object::toString)
@@ -437,7 +443,8 @@
      * @return The return or field type of the element
      * @throws ProcessingException If the element is not a field or a method
      */
-    private TypeMirror extractReturnOrFieldType(Element element) {
+    @NonNull
+    private TypeMirror extractReturnOrFieldType(@NonNull Element element) {
         switch (element.getKind()) {
             case FIELD:
                 return element.asType();
@@ -460,7 +467,10 @@
      * @return The property type returned by the getter
      * @throws ProcessingException If the return type is not a primitive or an object
      */
-    private Property.Type convertTypeMirrorToPropertyType(TypeMirror typeMirror, Element element) {
+    @NonNull
+    private Property.Type convertTypeMirrorToPropertyType(
+            @NonNull TypeMirror typeMirror,
+            @NonNull Element element) {
         switch (unboxType(typeMirror)) {
             case BOOLEAN:
                 return Property.Type.BOOLEAN;
@@ -503,10 +513,10 @@
      * @throws ProcessingException If the return type is not an int
      */
     private static void requirePackedIntToBeInt(
-            String typeName,
-            Property.Type returnType,
-            Element accessor,
-            AnnotationMirror annotation) {
+            @NonNull String typeName,
+            @NonNull Property.Type returnType,
+            @NonNull Element accessor,
+            @NonNull AnnotationMirror annotation) {
         if (returnType != Property.Type.INT) {
             throw new ProcessingException(
                     String.format(
@@ -528,7 +538,7 @@
      * @param accessor The getter or field to query
      * @return True if the getter has a color annotation, false otherwise
      */
-    private boolean hasColorAnnotation(Element accessor) {
+    private boolean hasColorAnnotation(@NonNull Element accessor) {
         switch (unboxType(extractReturnOrFieldType(accessor))) {
             case INT:
                 for (String name : COLOR_INT_ANNOTATION_NAMES) {
@@ -555,7 +565,7 @@
      * @param accessor The getter or field to query
      * @return True if the accessor is an integer and has a resource ID annotation, false otherwise
      */
-    private boolean hasResourceIdAnnotation(Element accessor) {
+    private boolean hasResourceIdAnnotation(@NonNull Element accessor) {
         if (unboxType(extractReturnOrFieldType(accessor)) == TypeKind.INT) {
             for (String name : RESOURCE_ID_ANNOTATION_NAMES) {
                 if (mAnnotationUtils.hasAnnotation(accessor, name)) {
@@ -581,7 +591,8 @@
      * @param getter An element representing a getter
      * @return A string property name
      */
-    private String inferPropertyNameFromGetter(ExecutableElement getter) {
+    @NonNull
+    private String inferPropertyNameFromGetter(@NonNull ExecutableElement getter) {
         final String name = getter.getSimpleName().toString();
 
         if (GETTER_GET_PREFIX.matcher(name).find()) {
@@ -600,7 +611,6 @@
      * {@link android.view.inspector.InspectableProperty.EnumMap} annotations into
      * {@link IntEnumEntry} objects. Further validation should be handled elsewhere
      *
-     * @see android.view.inspector.IntEnumMapping
      * @see android.view.inspector.InspectableProperty#enumMapping()
      * @param accessor The accessor of the property, used for exceptions
      * @param annotation The {@link android.view.inspector.InspectableProperty} annotation to
@@ -608,9 +618,10 @@
      * @return A list of int enum entries, in the order specified in source
      * @throws ProcessingException if mapping doesn't exist or is invalid
      */
+    @NonNull
     private List<IntEnumEntry> processEnumMapping(
-            Element accessor,
-            AnnotationMirror annotation) {
+            @NonNull Element accessor,
+            @NonNull AnnotationMirror annotation) {
         List<AnnotationMirror> enumAnnotations = mAnnotationUtils.typedArrayValuesByName(
                 "enumMapping", AnnotationMirror.class, accessor, annotation);
         List<IntEnumEntry> enumEntries = new ArrayList<>(enumAnnotations.size());
@@ -623,23 +634,19 @@
         for (AnnotationMirror enumAnnotation : enumAnnotations) {
             final String name = mAnnotationUtils.typedValueByName(
                     "name", String.class, accessor, enumAnnotation)
-                    .orElseThrow(() -> {
-                        throw new ProcessingException(
-                                "Name is required for @EnumMap",
-                                accessor,
-                                enumAnnotation);
-                    });
+                    .orElseThrow(() -> new ProcessingException(
+                            "Name is required for @EnumMap",
+                            accessor,
+                            enumAnnotation));
 
             final int value = mAnnotationUtils.typedValueByName(
                     "value", Integer.class, accessor, enumAnnotation)
-                    .orElseThrow(() -> {
-                        throw new ProcessingException(
-                                "Value is required for @EnumMap",
-                                accessor,
-                                enumAnnotation);
-                    });
+                    .orElseThrow(() -> new ProcessingException(
+                            "Value is required for @EnumMap",
+                            accessor,
+                            enumAnnotation));
 
-            enumEntries.add(new IntEnumEntry(name, value));
+            enumEntries.add(new IntEnumEntry(value, name));
         }
 
         return enumEntries;
@@ -660,9 +667,10 @@
      * @return A list of int flags entries, in the order specified in source
      * @throws ProcessingException if mapping doesn't exist or is invalid
      */
+    @NonNull
     private List<IntFlagEntry> processFlagMapping(
-            Element accessor,
-            AnnotationMirror annotation) {
+            @NonNull Element accessor,
+            @NonNull AnnotationMirror annotation) {
         List<AnnotationMirror> flagAnnotations = mAnnotationUtils.typedArrayValuesByName(
                 "flagMapping", AnnotationMirror.class, accessor, annotation);
         List<IntFlagEntry> flagEntries = new ArrayList<>(flagAnnotations.size());
@@ -675,29 +683,25 @@
         for (AnnotationMirror flagAnnotation : flagAnnotations) {
             final String name = mAnnotationUtils.typedValueByName(
                     "name", String.class, accessor, flagAnnotation)
-                    .orElseThrow(() -> {
-                        throw new ProcessingException(
-                                "Name is required for @FlagMap",
-                                accessor,
-                                flagAnnotation);
-                    });
+                    .orElseThrow(() -> new ProcessingException(
+                            "Name is required for @FlagMap",
+                            accessor,
+                            flagAnnotation));
 
             final int target = mAnnotationUtils.typedValueByName(
                     "target", Integer.class, accessor, flagAnnotation)
-                    .orElseThrow(() -> {
-                        throw new ProcessingException(
-                                "Target is required for @FlagMap",
-                                accessor,
-                                flagAnnotation);
-                    });
+                    .orElseThrow(() -> new ProcessingException(
+                            "Target is required for @FlagMap",
+                            accessor,
+                            flagAnnotation));
 
             final Optional<Integer> mask = mAnnotationUtils.typedValueByName(
                     "mask", Integer.class, accessor, flagAnnotation);
 
             if (mask.isPresent()) {
-                flagEntries.add(new IntFlagEntry(name, target, mask.get()));
+                flagEntries.add(new IntFlagEntry(mask.get(), target, name));
             } else {
-                flagEntries.add(new IntFlagEntry(name, target));
+                flagEntries.add(new IntFlagEntry(target, name));
             }
         }
 
@@ -710,7 +714,7 @@
      * @param type The type mirror to check
      * @return True if the type is a boolean
      */
-    private boolean isBoolean(TypeMirror type) {
+    private boolean isBoolean(@NonNull TypeMirror type) {
         if (type.getKind() == TypeKind.DECLARED) {
             return mProcessingEnv.getTypeUtils().unboxedType(type).getKind() == TypeKind.BOOLEAN;
         } else {
@@ -724,7 +728,8 @@
      * @param typeMirror The type mirror to unbox
      * @return The same type mirror, or an unboxed primitive version
      */
-    private TypeKind unboxType(TypeMirror typeMirror) {
+    @NonNull
+    private TypeKind unboxType(@NonNull TypeMirror typeMirror) {
         final TypeKind typeKind = typeMirror.getKind();
 
         if (typeKind.isPrimitive()) {
@@ -746,7 +751,7 @@
      * @param typeMirror The type mirror to test
      * @return True if it represents a subclass of color, false otherwise
      */
-    private boolean isColorType(TypeMirror typeMirror) {
+    private boolean isColorType(@NonNull TypeMirror typeMirror) {
         final TypeElement colorType = mProcessingEnv
                 .getElementUtils()
                 .getTypeElement("android.graphics.Color");
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java
index 6f6c1aa..c428a46 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/InspectionCompanionGenerator.java
@@ -16,11 +16,12 @@
 
 package android.processor.view.inspector;
 
-
 import android.processor.view.inspector.InspectableClassModel.IntEnumEntry;
 import android.processor.view.inspector.InspectableClassModel.IntFlagEntry;
 import android.processor.view.inspector.InspectableClassModel.Property;
 
+import androidx.annotation.NonNull;
+
 import com.squareup.javapoet.ClassName;
 import com.squareup.javapoet.CodeBlock;
 import com.squareup.javapoet.FieldSpec;
@@ -34,9 +35,11 @@
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.NoSuchElementException;
-import java.util.Optional;
+import java.util.stream.Collectors;
 
 import javax.annotation.processing.Filer;
 import javax.lang.model.element.Modifier;
@@ -45,8 +48,8 @@
  * Generates a source file defining a {@link android.view.inspector.InspectionCompanion}.
  */
 public final class InspectionCompanionGenerator {
-    private final Filer mFiler;
-    private final Class mRequestingClass;
+    private final @NonNull Filer mFiler;
+    private final @NonNull Class mRequestingClass;
 
     /**
      * The class name for {@code R.java}.
@@ -72,10 +75,9 @@
             "android.view.inspector", "PropertyReader");
 
     /**
-     * The class name of {@link android.view.inspector.IntEnumMapping}.
+     * The class name of {@link android.util.SparseArray}.
      */
-    private static final ClassName INT_ENUM_MAPPING = ClassName.get(
-            "android.view.inspector", "IntEnumMapping");
+    private static final ClassName SPARSE_ARRAY = ClassName.get("android.util", "SparseArray");
 
     /**
      * The class name of {@link android.view.inspector.IntFlagMapping}.
@@ -84,17 +86,6 @@
             "android.view.inspector", "IntFlagMapping");
 
     /**
-     * The {@code mPropertiesMapped} field.
-     */
-    private static final FieldSpec M_PROPERTIES_MAPPED = FieldSpec
-            .builder(TypeName.BOOLEAN, "mPropertiesMapped", Modifier.PRIVATE)
-            .initializer("false")
-            .addJavadoc(
-                    "Set by {@link #mapProperties($T)} once properties have been mapped.\n",
-                    PROPERTY_MAPPER)
-            .build();
-
-    /**
      * The suffix of the generated class name after the class's binary name.
      */
     private static final String GENERATED_CLASS_SUFFIX = "$InspectionCompanion";
@@ -110,7 +101,7 @@
      * @param filer A filer to write the generated source to
      * @param requestingClass A class object representing the class that invoked the generator
      */
-    public InspectionCompanionGenerator(Filer filer, Class requestingClass) {
+    public InspectionCompanionGenerator(@NonNull Filer filer, @NonNull Class requestingClass) {
         mFiler = filer;
         mRequestingClass = requestingClass;
     }
@@ -121,7 +112,7 @@
      * @param model The model to generated
      * @throws IOException From the Filer
      */
-    public void generate(InspectableClassModel model) throws IOException {
+    public void generate(@NonNull InspectableClassModel model) throws IOException {
         generateFile(model).writeTo(mFiler);
     }
 
@@ -133,7 +124,8 @@
      * @param model The model to generate from
      * @return A generated file of an {@link android.view.inspector.InspectionCompanion}
      */
-    JavaFile generateFile(InspectableClassModel model) {
+    @NonNull
+    JavaFile generateFile(@NonNull InspectableClassModel model) {
         return JavaFile
                 .builder(model.getClassName().packageName(), generateTypeSpec(model))
                 .indent("    ")
@@ -147,8 +139,12 @@
      * @param model The model to generate from
      * @return A TypeSpec of the inspection companion
      */
-    private TypeSpec generateTypeSpec(InspectableClassModel model) {
-        final List<PropertyIdField> propertyIdFields = generatePropertyIdFields(model);
+    @NonNull
+    private TypeSpec generateTypeSpec(@NonNull InspectableClassModel model) {
+        final List<Property> properties = new ArrayList<>(model.getAllProperties());
+        properties.sort(Comparator.comparing(Property::getName));
+
+        final Map<Property, FieldSpec> fields = generateIdFieldSpecs(properties);
 
         TypeSpec.Builder builder = TypeSpec
                 .classBuilder(generateClassName(model))
@@ -158,238 +154,325 @@
                 .addJavadoc("Inspection companion for {@link $T}.\n\n", model.getClassName())
                 .addJavadoc("Generated by {@link $T}\n", getClass())
                 .addJavadoc("on behalf of {@link $T}.\n", mRequestingClass)
-                .addField(M_PROPERTIES_MAPPED);
+                .addField(FieldSpec
+                        .builder(TypeName.BOOLEAN, "mPropertiesMapped", Modifier.PRIVATE)
+                        .initializer("false")
+                        .addJavadoc("Guards against reading properties before mapping them.\n")
+                        .build())
+                .addFields(properties.stream().map(fields::get).collect(Collectors.toList()))
+                .addMethod(generateMapProperties(properties, fields))
+                .addMethod(generateReadProperties(properties, fields, model.getClassName()));
 
-        for (PropertyIdField propertyIdField : propertyIdFields) {
-            builder.addField(propertyIdField.mFieldSpec);
-        }
-
-        builder.addMethod(generateMapProperties(propertyIdFields))
-                .addMethod(generateReadProperties(model, propertyIdFields));
-
-        generateGetNodeName(model).ifPresent(builder::addMethod);
+        model.getNodeName().ifPresent(name -> builder.addMethod(generateGetNodeName(name)));
 
         return builder.build();
     }
 
     /**
-     * Build a list of {@link PropertyIdField}'s for a model.
+     * Map properties to fields to store the mapping IDs in the generated inspection companion.
      *
-     * To insure idempotency of the generated code, this method sorts the list of properties
-     * alphabetically by name.
-     *
-     * A {@link NameAllocator} is used to ensure that the field names are valid Java identifiers,
-     * and it prevents overlaps in names by suffixing them as needed.
-     *
-     * @param model The model to get properties from
-     * @return A list of properties and fields
+     * @param properties A list of property models
+     * @return A map of properties to their {@link FieldSpec}
      */
-    private List<PropertyIdField> generatePropertyIdFields(InspectableClassModel model) {
-        final NameAllocator nameAllocator = new NameAllocator();
-        final List<Property> sortedProperties = new ArrayList<>(model.getAllProperties());
-        final List<PropertyIdField> propertyIdFields = new ArrayList<>(sortedProperties.size());
+    @NonNull
+    private Map<Property, FieldSpec> generateIdFieldSpecs(@NonNull List<Property> properties) {
+        final Map<Property, FieldSpec> fields = new HashMap<>();
+        final NameAllocator fieldNames = new NameAllocator();
+        fieldNames.newName("mPropertiesMapped");
 
-        sortedProperties.sort(Comparator.comparing(Property::getName));
-
-        for (Property property : sortedProperties) {
-            // Format a property to a member field name like "someProperty" -> "mSomePropertyId"
-            final String memberName = String.format(
+        for (Property property : properties) {
+            final String memberName = fieldNames.newName(String.format(
                     "m%s%sId",
                     property.getName().substring(0, 1).toUpperCase(),
-                    property.getName().substring(1));
-            final FieldSpec fieldSpec = FieldSpec
-                    .builder(TypeName.INT, nameAllocator.newName(memberName), Modifier.PRIVATE)
-                    .addJavadoc("Property ID of {@code $L}.\n", property.getName())
-                    .build();
+                    property.getName().substring(1)));
 
-            propertyIdFields.add(new PropertyIdField(fieldSpec, property));
+            fields.put(property, FieldSpec
+                    .builder(TypeName.INT, memberName, Modifier.PRIVATE)
+                    .addJavadoc("Property ID of {@code $L}.\n", property.getName())
+                    .build());
         }
 
-        return propertyIdFields;
+        return fields;
     }
 
     /**
-     * Generate a method definition for
-     * {@link android.view.inspector.InspectionCompanion#getNodeName()}, if needed.
-     *
-     * If {@link InspectableClassModel#getNodeName()} is empty, This method returns an empty
-     * optional, otherwise, it generates a simple method that returns the string value of the
-     * node name.
-     *
-     * @param model The model to generate from
-     * @return The method definition or an empty Optional
-     */
-    private Optional<MethodSpec> generateGetNodeName(InspectableClassModel model) {
-        return model.getNodeName().map(nodeName -> MethodSpec.methodBuilder("getNodeName")
-                .addAnnotation(Override.class)
-                .addModifiers(Modifier.PUBLIC)
-                .returns(String.class)
-                .addStatement("return $S", nodeName)
-                .build());
-    }
-
-    /**
-     * Generate a method definition for
+     * Generates an implementation of
      * {@link android.view.inspector.InspectionCompanion#mapProperties(
      * android.view.inspector.PropertyMapper)}.
      *
-     * @param propertyIdFields A list of properties to map to ID fields
-     * @return The method definition
+     * Example:
+     * <pre>
+     *     @Override
+     *     public void mapProperties(PropertyMapper propertyMapper) {
+     *         mValueId = propertyMapper.mapInt("value", R.attr.value);
+     *         mPropertiesMapped = true;
+     *     }
+     * </pre>
+     *
+     * @param properties A sorted list of property models
+     * @param fields A map of properties to their ID field specs
+     * @return A method definition
      */
-    private MethodSpec generateMapProperties(List<PropertyIdField> propertyIdFields) {
+    @NonNull
+    private MethodSpec generateMapProperties(
+            @NonNull List<Property> properties,
+            @NonNull Map<Property, FieldSpec> fields) {
+        final NameAllocator mappingVariables = new NameAllocator();
+
         final MethodSpec.Builder builder = MethodSpec.methodBuilder("mapProperties")
                 .addAnnotation(Override.class)
                 .addModifiers(Modifier.PUBLIC)
                 .addParameter(PROPERTY_MAPPER, "propertyMapper");
 
-        propertyIdFields.forEach(p -> builder.addStatement(generatePropertyMapperInvocation(p)));
-        builder.addStatement("$N = true", M_PROPERTIES_MAPPED);
+        // Reserve existing names
+        mappingVariables.newName("mPropertiesMapped");
+        mappingVariables.newName("propertyMapper");
+        properties.forEach(p -> mappingVariables.newName(fields.get(p).name));
 
-        return builder.build();
-    }
-
-    /**
-     * Generate a method definition for
-     * {@link android.view.inspector.InspectionCompanion#readProperties(
-     * Object, android.view.inspector.PropertyReader)}.
-     *
-     * @param model The model to generate from
-     * @param propertyIdFields A list of properties and ID fields to read from
-     * @return The method definition
-     */
-    private MethodSpec generateReadProperties(
-            InspectableClassModel model,
-            List<PropertyIdField> propertyIdFields) {
-        final MethodSpec.Builder builder =  MethodSpec.methodBuilder("readProperties")
-                .addAnnotation(Override.class)
-                .addModifiers(Modifier.PUBLIC)
-                .addParameter(model.getClassName(), "node")
-                .addParameter(PROPERTY_READER, "propertyReader")
-                .addCode(generatePropertyMapInitializationCheck());
-
-        for (PropertyIdField propertyIdField : propertyIdFields) {
-            builder.addStatement(
-                    "propertyReader.read$L($N, node.$L)",
-                    methodSuffixForPropertyType(propertyIdField.mProperty.getType()),
-                    propertyIdField.mFieldSpec,
-                    propertyIdField.mProperty.getAccessor().invocation());
-        }
-
-        return builder.build();
-    }
-
-    /**
-     * Generate a statement maps a property with a {@link android.view.inspector.PropertyMapper}.
-     *
-     * @param propertyIdField The property model and ID field to generate from
-     * @return A statement that invokes property mapper method
-     */
-    private CodeBlock generatePropertyMapperInvocation(PropertyIdField propertyIdField) {
-        final CodeBlock.Builder builder = CodeBlock.builder();
-        final Property property = propertyIdField.mProperty;
-        final FieldSpec fieldSpec = propertyIdField.mFieldSpec;
-
-        builder.add(
-                "$N = propertyMapper.map$L($S,$W",
-                fieldSpec,
-                methodSuffixForPropertyType(property.getType()),
-                property.getName());
-
-        if (property.isAttributeIdInferrableFromR()) {
-            builder.add("$T.attr.$L", R_CLASS_NAME, property.getName());
-        } else {
-            if (property.getAttributeId() == ID_NULL) {
-                builder.add("$L", ID_NULL);
-            } else {
-                builder.add("$L", hexLiteral(property.getAttributeId()));
+        for (Property property : properties) {
+            final FieldSpec field = fields.get(property);
+            switch (property.getType()) {
+                case INT_ENUM:
+                    builder.addCode(generateIntEnumPropertyMapperInvocation(
+                            property,
+                            field,
+                            mappingVariables.newName(property.getName() + "EnumMapping")));
+                    break;
+                case INT_FLAG:
+                    builder.addCode(generateIntFlagPropertyMapperInvocation(
+                            property,
+                            field,
+                            mappingVariables.newName(property.getName() + "FlagMapping")));
+                    break;
+                default:
+                    builder.addCode(generateSimplePropertyMapperInvocation(property, field));
             }
         }
 
-        switch (property.getType()) {
-            case INT_ENUM:
-                builder.add(",$W");
-                builder.add(generateIntEnumMappingBuilder(property.getIntEnumEntries()));
-                break;
-            case INT_FLAG:
-                builder.add(",$W");
-                builder.add(generateIntFlagMappingBuilder(property.getIntFlagEntries()));
-                break;
-        }
+        builder.addStatement("mPropertiesMapped = true");
 
-        return builder.add(")").build();
+        return builder.build();
     }
 
     /**
-     * Generate a check that throws
-     * {@link android.view.inspector.InspectionCompanion.UninitializedPropertyMapException}
-     * if the properties haven't been initialized.
+     * Generate a {@link android.view.inspector.PropertyMapper} invocation.
      *
+     * Example:
      * <pre>
-     *     if (!mPropertiesMapped) {
-     *         throw new InspectionCompanion.UninitializedPropertyMapException();
-     *     }
+     *     mValueId = propertyMapper.mapInt("value", R.attr.value);
      * </pre>
      *
-     * @return A codeblock containing the property map initialization check
+     * @param property A property model to map
+     * @param field The property ID field for the property
+     * @return A code block containing a statement
      */
-    private CodeBlock generatePropertyMapInitializationCheck() {
-        return CodeBlock.builder()
-                .beginControlFlow("if (!$N)", M_PROPERTIES_MAPPED)
+    @NonNull
+    private CodeBlock generateSimplePropertyMapperInvocation(
+            @NonNull Property property,
+            @NonNull FieldSpec field) {
+        return CodeBlock
+                .builder()
                 .addStatement(
-                        "throw new $T()",
-                        INSPECTION_COMPANION.nestedClass("UninitializedPropertyMapException"))
-                .endControlFlow()
+                        "$N = propertyMapper.map$L($S, $L)",
+                        field,
+                        methodSuffixForPropertyType(property.getType()),
+                        property.getName(),
+                        generateAttributeId(property))
                 .build();
     }
 
     /**
-     * Generate an invocation of {@link android.view.inspector.IntEnumMapping.Builder}.
+     * Generate a {@link android.view.inspector.PropertyMapper} invocation for an int enum.
      *
+     * Example:
      * <pre>
-     *      new IntEnumMapping.Builder()
-     *          .addValue("ONE", 1)
-     *          .build()
+     *     final SparseArray<String> valueEnumMapping = new SparseArray<>();
+     *     valueEnumMapping.put(1, "ONE");
+     *     valueEnumMapping.put(2, "TWO");
+     *     mValueId = propertyMapper.mapIntEnum("value", R.attr.value, valueEnumMapping::get);
      * </pre>
      *
-     * @return A codeblock containing the an int enum mapping builder
+     * @param property A property model to map
+     * @param field The property ID field for the property
+     * @param variable The name of a local variable to use to store the mapping in
+     * @return A code block containing a series of statements
      */
-    private CodeBlock generateIntEnumMappingBuilder(List<IntEnumEntry> intEnumEntries) {
-        final ArrayList<IntEnumEntry> sortedEntries = new ArrayList<>(intEnumEntries);
-        sortedEntries.sort(Comparator.comparing(IntEnumEntry::getValue));
+    @NonNull
+    private CodeBlock generateIntEnumPropertyMapperInvocation(
+            @NonNull Property property,
+            @NonNull FieldSpec field,
+            @NonNull String variable) {
+        final CodeBlock.Builder builder = CodeBlock.builder();
 
-        final CodeBlock.Builder builder = CodeBlock.builder()
-                .add("new $T()$>", INT_ENUM_MAPPING.nestedClass("Builder"));
+        final List<IntEnumEntry> enumEntries = property.getIntEnumEntries();
+        enumEntries.sort(Comparator.comparing(IntEnumEntry::getValue));
 
-        for (IntEnumEntry entry : sortedEntries) {
-            builder.add("\n.addValue($S, $L)", entry.getName(), entry.getValue());
+        builder.addStatement(
+                "final $1T<$2T> $3N = new $1T<>()",
+                SPARSE_ARRAY,
+                String.class,
+                variable);
+
+        for (IntEnumEntry enumEntry : enumEntries) {
+            builder.addStatement(
+                    "$N.put($L, $S)",
+                    variable,
+                    enumEntry.getValue(),
+                    enumEntry.getName());
         }
 
-        return builder.add("\n.build()$<").build();
+        builder.addStatement(
+                "$N = propertyMapper.mapIntEnum($S, $L, $N::get)",
+                field,
+                property.getName(),
+                generateAttributeId(property),
+                variable);
+
+        return builder.build();
     }
 
-    private CodeBlock generateIntFlagMappingBuilder(List<IntFlagEntry> intFlagEntries) {
-        final ArrayList<IntFlagEntry> sortedEntries = new ArrayList<>(intFlagEntries);
-        sortedEntries.sort(Comparator.comparing(IntFlagEntry::getName));
+    /**
+     * Generate a {@link android.view.inspector.PropertyMapper} invocation for an int flag.
+     *
+     * Example:
+     * <pre>
+     *     final IntFlagMapping valueFlagMapping = new IntFlagMapping();
+     *     valueFlagMapping.add(0x00000003, 0x00000001, "ONE");
+     *     valueFlagMapping.add(0x00000003, 0x00000002, "TWO");
+     *     mValueId = propertyMapper.mapIntFlag("value", R.attr.value, valueFlagMapping::get);
+     * </pre>
+     *
+     * @param property A property model to map
+     * @param field The property ID field for the property
+     * @param variable The name of a local variable to use to store the mapping in
+     * @return A code block containing a series of statements
+     */
+    @NonNull
+    private CodeBlock generateIntFlagPropertyMapperInvocation(
+            @NonNull Property property,
+            @NonNull FieldSpec field,
+            @NonNull String variable) {
+        final CodeBlock.Builder builder = CodeBlock.builder();
 
-        final CodeBlock.Builder builder = CodeBlock.builder()
-                .add("new $T()$>", INT_FLAG_MAPPING.nestedClass("Builder"));
+        final List<IntFlagEntry> flagEntries = property.getIntFlagEntries();
+        flagEntries.sort(Comparator.comparing(IntFlagEntry::getName));
 
-        for (IntFlagEntry entry : sortedEntries) {
-            if (entry.hasMask()) {
-                builder.add(
-                        "\n.addFlag($S, $L, $L)",
-                        entry.getName(),
-                        hexLiteral(entry.getTarget()),
-                        hexLiteral(entry.getMask()));
-            } else {
-                builder.add(
-                        "\n.addFlag($S, $L)",
-                        entry.getName(),
-                        hexLiteral(entry.getTarget()));
-            }
+        builder.addStatement(
+                "final $1T $2N = new $1T()",
+                INT_FLAG_MAPPING,
+                variable);
+
+        for (IntFlagEntry flagEntry : flagEntries) {
+            builder.addStatement(
+                    "$N.add($L, $L, $S)",
+                    variable,
+                    hexLiteral(flagEntry.getMask()),
+                    hexLiteral(flagEntry.getTarget()),
+                    flagEntry.getName());
         }
 
-        return builder.add("\n.build()$<").build();
+        builder.addStatement(
+                "$N = propertyMapper.mapIntFlag($S, $L, $N::get)",
+                field,
+                property.getName(),
+                generateAttributeId(property),
+                variable);
+
+        return builder.build();
+    }
+
+    /**
+     * Generate a literal attribute ID or reference to {@link android.R.attr}.
+     *
+     * Example: {@code R.attr.value} or {@code 0xdecafbad}.
+     *
+     * @param property A property model
+     * @return A code block containing the attribute ID
+     */
+    @NonNull
+    private CodeBlock generateAttributeId(@NonNull Property property) {
+        if (property.isAttributeIdInferrableFromR()) {
+            return CodeBlock.of("$T.attr.$L", R_CLASS_NAME, property.getName());
+        } else {
+            if (property.getAttributeId() == ID_NULL) {
+                return CodeBlock.of("$L", ID_NULL);
+            } else {
+                return CodeBlock.of("$L", hexLiteral(property.getAttributeId()));
+            }
+        }
+    }
+
+    /**
+     * Generate an implementation of
+     * {@link android.view.inspector.InspectionCompanion#readProperties(Object,
+     * android.view.inspector.PropertyReader)}.
+     *
+     * Example:
+     * <pre>
+     *     @Override
+     *     public void readProperties(MyNode node, PropertyReader propertyReader) {
+     *         if (!mPropertiesMapped) {
+     *             throw new InspectionCompanion.UninitializedPropertyMapException();
+     *         }
+     *         propertyReader.readInt(mValueId, node.getValue());
+     *     }
+     * </pre>
+     *
+     * @param properties An ordered list of property models
+     * @param fields A map from properties to their field specs
+     * @param nodeClass The class of the node, used for the parameter type
+     * @return A method definition
+     */
+    @NonNull
+    private MethodSpec generateReadProperties(
+            @NonNull List<Property> properties,
+            @NonNull Map<Property, FieldSpec> fields,
+            @NonNull ClassName nodeClass) {
+        final MethodSpec.Builder builder =  MethodSpec.methodBuilder("readProperties")
+                .addAnnotation(Override.class)
+                .addModifiers(Modifier.PUBLIC)
+                .addParameter(nodeClass, "node")
+                .addParameter(PROPERTY_READER, "propertyReader")
+                .beginControlFlow("if (!mPropertiesMapped)")
+                .addStatement(
+                        "throw new $T()",
+                        INSPECTION_COMPANION.nestedClass("UninitializedPropertyMapException"))
+                .endControlFlow();
+
+        for (Property property : properties) {
+            builder.addStatement(
+                    "propertyReader.read$L($N, node.$L)",
+                    methodSuffixForPropertyType(property.getType()),
+                    fields.get(property),
+                    property.getAccessor().invocation());
+        }
+
+        return builder.build();
+    }
+
+    /**
+     * Generate an implementation of
+     * {@link android.view.inspector.InspectionCompanion#getNodeName()}.
+     *
+     * Example:
+     * <pre>
+     *     @Override
+     *     public String getNodeName() {
+     *         return "nodeName";
+     *     }
+     * </pre>
+     *
+     * @param nodeName The name of this node
+     * @return A method definition that returns the node name
+     */
+    @NonNull
+    private MethodSpec generateGetNodeName(@NonNull String nodeName) {
+        return MethodSpec.methodBuilder("getNodeName")
+                .addAnnotation(Override.class)
+                .addModifiers(Modifier.PUBLIC)
+                .returns(String.class)
+                .addStatement("return $S", nodeName)
+                .build();
     }
 
     /**
@@ -397,14 +480,15 @@
      *
      * The generated class is added to the same package as the source class. If the class in the
      * model is a nested class, the nested class names are joined with {@code "$"}. The suffix
-     * {@code "$$InspectionCompanion"} is always added the the generated name. E.g.: For modeled
+     * {@code "$InspectionCompanion"} is always added to the generated name. E.g.: For modeled
      * class {@code com.example.Outer.Inner}, the generated class name will be
-     * {@code com.example.Outer$Inner$$InspectionCompanion}.
+     * {@code com.example.Outer$Inner$InspectionCompanion}.
      *
      * @param model The model to generate from
      * @return A class name for the generated inspection companion class
      */
-    private static ClassName generateClassName(InspectableClassModel model) {
+    @NonNull
+    private static ClassName generateClassName(@NonNull InspectableClassModel model) {
         final ClassName className = model.getClassName();
 
         return ClassName.get(
@@ -418,7 +502,8 @@
      * @param type The requested property type
      * @return A method suffix
      */
-    private static String methodSuffixForPropertyType(Property.Type type) {
+    @NonNull
+    private static String methodSuffixForPropertyType(@NonNull Property.Type type) {
         switch (type) {
             case BOOLEAN:
                 return "Boolean";
@@ -453,20 +538,14 @@
         }
     }
 
+    /**
+     * Format an int as an 8 digit hex literal
+     *
+     * @param value The value to format
+     * @return A string representation of the hex literal
+     */
+    @NonNull
     private static String hexLiteral(int value) {
         return String.format("0x%08x", value);
     }
-
-    /**
-     * Value class that holds a {@link Property} and a {@link FieldSpec} for that property.
-     */
-    private static final class PropertyIdField {
-        private final FieldSpec mFieldSpec;
-        private final Property mProperty;
-
-        private PropertyIdField(FieldSpec fieldSpec, Property property) {
-            mFieldSpec = fieldSpec;
-            mProperty = property;
-        }
-    }
 }
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/ModelProcessor.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/ModelProcessor.java
index 6f52260..ab38f4c 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/ModelProcessor.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/ModelProcessor.java
@@ -16,6 +16,8 @@
 
 package android.processor.view.inspector;
 
+import androidx.annotation.NonNull;
+
 import javax.lang.model.element.Element;
 
 /**
@@ -28,5 +30,5 @@
      * @param element The annotated element to operate on
      * @param model The model this element should be merged into
      */
-    void process(Element element, InspectableClassModel model);
+    void process(@NonNull Element element, @NonNull InspectableClassModel model);
 }
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java
index fd142c6..d9ed1fb 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/PlatformInspectableProcessor.java
@@ -18,6 +18,8 @@
 
 import static javax.tools.Diagnostic.Kind.ERROR;
 
+import androidx.annotation.NonNull;
+
 import com.squareup.javapoet.ClassName;
 
 import java.io.IOException;
@@ -63,7 +65,9 @@
     }
 
     @Override
-    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
+    public boolean process(
+            @NonNull Set<? extends TypeElement> annotations,
+            @NonNull RoundEnvironment roundEnv) {
         final Map<String, InspectableClassModel> modelMap = new HashMap<>();
 
         for (TypeElement annotation : annotations) {
@@ -109,9 +113,9 @@
      * @param modelMap A map of qualified class names to models
      */
     private void runModelProcessor(
-            Set<? extends Element> elements,
-            ModelProcessor processor,
-            Map<String, InspectableClassModel> modelMap) {
+            @NonNull Set<? extends Element> elements,
+            @NonNull ModelProcessor processor,
+            @NonNull Map<String, InspectableClassModel> modelMap) {
         for (Element element : elements) {
             final Optional<TypeElement> classElement = enclosingClassElement(element);
 
@@ -149,7 +153,7 @@
      * @param typeElement A type element representing the class to check
      * @return f the class contains a class named {@code InspectionCompanion}
      */
-    private static boolean hasNestedInspectionCompanion(TypeElement typeElement) {
+    private static boolean hasNestedInspectionCompanion(@NonNull TypeElement typeElement) {
         for (TypeElement nestedClass : ElementFilter.typesIn(typeElement.getEnclosedElements())) {
             if (nestedClass.getSimpleName().toString().equals("InspectionCompanion")) {
                 return true;
@@ -167,7 +171,8 @@
      * @param element An element to search from
      * @return A TypeElement of the nearest enclosing class or an empty optional
      */
-    private static Optional<TypeElement> enclosingClassElement(Element element) {
+    @NonNull
+    private static Optional<TypeElement> enclosingClassElement(@NonNull Element element) {
         Element cursor = element;
 
         while (cursor != null) {
@@ -186,7 +191,7 @@
      *
      * @param message Message to print
      */
-    private void fail(String message) {
+    private void fail(@NonNull String message) {
         processingEnv.getMessager().printMessage(ERROR, message);
     }
 
@@ -196,7 +201,7 @@
      * @param message Message to print
      * @param element The element that failed
      */
-    private void fail(String message, Element element) {
+    private void fail(@NonNull String message, @NonNull Element element) {
         processingEnv.getMessager().printMessage(ERROR, message, element);
     }
 }
diff --git a/tools/processors/view_inspector/src/java/android/processor/view/inspector/ProcessingException.java b/tools/processors/view_inspector/src/java/android/processor/view/inspector/ProcessingException.java
index b4c6466..7389c24 100644
--- a/tools/processors/view_inspector/src/java/android/processor/view/inspector/ProcessingException.java
+++ b/tools/processors/view_inspector/src/java/android/processor/view/inspector/ProcessingException.java
@@ -18,6 +18,9 @@
 
 import static javax.tools.Diagnostic.Kind.ERROR;
 
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+
 import javax.annotation.processing.Messager;
 import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.AnnotationValue;
@@ -27,27 +30,30 @@
  * Internal exception used to signal an error processing an annotation.
  */
 final class ProcessingException extends RuntimeException {
-    private final Element mElement;
-    private final AnnotationMirror mAnnotationMirror;
-    private final AnnotationValue mAnnotationValue;
+    private final @Nullable Element mElement;
+    private final @Nullable AnnotationMirror mAnnotationMirror;
+    private final @Nullable AnnotationValue mAnnotationValue;
 
-    ProcessingException(String message) {
+    ProcessingException(@NonNull String message) {
         this(message, null, null, null);
     }
 
-    ProcessingException(String message, Element element) {
+    ProcessingException(@NonNull String message, @NonNull Element element) {
         this(message, element, null, null);
     }
 
-    ProcessingException(String message, Element element, AnnotationMirror annotationMirror) {
+    ProcessingException(
+            @NonNull String message,
+            @NonNull Element element,
+            @NonNull AnnotationMirror annotationMirror) {
         this(message, element, annotationMirror, null);
     }
 
     ProcessingException(
-            String message,
-            Element element,
-            AnnotationMirror annotationMirror,
-            AnnotationValue annotationValue) {
+            @NonNull String message,
+            @Nullable Element element,
+            @Nullable AnnotationMirror annotationMirror,
+            @Nullable AnnotationValue annotationValue) {
         super(message);
         mElement = element;
         mAnnotationMirror = annotationMirror;
@@ -59,7 +65,7 @@
      *
      * @param messager A Messager to print to
      */
-    void print(Messager messager) {
+    void print(@NonNull Messager messager) {
         if (mElement != null) {
             if (mAnnotationMirror != null) {
                 if (mAnnotationValue != null) {
diff --git a/tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java b/tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java
index 4eed504..3ec620a 100644
--- a/tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java
+++ b/tools/processors/view_inspector/test/java/android/processor/view/inspector/InspectionCompanionGeneratorTest.java
@@ -118,9 +118,9 @@
                 Property.Type.INT_ENUM);
 
         property.setIntEnumEntries(Arrays.asList(
-                new IntEnumEntry("THREE", 3),
-                new IntEnumEntry("TWO", 2),
-                new IntEnumEntry("ONE", 1)));
+                new IntEnumEntry(3, "THREE"),
+                new IntEnumEntry(2, "TWO"),
+                new IntEnumEntry(1, "ONE")));
 
         mModel.putProperty(property);
 
@@ -136,9 +136,9 @@
 
         property.setAttributeIdInferrableFromR(false);
         property.setIntFlagEntries(Arrays.asList(
-                new IntFlagEntry("TURBO", 0x1, 0x3),
-                new IntFlagEntry("OVERDRIVE", 0x2, 0x3),
-                new IntFlagEntry("WARP", 0x4)
+                new IntFlagEntry(0x3, 0x1, "TURBO"),
+                new IntFlagEntry(0x3, 0x2, "OVERDRIVE"),
+                new IntFlagEntry(0x4, "WARP")
         ));
 
         assertGeneratedFileEquals("IntFlag");
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/FieldProperty.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/FieldProperty.java.txt
index 9a0fe5b..e4a8ba4 100644
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/FieldProperty.java.txt
+++ b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/FieldProperty.java.txt
@@ -14,7 +14,7 @@
  */
 public final class TestNode$InspectionCompanion implements InspectionCompanion<TestNode> {
     /**
-     * Set by {@link #mapProperties(PropertyMapper)} once properties have been mapped.
+     * Guards against reading properties before mapping them.
      */
     private boolean mPropertiesMapped = false;
 
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/IntEnum.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/IntEnum.java.txt
index b491de1..fa9dbfd 100644
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/IntEnum.java.txt
+++ b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/IntEnum.java.txt
@@ -1,11 +1,12 @@
 package com.android.node;
 
 import android.R;
+import android.util.SparseArray;
 import android.view.inspector.InspectionCompanion;
-import android.view.inspector.IntEnumMapping;
 import android.view.inspector.PropertyMapper;
 import android.view.inspector.PropertyReader;
 import java.lang.Override;
+import java.lang.String;
 
 /**
  * Inspection companion for {@link TestNode}.
@@ -15,7 +16,7 @@
  */
 public final class TestNode$InspectionCompanion implements InspectionCompanion<TestNode> {
     /**
-     * Set by {@link #mapProperties(PropertyMapper)} once properties have been mapped.
+     * Guards against reading properties before mapping them.
      */
     private boolean mPropertiesMapped = false;
 
@@ -26,12 +27,11 @@
 
     @Override
     public void mapProperties(PropertyMapper propertyMapper) {
-        mIntEnumPropertyId = propertyMapper.mapIntEnum("intEnumProperty", R.attr.intEnumProperty,
-                new IntEnumMapping.Builder()
-                    .addValue("ONE", 1)
-                    .addValue("TWO", 2)
-                    .addValue("THREE", 3)
-                    .build());
+        final SparseArray<String> intEnumPropertyEnumMapping = new SparseArray<>();
+        intEnumPropertyEnumMapping.put(1, "ONE");
+        intEnumPropertyEnumMapping.put(2, "TWO");
+        intEnumPropertyEnumMapping.put(3, "THREE");
+        mIntEnumPropertyId = propertyMapper.mapIntEnum("intEnumProperty", R.attr.intEnumProperty, intEnumPropertyEnumMapping::get);
         mPropertiesMapped = true;
     }
 
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/IntFlag.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/IntFlag.java.txt
index 7d18058..ed3d8ee 100644
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/IntFlag.java.txt
+++ b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/IntFlag.java.txt
@@ -14,7 +14,7 @@
  */
 public final class TestNode$InspectionCompanion implements InspectionCompanion<TestNode> {
     /**
-     * Set by {@link #mapProperties(PropertyMapper)} once properties have been mapped.
+     * Guards against reading properties before mapping them.
      */
     private boolean mPropertiesMapped = false;
 
@@ -25,11 +25,11 @@
 
     @Override
     public void mapProperties(PropertyMapper propertyMapper) {
-        mIntFlagId = propertyMapper.mapIntFlag("intFlag", 0, new IntFlagMapping.Builder()
-                    .addFlag("OVERDRIVE", 0x00000002, 0x00000003)
-                    .addFlag("TURBO", 0x00000001, 0x00000003)
-                    .addFlag("WARP", 0x00000004)
-                    .build());
+        final IntFlagMapping intFlagFlagMapping = new IntFlagMapping();
+        intFlagFlagMapping.add(0x00000003, 0x00000002, "OVERDRIVE");
+        intFlagFlagMapping.add(0x00000003, 0x00000001, "TURBO");
+        intFlagFlagMapping.add(0x00000004, 0x00000004, "WARP");
+        mIntFlagId = propertyMapper.mapIntFlag("intFlag", 0, intFlagFlagMapping::get);
         mPropertiesMapped = true;
     }
 
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NestedClass.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NestedClass.java.txt
index dc27abb..4514ed9 100644
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NestedClass.java.txt
+++ b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NestedClass.java.txt
@@ -13,7 +13,7 @@
  */
 public final class Outer$Inner$InspectionCompanion implements InspectionCompanion<Outer.Inner> {
     /**
-     * Set by {@link #mapProperties(PropertyMapper)} once properties have been mapped.
+     * Guards against reading properties before mapping them.
      */
     private boolean mPropertiesMapped = false;
 
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NoAttributeId.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NoAttributeId.java.txt
index 738bcd3..563f93df 100644
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NoAttributeId.java.txt
+++ b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NoAttributeId.java.txt
@@ -13,7 +13,7 @@
  */
 public final class TestNode$InspectionCompanion implements InspectionCompanion<TestNode> {
     /**
-     * Set by {@link #mapProperties(PropertyMapper)} once properties have been mapped.
+     * Guards against reading properties before mapping them.
      */
     private boolean mPropertiesMapped = false;
 
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NodeName.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NodeName.java.txt
index 82dd66e..ffa1f0b 100644
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NodeName.java.txt
+++ b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/NodeName.java.txt
@@ -14,7 +14,7 @@
  */
 public final class TestNode$InspectionCompanion implements InspectionCompanion<TestNode> {
     /**
-     * Set by {@link #mapProperties(PropertyMapper)} once properties have been mapped.
+     * Guards against reading properties before mapping them.
      */
     private boolean mPropertiesMapped = false;
 
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/SimpleProperties.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/SimpleProperties.java.txt
index 08ea696..cb85767 100644
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/SimpleProperties.java.txt
+++ b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/SimpleProperties.java.txt
@@ -14,7 +14,7 @@
  */
 public final class TestNode$InspectionCompanion implements InspectionCompanion<TestNode> {
     /**
-     * Set by {@link #mapProperties(PropertyMapper)} once properties have been mapped.
+     * Guards against reading properties before mapping them.
      */
     private boolean mPropertiesMapped = false;
 
diff --git a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/SuppliedAttributeId.java.txt b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/SuppliedAttributeId.java.txt
index 3bfa78a..731d410 100644
--- a/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/SuppliedAttributeId.java.txt
+++ b/tools/processors/view_inspector/test/resources/android/processor/view/inspector/InspectionCompanionGeneratorTest/SuppliedAttributeId.java.txt
@@ -13,7 +13,7 @@
  */
 public final class TestNode$InspectionCompanion implements InspectionCompanion<TestNode> {
     /**
-     * Set by {@link #mapProperties(PropertyMapper)} once properties have been mapped.
+     * Guards against reading properties before mapping them.
      */
     private boolean mPropertiesMapped = false;
 
@@ -24,8 +24,7 @@
 
     @Override
     public void mapProperties(PropertyMapper propertyMapper) {
-        mSuppliedAttributePropertyId = propertyMapper.mapInt("suppliedAttributeProperty",
-                0xdecafbad);
+        mSuppliedAttributePropertyId = propertyMapper.mapInt("suppliedAttributeProperty", 0xdecafbad);
         mPropertiesMapped = true;
     }
 
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index d38b2f4..06a99e2 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -4880,14 +4880,14 @@
 
     /**
      * Provide a Wi-Fi usability score information to be recorded (but not acted upon) by the
-     * framework. The Wi-Fi usability score is derived from {@link WifiUsabilityStatsListener}
+     * framework. The Wi-Fi usability score is derived from {@link OnWifiUsabilityStatsListener}
      * where a score is matched to Wi-Fi usability statistics using the sequence number. The score
      * is used to quantify whether Wi-Fi is usable in a future time.
      *
      * @param seqNum Sequence number of the Wi-Fi usability score.
-     * @param score The Wi-Fi usability score.
+     * @param score The Wi-Fi usability score, expected range: [0, 100].
      * @param predictionHorizonSec Prediction horizon of the Wi-Fi usability score in second,
-     *                             expected range: [0, 100].
+     *                             expected range: [0, 30].
      *
      * @hide
      */