Merge "Move overflow bubble to stack on update" into rvc-dev
diff --git a/Android.bp b/Android.bp
index 9c1a085..8adf48d 100644
--- a/Android.bp
+++ b/Android.bp
@@ -546,7 +546,6 @@
         // DO NOT ADD ANY MORE ENTRIES TO THIS LIST
         "//external/robolectric-shadows:__subpackages__",
         "//frameworks/layoutlib:__subpackages__",
-        "//frameworks/opt/net/ike:__subpackages__",
     ],
 }
 
@@ -694,6 +693,7 @@
         "core/java/android/annotation/CallbackExecutor.java",
         "core/java/android/annotation/CheckResult.java",
         "core/java/android/annotation/CurrentTimeMillisLong.java",
+        "core/java/android/annotation/Hide.java",
         "core/java/android/annotation/IntDef.java",
         "core/java/android/annotation/IntRange.java",
         "core/java/android/annotation/LongDef.java",
@@ -753,6 +753,18 @@
     ],
 }
 
+filegroup {
+    name: "framework-services-net-module-wifi-shared-srcs",
+    srcs: [
+        "core/java/android/net/DhcpResults.java",
+        "core/java/android/net/shared/Inet4AddressUtils.java",
+        "core/java/android/net/shared/InetAddressUtils.java",
+        "core/java/android/net/util/IpUtils.java",
+        "core/java/android/util/LocalLog.java",
+        "core/java/com/android/internal/util/Preconditions.java",
+    ],
+}
+
 // keep these files in sync with the package/Tethering/jarjar-rules.txt for the tethering module.
 filegroup {
     name: "framework-tethering-shared-srcs",
@@ -974,7 +986,6 @@
     srcs: [
         "core/java/android/os/incremental/IIncrementalService.aidl",
         "core/java/android/os/incremental/IncrementalNewFileParams.aidl",
-        "core/java/android/os/incremental/IncrementalSignature.aidl",
     ],
     path: "core/java",
 }
@@ -1241,7 +1252,6 @@
         "core/java/android/net/InterfaceConfiguration.java",
         "core/java/android/os/BasicShellCommandHandler.java",
         "core/java/android/util/BackupUtils.java",
-        "core/java/android/util/LocalLog.java",
         "core/java/android/util/Rational.java",
         "core/java/com/android/internal/util/FastXmlSerializer.java",
         "core/java/com/android/internal/util/HexDump.java",
diff --git a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java
index c458d11..e042782 100644
--- a/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java
+++ b/apct-tests/perftests/multiuser/src/android/multiuser/UserLifecycleTests.java
@@ -670,7 +670,7 @@
     private void startApp(int userId, String packageName) throws RemoteException {
         final Context context = InstrumentationRegistry.getContext();
         final WaitResult result = ActivityTaskManager.getService().startActivityAndWait(null,
-                context.getPackageName(), context.getFeatureId(),
+                context.getPackageName(), context.getAttributionTag(),
                 context.getPackageManager().getLaunchIntentForPackage(packageName), null, null,
                 null, 0, 0, null, null, userId);
         attestTrue("User " + userId + " failed to start " + packageName,
diff --git a/api/current.txt b/api/current.txt
index 1b7f6e5..f86b9a3 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -290,6 +290,7 @@
     field public static final int allowAudioPlaybackCapture = 16844289; // 0x1010601
     field public static final int allowBackup = 16843392; // 0x1010280
     field public static final int allowClearUserData = 16842757; // 0x1010005
+    field public static final int allowDontAutoRevokePermissions = 16844309; // 0x1010615
     field public static final int allowEmbedded = 16843765; // 0x10103f5
     field public static final int allowNativeHeapPointerTagging = 16844307; // 0x1010613
     field public static final int allowParallelSyncs = 16843570; // 0x1010332
@@ -572,7 +573,7 @@
     field public static final int elevation = 16843840; // 0x1010440
     field public static final int ellipsize = 16842923; // 0x10100ab
     field public static final int ems = 16843096; // 0x1010158
-    field public static final int enableGwpAsan = 16844310; // 0x1010616
+    field public static final int enableGwpAsan = 16844312; // 0x1010618
     field public static final int enableVrMode = 16844069; // 0x1010525
     field public static final int enabled = 16842766; // 0x101000e
     field public static final int end = 16843996; // 0x10104dc
@@ -621,7 +622,6 @@
     field public static final int fastScrollTextColor = 16843609; // 0x1010359
     field public static final int fastScrollThumbDrawable = 16843574; // 0x1010336
     field public static final int fastScrollTrackDrawable = 16843577; // 0x1010339
-    field public static final int featureId = 16844301; // 0x101060d
     field public static final int fillAfter = 16843197; // 0x10101bd
     field public static final int fillAlpha = 16843980; // 0x10104cc
     field public static final int fillBefore = 16843196; // 0x10101bc
@@ -954,7 +954,7 @@
     field public static final int mediaRouteButtonStyle = 16843693; // 0x10103ad
     field public static final int mediaRouteTypes = 16843694; // 0x10103ae
     field public static final int menuCategory = 16843230; // 0x10101de
-    field public static final int mimeGroup = 16844309; // 0x1010615
+    field public static final int mimeGroup = 16844311; // 0x1010617
     field public static final int mimeType = 16842790; // 0x1010026
     field public static final int min = 16844089; // 0x1010539
     field public static final int minAspectRatio = 16844187; // 0x101059b
@@ -1083,7 +1083,7 @@
     field public static final int preferenceScreenStyle = 16842891; // 0x101008b
     field public static final int preferenceStyle = 16842894; // 0x101008e
     field public static final int presentationTheme = 16843712; // 0x10103c0
-    field public static final int preserveLegacyExternalStorage = 16844308; // 0x1010614
+    field public static final int preserveLegacyExternalStorage = 16844310; // 0x1010616
     field public static final int previewImage = 16843482; // 0x10102da
     field public static final int primaryContentAlpha = 16844114; // 0x1010552
     field public static final int priority = 16842780; // 0x101001c
@@ -1140,6 +1140,7 @@
     field public static final int reqKeyboardType = 16843304; // 0x1010228
     field public static final int reqNavigation = 16843306; // 0x101022a
     field public static final int reqTouchScreen = 16843303; // 0x1010227
+    field public static final int requestDontAutoRevokePermissions = 16844308; // 0x1010614
     field public static final int requestLegacyExternalStorage = 16844291; // 0x1010603
     field public static final int requireDeviceUnlock = 16843756; // 0x10103ec
     field public static final int required = 16843406; // 0x101028e
@@ -4587,7 +4588,7 @@
 
   public final class AsyncNotedAppOp implements android.os.Parcelable {
     method public int describeContents();
-    method @Nullable public String getFeatureId();
+    method @Nullable public String getAttributionTag();
     method @NonNull public String getMessage();
     method @IntRange(from=0) public int getNotingUid();
     method @NonNull public String getOp();
@@ -6431,7 +6432,7 @@
   public final class SyncNotedAppOp implements android.os.Parcelable {
     ctor public SyncNotedAppOp(@IntRange(from=0L) int, @Nullable String);
     method public int describeContents();
-    method @Nullable public String getFeatureId();
+    method @Nullable public String getAttributionTag();
     method @NonNull public String getOp();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.app.SyncNotedAppOp> CREATOR;
@@ -6857,9 +6858,9 @@
     method @Nullable public String getAlwaysOnVpnPackage(@NonNull android.content.ComponentName);
     method @NonNull @WorkerThread public android.os.Bundle getApplicationRestrictions(@Nullable android.content.ComponentName, String);
     method @Deprecated @Nullable public String getApplicationRestrictionsManagingPackage(@NonNull android.content.ComponentName);
-    method public boolean getAutoTime(@NonNull android.content.ComponentName);
+    method public boolean getAutoTimeEnabled(@NonNull android.content.ComponentName);
     method @Deprecated public boolean getAutoTimeRequired();
-    method public boolean getAutoTimeZone(@NonNull android.content.ComponentName);
+    method public boolean getAutoTimeZoneEnabled(@NonNull android.content.ComponentName);
     method @NonNull public java.util.List<android.os.UserHandle> getBindDeviceAdminTargetUsers(@NonNull android.content.ComponentName);
     method public boolean getBluetoothContactSharingDisabled(@NonNull android.content.ComponentName);
     method public boolean getCameraDisabled(@Nullable android.content.ComponentName);
@@ -6983,9 +6984,9 @@
     method public boolean setApplicationHidden(@NonNull android.content.ComponentName, String, boolean);
     method @WorkerThread public void setApplicationRestrictions(@Nullable android.content.ComponentName, String, android.os.Bundle);
     method @Deprecated public void setApplicationRestrictionsManagingPackage(@NonNull android.content.ComponentName, @Nullable String) throws android.content.pm.PackageManager.NameNotFoundException;
-    method public void setAutoTime(@NonNull android.content.ComponentName, boolean);
+    method public void setAutoTimeEnabled(@NonNull android.content.ComponentName, boolean);
     method @Deprecated public void setAutoTimeRequired(@NonNull android.content.ComponentName, boolean);
-    method public void setAutoTimeZone(@NonNull android.content.ComponentName, boolean);
+    method public void setAutoTimeZoneEnabled(@NonNull android.content.ComponentName, boolean);
     method public void setBackupServiceEnabled(@NonNull android.content.ComponentName, boolean);
     method public void setBluetoothContactSharingDisabled(@NonNull android.content.ComponentName, boolean);
     method public void setCameraDisabled(@NonNull android.content.ComponentName, boolean);
@@ -9697,7 +9698,7 @@
     method public abstract int delete(@NonNull android.net.Uri, @Nullable String, @Nullable String[]);
     method public int delete(@NonNull android.net.Uri, @Nullable android.os.Bundle);
     method public void dump(java.io.FileDescriptor, java.io.PrintWriter, String[]);
-    method @Nullable public final String getCallingFeatureId();
+    method @Nullable public final String getCallingAttributionTag();
     method @Nullable public final String getCallingPackage();
     method @Nullable public final String getCallingPackageUnchecked();
     method @Nullable public final android.content.Context getContext();
@@ -10031,11 +10032,11 @@
     method @CheckResult(suggest="#enforceUriPermission(Uri,int,int,String)") public abstract int checkUriPermission(android.net.Uri, int, int, int);
     method @CheckResult(suggest="#enforceUriPermission(Uri,String,String,int,int,int,String)") public abstract int checkUriPermission(@Nullable android.net.Uri, @Nullable String, @Nullable String, int, int, int);
     method @Deprecated public abstract void clearWallpaper() throws java.io.IOException;
+    method @NonNull public android.content.Context createAttributionContext(@Nullable String);
     method public abstract android.content.Context createConfigurationContext(@NonNull android.content.res.Configuration);
     method public abstract android.content.Context createContextForSplit(String) throws android.content.pm.PackageManager.NameNotFoundException;
     method public abstract android.content.Context createDeviceProtectedStorageContext();
     method public abstract android.content.Context createDisplayContext(@NonNull android.view.Display);
-    method @NonNull public android.content.Context createFeatureContext(@Nullable String);
     method public abstract android.content.Context createPackageContext(String, int) throws android.content.pm.PackageManager.NameNotFoundException;
     method @NonNull public android.content.Context createWindowContext(int, @Nullable android.os.Bundle);
     method public abstract String[] databaseList();
@@ -10053,6 +10054,7 @@
     method public abstract android.content.Context getApplicationContext();
     method public abstract android.content.pm.ApplicationInfo getApplicationInfo();
     method public abstract android.content.res.AssetManager getAssets();
+    method @Nullable public String getAttributionTag();
     method public abstract java.io.File getCacheDir();
     method public abstract ClassLoader getClassLoader();
     method public abstract java.io.File getCodeCacheDir();
@@ -10069,7 +10071,6 @@
     method @Nullable public abstract java.io.File getExternalFilesDir(@Nullable String);
     method public abstract java.io.File[] getExternalFilesDirs(String);
     method @Deprecated public abstract java.io.File[] getExternalMediaDirs();
-    method @Nullable public String getFeatureId();
     method public abstract java.io.File getFileStreamPath(String);
     method public abstract java.io.File getFilesDir();
     method public java.util.concurrent.Executor getMainExecutor();
@@ -12024,6 +12025,7 @@
     method public boolean hasSigningCertificate(int, @NonNull byte[], int);
     method public abstract boolean hasSystemFeature(@NonNull String);
     method public abstract boolean hasSystemFeature(@NonNull String, int);
+    method public boolean isAutoRevokeWhitelisted();
     method public boolean isDefaultApplicationIcon(@NonNull android.graphics.drawable.Drawable);
     method public boolean isDeviceUpgrading();
     method public abstract boolean isInstantApp();
@@ -17354,7 +17356,7 @@
   public final class CameraManager {
     method @NonNull public android.hardware.camera2.CameraCharacteristics getCameraCharacteristics(@NonNull String) throws android.hardware.camera2.CameraAccessException;
     method @NonNull public String[] getCameraIdList() throws android.hardware.camera2.CameraAccessException;
-    method @NonNull public java.util.Set<java.util.Set<java.lang.String>> getConcurrentStreamingCameraIds() throws android.hardware.camera2.CameraAccessException;
+    method @NonNull public java.util.Set<java.util.Set<java.lang.String>> getConcurrentCameraIds() throws android.hardware.camera2.CameraAccessException;
     method @RequiresPermission(android.Manifest.permission.CAMERA) public boolean isConcurrentSessionConfigurationSupported(@NonNull java.util.Map<java.lang.String,android.hardware.camera2.params.SessionConfiguration>) throws android.hardware.camera2.CameraAccessException;
     method @RequiresPermission(android.Manifest.permission.CAMERA) public void openCamera(@NonNull String, @NonNull android.hardware.camera2.CameraDevice.StateCallback, @Nullable android.os.Handler) throws android.hardware.camera2.CameraAccessException;
     method @RequiresPermission(android.Manifest.permission.CAMERA) public void openCamera(@NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.camera2.CameraDevice.StateCallback) throws android.hardware.camera2.CameraAccessException;
@@ -20096,8 +20098,7 @@
     method public T numberFormatterSecond(android.icu.number.UnlocalizedNumberFormatter);
   }
 
-  public abstract class Precision implements java.lang.Cloneable {
-    method public Object clone();
+  public abstract class Precision {
     method public static android.icu.number.CurrencyPrecision currency(android.icu.util.Currency.CurrencyUsage);
     method public static android.icu.number.FractionPrecision fixedFraction(int);
     method public static android.icu.number.Precision fixedSignificantDigits(int);
@@ -20120,8 +20121,7 @@
     method public static android.icu.number.Scale powerOfTen(int);
   }
 
-  public class ScientificNotation extends android.icu.number.Notation implements java.lang.Cloneable {
-    method public Object clone();
+  public class ScientificNotation extends android.icu.number.Notation {
     method public android.icu.number.ScientificNotation withExponentSignDisplay(android.icu.number.NumberFormatter.SignDisplay);
     method public android.icu.number.ScientificNotation withMinExponentDigits(int);
   }
@@ -40718,6 +40718,7 @@
     field public static final String PARENTAL_CONTROL_LAST_UPDATE = "parental_control_last_update";
     field public static final String PARENTAL_CONTROL_REDIRECT_URL = "parental_control_redirect_url";
     field public static final String RTT_CALLING_MODE = "rtt_calling_mode";
+    field public static final String SECURE_FRP_MODE = "secure_frp_mode";
     field public static final String SELECTED_INPUT_METHOD_SUBTYPE = "selected_input_method_subtype";
     field public static final String SETTINGS_CLASSNAME = "settings_classname";
     field public static final String SKIP_FIRST_USE_HINTS = "skip_first_use_hints";
@@ -43016,12 +43017,12 @@
   }
 
   public static final class Dataset.Builder {
-    ctor public Dataset.Builder(@NonNull android.widget.RemoteViews, @NonNull android.service.autofill.InlinePresentation);
     ctor public Dataset.Builder(@NonNull android.widget.RemoteViews);
     ctor public Dataset.Builder();
     method @NonNull public android.service.autofill.Dataset build();
     method @NonNull public android.service.autofill.Dataset.Builder setAuthentication(@Nullable android.content.IntentSender);
     method @NonNull public android.service.autofill.Dataset.Builder setId(@Nullable String);
+    method @NonNull public android.service.autofill.Dataset.Builder setInlinePresentation(@NonNull android.service.autofill.InlinePresentation);
     method @NonNull public android.service.autofill.Dataset.Builder setValue(@NonNull android.view.autofill.AutofillId, @Nullable android.view.autofill.AutofillValue);
     method @NonNull public android.service.autofill.Dataset.Builder setValue(@NonNull android.view.autofill.AutofillId, @Nullable android.view.autofill.AutofillValue, @NonNull android.widget.RemoteViews);
     method @NonNull public android.service.autofill.Dataset.Builder setValue(@NonNull android.view.autofill.AutofillId, @Nullable android.view.autofill.AutofillValue, @Nullable java.util.regex.Pattern);
@@ -56741,6 +56742,7 @@
     method public final void notifySessionResumed();
     method public final void notifyViewAppeared(@NonNull android.view.ViewStructure);
     method public final void notifyViewDisappeared(@NonNull android.view.autofill.AutofillId);
+    method public final void notifyViewInsetsChanged(@NonNull android.graphics.Insets);
     method public final void notifyViewTextChanged(@NonNull android.view.autofill.AutofillId, @Nullable CharSequence);
     method public final void notifyViewsDisappeared(@NonNull android.view.autofill.AutofillId, @NonNull long[]);
     method public final void setContentCaptureContext(@Nullable android.view.contentcapture.ContentCaptureContext);
diff --git a/api/removed.txt b/api/removed.txt
index 8537b21..077c915 100644
--- a/api/removed.txt
+++ b/api/removed.txt
@@ -1,4 +1,12 @@
 // Signature format: 2.0
+package android {
+
+  public static final class R.attr {
+    field public static final int featureId = 16844301; // 0x101060d
+  }
+
+}
+
 package android.app {
 
   public class ActivityManager {
@@ -69,11 +77,17 @@
 
 package android.content {
 
+  public abstract class ContentProvider implements android.content.ComponentCallbacks2 {
+    method @Deprecated @Nullable public final String getCallingFeatureId();
+  }
+
   public abstract class ContentResolver {
     method @Deprecated public void notifyChange(@NonNull Iterable<android.net.Uri>, @Nullable android.database.ContentObserver, int);
   }
 
   public abstract class Context {
+    method @Deprecated @NonNull public android.content.Context createFeatureContext(@Nullable String);
+    method @Deprecated @Nullable public String getFeatureId();
     method public abstract android.content.SharedPreferences getSharedPreferences(java.io.File, int);
     method public abstract java.io.File getSharedPreferencesPath(String);
   }
diff --git a/api/system-current.txt b/api/system-current.txt
index c102e66..460fb05 100755
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -448,14 +448,37 @@
     field public static final int UID_STATE_TOP = 200; // 0xc8
   }
 
-  public static final class AppOpsManager.HistoricalFeatureOps implements android.os.Parcelable {
+  public static final class AppOpsManager.AttributedHistoricalOps implements android.os.Parcelable {
     method public int describeContents();
-    method @Nullable public String getFeatureId();
     method @Nullable public android.app.AppOpsManager.HistoricalOp getOp(@NonNull String);
     method @NonNull public android.app.AppOpsManager.HistoricalOp getOpAt(@IntRange(from=0) int);
     method @IntRange(from=0) public int getOpCount();
+    method @Nullable public String getTag();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
-    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.HistoricalFeatureOps> CREATOR;
+    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.AttributedHistoricalOps> CREATOR;
+  }
+
+  public static final class AppOpsManager.AttributedOpEntry implements android.os.Parcelable {
+    method public int describeContents();
+    method public long getLastAccessBackgroundTime(int);
+    method public long getLastAccessForegroundTime(int);
+    method public long getLastAccessTime(int);
+    method public long getLastAccessTime(int, int, int);
+    method public long getLastBackgroundDuration(int);
+    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastBackgroundProxyInfo(int);
+    method public long getLastDuration(int);
+    method public long getLastDuration(int, int, int);
+    method public long getLastForegroundDuration(int);
+    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastForegroundProxyInfo(int);
+    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int);
+    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int, int, int);
+    method public long getLastRejectBackgroundTime(int);
+    method public long getLastRejectForegroundTime(int);
+    method public long getLastRejectTime(int);
+    method public long getLastRejectTime(int, int, int);
+    method public boolean isRunning();
+    method public void writeToParcel(@NonNull android.os.Parcel, int);
+    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.AttributedOpEntry> CREATOR;
   }
 
   public static final class AppOpsManager.HistoricalOp implements android.os.Parcelable {
@@ -491,7 +514,7 @@
   public static final class AppOpsManager.HistoricalOpsRequest.Builder {
     ctor public AppOpsManager.HistoricalOpsRequest.Builder(long, long);
     method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest build();
-    method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setFeatureId(@Nullable String);
+    method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setAttributionTag(@Nullable String);
     method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setFlags(int);
     method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setOpNames(@Nullable java.util.List<java.lang.String>);
     method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setPackageName(@Nullable String);
@@ -500,9 +523,9 @@
 
   public static final class AppOpsManager.HistoricalPackageOps implements android.os.Parcelable {
     method public int describeContents();
-    method @IntRange(from=0) public int getFeatureCount();
-    method @Nullable public android.app.AppOpsManager.HistoricalFeatureOps getFeatureOps(@NonNull String);
-    method @NonNull public android.app.AppOpsManager.HistoricalFeatureOps getFeatureOpsAt(@IntRange(from=0) int);
+    method @Nullable public android.app.AppOpsManager.AttributedHistoricalOps getAttributedOps(@NonNull String);
+    method @NonNull public android.app.AppOpsManager.AttributedHistoricalOps getAttributedOpsAt(@IntRange(from=0) int);
+    method @IntRange(from=0) public int getAttributedOpsCount();
     method @Nullable public android.app.AppOpsManager.HistoricalOp getOp(@NonNull String);
     method @NonNull public android.app.AppOpsManager.HistoricalOp getOpAt(@IntRange(from=0) int);
     method @IntRange(from=0) public int getOpCount();
@@ -523,8 +546,8 @@
 
   public static final class AppOpsManager.OpEntry implements android.os.Parcelable {
     method public int describeContents();
+    method @NonNull public java.util.Map<java.lang.String,android.app.AppOpsManager.AttributedOpEntry> getAttributedOpEntries();
     method @Deprecated public long getDuration();
-    method @NonNull public java.util.Map<java.lang.String,android.app.AppOpsManager.OpFeatureEntry> getFeatures();
     method public long getLastAccessBackgroundTime(int);
     method public long getLastAccessForegroundTime(int);
     method public long getLastAccessTime(int);
@@ -554,36 +577,13 @@
 
   public static final class AppOpsManager.OpEventProxyInfo implements android.os.Parcelable {
     method public int describeContents();
-    method @Nullable public String getFeatureId();
+    method @Nullable public String getAttributionTag();
     method @Nullable public String getPackageName();
     method @IntRange(from=0) public int getUid();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpEventProxyInfo> CREATOR;
   }
 
-  public static final class AppOpsManager.OpFeatureEntry implements android.os.Parcelable {
-    method public int describeContents();
-    method public long getLastAccessBackgroundTime(int);
-    method public long getLastAccessForegroundTime(int);
-    method public long getLastAccessTime(int);
-    method public long getLastAccessTime(int, int, int);
-    method public long getLastBackgroundDuration(int);
-    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastBackgroundProxyInfo(int);
-    method public long getLastDuration(int);
-    method public long getLastDuration(int, int, int);
-    method public long getLastForegroundDuration(int);
-    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastForegroundProxyInfo(int);
-    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int);
-    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int, int, int);
-    method public long getLastRejectBackgroundTime(int);
-    method public long getLastRejectForegroundTime(int);
-    method public long getLastRejectTime(int);
-    method public long getLastRejectTime(int, int, int);
-    method public boolean isRunning();
-    method public void writeToParcel(@NonNull android.os.Parcel, int);
-    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpFeatureEntry> CREATOR;
-  }
-
   public static final class AppOpsManager.PackageOps implements android.os.Parcelable {
     method public int describeContents();
     method @NonNull public java.util.List<android.app.AppOpsManager.OpEntry> getOps();
@@ -688,7 +688,7 @@
   public final class RuntimeAppOpAccessMessage implements android.os.Parcelable {
     ctor public RuntimeAppOpAccessMessage(@IntRange(from=0L) int, @IntRange(from=0L) int, @NonNull String, @Nullable String, @NonNull String, int);
     method public int describeContents();
-    method @Nullable public String getFeatureId();
+    method @Nullable public String getAttributionTag();
     method @NonNull public String getMessage();
     method @NonNull public String getOp();
     method @NonNull public String getPackageName();
@@ -1371,7 +1371,6 @@
     method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void addRoleHolderAsUser(@NonNull String, @NonNull String, int, @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
     method @RequiresPermission("com.android.permissioncontroller.permission.MANAGE_ROLES_FROM_CONTROLLER") public boolean addRoleHolderFromController(@NonNull String, @NonNull String);
     method @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public void clearRoleHoldersAsUser(@NonNull String, int, @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
-    method @Nullable public String getDefaultSmsPackage(int);
     method @NonNull @RequiresPermission("com.android.permissioncontroller.permission.MANAGE_ROLES_FROM_CONTROLLER") public java.util.List<java.lang.String> getHeldRolesFromController(@NonNull String);
     method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public java.util.List<java.lang.String> getRoleHolders(@NonNull String);
     method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_ROLE_HOLDERS) public java.util.List<java.lang.String> getRoleHoldersAsUser(@NonNull String, @NonNull android.os.UserHandle);
@@ -2216,7 +2215,7 @@
     field public static final String FEATURE_INCREMENTAL_DELIVERY = "android.software.incremental_delivery";
     field public static final String FEATURE_REBOOT_ESCROW = "android.hardware.reboot_escrow";
     field public static final String FEATURE_TELEPHONY_CARRIERLOCK = "android.hardware.telephony.carrierlock";
-    field public static final int FLAGS_PERMISSION_RESERVED_PERMISSIONCONTROLLER = -268435456; // 0xf0000000
+    field public static final int FLAGS_PERMISSION_RESERVED_PERMISSION_CONTROLLER = -268435456; // 0xf0000000
     field public static final int FLAG_PERMISSION_APPLY_RESTRICTION = 16384; // 0x4000
     field public static final int FLAG_PERMISSION_AUTO_REVOKED = 131072; // 0x20000
     field public static final int FLAG_PERMISSION_GRANTED_BY_DEFAULT = 32; // 0x20
@@ -8943,11 +8942,13 @@
     method @BinderThread public abstract void onRevokeRuntimePermissions(@NonNull java.util.Map<java.lang.String,java.util.List<java.lang.String>>, boolean, int, @NonNull String, @NonNull java.util.function.Consumer<java.util.Map<java.lang.String,java.util.List<java.lang.String>>>);
     method @BinderThread public abstract void onSetRuntimePermissionGrantStateByDeviceAdmin(@NonNull String, @NonNull String, @NonNull String, int, @NonNull java.util.function.Consumer<java.lang.Boolean>);
     method @BinderThread public void onStageAndApplyRuntimePermissionsBackup(@NonNull android.os.UserHandle, @NonNull java.io.InputStream, @NonNull Runnable);
-    method @BinderThread public void onUpdateUserSensitivePermissionFlags();
+    method @BinderThread public void onUpdateUserSensitivePermissionFlags(int, @NonNull Runnable);
     field public static final String SERVICE_INTERFACE = "android.permission.PermissionControllerService";
   }
 
   public final class PermissionManager {
+    method @NonNull @RequiresPermission(android.Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY) public java.util.Set<java.lang.String> getAutoRevokeExemptionGrantedPackages();
+    method @NonNull @RequiresPermission(android.Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY) public java.util.Set<java.lang.String> getAutoRevokeExemptionRequestedPackages();
     method @IntRange(from=0) @RequiresPermission(anyOf={android.Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY, android.Manifest.permission.UPGRADE_RUNTIME_PERMISSIONS}) public int getRuntimePermissionsVersion();
     method @NonNull public java.util.List<android.permission.PermissionManager.SplitPermissionInfo> getSplitPermissions();
     method @RequiresPermission(android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS) public void grantDefaultPermissionsToEnabledCarrierApps(@NonNull String[], @NonNull android.os.UserHandle, @NonNull java.util.concurrent.Executor, @NonNull java.util.function.Consumer<java.lang.Boolean>);
@@ -9381,7 +9382,6 @@
     field public static final String LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS = "lock_screen_allow_private_notifications";
     field public static final String LOCK_SCREEN_SHOW_NOTIFICATIONS = "lock_screen_show_notifications";
     field public static final String ODI_CAPTIONS_ENABLED = "odi_captions_enabled";
-    field public static final String SECURE_FRP_MODE = "secure_frp_mode";
     field public static final String THEME_CUSTOMIZATION_OVERLAY_PACKAGES = "theme_customization_overlay_packages";
     field public static final String USER_SETUP_COMPLETE = "user_setup_complete";
     field public static final int USER_SETUP_PERSONALIZATION_COMPLETE = 10; // 0xa
@@ -9428,9 +9428,7 @@
   public static final class Telephony.Carriers implements android.provider.BaseColumns {
     field public static final String APN_SET_ID = "apn_set_id";
     field public static final int CARRIER_EDITED = 4; // 0x4
-    field @NonNull public static final android.net.Uri DPC_URI;
     field public static final String EDITED_STATUS = "edited";
-    field public static final int INVALID_APN_ID = -1; // 0xffffffff
     field public static final String MAX_CONNECTIONS = "max_conns";
     field public static final String MODEM_PERSIST = "modem_cognitive";
     field public static final String MTU = "mtu";
@@ -9799,7 +9797,7 @@
 
   public static final class Dataset.Builder {
     ctor public Dataset.Builder(@NonNull android.service.autofill.InlinePresentation);
-    method @NonNull public android.service.autofill.Dataset.Builder setInlinePresentation(@NonNull android.view.autofill.AutofillId, @Nullable android.view.autofill.AutofillValue, @Nullable java.util.regex.Pattern, @NonNull android.service.autofill.InlinePresentation);
+    method @NonNull public android.service.autofill.Dataset.Builder setFieldInlinePresentation(@NonNull android.view.autofill.AutofillId, @Nullable android.view.autofill.AutofillValue, @Nullable java.util.regex.Pattern, @NonNull android.service.autofill.InlinePresentation);
   }
 
   public abstract class InlineSuggestionRenderService extends android.app.Service {
@@ -11541,7 +11539,6 @@
   }
 
   public class TelephonyManager {
-    method public int addDevicePolicyOverrideApn(@NonNull android.content.Context, @NonNull android.telephony.data.ApnSetting);
     method @Deprecated @RequiresPermission(android.Manifest.permission.CALL_PHONE) public void call(String, String);
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public int changeIccLockPassword(@NonNull String, @NonNull String);
     method public int checkCarrierPrivilegesForPackage(String);
@@ -11574,7 +11571,6 @@
     method @Deprecated public boolean getDataEnabled();
     method @Deprecated public boolean getDataEnabled(int);
     method @Nullable public static android.content.ComponentName getDefaultRespondViaMessageApplication(@NonNull android.content.Context, boolean);
-    method @NonNull public java.util.List<android.telephony.data.ApnSetting> getDevicePolicyOverrideApns(@NonNull android.content.Context);
     method @Nullable @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public String getDeviceSoftwareVersion(int);
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean getEmergencyCallbackMode();
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public int getEmergencyNumberDbVersion();
@@ -11624,7 +11620,6 @@
     method @Deprecated @RequiresPermission(anyOf={android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isVideoCallingEnabled();
     method @Deprecated @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE) public boolean isVisualVoicemailEnabled(android.telecom.PhoneAccountHandle);
     method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean matchesCurrentSimOperator(@NonNull String, int, @Nullable String);
-    method public boolean modifyDevicePolicyOverrideApn(@NonNull android.content.Context, int, @NonNull android.telephony.data.ApnSetting);
     method public boolean needsOtaServiceProvisioning();
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void notifyOtaEmergencyNumberDbInstalled();
     method @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void notifyUserActivity();
@@ -12983,17 +12978,6 @@
     method public int updateClir(int);
     method public int updateColp(boolean);
     method public int updateColr(int);
-    field public static final int CALL_BARRING_ALL = 7; // 0x7
-    field public static final int CALL_BARRING_ALL_INCOMING = 1; // 0x1
-    field public static final int CALL_BARRING_ALL_OUTGOING = 2; // 0x2
-    field public static final int CALL_BARRING_ANONYMOUS_INCOMING = 6; // 0x6
-    field public static final int CALL_BARRING_INCOMING_ALL_SERVICES = 9; // 0x9
-    field public static final int CALL_BARRING_OUTGOING_ALL_SERVICES = 8; // 0x8
-    field public static final int CALL_BARRING_OUTGOING_INTL = 3; // 0x3
-    field public static final int CALL_BARRING_OUTGOING_INTL_EXCL_HOME = 4; // 0x4
-    field public static final int CALL_BARRING_SPECIFIC_INCOMING_CALLS = 10; // 0xa
-    field public static final int CALL_BLOCKING_INCOMING_WHEN_ROAMING = 5; // 0x5
-    field public static final int INVALID_RESULT = -1; // 0xffffffff
   }
 
 }
@@ -13198,6 +13182,7 @@
     method public long getEventTime();
     method @Nullable public android.view.autofill.AutofillId getId();
     method @Nullable public java.util.List<android.view.autofill.AutofillId> getIds();
+    method @Nullable public android.graphics.Insets getInsets();
     method @Nullable public CharSequence getText();
     method public int getType();
     method @Nullable public android.view.contentcapture.ViewNode getViewNode();
@@ -13208,6 +13193,7 @@
     field public static final int TYPE_SESSION_RESUMED = 7; // 0x7
     field public static final int TYPE_VIEW_APPEARED = 1; // 0x1
     field public static final int TYPE_VIEW_DISAPPEARED = 2; // 0x2
+    field public static final int TYPE_VIEW_INSETS_CHANGED = 9; // 0x9
     field public static final int TYPE_VIEW_TEXT_CHANGED = 3; // 0x3
     field public static final int TYPE_VIEW_TREE_APPEARED = 5; // 0x5
     field public static final int TYPE_VIEW_TREE_APPEARING = 4; // 0x4
diff --git a/api/test-current.txt b/api/test-current.txt
index a5f1f68..7c71c77 100644
--- a/api/test-current.txt
+++ b/api/test-current.txt
@@ -83,6 +83,7 @@
     method public static void resumeAppSwitches() throws android.os.RemoteException;
     method @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION) public void scheduleApplicationInfoChanged(java.util.List<java.lang.String>, int);
     method @RequiresPermission("android.permission.MANAGE_USERS") public boolean switchUser(@NonNull android.os.UserHandle);
+    method @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION) public boolean updateMccMncConfiguration(@NonNull String, @NonNull String);
     field public static final int PROCESS_CAPABILITY_ALL = 7; // 0x7
     field public static final int PROCESS_CAPABILITY_ALL_EXPLICIT = 1; // 0x1
     field public static final int PROCESS_CAPABILITY_ALL_IMPLICIT = 6; // 0x6
@@ -263,14 +264,37 @@
     field public static final int UID_STATE_TOP = 200; // 0xc8
   }
 
-  public static final class AppOpsManager.HistoricalFeatureOps implements android.os.Parcelable {
+  public static final class AppOpsManager.AttributedHistoricalOps implements android.os.Parcelable {
     method public int describeContents();
-    method @Nullable public String getFeatureId();
     method @Nullable public android.app.AppOpsManager.HistoricalOp getOp(@NonNull String);
     method @NonNull public android.app.AppOpsManager.HistoricalOp getOpAt(@IntRange(from=0) int);
     method @IntRange(from=0) public int getOpCount();
+    method @Nullable public String getTag();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
-    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.HistoricalFeatureOps> CREATOR;
+    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.AttributedHistoricalOps> CREATOR;
+  }
+
+  public static final class AppOpsManager.AttributedOpEntry implements android.os.Parcelable {
+    method public int describeContents();
+    method public long getLastAccessBackgroundTime(int);
+    method public long getLastAccessForegroundTime(int);
+    method public long getLastAccessTime(int);
+    method public long getLastAccessTime(int, int, int);
+    method public long getLastBackgroundDuration(int);
+    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastBackgroundProxyInfo(int);
+    method public long getLastDuration(int);
+    method public long getLastDuration(int, int, int);
+    method public long getLastForegroundDuration(int);
+    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastForegroundProxyInfo(int);
+    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int);
+    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int, int, int);
+    method public long getLastRejectBackgroundTime(int);
+    method public long getLastRejectForegroundTime(int);
+    method public long getLastRejectTime(int);
+    method public long getLastRejectTime(int, int, int);
+    method public boolean isRunning();
+    method public void writeToParcel(@NonNull android.os.Parcel, int);
+    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.AttributedOpEntry> CREATOR;
   }
 
   public static final class AppOpsManager.HistoricalOp implements android.os.Parcelable {
@@ -311,7 +335,7 @@
   public static final class AppOpsManager.HistoricalOpsRequest.Builder {
     ctor public AppOpsManager.HistoricalOpsRequest.Builder(long, long);
     method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest build();
-    method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setFeatureId(@Nullable String);
+    method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setAttributionTag(@Nullable String);
     method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setFlags(int);
     method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setOpNames(@Nullable java.util.List<java.lang.String>);
     method @NonNull public android.app.AppOpsManager.HistoricalOpsRequest.Builder setPackageName(@Nullable String);
@@ -320,9 +344,9 @@
 
   public static final class AppOpsManager.HistoricalPackageOps implements android.os.Parcelable {
     method public int describeContents();
-    method @IntRange(from=0) public int getFeatureCount();
-    method @Nullable public android.app.AppOpsManager.HistoricalFeatureOps getFeatureOps(@NonNull String);
-    method @NonNull public android.app.AppOpsManager.HistoricalFeatureOps getFeatureOpsAt(@IntRange(from=0) int);
+    method @Nullable public android.app.AppOpsManager.AttributedHistoricalOps getAttributedOps(@NonNull String);
+    method @NonNull public android.app.AppOpsManager.AttributedHistoricalOps getAttributedOpsAt(@IntRange(from=0) int);
+    method @IntRange(from=0) public int getAttributedOpsCount();
     method @Nullable public android.app.AppOpsManager.HistoricalOp getOp(@NonNull String);
     method @NonNull public android.app.AppOpsManager.HistoricalOp getOpAt(@IntRange(from=0) int);
     method @IntRange(from=0) public int getOpCount();
@@ -343,8 +367,8 @@
 
   public static final class AppOpsManager.OpEntry implements android.os.Parcelable {
     method public int describeContents();
+    method @NonNull public java.util.Map<java.lang.String,android.app.AppOpsManager.AttributedOpEntry> getAttributedOpEntries();
     method @Deprecated public long getDuration();
-    method @NonNull public java.util.Map<java.lang.String,android.app.AppOpsManager.OpFeatureEntry> getFeatures();
     method public long getLastAccessBackgroundTime(int);
     method public long getLastAccessForegroundTime(int);
     method public long getLastAccessTime(int);
@@ -374,36 +398,13 @@
 
   public static final class AppOpsManager.OpEventProxyInfo implements android.os.Parcelable {
     method public int describeContents();
-    method @Nullable public String getFeatureId();
+    method @Nullable public String getAttributionTag();
     method @Nullable public String getPackageName();
     method @IntRange(from=0) public int getUid();
     method public void writeToParcel(@NonNull android.os.Parcel, int);
     field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpEventProxyInfo> CREATOR;
   }
 
-  public static final class AppOpsManager.OpFeatureEntry implements android.os.Parcelable {
-    method public int describeContents();
-    method public long getLastAccessBackgroundTime(int);
-    method public long getLastAccessForegroundTime(int);
-    method public long getLastAccessTime(int);
-    method public long getLastAccessTime(int, int, int);
-    method public long getLastBackgroundDuration(int);
-    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastBackgroundProxyInfo(int);
-    method public long getLastDuration(int);
-    method public long getLastDuration(int, int, int);
-    method public long getLastForegroundDuration(int);
-    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastForegroundProxyInfo(int);
-    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int);
-    method @Nullable public android.app.AppOpsManager.OpEventProxyInfo getLastProxyInfo(int, int, int);
-    method public long getLastRejectBackgroundTime(int);
-    method public long getLastRejectForegroundTime(int);
-    method public long getLastRejectTime(int);
-    method public long getLastRejectTime(int, int, int);
-    method public boolean isRunning();
-    method public void writeToParcel(@NonNull android.os.Parcel, int);
-    field @NonNull public static final android.os.Parcelable.Creator<android.app.AppOpsManager.OpFeatureEntry> CREATOR;
-  }
-
   public static final class AppOpsManager.PackageOps implements android.os.Parcelable {
     method public int describeContents();
     method @NonNull public java.util.List<android.app.AppOpsManager.OpEntry> getOps();
@@ -465,7 +466,7 @@
   public final class RuntimeAppOpAccessMessage implements android.os.Parcelable {
     ctor public RuntimeAppOpAccessMessage(@IntRange(from=0L) int, @IntRange(from=0L) int, @NonNull String, @Nullable String, @NonNull String, int);
     method public int describeContents();
-    method @Nullable public String getFeatureId();
+    method @Nullable public String getAttributionTag();
     method @NonNull public String getMessage();
     method @NonNull public String getOp();
     method @NonNull public String getPackageName();
@@ -3134,7 +3135,7 @@
 
   public static final class Dataset.Builder {
     ctor public Dataset.Builder(@NonNull android.service.autofill.InlinePresentation);
-    method @NonNull public android.service.autofill.Dataset.Builder setInlinePresentation(@NonNull android.view.autofill.AutofillId, @Nullable android.view.autofill.AutofillValue, @Nullable java.util.regex.Pattern, @NonNull android.service.autofill.InlinePresentation);
+    method @NonNull public android.service.autofill.Dataset.Builder setFieldInlinePresentation(@NonNull android.view.autofill.AutofillId, @Nullable android.view.autofill.AutofillValue, @Nullable java.util.regex.Pattern, @NonNull android.service.autofill.InlinePresentation);
   }
 
   public final class DateTransformation extends android.service.autofill.InternalTransformation implements android.os.Parcelable android.service.autofill.Transformation {
@@ -4671,17 +4672,6 @@
     method public int updateClir(int);
     method public int updateColp(boolean);
     method public int updateColr(int);
-    field public static final int CALL_BARRING_ALL = 7; // 0x7
-    field public static final int CALL_BARRING_ALL_INCOMING = 1; // 0x1
-    field public static final int CALL_BARRING_ALL_OUTGOING = 2; // 0x2
-    field public static final int CALL_BARRING_ANONYMOUS_INCOMING = 6; // 0x6
-    field public static final int CALL_BARRING_INCOMING_ALL_SERVICES = 9; // 0x9
-    field public static final int CALL_BARRING_OUTGOING_ALL_SERVICES = 8; // 0x8
-    field public static final int CALL_BARRING_OUTGOING_INTL = 3; // 0x3
-    field public static final int CALL_BARRING_OUTGOING_INTL_EXCL_HOME = 4; // 0x4
-    field public static final int CALL_BARRING_SPECIFIC_INCOMING_CALLS = 10; // 0xa
-    field public static final int CALL_BLOCKING_INCOMING_WHEN_ROAMING = 5; // 0x5
-    field public static final int INVALID_RESULT = -1; // 0xffffffff
   }
 
 }
@@ -4970,7 +4960,7 @@
     method public void resetRtlProperties();
     method public boolean restoreFocusInCluster(int);
     method public boolean restoreFocusNotInCluster();
-    method public void setAutofilled(boolean);
+    method public void setAutofilled(boolean, boolean);
     method public final void setFocusedInCluster();
     method public void setIsRootNamespace(boolean);
     method public final void setShowingLayoutBounds(boolean);
@@ -5084,6 +5074,7 @@
     method public long getEventTime();
     method @Nullable public android.view.autofill.AutofillId getId();
     method @Nullable public java.util.List<android.view.autofill.AutofillId> getIds();
+    method @Nullable public android.graphics.Insets getInsets();
     method @Nullable public CharSequence getText();
     method public int getType();
     method @Nullable public android.view.contentcapture.ViewNode getViewNode();
@@ -5094,6 +5085,7 @@
     field public static final int TYPE_SESSION_RESUMED = 7; // 0x7
     field public static final int TYPE_VIEW_APPEARED = 1; // 0x1
     field public static final int TYPE_VIEW_DISAPPEARED = 2; // 0x2
+    field public static final int TYPE_VIEW_INSETS_CHANGED = 9; // 0x9
     field public static final int TYPE_VIEW_TEXT_CHANGED = 3; // 0x3
     field public static final int TYPE_VIEW_TREE_APPEARED = 5; // 0x5
     field public static final int TYPE_VIEW_TREE_APPEARING = 4; // 0x4
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 56f2340..bd5bdc6 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -485,7 +485,7 @@
         PackageNotificationChannelGroupPreferences package_notification_channel_group_preferences =
                 10073 [(module) = "framework"];
         GnssStats gnss_stats = 10074 [(module) = "framework"];
-        AppFeaturesOps app_features_ops = 10075 [(module) = "framework"];
+        AttributedAppOps attributed_app_ops = 10075 [(module) = "framework"];
         VoiceCallSession voice_call_session = 10076 [(module) = "telephony"];
         VoiceCallRatUsage voice_call_rat_usage = 10077 [(module) = "telephony"];
         SimSlotState sim_slot_state = 10078 [(module) = "telephony"];
@@ -7603,18 +7603,19 @@
 }
 
 /**
- * Historical app ops data per package and features.
+ * Historical app ops data per package and attribution tag.
  */
-message AppFeaturesOps {
+message AttributedAppOps {
     // Uid of the package requesting the op
     optional int32 uid = 1 [(is_uid) = true];
 
     // Name of the package performing the op
     optional string package_name = 2;
 
-    // feature id; provided by developer when accessing related API, limited at 50 chars by API.
-    // Features must be provided through manifest using <feature> tag available in R and above.
-    optional string feature_id = 3;
+    // tag; provided by developer when accessing related API, limited at 50 chars by API.
+    // Attributions must be provided through manifest using <attribution> tag available in R and
+    // above.
+    optional string tag = 3;
 
     // operation id; maps to the OPSTR_* constants in AppOpsManager.java
     optional string op = 4;
@@ -8476,9 +8477,11 @@
     // operation string id per OPSTR_ constants in AppOpsManager.java
     optional string op = 3;
 
-    // feature id; provided by developer when accessing related API, limited at 50 chars by API.
-    // Features must be provided through manifest using <feature> tag available in R and above.
-    optional string feature_id = 4;
+    // attribution_tag; provided by developer when accessing related API, limited at 50 chars by
+    // API.
+    // Attributions must be provided through manifest using <attribution> tag available in R and
+    // above.
+    optional string attribution_tag = 4;
 
     // message related to app op access, limited to 600 chars by API
     optional string message = 5;
diff --git a/cmds/statsd/src/logd/LogEvent.cpp b/cmds/statsd/src/logd/LogEvent.cpp
index 258f84d..b515d0a 100644
--- a/cmds/statsd/src/logd/LogEvent.cpp
+++ b/cmds/statsd/src/logd/LogEvent.cpp
@@ -350,17 +350,19 @@
     return false;
 }
 
-void LogEvent::parseInt32(int32_t* pos, int32_t depth, bool* last) {
+void LogEvent::parseInt32(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations) {
     int32_t value = readNextValue<int32_t>();
     addToValues(pos, depth, value, last);
+    parseAnnotations(numAnnotations);
 }
 
-void LogEvent::parseInt64(int32_t* pos, int32_t depth, bool* last) {
+void LogEvent::parseInt64(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations) {
     int64_t value = readNextValue<int64_t>();
     addToValues(pos, depth, value, last);
+    parseAnnotations(numAnnotations);
 }
 
-void LogEvent::parseString(int32_t* pos, int32_t depth, bool* last) {
+void LogEvent::parseString(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations) {
     int32_t numBytes = readNextValue<int32_t>();
     if ((uint32_t)numBytes > mRemainingLen) {
         mValid = false;
@@ -371,20 +373,23 @@
     mBuf += numBytes;
     mRemainingLen -= numBytes;
     addToValues(pos, depth, value, last);
+    parseAnnotations(numAnnotations);
 }
 
-void LogEvent::parseFloat(int32_t* pos, int32_t depth, bool* last) {
+void LogEvent::parseFloat(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations) {
     float value = readNextValue<float>();
     addToValues(pos, depth, value, last);
+    parseAnnotations(numAnnotations);
 }
 
-void LogEvent::parseBool(int32_t* pos, int32_t depth, bool* last) {
+void LogEvent::parseBool(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations) {
     // cast to int32_t because FieldValue does not support bools
     int32_t value = (int32_t)readNextValue<uint8_t>();
     addToValues(pos, depth, value, last);
+    parseAnnotations(numAnnotations);
 }
 
-void LogEvent::parseByteArray(int32_t* pos, int32_t depth, bool* last) {
+void LogEvent::parseByteArray(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations) {
     int32_t numBytes = readNextValue<int32_t>();
     if ((uint32_t)numBytes > mRemainingLen) {
         mValid = false;
@@ -395,9 +400,10 @@
     mBuf += numBytes;
     mRemainingLen -= numBytes;
     addToValues(pos, depth, value, last);
+    parseAnnotations(numAnnotations);
 }
 
-void LogEvent::parseKeyValuePairs(int32_t* pos, int32_t depth, bool* last) {
+void LogEvent::parseKeyValuePairs(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations) {
     int32_t numPairs = readNextValue<uint8_t>();
 
     for (pos[1] = 1; pos[1] <= numPairs; pos[1]++) {
@@ -405,56 +411,79 @@
 
         // parse key
         pos[2] = 1;
-        parseInt32(pos, 2, last);
+        parseInt32(pos, /*depth=*/2, last, /*numAnnotations=*/0);
 
         // parse value
         last[2] = true;
-        uint8_t typeId = getTypeId(readNextValue<uint8_t>());
-        switch (typeId) {
+
+        uint8_t typeInfo = readNextValue<uint8_t>();
+        switch (getTypeId(typeInfo)) {
             case INT32_TYPE:
                 pos[2] = 2; // pos[2] determined by index of type in KeyValuePair in atoms.proto
-                parseInt32(pos, 2, last);
+                parseInt32(pos, /*depth=*/2, last, /*numAnnotations=*/0);
                 break;
             case INT64_TYPE:
                 pos[2] = 3;
-                parseInt64(pos, 2, last);
+                parseInt64(pos, /*depth=*/2, last, /*numAnnotations=*/0);
                 break;
             case STRING_TYPE:
                 pos[2] = 4;
-                parseString(pos, 2, last);
+                parseString(pos, /*depth=*/2, last, /*numAnnotations=*/0);
                 break;
             case FLOAT_TYPE:
                 pos[2] = 5;
-                parseFloat(pos, 2, last);
+                parseFloat(pos, /*depth=*/2, last, /*numAnnotations=*/0);
                 break;
             default:
                 mValid = false;
         }
     }
 
+    parseAnnotations(numAnnotations);
+
     pos[1] = pos[2] = 1;
     last[1] = last[2] = false;
 }
 
-void LogEvent::parseAttributionChain(int32_t* pos, int32_t depth, bool* last) {
+void LogEvent::parseAttributionChain(int32_t* pos, int32_t depth, bool* last,
+                                     uint8_t numAnnotations) {
     int32_t numNodes = readNextValue<uint8_t>();
     for (pos[1] = 1; pos[1] <= numNodes; pos[1]++) {
         last[1] = (pos[1] == numNodes);
 
         // parse uid
         pos[2] = 1;
-        parseInt32(pos, 2, last);
+        parseInt32(pos, /*depth=*/2, last, /*numAnnotations=*/0);
 
         // parse tag
         pos[2] = 2;
         last[2] = true;
-        parseString(pos, 2, last);
+        parseString(pos, /*depth=*/2, last, /*numAnnotations=*/0);
     }
 
+    parseAnnotations(numAnnotations);
+
     pos[1] = pos[2] = 1;
     last[1] = last[2] = false;
 }
 
+// TODO(b/151109630): store annotation information within LogEvent
+void LogEvent::parseAnnotations(uint8_t numAnnotations) {
+    for (uint8_t i = 0; i < numAnnotations; i++) {
+        /*uint8_t annotationId = */ readNextValue<uint8_t>();
+        uint8_t annotationType = readNextValue<uint8_t>();
+        switch (annotationType) {
+            case BOOL_TYPE:
+                /*bool annotationValue = */ readNextValue<uint8_t>();
+                break;
+            case INT32_TYPE:
+                /*int32_t annotationValue =*/ readNextValue<int32_t>();
+                break;
+            default:
+                mValid = false;
+        }
+    }
+}
 
 // This parsing logic is tied to the encoding scheme used in StatsEvent.java and
 // stats_event.c
@@ -475,6 +504,7 @@
     typeInfo = readNextValue<uint8_t>();
     if (getTypeId(typeInfo) != INT64_TYPE) mValid = false;
     mElapsedTimestampNs = readNextValue<int64_t>();
+    parseAnnotations(getNumAnnotations(typeInfo)); // atom-level annotations
     numElements--;
 
     typeInfo = readNextValue<uint8_t>();
@@ -484,37 +514,36 @@
 
 
     for (pos[0] = 1; pos[0] <= numElements && mValid; pos[0]++) {
+        last[0] = (pos[0] == numElements);
+
         typeInfo = readNextValue<uint8_t>();
         uint8_t typeId = getTypeId(typeInfo);
 
-        last[0] = (pos[0] == numElements);
-
         // TODO(b/144373276): handle errors passed to the socket
-        // TODO(b/144373257): parse annotations
         switch(typeId) {
             case BOOL_TYPE:
-                parseBool(pos, 0, last);
+                parseBool(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
                 break;
             case INT32_TYPE:
-                parseInt32(pos, 0, last);
+                parseInt32(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
                 break;
             case INT64_TYPE:
-                parseInt64(pos, 0, last);
+                parseInt64(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
                 break;
             case FLOAT_TYPE:
-                parseFloat(pos, 0, last);
+                parseFloat(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
                 break;
             case BYTE_ARRAY_TYPE:
-                parseByteArray(pos, 0, last);
+                parseByteArray(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
                 break;
             case STRING_TYPE:
-                parseString(pos, 0, last);
+                parseString(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
                 break;
             case KEY_VALUE_PAIRS_TYPE:
-                parseKeyValuePairs(pos, 0, last);
+                parseKeyValuePairs(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
                 break;
             case ATTRIBUTION_CHAIN_TYPE:
-                parseAttributionChain(pos, 0, last);
+                parseAttributionChain(pos, /*depth=*/0, last, getNumAnnotations(typeInfo));
                 break;
             default:
                 mValid = false;
@@ -531,7 +560,7 @@
 }
 
 uint8_t LogEvent::getNumAnnotations(uint8_t typeInfo) {
-    return (typeInfo >> 4) & 0x0F;
+    return (typeInfo >> 4) & 0x0F; // num annotations in upper 4 bytes
 }
 
 int64_t LogEvent::GetLong(size_t key, status_t* err) const {
diff --git a/cmds/statsd/src/logd/LogEvent.h b/cmds/statsd/src/logd/LogEvent.h
index b68eeb8..6537f13 100644
--- a/cmds/statsd/src/logd/LogEvent.h
+++ b/cmds/statsd/src/logd/LogEvent.h
@@ -232,14 +232,15 @@
      */
     LogEvent(const LogEvent&);
 
-    void parseInt32(int32_t* pos, int32_t depth, bool* last);
-    void parseInt64(int32_t* pos, int32_t depth, bool* last);
-    void parseString(int32_t* pos, int32_t depth, bool* last);
-    void parseFloat(int32_t* pos, int32_t depth, bool* last);
-    void parseBool(int32_t* pos, int32_t depth, bool* last);
-    void parseByteArray(int32_t* pos, int32_t depth, bool* last);
-    void parseKeyValuePairs(int32_t* pos, int32_t depth, bool* last);
-    void parseAttributionChain(int32_t* pos, int32_t depth, bool* last);
+    void parseInt32(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations);
+    void parseInt64(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations);
+    void parseString(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations);
+    void parseFloat(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations);
+    void parseBool(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations);
+    void parseByteArray(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations);
+    void parseKeyValuePairs(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations);
+    void parseAttributionChain(int32_t* pos, int32_t depth, bool* last, uint8_t numAnnotations);
+    void parseAnnotations(uint8_t numAnnotations);
 
     /**
      * The below three variables are only valid during the execution of
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index 8d6bc72..6480a6a 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -5829,7 +5829,7 @@
                 intent.prepareToLeaveProcess(this);
                 result = ActivityTaskManager.getService()
                     .startActivity(mMainThread.getApplicationThread(), getBasePackageName(),
-                            getFeatureId(), intent,
+                            getAttributionTag(), intent,
                             intent.resolveTypeIfNeeded(getContentResolver()), mToken, mEmbeddedID,
                             requestCode, ActivityManager.START_FLAG_ONLY_IF_NEEDED, null, options);
             } catch (RemoteException e) {
@@ -6624,12 +6624,10 @@
         String packageName = getPackageName();
         try {
             data.prepareToLeaveProcess(this);
-            IIntentSender target =
-                ActivityManager.getService().getIntentSenderWithFeature(
-                        ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, getFeatureId(),
-                        mParent == null ? mToken : mParent.mToken,
-                        mEmbeddedID, requestCode, new Intent[] { data }, null, flags, null,
-                        getUserId());
+            IIntentSender target = ActivityManager.getService().getIntentSenderWithFeature(
+                    ActivityManager.INTENT_SENDER_ACTIVITY_RESULT, packageName, getAttributionTag(),
+                    mParent == null ? mToken : mParent.mToken, mEmbeddedID, requestCode,
+                    new Intent[]{data}, null, flags, null, getUserId());
             return target != null ? new PendingIntent(target) : null;
         } catch (RemoteException e) {
             // Empty
diff --git a/core/java/android/app/ActivityManager.java b/core/java/android/app/ActivityManager.java
index dd4788e..1a92b75 100644
--- a/core/java/android/app/ActivityManager.java
+++ b/core/java/android/app/ActivityManager.java
@@ -4243,6 +4243,7 @@
      * @hide
      */
     @SystemApi
+    @TestApi
     @RequiresPermission(android.Manifest.permission.CHANGE_CONFIGURATION)
     public boolean updateMccMncConfiguration(@NonNull String mcc, @NonNull String mnc) {
         if (mcc == null || mnc == null) {
diff --git a/core/java/android/app/AppOps.md b/core/java/android/app/AppOps.md
new file mode 100644
index 0000000..bee701a
--- /dev/null
+++ b/core/java/android/app/AppOps.md
@@ -0,0 +1,212 @@
+<!--
+  Copyright (C) 2020 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
+  -->
+
+# App-ops
+
+App-ops are used for two purposes: Access control and tracking.
+
+App-ops cover a wide variety of functionality from helping with runtime permissions to battery
+consumption tracking.
+
+App-ops are defined in `AppOpsManager` as `OP_...` and need to be continuously numbered. The
+integer values of the app-ops are not exposed. For app-ops visible to 3rd party apps,
+the name of the app-op might be exposed as `OPSTR_`. As the integers are not part of the API, they
+might (and have) changed between platform versions and OEM implementations.
+`AppOpsManager.opToPublicName` and `AppOpsManager.strOpToOp` allow for conversion between integer
+and string identifier for the op.
+
+## App-ops as access restrictions
+
+App-ops can either be controlled for each [uid](../os/Users.md#int-uid) or for each package. Which
+one is used depends on the API provider maintaining this app-op.
+
+For any security or privacy related app-ops the provider needs to control the app-op per uid
+as all security and privacy is based on uid in Android.
+
+App-op used for non-security related tasks are usually controlled per package to provide finer
+granularity.
+
+### Setting the app-op mode
+
+To control access the app-op can be set to:
+
+`MODE_DEFAULT`
+: Default behavior, might differ from app-op to app-op
+
+`MODE_ALLOWED`
+: Allow the access
+
+`MODE_FOREGROUND`
+: Allow the access but only if the app is currently in the [foreground](#foreground)
+
+`MODE_IGNORED`
+: Don't allow the access, i.e. don't perform the requested action or return dummy data
+
+`MODE_ERRORED`
+: Throw a `SecurityException` on access. This can be suppressed by using a `...noThrow` method to
+check the mode
+
+The initial state of an app-op is defined in `AppOpsManager.sOpDefaultMode`. Confusingly the
+initial state is often not `MODE_DEFAULT`
+
+Per-package modes can be set using `AppOpsManager.setMode` and per-uid modes can be set using
+`AppOpsManager.setUidMode`.
+
+**Warning**: Do not use `setMode` and `setUidMode` for the same app-op. Due to the way the
+internal storage for the mode works this can lead to very confusing behavior. If this ever happened
+by accident this needs to be cleaned up for any affected user as the app-op mode is retained over
+reboot.
+
+App-ops can also be set via the shell using the `appops set` command. The target package/uid can be
+defined via parameters to this command.
+
+The current state of the app-op can be read via the `appops get` command or via `dumpsys appops`.
+If the app-op is not mentioned in the output the app-op is in it's initial state.
+
+For example `dumpsys appops`:
+```
+[...]
+  Uid 2000:
+    [...]
+      COARSE_LOCATION: mode=foreground
+      START_FOREGROUND: mode=foreground
+      LEGACY_STORAGE: mode=ignore
+    [...]
+```
+
+### Guarding access based on app-ops
+
+API providers need to check the mode returned by `AppOpsManager.noteOp` if they are are allowing
+access to operations gated by the app-op. `AppOpsManager.unsafeCheckOp` should be used to check the
+mode if no access is granted. E.g. this can be for displaying app-op state in the UI or when
+checking the state before later calling `noteOp` anyway.
+
+If an operation refers to a time span (e.g. a audio-recording session) the API provider should
+use `AppOpsManager.startOp` and `AppOpsManager.finishOp` instead of `noteOp`.
+
+`noteOp` and `startOp` take a `packageName` and `featureId` parameter. These need to be read from
+the calling apps context as `Context.getOpPackageName` and `Context.getFeatureId`, then send to
+the data provider and then passed on the `noteOp`/`startOp` method.
+
+#### App-ops and permissions
+
+Access guarding is often done in combination with permissions using [runtime permissions
+](../permission/Permissions.md#runtime-permissions-and-app-ops) or [app-op permissions
+](../permission/Permissions.md#app-op-permissions). This is preferred over just using an app-op
+ as permissions a concept more familiar to app developers.
+
+### Foreground
+
+The `AppOpsService` tracks the apps' proc state (== foreground-ness) by following the
+`ActivityManagerService`'s proc state. It reduces the possible proc states to only those needed
+for app-ops. It also delays the changes by a _settle time_. This delay is needed as the proc state
+can fluctuate when switching apps. By delaying the change the appops service is not affected by
+those.
+
+The proc state is used for two use cases: Firstly, Tracking remembers the proc state for each
+tracked event. Secondly, `noteOp`/`checkOp` calls for app-op that are set to `MODE_FOREGROUND` are
+translated using the `AppOpsService.UidState.evalMode` method into `MODE_ALLOWED` when the app is
+counted as foreground and `MODE_IGNORED` when the app is counted as background. `checkOpRaw`
+calls are not affected.
+
+The current proc state for an app can be read from `dumpsys appops`. The tracking information can
+be read from `dumpsys appops`
+
+```
+Uid u0a118:
+  state=fg
+  capability=6
+```
+
+## App-ops for tracking
+
+App-ops track many important events, including all accesses to runtime permission protected
+APIs. This is done by tracking when an app-op was noted or started. The tracked data can only be
+read by system components.
+
+**Note:** Only `noteOp`/`startOp` calls are tracked; `unsafeCheckOp` is not tracked. Hence it is
+important to eventually call `noteOp` or `startOp` when providing access to protected operations
+or data.
+
+Some apps are forwarding access to other apps. E.g. an app might get the location from the
+system's location provider and then send the location further to a 3rd app. In this case the
+app passing on the data needs to call `AppOpsManager.noteProxyOp` to signal the access proxying.
+This might also make sense inside of a single app if the access is forwarded between two features of
+the app. In this case an app-op is noted for the forwarding app (proxy) and the app that received
+the data (proxied). As any app can do it is important to track how much the system trusts this
+proxy-access-tracking. For more details see `AppOpService.noteProxyOperation`.
+
+The tracking information can be read from `dumpsys appops` split by feature, proc state and
+proxying information with the syntax
+
+```
+Package THE_PACKAGE_NAME:
+  AN_APP_OP (CURRENT_MODE):
+    FEATURE_ID (or null for default feature)=[
+      ACCESS_OR_REJECT: [PROC_STATE-PROXYING_TAG] TIME proxy[INFO_ABOUT_PROXY IF_PROXY_ACCESS]
+```
+
+Example:
+
+```
+Package com.google.android.gms:
+  READ_CONTACTS (allow):
+    null=[
+      Access: [fgsvc-s] 2020-02-14 14:24:10.559 (-3d23h15m43s642ms)
+      Access: [fgsvc-tp] 2020-02-14 14:23:58.189 (-3d23h15m56s12ms)
+    ]
+    apkappcontext=[
+      Access: [fg-tp] 2020-02-17 14:24:54.721 (-23h14m59s480ms)
+    ]
+    com.google.android.gms.icing=[
+      Access: [fgsvc-tpd] 2020-02-14 14:26:27.018 (-3d23h13m27s183ms) proxy[uid=10070, pkg=com.android.providers.contacts, feature=null]
+      Access: [fg-tpd] 2020-02-18 02:26:08.711 (-11h13m45s490ms) proxy[uid=10070, pkg=com.android.providers.contacts, feature=null]
+      Access: [bg-tpd] 2020-02-14 14:34:55.310 (-3d23h4m58s891ms) proxy[uid=10070, pkg=com.android.providers.contacts, feature=null]
+    ]
+  MANAGE_EXTERNAL_STORAGE (default):
+    null=[
+      Reject: [fg-s]2020-02-18 08:00:04.444 (-5h39m49s757ms)
+      Reject: [bg-s]2020-02-18 08:00:04.427 (-5h39m49s774ms)
+    ]
+```
+
+### Tracking an app's own private data accesses
+
+An app can register an `AppOpsManager.OnOpNotedCallback` to get informed about what accesses the
+system is tracking for it. As each runtime permission has an associated app-op this API is
+particularly useful for an app that want to find unexpected private data accesses.
+
+## Listening to app-op events
+
+System apps (with the appropriate permissions) can listen to most app-op events, such as
+
+`noteOp`
+: `startWatchingNoted`
+
+`startOp`/`finishOp`
+: `startWatchingActive`
+
+mode changes
+: `startWatchingMode`
+
+[foreground](#foreground)-ness changes
+: `startWatchingMode` using the `WATCH_FOREGROUND_CHANGES` flag
+
+Watching such events is only ever as good as the tracked events. E.g. if the audio provider does
+not call `startOp` for a audio-session, the app's activeness for the record-audio app-op is not
+changed. Further there were cases where app-ops were noted even though no data was accessed or
+operation was performed. Hence before relying on the data from app-ops, double check if the data
+is actually reliable.
diff --git a/core/java/android/app/AppOpsManager.java b/core/java/android/app/AppOpsManager.java
index 9925d69..f6a79cd 100644
--- a/core/java/android/app/AppOpsManager.java
+++ b/core/java/android/app/AppOpsManager.java
@@ -160,8 +160,8 @@
  * <p>Some apps are forwarding access to other apps. E.g. an app might get the location from the
  * system's location provider and then send the location further to a 3rd app. In this case the
  * app passing on the data needs to call {@link #noteProxyOp} to signal the access proxying. This
- * might also make sense inside of a single app if the access is forwarded between two features of
- * the app.
+ * might also make sense inside of a single app if the access is forwarded between two parts of
+ * the tagged with different attribution tags.
  *
  * <p>An app can register an {@link OnOpNotedCallback} to get informed about what accesses the
  * system is tracking for it. As each runtime permission has an associated app-op this API is
@@ -2658,23 +2658,23 @@
         private @IntRange(from = 0) int mUid;
         /** Package of the proxy that noted the op */
         private @Nullable String mPackageName;
-        /** ID of the feature of the proxy that noted the op */
-        private @Nullable String mFeatureId;
+        /** Attribution tag of the proxy that noted the op */
+        private @Nullable String mAttributionTag;
 
         /**
          * Reinit existing object with new state.
          *
          * @param uid UID of the proxy app that noted the op
          * @param packageName Package of the proxy that noted the op
-         * @param featureId ID of the feature of the proxy that noted the op
+         * @param attributionTag attribution tag of the proxy that noted the op
          *
          * @hide
          */
         public void reinit(@IntRange(from = 0) int uid, @Nullable String packageName,
-                @Nullable String featureId) {
+                @Nullable String attributionTag) {
             mUid = Preconditions.checkArgumentNonnegative(uid);
             mPackageName = packageName;
-            mFeatureId = featureId;
+            mAttributionTag = attributionTag;
         }
 
 
@@ -2699,21 +2699,21 @@
          *   UID of the proxy app that noted the op
          * @param packageName
          *   Package of the proxy that noted the op
-         * @param featureId
-         *   ID of the feature of the proxy that noted the op
+         * @param attributionTag
+         *   Attribution tag of the proxy that noted the op
          * @hide
          */
         @DataClass.Generated.Member
         public OpEventProxyInfo(
                 @IntRange(from = 0) int uid,
                 @Nullable String packageName,
-                @Nullable String featureId) {
+                @Nullable String attributionTag) {
             this.mUid = uid;
             com.android.internal.util.AnnotationValidations.validate(
                     IntRange.class, null, mUid,
                     "from", 0);
             this.mPackageName = packageName;
-            this.mFeatureId = featureId;
+            this.mAttributionTag = attributionTag;
 
             // onConstructed(); // You can define this method to get a callback
         }
@@ -2727,7 +2727,7 @@
         public OpEventProxyInfo(@NonNull OpEventProxyInfo orig) {
             mUid = orig.mUid;
             mPackageName = orig.mPackageName;
-            mFeatureId = orig.mFeatureId;
+            mAttributionTag = orig.mAttributionTag;
         }
 
         /**
@@ -2747,11 +2747,11 @@
         }
 
         /**
-         * ID of the feature of the proxy that noted the op
+         * Attribution tag of the proxy that noted the op
          */
         @DataClass.Generated.Member
-        public @Nullable String getFeatureId() {
-            return mFeatureId;
+        public @Nullable String getAttributionTag() {
+            return mAttributionTag;
         }
 
         @Override
@@ -2762,11 +2762,11 @@
 
             byte flg = 0;
             if (mPackageName != null) flg |= 0x2;
-            if (mFeatureId != null) flg |= 0x4;
+            if (mAttributionTag != null) flg |= 0x4;
             dest.writeByte(flg);
             dest.writeInt(mUid);
             if (mPackageName != null) dest.writeString(mPackageName);
-            if (mFeatureId != null) dest.writeString(mFeatureId);
+            if (mAttributionTag != null) dest.writeString(mAttributionTag);
         }
 
         @Override
@@ -2783,14 +2783,14 @@
             byte flg = in.readByte();
             int uid = in.readInt();
             String packageName = (flg & 0x2) == 0 ? null : in.readString();
-            String featureId = (flg & 0x4) == 0 ? null : in.readString();
+            String attributionTag = (flg & 0x4) == 0 ? null : in.readString();
 
             this.mUid = uid;
             com.android.internal.util.AnnotationValidations.validate(
                     IntRange.class, null, mUid,
                     "from", 0);
             this.mPackageName = packageName;
-            this.mFeatureId = featureId;
+            this.mAttributionTag = attributionTag;
 
             // onConstructed(); // You can define this method to get a callback
         }
@@ -2814,7 +2814,7 @@
                 time = 1576814974615L,
                 codegenVersion = "1.0.14",
                 sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
-                inputSignatures = "private @android.annotation.IntRange(from=0L) int mUid\nprivate @android.annotation.Nullable java.lang.String mPackageName\nprivate @android.annotation.Nullable java.lang.String mFeatureId\npublic  void reinit(int,java.lang.String,java.lang.String)\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genHiddenCopyConstructor=true)")
+                inputSignatures = "private @android.annotation.IntRange(from=0L) int mUid\nprivate @android.annotation.Nullable java.lang.String mPackageName\nprivate @android.annotation.Nullable java.lang.String mAttributionTag\npublic  void reinit(int,java.lang.String,java.lang.String)\nclass OpEventProxyInfo extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genHiddenCopyConstructor=true)")
         @Deprecated
         private void __metadata() {}
         */
@@ -3013,7 +3013,7 @@
 
     /**
      * Last {@link #noteOp} and {@link #startOp} events performed for a single op and a specific
-     * {@link Context#createFeatureContext(String) feature} for all uidModes and opFlags.
+     * {@link Context#createAttributionContext(String) attribution} for all uidModes and opFlags.
      *
      * @hide
      */
@@ -3022,7 +3022,7 @@
     @Immutable
     // @DataClass(genHiddenConstructor = true) codegen verifier is broken
     @DataClass.Suppress({"getAccessEvents", "getRejectEvents", "getOp"})
-    public static final class OpFeatureEntry implements Parcelable {
+    public static final class AttributedOpEntry implements Parcelable {
         /** The code of the op */
         private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp;
         /** Whether the op is running */
@@ -3321,8 +3321,8 @@
         }
 
         /**
-         * Gets the proxy info of the app that performed the last access on behalf of this feature
-         * and as a result blamed the op on this app.
+         * Gets the proxy info of the app that performed the last access on behalf of this
+         * attribution and as a result blamed the op on this attribution.
          *
          * @param flags The op flags
          *
@@ -3339,7 +3339,7 @@
 
         /**
          * Gets the proxy info of the app that performed the last foreground access on behalf of
-         * this feature and as a result blamed the op on this app.
+         * this attribution and as a result blamed the op on this attribution.
          *
          * @param flags The op flags
          *
@@ -3357,7 +3357,7 @@
 
         /**
          * Gets the proxy info of the app that performed the last background access on behalf of
-         * this feature and as a result blamed the op on this app.
+         * this attribution and as a result blamed the op on this attribution.
          *
          * @param flags The op flags
          *
@@ -3374,8 +3374,8 @@
         }
 
         /**
-         * Gets the proxy info of the app that performed the last access on behalf of this feature
-         * and as a result blamed the op on this app.
+         * Gets the proxy info of the app that performed the last access on behalf of this
+         * attribution and as a result blamed the op on this attribution.
          *
          * @param fromUidState The lowest UID state for which to query
          * @param toUidState The highest UID state for which to query (inclusive)
@@ -3450,7 +3450,7 @@
 
 
         /**
-         * Creates a new OpFeatureEntry.
+         * Creates a new OpAttributionEntry.
          *
          * @param op
          *   The code of the op
@@ -3463,7 +3463,7 @@
          * @hide
          */
         @DataClass.Generated.Member
-        public OpFeatureEntry(
+        public AttributedOpEntry(
                 @IntRange(from = 0, to = _NUM_OP - 1) int op,
                 boolean running,
                 @Nullable LongSparseArray<NoteOpEvent> accessEvents,
@@ -3533,7 +3533,7 @@
         /** @hide */
         @SuppressWarnings({"unchecked", "RedundantCast"})
         @DataClass.Generated.Member
-        /* package-private */ OpFeatureEntry(@NonNull Parcel in) {
+        /* package-private */ AttributedOpEntry(@NonNull Parcel in) {
             // You can override field unparcelling by defining methods like:
             // static FieldType unparcelFieldName(Parcel in) { ... }
 
@@ -3556,16 +3556,16 @@
         }
 
         @DataClass.Generated.Member
-        public static final @NonNull Parcelable.Creator<OpFeatureEntry> CREATOR
-                = new Parcelable.Creator<OpFeatureEntry>() {
+        public static final @NonNull Parcelable.Creator<AttributedOpEntry> CREATOR
+                = new Parcelable.Creator<AttributedOpEntry>() {
             @Override
-            public OpFeatureEntry[] newArray(int size) {
-                return new OpFeatureEntry[size];
+            public AttributedOpEntry[] newArray(int size) {
+                return new AttributedOpEntry[size];
             }
 
             @Override
-            public OpFeatureEntry createFromParcel(@NonNull Parcel in) {
-                return new OpFeatureEntry(in);
+            public AttributedOpEntry createFromParcel(@NonNull Parcel in) {
+                return new AttributedOpEntry(in);
             }
         };
 
@@ -3574,7 +3574,7 @@
                 time = 1574809856239L,
                 codegenVersion = "1.0.14",
                 sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
-                inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final  boolean mRunning\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpFeatureEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray<android.app.NoteOpEvent> mAccessEvents\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpFeatureEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray<android.app.NoteOpEvent> mRejectEvents\npublic @android.annotation.NonNull android.util.ArraySet<java.lang.Long> collectKeys()\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic  long getAccessTime(int,int)\npublic  long getRejectTime(int,int)\npublic  long getDuration(int,int)\npublic  int getProxyUid(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyFeatureId(int,int)\nclass OpFeatureEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
+                inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final  boolean mRunning\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpAttributionEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray<android.app.NoteOpEvent> mAccessEvents\nprivate final @com.android.internal.util.DataClass.ParcelWith(android.app.OpAttributionEntry.LongSparseArrayParceling.class) @android.annotation.Nullable android.util.LongSparseArray<android.app.NoteOpEvent> mRejectEvents\npublic @android.annotation.NonNull android.util.ArraySet<java.lang.Long> collectKeys()\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic  long getAccessTime(int,int)\npublic  long getRejectTime(int,int)\npublic  long getDuration(int,int)\npublic  int getProxyUid(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\npublic @android.annotation.Nullable java.lang.String getProxyAttributionTag(int,int)\nclass OpAttributionEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
         @Deprecated
         private void __metadata() {}
          */
@@ -3600,8 +3600,8 @@
         private final @IntRange(from = 0, to = _NUM_OP - 1) int mOp;
         /** The mode of the op */
         private final @Mode int mMode;
-        /** The features that have been used when checking the op */
-        private final @NonNull Map<String, OpFeatureEntry> mFeatures;
+        /** The attributed entries by attribution tag */
+        private final @NonNull Map<String, AttributedOpEntry> mAttributedOpEntries;
 
         /**
          * @hide
@@ -3642,7 +3642,7 @@
          * @see #getLastAccessForegroundTime(int)
          * @see #getLastAccessBackgroundTime(int)
          * @see #getLastAccessTime(int, int, int)
-         * @see OpFeatureEntry#getLastAccessTime(int)
+         * @see AttributedOpEntry#getLastAccessTime(int)
          */
         public long getLastAccessTime(@OpFlags int flags) {
             return getLastAccessTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
@@ -3659,7 +3659,7 @@
          * @see #getLastAccessTime(int)
          * @see #getLastAccessBackgroundTime(int)
          * @see #getLastAccessTime(int, int, int)
-         * @see OpFeatureEntry#getLastAccessForegroundTime(int)
+         * @see AttributedOpEntry#getLastAccessForegroundTime(int)
          */
         public long getLastAccessForegroundTime(@OpFlags int flags) {
             return getLastAccessTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
@@ -3677,7 +3677,7 @@
          * @see #getLastAccessTime(int)
          * @see #getLastAccessForegroundTime(int)
          * @see #getLastAccessTime(int, int, int)
-         * @see OpFeatureEntry#getLastAccessBackgroundTime(int)
+         * @see AttributedOpEntry#getLastAccessBackgroundTime(int)
          */
         public long getLastAccessBackgroundTime(@OpFlags int flags) {
             return getLastAccessTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
@@ -3694,13 +3694,14 @@
         private @Nullable NoteOpEvent getLastAccessEvent(@UidState int fromUidState,
                 @UidState int toUidState, @OpFlags int flags) {
             NoteOpEvent lastAccessEvent = null;
-            for (OpFeatureEntry featureEntry : mFeatures.values()) {
-                NoteOpEvent lastFeatureAccessEvent = featureEntry.getLastAccessEvent(fromUidState,
-                        toUidState, flags);
+            for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) {
+                NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastAccessEvent(
+                        fromUidState, toUidState, flags);
 
-                if (lastAccessEvent == null || (lastFeatureAccessEvent != null
-                        && lastFeatureAccessEvent.getNoteTime() > lastAccessEvent.getNoteTime())) {
-                    lastAccessEvent = lastFeatureAccessEvent;
+                if (lastAccessEvent == null || (lastAttributionAccessEvent != null
+                        && lastAttributionAccessEvent.getNoteTime()
+                        > lastAccessEvent.getNoteTime())) {
+                    lastAccessEvent = lastAttributionAccessEvent;
                 }
             }
 
@@ -3720,7 +3721,7 @@
          * @see #getLastAccessTime(int)
          * @see #getLastAccessForegroundTime(int)
          * @see #getLastAccessBackgroundTime(int)
-         * @see OpFeatureEntry#getLastAccessTime(int, int, int)
+         * @see AttributedOpEntry#getLastAccessTime(int, int, int)
          */
         public long getLastAccessTime(@UidState int fromUidState, @UidState int toUidState,
                 @OpFlags int flags) {
@@ -3756,7 +3757,7 @@
          * @see #getLastRejectForegroundTime(int)
          * @see #getLastRejectBackgroundTime(int)
          * @see #getLastRejectTime(int, int, int)
-         * @see OpFeatureEntry#getLastRejectTime(int)
+         * @see AttributedOpEntry#getLastRejectTime(int)
          */
         public long getLastRejectTime(@OpFlags int flags) {
             return getLastRejectTime(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
@@ -3773,7 +3774,7 @@
          * @see #getLastRejectTime(int)
          * @see #getLastRejectBackgroundTime(int)
          * @see #getLastRejectTime(int, int, int)
-         * @see OpFeatureEntry#getLastRejectForegroundTime(int)
+         * @see AttributedOpEntry#getLastRejectForegroundTime(int)
          */
         public long getLastRejectForegroundTime(@OpFlags int flags) {
             return getLastRejectTime(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
@@ -3791,7 +3792,7 @@
          * @see #getLastRejectTime(int)
          * @see #getLastRejectForegroundTime(int)
          * @see #getLastRejectTime(int, int, int)
-         * @see OpFeatureEntry#getLastRejectBackgroundTime(int)
+         * @see AttributedOpEntry#getLastRejectBackgroundTime(int)
          */
         public long getLastRejectBackgroundTime(@OpFlags int flags) {
             return getLastRejectTime(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
@@ -3808,13 +3809,14 @@
         private @Nullable NoteOpEvent getLastRejectEvent(@UidState int fromUidState,
                 @UidState int toUidState, @OpFlags int flags) {
             NoteOpEvent lastAccessEvent = null;
-            for (OpFeatureEntry featureEntry : mFeatures.values()) {
-                NoteOpEvent lastFeatureAccessEvent = featureEntry.getLastRejectEvent(fromUidState,
-                        toUidState, flags);
+            for (AttributedOpEntry attributionEntry : mAttributedOpEntries.values()) {
+                NoteOpEvent lastAttributionAccessEvent = attributionEntry.getLastRejectEvent(
+                        fromUidState, toUidState, flags);
 
-                if (lastAccessEvent == null || (lastFeatureAccessEvent != null
-                        && lastFeatureAccessEvent.getNoteTime() > lastAccessEvent.getNoteTime())) {
-                    lastAccessEvent = lastFeatureAccessEvent;
+                if (lastAccessEvent == null || (lastAttributionAccessEvent != null
+                        && lastAttributionAccessEvent.getNoteTime()
+                        > lastAccessEvent.getNoteTime())) {
+                    lastAccessEvent = lastAttributionAccessEvent;
                 }
             }
 
@@ -3835,7 +3837,7 @@
          * @see #getLastRejectForegroundTime(int)
          * @see #getLastRejectBackgroundTime(int)
          * @see #getLastRejectTime(int, int, int)
-         * @see OpFeatureEntry#getLastRejectTime(int, int, int)
+         * @see AttributedOpEntry#getLastRejectTime(int, int, int)
          */
         public long getLastRejectTime(@UidState int fromUidState, @UidState int toUidState,
                 @OpFlags int flags) {
@@ -3851,8 +3853,8 @@
          * @return Whether the operation is running.
          */
         public boolean isRunning() {
-            for (OpFeatureEntry opFeatureEntry : mFeatures.values()) {
-                if (opFeatureEntry.isRunning()) {
+            for (AttributedOpEntry opAttributionEntry : mAttributedOpEntries.values()) {
+                if (opAttributionEntry.isRunning()) {
                     return true;
                 }
             }
@@ -3878,7 +3880,7 @@
          * @see #getLastForegroundDuration(int)
          * @see #getLastBackgroundDuration(int)
          * @see #getLastDuration(int, int, int)
-         * @see OpFeatureEntry#getLastDuration(int)
+         * @see AttributedOpEntry#getLastDuration(int)
          */
         public long getLastDuration(@OpFlags int flags) {
             return getLastDuration(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
@@ -3894,7 +3896,7 @@
          * @see #getLastDuration(int)
          * @see #getLastBackgroundDuration(int)
          * @see #getLastDuration(int, int, int)
-         * @see OpFeatureEntry#getLastForegroundDuration(int)
+         * @see AttributedOpEntry#getLastForegroundDuration(int)
          */
         public long getLastForegroundDuration(@OpFlags int flags) {
             return getLastDuration(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
@@ -3911,7 +3913,7 @@
          * @see #getLastDuration(int)
          * @see #getLastForegroundDuration(int)
          * @see #getLastDuration(int, int, int)
-         * @see OpFeatureEntry#getLastBackgroundDuration(int)
+         * @see AttributedOpEntry#getLastBackgroundDuration(int)
          */
         public long getLastBackgroundDuration(@OpFlags int flags) {
             return getLastDuration(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
@@ -3930,7 +3932,7 @@
          * @see #getLastDuration(int)
          * @see #getLastForegroundDuration(int)
          * @see #getLastBackgroundDuration(int)
-         * @see OpFeatureEntry#getLastDuration(int, int, int)
+         * @see AttributedOpEntry#getLastDuration(int, int, int)
          */
         public long getLastDuration(@UidState int fromUidState, @UidState int toUidState,
                 @OpFlags int flags) {
@@ -4005,7 +4007,7 @@
          * @see #getLastForegroundProxyInfo(int)
          * @see #getLastBackgroundProxyInfo(int)
          * @see #getLastProxyInfo(int, int, int)
-         * @see OpFeatureEntry#getLastProxyInfo(int)
+         * @see AttributedOpEntry#getLastProxyInfo(int)
          */
         public @Nullable OpEventProxyInfo getLastProxyInfo(@OpFlags int flags) {
             return getLastProxyInfo(MAX_PRIORITY_UID_STATE, MIN_PRIORITY_UID_STATE, flags);
@@ -4022,7 +4024,7 @@
          * @see #getLastProxyInfo(int)
          * @see #getLastBackgroundProxyInfo(int)
          * @see #getLastProxyInfo(int, int, int)
-         * @see OpFeatureEntry#getLastForegroundProxyInfo(int)
+         * @see AttributedOpEntry#getLastForegroundProxyInfo(int)
          */
         public @Nullable OpEventProxyInfo getLastForegroundProxyInfo(@OpFlags int flags) {
             return getLastProxyInfo(MAX_PRIORITY_UID_STATE, resolveFirstUnrestrictedUidState(mOp),
@@ -4040,7 +4042,7 @@
          * @see #getLastProxyInfo(int)
          * @see #getLastForegroundProxyInfo(int)
          * @see #getLastProxyInfo(int, int, int)
-         * @see OpFeatureEntry#getLastBackgroundProxyInfo(int)
+         * @see AttributedOpEntry#getLastBackgroundProxyInfo(int)
          */
         public @Nullable OpEventProxyInfo getLastBackgroundProxyInfo(@OpFlags int flags) {
             return getLastProxyInfo(resolveLastRestrictedUidState(mOp), MIN_PRIORITY_UID_STATE,
@@ -4060,7 +4062,7 @@
          * @see #getLastProxyInfo(int)
          * @see #getLastForegroundProxyInfo(int)
          * @see #getLastBackgroundProxyInfo(int)
-         * @see OpFeatureEntry#getLastProxyInfo(int, int, int)
+         * @see AttributedOpEntry#getLastProxyInfo(int, int, int)
          */
         public @Nullable OpEventProxyInfo getLastProxyInfo(@UidState int fromUidState,
                 @UidState int toUidState, @OpFlags int flags) {
@@ -4094,15 +4096,15 @@
          *   The code of the op
          * @param mode
          *   The mode of the op
-         * @param features
-         *   The features that have been used when checking the op
+         * @param attributedOpEntries
+         *   The attributions that have been used when noting the op
          * @hide
          */
         @DataClass.Generated.Member
         public OpEntry(
                 @IntRange(from = 0, to = _NUM_OP - 1) int op,
                 @Mode int mode,
-                @NonNull Map<String,OpFeatureEntry> features) {
+                @NonNull Map<String, AttributedOpEntry> attributedOpEntries) {
             this.mOp = op;
             com.android.internal.util.AnnotationValidations.validate(
                     IntRange.class, null, mOp,
@@ -4111,9 +4113,9 @@
             this.mMode = mode;
             com.android.internal.util.AnnotationValidations.validate(
                     Mode.class, null, mMode);
-            this.mFeatures = features;
+            this.mAttributedOpEntries = attributedOpEntries;
             com.android.internal.util.AnnotationValidations.validate(
-                    NonNull.class, null, mFeatures);
+                    NonNull.class, null, mAttributedOpEntries);
 
             // onConstructed(); // You can define this method to get a callback
         }
@@ -4127,14 +4129,14 @@
         }
 
         /**
-         * The features that have been used when checking the op keyed by id of the feature.
+         * The attributed entries keyed by attribution tag.
          *
-         * @see Context#createFeatureContext(String)
+         * @see Context#createAttributionContext(String)
          * @see #noteOp(String, int, String, String, String)
          */
         @DataClass.Generated.Member
-        public @NonNull Map<String,OpFeatureEntry> getFeatures() {
-            return mFeatures;
+        public @NonNull Map<String, AttributedOpEntry> getAttributedOpEntries() {
+            return mAttributedOpEntries;
         }
 
         @Override
@@ -4145,7 +4147,7 @@
 
             dest.writeInt(mOp);
             dest.writeInt(mMode);
-            dest.writeMap(mFeatures);
+            dest.writeMap(mAttributedOpEntries);
         }
 
         @Override
@@ -4161,8 +4163,8 @@
 
             int op = in.readInt();
             int mode = in.readInt();
-            Map<String,OpFeatureEntry> features = new java.util.LinkedHashMap<>();
-            in.readMap(features, OpFeatureEntry.class.getClassLoader());
+            Map<String, AttributedOpEntry> attributions = new java.util.LinkedHashMap<>();
+            in.readMap(attributions, AttributedOpEntry.class.getClassLoader());
 
             this.mOp = op;
             com.android.internal.util.AnnotationValidations.validate(
@@ -4172,9 +4174,9 @@
             this.mMode = mode;
             com.android.internal.util.AnnotationValidations.validate(
                     Mode.class, null, mMode);
-            this.mFeatures = features;
+            this.mAttributedOpEntries = attributions;
             com.android.internal.util.AnnotationValidations.validate(
-                    NonNull.class, null, mFeatures);
+                    NonNull.class, null, mAttributedOpEntries);
 
             // onConstructed(); // You can define this method to get a callback
         }
@@ -4198,7 +4200,7 @@
                 time = 1574809856259L,
                 codegenVersion = "1.0.14",
                 sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
-                inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final @android.app.Mode int mMode\nprivate final @android.annotation.NonNull java.util.Map<java.lang.String,android.app.OpFeatureEntry> mFeatures\npublic @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getOpStr()}\") int getOp()\npublic @android.annotation.NonNull java.lang.String getOpStr()\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getAccessTime(int, int)}\") long getTime()\npublic @java.lang.Deprecated long getLastAccessTime(int)\npublic @java.lang.Deprecated long getLastAccessForegroundTime(int)\npublic @java.lang.Deprecated long getLastAccessBackgroundTime(int)\npublic @java.lang.Deprecated long getLastAccessTime(int,int,int)\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getLastRejectTime(int, int, int)}\") long getRejectTime()\npublic @java.lang.Deprecated long getLastRejectTime(int)\npublic @java.lang.Deprecated long getLastRejectForegroundTime(int)\npublic @java.lang.Deprecated long getLastRejectBackgroundTime(int)\npublic @java.lang.Deprecated long getLastRejectTime(int,int,int)\npublic  long getAccessTime(int,int)\npublic  long getRejectTime(int,int)\npublic  boolean isRunning()\nprivate  android.app.NoteOpEvent getLastAccessEvent(int,int,int)\npublic @java.lang.Deprecated long getDuration()\npublic @java.lang.Deprecated long getLastForegroundDuration(int)\npublic @java.lang.Deprecated long getLastBackgroundDuration(int)\npublic @java.lang.Deprecated long getLastDuration(int,int,int)\npublic @java.lang.Deprecated int getProxyUid()\npublic @java.lang.Deprecated @android.annotation.Nullable java.lang.String getProxyPackageName()\nprivate @android.app.UidState int getLastAccessUidStateForFlagsInStatesOfAllFeatures(int,int,int)\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\nprivate @android.app.UidState int getLastRejectUidStateForFlagsInStatesOfAllFeatures(int,int,int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic  long getDuration(int,int)\npublic  int getProxyUid(int,int)\nprivate  int getProxyUid(int,int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\nprivate @android.annotation.Nullable java.lang.String getProxyPackageName(int,int,int)\nclass OpEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
+                inputSignatures = "private final @android.annotation.IntRange(from=0L, to=_NUM_OP - 1) int mOp\nprivate final @android.app.Mode int mMode\nprivate final @android.annotation.NonNull java.util.Map<java.lang.String,android.app.OpAttributionEntry> mAttributions\npublic @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getOpStr()}\") int getOp()\npublic @android.annotation.NonNull java.lang.String getOpStr()\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getAccessTime(int, int)}\") long getTime()\npublic @java.lang.Deprecated long getLastAccessTime(int)\npublic @java.lang.Deprecated long getLastAccessForegroundTime(int)\npublic @java.lang.Deprecated long getLastAccessBackgroundTime(int)\npublic @java.lang.Deprecated long getLastAccessTime(int,int,int)\npublic @java.lang.Deprecated @android.annotation.UnsupportedAppUsage(maxTargetSdk=Build.VERSION_CODES.Q, publicAlternatives=\"{@code \" + \"#getLastRejectTime(int, int, int)}\") long getRejectTime()\npublic @java.lang.Deprecated long getLastRejectTime(int)\npublic @java.lang.Deprecated long getLastRejectForegroundTime(int)\npublic @java.lang.Deprecated long getLastRejectBackgroundTime(int)\npublic @java.lang.Deprecated long getLastRejectTime(int,int,int)\npublic  long getAccessTime(int,int)\npublic  long getRejectTime(int,int)\npublic  boolean isRunning()\nprivate  android.app.NoteOpEvent getLastAccessEvent(int,int,int)\npublic @java.lang.Deprecated long getDuration()\npublic @java.lang.Deprecated long getLastForegroundDuration(int)\npublic @java.lang.Deprecated long getLastBackgroundDuration(int)\npublic @java.lang.Deprecated long getLastDuration(int,int,int)\npublic @java.lang.Deprecated int getProxyUid()\npublic @java.lang.Deprecated @android.annotation.Nullable java.lang.String getProxyPackageName()\nprivate @android.app.UidState int getLastAccessUidStateForFlagsInStatesOfAllAttributions(int,int,int)\npublic @android.app.UidState int getLastAccessUidState(int)\npublic @android.app.UidState int getLastForegroundAccessUidState(int)\npublic @android.app.UidState int getLastBackgroundAccessUidState(int)\nprivate @android.app.UidState int getLastRejectUidStateForFlagsInStatesOfAllAttributions(int,int,int)\npublic @android.app.UidState int getLastRejectUidState(int)\npublic @android.app.UidState int getLastForegroundRejectUidState(int)\npublic @android.app.UidState int getLastBackgroundRejectUidState(int)\npublic  long getDuration(int,int)\npublic  int getProxyUid(int,int)\nprivate  int getProxyUid(int,int,int)\npublic @android.annotation.Nullable java.lang.String getProxyPackageName(int,int)\nprivate @android.annotation.Nullable java.lang.String getProxyPackageName(int,int,int)\nclass OpEntry extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true)")
         @Deprecated
         private void __metadata() {}
          */
@@ -4214,7 +4216,7 @@
         void visitHistoricalOps(@NonNull HistoricalOps ops);
         void visitHistoricalUidOps(@NonNull HistoricalUidOps ops);
         void visitHistoricalPackageOps(@NonNull HistoricalPackageOps ops);
-        void visitHistoricalFeatureOps(@NonNull HistoricalFeatureOps ops);
+        void visitHistoricalAttributionOps(@NonNull AttributedHistoricalOps ops);
         void visitHistoricalOp(@NonNull HistoricalOp ops);
     }
 
@@ -4227,7 +4229,7 @@
     @IntDef(flag = true, prefix = { "FILTER_BY_" }, value = {
             FILTER_BY_UID,
             FILTER_BY_PACKAGE_NAME,
-            FILTER_BY_FEATURE_ID,
+            FILTER_BY_ATTRIBUTION_TAG,
             FILTER_BY_OP_NAMES
     })
     public @interface HistoricalOpsRequestFilter {}
@@ -4247,11 +4249,11 @@
     public static final int FILTER_BY_PACKAGE_NAME = 1<<1;
 
     /**
-     * Filter historical appop request by feature id.
+     * Filter historical appop request by attribution tag.
      *
      * @hide
      */
-    public static final int FILTER_BY_FEATURE_ID = 1<<2;
+    public static final int FILTER_BY_ATTRIBUTION_TAG = 1<<2;
 
     /**
      * Filter historical appop request by op names.
@@ -4272,7 +4274,7 @@
     public static final class HistoricalOpsRequest {
         private final int mUid;
         private final @Nullable String mPackageName;
-        private final @Nullable String mFeatureId;
+        private final @Nullable String mAttributionTag;
         private final @Nullable List<String> mOpNames;
         private final @HistoricalOpsRequestFilter int mFilter;
         private final long mBeginTimeMillis;
@@ -4280,12 +4282,12 @@
         private final @OpFlags int mFlags;
 
         private HistoricalOpsRequest(int uid, @Nullable String packageName,
-                @Nullable String featureId, @Nullable List<String> opNames,
+                @Nullable String attributionTag, @Nullable List<String> opNames,
                 @HistoricalOpsRequestFilter int filter, long beginTimeMillis,
                 long endTimeMillis, @OpFlags int flags) {
             mUid = uid;
             mPackageName = packageName;
-            mFeatureId = featureId;
+            mAttributionTag = attributionTag;
             mOpNames = opNames;
             mFilter = filter;
             mBeginTimeMillis = beginTimeMillis;
@@ -4303,7 +4305,7 @@
         public static final class Builder {
             private int mUid = Process.INVALID_UID;
             private @Nullable String mPackageName;
-            private @Nullable String mFeatureId;
+            private @Nullable String mAttributionTag;
             private @Nullable List<String> mOpNames;
             private @HistoricalOpsRequestFilter int mFilter;
             private final long mBeginTimeMillis;
@@ -4367,14 +4369,14 @@
             }
 
             /**
-             * Sets the feature id to query for.
+             * Sets the attribution tag to query for.
              *
-             * @param featureId The id of the feature.
+             * @param attributionTag attribution tag
              * @return This builder.
              */
-            public @NonNull Builder setFeatureId(@Nullable String featureId) {
-                mFeatureId = featureId;
-                mFilter |= FILTER_BY_FEATURE_ID;
+            public @NonNull Builder setAttributionTag(@Nullable String attributionTag) {
+                mAttributionTag = attributionTag;
+                mFilter |= FILTER_BY_ATTRIBUTION_TAG;
 
                 return this;
             }
@@ -4425,7 +4427,7 @@
              * @return a new {@link HistoricalOpsRequest}.
              */
             public @NonNull HistoricalOpsRequest build() {
-                return new HistoricalOpsRequest(mUid, mPackageName, mFeatureId, mOpNames,
+                return new HistoricalOpsRequest(mUid, mPackageName, mAttributionTag, mOpNames,
                         mFilter, mBeginTimeMillis, mEndTimeMillis, mFlags);
             }
         }
@@ -4585,7 +4587,7 @@
          *
          * @param uid Uid to filter for.
          * @param packageName Package to filter for.
-         * @param featureId Package to filter for.
+         * @param attributionTag attribution tag to filter for
          * @param opNames Ops to filter for.
          * @param filter Which parameters to filter on.
          * @param beginTimeMillis The begin time to filter for or {@link Long#MIN_VALUE} for all.
@@ -4593,7 +4595,7 @@
          *
          * @hide
          */
-        public void filter(int uid, @Nullable String packageName, @Nullable String featureId,
+        public void filter(int uid, @Nullable String packageName, @Nullable String attributionTag,
                 @Nullable String[] opNames, @HistoricalOpsRequestFilter int filter,
                 long beginTimeMillis, long endTimeMillis) {
             final long durationMillis = getDurationMillis();
@@ -4607,7 +4609,7 @@
                 if ((filter & FILTER_BY_UID) != 0 && uid != uidOp.getUid()) {
                     mHistoricalUidOps.removeAt(i);
                 } else {
-                    uidOp.filter(packageName, featureId, opNames, filter, scaleFactor);
+                    uidOp.filter(packageName, attributionTag, opNames, filter, scaleFactor);
                     if (uidOp.getPackageCount() == 0) {
                         mHistoricalUidOps.removeAt(i);
                     }
@@ -4638,28 +4640,28 @@
         /** @hide */
         @TestApi
         public void increaseAccessCount(int opCode, int uid, @NonNull String packageName,
-                @Nullable String featureId, @UidState int uidState,  @OpFlags int flags,
+                @Nullable String attributionTag, @UidState int uidState,  @OpFlags int flags,
                 long increment) {
             getOrCreateHistoricalUidOps(uid).increaseAccessCount(opCode,
-                    packageName, featureId, uidState, flags, increment);
+                    packageName, attributionTag, uidState, flags, increment);
         }
 
         /** @hide */
         @TestApi
         public void increaseRejectCount(int opCode, int uid, @NonNull String packageName,
-                @Nullable String featureId, @UidState int uidState, @OpFlags int flags,
+                @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
                 long increment) {
             getOrCreateHistoricalUidOps(uid).increaseRejectCount(opCode,
-                    packageName, featureId, uidState, flags, increment);
+                    packageName, attributionTag, uidState, flags, increment);
         }
 
         /** @hide */
         @TestApi
         public void increaseAccessDuration(int opCode, int uid, @NonNull String packageName,
-                @Nullable String featureId, @UidState int uidState, @OpFlags int flags,
+                @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
                 long increment) {
             getOrCreateHistoricalUidOps(uid).increaseAccessDuration(opCode,
-                    packageName, featureId, uidState, flags, increment);
+                    packageName, attributionTag, uidState, flags, increment);
         }
 
         /** @hide */
@@ -4939,7 +4941,7 @@
             }
         }
 
-        private void filter(@Nullable String packageName, @Nullable String featureId,
+        private void filter(@Nullable String packageName, @Nullable String attributionTag,
                 @Nullable String[] opNames, @HistoricalOpsRequestFilter int filter,
                 double fractionToRemove) {
             final int packageCount = getPackageCount();
@@ -4949,8 +4951,8 @@
                         packageOps.getPackageName())) {
                     mHistoricalPackageOps.removeAt(i);
                 } else {
-                    packageOps.filter(featureId, opNames, filter, fractionToRemove);
-                    if (packageOps.getFeatureCount() == 0) {
+                    packageOps.filter(attributionTag, opNames, filter, fractionToRemove);
+                    if (packageOps.getAttributedOpsCount() == 0) {
                         mHistoricalPackageOps.removeAt(i);
                     }
                 }
@@ -4969,24 +4971,24 @@
         }
 
         private void increaseAccessCount(int opCode, @NonNull String packageName,
-                @Nullable String featureId, @UidState int uidState, @OpFlags int flags,
+                @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
                 long increment) {
             getOrCreateHistoricalPackageOps(packageName).increaseAccessCount(
-                    opCode, featureId, uidState, flags, increment);
+                    opCode, attributionTag, uidState, flags, increment);
         }
 
         private void increaseRejectCount(int opCode, @NonNull String packageName,
-                @Nullable String featureId, @UidState int uidState,  @OpFlags int flags,
+                @Nullable String attributionTag, @UidState int uidState,  @OpFlags int flags,
                 long increment) {
             getOrCreateHistoricalPackageOps(packageName).increaseRejectCount(
-                    opCode, featureId, uidState, flags, increment);
+                    opCode, attributionTag, uidState, flags, increment);
         }
 
         private void increaseAccessDuration(int opCode, @NonNull String packageName,
-                @Nullable String featureId, @UidState int uidState, @OpFlags int flags,
+                @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
                 long increment) {
             getOrCreateHistoricalPackageOps(packageName).increaseAccessDuration(
-                    opCode, featureId, uidState, flags, increment);
+                    opCode, attributionTag, uidState, flags, increment);
         }
 
         /**
@@ -5131,7 +5133,7 @@
     @SystemApi
     public static final class HistoricalPackageOps implements Parcelable {
         private final @NonNull String mPackageName;
-        private @Nullable ArrayMap<String, HistoricalFeatureOps> mHistoricalFeatureOps;
+        private @Nullable ArrayMap<String, AttributedHistoricalOps> mAttributedHistoricalOps;
 
         /** @hide */
         public HistoricalPackageOps(@NonNull String packageName) {
@@ -5140,70 +5142,71 @@
 
         private HistoricalPackageOps(@NonNull HistoricalPackageOps other) {
             mPackageName = other.mPackageName;
-            final int opCount = other.getFeatureCount();
+            final int opCount = other.getAttributedOpsCount();
             for (int i = 0; i < opCount; i++) {
-                final HistoricalFeatureOps origOps = other.getFeatureOpsAt(i);
-                final HistoricalFeatureOps cloneOps = new HistoricalFeatureOps(origOps);
-                if (mHistoricalFeatureOps == null) {
-                    mHistoricalFeatureOps = new ArrayMap<>(opCount);
+                final AttributedHistoricalOps origOps = other.getAttributedOpsAt(i);
+                final AttributedHistoricalOps cloneOps = new AttributedHistoricalOps(origOps);
+                if (mAttributedHistoricalOps == null) {
+                    mAttributedHistoricalOps = new ArrayMap<>(opCount);
                 }
-                mHistoricalFeatureOps.put(cloneOps.getFeatureId(), cloneOps);
+                mAttributedHistoricalOps.put(cloneOps.getTag(), cloneOps);
             }
         }
 
         private HistoricalPackageOps(@NonNull Parcel parcel) {
             mPackageName = parcel.readString();
-            mHistoricalFeatureOps = parcel.createTypedArrayMap(HistoricalFeatureOps.CREATOR);
+            mAttributedHistoricalOps = parcel.createTypedArrayMap(AttributedHistoricalOps.CREATOR);
         }
 
         private @Nullable HistoricalPackageOps splice(double fractionToRemove) {
             HistoricalPackageOps splice = null;
-            final int featureCount = getFeatureCount();
-            for (int i = 0; i < featureCount; i++) {
-                final HistoricalFeatureOps origOps = getFeatureOpsAt(i);
-                final HistoricalFeatureOps spliceOps = origOps.splice(fractionToRemove);
+            final int attributionCount = getAttributedOpsCount();
+            for (int i = 0; i < attributionCount; i++) {
+                final AttributedHistoricalOps origOps = getAttributedOpsAt(i);
+                final AttributedHistoricalOps spliceOps = origOps.splice(fractionToRemove);
                 if (spliceOps != null) {
                     if (splice == null) {
                         splice = new HistoricalPackageOps(mPackageName);
                     }
-                    if (splice.mHistoricalFeatureOps == null) {
-                        splice.mHistoricalFeatureOps = new ArrayMap<>();
+                    if (splice.mAttributedHistoricalOps == null) {
+                        splice.mAttributedHistoricalOps = new ArrayMap<>();
                     }
-                    splice.mHistoricalFeatureOps.put(spliceOps.getFeatureId(), spliceOps);
+                    splice.mAttributedHistoricalOps.put(spliceOps.getTag(), spliceOps);
                 }
             }
             return splice;
         }
 
         private void merge(@NonNull HistoricalPackageOps other) {
-            final int featureCount = other.getFeatureCount();
-            for (int i = 0; i < featureCount; i++) {
-                final HistoricalFeatureOps otherFeatureOps = other.getFeatureOpsAt(i);
-                final HistoricalFeatureOps thisFeatureOps = getFeatureOps(
-                        otherFeatureOps.getFeatureId());
-                if (thisFeatureOps != null) {
-                    thisFeatureOps.merge(otherFeatureOps);
+            final int attributionCount = other.getAttributedOpsCount();
+            for (int i = 0; i < attributionCount; i++) {
+                final AttributedHistoricalOps otherAttributionOps = other.getAttributedOpsAt(i);
+                final AttributedHistoricalOps thisAttributionOps = getAttributedOps(
+                        otherAttributionOps.getTag());
+                if (thisAttributionOps != null) {
+                    thisAttributionOps.merge(otherAttributionOps);
                 } else {
-                    if (mHistoricalFeatureOps == null) {
-                        mHistoricalFeatureOps = new ArrayMap<>();
+                    if (mAttributedHistoricalOps == null) {
+                        mAttributedHistoricalOps = new ArrayMap<>();
                     }
-                    mHistoricalFeatureOps.put(otherFeatureOps.getFeatureId(), otherFeatureOps);
+                    mAttributedHistoricalOps.put(otherAttributionOps.getTag(),
+                            otherAttributionOps);
                 }
             }
         }
 
-        private void filter(@Nullable String featureId, @Nullable String[] opNames,
+        private void filter(@Nullable String attributionTag, @Nullable String[] opNames,
                 @HistoricalOpsRequestFilter int filter, double fractionToRemove) {
-            final int featureCount = getFeatureCount();
-            for (int i = featureCount - 1; i >= 0; i--) {
-                final HistoricalFeatureOps featureOps = getFeatureOpsAt(i);
-                if ((filter & FILTER_BY_FEATURE_ID) != 0 && !Objects.equals(featureId,
-                        featureOps.getFeatureId())) {
-                    mHistoricalFeatureOps.removeAt(i);
+            final int attributionCount = getAttributedOpsCount();
+            for (int i = attributionCount - 1; i >= 0; i--) {
+                final AttributedHistoricalOps attributionOps = getAttributedOpsAt(i);
+                if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(attributionTag,
+                        attributionOps.getTag())) {
+                    mAttributedHistoricalOps.removeAt(i);
                 } else {
-                    featureOps.filter(opNames, filter, fractionToRemove);
-                    if (featureOps.getOpCount() == 0) {
-                        mHistoricalFeatureOps.removeAt(i);
+                    attributionOps.filter(opNames, filter, fractionToRemove);
+                    if (attributionOps.getOpCount() == 0) {
+                        mAttributedHistoricalOps.removeAt(i);
                     }
                 }
             }
@@ -5211,38 +5214,38 @@
 
         private void accept(@NonNull HistoricalOpsVisitor visitor) {
             visitor.visitHistoricalPackageOps(this);
-            final int featureCount = getFeatureCount();
-            for (int i = 0; i < featureCount; i++) {
-                getFeatureOpsAt(i).accept(visitor);
+            final int attributionCount = getAttributedOpsCount();
+            for (int i = 0; i < attributionCount; i++) {
+                getAttributedOpsAt(i).accept(visitor);
             }
         }
 
         private boolean isEmpty() {
-            final int featureCount = getFeatureCount();
-            for (int i = featureCount - 1; i >= 0; i--) {
-                final HistoricalFeatureOps featureOps = mHistoricalFeatureOps.valueAt(i);
-                if (!featureOps.isEmpty()) {
+            final int attributionCount = getAttributedOpsCount();
+            for (int i = attributionCount - 1; i >= 0; i--) {
+                final AttributedHistoricalOps attributionOps = mAttributedHistoricalOps.valueAt(i);
+                if (!attributionOps.isEmpty()) {
                     return false;
                 }
             }
             return true;
         }
 
-        private void increaseAccessCount(int opCode, @Nullable String featureId,
+        private void increaseAccessCount(int opCode, @Nullable String attributionTag,
                 @UidState int uidState, @OpFlags int flags, long increment) {
-            getOrCreateHistoricalFeatureOps(featureId).increaseAccessCount(
+            getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessCount(
                     opCode, uidState, flags, increment);
         }
 
-        private void increaseRejectCount(int opCode, @Nullable String featureId,
+        private void increaseRejectCount(int opCode, @Nullable String attributionTag,
                 @UidState int uidState, @OpFlags int flags, long increment) {
-            getOrCreateHistoricalFeatureOps(featureId).increaseRejectCount(
+            getOrCreateAttributedHistoricalOps(attributionTag).increaseRejectCount(
                     opCode, uidState, flags, increment);
         }
 
-        private void increaseAccessDuration(int opCode, @Nullable String featureId,
+        private void increaseAccessDuration(int opCode, @Nullable String attributionTag,
                 @UidState int uidState, @OpFlags int flags, long increment) {
-            getOrCreateHistoricalFeatureOps(featureId).increaseAccessDuration(
+            getOrCreateAttributedHistoricalOps(attributionTag).increaseAccessDuration(
                     opCode, uidState, flags, increment);
         }
 
@@ -5255,17 +5258,18 @@
             return mPackageName;
         }
 
-        private @NonNull HistoricalFeatureOps getOrCreateHistoricalFeatureOps(
-                @Nullable String featureId) {
-            if (mHistoricalFeatureOps == null) {
-                mHistoricalFeatureOps = new ArrayMap<>();
+        private @NonNull AttributedHistoricalOps getOrCreateAttributedHistoricalOps(
+                @Nullable String attributionTag) {
+            if (mAttributedHistoricalOps == null) {
+                mAttributedHistoricalOps = new ArrayMap<>();
             }
-            HistoricalFeatureOps historicalFeatureOp = mHistoricalFeatureOps.get(featureId);
-            if (historicalFeatureOp == null) {
-                historicalFeatureOp = new HistoricalFeatureOps(featureId);
-                mHistoricalFeatureOps.put(featureId, historicalFeatureOp);
+            AttributedHistoricalOps historicalAttributionOp = mAttributedHistoricalOps.get(
+                    attributionTag);
+            if (historicalAttributionOp == null) {
+                historicalAttributionOp = new AttributedHistoricalOps(attributionTag);
+                mAttributedHistoricalOps.put(attributionTag, historicalAttributionOp);
             }
-            return historicalFeatureOp;
+            return historicalAttributionOp;
         }
 
         /**
@@ -5276,13 +5280,13 @@
          */
         public @IntRange(from = 0) int getOpCount() {
             int numOps = 0;
-            int numFeatures = getFeatureCount();
+            int numAttributions = getAttributedOpsCount();
 
             for (int code = 0; code < _NUM_OP; code++) {
                 String opName = opToPublicName(code);
 
-                for (int featureNum = 0; featureNum < numFeatures; featureNum++) {
-                    if (getFeatureOpsAt(featureNum).getOp(opName) != null) {
+                for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) {
+                    if (getAttributedOpsAt(attributionNum).getOp(opName) != null) {
                         numOps++;
                         break;
                     }
@@ -5295,7 +5299,7 @@
         /**
          * Gets the historical op at a given index.
          *
-         * <p>This combines the counts from all features.
+         * <p>This combines the counts from all attributions.
          *
          * @param index The index to lookup.
          * @return The op at the given index.
@@ -5303,13 +5307,13 @@
          */
         public @NonNull HistoricalOp getOpAt(@IntRange(from = 0) int index) {
             int numOpsFound = 0;
-            int numFeatures = getFeatureCount();
+            int numAttributions = getAttributedOpsCount();
 
             for (int code = 0; code < _NUM_OP; code++) {
                 String opName = opToPublicName(code);
 
-                for (int featureNum = 0; featureNum < numFeatures; featureNum++) {
-                    if (getFeatureOpsAt(featureNum).getOp(opName) != null) {
+                for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) {
+                    if (getAttributedOpsAt(attributionNum).getOp(opName) != null) {
                         if (numOpsFound == index) {
                             return getOp(opName);
                         } else {
@@ -5326,25 +5330,25 @@
         /**
          * Gets the historical entry for a given op name.
          *
-         * <p>This combines the counts from all features.
+         * <p>This combines the counts from all attributions.
          *
          * @param opName The op name.
          * @return The historical entry for that op name.
          */
         public @Nullable HistoricalOp getOp(@NonNull String opName) {
-            if (mHistoricalFeatureOps == null) {
+            if (mAttributedHistoricalOps == null) {
                 return null;
             }
 
             HistoricalOp combinedOp = null;
-            int numFeatures = getFeatureCount();
-            for (int i = 0; i < numFeatures; i++) {
-                HistoricalOp featureOp = getFeatureOpsAt(i).getOp(opName);
-                if (featureOp != null) {
+            int numAttributions = getAttributedOpsCount();
+            for (int i = 0; i < numAttributions; i++) {
+                HistoricalOp attributionOp = getAttributedOpsAt(i).getOp(opName);
+                if (attributionOp != null) {
                     if (combinedOp == null) {
-                        combinedOp = new HistoricalOp(featureOp);
+                        combinedOp = new HistoricalOp(attributionOp);
                     } else {
-                        combinedOp.merge(featureOp);
+                        combinedOp.merge(attributionOp);
                     }
                 }
             }
@@ -5360,7 +5364,7 @@
         @Override
         public void writeToParcel(@NonNull Parcel parcel, int flags) {
             parcel.writeString(mPackageName);
-            parcel.writeTypedArrayMap(mHistoricalFeatureOps, flags);
+            parcel.writeTypedArrayMap(mAttributedHistoricalOps, flags);
         }
 
         public static final @android.annotation.NonNull Creator<HistoricalPackageOps> CREATOR =
@@ -5388,11 +5392,11 @@
             if (!mPackageName.equals(other.mPackageName)) {
                 return false;
             }
-            if (mHistoricalFeatureOps == null) {
-                if (other.mHistoricalFeatureOps != null) {
+            if (mAttributedHistoricalOps == null) {
+                if (other.mAttributedHistoricalOps != null) {
                     return false;
                 }
-            } else if (!mHistoricalFeatureOps.equals(other.mHistoricalFeatureOps)) {
+            } else if (!mAttributedHistoricalOps.equals(other.mAttributedHistoricalOps)) {
                 return false;
             }
             return true;
@@ -5401,58 +5405,58 @@
         @Override
         public int hashCode() {
             int result = mPackageName != null ? mPackageName.hashCode() : 0;
-            result = 31 * result + (mHistoricalFeatureOps != null ? mHistoricalFeatureOps.hashCode()
-                    : 0);
+            result = 31 * result + (mAttributedHistoricalOps != null
+                    ? mAttributedHistoricalOps.hashCode() : 0);
             return result;
         }
 
         /**
-         * Gets number of feature with historical ops.
+         * Gets number of attributed historical ops.
          *
-         * @return The number of feature with historical ops.
+         * @return The number of attribution with historical ops.
          *
-         * @see #getFeatureOpsAt(int)
+         * @see #getAttributedOpsAt(int)
          */
-        public @IntRange(from = 0) int getFeatureCount() {
-            if (mHistoricalFeatureOps == null) {
+        public @IntRange(from = 0) int getAttributedOpsCount() {
+            if (mAttributedHistoricalOps == null) {
                 return 0;
             }
-            return mHistoricalFeatureOps.size();
+            return mAttributedHistoricalOps.size();
         }
 
         /**
-         * Gets the historical feature ops at a given index.
+         * Gets the attributed historical ops at a given index.
          *
          * @param index The index.
          *
-         * @return The historical feature ops at the given index.
+         * @return The historical attribution ops at the given index.
          *
-         * @see #getFeatureCount()
+         * @see #getAttributedOpsCount()
          */
-        public @NonNull HistoricalFeatureOps getFeatureOpsAt(@IntRange(from = 0) int index) {
-            if (mHistoricalFeatureOps == null) {
+        public @NonNull AttributedHistoricalOps getAttributedOpsAt(@IntRange(from = 0) int index) {
+            if (mAttributedHistoricalOps == null) {
                 throw new IndexOutOfBoundsException();
             }
-            return mHistoricalFeatureOps.valueAt(index);
+            return mAttributedHistoricalOps.valueAt(index);
         }
 
         /**
-         * Gets the historical feature ops for a given feature.
+         * Gets the attributed historical ops for a given attribution tag.
          *
-         * @param featureId The feature id.
+         * @param attributionTag The attribution tag.
          *
-         * @return The historical ops for the feature.
+         * @return The historical ops for the attribution.
          */
-        public @Nullable HistoricalFeatureOps getFeatureOps(@NonNull String featureId) {
-            if (mHistoricalFeatureOps == null) {
+        public @Nullable AttributedHistoricalOps getAttributedOps(@NonNull String attributionTag) {
+            if (mAttributedHistoricalOps == null) {
                 return null;
             }
-            return mHistoricalFeatureOps.get(featureId);
+            return mAttributedHistoricalOps.get(attributionTag);
         }
     }
 
     /**
-     * This class represents historical app op information about a feature in a package.
+     * This class represents historical app op information about a attribution in a package.
      *
      * @hide
      */
@@ -5462,20 +5466,20 @@
     @DataClass(genHiddenConstructor = true,
             genEqualsHashCode = true, genHiddenCopyConstructor = true) */
     @DataClass.Suppress("getHistoricalOps")
-    public static final class HistoricalFeatureOps implements Parcelable {
-        /** Id of the {@link Context#createFeatureContext feature} in the package */
-        private final @Nullable String mFeatureId;
+    public static final class AttributedHistoricalOps implements Parcelable {
+        /** {@link Context#createAttributionContext attribution} tag */
+        private final @Nullable String mTag;
 
-        /** Ops for this feature */
+        /** Ops for this attribution */
         private @Nullable ArrayMap<String, HistoricalOp> mHistoricalOps;
 
         /** @hide */
-        public HistoricalFeatureOps(@NonNull String featureId) {
-            mFeatureId = featureId;
+        public AttributedHistoricalOps(@NonNull String tag) {
+            mTag = tag;
         }
 
-        private HistoricalFeatureOps(@NonNull HistoricalFeatureOps other) {
-            mFeatureId = other.mFeatureId;
+        private AttributedHistoricalOps(@NonNull AttributedHistoricalOps other) {
+            mTag = other.mTag;
             final int opCount = other.getOpCount();
             for (int i = 0; i < opCount; i++) {
                 final HistoricalOp origOp = other.getOpAt(i);
@@ -5487,15 +5491,15 @@
             }
         }
 
-        private @Nullable HistoricalFeatureOps splice(double fractionToRemove) {
-            HistoricalFeatureOps splice = null;
+        private @Nullable AttributedHistoricalOps splice(double fractionToRemove) {
+            AttributedHistoricalOps splice = null;
             final int opCount = getOpCount();
             for (int i = 0; i < opCount; i++) {
                 final HistoricalOp origOps = getOpAt(i);
                 final HistoricalOp spliceOps = origOps.splice(fractionToRemove);
                 if (spliceOps != null) {
                     if (splice == null) {
-                        splice = new HistoricalFeatureOps(mFeatureId, null);
+                        splice = new AttributedHistoricalOps(mTag, null);
                     }
                     if (splice.mHistoricalOps == null) {
                         splice.mHistoricalOps = new ArrayMap<>();
@@ -5506,7 +5510,7 @@
             return splice;
         }
 
-        private void merge(@NonNull HistoricalFeatureOps other) {
+        private void merge(@NonNull AttributedHistoricalOps other) {
             final int opCount = other.getOpCount();
             for (int i = 0; i < opCount; i++) {
                 final HistoricalOp otherOp = other.getOpAt(i);
@@ -5603,7 +5607,7 @@
         }
 
         private void accept(@NonNull HistoricalOpsVisitor visitor) {
-            visitor.visitHistoricalFeatureOps(this);
+            visitor.visitHistoricalAttributionOps(this);
             final int opCount = getOpCount();
             for (int i = 0; i < opCount; i++) {
                 getOpAt(i).accept(visitor);
@@ -5639,46 +5643,46 @@
 
 
         /**
-         * Creates a new HistoricalFeatureOps.
+         * Creates a new HistoricalAttributionOps.
          *
-         * @param featureId
-         *   Id of the {@link Context#createFeatureContext feature} in the package
+         * @param tag
+         *   {@link Context#createAttributionContext attribution} tag
          * @param historicalOps
-         *   Ops for this feature
+         *   Ops for this attribution
          * @hide
          */
         @DataClass.Generated.Member
-        public HistoricalFeatureOps(
-                @Nullable String featureId,
+        public AttributedHistoricalOps(
+                @Nullable String tag,
                 @Nullable ArrayMap<String,HistoricalOp> historicalOps) {
-            this.mFeatureId = featureId;
+            this.mTag = tag;
             this.mHistoricalOps = historicalOps;
 
             // onConstructed(); // You can define this method to get a callback
         }
 
         /**
-         * Id of the {@link Context#createFeatureContext feature} in the package
+         * {@link Context#createAttributionContext attribution} tag
          */
         @DataClass.Generated.Member
-        public @Nullable String getFeatureId() {
-            return mFeatureId;
+        public @Nullable String getTag() {
+            return mTag;
         }
 
         @Override
         @DataClass.Generated.Member
         public boolean equals(@Nullable Object o) {
             // You can override field equality logic by defining either of the methods like:
-            // boolean fieldNameEquals(HistoricalFeatureOps other) { ... }
+            // boolean fieldNameEquals(HistoricalAttributionOps other) { ... }
             // boolean fieldNameEquals(FieldType otherValue) { ... }
 
             if (this == o) return true;
             if (o == null || getClass() != o.getClass()) return false;
             @SuppressWarnings("unchecked")
-            HistoricalFeatureOps that = (HistoricalFeatureOps) o;
+            AttributedHistoricalOps that = (AttributedHistoricalOps) o;
             //noinspection PointlessBooleanExpression
             return true
-                    && Objects.equals(mFeatureId, that.mFeatureId)
+                    && Objects.equals(mTag, that.mTag)
                     && Objects.equals(mHistoricalOps, that.mHistoricalOps);
         }
 
@@ -5689,7 +5693,7 @@
             // int fieldNameHashCode() { ... }
 
             int _hash = 1;
-            _hash = 31 * _hash + Objects.hashCode(mFeatureId);
+            _hash = 31 * _hash + Objects.hashCode(mTag);
             _hash = 31 * _hash + Objects.hashCode(mHistoricalOps);
             return _hash;
         }
@@ -5701,10 +5705,10 @@
             // void parcelFieldName(Parcel dest, int flags) { ... }
 
             byte flg = 0;
-            if (mFeatureId != null) flg |= 0x1;
+            if (mTag != null) flg |= 0x1;
             if (mHistoricalOps != null) flg |= 0x2;
             dest.writeByte(flg);
-            if (mFeatureId != null) dest.writeString(mFeatureId);
+            if (mTag != null) dest.writeString(mTag);
             if (mHistoricalOps != null) dest.writeMap(mHistoricalOps);
         }
 
@@ -5715,35 +5719,35 @@
         /** @hide */
         @SuppressWarnings({"unchecked", "RedundantCast"})
         @DataClass.Generated.Member
-        /* package-private */ HistoricalFeatureOps(@NonNull Parcel in) {
+        /* package-private */ AttributedHistoricalOps(@NonNull Parcel in) {
             // You can override field unparcelling by defining methods like:
             // static FieldType unparcelFieldName(Parcel in) { ... }
 
             byte flg = in.readByte();
-            String featureId = (flg & 0x1) == 0 ? null : in.readString();
+            String attributionTag = (flg & 0x1) == 0 ? null : in.readString();
             ArrayMap<String,HistoricalOp> historicalOps = null;
             if ((flg & 0x2) != 0) {
                 historicalOps = new ArrayMap();
                 in.readMap(historicalOps, HistoricalOp.class.getClassLoader());
             }
 
-            this.mFeatureId = featureId;
+            this.mTag = attributionTag;
             this.mHistoricalOps = historicalOps;
 
             // onConstructed(); // You can define this method to get a callback
         }
 
         @DataClass.Generated.Member
-        public static final @NonNull Parcelable.Creator<HistoricalFeatureOps> CREATOR
-                = new Parcelable.Creator<HistoricalFeatureOps>() {
+        public static final @NonNull Parcelable.Creator<AttributedHistoricalOps> CREATOR
+                = new Parcelable.Creator<AttributedHistoricalOps>() {
             @Override
-            public HistoricalFeatureOps[] newArray(int size) {
-                return new HistoricalFeatureOps[size];
+            public AttributedHistoricalOps[] newArray(int size) {
+                return new AttributedHistoricalOps[size];
             }
 
             @Override
-            public HistoricalFeatureOps createFromParcel(@NonNull Parcel in) {
-                return new HistoricalFeatureOps(in);
+            public AttributedHistoricalOps createFromParcel(@NonNull Parcel in) {
+                return new AttributedHistoricalOps(in);
             }
         };
 
@@ -5752,7 +5756,7 @@
                 time = 1578113234821L,
                 codegenVersion = "1.0.14",
                 sourceFile = "frameworks/base/core/java/android/app/AppOpsManager.java",
-                inputSignatures = "private final @android.annotation.Nullable java.lang.String mFeatureId\nprivate @android.annotation.Nullable android.util.ArrayMap<java.lang.String,android.app.HistoricalOp> mHistoricalOps\nprivate @android.annotation.Nullable android.app.HistoricalFeatureOps splice(double)\nprivate  void merge(android.app.HistoricalFeatureOps)\nprivate  void filter(java.lang.String[],int,double)\nprivate  boolean isEmpty()\nprivate  void increaseAccessCount(int,int,int,long)\nprivate  void increaseRejectCount(int,int,int,long)\nprivate  void increaseAccessDuration(int,int,int,long)\npublic @android.annotation.IntRange(from=0L) int getOpCount()\npublic @android.annotation.NonNull android.app.HistoricalOp getOpAt(int)\npublic @android.annotation.Nullable android.app.HistoricalOp getOp(java.lang.String)\nprivate  void accept(android.app.HistoricalOpsVisitor)\nprivate @android.annotation.NonNull android.app.HistoricalOp getOrCreateHistoricalOp(int)\nclass HistoricalFeatureOps extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genEqualsHashCode=true, genHiddenCopyConstructor=true)")
+                inputSignatures = "private final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate @android.annotation.Nullable android.util.ArrayMap<java.lang.String,android.app.HistoricalOp> mHistoricalOps\nprivate @android.annotation.Nullable android.app.HistoricalAttributionOps splice(double)\nprivate  void merge(android.app.HistoricalAttributionOps)\nprivate  void filter(java.lang.String[],int,double)\nprivate  boolean isEmpty()\nprivate  void increaseAccessCount(int,int,int,long)\nprivate  void increaseRejectCount(int,int,int,long)\nprivate  void increaseAccessDuration(int,int,int,long)\npublic @android.annotation.IntRange(from=0L) int getOpCount()\npublic @android.annotation.NonNull android.app.HistoricalOp getOpAt(int)\npublic @android.annotation.Nullable android.app.HistoricalOp getOp(java.lang.String)\nprivate  void accept(android.app.HistoricalOpsVisitor)\nprivate @android.annotation.NonNull android.app.HistoricalOp getOrCreateHistoricalOp(int)\nclass HistoricalAttributionOps extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genHiddenConstructor=true, genEqualsHashCode=true, genHiddenCopyConstructor=true)")
         @Deprecated
         private void __metadata() {}
         */
@@ -6428,7 +6432,7 @@
         Objects.requireNonNull(executor, "executor cannot be null");
         Objects.requireNonNull(callback, "callback cannot be null");
         try {
-            mService.getHistoricalOps(request.mUid, request.mPackageName, request.mFeatureId,
+            mService.getHistoricalOps(request.mUid, request.mPackageName, request.mAttributionTag,
                     request.mOpNames, request.mFilter, request.mBeginTimeMillis,
                     request.mEndTimeMillis, request.mFlags, new RemoteCallback((result) -> {
                 final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS);
@@ -6468,8 +6472,9 @@
         Objects.requireNonNull(callback, "callback cannot be null");
         try {
             mService.getHistoricalOpsFromDiskRaw(request.mUid, request.mPackageName,
-                    request.mFeatureId, request.mOpNames, request.mFilter, request.mBeginTimeMillis,
-                    request.mEndTimeMillis, request.mFlags, new RemoteCallback((result) -> {
+                    request.mAttributionTag, request.mOpNames, request.mFilter,
+                    request.mBeginTimeMillis, request.mEndTimeMillis, request.mFlags,
+                    new RemoteCallback((result) -> {
                 final HistoricalOps ops = result.getParcelable(KEY_HISTORICAL_OPS);
                 final long identity = Binder.clearCallingIdentity();
                 try {
@@ -7059,8 +7064,8 @@
      * @param op The operation to note.  One of the OPSTR_* constants.
      * @param uid The user id of the application attempting to perform the operation.
      * @param packageName The name of the application attempting to perform the operation.
-     * @param featureId The {@link Context#createFeatureContext feature} in the package or {@code
-     * null} for default feature
+     * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code
+     * null} for default attribution
      * @param message A message describing the reason the op was noted
      *
      * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
@@ -7070,8 +7075,8 @@
      * @throws SecurityException If the app has been configured to crash on this op.
      */
     public int noteOp(@NonNull String op, int uid, @Nullable String packageName,
-            @Nullable String featureId, @Nullable String message) {
-        return noteOp(strOpToOp(op), uid, packageName, featureId, message);
+            @Nullable String attributionTag, @Nullable String message) {
+        return noteOp(strOpToOp(op), uid, packageName, attributionTag, message);
     }
 
     /**
@@ -7087,7 +7092,8 @@
      * @param op The operation to note.  One of the OP_* constants.
      * @param uid The user id of the application attempting to perform the operation.
      * @param packageName The name of the application attempting to perform the operation.
-     * @param featureId The feature in the app or {@code null} for default feature
+     * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code
+     * null} for default attribution
      * @param message A message describing the reason the op was noted
      *
      * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
@@ -7098,9 +7104,9 @@
      *
      * @hide
      */
-    public int noteOp(int op, int uid, @Nullable String packageName, @Nullable String featureId,
-            @Nullable String message) {
-        final int mode = noteOpNoThrow(op, uid, packageName, featureId, message);
+    public int noteOp(int op, int uid, @Nullable String packageName,
+            @Nullable String attributionTag, @Nullable String message) {
+        final int mode = noteOpNoThrow(op, uid, packageName, attributionTag, message);
         if (mode == MODE_ERRORED) {
             throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
         }
@@ -7135,8 +7141,8 @@
      * @param op The operation to note.  One of the OPSTR_* constants.
      * @param uid The user id of the application attempting to perform the operation.
      * @param packageName The name of the application attempting to perform the operation.
-     * @param featureId The {@link Context#createFeatureContext feature} in the package or {@code
-     * null} for default feature
+     * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code
+     * null} for default attribution
      * @param message A message describing the reason the op was noted
      *
      * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
@@ -7144,8 +7150,8 @@
      * causing the app to crash).
      */
     public int noteOpNoThrow(@NonNull String op, int uid, @NonNull String packageName,
-            @Nullable String featureId, @Nullable String message) {
-        return noteOpNoThrow(strOpToOp(op), uid, packageName, featureId, message);
+            @Nullable String attributionTag, @Nullable String message) {
+        return noteOpNoThrow(strOpToOp(op), uid, packageName, attributionTag, message);
     }
 
     /**
@@ -7155,7 +7161,8 @@
      * @param op The operation to note.  One of the OP_* constants.
      * @param uid The user id of the application attempting to perform the operation.
      * @param packageName The name of the application attempting to perform the operation.
-     * @param featureId The feature in the app or {@code null} for default feature
+     * @param attributionTag The {@link Context#createAttributionContext attribution tag} or {@code
+     * null} for default attribution
      * @param message A message describing the reason the op was noted
      *
      * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
@@ -7165,7 +7172,7 @@
      * @hide
      */
     public int noteOpNoThrow(int op, int uid, @Nullable String packageName,
-            @Nullable String featureId, @Nullable String message) {
+            @Nullable String attributionTag, @Nullable String message) {
         try {
             collectNoteOpCallsForValidation(op);
             int collectionMode = getNotedOpCollectionMode(uid, packageName, op);
@@ -7176,14 +7183,14 @@
                 }
             }
 
-            int mode = mService.noteOperation(op, uid, packageName, featureId,
+            int mode = mService.noteOperation(op, uid, packageName, attributionTag,
                     collectionMode == COLLECT_ASYNC, message);
 
             if (mode == MODE_ALLOWED) {
                 if (collectionMode == COLLECT_SELF) {
-                    collectNotedOpForSelf(op, featureId);
+                    collectNotedOpForSelf(op, attributionTag);
                 } else if (collectionMode == COLLECT_SYNC) {
-                    collectNotedOpSync(op, featureId);
+                    collectNotedOpSync(op, attributionTag);
                 }
             }
 
@@ -7223,8 +7230,8 @@
      * @param op The operation to note. One of the OP_* constants.
      * @param proxiedPackageName The name of the application calling into the proxy application.
      * @param proxiedUid The uid of the proxied application
-     * @param proxiedFeatureId The feature in the proxied app or {@code null} for default
-     *                           feature
+     * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext
+     * attribution tag} or {@code null} for default attribution
      * @param message A message describing the reason the op was noted
      *
      * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED}
@@ -7236,8 +7243,8 @@
      * @hide
      */
     public int noteProxyOp(int op, @Nullable String proxiedPackageName, int proxiedUid,
-            @Nullable String proxiedFeatureId, @Nullable String message) {
-        int mode = noteProxyOpNoThrow(op, proxiedPackageName, proxiedUid, proxiedFeatureId,
+            @Nullable String proxiedAttributionTag, @Nullable String message) {
+        int mode = noteProxyOpNoThrow(op, proxiedPackageName, proxiedUid, proxiedAttributionTag,
                 message);
         if (mode == MODE_ERRORED) {
             throw new SecurityException("Proxy package " + mContext.getOpPackageName()
@@ -7256,8 +7263,8 @@
      * @param op The operation to note. One of the OPSTR_* constants.
      * @param proxiedPackageName The name of the application calling into the proxy application.
      * @param proxiedUid The uid of the proxied application
-     * @param proxiedFeatureId The feature in the proxied app or {@code null} for default
-     *                           feature
+     * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext
+     * attribution tag} or {@code null} for default attribution
      * @param message A message describing the reason the op was noted
      *
      * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or {@link #MODE_IGNORED}
@@ -7267,8 +7274,8 @@
      * op.
      */
     public int noteProxyOp(@NonNull String op, @Nullable String proxiedPackageName, int proxiedUid,
-            @Nullable String proxiedFeatureId, @Nullable String message) {
-        return noteProxyOp(strOpToOp(op), proxiedPackageName, proxiedUid, proxiedFeatureId,
+            @Nullable String proxiedAttributionTag, @Nullable String message) {
+        return noteProxyOp(strOpToOp(op), proxiedPackageName, proxiedUid, proxiedAttributionTag,
                 message);
     }
 
@@ -7299,14 +7306,14 @@
      * @param op The op to note
      * @param proxiedPackageName The package to note the op for
      * @param proxiedUid The uid the package belongs to
-     * @param proxiedFeatureId The feature in the proxied app or {@code null} for default
-     *                           feature
+     * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext
+     * attribution tag} or {@code null} for default attribution
      * @param message A message describing the reason the op was noted
      */
     public int noteProxyOpNoThrow(@NonNull String op, @Nullable String proxiedPackageName,
-            int proxiedUid, @Nullable String proxiedFeatureId, @Nullable String message) {
+            int proxiedUid, @Nullable String proxiedAttributionTag, @Nullable String message) {
         return noteProxyOpNoThrow(strOpToOp(op), proxiedPackageName, proxiedUid,
-                proxiedFeatureId, message);
+                proxiedAttributionTag, message);
     }
 
     /**
@@ -7317,14 +7324,14 @@
      * @param proxiedPackageName The package to note the op for or {@code null} if the op should be
      *                           noted for the "android" package
      * @param proxiedUid The uid the package belongs to
-     * @param proxiedFeatureId The feature in the proxied app or {@code null} for default
-     *                           feature
+     * @param proxiedAttributionTag The proxied {@link Context#createAttributionContext
+     * attribution tag} or {@code null} for default attribution
      * @param message A message describing the reason the op was noted
      *
      * @hide
      */
     public int noteProxyOpNoThrow(int op, @Nullable String proxiedPackageName, int proxiedUid,
-            @Nullable String proxiedFeatureId, @Nullable String message) {
+            @Nullable String proxiedAttributionTag, @Nullable String message) {
         int myUid = Process.myUid();
 
         try {
@@ -7338,17 +7345,17 @@
             }
 
             int mode = mService.noteProxyOperation(op, proxiedUid, proxiedPackageName,
-                    proxiedFeatureId, myUid, mContext.getOpPackageName(),
-                    mContext.getFeatureId(), collectionMode == COLLECT_ASYNC, message);
+                    proxiedAttributionTag, myUid, mContext.getOpPackageName(),
+                    mContext.getAttributionTag(), collectionMode == COLLECT_ASYNC, message);
 
             if (mode == MODE_ALLOWED) {
                 if (collectionMode == COLLECT_SELF) {
-                    collectNotedOpForSelf(op, proxiedFeatureId);
+                    collectNotedOpForSelf(op, proxiedAttributionTag);
                 } else if (collectionMode == COLLECT_SYNC
                         // Only collect app-ops when the proxy is trusted
                         && mContext.checkPermission(Manifest.permission.UPDATE_APP_OPS_STATS, -1,
                         myUid) == PackageManager.PERMISSION_GRANTED) {
-                    collectNotedOpSync(op, proxiedFeatureId);
+                    collectNotedOpSync(op, proxiedAttributionTag);
                 }
             }
 
@@ -7537,8 +7544,8 @@
      * @param op The operation to start.  One of the OPSTR_* constants.
      * @param uid The user id of the application attempting to perform the operation.
      * @param packageName The name of the application attempting to perform the operation.
-     * @param featureId The {@link Context#createFeatureContext feature} in the package or {@code
-     * null} for default feature
+     * @param attributionTag The {@link Context#createAttributionContext attribution tag} or
+     * {@code null} for default attribution
      * @param message Description why op was started
      *
      * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
@@ -7549,8 +7556,8 @@
      * the package is not in the passed in UID.
      */
     public int startOp(@NonNull String op, int uid, @Nullable String packageName,
-            @Nullable String featureId, @Nullable String message) {
-        return startOp(strOpToOp(op), uid, packageName, false, featureId, message);
+            @Nullable String attributionTag, @Nullable String message) {
+        return startOp(strOpToOp(op), uid, packageName, false, attributionTag, message);
     }
 
     /**
@@ -7559,7 +7566,8 @@
      * @param op The operation to start.  One of the OP_* constants.
      * @param uid The user id of the application attempting to perform the operation.
      * @param packageName The name of the application attempting to perform the operation.
-     * @param featureId The feature in the app or {@code null} for default feature
+     * @param attributionTag The {@link Context#createAttributionContext attribution tag} or
+     * {@code null} for default attribution
      * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}.
      * @param message Description why op was started
      *
@@ -7573,8 +7581,8 @@
      * @hide
      */
     public int startOp(int op, int uid, @Nullable String packageName, boolean startIfModeDefault,
-            @Nullable String featureId, @Nullable String message) {
-        final int mode = startOpNoThrow(op, uid, packageName, startIfModeDefault, featureId,
+            @Nullable String attributionTag, @Nullable String message) {
+        final int mode = startOpNoThrow(op, uid, packageName, startIfModeDefault, attributionTag,
                 message);
         if (mode == MODE_ERRORED) {
             throw new SecurityException(buildSecurityExceptionMsg(op, uid, packageName));
@@ -7617,7 +7625,8 @@
      * @param op The operation to start.  One of the OP_* constants.
      * @param uid The user id of the application attempting to perform the operation.
      * @param packageName The name of the application attempting to perform the operation.
-     * @param featureId The feature in the app or {@code null} for default feature
+     * @param attributionTag The {@link Context#createAttributionContext attribution tag} or
+     * {@code null} for default attribution
      * @param message Description why op was started
      *
      * @return Returns {@link #MODE_ALLOWED} if the operation is allowed, or
@@ -7625,8 +7634,8 @@
      * causing the app to crash).
      */
     public int startOpNoThrow(@NonNull String op, int uid, @NonNull String packageName,
-            @NonNull String featureId, @Nullable String message) {
-        return startOpNoThrow(strOpToOp(op), uid, packageName, false, featureId, message);
+            @NonNull String attributionTag, @Nullable String message) {
+        return startOpNoThrow(strOpToOp(op), uid, packageName, false, attributionTag, message);
     }
 
     /**
@@ -7636,7 +7645,8 @@
      * @param op The operation to start.  One of the OP_* constants.
      * @param uid The user id of the application attempting to perform the operation.
      * @param packageName The name of the application attempting to perform the operation.
-     * @param featureId The feature in the app or {@code null} for default feature
+     * @param attributionTag The {@link Context#createAttributionContext attribution tag} or
+     * {@code null} for default attribution
      * @param startIfModeDefault Whether to start if mode is {@link #MODE_DEFAULT}.
      * @param message Description why op was started
      *
@@ -7647,7 +7657,7 @@
      * @hide
      */
     public int startOpNoThrow(int op, int uid, @NonNull String packageName,
-            boolean startIfModeDefault, @Nullable String featureId, @Nullable String message) {
+            boolean startIfModeDefault, @Nullable String attributionTag, @Nullable String message) {
         try {
             collectNoteOpCallsForValidation(op);
             int collectionMode = getNotedOpCollectionMode(uid, packageName, op);
@@ -7659,13 +7669,13 @@
             }
 
             int mode = mService.startOperation(getClientId(), op, uid, packageName,
-                    featureId, startIfModeDefault, collectionMode == COLLECT_ASYNC, message);
+                    attributionTag, startIfModeDefault, collectionMode == COLLECT_ASYNC, message);
 
             if (mode == MODE_ALLOWED) {
                 if (collectionMode == COLLECT_SELF) {
-                    collectNotedOpForSelf(op, featureId);
+                    collectNotedOpForSelf(op, attributionTag);
                 } else if (collectionMode == COLLECT_SYNC) {
-                    collectNotedOpSync(op, featureId);
+                    collectNotedOpSync(op, attributionTag);
                 }
             }
 
@@ -7699,8 +7709,8 @@
      * previously passed in when starting the operation.
      */
     public void finishOp(@NonNull String op, int uid, @NonNull String packageName,
-            @Nullable String featureId) {
-        finishOp(strOpToOp(op), uid, packageName, featureId);
+            @Nullable String attributionTag) {
+        finishOp(strOpToOp(op), uid, packageName, attributionTag);
     }
 
     /**
@@ -7721,9 +7731,9 @@
      * @hide
      */
     public void finishOp(int op, int uid, @NonNull String packageName,
-            @Nullable String featureId) {
+            @Nullable String attributionTag) {
         try {
-            mService.finishOperation(getClientId(), op, uid, packageName, featureId);
+            mService.finishOperation(getClientId(), op, uid, packageName, attributionTag);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -7834,15 +7844,15 @@
      * Collect a noted op for the current process.
      *
      * @param op The noted op
-     * @param featureId The feature the op is noted for
+     * @param attributionTag The attribution tag the op is noted for
      */
-    private void collectNotedOpForSelf(int op, @Nullable String featureId) {
+    private void collectNotedOpForSelf(int op, @Nullable String attributionTag) {
         synchronized (sLock) {
             if (sOnOpNotedCallback != null) {
-                sOnOpNotedCallback.onSelfNoted(new SyncNotedAppOp(op, featureId));
+                sOnOpNotedCallback.onSelfNoted(new SyncNotedAppOp(op, attributionTag));
             }
         }
-        sMessageCollector.onSelfNoted(new SyncNotedAppOp(op, featureId));
+        sMessageCollector.onSelfNoted(new SyncNotedAppOp(op, attributionTag));
     }
 
     /**
@@ -7851,9 +7861,9 @@
      * <p> Delivered to caller via {@link #prefixParcelWithAppOpsIfNeeded}
      *
      * @param op The noted op
-     * @param featureId The feature the op is noted for
+     * @param attributionTag The attribution tag the op is noted for
      */
-    private void collectNotedOpSync(int op, @Nullable String featureId) {
+    private void collectNotedOpSync(int op, @Nullable String attributionTag) {
         // If this is inside of a two-way binder call:
         // We are inside of a two-way binder call. Delivered to caller via
         // {@link #prefixParcelWithAppOpsIfNeeded}
@@ -7863,16 +7873,16 @@
             sAppOpsNotedInThisBinderTransaction.set(appOpsNoted);
         }
 
-        long[] appOpsNotedForFeature = appOpsNoted.get(featureId);
-        if (appOpsNotedForFeature == null) {
-            appOpsNotedForFeature = new long[2];
-            appOpsNoted.put(featureId, appOpsNotedForFeature);
+        long[] appOpsNotedForAttribution = appOpsNoted.get(attributionTag);
+        if (appOpsNotedForAttribution == null) {
+            appOpsNotedForAttribution = new long[2];
+            appOpsNoted.put(attributionTag, appOpsNotedForAttribution);
         }
 
         if (op < 64) {
-            appOpsNotedForFeature[0] |= 1L << op;
+            appOpsNotedForAttribution[0] |= 1L << op;
         } else {
-            appOpsNotedForFeature[1] |= 1L << (op - 64);
+            appOpsNotedForAttribution[1] |= 1L << (op - 64);
         }
     }
 
@@ -7953,10 +7963,10 @@
 
         p.writeInt(Parcel.EX_HAS_NOTED_APPOPS_REPLY_HEADER);
 
-        int numFeatureWithNotesAppOps = notedAppOps.size();
-        p.writeInt(numFeatureWithNotesAppOps);
+        int numAttributionWithNotesAppOps = notedAppOps.size();
+        p.writeInt(numAttributionWithNotesAppOps);
 
-        for (int i = 0; i < numFeatureWithNotesAppOps; i++) {
+        for (int i = 0; i < numAttributionWithNotesAppOps; i++) {
             p.writeString(notedAppOps.keyAt(i));
             p.writeLong(notedAppOps.valueAt(i)[0]);
             p.writeLong(notedAppOps.valueAt(i)[1]);
@@ -7974,10 +7984,10 @@
      * @hide
      */
     public static void readAndLogNotedAppops(@NonNull Parcel p) {
-        int numFeaturesWithNotedAppOps = p.readInt();
+        int numAttributionsWithNotedAppOps = p.readInt();
 
-        for (int i = 0; i < numFeaturesWithNotedAppOps; i++) {
-            String featureId = p.readString();
+        for (int i = 0; i < numAttributionsWithNotedAppOps; i++) {
+            String attributionTag = p.readString();
             long[] rawNotedAppOps = new long[2];
             rawNotedAppOps[0] = p.readLong();
             rawNotedAppOps[1] = p.readLong();
@@ -7989,13 +7999,13 @@
                     for (int code = notedAppOps.nextSetBit(0); code != -1;
                             code = notedAppOps.nextSetBit(code + 1)) {
                         if (sOnOpNotedCallback != null) {
-                            sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, featureId));
+                            sOnOpNotedCallback.onNoted(new SyncNotedAppOp(code, attributionTag));
                         }
                     }
                 }
                 for (int code = notedAppOps.nextSetBit(0); code != -1;
                         code = notedAppOps.nextSetBit(code + 1)) {
-                    sMessageCollector.onNoted(new SyncNotedAppOp(code, featureId));
+                    sMessageCollector.onNoted(new SyncNotedAppOp(code, attributionTag));
                 }
             }
         }
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 87d33a9..bfaa2be 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -3337,6 +3337,15 @@
         }
     }
 
+    @Override
+    public boolean isAutoRevokeWhitelisted() {
+        try {
+            return mPM.isAutoRevokeWhitelisted(mContext.getPackageName());
+        } catch (RemoteException e) {
+            throw e.rethrowAsRuntimeException();
+        }
+    }
+
     public void setMimeGroup(String mimeGroup, Set<String> mimeTypes) {
         try {
             mPM.setMimeGroup(mContext.getPackageName(), mimeGroup,
diff --git a/core/java/android/app/AsyncNotedAppOp.java b/core/java/android/app/AsyncNotedAppOp.java
index 4d955db..b0c2762c 100644
--- a/core/java/android/app/AsyncNotedAppOp.java
+++ b/core/java/android/app/AsyncNotedAppOp.java
@@ -48,8 +48,8 @@
     /** Uid that noted the op */
     private final @IntRange(from = 0) int mNotingUid;
 
-    /** {@link android.content.Context#createFeatureContext Feature} in the app */
-    private final @Nullable String mFeatureId;
+    /** {@link android.content.Context#createAttributionContext attribution tag} */
+    private final @Nullable String mAttributionTag;
 
     /** Message associated with the noteOp. This message is set by the app noting the op */
     private final @NonNull String mMessage;
@@ -92,8 +92,8 @@
      *   Op that was noted
      * @param notingUid
      *   Uid that noted the op
-     * @param featureId
-     *   {@link android.content.Context#createFeatureContext Feature} in the app
+     * @param attributionTag
+     *   {@link android.content.Context#createAttributionContext attribution tag}
      * @param message
      *   Message associated with the noteOp. This message is set by the app noting the op
      * @param time
@@ -104,7 +104,7 @@
     public AsyncNotedAppOp(
             @IntRange(from = 0) int opCode,
             @IntRange(from = 0) int notingUid,
-            @Nullable String featureId,
+            @Nullable String attributionTag,
             @NonNull String message,
             @CurrentTimeMillisLong long time) {
         this.mOpCode = opCode;
@@ -115,7 +115,7 @@
         com.android.internal.util.AnnotationValidations.validate(
                 IntRange.class, null, mNotingUid,
                 "from", 0);
-        this.mFeatureId = featureId;
+        this.mAttributionTag = attributionTag;
         this.mMessage = message;
         com.android.internal.util.AnnotationValidations.validate(
                 NonNull.class, null, mMessage);
@@ -135,11 +135,11 @@
     }
 
     /**
-     * {@link android.content.Context#createFeatureContext Feature} in the app
+     * {@link android.content.Context#createAttributionContext attribution tag}
      */
     @DataClass.Generated.Member
-    public @Nullable String getFeatureId() {
-        return mFeatureId;
+    public @Nullable String getAttributionTag() {
+        return mAttributionTag;
     }
 
     /**
@@ -173,7 +173,7 @@
         return true
                 && mOpCode == that.mOpCode
                 && mNotingUid == that.mNotingUid
-                && java.util.Objects.equals(mFeatureId, that.mFeatureId)
+                && java.util.Objects.equals(mAttributionTag, that.mAttributionTag)
                 && java.util.Objects.equals(mMessage, that.mMessage)
                 && mTime == that.mTime;
     }
@@ -187,7 +187,7 @@
         int _hash = 1;
         _hash = 31 * _hash + mOpCode;
         _hash = 31 * _hash + mNotingUid;
-        _hash = 31 * _hash + java.util.Objects.hashCode(mFeatureId);
+        _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag);
         _hash = 31 * _hash + java.util.Objects.hashCode(mMessage);
         _hash = 31 * _hash + Long.hashCode(mTime);
         return _hash;
@@ -200,11 +200,11 @@
         // void parcelFieldName(Parcel dest, int flags) { ... }
 
         byte flg = 0;
-        if (mFeatureId != null) flg |= 0x4;
+        if (mAttributionTag != null) flg |= 0x4;
         dest.writeByte(flg);
         dest.writeInt(mOpCode);
         dest.writeInt(mNotingUid);
-        if (mFeatureId != null) dest.writeString(mFeatureId);
+        if (mAttributionTag != null) dest.writeString(mAttributionTag);
         dest.writeString(mMessage);
         dest.writeLong(mTime);
     }
@@ -223,7 +223,7 @@
         byte flg = in.readByte();
         int opCode = in.readInt();
         int notingUid = in.readInt();
-        String featureId = (flg & 0x4) == 0 ? null : in.readString();
+        String attributionTag = (flg & 0x4) == 0 ? null : in.readString();
         String message = in.readString();
         long time = in.readLong();
 
@@ -235,7 +235,7 @@
         com.android.internal.util.AnnotationValidations.validate(
                 IntRange.class, null, mNotingUid,
                 "from", 0);
-        this.mFeatureId = featureId;
+        this.mAttributionTag = attributionTag;
         this.mMessage = message;
         com.android.internal.util.AnnotationValidations.validate(
                 NonNull.class, null, mMessage);
@@ -261,10 +261,10 @@
     };
 
     @DataClass.Generated(
-            time = 1583866178330L,
+            time = 1583866239013L,
             codegenVersion = "1.0.15",
             sourceFile = "frameworks/base/core/java/android/app/AsyncNotedAppOp.java",
-            inputSignatures = "private final @android.annotation.IntRange(from=0L) int mOpCode\nprivate final @android.annotation.IntRange(from=0L) int mNotingUid\nprivate final @android.annotation.Nullable java.lang.String mFeatureId\nprivate final @android.annotation.NonNull java.lang.String mMessage\nprivate final @android.annotation.CurrentTimeMillisLong long mTime\npublic @android.annotation.NonNull java.lang.String getOp()\nprivate  void onConstructed()\nclass AsyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genHiddenConstructor=true)")
+            inputSignatures = "private final @android.annotation.IntRange(from=0L) int mOpCode\nprivate final @android.annotation.IntRange(from=0L) int mNotingUid\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate final @android.annotation.NonNull java.lang.String mMessage\nprivate final @android.annotation.CurrentTimeMillisLong long mTime\npublic @android.annotation.NonNull java.lang.String getOp()\nprivate  void onConstructed()\nclass AsyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genAidl=true, genHiddenConstructor=true)")
     @Deprecated
     private void __metadata() {}
 
diff --git a/core/java/android/app/ContextImpl.java b/core/java/android/app/ContextImpl.java
index 2873b10..56e6aee 100644
--- a/core/java/android/app/ContextImpl.java
+++ b/core/java/android/app/ContextImpl.java
@@ -219,8 +219,8 @@
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
     private final String mOpPackageName;
 
-    /** If of feature this context is for */
-    private final @Nullable String mFeatureId;
+    /** Attribution tag of this context */
+    private final @Nullable String mAttributionTag;
 
     private final @NonNull ResourcesManager mResourcesManager;
     @UnsupportedAppUsage
@@ -421,8 +421,8 @@
 
     /** @hide */
     @Override
-    public @Nullable String getFeatureId() {
-        return mFeatureId;
+    public @Nullable String getAttributionTag() {
+        return mAttributionTag;
     }
 
     @Override
@@ -1026,10 +1026,10 @@
     public void startActivityAsUser(Intent intent, Bundle options, UserHandle user) {
         try {
             ActivityTaskManager.getService().startActivityAsUser(
-                mMainThread.getApplicationThread(), getBasePackageName(), getFeatureId(), intent,
-                intent.resolveTypeIfNeeded(getContentResolver()),
-                null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options,
-                user.getIdentifier());
+                    mMainThread.getApplicationThread(), getBasePackageName(), getAttributionTag(),
+                    intent, intent.resolveTypeIfNeeded(getContentResolver()),
+                    null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, options,
+                    user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1109,9 +1109,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false, false,
-                    getUserId());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false,
+                    false, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1126,9 +1126,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE,
-                    null, false, false, getUserId());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, receiverPermissions,
+                    AppOpsManager.OP_NONE, null, false, false, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1141,9 +1141,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE,
-                    null, false, false, getUserId());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, receiverPermissions,
+                    AppOpsManager.OP_NONE, null, false, false, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1156,9 +1156,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE,
-                    null, false, false, user.getIdentifier());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, receiverPermissions,
+                    AppOpsManager.OP_NONE, null, false, false, user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1173,9 +1173,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE,
-                    options, false, false, getUserId());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, receiverPermissions,
+                    AppOpsManager.OP_NONE, options, false, false, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1190,9 +1190,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, receiverPermissions, appOp, null, false, false,
-                    getUserId());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, receiverPermissions, appOp, null, false,
+                    false, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1207,9 +1207,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE,
-                    null, true, false, getUserId());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, receiverPermissions,
+                    AppOpsManager.OP_NONE, null, true, false, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1270,8 +1270,8 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, rd,
-                initialCode, initialData, initialExtras, receiverPermissions, appOp,
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    rd, initialCode, initialData, initialExtras, receiverPermissions, appOp,
                     options, true, false, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
@@ -1284,9 +1284,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false, false,
-                    user.getIdentifier());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false,
+                    false, user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1307,9 +1307,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, receiverPermissions, AppOpsManager.OP_NONE,
-                    options, false, false, user.getIdentifier());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, receiverPermissions,
+                    AppOpsManager.OP_NONE, options, false, false, user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1324,9 +1324,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                    mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                    Activity.RESULT_OK, null, null, receiverPermissions, appOp, null, false, false,
-                    user.getIdentifier());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, receiverPermissions, appOp, null, false,
+                    false, user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1375,9 +1375,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, rd,
-                initialCode, initialData, initialExtras, receiverPermissions,
-                    appOp, options, true, false, user.getIdentifier());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    rd, initialCode, initialData, initialExtras, receiverPermissions, appOp,
+                    options, true, false, user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1416,9 +1416,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false, true,
-                getUserId());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false,
+                    true, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1452,9 +1452,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, rd,
-                initialCode, initialData, initialExtras, null,
-                    AppOpsManager.OP_NONE, null, true, true, getUserId());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    rd, initialCode, initialData, initialExtras, null, AppOpsManager.OP_NONE, null,
+                    true, true, getUserId());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1484,9 +1484,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false, true,
-                    user.getIdentifier());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, null, false,
+                    true, user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1499,9 +1499,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, null,
-                Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, options, false, true,
-                user.getIdentifier());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    null, Activity.RESULT_OK, null, null, null, AppOpsManager.OP_NONE, options,
+                    false, true, user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1534,9 +1534,9 @@
         try {
             intent.prepareToLeaveProcess(this);
             ActivityManager.getService().broadcastIntentWithFeature(
-                mMainThread.getApplicationThread(), getFeatureId(), intent, resolvedType, rd,
-                initialCode, initialData, initialExtras, null,
-                    AppOpsManager.OP_NONE, null, true, true, user.getIdentifier());
+                    mMainThread.getApplicationThread(), getAttributionTag(), intent, resolvedType,
+                    rd, initialCode, initialData, initialExtras, null, AppOpsManager.OP_NONE, null,
+                    true, true, user.getIdentifier());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1620,7 +1620,7 @@
         }
         try {
             final Intent intent = ActivityManager.getService().registerReceiverWithFeature(
-                    mMainThread.getApplicationThread(), mBasePackageName, getFeatureId(), rd,
+                    mMainThread.getApplicationThread(), mBasePackageName, getAttributionTag(), rd,
                     filter, broadcastPermission, userId, flags);
             if (intent != null) {
                 intent.setExtrasClassLoader(getClassLoader());
@@ -1696,7 +1696,7 @@
             ComponentName cn = ActivityManager.getService().startService(
                     mMainThread.getApplicationThread(), service,
                     service.resolveTypeIfNeeded(getContentResolver()), requireForeground,
-                    getOpPackageName(), getFeatureId(), user.getIdentifier());
+                    getOpPackageName(), getAttributionTag(), user.getIdentifier());
             if (cn != null) {
                 if (cn.getPackageName().equals("!")) {
                     throw new SecurityException(
@@ -2285,14 +2285,14 @@
         if (packageName.equals("system") || packageName.equals("android")) {
             // The system resources are loaded in every application, so we can safely copy
             // the context without reloading Resources.
-            return new ContextImpl(this, mMainThread, mPackageInfo, mFeatureId, null,
+            return new ContextImpl(this, mMainThread, mPackageInfo, mAttributionTag, null,
                     mToken, user, flags, null, null);
         }
 
         LoadedApk pi = mMainThread.getPackageInfo(packageName, mResources.getCompatibilityInfo(),
                 flags | CONTEXT_REGISTER_PACKAGE, user.getIdentifier());
         if (pi != null) {
-            ContextImpl c = new ContextImpl(this, mMainThread, pi, mFeatureId, null,
+            ContextImpl c = new ContextImpl(this, mMainThread, pi, mAttributionTag, null,
                     mToken, user, flags, null, null);
 
             final int displayId = getDisplayId();
@@ -2329,7 +2329,7 @@
         final String[] paths = mPackageInfo.getSplitPaths(splitName);
 
         final ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo,
-                mFeatureId, splitName, mToken, mUser, mFlags, classLoader, null);
+                mAttributionTag, splitName, mToken, mUser, mFlags, classLoader, null);
 
         final int displayId = getDisplayId();
 
@@ -2353,7 +2353,7 @@
             throw new IllegalArgumentException("overrideConfiguration must not be null");
         }
 
-        ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mFeatureId,
+        ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mAttributionTag,
                 mSplitName, mToken, mUser, mFlags, mClassLoader, null);
 
         final int displayId = getDisplayId();
@@ -2370,7 +2370,7 @@
             throw new IllegalArgumentException("display must not be null");
         }
 
-        ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mFeatureId,
+        ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mAttributionTag,
                 mSplitName, mToken, mUser, mFlags, mClassLoader, null);
 
         final int displayId = display.getDisplayId();
@@ -2394,7 +2394,7 @@
     }
 
     ContextImpl createBaseWindowContext(IBinder token) {
-        ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mFeatureId,
+        ContextImpl context = new ContextImpl(this, mMainThread, mPackageInfo, mAttributionTag,
                 mSplitName, token, mUser, mFlags, mClassLoader, null);
         context.mIsUiContext = true;
 
@@ -2420,8 +2420,8 @@
     }
 
     @Override
-    public @NonNull Context createFeatureContext(@Nullable String featureId) {
-        return new ContextImpl(this, mMainThread, mPackageInfo, featureId, mSplitName,
+    public @NonNull Context createAttributionContext(@Nullable String attributionTag) {
+        return new ContextImpl(this, mMainThread, mPackageInfo, attributionTag, mSplitName,
                 mToken, mUser, mFlags, mClassLoader, null);
     }
 
@@ -2429,7 +2429,7 @@
     public Context createDeviceProtectedStorageContext() {
         final int flags = (mFlags & ~Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE)
                 | Context.CONTEXT_DEVICE_PROTECTED_STORAGE;
-        return new ContextImpl(this, mMainThread, mPackageInfo, mFeatureId, mSplitName,
+        return new ContextImpl(this, mMainThread, mPackageInfo, mAttributionTag, mSplitName,
                 mToken, mUser, flags, mClassLoader, null);
     }
 
@@ -2437,7 +2437,7 @@
     public Context createCredentialProtectedStorageContext() {
         final int flags = (mFlags & ~Context.CONTEXT_DEVICE_PROTECTED_STORAGE)
                 | Context.CONTEXT_CREDENTIAL_PROTECTED_STORAGE;
-        return new ContextImpl(this, mMainThread, mPackageInfo, mFeatureId, mSplitName,
+        return new ContextImpl(this, mMainThread, mPackageInfo, mAttributionTag, mSplitName,
                 mToken, mUser, flags, mClassLoader, null);
     }
 
@@ -2700,7 +2700,7 @@
     }
 
     private ContextImpl(@Nullable ContextImpl container, @NonNull ActivityThread mainThread,
-            @NonNull LoadedApk packageInfo, @Nullable String featureId,
+            @NonNull LoadedApk packageInfo, @Nullable String attributionTag,
             @Nullable String splitName, @Nullable IBinder activityToken, @Nullable UserHandle user,
             int flags, @Nullable ClassLoader classLoader, @Nullable String overrideOpPackageName) {
         mOuterContext = this;
@@ -2754,7 +2754,7 @@
         }
 
         mOpPackageName = overrideOpPackageName != null ? overrideOpPackageName : opPackageName;
-        mFeatureId = featureId;
+        mAttributionTag = attributionTag;
         mContentResolver = new ApplicationContentResolver(this, mainThread);
     }
 
diff --git a/core/java/android/app/Instrumentation.java b/core/java/android/app/Instrumentation.java
index 18932c6..818a121 100644
--- a/core/java/android/app/Instrumentation.java
+++ b/core/java/android/app/Instrumentation.java
@@ -1720,11 +1720,10 @@
         try {
             intent.migrateExtraStreamToClipData();
             intent.prepareToLeaveProcess(who);
-            int result = ActivityTaskManager.getService()
-                .startActivity(whoThread, who.getBasePackageName(), who.getFeatureId(), intent,
-                        intent.resolveTypeIfNeeded(who.getContentResolver()),
-                        token, target != null ? target.mEmbeddedID : null,
-                        requestCode, 0, null, options);
+            int result = ActivityTaskManager.getService().startActivity(whoThread,
+                    who.getBasePackageName(), who.getAttributionTag(), intent,
+                    intent.resolveTypeIfNeeded(who.getContentResolver()), token,
+                    target != null ? target.mEmbeddedID : null, requestCode, 0, null, options);
             checkStartActivityResult(result, intent);
         } catch (RemoteException e) {
             throw new RuntimeException("Failure from system", e);
@@ -1793,9 +1792,9 @@
                 intents[i].prepareToLeaveProcess(who);
                 resolvedTypes[i] = intents[i].resolveTypeIfNeeded(who.getContentResolver());
             }
-            int result = ActivityTaskManager.getService()
-                .startActivities(whoThread, who.getBasePackageName(), who.getFeatureId(), intents,
-                        resolvedTypes, token, options, userId);
+            int result = ActivityTaskManager.getService().startActivities(whoThread,
+                    who.getBasePackageName(), who.getAttributionTag(), intents, resolvedTypes,
+                    token, options, userId);
             checkStartActivityResult(result, intents[0]);
             return result;
         } catch (RemoteException e) {
@@ -1860,10 +1859,10 @@
         try {
             intent.migrateExtraStreamToClipData();
             intent.prepareToLeaveProcess(who);
-            int result = ActivityTaskManager.getService()
-                .startActivity(whoThread, who.getBasePackageName(), who.getFeatureId(), intent,
-                        intent.resolveTypeIfNeeded(who.getContentResolver()),
-                        token, target, requestCode, 0, null, options);
+            int result = ActivityTaskManager.getService().startActivity(whoThread,
+                    who.getBasePackageName(), who.getAttributionTag(), intent,
+                    intent.resolveTypeIfNeeded(who.getContentResolver()), token, target,
+                    requestCode, 0, null, options);
             checkStartActivityResult(result, intent);
         } catch (RemoteException e) {
             throw new RuntimeException("Failure from system", e);
@@ -1927,11 +1926,10 @@
         try {
             intent.migrateExtraStreamToClipData();
             intent.prepareToLeaveProcess(who);
-            int result = ActivityTaskManager.getService()
-                .startActivityAsUser(whoThread, who.getBasePackageName(), who.getFeatureId(),
-                        intent, intent.resolveTypeIfNeeded(who.getContentResolver()),
-                        token, resultWho,
-                        requestCode, 0, null, options, user.getIdentifier());
+            int result = ActivityTaskManager.getService().startActivityAsUser(whoThread,
+                    who.getBasePackageName(), who.getAttributionTag(), intent,
+                    intent.resolveTypeIfNeeded(who.getContentResolver()), token, resultWho,
+                    requestCode, 0, null, options, user.getIdentifier());
             checkStartActivityResult(result, intent);
         } catch (RemoteException e) {
             throw new RuntimeException("Failure from system", e);
@@ -2022,7 +2020,7 @@
             intent.migrateExtraStreamToClipData();
             intent.prepareToLeaveProcess(who);
             int result = appTask.startActivity(whoThread.asBinder(), who.getBasePackageName(),
-                    who.getFeatureId(), intent,
+                    who.getAttributionTag(), intent,
                     intent.resolveTypeIfNeeded(who.getContentResolver()), options);
             checkStartActivityResult(result, intent);
         } catch (RemoteException e) {
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 32e7d84..061e5ff 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -21,6 +21,7 @@
 import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP;
 
 import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast;
+import static com.android.internal.widget.ConversationLayout.CONVERSATION_LAYOUT_ENABLED;
 
 import android.annotation.ColorInt;
 import android.annotation.DimenRes;
@@ -389,6 +390,7 @@
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_text);
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_inbox);
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_messaging);
+        STANDARD_LAYOUTS.add(R.layout.notification_template_material_conversation);
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_media);
         STANDARD_LAYOUTS.add(R.layout.notification_template_material_big_media);
         STANDARD_LAYOUTS.add(R.layout.notification_template_header);
@@ -5138,7 +5140,7 @@
             int color = isColorized(p) ? getPrimaryTextColor(p) : getSecondaryTextColor(p);
             contentView.setDrawableTint(R.id.expand_button, false, color,
                     PorterDuff.Mode.SRC_ATOP);
-            contentView.setInt(R.id.notification_header, "setOriginalNotificationColor",
+            contentView.setInt(R.id.expand_button, "setOriginalNotificationColor",
                     color);
         }
 
@@ -6116,7 +6118,9 @@
         }
 
         private int getMessagingLayoutResource() {
-            return R.layout.notification_template_material_messaging;
+            return CONVERSATION_LAYOUT_ENABLED
+                    ? R.layout.notification_template_material_conversation
+                    : R.layout.notification_template_material_messaging;
         }
 
         private int getActionLayoutResource() {
@@ -6221,6 +6225,17 @@
             }
             return loadHeaderAppName();
         }
+
+        /**
+         * @return if this builder uses a template
+         *
+         * @hide
+         */
+        public boolean usesTemplate() {
+            return (mN.contentView == null && mN.headsUpContentView == null
+                    && mN.bigContentView == null)
+                    || (mStyle != null && mStyle.displayCustomViewInline());
+        }
     }
 
     /**
@@ -7379,7 +7394,7 @@
         public RemoteViews makeContentView(boolean increasedHeight) {
             mBuilder.mOriginalActions = mBuilder.mActions;
             mBuilder.mActions = new ArrayList<>();
-            RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */,
+            RemoteViews remoteViews = makeMessagingView(true /* isCollapsed */,
                     false /* hideLargeIcon */);
             mBuilder.mActions = mBuilder.mOriginalActions;
             mBuilder.mOriginalActions = null;
@@ -7469,19 +7484,18 @@
          */
         @Override
         public RemoteViews makeBigContentView() {
-            return makeMessagingView(false /* displayImagesAtEnd */, true /* hideLargeIcon */);
+            return makeMessagingView(false /* isCollapsed */, true /* hideLargeIcon */);
         }
 
         /**
          * Create a messaging layout.
          *
-         * @param displayImagesAtEnd should images be displayed at the end of the content instead
-         *                           of inline.
+         * @param isCollapsed Should this use the collapsed layout
          * @param hideRightIcons Should the reply affordance be shown at the end of the notification
          * @return the created remoteView.
          */
         @NonNull
-        private RemoteViews makeMessagingView(boolean displayImagesAtEnd, boolean hideRightIcons) {
+        private RemoteViews makeMessagingView(boolean isCollapsed, boolean hideRightIcons) {
             CharSequence conversationTitle = !TextUtils.isEmpty(super.mBigContentTitle)
                     ? super.mBigContentTitle
                     : mConversationTitle;
@@ -7522,14 +7536,21 @@
                     mBuilder.getPrimaryTextColor(p));
             contentView.setInt(R.id.status_bar_latest_event_content, "setMessageTextColor",
                     mBuilder.getSecondaryTextColor(p));
-            contentView.setBoolean(R.id.status_bar_latest_event_content, "setDisplayImagesAtEnd",
-                    displayImagesAtEnd);
+            contentView.setInt(R.id.status_bar_latest_event_content,
+                    "setNotificationBackgroundColor",
+                    mBuilder.resolveBackgroundColor(p));
+            contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsCollapsed",
+                    isCollapsed);
             contentView.setIcon(R.id.status_bar_latest_event_content, "setAvatarReplacement",
                     avatarReplacement);
             contentView.setCharSequence(R.id.status_bar_latest_event_content, "setNameReplacement",
                     nameReplacement);
             contentView.setBoolean(R.id.status_bar_latest_event_content, "setIsOneToOne",
                     isOneToOne);
+            contentView.setCharSequence(R.id.status_bar_latest_event_content,
+                    "setConversationTitle", conversationTitle);
+            contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon",
+                    mBuilder.mN.mLargeIcon);
             contentView.setBundle(R.id.status_bar_latest_event_content, "setData",
                     mBuilder.mN.extras);
             return contentView;
@@ -7590,9 +7611,11 @@
          */
         @Override
         public RemoteViews makeHeadsUpContentView(boolean increasedHeight) {
-            RemoteViews remoteViews = makeMessagingView(true /* displayImagesAtEnd */,
+            RemoteViews remoteViews = makeMessagingView(true /* isCollapsed */,
                     true /* hideLargeIcon */);
-            remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1);
+            if (!CONVERSATION_LAYOUT_ENABLED) {
+                remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1);
+            }
             return remoteViews;
         }
 
diff --git a/core/java/android/app/PendingIntent.java b/core/java/android/app/PendingIntent.java
index f68c929..792f840 100644
--- a/core/java/android/app/PendingIntent.java
+++ b/core/java/android/app/PendingIntent.java
@@ -355,8 +355,8 @@
             intent.prepareToLeaveProcess(context);
             IIntentSender target =
                 ActivityManager.getService().getIntentSenderWithFeature(
-                    ActivityManager.INTENT_SENDER_ACTIVITY, packageName, context.getFeatureId(),
-                    null, null, requestCode, new Intent[] { intent },
+                    ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
+                    context.getAttributionTag(), null, null, requestCode, new Intent[] { intent },
                     resolvedType != null ? new String[] { resolvedType } : null,
                     flags, options, context.getUserId());
             return target != null ? new PendingIntent(target) : null;
@@ -381,8 +381,8 @@
             intent.prepareToLeaveProcess(context);
             IIntentSender target =
                 ActivityManager.getService().getIntentSenderWithFeature(
-                    ActivityManager.INTENT_SENDER_ACTIVITY, packageName, context.getFeatureId(),
-                    null, null, requestCode, new Intent[] { intent },
+                    ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
+                    context.getAttributionTag(), null, null, requestCode, new Intent[] { intent },
                     resolvedType != null ? new String[] { resolvedType } : null,
                     flags, options, user.getIdentifier());
             return target != null ? new PendingIntent(target) : null;
@@ -498,9 +498,9 @@
         try {
             IIntentSender target =
                 ActivityManager.getService().getIntentSenderWithFeature(
-                    ActivityManager.INTENT_SENDER_ACTIVITY, packageName, context.getFeatureId(),
-                    null, null, requestCode, intents, resolvedTypes, flags, options,
-                    context.getUserId());
+                    ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
+                    context.getAttributionTag(), null, null, requestCode, intents, resolvedTypes,
+                    flags, options, context.getUserId());
             return target != null ? new PendingIntent(target) : null;
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
@@ -524,8 +524,8 @@
         try {
             IIntentSender target =
                 ActivityManager.getService().getIntentSenderWithFeature(
-                    ActivityManager.INTENT_SENDER_ACTIVITY, packageName, context.getFeatureId(),
-                    null, null, requestCode, intents, resolvedTypes,
+                    ActivityManager.INTENT_SENDER_ACTIVITY, packageName,
+                    context.getAttributionTag(), null, null, requestCode, intents, resolvedTypes,
                     flags, options, user.getIdentifier());
             return target != null ? new PendingIntent(target) : null;
         } catch (RemoteException e) {
@@ -576,8 +576,8 @@
             intent.prepareToLeaveProcess(context);
             IIntentSender target =
                 ActivityManager.getService().getIntentSenderWithFeature(
-                    ActivityManager.INTENT_SENDER_BROADCAST, packageName, context.getFeatureId(),
-                    null, null, requestCode, new Intent[] { intent },
+                    ActivityManager.INTENT_SENDER_BROADCAST, packageName,
+                    context.getAttributionTag(), null, null, requestCode, new Intent[] { intent },
                     resolvedType != null ? new String[] { resolvedType } : null,
                     flags, null, userHandle.getIdentifier());
             return target != null ? new PendingIntent(target) : null;
@@ -655,7 +655,7 @@
             intent.prepareToLeaveProcess(context);
             IIntentSender target =
                 ActivityManager.getService().getIntentSenderWithFeature(
-                    serviceKind, packageName, context.getFeatureId(),
+                    serviceKind, packageName, context.getAttributionTag(),
                     null, null, requestCode, new Intent[] { intent },
                     resolvedType != null ? new String[] { resolvedType } : null,
                     flags, null, context.getUserId());
diff --git a/core/java/android/app/RuntimeAppOpAccessMessage.java b/core/java/android/app/RuntimeAppOpAccessMessage.java
index a81b8e7..a19f815 100644
--- a/core/java/android/app/RuntimeAppOpAccessMessage.java
+++ b/core/java/android/app/RuntimeAppOpAccessMessage.java
@@ -44,7 +44,7 @@
     /** Name of package for which runtime app op access message was collected */
     private final @NonNull String mPackageName;
     /** Feature of package for which runtime app op access message was collected */
-    private final @Nullable String mFeatureId;
+    private final @Nullable String mAttributionTag;
     /** Message collected (including stacktrace for synchronous ops) */
     private final @NonNull String mMessage;
     /** Sampling strategy used to collect this message. */
@@ -63,8 +63,8 @@
      *   Op code of operation access which was collected
      * @param packageName
      *   Name of package for which runtime app op access message was collected
-     * @param featureId
-     *   Feature of package for which runtime app op access message was collected
+     * @param attributionTag
+     *   Attribution tag for which runtime app op access message was collected
      * @param message
      *   Message collected (including stacktrace for synchronous ops)
      * @param samplingStrategy
@@ -75,7 +75,7 @@
             @IntRange(from = 0L) int uid,
             @IntRange(from = 0L) int opCode,
             @NonNull String packageName,
-            @Nullable String featureId,
+            @Nullable String attributionTag,
             @NonNull String message,
             @AppOpsManager.SamplingStrategy int samplingStrategy) {
         this.mUid = uid;
@@ -90,7 +90,7 @@
         this.mPackageName = packageName;
         com.android.internal.util.AnnotationValidations.validate(
                 NonNull.class, null, mPackageName);
-        this.mFeatureId = featureId;
+        this.mAttributionTag = attributionTag;
         this.mMessage = message;
         com.android.internal.util.AnnotationValidations.validate(
                 NonNull.class, null, mMessage);
@@ -134,11 +134,11 @@
     }
 
     /**
-     * Feature of package for which runtime app op access message was collected
+     * Attribution tag for which runtime app op access message was collected
      */
     @DataClass.Generated.Member
-    public @Nullable String getFeatureId() {
-        return mFeatureId;
+    public @Nullable String getAttributionTag() {
+        return mAttributionTag;
     }
 
     /**
@@ -164,12 +164,12 @@
         // void parcelFieldName(Parcel dest, int flags) { ... }
 
         byte flg = 0;
-        if (mFeatureId != null) flg |= 0x8;
+        if (mAttributionTag != null) flg |= 0x8;
         dest.writeByte(flg);
         dest.writeInt(mUid);
         dest.writeInt(mOpCode);
         dest.writeString(mPackageName);
-        if (mFeatureId != null) dest.writeString(mFeatureId);
+        if (mAttributionTag != null) dest.writeString(mAttributionTag);
         dest.writeString(mMessage);
         dest.writeInt(mSamplingStrategy);
     }
@@ -189,7 +189,7 @@
         int uid = in.readInt();
         int opCode = in.readInt();
         String packageName = in.readString();
-        String featureId = (flg & 0x8) == 0 ? null : in.readString();
+        String attributionTag = (flg & 0x8) == 0 ? null : in.readString();
         String message = in.readString();
         int samplingStrategy = in.readInt();
 
@@ -205,7 +205,7 @@
         this.mPackageName = packageName;
         com.android.internal.util.AnnotationValidations.validate(
                 NonNull.class, null, mPackageName);
-        this.mFeatureId = featureId;
+        this.mAttributionTag = attributionTag;
         this.mMessage = message;
         com.android.internal.util.AnnotationValidations.validate(
                 NonNull.class, null, mMessage);
@@ -234,7 +234,7 @@
             time = 1581517099127L,
             codegenVersion = "1.0.14",
             sourceFile = "frameworks/base/core/java/android/app/RuntimeAppOpAccessMessage.java",
-            inputSignatures = "private final @android.annotation.IntRange(from=0L) int mUid\nprivate final @android.annotation.IntRange(from=0L, to=AppOpsManager._NUM_OP - 1) int mOpCode\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mFeatureId\nprivate final @android.annotation.NonNull java.lang.String mMessage\nprivate final @android.app.AppOpsManager.SamplingStrategy int mSamplingStrategy\npublic @android.annotation.NonNull java.lang.String getOp()\nclass RuntimeAppOpAccessMessage extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false)")*/
+            inputSignatures = "private final @android.annotation.IntRange(from=0L) int mUid\nprivate final @android.annotation.IntRange(from=0L, to=AppOpsManager._NUM_OP - 1) int mOpCode\nprivate final @android.annotation.NonNull java.lang.String mPackageName\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\nprivate final @android.annotation.NonNull java.lang.String mMessage\nprivate final @android.app.AppOpsManager.SamplingStrategy int mSamplingStrategy\npublic @android.annotation.NonNull java.lang.String getOp()\nclass RuntimeAppOpAccessMessage extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genConstructor=false)")*/
     @Deprecated
     private void __metadata() {}
 
diff --git a/core/java/android/app/SyncNotedAppOp.java b/core/java/android/app/SyncNotedAppOp.java
index 13b90ca..0a880dc 100644
--- a/core/java/android/app/SyncNotedAppOp.java
+++ b/core/java/android/app/SyncNotedAppOp.java
@@ -43,24 +43,24 @@
 
     /** op code of synchronous appop noted */
     private final @IntRange(from = 0L, to = AppOpsManager._NUM_OP - 1) int mOpCode;
-    /** featureId of synchronous appop noted */
-    private final @Nullable String mFeatureId;
+    /** attributionTag of synchronous appop noted */
+    private final @Nullable String mAttributionTag;
 
     /**
      * Creates a new SyncNotedAppOp.
      *
      * @param opCode
      *   op code of synchronous appop noted
-     * @param featureId
-     *   featureId of synchronous appop noted
+     * @param attributionTag
+     *   attributionTag of synchronous appop noted
      */
-    public SyncNotedAppOp(@IntRange(from = 0L) int opCode, @Nullable String featureId) {
+    public SyncNotedAppOp(@IntRange(from = 0L) int opCode, @Nullable String attributionTag) {
         this.mOpCode = opCode;
         com.android.internal.util.AnnotationValidations.validate(
                 IntRange.class, null, mOpCode,
                 "from", 0,
                 "to", AppOpsManager._NUM_OP - 1);
-        this.mFeatureId = featureId;
+        this.mAttributionTag = attributionTag;
     }
 
     /**
@@ -84,11 +84,11 @@
 
 
     /**
-     * featureId of synchronous appop noted
+     * attributionTag of synchronous appop noted
      */
     @DataClass.Generated.Member
-    public @Nullable String getFeatureId() {
-        return mFeatureId;
+    public @Nullable String getAttributionTag() {
+        return mAttributionTag;
     }
 
     @Override
@@ -105,7 +105,7 @@
         //noinspection PointlessBooleanExpression
         return true
                 && mOpCode == that.mOpCode
-                && java.util.Objects.equals(mFeatureId, that.mFeatureId);
+                && java.util.Objects.equals(mAttributionTag, that.mAttributionTag);
     }
 
     @Override
@@ -116,7 +116,7 @@
 
         int _hash = 1;
         _hash = 31 * _hash + mOpCode;
-        _hash = 31 * _hash + java.util.Objects.hashCode(mFeatureId);
+        _hash = 31 * _hash + java.util.Objects.hashCode(mAttributionTag);
         return _hash;
     }
 
@@ -127,10 +127,10 @@
         // void parcelFieldName(Parcel dest, int flags) { ... }
 
         byte flg = 0;
-        if (mFeatureId != null) flg |= 0x2;
+        if (mAttributionTag != null) flg |= 0x2;
         dest.writeByte(flg);
         dest.writeInt(mOpCode);
-        if (mFeatureId != null) dest.writeString(mFeatureId);
+        if (mAttributionTag != null) dest.writeString(mAttributionTag);
     }
 
     @Override
@@ -146,14 +146,14 @@
 
         byte flg = in.readByte();
         int opCode = in.readInt();
-        String featureId = (flg & 0x2) == 0 ? null : in.readString();
+        String attributionTag = (flg & 0x2) == 0 ? null : in.readString();
 
         this.mOpCode = opCode;
         com.android.internal.util.AnnotationValidations.validate(
                 IntRange.class, null, mOpCode,
                 "from", 0,
                 "to", AppOpsManager._NUM_OP - 1);
-        this.mFeatureId = featureId;
+        this.mAttributionTag = attributionTag;
 
         // onConstructed(); // You can define this method to get a callback
     }
@@ -176,7 +176,7 @@
             time = 1579188889960L,
             codegenVersion = "1.0.14",
             sourceFile = "frameworks/base/core/java/android/app/SyncNotedAppOp.java",
-            inputSignatures = "private final @android.annotation.IntRange(from=0L, to=AppOpsManager._NUM_OP - 1) int mOpCode\nprivate final @android.annotation.Nullable java.lang.String mFeatureId\npublic @android.annotation.NonNull java.lang.String getOp()\npublic @android.annotation.SystemApi int getOpCode()\nclass SyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genConstructor=false)")*/
+            inputSignatures = "private final @android.annotation.IntRange(from=0L, to=AppOpsManager._NUM_OP - 1) int mOpCode\nprivate final @android.annotation.Nullable java.lang.String mAttributionTag\npublic @android.annotation.NonNull java.lang.String getOp()\npublic @android.annotation.SystemApi int getOpCode()\nclass SyncNotedAppOp extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genConstructor=false)")*/
     @Deprecated
     private void __metadata() {}
 
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 345eaae..1b1568a 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -478,7 +478,7 @@
             try {
                 Bundle params = new Bundle();
                 ParcelFileDescriptor pfd = mService.getWallpaperWithFeature(
-                        context.getOpPackageName(), context.getFeatureId(), this, FLAG_SYSTEM,
+                        context.getOpPackageName(), context.getAttributionTag(), this, FLAG_SYSTEM,
                         params, userId);
 
                 if (pfd != null) {
@@ -1069,7 +1069,7 @@
             try {
                 Bundle outParams = new Bundle();
                 return sGlobals.mService.getWallpaperWithFeature(mContext.getOpPackageName(),
-                        mContext.getFeatureId(), null, which, outParams, userId);
+                        mContext.getAttributionTag(), null, which, outParams, userId);
             } catch (RemoteException e) {
                 throw e.rethrowFromSystemServer();
             } catch (SecurityException e) {
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index c532279..347648a 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -6001,7 +6001,7 @@
      * @param admin Which {@link DeviceAdminReceiver} this request is associated with.
      * @param required Whether auto time is set required or not.
      * @throws SecurityException if {@code admin} is not a device owner.
-     * @deprecated From {@link android.os.Build.VERSION_CODES#R}. Use {@link #setAutoTime}
+     * @deprecated From {@link android.os.Build.VERSION_CODES#R}. Use {@link #setAutoTimeEnabled}
      * to turn auto time on or off and use {@link UserManager#DISALLOW_CONFIG_DATE_TIME}
      * to prevent the user from changing this setting.
      */
@@ -6019,7 +6019,7 @@
 
     /**
      * @return true if auto time is required.
-     * @deprecated From {@link android.os.Build.VERSION_CODES#R}. Use {@link #getAutoTime}
+     * @deprecated From {@link android.os.Build.VERSION_CODES#R}. Use {@link #getAutoTimeEnabled}
      */
     @Deprecated
     public boolean getAutoTimeRequired() {
@@ -6049,10 +6049,10 @@
      * @throws SecurityException if caller is not a device owner, a profile owner for the
      * primary user, or a profile owner of an organization-owned managed profile.
      */
-    public void setAutoTime(@NonNull ComponentName admin, boolean enabled) {
+    public void setAutoTimeEnabled(@NonNull ComponentName admin, boolean enabled) {
         if (mService != null) {
             try {
-                mService.setAutoTime(admin, enabled);
+                mService.setAutoTimeEnabled(admin, enabled);
             } catch (RemoteException e) {
                 throw e.rethrowFromSystemServer();
             }
@@ -6064,10 +6064,10 @@
      * @throws SecurityException if caller is not a device owner, a profile owner for the
      * primary user, or a profile owner of an organization-owned managed profile.
      */
-    public boolean getAutoTime(@NonNull ComponentName admin) {
+    public boolean getAutoTimeEnabled(@NonNull ComponentName admin) {
         if (mService != null) {
             try {
-                return mService.getAutoTime(admin);
+                return mService.getAutoTimeEnabled(admin);
             } catch (RemoteException e) {
                 throw e.rethrowFromSystemServer();
             }
@@ -6090,11 +6090,11 @@
      * @throws SecurityException if caller is not a device owner, a profile owner for the
      * primary user, or a profile owner of an organization-owned managed profile.
      */
-    public void setAutoTimeZone(@NonNull ComponentName admin, boolean enabled) {
+    public void setAutoTimeZoneEnabled(@NonNull ComponentName admin, boolean enabled) {
         throwIfParentInstance("setAutoTimeZone");
         if (mService != null) {
             try {
-                mService.setAutoTimeZone(admin, enabled);
+                mService.setAutoTimeZoneEnabled(admin, enabled);
             } catch (RemoteException e) {
                 throw e.rethrowFromSystemServer();
             }
@@ -6106,11 +6106,11 @@
      * @throws SecurityException if caller is not a device owner, a profile owner for the
      * primary user, or a profile owner of an organization-owned managed profile.
      */
-    public boolean getAutoTimeZone(@NonNull ComponentName admin) {
+    public boolean getAutoTimeZoneEnabled(@NonNull ComponentName admin) {
         throwIfParentInstance("getAutoTimeZone");
         if (mService != null) {
             try {
-                return mService.getAutoTimeZone(admin);
+                return mService.getAutoTimeZoneEnabled(admin);
             } catch (RemoteException e) {
                 throw e.rethrowFromSystemServer();
             }
@@ -8804,10 +8804,11 @@
      * <p>
      * The following settings used to be supported, but can be controlled in other ways:
      * <ul>
-     * <li>{@link android.provider.Settings.Global#AUTO_TIME} : Use {@link #setAutoTime} and
+     * <li>{@link android.provider.Settings.Global#AUTO_TIME} : Use {@link #setAutoTimeEnabled} and
      * {@link UserManager#DISALLOW_CONFIG_DATE_TIME} instead.</li>
-     * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE} : Use {@link #setAutoTimeZone}
-     * and {@link UserManager#DISALLOW_CONFIG_DATE_TIME} instead.</li>
+     * <li>{@link android.provider.Settings.Global#AUTO_TIME_ZONE} : Use
+     * {@link #setAutoTimeZoneEnabled} and {@link UserManager#DISALLOW_CONFIG_DATE_TIME}
+     * instead.</li>
      * <li>{@link android.provider.Settings.Global#DATA_ROAMING} : Use
      * {@link UserManager#DISALLOW_DATA_ROAMING} instead.</li>
      * </ul>
@@ -11984,17 +11985,17 @@
      * must handle this intent.
      *
      * @param admin Which {@link DeviceAdminReceiver} this request is associated with
-     * @param timeoutMs Maximum time the profile is allowed to be off in milliseconds or 0 if
+     * @param timeoutMillis Maximum time the profile is allowed to be off in milliseconds or 0 if
      *        not limited.
      * @throws IllegalStateException if the profile owner doesn't have an activity that handles
      *        {@link #ACTION_CHECK_POLICY_COMPLIANCE}
      * @see #setPersonalAppsSuspended
      */
-    public void setManagedProfileMaximumTimeOff(@NonNull ComponentName admin, long timeoutMs) {
+    public void setManagedProfileMaximumTimeOff(@NonNull ComponentName admin, long timeoutMillis) {
         throwIfParentInstance("setManagedProfileMaximumTimeOff");
         if (mService != null) {
             try {
-                mService.setManagedProfileMaximumTimeOff(admin, timeoutMs);
+                mService.setManagedProfileMaximumTimeOff(admin, timeoutMillis);
             } catch (RemoteException re) {
                 throw re.rethrowFromSystemServer();
             }
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index da48663..f071239 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -308,11 +308,11 @@
     void setAutoTimeRequired(in ComponentName who, boolean required);
     boolean getAutoTimeRequired();
 
-    void setAutoTime(in ComponentName who, boolean enabled);
-    boolean getAutoTime(in ComponentName who);
+    void setAutoTimeEnabled(in ComponentName who, boolean enabled);
+    boolean getAutoTimeEnabled(in ComponentName who);
 
-    void setAutoTimeZone(in ComponentName who, boolean enabled);
-    boolean getAutoTimeZone(in ComponentName who);
+    void setAutoTimeZoneEnabled(in ComponentName who, boolean enabled);
+    boolean getAutoTimeZoneEnabled(in ComponentName who);
 
     void setForceEphemeralUsers(in ComponentName who, boolean forceEpehemeralUsers);
     boolean getForceEphemeralUsers(in ComponentName who);
diff --git a/core/java/android/app/role/RoleManager.java b/core/java/android/app/role/RoleManager.java
index db4f1de..917eeb8 100644
--- a/core/java/android/app/role/RoleManager.java
+++ b/core/java/android/app/role/RoleManager.java
@@ -636,7 +636,6 @@
      * @hide
      */
     @Nullable
-    @SystemApi
     public String getDefaultSmsPackage(@UserIdInt int userId) {
         try {
             return mService.getDefaultSmsPackage(userId);
diff --git a/core/java/android/bluetooth/BluetoothAdapter.java b/core/java/android/bluetooth/BluetoothAdapter.java
index 6ae68fc..608b563 100644
--- a/core/java/android/bluetooth/BluetoothAdapter.java
+++ b/core/java/android/bluetooth/BluetoothAdapter.java
@@ -849,7 +849,7 @@
         synchronized (mLock) {
             if (sBluetoothLeScanner == null) {
                 sBluetoothLeScanner = new BluetoothLeScanner(mManagerService, getOpPackageName(),
-                        getFeatureId());
+                        getAttributionTag());
             }
         }
         return sBluetoothLeScanner;
@@ -1663,11 +1663,11 @@
         return ActivityThread.currentOpPackageName();
     }
 
-    private String getFeatureId() {
+    private String getAttributionTag() {
         // Workaround for legacy API for getting a BluetoothAdapter not
         // passing a context
         if (mContext != null) {
-            return mContext.getFeatureId();
+            return mContext.getAttributionTag();
         }
         return null;
     }
@@ -1709,7 +1709,7 @@
         try {
             mServiceLock.readLock().lock();
             if (mService != null) {
-                return mService.startDiscovery(getOpPackageName(), getFeatureId());
+                return mService.startDiscovery(getOpPackageName(), getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "", e);
diff --git a/core/java/android/bluetooth/BluetoothManager.java b/core/java/android/bluetooth/BluetoothManager.java
index 7ff6466..3b4fe0a 100644
--- a/core/java/android/bluetooth/BluetoothManager.java
+++ b/core/java/android/bluetooth/BluetoothManager.java
@@ -62,7 +62,7 @@
      * @hide
      */
     public BluetoothManager(Context context) {
-        if (context.getFeatureId() == null) {
+        if (context.getAttributionTag() == null) {
             context = context.getApplicationContext();
             if (context == null) {
                 throw new IllegalArgumentException(
diff --git a/core/java/android/content/ContentProvider.java b/core/java/android/content/ContentProvider.java
index bd3298c..d8e8b27 100644
--- a/core/java/android/content/ContentProvider.java
+++ b/core/java/android/content/ContentProvider.java
@@ -230,12 +230,12 @@
         }
 
         @Override
-        public Cursor query(String callingPkg, @Nullable String featureId, Uri uri,
+        public Cursor query(String callingPkg, @Nullable String attributionTag, Uri uri,
                 @Nullable String[] projection, @Nullable Bundle queryArgs,
                 @Nullable ICancellationSignal cancellationSignal) {
             uri = validateIncomingUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
-            if (enforceReadPermission(callingPkg, featureId, uri, null)
+            if (enforceReadPermission(callingPkg, attributionTag, uri, null)
                     != AppOpsManager.MODE_ALLOWED) {
                 // The caller has no access to the data, so return an empty cursor with
                 // the columns in the requested order. The caller may ask for an invalid
@@ -253,7 +253,7 @@
                 // columns. We then use the column names to return an empty cursor.
                 Cursor cursor;
                 final Pair<String, String> original = setCallingPackage(
-                        new Pair<>(callingPkg, featureId));
+                        new Pair<>(callingPkg, attributionTag));
                 try {
                     cursor = mInterface.query(
                             uri, projection, queryArgs,
@@ -272,7 +272,7 @@
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "query");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.query(
                         uri, projection, queryArgs,
@@ -308,15 +308,15 @@
         }
 
         @Override
-        public Uri insert(String callingPkg, @Nullable String featureId, Uri uri,
+        public Uri insert(String callingPkg, @Nullable String attributionTag, Uri uri,
                 ContentValues initialValues, Bundle extras) {
             uri = validateIncomingUri(uri);
             int userId = getUserIdFromUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
-            if (enforceWritePermission(callingPkg, featureId, uri, null)
+            if (enforceWritePermission(callingPkg, attributionTag, uri, null)
                     != AppOpsManager.MODE_ALLOWED) {
                 final Pair<String, String> original = setCallingPackage(
-                        new Pair<>(callingPkg, featureId));
+                        new Pair<>(callingPkg, attributionTag));
                 try {
                     return rejectInsert(uri, initialValues);
                 } finally {
@@ -325,7 +325,7 @@
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "insert");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return maybeAddUserId(mInterface.insert(uri, initialValues, extras), userId);
             } catch (RemoteException e) {
@@ -337,17 +337,17 @@
         }
 
         @Override
-        public int bulkInsert(String callingPkg, @Nullable String featureId, Uri uri,
+        public int bulkInsert(String callingPkg, @Nullable String attributionTag, Uri uri,
                 ContentValues[] initialValues) {
             uri = validateIncomingUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
-            if (enforceWritePermission(callingPkg, featureId, uri, null)
+            if (enforceWritePermission(callingPkg, attributionTag, uri, null)
                     != AppOpsManager.MODE_ALLOWED) {
                 return 0;
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "bulkInsert");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.bulkInsert(uri, initialValues);
             } catch (RemoteException e) {
@@ -359,8 +359,9 @@
         }
 
         @Override
-        public ContentProviderResult[] applyBatch(String callingPkg, @Nullable String featureId,
-                String authority, ArrayList<ContentProviderOperation> operations)
+        public ContentProviderResult[] applyBatch(String callingPkg,
+                @Nullable String attributionTag, String authority,
+                ArrayList<ContentProviderOperation> operations)
                 throws OperationApplicationException {
             validateIncomingAuthority(authority);
             int numOperations = operations.size();
@@ -377,13 +378,13 @@
                     operations.set(i, operation);
                 }
                 if (operation.isReadOperation()) {
-                    if (enforceReadPermission(callingPkg, featureId, uri, null)
+                    if (enforceReadPermission(callingPkg, attributionTag, uri, null)
                             != AppOpsManager.MODE_ALLOWED) {
                         throw new OperationApplicationException("App op not allowed", 0);
                     }
                 }
                 if (operation.isWriteOperation()) {
-                    if (enforceWritePermission(callingPkg, featureId, uri, null)
+                    if (enforceWritePermission(callingPkg, attributionTag, uri, null)
                             != AppOpsManager.MODE_ALLOWED) {
                         throw new OperationApplicationException("App op not allowed", 0);
                     }
@@ -391,7 +392,7 @@
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "applyBatch");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 ContentProviderResult[] results = mInterface.applyBatch(authority,
                         operations);
@@ -413,16 +414,17 @@
         }
 
         @Override
-        public int delete(String callingPkg, @Nullable String featureId, Uri uri, Bundle extras) {
+        public int delete(String callingPkg, @Nullable String attributionTag, Uri uri,
+                Bundle extras) {
             uri = validateIncomingUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
-            if (enforceWritePermission(callingPkg, featureId, uri, null)
+            if (enforceWritePermission(callingPkg, attributionTag, uri, null)
                     != AppOpsManager.MODE_ALLOWED) {
                 return 0;
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "delete");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.delete(uri, extras);
             } catch (RemoteException e) {
@@ -434,17 +436,17 @@
         }
 
         @Override
-        public int update(String callingPkg, @Nullable String featureId, Uri uri,
+        public int update(String callingPkg, @Nullable String attributionTag, Uri uri,
                 ContentValues values, Bundle extras) {
             uri = validateIncomingUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
-            if (enforceWritePermission(callingPkg, featureId, uri, null)
+            if (enforceWritePermission(callingPkg, attributionTag, uri, null)
                     != AppOpsManager.MODE_ALLOWED) {
                 return 0;
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "update");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.update(uri, values, extras);
             } catch (RemoteException e) {
@@ -456,15 +458,15 @@
         }
 
         @Override
-        public ParcelFileDescriptor openFile(String callingPkg, @Nullable String featureId,
+        public ParcelFileDescriptor openFile(String callingPkg, @Nullable String attributionTag,
                 Uri uri, String mode, ICancellationSignal cancellationSignal, IBinder callerToken)
                 throws FileNotFoundException {
             uri = validateIncomingUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
-            enforceFilePermission(callingPkg, featureId, uri, mode, callerToken);
+            enforceFilePermission(callingPkg, attributionTag, uri, mode, callerToken);
             Trace.traceBegin(TRACE_TAG_DATABASE, "openFile");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.openFile(
                         uri, mode, CancellationSignal.fromTransport(cancellationSignal));
@@ -477,15 +479,15 @@
         }
 
         @Override
-        public AssetFileDescriptor openAssetFile(String callingPkg, @Nullable String featureId,
+        public AssetFileDescriptor openAssetFile(String callingPkg, @Nullable String attributionTag,
                 Uri uri, String mode, ICancellationSignal cancellationSignal)
                 throws FileNotFoundException {
             uri = validateIncomingUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
-            enforceFilePermission(callingPkg, featureId, uri, mode, null);
+            enforceFilePermission(callingPkg, attributionTag, uri, mode, null);
             Trace.traceBegin(TRACE_TAG_DATABASE, "openAssetFile");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.openAssetFile(
                         uri, mode, CancellationSignal.fromTransport(cancellationSignal));
@@ -498,13 +500,13 @@
         }
 
         @Override
-        public Bundle call(String callingPkg, @Nullable String featureId, String authority,
+        public Bundle call(String callingPkg, @Nullable String attributionTag, String authority,
                 String method, @Nullable String arg, @Nullable Bundle extras) {
             validateIncomingAuthority(authority);
             Bundle.setDefusable(extras, true);
             Trace.traceBegin(TRACE_TAG_DATABASE, "call");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.call(authority, method, arg, extras);
             } catch (RemoteException e) {
@@ -532,15 +534,15 @@
 
         @Override
         public AssetFileDescriptor openTypedAssetFile(String callingPkg,
-                @Nullable String featureId, Uri uri, String mimeType, Bundle opts,
+                @Nullable String attributionTag, Uri uri, String mimeType, Bundle opts,
                 ICancellationSignal cancellationSignal) throws FileNotFoundException {
             Bundle.setDefusable(opts, true);
             uri = validateIncomingUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
-            enforceFilePermission(callingPkg, featureId, uri, "r", null);
+            enforceFilePermission(callingPkg, attributionTag, uri, "r", null);
             Trace.traceBegin(TRACE_TAG_DATABASE, "openTypedAssetFile");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.openTypedAssetFile(
                         uri, mimeType, opts, CancellationSignal.fromTransport(cancellationSignal));
@@ -558,17 +560,17 @@
         }
 
         @Override
-        public Uri canonicalize(String callingPkg, @Nullable String featureId, Uri uri) {
+        public Uri canonicalize(String callingPkg, @Nullable String attributionTag, Uri uri) {
             uri = validateIncomingUri(uri);
             int userId = getUserIdFromUri(uri);
             uri = getUriWithoutUserId(uri);
-            if (enforceReadPermission(callingPkg, featureId, uri, null)
+            if (enforceReadPermission(callingPkg, attributionTag, uri, null)
                     != AppOpsManager.MODE_ALLOWED) {
                 return null;
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "canonicalize");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return maybeAddUserId(mInterface.canonicalize(uri), userId);
             } catch (RemoteException e) {
@@ -580,26 +582,26 @@
         }
 
         @Override
-        public void canonicalizeAsync(String callingPkg, @Nullable String featureId, Uri uri,
+        public void canonicalizeAsync(String callingPkg, @Nullable String attributionTag, Uri uri,
                 RemoteCallback callback) {
             final Bundle result = new Bundle();
             result.putParcelable(ContentResolver.REMOTE_CALLBACK_RESULT,
-                    canonicalize(callingPkg, featureId, uri));
+                    canonicalize(callingPkg, attributionTag, uri));
             callback.sendResult(result);
         }
 
         @Override
-        public Uri uncanonicalize(String callingPkg, String featureId,  Uri uri) {
+        public Uri uncanonicalize(String callingPkg, String attributionTag,  Uri uri) {
             uri = validateIncomingUri(uri);
             int userId = getUserIdFromUri(uri);
             uri = getUriWithoutUserId(uri);
-            if (enforceReadPermission(callingPkg, featureId, uri, null)
+            if (enforceReadPermission(callingPkg, attributionTag, uri, null)
                     != AppOpsManager.MODE_ALLOWED) {
                 return null;
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "uncanonicalize");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return maybeAddUserId(mInterface.uncanonicalize(uri), userId);
             } catch (RemoteException e) {
@@ -611,17 +613,17 @@
         }
 
         @Override
-        public boolean refresh(String callingPkg, String featureId, Uri uri, Bundle extras,
+        public boolean refresh(String callingPkg, String attributionTag, Uri uri, Bundle extras,
                 ICancellationSignal cancellationSignal) throws RemoteException {
             uri = validateIncomingUri(uri);
             uri = getUriWithoutUserId(uri);
-            if (enforceReadPermission(callingPkg, featureId, uri, null)
+            if (enforceReadPermission(callingPkg, attributionTag, uri, null)
                     != AppOpsManager.MODE_ALLOWED) {
                 return false;
             }
             Trace.traceBegin(TRACE_TAG_DATABASE, "refresh");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.refresh(uri, extras,
                         CancellationSignal.fromTransport(cancellationSignal));
@@ -632,13 +634,13 @@
         }
 
         @Override
-        public int checkUriPermission(String callingPkg, @Nullable String featureId, Uri uri,
+        public int checkUriPermission(String callingPkg, @Nullable String attributionTag, Uri uri,
                 int uid, int modeFlags) {
             uri = validateIncomingUri(uri);
             uri = maybeGetUriWithoutUserId(uri);
             Trace.traceBegin(TRACE_TAG_DATABASE, "checkUriPermission");
             final Pair<String, String> original = setCallingPackage(
-                    new Pair<>(callingPkg, featureId));
+                    new Pair<>(callingPkg, attributionTag));
             try {
                 return mInterface.checkUriPermission(uri, uid, modeFlags);
             } catch (RemoteException e) {
@@ -649,47 +651,50 @@
             }
         }
 
-        private void enforceFilePermission(String callingPkg, @Nullable String featureId, Uri uri,
-                String mode, IBinder callerToken) throws FileNotFoundException, SecurityException {
+        private void enforceFilePermission(String callingPkg, @Nullable String attributionTag,
+                Uri uri, String mode, IBinder callerToken)
+                throws FileNotFoundException, SecurityException {
             if (mode != null && mode.indexOf('w') != -1) {
-                if (enforceWritePermission(callingPkg, featureId, uri, callerToken)
+                if (enforceWritePermission(callingPkg, attributionTag, uri, callerToken)
                         != AppOpsManager.MODE_ALLOWED) {
                     throw new FileNotFoundException("App op not allowed");
                 }
             } else {
-                if (enforceReadPermission(callingPkg, featureId, uri, callerToken)
+                if (enforceReadPermission(callingPkg, attributionTag, uri, callerToken)
                         != AppOpsManager.MODE_ALLOWED) {
                     throw new FileNotFoundException("App op not allowed");
                 }
             }
         }
 
-        private int enforceReadPermission(String callingPkg, @Nullable String featureId, Uri uri,
-                IBinder callerToken)
+        private int enforceReadPermission(String callingPkg, @Nullable String attributionTag,
+                Uri uri, IBinder callerToken)
                 throws SecurityException {
-            final int mode = enforceReadPermissionInner(uri, callingPkg, featureId, callerToken);
+            final int mode = enforceReadPermissionInner(uri, callingPkg, attributionTag,
+                    callerToken);
             if (mode != MODE_ALLOWED) {
                 return mode;
             }
 
-            return noteProxyOp(callingPkg, featureId, mReadOp);
+            return noteProxyOp(callingPkg, attributionTag, mReadOp);
         }
 
-        private int enforceWritePermission(String callingPkg, String featureId, Uri uri,
+        private int enforceWritePermission(String callingPkg, String attributionTag, Uri uri,
                 IBinder callerToken)
                 throws SecurityException {
-            final int mode = enforceWritePermissionInner(uri, callingPkg, featureId, callerToken);
+            final int mode = enforceWritePermissionInner(uri, callingPkg, attributionTag,
+                    callerToken);
             if (mode != MODE_ALLOWED) {
                 return mode;
             }
 
-            return noteProxyOp(callingPkg, featureId, mWriteOp);
+            return noteProxyOp(callingPkg, attributionTag, mWriteOp);
         }
 
-        private int noteProxyOp(String callingPkg, String featureId, int op) {
+        private int noteProxyOp(String callingPkg, String attributionTag, int op) {
             if (op != AppOpsManager.OP_NONE) {
                 int mode = mAppOpsManager.noteProxyOp(op, callingPkg, Binder.getCallingUid(),
-                        featureId, null);
+                        attributionTag, null);
                 return mode == MODE_DEFAULT ? MODE_IGNORED : mode;
             }
 
@@ -711,19 +716,19 @@
      * associated with that permission.
      */
     private int checkPermissionAndAppOp(String permission, String callingPkg,
-            @Nullable String featureId, IBinder callerToken) {
+            @Nullable String attributionTag, IBinder callerToken) {
         if (getContext().checkPermission(permission, Binder.getCallingPid(), Binder.getCallingUid(),
                 callerToken) != PERMISSION_GRANTED) {
             return MODE_ERRORED;
         }
 
-        return mTransport.noteProxyOp(callingPkg, featureId,
+        return mTransport.noteProxyOp(callingPkg, attributionTag,
                 AppOpsManager.permissionToOpCode(permission));
     }
 
     /** {@hide} */
     protected int enforceReadPermissionInner(Uri uri, String callingPkg,
-            @Nullable String featureId, IBinder callerToken) throws SecurityException {
+            @Nullable String attributionTag, IBinder callerToken) throws SecurityException {
         final Context context = getContext();
         final int pid = Binder.getCallingPid();
         final int uid = Binder.getCallingUid();
@@ -737,7 +742,7 @@
         if (mExported && checkUser(pid, uid, context)) {
             final String componentPerm = getReadPermission();
             if (componentPerm != null) {
-                final int mode = checkPermissionAndAppOp(componentPerm, callingPkg, featureId,
+                final int mode = checkPermissionAndAppOp(componentPerm, callingPkg, attributionTag,
                         callerToken);
                 if (mode == MODE_ALLOWED) {
                     return MODE_ALLOWED;
@@ -757,8 +762,8 @@
                 for (PathPermission pp : pps) {
                     final String pathPerm = pp.getReadPermission();
                     if (pathPerm != null && pp.match(path)) {
-                        final int mode = checkPermissionAndAppOp(pathPerm, callingPkg, featureId,
-                                callerToken);
+                        final int mode = checkPermissionAndAppOp(pathPerm, callingPkg,
+                                attributionTag, callerToken);
                         if (mode == MODE_ALLOWED) {
                             return MODE_ALLOWED;
                         } else {
@@ -807,7 +812,7 @@
 
     /** {@hide} */
     protected int enforceWritePermissionInner(Uri uri, String callingPkg,
-            @Nullable String featureId, IBinder callerToken) throws SecurityException {
+            @Nullable String attributionTag, IBinder callerToken) throws SecurityException {
         final Context context = getContext();
         final int pid = Binder.getCallingPid();
         final int uid = Binder.getCallingUid();
@@ -821,8 +826,8 @@
         if (mExported && checkUser(pid, uid, context)) {
             final String componentPerm = getWritePermission();
             if (componentPerm != null) {
-                final int mode = checkPermissionAndAppOp(componentPerm, callingPkg, featureId,
-                        callerToken);
+                final int mode = checkPermissionAndAppOp(componentPerm, callingPkg,
+                        attributionTag, callerToken);
                 if (mode == MODE_ALLOWED) {
                     return MODE_ALLOWED;
                 } else {
@@ -841,8 +846,8 @@
                 for (PathPermission pp : pps) {
                     final String pathPerm = pp.getWritePermission();
                     if (pathPerm != null && pp.match(path)) {
-                        final int mode = checkPermissionAndAppOp(pathPerm, callingPkg, featureId,
-                                callerToken);
+                        final int mode = checkPermissionAndAppOp(pathPerm, callingPkg,
+                                attributionTag, callerToken);
                         if (mode == MODE_ALLOWED) {
                             return MODE_ALLOWED;
                         } else {
@@ -943,16 +948,16 @@
     }
 
     /**
-     * Return the feature in the package of the caller that initiated the request being
+     * Return the attribution tag of the caller that initiated the request being
      * processed on the current thread. Returns {@code null} if not currently processing
-     * a request of the request is for the default feature.
+     * a request of the request is for the default attribution.
      * <p>
      * This will always return {@code null} when processing
      * {@link #getType(Uri)} or {@link #getStreamTypes(Uri, String)} requests.
      *
      * @see #getCallingPackage
      */
-    public final @Nullable String getCallingFeatureId() {
+    public final @Nullable String getCallingAttributionTag() {
         final Pair<String, String> pkg = mCallingPackage.get();
         if (pkg != null) {
             return pkg.second;
@@ -962,6 +967,14 @@
     }
 
     /**
+     * @removed
+     */
+    @Deprecated
+    public final @Nullable String getCallingFeatureId() {
+        return getCallingAttributionTag();
+    }
+
+    /**
      * Return the package name of the caller that initiated the request being
      * processed on the current thread. The returned package will have
      * <em>not</em> been verified to belong to the calling UID. Returns
diff --git a/core/java/android/content/ContentProviderClient.java b/core/java/android/content/ContentProviderClient.java
index a9b7862..d0f5ec4 100644
--- a/core/java/android/content/ContentProviderClient.java
+++ b/core/java/android/content/ContentProviderClient.java
@@ -80,7 +80,7 @@
     private final IContentProvider mContentProvider;
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023)
     private final String mPackageName;
-    private final @Nullable String mFeatureId;
+    private final @Nullable String mAttributionTag;
     private final String mAuthority;
     private final boolean mStable;
 
@@ -104,7 +104,7 @@
         mContentResolver = contentResolver;
         mContentProvider = contentProvider;
         mPackageName = contentResolver.mPackageName;
-        mFeatureId = contentResolver.mFeatureId;
+        mAttributionTag = contentResolver.mAttributionTag;
 
         mAuthority = authority;
         mStable = stable;
@@ -195,7 +195,8 @@
                 cancellationSignal.setRemote(remoteCancellationSignal);
             }
             final Cursor cursor = mContentProvider.query(
-                    mPackageName, mFeatureId, uri, projection, queryArgs, remoteCancellationSignal);
+                    mPackageName, mAttributionTag, uri, projection, queryArgs,
+                    remoteCancellationSignal);
             if (cursor == null) {
                 return null;
             }
@@ -255,7 +256,7 @@
 
         beforeRemote();
         try {
-            return mContentProvider.canonicalize(mPackageName, mFeatureId, url);
+            return mContentProvider.canonicalize(mPackageName, mAttributionTag, url);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -273,7 +274,7 @@
 
         beforeRemote();
         try {
-            return mContentProvider.uncanonicalize(mPackageName, mFeatureId, url);
+            return mContentProvider.uncanonicalize(mPackageName, mAttributionTag, url);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -298,7 +299,7 @@
                 remoteCancellationSignal = mContentProvider.createCancellationSignal();
                 cancellationSignal.setRemote(remoteCancellationSignal);
             }
-            return mContentProvider.refresh(mPackageName, mFeatureId, url, extras,
+            return mContentProvider.refresh(mPackageName, mAttributionTag, url, extras,
                     remoteCancellationSignal);
         } catch (DeadObjectException e) {
             if (!mStable) {
@@ -318,7 +319,7 @@
 
         beforeRemote();
         try {
-            return mContentProvider.checkUriPermission(mPackageName, mFeatureId, uri, uid,
+            return mContentProvider.checkUriPermission(mPackageName, mAttributionTag, uri, uid,
                     modeFlags);
         } catch (DeadObjectException e) {
             if (!mStable) {
@@ -344,7 +345,8 @@
 
         beforeRemote();
         try {
-            return mContentProvider.insert(mPackageName, mFeatureId, url, initialValues, extras);
+            return mContentProvider.insert(mPackageName, mAttributionTag, url, initialValues,
+                    extras);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -364,7 +366,7 @@
 
         beforeRemote();
         try {
-            return mContentProvider.bulkInsert(mPackageName, mFeatureId, url, initialValues);
+            return mContentProvider.bulkInsert(mPackageName, mAttributionTag, url, initialValues);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -388,7 +390,7 @@
 
         beforeRemote();
         try {
-            return mContentProvider.delete(mPackageName, mFeatureId, url, extras);
+            return mContentProvider.delete(mPackageName, mAttributionTag, url, extras);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -413,7 +415,7 @@
 
         beforeRemote();
         try {
-            return mContentProvider.update(mPackageName, mFeatureId, url, values, extras);
+            return mContentProvider.update(mPackageName, mAttributionTag, url, values, extras);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -457,8 +459,8 @@
                 remoteSignal = mContentProvider.createCancellationSignal();
                 signal.setRemote(remoteSignal);
             }
-            return mContentProvider.openFile(mPackageName, mFeatureId, url, mode, remoteSignal,
-                    null);
+            return mContentProvider.openFile(mPackageName, mAttributionTag, url, mode,
+                    remoteSignal, null);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -502,7 +504,7 @@
                 remoteSignal = mContentProvider.createCancellationSignal();
                 signal.setRemote(remoteSignal);
             }
-            return mContentProvider.openAssetFile(mPackageName, mFeatureId, url, mode,
+            return mContentProvider.openAssetFile(mPackageName, mAttributionTag, url, mode,
                     remoteSignal);
         } catch (DeadObjectException e) {
             if (!mStable) {
@@ -544,7 +546,7 @@
                 signal.setRemote(remoteSignal);
             }
             return mContentProvider.openTypedAssetFile(
-                    mPackageName, mFeatureId, uri, mimeTypeFilter, opts, remoteSignal);
+                    mPackageName, mAttributionTag, uri, mimeTypeFilter, opts, remoteSignal);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -571,7 +573,8 @@
 
         beforeRemote();
         try {
-            return mContentProvider.applyBatch(mPackageName, mFeatureId, authority, operations);
+            return mContentProvider.applyBatch(mPackageName, mAttributionTag, authority,
+                    operations);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
@@ -597,7 +600,8 @@
 
         beforeRemote();
         try {
-            return mContentProvider.call(mPackageName, mFeatureId, authority, method, arg, extras);
+            return mContentProvider.call(mPackageName, mAttributionTag, authority, method, arg,
+                    extras);
         } catch (DeadObjectException e) {
             if (!mStable) {
                 mContentResolver.unstableProviderDied(mContentProvider);
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java
index 31e1fc8..b134c37 100644
--- a/core/java/android/content/ContentResolver.java
+++ b/core/java/android/content/ContentResolver.java
@@ -767,7 +767,7 @@
     public ContentResolver(@Nullable Context context, @Nullable ContentInterface wrapped) {
         mContext = context != null ? context : ActivityThread.currentApplication();
         mPackageName = mContext.getOpPackageName();
-        mFeatureId = mContext.getFeatureId();
+        mAttributionTag = mContext.getAttributionTag();
         mTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion;
         mWrapped = wrapped;
     }
@@ -1144,7 +1144,7 @@
                 cancellationSignal.setRemote(remoteCancellationSignal);
             }
             try {
-                qCursor = unstableProvider.query(mPackageName, mFeatureId, uri, projection,
+                qCursor = unstableProvider.query(mPackageName, mAttributionTag, uri, projection,
                         queryArgs, remoteCancellationSignal);
             } catch (DeadObjectException e) {
                 // The remote process has died...  but we only hold an unstable
@@ -1155,7 +1155,7 @@
                 if (stableProvider == null) {
                     return null;
                 }
-                qCursor = stableProvider.query(mPackageName, mFeatureId, uri, projection,
+                qCursor = stableProvider.query(mPackageName, mAttributionTag, uri, projection,
                         queryArgs, remoteCancellationSignal);
             }
             if (qCursor == null) {
@@ -1247,7 +1247,7 @@
 
         try {
             final UriResultListener resultListener = new UriResultListener();
-            provider.canonicalizeAsync(mPackageName, mFeatureId, url,
+            provider.canonicalizeAsync(mPackageName, mAttributionTag, url,
                     new RemoteCallback(resultListener));
             resultListener.waitForResult(CONTENT_PROVIDER_TIMEOUT_MILLIS);
             return resultListener.result;
@@ -1294,7 +1294,7 @@
         }
 
         try {
-            return provider.uncanonicalize(mPackageName, mFeatureId, url);
+            return provider.uncanonicalize(mPackageName, mAttributionTag, url);
         } catch (RemoteException e) {
             // Arbitrary and not worth documenting, as Activity
             // Manager will kill this process shortly anyway.
@@ -1346,7 +1346,7 @@
                 remoteCancellationSignal = provider.createCancellationSignal();
                 cancellationSignal.setRemote(remoteCancellationSignal);
             }
-            return provider.refresh(mPackageName, mFeatureId, url, extras,
+            return provider.refresh(mPackageName, mAttributionTag, url, extras,
                     remoteCancellationSignal);
         } catch (RemoteException e) {
             // Arbitrary and not worth documenting, as Activity
@@ -1748,7 +1748,8 @@
 
                     try {
                         fd = unstableProvider.openAssetFile(
-                                mPackageName, mFeatureId, uri, mode, remoteCancellationSignal);
+                                mPackageName, mAttributionTag, uri, mode,
+                                remoteCancellationSignal);
                         if (fd == null) {
                             // The provider will be released by the finally{} clause
                             return null;
@@ -1763,7 +1764,7 @@
                             throw new FileNotFoundException("No content provider: " + uri);
                         }
                         fd = stableProvider.openAssetFile(
-                                mPackageName, mFeatureId, uri, mode, remoteCancellationSignal);
+                                mPackageName, mAttributionTag, uri, mode, remoteCancellationSignal);
                         if (fd == null) {
                             // The provider will be released by the finally{} clause
                             return null;
@@ -1914,7 +1915,8 @@
 
             try {
                 fd = unstableProvider.openTypedAssetFile(
-                        mPackageName, mFeatureId, uri, mimeType, opts, remoteCancellationSignal);
+                        mPackageName, mAttributionTag, uri, mimeType, opts,
+                        remoteCancellationSignal);
                 if (fd == null) {
                     // The provider will be released by the finally{} clause
                     return null;
@@ -1929,7 +1931,8 @@
                     throw new FileNotFoundException("No content provider: " + uri);
                 }
                 fd = stableProvider.openTypedAssetFile(
-                        mPackageName, mFeatureId, uri, mimeType, opts, remoteCancellationSignal);
+                        mPackageName, mAttributionTag, uri, mimeType, opts,
+                        remoteCancellationSignal);
                 if (fd == null) {
                     // The provider will be released by the finally{} clause
                     return null;
@@ -2077,7 +2080,7 @@
         }
         try {
             long startTime = SystemClock.uptimeMillis();
-            Uri createdRow = provider.insert(mPackageName, mFeatureId, url, values, extras);
+            Uri createdRow = provider.insert(mPackageName, mAttributionTag, url, values, extras);
             long durationMillis = SystemClock.uptimeMillis() - startTime;
             maybeLogUpdateToEventLog(durationMillis, url, "insert", null /* where */);
             return createdRow;
@@ -2158,7 +2161,7 @@
         }
         try {
             long startTime = SystemClock.uptimeMillis();
-            int rowsCreated = provider.bulkInsert(mPackageName, mFeatureId, url, values);
+            int rowsCreated = provider.bulkInsert(mPackageName, mAttributionTag, url, values);
             long durationMillis = SystemClock.uptimeMillis() - startTime;
             maybeLogUpdateToEventLog(durationMillis, url, "bulkinsert", null /* where */);
             return rowsCreated;
@@ -2217,7 +2220,7 @@
         }
         try {
             long startTime = SystemClock.uptimeMillis();
-            int rowsDeleted = provider.delete(mPackageName, mFeatureId, url, extras);
+            int rowsDeleted = provider.delete(mPackageName, mAttributionTag, url, extras);
             long durationMillis = SystemClock.uptimeMillis() - startTime;
             maybeLogUpdateToEventLog(durationMillis, url, "delete", null);
             return rowsDeleted;
@@ -2284,7 +2287,7 @@
         }
         try {
             long startTime = SystemClock.uptimeMillis();
-            int rowsUpdated = provider.update(mPackageName, mFeatureId, uri, values, extras);
+            int rowsUpdated = provider.update(mPackageName, mAttributionTag, uri, values, extras);
             long durationMillis = SystemClock.uptimeMillis() - startTime;
             maybeLogUpdateToEventLog(durationMillis, uri, "update", null);
             return rowsUpdated;
@@ -2333,7 +2336,7 @@
             throw new IllegalArgumentException("Unknown authority " + authority);
         }
         try {
-            final Bundle res = provider.call(mPackageName, mFeatureId, authority, method, arg,
+            final Bundle res = provider.call(mPackageName, mAttributionTag, authority, method, arg,
                     extras);
             Bundle.setDefusable(res, true);
             return res;
@@ -3746,8 +3749,8 @@
     }
 
     /** @hide */
-    public @Nullable String getFeatureId() {
-        return mFeatureId;
+    public @Nullable String getAttributionTag() {
+        return mAttributionTag;
     }
 
     @UnsupportedAppUsage
@@ -3757,7 +3760,7 @@
 
     @UnsupportedAppUsage
     final String mPackageName;
-    final @Nullable String mFeatureId;
+    final @Nullable String mAttributionTag;
     final int mTargetSdkVersion;
     final ContentInterface mWrapped;
 
diff --git a/core/java/android/content/Context.java b/core/java/android/content/Context.java
index 5e9ed60..318ae11 100644
--- a/core/java/android/content/Context.java
+++ b/core/java/android/content/Context.java
@@ -815,16 +815,25 @@
     }
 
     /**
-     * <p>Features are used in complex apps to logically separate parts of the app. E.g. a
-     * blogging app might also have a instant messaging app built in.
+     * <p>Attribution can be used in complex apps to logically separate parts of the app. E.g. a
+     * blogging app might also have a instant messaging app built in. In this case two separate tags
+     * can for used each sub-feature.
      *
-     * @return the feature id this context is for or {@code null} if this is the default
-     * feature.
+     * @return the attribution tag this context is for or {@code null} if this is the default.
      */
-    public @Nullable String getFeatureId() {
+    public @Nullable String getAttributionTag() {
         return null;
     }
 
+    // TODO moltmann: Remove
+    /**
+     * @removed
+     */
+    @Deprecated
+    public @Nullable String getFeatureId() {
+        return getAttributionTag();
+    }
+
     /** Return the full application info for this context's package. */
     public abstract ApplicationInfo getApplicationInfo();
 
@@ -5826,19 +5835,29 @@
     }
 
     /**
-     * Return a new Context object for the current Context but for a different feature in the app.
-     * Features can be used by complex apps to separate logical parts.
+     * Return a new Context object for the current Context but attribute to a different tag.
+     * In complex apps attribution tagging can be used to distinguish between separate logical
+     * parts.
      *
-     * @param featureId The feature id or {@code null} to create a context for the default feature.
+     * @param attributionTag The tag or {@code null} to create a context for the default.
      *
-     * @return A {@link Context} for the feature
+     * @return A {@link Context} that is tagged for the new attribution
      *
-     * @see #getFeatureId()
+     * @see #getAttributionTag()
      */
-    public @NonNull Context createFeatureContext(@Nullable String featureId) {
+    public @NonNull Context createAttributionContext(@Nullable String attributionTag) {
         throw new RuntimeException("Not implemented. Must override in a subclass.");
     }
 
+    // TODO moltmann: remove
+    /**
+     * @removed
+     */
+    @Deprecated
+    public @NonNull Context createFeatureContext(@Nullable String featureId) {
+        return createAttributionContext(featureId);
+    }
+
     /**
      * Return a new Context object for the current Context but whose storage
      * APIs are backed by device-protected storage.
diff --git a/core/java/android/content/ContextWrapper.java b/core/java/android/content/ContextWrapper.java
index b7e04cf..d389d2a 100644
--- a/core/java/android/content/ContextWrapper.java
+++ b/core/java/android/content/ContextWrapper.java
@@ -164,8 +164,8 @@
 
     /** @hide */
     @Override
-    public @Nullable String getFeatureId() {
-        return mBase.getFeatureId();
+    public @Nullable String getAttributionTag() {
+        return mBase.getAttributionTag();
     }
 
     @Override
@@ -984,8 +984,8 @@
     }
 
     @Override
-    public @NonNull Context createFeatureContext(@Nullable String featureId) {
-        return mBase.createFeatureContext(featureId);
+    public @NonNull Context createAttributionContext(@Nullable String attributionTag) {
+        return mBase.createAttributionContext(attributionTag);
     }
 
     @Override
diff --git a/core/java/android/content/IContentProvider.java b/core/java/android/content/IContentProvider.java
index 37643da..84b0f0e 100644
--- a/core/java/android/content/IContentProvider.java
+++ b/core/java/android/content/IContentProvider.java
@@ -38,7 +38,7 @@
  * @hide
  */
 public interface IContentProvider extends IInterface {
-    public Cursor query(String callingPkg, @Nullable String featureId, Uri url,
+    public Cursor query(String callingPkg, @Nullable String attributionTag, Uri url,
             @Nullable String[] projection,
             @Nullable Bundle queryArgs, @Nullable ICancellationSignal cancellationSignal)
             throws RemoteException;
@@ -59,8 +59,8 @@
             throws RemoteException {
         return insert(callingPkg, null, url, initialValues, null);
     }
-    public Uri insert(String callingPkg, String featureId, Uri url, ContentValues initialValues,
-            Bundle extras) throws RemoteException;
+    public Uri insert(String callingPkg, String attributionTag, Uri url,
+            ContentValues initialValues, Bundle extras) throws RemoteException;
     @Deprecated
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link "
             + "ContentProviderClient#bulkInsert(android.net.Uri, android.content.ContentValues[])"
@@ -69,7 +69,7 @@
             throws RemoteException {
         return bulkInsert(callingPkg, null, url, initialValues);
     }
-    public int bulkInsert(String callingPkg, String featureId, Uri url,
+    public int bulkInsert(String callingPkg, String attributionTag, Uri url,
             ContentValues[] initialValues) throws RemoteException;
     @Deprecated
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link "
@@ -80,7 +80,7 @@
         return delete(callingPkg, null, url,
                 ContentResolver.createSqlQueryBundle(selection, selectionArgs));
     }
-    public int delete(String callingPkg, String featureId, Uri url, Bundle extras)
+    public int delete(String callingPkg, String attributionTag, Uri url, Bundle extras)
             throws RemoteException;
     @Deprecated
     @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.Q, publicAlternatives = "Use {@link "
@@ -91,18 +91,18 @@
         return update(callingPkg, null, url, values,
                 ContentResolver.createSqlQueryBundle(selection, selectionArgs));
     }
-    public int update(String callingPkg, String featureId, Uri url, ContentValues values,
+    public int update(String callingPkg, String attributionTag, Uri url, ContentValues values,
             Bundle extras) throws RemoteException;
 
-    public ParcelFileDescriptor openFile(String callingPkg, @Nullable String featureId, Uri url,
-            String mode, ICancellationSignal signal, IBinder callerToken)
+    public ParcelFileDescriptor openFile(String callingPkg, @Nullable String attributionTag,
+            Uri url, String mode, ICancellationSignal signal, IBinder callerToken)
             throws RemoteException, FileNotFoundException;
 
-    public AssetFileDescriptor openAssetFile(String callingPkg, @Nullable String featureId,
+    public AssetFileDescriptor openAssetFile(String callingPkg, @Nullable String attributionTag,
             Uri url, String mode, ICancellationSignal signal)
             throws RemoteException, FileNotFoundException;
 
-    public ContentProviderResult[] applyBatch(String callingPkg, @Nullable String featureId,
+    public ContentProviderResult[] applyBatch(String callingPkg, @Nullable String attributionTag,
             String authority, ArrayList<ContentProviderOperation> operations)
             throws RemoteException, OperationApplicationException;
 
@@ -115,15 +115,15 @@
         return call(callingPkg, null, "unknown", method, arg, extras);
     }
 
-    public Bundle call(String callingPkg, @Nullable String featureId, String authority,
+    public Bundle call(String callingPkg, @Nullable String attributionTag, String authority,
             String method, @Nullable String arg, @Nullable Bundle extras) throws RemoteException;
 
-    public int checkUriPermission(String callingPkg, @Nullable String featureId, Uri uri, int uid,
-            int modeFlags) throws RemoteException;
+    public int checkUriPermission(String callingPkg, @Nullable String attributionTag, Uri uri,
+            int uid, int modeFlags) throws RemoteException;
 
     public ICancellationSignal createCancellationSignal() throws RemoteException;
 
-    public Uri canonicalize(String callingPkg, @Nullable String featureId, Uri uri)
+    public Uri canonicalize(String callingPkg, @Nullable String attributionTag, Uri uri)
             throws RemoteException;
 
     /**
@@ -131,20 +131,21 @@
      * call returns immediately, and the resulting type is returned when available via
      * a binder callback.
      */
-    void canonicalizeAsync(String callingPkg, @Nullable String featureId, Uri uri,
+    void canonicalizeAsync(String callingPkg, @Nullable String attributionTag, Uri uri,
             RemoteCallback callback) throws RemoteException;
 
-    public Uri uncanonicalize(String callingPkg, @Nullable String featureId, Uri uri)
+    public Uri uncanonicalize(String callingPkg, @Nullable String attributionTag, Uri uri)
             throws RemoteException;
 
-    public boolean refresh(String callingPkg, @Nullable String featureId, Uri url,
+    public boolean refresh(String callingPkg, @Nullable String attributionTag, Uri url,
             @Nullable Bundle extras, ICancellationSignal cancellationSignal) throws RemoteException;
 
     // Data interchange.
     public String[] getStreamTypes(Uri url, String mimeTypeFilter) throws RemoteException;
 
-    public AssetFileDescriptor openTypedAssetFile(String callingPkg, @Nullable String featureId,
-            Uri url, String mimeType, Bundle opts, ICancellationSignal signal)
+    public AssetFileDescriptor openTypedAssetFile(String callingPkg,
+            @Nullable String attributionTag, Uri url, String mimeType, Bundle opts,
+            ICancellationSignal signal)
             throws RemoteException, FileNotFoundException;
 
     /* IPC constants */
diff --git a/core/java/android/content/PermissionChecker.java b/core/java/android/content/PermissionChecker.java
index 33bd839..b434072 100644
--- a/core/java/android/content/PermissionChecker.java
+++ b/core/java/android/content/PermissionChecker.java
@@ -123,7 +123,7 @@
      * @param uid The uid for which to check.
      * @param packageName The package name for which to check. If null the
      *     the first package for the calling UID will be used.
-     * @param featureId Feature in the package
+     * @param attributionTag attribution tag
      * @return The permission check result which is either {@link #PERMISSION_GRANTED}
      *     or {@link #PERMISSION_SOFT_DENIED} or {@link #PERMISSION_HARD_DENIED}.
      * @param message A message describing the reason the permission was checked
@@ -133,9 +133,9 @@
     @PermissionResult
     public static int checkPermissionForDataDelivery(@NonNull Context context,
             @NonNull String permission, int pid, int uid, @Nullable String packageName,
-            @Nullable String featureId, @Nullable String message) {
-        return checkPermissionCommon(context, permission, pid, uid, packageName, featureId, message,
-                true /*forDataDelivery*/);
+            @Nullable String attributionTag, @Nullable String message) {
+        return checkPermissionCommon(context, permission, pid, uid, packageName, attributionTag,
+                message, true /*forDataDelivery*/);
     }
 
     /**
@@ -171,8 +171,8 @@
     @PermissionResult
     public static int checkPermissionForPreflight(@NonNull Context context,
             @NonNull String permission, int pid, int uid, @Nullable String packageName) {
-        return checkPermissionCommon(context, permission, pid, uid, packageName, null /*featureId*/,
-                null /*message*/, false /*forDataDelivery*/);
+        return checkPermissionCommon(context, permission, pid, uid, packageName,
+                null /*attributionTag*/, null /*message*/, false /*forDataDelivery*/);
     }
 
     /**
@@ -207,7 +207,7 @@
     public static int checkSelfPermissionForDataDelivery(@NonNull Context context,
             @NonNull String permission, @Nullable String message) {
         return checkPermissionForDataDelivery(context, permission, Process.myPid(),
-                Process.myUid(), context.getPackageName(), context.getFeatureId(), message);
+                Process.myUid(), context.getPackageName(), context.getAttributionTag(), message);
     }
 
     /**
@@ -266,7 +266,7 @@
      * @param permission The permission to check.
      * @param packageName The package name making the IPC. If null the
      *     the first package for the calling UID will be used.
-     * @param featureId The feature inside of the app
+     * @param attributionTag attribution tag
      * @return The permission check result which is either {@link #PERMISSION_GRANTED}
      *     or {@link #PERMISSION_SOFT_DENIED} or {@link #PERMISSION_HARD_DENIED}.
      * @param message A message describing the reason the permission was checked
@@ -276,12 +276,12 @@
     @PermissionResult
     public static int checkCallingPermissionForDataDelivery(@NonNull Context context,
             @NonNull String permission, @Nullable String packageName,
-            @Nullable String featureId, @Nullable String message) {
+            @Nullable String attributionTag, @Nullable String message) {
         if (Binder.getCallingPid() == Process.myPid()) {
             return PERMISSION_HARD_DENIED;
         }
         return checkPermissionForDataDelivery(context, permission, Binder.getCallingPid(),
-                Binder.getCallingUid(), packageName, featureId, message);
+                Binder.getCallingUid(), packageName, attributionTag, message);
     }
 
     /**
@@ -343,20 +343,20 @@
      * @param permission The permission to check.
      * @return The permission check result which is either {@link #PERMISSION_GRANTED}
      *     or {@link #PERMISSION_SOFT_DENIED} or {@link #PERMISSION_HARD_DENIED}.
-     * @param featureId feature Id of caller (if not self)
+     * @param attributionTag attribution tag of caller (if not self)
      * @param message A message describing the reason the permission was checked
      *
      * @see #checkCallingOrSelfPermissionForPreflight(Context, String)
      */
     @PermissionResult
     public static int checkCallingOrSelfPermissionForDataDelivery(@NonNull Context context,
-            @NonNull String permission, @Nullable String featureId, @Nullable String message) {
+            @NonNull String permission, @Nullable String attributionTag, @Nullable String message) {
         String packageName = (Binder.getCallingPid() == Process.myPid())
                 ? context.getPackageName() : null;
-        featureId = (Binder.getCallingPid() == Process.myPid())
-                ? context.getFeatureId() : featureId;
+        attributionTag = (Binder.getCallingPid() == Process.myPid())
+                ? context.getAttributionTag() : attributionTag;
         return checkPermissionForDataDelivery(context, permission, Binder.getCallingPid(),
-                Binder.getCallingUid(), packageName, featureId, message);
+                Binder.getCallingUid(), packageName, attributionTag, message);
     }
 
     /**
@@ -395,7 +395,7 @@
     }
 
     static int checkPermissionCommon(@NonNull Context context, @NonNull String permission,
-            int pid, int uid, @Nullable String packageName, @Nullable String featureId,
+            int pid, int uid, @Nullable String packageName, @Nullable String attributionTag,
             @Nullable String message, boolean forDataDelivery) {
         final PermissionInfo permissionInfo;
         try {
@@ -414,18 +414,18 @@
         }
 
         if (permissionInfo.isAppOp()) {
-            return checkAppOpPermission(context, permission, pid, uid, packageName, featureId,
+            return checkAppOpPermission(context, permission, pid, uid, packageName, attributionTag,
                     message, forDataDelivery);
         }
         if (permissionInfo.isRuntime()) {
-            return checkRuntimePermission(context, permission, pid, uid, packageName, featureId,
-                    message, forDataDelivery);
+            return checkRuntimePermission(context, permission, pid, uid, packageName,
+                    attributionTag, message, forDataDelivery);
         }
         return context.checkPermission(permission, pid, uid);
     }
 
     private static int checkAppOpPermission(@NonNull Context context, @NonNull String permission,
-            int pid, int uid, @Nullable String packageName, @Nullable String featureId,
+            int pid, int uid, @Nullable String packageName, @Nullable String attributionTag,
             @Nullable String message, boolean forDataDelivery) {
         final String op = AppOpsManager.permissionToOp(permission);
         if (op == null || packageName == null) {
@@ -434,11 +434,12 @@
 
         final AppOpsManager appOpsManager = context.getSystemService(AppOpsManager.class);
         final int opMode = (forDataDelivery)
-                ? appOpsManager.noteProxyOpNoThrow(op, packageName, uid, featureId, message)
-                : appOpsManager.unsafeCheckOpNoThrow(op, uid, packageName);
+                ? appOpsManager.noteProxyOpNoThrow(op, packageName, uid, attributionTag, message)
+                : appOpsManager.unsafeCheckOpRawNoThrow(op, uid, packageName);
 
         switch (opMode) {
-            case AppOpsManager.MODE_ALLOWED: {
+            case AppOpsManager.MODE_ALLOWED:
+            case AppOpsManager.MODE_FOREGROUND: {
                 return PERMISSION_GRANTED;
             }
             case AppOpsManager.MODE_DEFAULT: {
@@ -453,7 +454,7 @@
     }
 
     private static int checkRuntimePermission(@NonNull Context context, @NonNull String permission,
-            int pid, int uid, @Nullable String packageName, @Nullable String featureId,
+            int pid, int uid, @Nullable String packageName, @Nullable String attributionTag,
             @Nullable String message, boolean forDataDelivery) {
         if (context.checkPermission(permission, pid, uid) == PackageManager.PERMISSION_DENIED) {
             return PERMISSION_HARD_DENIED;
@@ -466,13 +467,15 @@
 
         final AppOpsManager appOpsManager = context.getSystemService(AppOpsManager.class);
         final int opMode = (forDataDelivery)
-                ? appOpsManager.noteProxyOpNoThrow(op, packageName, uid, featureId, message)
-                : appOpsManager.unsafeCheckOpNoThrow(op, uid, packageName);
+                ? appOpsManager.noteProxyOpNoThrow(op, packageName, uid, attributionTag, message)
+                : appOpsManager.unsafeCheckOpRawNoThrow(op, uid, packageName);
 
-        if (opMode == AppOpsManager.MODE_ALLOWED) {
-            return PERMISSION_GRANTED;
-        } else {
-            return PERMISSION_SOFT_DENIED;
+        switch (opMode) {
+            case AppOpsManager.MODE_ALLOWED:
+            case AppOpsManager.MODE_FOREGROUND:
+                return PERMISSION_GRANTED;
+            default:
+                return PERMISSION_SOFT_DENIED;
         }
     }
 }
diff --git a/core/java/android/content/pm/ActivityInfo.java b/core/java/android/content/pm/ActivityInfo.java
index 0b2b5b1..f25ce76 100644
--- a/core/java/android/content/pm/ActivityInfo.java
+++ b/core/java/android/content/pm/ActivityInfo.java
@@ -1222,13 +1222,7 @@
         dest.writeInt(lockTaskLaunchMode);
         if (windowLayout != null) {
             dest.writeInt(1);
-            dest.writeInt(windowLayout.width);
-            dest.writeFloat(windowLayout.widthFraction);
-            dest.writeInt(windowLayout.height);
-            dest.writeFloat(windowLayout.heightFraction);
-            dest.writeInt(windowLayout.gravity);
-            dest.writeInt(windowLayout.minWidth);
-            dest.writeInt(windowLayout.minHeight);
+            windowLayout.writeToParcel(dest);
         } else {
             dest.writeInt(0);
         }
@@ -1372,8 +1366,8 @@
      * @attr ref android.R.styleable#AndroidManifestLayout_minHeight
      */
     public static final class WindowLayout {
-        public WindowLayout(int width, float widthFraction, int height, float heightFraction, int gravity,
-                int minWidth, int minHeight) {
+        public WindowLayout(int width, float widthFraction, int height, float heightFraction,
+                int gravity, int minWidth, int minHeight) {
             this.width = width;
             this.widthFraction = widthFraction;
             this.height = height;
@@ -1392,6 +1386,7 @@
             gravity = source.readInt();
             minWidth = source.readInt();
             minHeight = source.readInt();
+            windowLayoutAffinity = source.readString();
         }
 
         /**
@@ -1458,11 +1453,30 @@
         public final int minHeight;
 
         /**
+         * Affinity of window layout parameters. Activities with the same UID and window layout
+         * affinity will share the same window dimension record.
+         * @hide
+         */
+        public String windowLayoutAffinity;
+
+        /**
          * Returns if this {@link WindowLayout} has specified bounds.
          * @hide
          */
         public boolean hasSpecifiedSize() {
             return width >= 0 || height >= 0 || widthFraction >= 0 || heightFraction >= 0;
         }
+
+        /** @hide */
+        public void writeToParcel(Parcel dest) {
+            dest.writeInt(width);
+            dest.writeFloat(widthFraction);
+            dest.writeInt(height);
+            dest.writeFloat(heightFraction);
+            dest.writeInt(gravity);
+            dest.writeInt(minWidth);
+            dest.writeInt(minHeight);
+            dest.writeString(windowLayoutAffinity);
+        }
     }
 }
diff --git a/core/java/android/content/pm/CrossProfileApps.java b/core/java/android/content/pm/CrossProfileApps.java
index 5e7e0c8..dc3a029 100644
--- a/core/java/android/content/pm/CrossProfileApps.java
+++ b/core/java/android/content/pm/CrossProfileApps.java
@@ -96,7 +96,7 @@
             mService.startActivityAsUser(
                     mContext.getIApplicationThread(),
                     mContext.getPackageName(),
-                    mContext.getFeatureId(),
+                    mContext.getAttributionTag(),
                     component,
                     targetUser.getIdentifier(),
                     true);
@@ -162,7 +162,7 @@
             mService.startActivityAsUserByIntent(
                     mContext.getIApplicationThread(),
                     mContext.getPackageName(),
-                    mContext.getFeatureId(),
+                    mContext.getAttributionTag(),
                     intent,
                     targetUser.getIdentifier(),
                     callingActivity != null ? callingActivity.getActivityToken() : null,
@@ -190,7 +190,7 @@
     public void startActivity(@NonNull ComponentName component, @NonNull UserHandle targetUser) {
         try {
             mService.startActivityAsUser(mContext.getIApplicationThread(),
-                    mContext.getPackageName(), mContext.getFeatureId(), component,
+                    mContext.getPackageName(), mContext.getAttributionTag(), component,
                     targetUser.getIdentifier(), false);
         } catch (RemoteException ex) {
             throw ex.rethrowFromSystemServer();
diff --git a/core/java/android/content/pm/IPackageManager.aidl b/core/java/android/content/pm/IPackageManager.aidl
index 8c3eef2..0311120 100644
--- a/core/java/android/content/pm/IPackageManager.aidl
+++ b/core/java/android/content/pm/IPackageManager.aidl
@@ -748,4 +748,6 @@
     void clearMimeGroup(String packageName, String group);
 
     List<String> getMimeGroup(String packageName, String group);
+
+    boolean isAutoRevokeWhitelisted(String packageName);
 }
diff --git a/core/java/android/content/pm/LauncherApps.java b/core/java/android/content/pm/LauncherApps.java
index 86242fd..4e4897f 100644
--- a/core/java/android/content/pm/LauncherApps.java
+++ b/core/java/android/content/pm/LauncherApps.java
@@ -721,7 +721,7 @@
         }
         try {
             mService.startActivityAsUser(mContext.getIApplicationThread(),
-                    mContext.getPackageName(), mContext.getFeatureId(),
+                    mContext.getPackageName(), mContext.getAttributionTag(),
                     component, sourceBounds, opts, user);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
@@ -739,8 +739,8 @@
             @Nullable Rect sourceBounds, @Nullable Bundle opts) {
         try {
             mService.startSessionDetailsActivityAsUser(mContext.getIApplicationThread(),
-                    mContext.getPackageName(), mContext.getFeatureId(), sessionInfo, sourceBounds,
-                    opts, sessionInfo.getUser());
+                    mContext.getPackageName(), mContext.getAttributionTag(), sessionInfo,
+                    sourceBounds, opts, sessionInfo.getUser());
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
         }
@@ -760,7 +760,7 @@
         logErrorForInvalidProfileAccess(user);
         try {
             mService.showAppDetailsAsUser(mContext.getIApplicationThread(),
-                    mContext.getPackageName(), mContext.getFeatureId(),
+                    mContext.getPackageName(), mContext.getAttributionTag(),
                     component, sourceBounds, opts, user);
         } catch (RemoteException re) {
             throw re.rethrowFromSystemServer();
diff --git a/core/java/android/content/pm/PackageManager.java b/core/java/android/content/pm/PackageManager.java
index 7600a08..b2ff3f4 100644
--- a/core/java/android/content/pm/PackageManager.java
+++ b/core/java/android/content/pm/PackageManager.java
@@ -1978,7 +1978,7 @@
      * Feature for {@link #getSystemAvailableFeatures} and
      * {@link #hasSystemFeature}: The device's main front and back cameras can stream
      * concurrently as described in  {@link
-     * android.hardware.camera2.CameraManager#getConcurrentStreamingCameraIds()}
+     * android.hardware.camera2.CameraManager#getConcurrentCameraIds()}
      */
     @SdkConstant(SdkConstantType.FEATURE)
     public static final String FEATURE_CAMERA_CONCURRENT = "android.hardware.camera.concurrent";
@@ -3411,12 +3411,13 @@
     public static final int FLAG_PERMISSION_AUTO_REVOKED = 1 << 17;
 
     /**
-     * Permission flags: Reserved for use by the permission controller.
-     *
+     * Permission flags: Reserved for use by the permission controller. The platform and any
+     * packages besides the permission controller should not assume any definition about these
+     * flags.
      * @hide
      */
     @SystemApi
-    public static final int FLAGS_PERMISSION_RESERVED_PERMISSIONCONTROLLER = 1 << 28 | 1 << 29
+    public static final int FLAGS_PERMISSION_RESERVED_PERMISSION_CONTROLLER = 1 << 28 | 1 << 29
             | 1 << 30 | 1 << 31;
 
     /**
@@ -7834,6 +7835,15 @@
     }
 
     /**
+     * @return whether this package is whitelisted from having its runtime permission be
+     *         auto-revoked if unused for an extended period of time.
+     */
+    public boolean isAutoRevokeWhitelisted() {
+        throw new UnsupportedOperationException(
+                "isAutoRevokeWhitelisted not implemented in subclass");
+    }
+
+    /**
      * Returns if the provided drawable represents the default activity icon provided by the system.
      *
      * PackageManager silently returns a default application icon for any package/activity if the
diff --git a/core/java/android/content/pm/PackageParser.java b/core/java/android/content/pm/PackageParser.java
index c6875a4..18f1343 100644
--- a/core/java/android/content/pm/PackageParser.java
+++ b/core/java/android/content/pm/PackageParser.java
@@ -55,7 +55,6 @@
 import android.content.ComponentName;
 import android.content.Intent;
 import android.content.IntentFilter;
-import android.content.pm.parsing.ParsingPackageUtils;
 import android.content.pm.permission.SplitPermissionInfoParcelable;
 import android.content.pm.split.DefaultSplitAssetLoader;
 import android.content.pm.split.SplitAssetDependencyLoader;
@@ -190,7 +189,7 @@
     public static final String TAG_OVERLAY = "overlay";
     public static final String TAG_PACKAGE = "package";
     public static final String TAG_PACKAGE_VERIFIER = "package-verifier";
-    public static final String TAG_FEATURE = "feature";
+    public static final String TAG_ATTRIBUTION = "attribution";
     public static final String TAG_PERMISSION = "permission";
     public static final String TAG_PERMISSION_GROUP = "permission-group";
     public static final String TAG_PERMISSION_TREE = "permission-tree";
@@ -209,6 +208,8 @@
     public static final String TAG_USES_SPLIT = "uses-split";
 
     public static final String METADATA_MAX_ASPECT_RATIO = "android.max_aspect";
+    public static final String METADATA_ACTIVITY_WINDOW_LAYOUT_AFFINITY =
+            "android.activity_window_layout_affinity";
 
     /**
      * Bit mask of all the valid bits that can be set in recreateOnConfigChanges.
@@ -4560,6 +4561,8 @@
             }
         }
 
+        resolveWindowLayout(a);
+
         if (!setExported) {
             a.info.exported = a.intents.size() > 0;
         }
@@ -4726,6 +4729,35 @@
                 height, heightFraction, gravity, minWidth, minHeight);
     }
 
+    /**
+     * Resolves values in {@link ActivityInfo.WindowLayout}.
+     *
+     * <p>{@link ActivityInfo.WindowLayout#windowLayoutAffinity} has a fallback metadata used in
+     * Android R and some variants of pre-R.
+     */
+    private void resolveWindowLayout(Activity activity) {
+        // There isn't a metadata for us to fall back. Whatever is in layout is correct.
+        if (activity.metaData == null
+                || !activity.metaData.containsKey(METADATA_ACTIVITY_WINDOW_LAYOUT_AFFINITY)) {
+            return;
+        }
+
+        final ActivityInfo aInfo = activity.info;
+        // Layout already specifies a value. We should just use that one.
+        if (aInfo.windowLayout != null && aInfo.windowLayout.windowLayoutAffinity != null) {
+            return;
+        }
+
+        String windowLayoutAffinity = activity.metaData.getString(
+                METADATA_ACTIVITY_WINDOW_LAYOUT_AFFINITY);
+        if (aInfo.windowLayout == null) {
+            aInfo.windowLayout = new ActivityInfo.WindowLayout(-1 /* width */,
+                    -1 /* widthFraction */, -1 /* height */, -1 /* heightFraction */,
+                    Gravity.NO_GRAVITY, -1 /* minWidth */, -1 /* minHeight */);
+        }
+        aInfo.windowLayout.windowLayoutAffinity = windowLayoutAffinity;
+    }
+
     private Activity parseActivityAlias(Package owner, Resources res,
             XmlResourceParser parser, int flags, String[] outError,
             CachedComponentArgs cachedArgs)
diff --git a/core/java/android/content/pm/parsing/ParsingPackage.java b/core/java/android/content/pm/parsing/ParsingPackage.java
index a479b2e..1304ba8 100644
--- a/core/java/android/content/pm/parsing/ParsingPackage.java
+++ b/core/java/android/content/pm/parsing/ParsingPackage.java
@@ -24,7 +24,7 @@
 import android.content.pm.FeatureInfo;
 import android.content.pm.PackageParser;
 import android.content.pm.parsing.component.ParsedActivity;
-import android.content.pm.parsing.component.ParsedFeature;
+import android.content.pm.parsing.component.ParsedAttribution;
 import android.content.pm.parsing.component.ParsedInstrumentation;
 import android.content.pm.parsing.component.ParsedIntentInfo;
 import android.content.pm.parsing.component.ParsedPermission;
@@ -77,7 +77,7 @@
 
     ParsingPackage addProvider(ParsedProvider parsedProvider);
 
-    ParsingPackage addFeature(ParsedFeature permission);
+    ParsingPackage addAttribution(ParsedAttribution attribution);
 
     ParsingPackage addReceiver(ParsedActivity parsedReceiver);
 
@@ -191,7 +191,11 @@
     ParsingPackage setRequestLegacyExternalStorage(boolean requestLegacyExternalStorage);
 
     ParsingPackage setAllowNativeHeapPointerTagging(boolean allowNativeHeapPointerTagging);
-  
+
+    ParsingPackage setDontAutoRevokePermissions(boolean dontAutoRevokePermissions);
+
+    ParsingPackage setAllowDontAutoRevokePermissions(boolean allowDontAutoRevokePermissions);
+
     ParsingPackage setPreserveLegacyExternalStorage(boolean preserveLegacyExternalStorage);
 
     ParsingPackage setRestoreAnyVersion(boolean restoreAnyVersion);
diff --git a/core/java/android/content/pm/parsing/ParsingPackageImpl.java b/core/java/android/content/pm/parsing/ParsingPackageImpl.java
index f6a415e..3390f16 100644
--- a/core/java/android/content/pm/parsing/ParsingPackageImpl.java
+++ b/core/java/android/content/pm/parsing/ParsingPackageImpl.java
@@ -32,8 +32,8 @@
 import android.content.pm.PackageParser;
 import android.content.pm.ProcessInfo;
 import android.content.pm.parsing.component.ParsedActivity;
+import android.content.pm.parsing.component.ParsedAttribution;
 import android.content.pm.parsing.component.ParsedComponent;
-import android.content.pm.parsing.component.ParsedFeature;
 import android.content.pm.parsing.component.ParsedInstrumentation;
 import android.content.pm.parsing.component.ParsedIntentInfo;
 import android.content.pm.parsing.component.ParsedMainComponent;
@@ -244,7 +244,7 @@
     protected List<ParsedProvider> providers = emptyList();
 
     @NonNull
-    private List<ParsedFeature> features = emptyList();
+    private List<ParsedAttribution> attributions = emptyList();
 
     @NonNull
     protected List<ParsedPermission> permissions = emptyList();
@@ -405,6 +405,8 @@
     private boolean hasFragileUserData;
     private boolean cantSaveState;
     private boolean allowNativeHeapPointerTagging;
+    private boolean dontAutoRevokePermissions;
+    private boolean allowDontAutoRevokePermissions;
     private boolean preserveLegacyExternalStorage;
 
     @Nullable
@@ -625,8 +627,8 @@
     }
 
     @Override
-    public ParsingPackageImpl addFeature(ParsedFeature feature) {
-        this.features = CollectionUtils.add(this.features, feature);
+    public ParsingPackageImpl addAttribution(ParsedAttribution attribution) {
+        this.attributions = CollectionUtils.add(this.attributions, attribution);
         return this;
     }
 
@@ -995,7 +997,7 @@
         dest.writeTypedList(this.receivers);
         dest.writeTypedList(this.services);
         dest.writeTypedList(this.providers);
-        dest.writeTypedList(this.features);
+        dest.writeTypedList(this.attributions);
         dest.writeTypedList(this.permissions);
         dest.writeTypedList(this.permissionGroups);
         dest.writeTypedList(this.instrumentations);
@@ -1089,6 +1091,8 @@
         dest.writeBoolean(this.hasFragileUserData);
         dest.writeBoolean(this.cantSaveState);
         dest.writeBoolean(this.allowNativeHeapPointerTagging);
+        dest.writeBoolean(this.dontAutoRevokePermissions);
+        dest.writeBoolean(this.allowDontAutoRevokePermissions);
         dest.writeBoolean(this.preserveLegacyExternalStorage);
         dest.writeArraySet(this.mimeGroups);
         sForBoolean.parcel(this.enableGwpAsan, dest, flags);
@@ -1155,7 +1159,7 @@
         this.receivers = in.createTypedArrayList(ParsedActivity.CREATOR);
         this.services = in.createTypedArrayList(ParsedService.CREATOR);
         this.providers = in.createTypedArrayList(ParsedProvider.CREATOR);
-        this.features = in.createTypedArrayList(ParsedFeature.CREATOR);
+        this.attributions = in.createTypedArrayList(ParsedAttribution.CREATOR);
         this.permissions = in.createTypedArrayList(ParsedPermission.CREATOR);
         this.permissionGroups = in.createTypedArrayList(ParsedPermissionGroup.CREATOR);
         this.instrumentations = in.createTypedArrayList(ParsedInstrumentation.CREATOR);
@@ -1247,6 +1251,8 @@
         this.hasFragileUserData = in.readBoolean();
         this.cantSaveState = in.readBoolean();
         this.allowNativeHeapPointerTagging = in.readBoolean();
+        this.dontAutoRevokePermissions = in.readBoolean();
+        this.allowDontAutoRevokePermissions = in.readBoolean();
         this.preserveLegacyExternalStorage = in.readBoolean();
         this.mimeGroups = (ArraySet<String>) in.readArraySet(boot);
         this.enableGwpAsan = sForBoolean.unparcel(in);
@@ -1516,8 +1522,8 @@
 
     @NonNull
     @Override
-    public List<ParsedFeature> getFeatures() {
-        return features;
+    public List<ParsedAttribution> getAttributions() {
+        return attributions;
     }
 
     @NonNull
@@ -2023,6 +2029,16 @@
     }
 
     @Override
+    public boolean isDontAutoRevokePermmissions() {
+        return dontAutoRevokePermissions;
+    }
+
+    @Override
+    public boolean isAllowDontAutoRevokePermmissions() {
+        return allowDontAutoRevokePermissions;
+    }
+
+    @Override
     public boolean hasPreserveLegacyExternalStorage() {
         return preserveLegacyExternalStorage;
     }
@@ -2493,6 +2509,18 @@
     }
 
     @Override
+    public ParsingPackageImpl setDontAutoRevokePermissions(boolean value) {
+        dontAutoRevokePermissions = value;
+        return this;
+    }
+
+    @Override
+    public ParsingPackageImpl setAllowDontAutoRevokePermissions(boolean value) {
+        allowDontAutoRevokePermissions = value;
+        return this;
+    }
+
+    @Override
     public ParsingPackageImpl setPreserveLegacyExternalStorage(boolean value) {
         preserveLegacyExternalStorage = value;
         return this;
diff --git a/core/java/android/content/pm/parsing/ParsingPackageRead.java b/core/java/android/content/pm/parsing/ParsingPackageRead.java
index 61d7824..9c13c85 100644
--- a/core/java/android/content/pm/parsing/ParsingPackageRead.java
+++ b/core/java/android/content/pm/parsing/ParsingPackageRead.java
@@ -28,7 +28,7 @@
 import android.content.pm.PackageParser;
 import android.content.pm.ServiceInfo;
 import android.content.pm.parsing.component.ParsedActivity;
-import android.content.pm.parsing.component.ParsedFeature;
+import android.content.pm.parsing.component.ParsedAttribution;
 import android.content.pm.parsing.component.ParsedInstrumentation;
 import android.content.pm.parsing.component.ParsedIntentInfo;
 import android.content.pm.parsing.component.ParsedPermission;
@@ -80,7 +80,7 @@
     List<ConfigurationInfo> getConfigPreferences();
 
     @NonNull
-    List<ParsedFeature> getFeatures();
+    List<ParsedAttribution> getAttributions();
 
     /**
      * @see PackageInfo#featureGroups
@@ -771,6 +771,12 @@
     /** @see ApplicationInfo#PRIVATE_FLAG_ALLOW_NATIVE_HEAP_POINTER_TAGGING */
     boolean isAllowNativeHeapPointerTagging();
 
+    /** @see ApplicationInfo#PRIVATE_FLAG2_DONT_AUTO_REVOKE_PERMISSIONS */
+    boolean isDontAutoRevokePermmissions();
+
+    /** @see ApplicationInfo#PRIVATE_FLAG2_ALLOW_DONT_AUTO_REVOKE_PERMISSIONS */
+    boolean isAllowDontAutoRevokePermmissions();
+
     boolean hasPreserveLegacyExternalStorage();
 
     /**
diff --git a/core/java/android/content/pm/parsing/ParsingPackageUtils.java b/core/java/android/content/pm/parsing/ParsingPackageUtils.java
index 19da71c..e41ed85 100644
--- a/core/java/android/content/pm/parsing/ParsingPackageUtils.java
+++ b/core/java/android/content/pm/parsing/ParsingPackageUtils.java
@@ -49,8 +49,8 @@
 import android.content.pm.parsing.component.ComponentParseUtils;
 import android.content.pm.parsing.component.ParsedActivity;
 import android.content.pm.parsing.component.ParsedActivityUtils;
-import android.content.pm.parsing.component.ParsedFeature;
-import android.content.pm.parsing.component.ParsedFeatureUtils;
+import android.content.pm.parsing.component.ParsedAttribution;
+import android.content.pm.parsing.component.ParsedAttributionUtils;
 import android.content.pm.parsing.component.ParsedInstrumentation;
 import android.content.pm.parsing.component.ParsedInstrumentationUtils;
 import android.content.pm.parsing.component.ParsedIntentInfo;
@@ -673,7 +673,7 @@
             );
         }
 
-        if (!ParsedFeature.isCombinationValid(pkg.getFeatures())) {
+        if (!ParsedAttribution.isCombinationValid(pkg.getAttributions())) {
             return input.error(
                     INSTALL_PARSE_FAILED_BAD_MANIFEST,
                     "Combination <feature> tags are not valid"
@@ -708,8 +708,9 @@
                 return parseOverlay(input, pkg, res, parser);
             case PackageParser.TAG_KEY_SETS:
                 return parseKeySets(input, pkg, res, parser);
-            case PackageParser.TAG_FEATURE:
-                return parseFeature(input, pkg, res, parser);
+            case "feature": // TODO moltmann: Remove
+            case PackageParser.TAG_ATTRIBUTION:
+                return parseAttribution(input, pkg, res, parser);
             case PackageParser.TAG_PERMISSION_GROUP:
                 return parsePermissionGroup(input, pkg, res, parser);
             case PackageParser.TAG_PERMISSION:
@@ -918,13 +919,15 @@
         return input.success(pkg);
     }
 
-    private static ParseResult<ParsingPackage> parseFeature(ParseInput input, ParsingPackage pkg,
-            Resources res, XmlResourceParser parser) throws IOException, XmlPullParserException {
-        ParseResult<ParsedFeature> result = ParsedFeatureUtils.parseFeature(res, parser, input);
+    private static ParseResult<ParsingPackage> parseAttribution(ParseInput input,
+            ParsingPackage pkg, Resources res, XmlResourceParser parser)
+            throws IOException, XmlPullParserException {
+        ParseResult<ParsedAttribution> result = ParsedAttributionUtils.parseAttribution(res,
+                parser, input);
         if (result.isError()) {
             return input.error(result);
         }
-        return input.success(pkg.addFeature(result.getResult()));
+        return input.success(pkg.addAttribution(result.getResult()));
     }
 
     private static ParseResult<ParsingPackage> parsePermissionGroup(ParseInput input,
@@ -1817,6 +1820,8 @@
                 .setUseEmbeddedDex(bool(false, R.styleable.AndroidManifestApplication_useEmbeddedDex, sa))
                 .setUsesNonSdkApi(bool(false, R.styleable.AndroidManifestApplication_usesNonSdkApi, sa))
                 .setVmSafeMode(bool(false, R.styleable.AndroidManifestApplication_vmSafeMode, sa))
+                .setDontAutoRevokePermissions(bool(false, R.styleable.AndroidManifestApplication_requestDontAutoRevokePermissions, sa))
+                .setAllowDontAutoRevokePermissions(bool(false, R.styleable.AndroidManifestApplication_allowDontAutoRevokePermissions, sa))
                 // targetSdkVersion gated
                 .setAllowAudioPlaybackCapture(bool(targetSdk >= Build.VERSION_CODES.Q, R.styleable.AndroidManifestApplication_allowAudioPlaybackCapture, sa))
                 .setBaseHardwareAccelerated(bool(targetSdk >= Build.VERSION_CODES.ICE_CREAM_SANDWICH, R.styleable.AndroidManifestApplication_hardwareAccelerated, sa))
diff --git a/core/java/android/content/pm/parsing/component/ParsedActivity.java b/core/java/android/content/pm/parsing/component/ParsedActivity.java
index d32171d..4c93d09 100644
--- a/core/java/android/content/pm/parsing/component/ParsedActivity.java
+++ b/core/java/android/content/pm/parsing/component/ParsedActivity.java
@@ -285,14 +285,8 @@
         dest.writeBundle(this.metaData);
 
         if (windowLayout != null) {
-            dest.writeBoolean(true);
-            dest.writeInt(windowLayout.width);
-            dest.writeFloat(windowLayout.widthFraction);
-            dest.writeInt(windowLayout.height);
-            dest.writeFloat(windowLayout.heightFraction);
-            dest.writeInt(windowLayout.gravity);
-            dest.writeInt(windowLayout.minWidth);
-            dest.writeInt(windowLayout.minHeight);
+            dest.writeInt(1);
+            windowLayout.writeToParcel(dest);
         } else {
             dest.writeBoolean(false);
         }
diff --git a/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java b/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
index 1dcf262..6e5c51a 100644
--- a/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
+++ b/core/java/android/content/pm/parsing/component/ParsedActivityUtils.java
@@ -17,16 +17,17 @@
 package android.content.pm.parsing.component;
 
 import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
-
 import static android.content.pm.parsing.component.ComponentParseUtils.flag;
 
 import android.annotation.NonNull;
 import android.app.ActivityTaskManager;
 import android.content.pm.ActivityInfo;
 import android.content.pm.PackageParser;
-
 import android.content.pm.parsing.ParsingPackage;
+import android.content.pm.parsing.ParsingPackageUtils;
 import android.content.pm.parsing.ParsingUtils;
+import android.content.pm.parsing.result.ParseInput;
+import android.content.pm.parsing.result.ParseResult;
 import android.content.res.Configuration;
 import android.content.res.Resources;
 import android.content.res.TypedArray;
@@ -42,9 +43,6 @@
 import com.android.internal.R;
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.ArrayUtils;
-import android.content.pm.parsing.ParsingPackageUtils;
-import android.content.pm.parsing.result.ParseInput;
-import android.content.pm.parsing.result.ParseResult;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -379,6 +377,12 @@
             }
         }
 
+        ParseResult<ActivityInfo.WindowLayout> layoutResult = resolveWindowLayout(activity, input);
+        if (layoutResult.isError()) {
+            return input.error(layoutResult);
+        }
+        activity.windowLayout = layoutResult.getResult();
+
         if (!setExported) {
             activity.exported = activity.getIntents().size() > 0;
         }
@@ -481,4 +485,35 @@
             sw.recycle();
         }
     }
+
+    /**
+     * Resolves values in {@link ActivityInfo.WindowLayout}.
+     *
+     * <p>{@link ActivityInfo.WindowLayout#windowLayoutAffinity} has a fallback metadata used in
+     * Android R and some variants of pre-R.
+     */
+    private static ParseResult<ActivityInfo.WindowLayout> resolveWindowLayout(
+            ParsedActivity activity, ParseInput input) {
+        // There isn't a metadata for us to fall back. Whatever is in layout is correct.
+        if (activity.metaData == null || !activity.metaData.containsKey(
+                PackageParser.METADATA_ACTIVITY_WINDOW_LAYOUT_AFFINITY)) {
+            return input.success(activity.windowLayout);
+        }
+
+        // Layout already specifies a value. We should just use that one.
+        if (activity.windowLayout != null && activity.windowLayout.windowLayoutAffinity != null) {
+            return input.success(activity.windowLayout);
+        }
+
+        String windowLayoutAffinity = activity.metaData.getString(
+                PackageParser.METADATA_ACTIVITY_WINDOW_LAYOUT_AFFINITY);
+        ActivityInfo.WindowLayout layout = activity.windowLayout;
+        if (layout == null) {
+            layout = new ActivityInfo.WindowLayout(-1 /* width */, -1 /* widthFraction */,
+                    -1 /* height */, -1 /* heightFraction */, Gravity.NO_GRAVITY,
+                    -1 /* minWidth */, -1 /* minHeight */);
+        }
+        layout.windowLayoutAffinity = windowLayoutAffinity;
+        return input.success(layout);
+    }
 }
diff --git a/core/java/android/content/pm/parsing/component/ParsedAttribution.java b/core/java/android/content/pm/parsing/component/ParsedAttribution.java
new file mode 100644
index 0000000..02b3c7d
--- /dev/null
+++ b/core/java/android/content/pm/parsing/component/ParsedAttribution.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2020 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.content.pm.parsing.component;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.StringRes;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.ArraySet;
+
+import com.android.internal.util.DataClass;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A {@link android.R.styleable#AndroidManifestAttribution &lt;attribution&gt;} tag parsed from the
+ * manifest.
+ *
+ * @hide
+ */
+@DataClass(genAidl = false)
+public class ParsedAttribution implements Parcelable {
+    /** Maximum length of attribution tag */
+    public static final int MAX_ATTRIBUTION_TAG_LEN = 50;
+
+    /** Maximum amount of attributions per package */
+    private static final int MAX_NUM_ATTRIBUTIONS = 1000;
+
+    /** Tag of the attribution */
+    public final @NonNull String tag;
+
+    /** User visible label fo the attribution */
+    public final @StringRes int label;
+
+    /** Ids of previously declared attributions this attribution inherits from */
+    public final @NonNull List<String> inheritFrom;
+
+    /**
+     * @return Is this set of attributions a valid combination for a single package?
+     */
+    public static boolean isCombinationValid(@Nullable List<ParsedAttribution> attributions) {
+        if (attributions == null) {
+            return true;
+        }
+
+        ArraySet<String> attributionTags = new ArraySet<>(attributions.size());
+        ArraySet<String> inheritFromAttributionTags = new ArraySet<>();
+
+        int numAttributions = attributions.size();
+        if (numAttributions > MAX_NUM_ATTRIBUTIONS) {
+            return false;
+        }
+
+        for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) {
+            boolean wasAdded = attributionTags.add(attributions.get(attributionNum).tag);
+            if (!wasAdded) {
+                // feature id is not unique
+                return false;
+            }
+        }
+
+        for (int attributionNum = 0; attributionNum < numAttributions; attributionNum++) {
+            ParsedAttribution feature = attributions.get(attributionNum);
+
+            int numInheritFrom = feature.inheritFrom.size();
+            for (int inheritFromNum = 0; inheritFromNum < numInheritFrom; inheritFromNum++) {
+                String inheritFrom = feature.inheritFrom.get(inheritFromNum);
+
+                if (attributionTags.contains(inheritFrom)) {
+                    // Cannot inherit from a attribution that is still defined
+                    return false;
+                }
+
+                boolean wasAdded = inheritFromAttributionTags.add(inheritFrom);
+                if (!wasAdded) {
+                    // inheritFrom is not unique
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
+
+
+    // Code below generated by codegen v1.0.14.
+    //
+    // DO NOT MODIFY!
+    // CHECKSTYLE:OFF Generated code
+    //
+    // To regenerate run:
+    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/component/ParsedAttribution.java
+    //
+    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
+    //   Settings > Editor > Code Style > Formatter Control
+    //@formatter:off
+
+
+    @android.annotation.IntDef(prefix = "MAX_", value = {
+        MAX_ATTRIBUTION_TAG_LEN,
+        MAX_NUM_ATTRIBUTIONS
+    })
+    @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
+    @DataClass.Generated.Member
+    public @interface Max {}
+
+    @DataClass.Generated.Member
+    public static String maxToString(@Max int value) {
+        switch (value) {
+            case MAX_ATTRIBUTION_TAG_LEN:
+                    return "MAX_ATTRIBUTION_TAG_LEN";
+            case MAX_NUM_ATTRIBUTIONS:
+                    return "MAX_NUM_ATTRIBUTIONS";
+            default: return Integer.toHexString(value);
+        }
+    }
+
+    /**
+     * Creates a new ParsedAttribution.
+     *
+     * @param tag
+     *   Tag of the attribution
+     * @param label
+     *   User visible label fo the attribution
+     * @param inheritFrom
+     *   Ids of previously declared attributions this attribution inherits from
+     */
+    @DataClass.Generated.Member
+    public ParsedAttribution(
+            @NonNull String tag,
+            @StringRes int label,
+            @NonNull List<String> inheritFrom) {
+        this.tag = tag;
+        com.android.internal.util.AnnotationValidations.validate(
+                NonNull.class, null, tag);
+        this.label = label;
+        com.android.internal.util.AnnotationValidations.validate(
+                StringRes.class, null, label);
+        this.inheritFrom = inheritFrom;
+        com.android.internal.util.AnnotationValidations.validate(
+                NonNull.class, null, inheritFrom);
+
+        // onConstructed(); // You can define this method to get a callback
+    }
+
+    @Override
+    @DataClass.Generated.Member
+    public void writeToParcel(@NonNull Parcel dest, int flags) {
+        // You can override field parcelling by defining methods like:
+        // void parcelFieldName(Parcel dest, int flags) { ... }
+
+        dest.writeString(tag);
+        dest.writeInt(label);
+        dest.writeStringList(inheritFrom);
+    }
+
+    @Override
+    @DataClass.Generated.Member
+    public int describeContents() { return 0; }
+
+    /** @hide */
+    @SuppressWarnings({"unchecked", "RedundantCast"})
+    @DataClass.Generated.Member
+    protected ParsedAttribution(@NonNull Parcel in) {
+        // You can override field unparcelling by defining methods like:
+        // static FieldType unparcelFieldName(Parcel in) { ... }
+
+        String _tag = in.readString();
+        int _label = in.readInt();
+        List<String> _inheritFrom = new ArrayList<>();
+        in.readStringList(_inheritFrom);
+
+        this.tag = _tag;
+        com.android.internal.util.AnnotationValidations.validate(
+                NonNull.class, null, tag);
+        this.label = _label;
+        com.android.internal.util.AnnotationValidations.validate(
+                StringRes.class, null, label);
+        this.inheritFrom = _inheritFrom;
+        com.android.internal.util.AnnotationValidations.validate(
+                NonNull.class, null, inheritFrom);
+
+        // onConstructed(); // You can define this method to get a callback
+    }
+
+    @DataClass.Generated.Member
+    public static final @NonNull Parcelable.Creator<ParsedAttribution> CREATOR
+            = new Parcelable.Creator<ParsedAttribution>() {
+        @Override
+        public ParsedAttribution[] newArray(int size) {
+            return new ParsedAttribution[size];
+        }
+
+        @Override
+        public ParsedAttribution createFromParcel(@NonNull Parcel in) {
+            return new ParsedAttribution(in);
+        }
+    };
+
+    @DataClass.Generated(
+            time = 1583436566499L,
+            codegenVersion = "1.0.14",
+            sourceFile = "frameworks/base/core/java/android/content/pm/parsing/component/ParsedAttribution.java",
+            inputSignatures = "public static final  int MAX_ATTRIBUTION_TAG_LEN\nprivate static final  int MAX_NUM_ATTRIBUTIONS\npublic final @android.annotation.NonNull java.lang.String tag\npublic final @android.annotation.StringRes int label\npublic final @android.annotation.NonNull java.util.List<java.lang.String> inheritFrom\npublic static  boolean isCombinationValid(java.util.List<android.content.pm.parsing.component.ParsedAttribution>)\nclass ParsedAttribution extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genAidl=false)")
+    @Deprecated
+    private void __metadata() {}
+
+
+    //@formatter:on
+    // End of generated code
+
+}
diff --git a/core/java/android/content/pm/parsing/component/ParsedFeatureUtils.java b/core/java/android/content/pm/parsing/component/ParsedAttributionUtils.java
similarity index 63%
rename from core/java/android/content/pm/parsing/component/ParsedFeatureUtils.java
rename to core/java/android/content/pm/parsing/component/ParsedAttributionUtils.java
index fb52801..c4b1a0e 100644
--- a/core/java/android/content/pm/parsing/component/ParsedFeatureUtils.java
+++ b/core/java/android/content/pm/parsing/component/ParsedAttributionUtils.java
@@ -34,34 +34,40 @@
 import java.util.List;
 
 /** @hide */
-public class ParsedFeatureUtils {
+public class ParsedAttributionUtils {
 
     @NonNull
-    public static ParseResult<ParsedFeature> parseFeature(Resources res, XmlResourceParser parser,
-            ParseInput input) throws IOException, XmlPullParserException {
-        String featureId;
+    public static ParseResult<ParsedAttribution> parseAttribution(Resources res,
+            XmlResourceParser parser, ParseInput input)
+            throws IOException, XmlPullParserException {
+        String attributionTag;
         int label;
         List<String> inheritFrom = null;
 
-        TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestFeature);
+        TypedArray sa = res.obtainAttributes(parser, R.styleable.AndroidManifestAttribution);
         if (sa == null) {
-            return input.error("<feature> could not be parsed");
+            return input.error("<attribution> could not be parsed");
         }
 
         try {
-            featureId = sa.getNonConfigurationString(R.styleable.AndroidManifestFeature_featureId,
-                    0);
-            if (featureId == null) {
-                return input.error("<featureId> does not specify android:featureId");
+            attributionTag = sa.getNonConfigurationString(
+                    R.styleable.AndroidManifestAttribution_tag, 0);
+            if (attributionTag == null) {
+                // TODO moltmann: Remove handling of featureId
+                attributionTag = sa.getNonConfigurationString(
+                        R.styleable.AndroidManifestAttribution_featureId, 0);
+                if (attributionTag == null) {
+                    return input.error("<attribution> does not specify android:tag");
+                }
             }
-            if (featureId.length() > ParsedFeature.MAX_FEATURE_ID_LEN) {
-                return input.error("<featureId> is too long. Max length is "
-                        + ParsedFeature.MAX_FEATURE_ID_LEN);
+            if (attributionTag.length() > ParsedAttribution.MAX_ATTRIBUTION_TAG_LEN) {
+                return input.error("android:tag is too long. Max length is "
+                        + ParsedAttribution.MAX_ATTRIBUTION_TAG_LEN);
             }
 
-            label = sa.getResourceId(R.styleable.AndroidManifestFeature_label, 0);
+            label = sa.getResourceId(R.styleable.AndroidManifestAttribution_label, 0);
             if (label == Resources.ID_NULL) {
-                return input.error("<featureId> does not specify android:label");
+                return input.error("<attribution> does not specify android:label");
             }
         } finally {
             sa.recycle();
@@ -77,14 +83,15 @@
 
             String tagName = parser.getName();
             if (tagName.equals("inherit-from")) {
-                sa = res.obtainAttributes(parser, R.styleable.AndroidManifestFeatureInheritFrom);
+                sa = res.obtainAttributes(parser,
+                        R.styleable.AndroidManifestAttributionInheritFrom);
                 if (sa == null) {
                     return input.error("<inherit-from> could not be parsed");
                 }
 
                 try {
                     String inheritFromId = sa.getNonConfigurationString(
-                            R.styleable.AndroidManifestFeatureInheritFrom_featureId,0);
+                            R.styleable.AndroidManifestAttributionInheritFrom_tag, 0);
 
                     if (inheritFrom == null) {
                         inheritFrom = new ArrayList<>();
@@ -94,7 +101,7 @@
                     sa.recycle();
                 }
             } else {
-                return input.error("Bad element under <feature>: " + tagName);
+                return input.error("Bad element under <attribution>: " + tagName);
             }
         }
 
@@ -104,6 +111,6 @@
             ((ArrayList) inheritFrom).trimToSize();
         }
 
-        return input.success(new ParsedFeature(featureId, label, inheritFrom));
+        return input.success(new ParsedAttribution(attributionTag, label, inheritFrom));
     }
 }
diff --git a/core/java/android/content/pm/parsing/component/ParsedFeature.java b/core/java/android/content/pm/parsing/component/ParsedFeature.java
deleted file mode 100644
index b8a9098..0000000
--- a/core/java/android/content/pm/parsing/component/ParsedFeature.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * Copyright (C) 2020 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.content.pm.parsing.component;
-
-import android.annotation.NonNull;
-import android.annotation.Nullable;
-import android.annotation.StringRes;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.util.ArraySet;
-
-import com.android.internal.util.DataClass;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * A {@link android.R.styleable#AndroidManifestFeature &lt;feature&gt;} tag parsed from the
- * manifest.
- *
- * @hide
- */
-@DataClass(genAidl = false)
-public class ParsedFeature implements Parcelable {
-    /** Maximum length of featureId */
-    public static final int MAX_FEATURE_ID_LEN = 50;
-
-    /** Maximum amount of features per package */
-    private static final int MAX_NUM_FEATURES = 1000;
-
-    /** Id of the feature */
-    public final @NonNull String id;
-
-    /** User visible label fo the feature */
-    public final @StringRes int label;
-
-    /** Ids of previously declared features this feature inherits from */
-    public final @NonNull List<String> inheritFrom;
-
-    /**
-     * @return Is this set of features a valid combination for a single package?
-     */
-    public static boolean isCombinationValid(@Nullable List<ParsedFeature> features) {
-        if (features == null) {
-            return true;
-        }
-
-        ArraySet<String> featureIds = new ArraySet<>(features.size());
-        ArraySet<String> inheritFromFeatureIds = new ArraySet<>();
-
-        int numFeatures = features.size();
-        if (numFeatures > MAX_NUM_FEATURES) {
-            return false;
-        }
-
-        for (int featureNum = 0; featureNum < numFeatures; featureNum++) {
-            boolean wasAdded = featureIds.add(features.get(featureNum).id);
-            if (!wasAdded) {
-                // feature id is not unique
-                return false;
-            }
-        }
-
-        for (int featureNum = 0; featureNum < numFeatures; featureNum++) {
-            ParsedFeature feature = features.get(featureNum);
-
-            int numInheritFrom = feature.inheritFrom.size();
-            for (int inheritFromNum = 0; inheritFromNum < numInheritFrom; inheritFromNum++) {
-                String inheritFrom = feature.inheritFrom.get(inheritFromNum);
-
-                if (featureIds.contains(inheritFrom)) {
-                    // Cannot inherit from a feature that is still defined
-                    return false;
-                }
-
-                boolean wasAdded = inheritFromFeatureIds.add(inheritFrom);
-                if (!wasAdded) {
-                    // inheritFrom is not unique
-                    return false;
-                }
-            }
-        }
-
-        return true;
-    }
-
-
-
-    // Code below generated by codegen v1.0.14.
-    //
-    // DO NOT MODIFY!
-    // CHECKSTYLE:OFF Generated code
-    //
-    // To regenerate run:
-    // $ codegen $ANDROID_BUILD_TOP/frameworks/base/core/java/android/content/pm/parsing/component/ParsedFeature.java
-    //
-    // To exclude the generated code from IntelliJ auto-formatting enable (one-time):
-    //   Settings > Editor > Code Style > Formatter Control
-    //@formatter:off
-
-
-    @android.annotation.IntDef(prefix = "MAX_", value = {
-        MAX_FEATURE_ID_LEN,
-        MAX_NUM_FEATURES
-    })
-    @java.lang.annotation.Retention(java.lang.annotation.RetentionPolicy.SOURCE)
-    @DataClass.Generated.Member
-    public @interface Max {}
-
-    @DataClass.Generated.Member
-    public static String maxToString(@Max int value) {
-        switch (value) {
-            case MAX_FEATURE_ID_LEN:
-                    return "MAX_FEATURE_ID_LEN";
-            case MAX_NUM_FEATURES:
-                    return "MAX_NUM_FEATURES";
-            default: return Integer.toHexString(value);
-        }
-    }
-
-    /**
-     * Creates a new ParsedFeature.
-     *
-     * @param id
-     *   Id of the feature
-     * @param label
-     *   User visible label fo the feature
-     * @param inheritFrom
-     *   Ids of previously declared features this feature inherits from
-     */
-    @DataClass.Generated.Member
-    public ParsedFeature(
-            @NonNull String id,
-            @StringRes int label,
-            @NonNull List<String> inheritFrom) {
-        this.id = id;
-        com.android.internal.util.AnnotationValidations.validate(
-                NonNull.class, null, id);
-        this.label = label;
-        com.android.internal.util.AnnotationValidations.validate(
-                StringRes.class, null, label);
-        this.inheritFrom = inheritFrom;
-        com.android.internal.util.AnnotationValidations.validate(
-                NonNull.class, null, inheritFrom);
-
-        // onConstructed(); // You can define this method to get a callback
-    }
-
-    @Override
-    @DataClass.Generated.Member
-    public void writeToParcel(@NonNull Parcel dest, int flags) {
-        // You can override field parcelling by defining methods like:
-        // void parcelFieldName(Parcel dest, int flags) { ... }
-
-        dest.writeString(id);
-        dest.writeInt(label);
-        dest.writeStringList(inheritFrom);
-    }
-
-    @Override
-    @DataClass.Generated.Member
-    public int describeContents() { return 0; }
-
-    /** @hide */
-    @SuppressWarnings({"unchecked", "RedundantCast"})
-    @DataClass.Generated.Member
-    protected ParsedFeature(@NonNull Parcel in) {
-        // You can override field unparcelling by defining methods like:
-        // static FieldType unparcelFieldName(Parcel in) { ... }
-
-        String _id = in.readString();
-        int _label = in.readInt();
-        List<String> _inheritFrom = new ArrayList<>();
-        in.readStringList(_inheritFrom);
-
-        this.id = _id;
-        com.android.internal.util.AnnotationValidations.validate(
-                NonNull.class, null, id);
-        this.label = _label;
-        com.android.internal.util.AnnotationValidations.validate(
-                StringRes.class, null, label);
-        this.inheritFrom = _inheritFrom;
-        com.android.internal.util.AnnotationValidations.validate(
-                NonNull.class, null, inheritFrom);
-
-        // onConstructed(); // You can define this method to get a callback
-    }
-
-    @DataClass.Generated.Member
-    public static final @NonNull Parcelable.Creator<ParsedFeature> CREATOR
-            = new Parcelable.Creator<ParsedFeature>() {
-        @Override
-        public ParsedFeature[] newArray(int size) {
-            return new ParsedFeature[size];
-        }
-
-        @Override
-        public ParsedFeature createFromParcel(@NonNull Parcel in) {
-            return new ParsedFeature(in);
-        }
-    };
-
-    @DataClass.Generated(
-            time = 1581379861853L,
-            codegenVersion = "1.0.14",
-            sourceFile = "frameworks/base/core/java/android/content/pm/parsing/component/ParsedFeature.java",
-            inputSignatures = "public static final  int MAX_FEATURE_ID_LEN\nprivate static final  int MAX_NUM_FEATURES\npublic final @android.annotation.NonNull java.lang.String id\npublic final @android.annotation.StringRes int label\npublic final @android.annotation.NonNull java.util.List<java.lang.String> inheritFrom\npublic static  boolean isCombinationValid(java.util.List<android.content.pm.parsing.component.ParsedFeature>)\nclass ParsedFeature extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genAidl=false)")
-    @Deprecated
-    private void __metadata() {}
-
-
-    //@formatter:on
-    // End of generated code
-
-}
diff --git a/core/java/android/hardware/biometrics/IBiometricServiceReceiverInternal.aidl b/core/java/android/hardware/biometrics/IBiometricServiceReceiverInternal.aidl
index 61310f3..8bcaf82 100644
--- a/core/java/android/hardware/biometrics/IBiometricServiceReceiverInternal.aidl
+++ b/core/java/android/hardware/biometrics/IBiometricServiceReceiverInternal.aidl
@@ -35,7 +35,7 @@
     // Notifies that a biometric has been acquired.
     void onAcquired(int acquiredInfo, String message);
     // Notifies that the SystemUI dialog has been dismissed.
-    void onDialogDismissed(int reason);
+    void onDialogDismissed(int reason, in byte[] credentialAttestation);
     // Notifies that the user has pressed the "try again" button on SystemUI
     void onTryAgainPressed();
     // Notifies that the user has pressed the "use password" button on SystemUI
diff --git a/core/java/android/hardware/camera2/CameraCharacteristics.java b/core/java/android/hardware/camera2/CameraCharacteristics.java
index b3a1ee2..7e72b73d 100644
--- a/core/java/android/hardware/camera2/CameraCharacteristics.java
+++ b/core/java/android/hardware/camera2/CameraCharacteristics.java
@@ -2884,12 +2884,12 @@
      * generated according to the documented
      * {@link android.hardware.camera2.CameraDevice#createCaptureSession guideline} for each device
      * which has its Id present in the set returned by
-     * {@link android.hardware.camera2.CameraManager#getConcurrentStreamingCameraIds}.
+     * {@link android.hardware.camera2.CameraManager#getConcurrentCameraIds}.
      * Clients can use the array as a quick reference to find an appropriate camera stream
      * combination.
      * The mandatory stream combination array will be {@code null} in case the device is not a part
      * of at least one set of combinations returned by
-     * {@link android.hardware.camera2.CameraManager#getConcurrentStreamingCameraIds}.</p>
+     * {@link android.hardware.camera2.CameraManager#getConcurrentCameraIds}.</p>
      * <p><b>Optional</b> - The value for this key may be {@code null} on some devices.</p>
      */
     @PublicKey
diff --git a/core/java/android/hardware/camera2/CameraDevice.java b/core/java/android/hardware/camera2/CameraDevice.java
index cc0c1a30..30ee326 100644
--- a/core/java/android/hardware/camera2/CameraDevice.java
+++ b/core/java/android/hardware/camera2/CameraDevice.java
@@ -681,7 +681,7 @@
      * </p>
      *
      *<p>Devices capable of streaming concurrently with other devices as described by
-     * {@link android.hardware.camera2.CameraManager#getConcurrentStreamingCameraIds} have the
+     * {@link android.hardware.camera2.CameraManager#getConcurrentCameraIds} have the
      * following guaranteed streams (when streaming concurrently with other devices)</p>
      *
      * <table>
diff --git a/core/java/android/hardware/camera2/CameraManager.java b/core/java/android/hardware/camera2/CameraManager.java
index a091f84..e81c649 100644
--- a/core/java/android/hardware/camera2/CameraManager.java
+++ b/core/java/android/hardware/camera2/CameraManager.java
@@ -160,8 +160,8 @@
      * @throws CameraAccessException if the camera device has been disconnected.
      */
     @NonNull
-    public Set<Set<String>> getConcurrentStreamingCameraIds() throws CameraAccessException {
-        return CameraManagerGlobal.get().getConcurrentStreamingCameraIds();
+    public Set<Set<String>> getConcurrentCameraIds() throws CameraAccessException {
+        return CameraManagerGlobal.get().getConcurrentCameraIds();
     }
 
     /**
@@ -189,11 +189,11 @@
      *
      * @return {@code true} if the given combination of session configurations and corresponding
      *                      camera ids are concurrently supported by the camera sub-system,
-     *         {@code false} otherwise.
+     *         {@code false} otherwise OR if the set of camera devices provided is not a subset of
+     *                       those returned by {@link #getConcurrentCameraIds}.
      *
-     * @throws IllegalArgumentException if the set of camera devices provided is not a subset of
-     *                                  those returned by getConcurrentStreamingCameraIds()
      * @throws CameraAccessException if one of the camera devices queried is no longer connected.
+     *
      */
     @RequiresPermission(android.Manifest.permission.CAMERA)
     public boolean isConcurrentSessionConfigurationSupported(
@@ -486,7 +486,7 @@
                             "Camera service is currently unavailable");
                     }
                     cameraUser = cameraService.connectDevice(callbacks, cameraId,
-                            mContext.getOpPackageName(), mContext.getFeatureId(), uid);
+                            mContext.getOpPackageName(), mContext.getAttributionTag(), uid);
                 } else {
                     // Use legacy camera implementation for HAL1 devices
                     int id;
@@ -1183,7 +1183,7 @@
 
             try {
                 ConcurrentCameraIdCombination[] cameraIdCombinations =
-                        cameraService.getConcurrentStreamingCameraIds();
+                        cameraService.getConcurrentCameraIds();
                 for (ConcurrentCameraIdCombination comb : cameraIdCombinations) {
                     mConcurrentCameraIdCombinations.add(comb.getConcurrentCameraIdCombination());
                 }
@@ -1372,7 +1372,7 @@
             return cameraIds;
         }
 
-        public @NonNull Set<Set<String>> getConcurrentStreamingCameraIds() {
+        public @NonNull Set<Set<String>> getConcurrentCameraIds() {
             Set<Set<String>> concurrentStreamingCameraIds = null;
             synchronized (mLock) {
                 // Try to make sure we have an up-to-date list of concurrent camera devices.
@@ -1398,7 +1398,7 @@
 
             synchronized (mLock) {
                 // Go through all the elements and check if the camera ids are valid at least /
-                // belong to one of the combinations returned by getConcurrentStreamingCameraIds()
+                // belong to one of the combinations returned by getConcurrentCameraIds()
                 boolean subsetFound = false;
                 for (Set<String> combination : mConcurrentCameraIdCombinations) {
                     if (combination.containsAll(cameraIdsAndSessionConfigurations.keySet())) {
@@ -1406,9 +1406,9 @@
                     }
                 }
                 if (!subsetFound) {
-                    throw new IllegalArgumentException(
-                            "The set of camera ids provided is not a subset of"
-                            + "getConcurrentStreamingCameraIds");
+                    Log.v(TAG, "isConcurrentSessionConfigurationSupported called with a subset of"
+                            + "camera ids not returned by getConcurrentCameraIds");
+                    return false;
                 }
                 CameraIdAndSessionConfiguration [] cameraIdsAndConfigs =
                         new CameraIdAndSessionConfiguration[size];
@@ -1436,10 +1436,10 @@
 
       /**
         * Helper function to find out if a camera id is in the set of combinations returned by
-        * getConcurrentStreamingCameraIds()
+        * getConcurrentCameraIds()
         * @param cameraId the unique identifier of the camera device to query
         * @return Whether the camera device was found in the set of combinations returned by
-        *         getConcurrentStreamingCameraIds
+        *         getConcurrentCameraIds
         */
         public boolean cameraIdHasConcurrentStreamsLocked(String cameraId) {
             if (!mDeviceStatus.containsKey(cameraId)) {
diff --git a/core/java/android/hardware/camera2/params/MandatoryStreamCombination.java b/core/java/android/hardware/camera2/params/MandatoryStreamCombination.java
index f0fab6a..20d9c30 100644
--- a/core/java/android/hardware/camera2/params/MandatoryStreamCombination.java
+++ b/core/java/android/hardware/camera2/params/MandatoryStreamCombination.java
@@ -721,7 +721,7 @@
         /**
           * Retrieve a list of all available mandatory concurrent stream combinations.
           * This method should only be called for devices which are listed in combinations returned
-          * by CameraManager.getConcurrentStreamingCameraIds.
+          * by CameraManager.getConcurrentCameraIds.
           *
           * @return a non-modifiable list of supported mandatory concurrent stream combinations.
           */
diff --git a/core/java/android/net/KeepalivePacketData.java b/core/java/android/net/KeepalivePacketData.java
index 2b8b7e6..6c0ba2f 100644
--- a/core/java/android/net/KeepalivePacketData.java
+++ b/core/java/android/net/KeepalivePacketData.java
@@ -22,7 +22,6 @@
 import android.annotation.NonNull;
 import android.annotation.SystemApi;
 import android.net.util.IpUtils;
-import android.os.Parcel;
 import android.util.Log;
 
 import java.net.InetAddress;
@@ -30,7 +29,6 @@
 /**
  * Represents the actual packets that are sent by the
  * {@link android.net.SocketKeepalive} API.
- *
  * @hide
  */
 @SystemApi
@@ -54,6 +52,9 @@
     /** Packet data. A raw byte string of packet data, not including the link-layer header. */
     private final byte[] mPacket;
 
+    // Note: If you add new fields, please modify the parcelling code in the child classes.
+
+
     // This should only be constructed via static factory methods, such as
     // nattKeepalivePacket.
     /**
@@ -87,21 +88,4 @@
         return mPacket.clone();
     }
 
-    /** @hide */
-    public void writeToParcel(Parcel out, int flags) {
-        out.writeString(srcAddress.getHostAddress());
-        out.writeString(dstAddress.getHostAddress());
-        out.writeInt(srcPort);
-        out.writeInt(dstPort);
-        out.writeByteArray(mPacket);
-    }
-
-    /** @hide */
-    protected KeepalivePacketData(Parcel in) {
-        srcAddress = NetworkUtils.numericToInetAddress(in.readString());
-        dstAddress = NetworkUtils.numericToInetAddress(in.readString());
-        srcPort = in.readInt();
-        dstPort = in.readInt();
-        mPacket = in.createByteArray();
-    }
 }
diff --git a/core/java/android/os/Looper.java b/core/java/android/os/Looper.java
index b478dbe..a7e3263 100644
--- a/core/java/android/os/Looper.java
+++ b/core/java/android/os/Looper.java
@@ -77,6 +77,7 @@
     @UnsupportedAppUsage
     final MessageQueue mQueue;
     final Thread mThread;
+    private boolean mInLoop;
 
     @UnsupportedAppUsage
     private Printer mLogging;
@@ -155,6 +156,12 @@
         if (me == null) {
             throw new RuntimeException("No Looper; Looper.prepare() wasn't called on this thread.");
         }
+        if (me.mInLoop) {
+            Slog.w(TAG, "Loop again would have the queued messages be executed"
+                    + " before this one completed.");
+        }
+
+        me.mInLoop = true;
         final MessageQueue queue = me.mQueue;
 
         // Make sure the identity of this thread is that of the local process,
diff --git a/core/java/android/os/Users.md b/core/java/android/os/Users.md
new file mode 100644
index 0000000..3bbbe54
--- /dev/null
+++ b/core/java/android/os/Users.md
@@ -0,0 +1,109 @@
+<!--
+  Copyright (C) 2020 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
+  -->
+
+# Users for system developers
+
+## Concepts
+
+### User
+
+A user of a device e.g. usually a human being. Each user has its own home screen.
+
+#### User Profile
+
+A user can have multiple profiles. E.g. one for the private life and one for work. Each profile
+has a different set of apps and accounts but they share one home screen. All profiles of a
+profile group can be active at the same time.
+
+Each profile has a separate [`userId`](#int-userid). Unless needed user profiles are treated as
+completely separate users.
+
+#### Profile Group
+
+All user profiles that share a home screen. You can list the profiles of a user via
+`UserManager#getEnabledProfiles` (you usually don't deal with disabled profiles)
+
+#### Foreground user vs background user
+
+Only a single user profile group can be in the foreground. This is the user profile the user
+currently interacts with.
+
+#### Parent user (profile)
+
+The main profile of a profile group, usually the personal (as opposed to work) profile. Get this via
+`UserManager#getProfileParent` (returns `null` if the user does not have profiles)
+
+#### Managed user (profile)
+
+The other profiles of a profile group. The name comes from the fact that these profiles are usually
+managed by a device policy controller app. You can create a managed profile from within the device
+policy controller app on your phone.
+
+#### Account
+
+An account of a user profile with a (usually internet based) service. E.g. aname@gmail.com or
+aname@yahoo.com. Each profile can have multiple accounts. A profile does not have to have a
+account.
+
+## Data types
+
+### int userId
+
+... usually marked as `@UserIdInt`
+
+The id of a user profile. List all users via `adb shell dumpsys user`. There is no data type for a
+user, all you can do is using the user id of the parent profile as a proxy for the user.
+
+### int uid
+
+Identity of an app. This is the same as a Linux uid, but in Android there is one uid per package,
+per user.
+
+It is highly discouraged, but uids can be shared between multiple packages using the
+`android:sharedUserId` manifest attribute.
+
+### class UserHandle
+
+A wrapper for userId. Used esp. in public APIs instead of `int userId` as it clearly distinguishes
+from uid.
+
+## Security model
+
+Multiple packages can share an uid by using `android:sharedUserId` manifest attribute. If packages
+share a uid they can run in the same process via `android:process` manifest attribute. Further file
+level access is also tracked by uid. Hence any security or privacy mechanism needs to be built on
+a uid granularity.
+
+On the other hand apps belonging to the same user cannot see each others files. They can only
+interact via activity launches, broadcasts, providers, and service bindings. All of them can be be
+protected by [permissions](../permission/Permissions.md). Hence any new general communication
+mechanism should be access controlled by permissions.
+
+## Lifecycle
+
+A system service should deal with users being started and stopped by overriding
+`SystemService.onSwitchUser` and `SystemService.onStopUser`.
+
+If users profiles become inactive the system should stop all apps of this profile from interacting
+with other apps or the system.
+
+Another important lifecycle event is `onUnlockUser`. Only for unlocked user profiles you can access
+all data, e.g. which packages are installed.
+
+You only want to deal with user profiles that
+
+- are in the profile group of the foreground user
+- the user profile is unlocked and not yet stopped
diff --git a/core/java/android/os/incremental/IncrementalNewFileParams.aidl b/core/java/android/os/incremental/IncrementalNewFileParams.aidl
index 182732c..8faf158 100644
--- a/core/java/android/os/incremental/IncrementalNewFileParams.aidl
+++ b/core/java/android/os/incremental/IncrementalNewFileParams.aidl
@@ -16,8 +16,6 @@
 
 package android.os.incremental;
 
-import android.os.incremental.IncrementalSignature;
-
 /**
  * All the parameters to create a new file on IncFS
  * FileId is a 16 byte-long identifier.
@@ -27,5 +25,5 @@
     long size;
     byte[] fileId;
     byte[] metadata;
-    @nullable IncrementalSignature signature;
+    @nullable byte[] signature;
 }
diff --git a/core/java/android/os/incremental/IncrementalStorage.java b/core/java/android/os/incremental/IncrementalStorage.java
index bf31bc2..7092751 100644
--- a/core/java/android/os/incremental/IncrementalStorage.java
+++ b/core/java/android/os/incremental/IncrementalStorage.java
@@ -20,8 +20,6 @@
 import android.annotation.Nullable;
 import android.os.RemoteException;
 
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.nio.ByteBuffer;
@@ -180,11 +178,12 @@
             if (id == null && metadata == null) {
                 throw new IOException("File ID and metadata cannot both be null");
             }
+            validateV4Signature(v4signatureBytes);
             final IncrementalNewFileParams params = new IncrementalNewFileParams();
             params.size = size;
             params.metadata = (metadata == null ? new byte[0] : metadata);
             params.fileId = idToBytes(id);
-            params.signature = parseV4Signature(v4signatureBytes);
+            params.signature = v4signatureBytes;
             int res = mService.makeFile(mId, path, params);
             if (res != 0) {
                 throw new IOException("makeFile() failed with errno " + -res);
@@ -415,27 +414,23 @@
         return new UUID(msb, lsb);
     }
 
-    private static final int INCFS_HASH_SHA256 = 1;
     private static final int INCFS_MAX_HASH_SIZE = 32; // SHA256
     private static final int INCFS_MAX_ADD_DATA_SIZE = 128;
 
     /**
      * Deserialize and validate v4 signature bytes.
      */
-    private static IncrementalSignature parseV4Signature(@Nullable byte[] v4signatureBytes)
+    private static void validateV4Signature(@Nullable byte[] v4signatureBytes)
             throws IOException {
         if (v4signatureBytes == null || v4signatureBytes.length == 0) {
-            return null;
+            return;
         }
 
         final V4Signature signature;
-        try (DataInputStream input = new DataInputStream(
-                new ByteArrayInputStream(v4signatureBytes))) {
-            try {
-                signature = V4Signature.readFrom(input);
-            } catch (IOException e) {
-                throw new IOException("Failed to read v4 signature:", e);
-            }
+        try {
+            signature = V4Signature.readFrom(v4signatureBytes);
+        } catch (IOException e) {
+            throw new IOException("Failed to read v4 signature:", e);
         }
 
         if (!signature.isVersionSupported()) {
@@ -443,25 +438,27 @@
                     + " is not supported");
         }
 
-        final byte[] rootHash = signature.verityRootHash;
-        final byte[] additionalData = signature.v3Digest;
-        final byte[] pkcs7Signature = signature.pkcs7SignatureBlock;
+        final V4Signature.HashingInfo hashingInfo = V4Signature.HashingInfo.fromByteArray(
+                signature.hashingInfo);
+        final V4Signature.SigningInfo signingInfo = V4Signature.SigningInfo.fromByteArray(
+                signature.signingInfo);
 
-        if (rootHash.length != INCFS_MAX_HASH_SIZE) {
-            throw new IOException("rootHash has to be " + INCFS_MAX_HASH_SIZE + " bytes");
+        if (hashingInfo.hashAlgorithm != V4Signature.HASHING_ALGORITHM_SHA256) {
+            throw new IOException("Unsupported hashAlgorithm: " + hashingInfo.hashAlgorithm);
         }
-        if (additionalData.length > INCFS_MAX_ADD_DATA_SIZE) {
+        if (hashingInfo.log2BlockSize != V4Signature.LOG2_BLOCK_SIZE_4096_BYTES) {
+            throw new IOException("Unsupported log2BlockSize: " + hashingInfo.log2BlockSize);
+        }
+        if (hashingInfo.salt != null && hashingInfo.salt.length > 0) {
+            throw new IOException("Unsupported salt: " + hashingInfo.salt);
+        }
+        if (hashingInfo.rawRootHash.length != INCFS_MAX_HASH_SIZE) {
+            throw new IOException("rawRootHash has to be " + INCFS_MAX_HASH_SIZE + " bytes");
+        }
+        if (signingInfo.additionalData.length > INCFS_MAX_ADD_DATA_SIZE) {
             throw new IOException(
                     "additionalData has to be at most " + INCFS_MAX_ADD_DATA_SIZE + " bytes");
         }
-
-        IncrementalSignature result = new IncrementalSignature();
-        result.hashAlgorithm = INCFS_HASH_SHA256;
-        result.rootHash = rootHash;
-        result.additionalData = additionalData;
-        result.signature = pkcs7Signature;
-
-        return result;
     }
 
     /**
diff --git a/core/java/android/os/incremental/V4Signature.java b/core/java/android/os/incremental/V4Signature.java
index 6d334f5..71f931d 100644
--- a/core/java/android/os/incremental/V4Signature.java
+++ b/core/java/android/os/incremental/V4Signature.java
@@ -20,9 +20,12 @@
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.EOFException;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
 
 /**
  * V4 signature fields.
@@ -31,30 +34,95 @@
  */
 public class V4Signature {
     public static final String EXT = ".idsig";
-    public static final int SUPPORTED_VERSION = 1;
+    public static final int SUPPORTED_VERSION = 2;
 
-    public final int version;
-    public final byte[] verityRootHash;
-    public final byte[] v3Digest;
-    public final byte[] pkcs7SignatureBlock;
+    public static final int HASHING_ALGORITHM_SHA256 = 1;
+    public static final byte LOG2_BLOCK_SIZE_4096_BYTES = 12;
+
+    /**
+     * IncFS hashing data.
+     */
+    public static class HashingInfo {
+        public final int hashAlgorithm; // only 1 == SHA256 supported
+        public final byte log2BlockSize; // only 12 (block size 4096) supported now
+        public final byte[] salt; // used exactly as in fs-verity, 32 bytes max
+        public final byte[] rawRootHash; // salted digest of the first Merkle tree page
+
+        HashingInfo(int hashAlgorithm, byte log2BlockSize, byte[] salt, byte[] rawRootHash) {
+            this.hashAlgorithm = hashAlgorithm;
+            this.log2BlockSize = log2BlockSize;
+            this.salt = salt;
+            this.rawRootHash = rawRootHash;
+        }
+
+        /**
+         * Constructs HashingInfo from byte array.
+         */
+        public static HashingInfo fromByteArray(byte[] bytes) throws IOException {
+            ByteBuffer buffer = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
+            final int hashAlgorithm = buffer.getInt();
+            final byte log2BlockSize = buffer.get();
+            byte[] salt = readBytes(buffer);
+            byte[] rawRootHash = readBytes(buffer);
+            return new HashingInfo(hashAlgorithm, log2BlockSize, salt, rawRootHash);
+        }
+    }
+
+    /**
+     * V4 signature data.
+     */
+    public static class SigningInfo {
+        public final byte[] v3Digest;  // used to match with the corresponding APK
+        public final byte[] certificate; // ASN.1 DER form
+        public final byte[] additionalData; // a free-form binary data blob
+        public final byte[] publicKey; // ASN.1 DER, must match the certificate
+        public final int signatureAlgorithmId; // see the APK v2 doc for the list
+        public final byte[] signature;
+
+        SigningInfo(byte[] v3Digest, byte[] certificate, byte[] additionalData,
+                byte[] publicKey, int signatureAlgorithmId, byte[] signature) {
+            this.v3Digest = v3Digest;
+            this.certificate = certificate;
+            this.additionalData = additionalData;
+            this.publicKey = publicKey;
+            this.signatureAlgorithmId = signatureAlgorithmId;
+            this.signature = signature;
+        }
+
+        /**
+         * Constructs SigningInfo from byte array.
+         */
+        public static SigningInfo fromByteArray(byte[] bytes) throws IOException {
+            ByteBuffer buffer = ByteBuffer.wrap(bytes).order(ByteOrder.LITTLE_ENDIAN);
+            byte[] v3Digest = readBytes(buffer);
+            byte[] certificate = readBytes(buffer);
+            byte[] additionalData = readBytes(buffer);
+            byte[] publicKey = readBytes(buffer);
+            int signatureAlgorithmId = buffer.getInt();
+            byte[] signature = readBytes(buffer);
+            return new SigningInfo(v3Digest, certificate, additionalData, publicKey,
+                    signatureAlgorithmId, signature);
+        }
+    }
+
+    public final int version; // Always 2 for now.
+    public final byte[] hashingInfo;
+    public final byte[] signingInfo; // Passed as-is to the kernel. Can be retrieved later.
 
     /**
      * Construct a V4Signature from .idsig file.
      */
     public static V4Signature readFrom(ParcelFileDescriptor pfd) throws IOException {
-        final ParcelFileDescriptor dupedFd = pfd.dup();
-        final ParcelFileDescriptor.AutoCloseInputStream fdInputStream =
-                new ParcelFileDescriptor.AutoCloseInputStream(dupedFd);
-        try (DataInputStream stream = new DataInputStream(fdInputStream)) {
+        try (InputStream stream = new ParcelFileDescriptor.AutoCloseInputStream(pfd.dup())) {
             return readFrom(stream);
         }
     }
 
     /**
-     * Construct a V4Signature from .idsig file.
+     * Construct a V4Signature from a byte array.
      */
     public static V4Signature readFrom(byte[] bytes) throws IOException {
-        try (DataInputStream stream = new DataInputStream(new ByteArrayInputStream(bytes))) {
+        try (InputStream stream = new ByteArrayInputStream(bytes)) {
             return readFrom(stream);
         }
     }
@@ -63,51 +131,131 @@
      * Store the V4Signature to a byte-array.
      */
     public byte[] toByteArray() {
-        try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
-            try (DataOutputStream steam = new DataOutputStream(byteArrayOutputStream)) {
-                this.writeTo(steam);
-                steam.flush();
-            }
-            return byteArrayOutputStream.toByteArray();
+        try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
+            this.writeTo(stream);
+            return stream.toByteArray();
         } catch (IOException e) {
             return null;
         }
     }
 
-    boolean isVersionSupported() {
+    /**
+     * Combines necessary data to a signed data blob.
+     * The blob can be validated against signingInfo.signature.
+     *
+     * @param fileSize - size of the signed file (APK)
+     */
+    public static byte[] getSigningData(long fileSize, HashingInfo hashingInfo,
+            SigningInfo signingInfo) {
+        final int size =
+                4/*size*/ + 8/*fileSize*/ + 4/*hash_algorithm*/ + 1/*log2_blocksize*/ + bytesSize(
+                        hashingInfo.salt) + bytesSize(hashingInfo.rawRootHash) + bytesSize(
+                        signingInfo.v3Digest) + bytesSize(signingInfo.certificate) + bytesSize(
+                        signingInfo.additionalData);
+        ByteBuffer buffer = ByteBuffer.allocate(size).order(ByteOrder.LITTLE_ENDIAN);
+        buffer.putInt(size);
+        buffer.putLong(fileSize);
+        buffer.putInt(hashingInfo.hashAlgorithm);
+        buffer.put(hashingInfo.log2BlockSize);
+        writeBytes(buffer, hashingInfo.salt);
+        writeBytes(buffer, hashingInfo.rawRootHash);
+        writeBytes(buffer, signingInfo.v3Digest);
+        writeBytes(buffer, signingInfo.certificate);
+        writeBytes(buffer, signingInfo.additionalData);
+        return buffer.array();
+    }
+
+    public boolean isVersionSupported() {
         return this.version == SUPPORTED_VERSION;
     }
 
-    static V4Signature readFrom(DataInputStream stream) throws IOException {
-        final int version = stream.readInt();
-        byte[] verityRootHash = readBytes(stream);
-        byte[] v3Digest = readBytes(stream);
-        byte[] pkcs7SignatureBlock = readBytes(stream);
-        return new V4Signature(version, verityRootHash, v3Digest, pkcs7SignatureBlock);
-    }
-
-    V4Signature(int version, byte[] verityRootHash, byte[] v3Digest, byte[] pkcs7SignatureBlock) {
+    private V4Signature(int version, byte[] hashingInfo, byte[] signingInfo) {
         this.version = version;
-        this.verityRootHash = verityRootHash;
-        this.v3Digest = v3Digest;
-        this.pkcs7SignatureBlock = pkcs7SignatureBlock;
+        this.hashingInfo = hashingInfo;
+        this.signingInfo = signingInfo;
     }
 
-    void writeTo(DataOutputStream stream) throws IOException {
-        stream.writeInt(this.version);
-        writeBytes(stream, this.verityRootHash);
-        writeBytes(stream, this.v3Digest);
-        writeBytes(stream, this.pkcs7SignatureBlock);
+    private static V4Signature readFrom(InputStream stream) throws IOException {
+        final int version = readIntLE(stream);
+        final byte[] hashingInfo = readBytes(stream);
+        final byte[] signingInfo = readBytes(stream);
+        return new V4Signature(version, hashingInfo, signingInfo);
     }
 
-    private static byte[] readBytes(DataInputStream stream) throws IOException {
-        byte[] result = new byte[stream.readInt()];
-        stream.read(result);
-        return result;
+    private void writeTo(OutputStream stream) throws IOException {
+        writeIntLE(stream, this.version);
+        writeBytes(stream, this.hashingInfo);
+        writeBytes(stream, this.signingInfo);
     }
 
-    private static void writeBytes(DataOutputStream stream, byte[] bytes) throws IOException {
-        stream.writeInt(bytes.length);
+    // Utility methods.
+    private static int bytesSize(byte[] bytes) {
+        return 4/*length*/ + (bytes == null ? 0 : bytes.length);
+    }
+
+    private static void readFully(InputStream stream, byte[] buffer) throws IOException {
+        int len = buffer.length;
+        int n = 0;
+        while (n < len) {
+            int count = stream.read(buffer, n, len - n);
+            if (count < 0) {
+                throw new EOFException();
+            }
+            n += count;
+        }
+    }
+
+    private static int readIntLE(InputStream stream) throws IOException {
+        final byte[] buffer = new byte[4];
+        readFully(stream, buffer);
+        return ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).getInt();
+    }
+
+    private static void writeIntLE(OutputStream stream, int v) throws IOException {
+        final byte[] buffer = ByteBuffer.wrap(new byte[4]).order(ByteOrder.LITTLE_ENDIAN).putInt(
+                v).array();
+        stream.write(buffer);
+    }
+
+    private static byte[] readBytes(InputStream stream) throws IOException {
+        try {
+            final int size = readIntLE(stream);
+            final byte[] bytes = new byte[size];
+            readFully(stream, bytes);
+            return bytes;
+        } catch (EOFException ignored) {
+            return null;
+        }
+    }
+
+    private static byte[] readBytes(ByteBuffer buffer) throws IOException {
+        if (buffer.remaining() < 4) {
+            throw new EOFException();
+        }
+        final int size = buffer.getInt();
+        if (buffer.remaining() < size) {
+            throw new EOFException();
+        }
+        final byte[] bytes = new byte[size];
+        buffer.get(bytes);
+        return bytes;
+    }
+
+    private static void writeBytes(OutputStream stream, byte[] bytes) throws IOException {
+        if (bytes == null) {
+            writeIntLE(stream, 0);
+            return;
+        }
+        writeIntLE(stream, bytes.length);
         stream.write(bytes);
     }
+
+    private static void writeBytes(ByteBuffer buffer, byte[] bytes) {
+        if (bytes == null) {
+            buffer.putInt(0);
+            return;
+        }
+        buffer.putInt(bytes.length);
+        buffer.put(bytes);
+    }
 }
diff --git a/core/java/android/permission/IPermissionController.aidl b/core/java/android/permission/IPermissionController.aidl
index 0483514..f011395 100644
--- a/core/java/android/permission/IPermissionController.aidl
+++ b/core/java/android/permission/IPermissionController.aidl
@@ -42,6 +42,6 @@
     void setRuntimePermissionGrantStateByDeviceAdmin(String callerPackageName, String packageName,
                 String permission, int grantState, in AndroidFuture callback);
     void grantOrUpgradeDefaultRuntimePermissions(in AndroidFuture callback);
-    void updateUserSensitive(in AndroidFuture callback);
     void notifyOneTimePermissionSessionTimeout(String packageName);
+    void updateUserSensitiveForApp(int uid, in AndroidFuture callback);
 }
diff --git a/core/java/android/permission/IPermissionManager.aidl b/core/java/android/permission/IPermissionManager.aidl
index 2615c98..40acb7b 100644
--- a/core/java/android/permission/IPermissionManager.aidl
+++ b/core/java/android/permission/IPermissionManager.aidl
@@ -106,4 +106,8 @@
             int importanceToResetTimer, int importanceToKeepSessionAlive);
 
     void stopOneTimePermissionSession(String packageName, int userId);
+
+    List<String> getAutoRevokeExemptionRequestedPackages(int userId);
+
+    List<String> getAutoRevokeExemptionGrantedPackages(int userId);
 }
diff --git a/core/java/android/permission/PermissionControllerManager.java b/core/java/android/permission/PermissionControllerManager.java
index 2a1857f..f08e3d25 100644
--- a/core/java/android/permission/PermissionControllerManager.java
+++ b/core/java/android/permission/PermissionControllerManager.java
@@ -46,6 +46,7 @@
 import android.os.Binder;
 import android.os.Bundle;
 import android.os.Handler;
+import android.os.Process;
 import android.os.UserHandle;
 import android.util.ArrayMap;
 import android.util.Log;
@@ -626,14 +627,26 @@
     }
 
     /**
-     * @see PermissionControllerService#onUpdateUserSensitive()
+     * @see PermissionControllerManager#updateUserSensitiveForApp
      * @hide
      */
     public void updateUserSensitive() {
+        updateUserSensitiveForApp(Process.INVALID_UID);
+    }
+
+    /**
+     * @see PermissionControllerService#onUpdateUserSensitiveForApp
+     * @hide
+     */
+    public void updateUserSensitiveForApp(int uid) {
         mRemoteService.postAsync(service -> {
             AndroidFuture<Void> future = new AndroidFuture<>();
-            service.updateUserSensitive(future);
+            service.updateUserSensitiveForApp(uid, future);
             return future;
+        }).whenComplete((res, err) -> {
+            if (err != null) {
+                Log.e(TAG, "Error updating user_sensitive flags for uid " + uid, err);
+            }
         });
     }
 
diff --git a/core/java/android/permission/PermissionControllerService.java b/core/java/android/permission/PermissionControllerService.java
index 263b2c7..4a42230 100644
--- a/core/java/android/permission/PermissionControllerService.java
+++ b/core/java/android/permission/PermissionControllerService.java
@@ -218,11 +218,14 @@
      * Called by system to update the
      * {@link PackageManager}{@code .FLAG_PERMISSION_USER_SENSITIVE_WHEN_*} flags for permissions.
      * <p>
-     * This is typically when creating a new user or upgrading either system or
-     * permission controller package.
+     *
+     * If uid is -1, updates the permission flags for all packages.
+     *
+     * Typically called by the system when a new app is installed or updated or when creating a
+     * new user or upgrading either system or permission controller package.
      */
     @BinderThread
-    public void onUpdateUserSensitivePermissionFlags() {
+    public void onUpdateUserSensitivePermissionFlags(int uid, @NonNull Runnable callback) {
         throw new AbstractMethodError("Must be overridden in implementing class");
     }
 
@@ -459,11 +462,14 @@
             }
 
             @Override
-            public void updateUserSensitive(AndroidFuture callback) {
+            public void updateUserSensitiveForApp(int uid, @NonNull AndroidFuture callback) {
                 Preconditions.checkNotNull(callback, "callback cannot be null");
 
-                onUpdateUserSensitivePermissionFlags();
-                callback.complete(null);
+                try {
+                    onUpdateUserSensitivePermissionFlags(uid, () -> callback.complete(null));
+                } catch (Exception e) {
+                    callback.completeExceptionally(e);
+                }
             }
 
             @Override
diff --git a/core/java/android/permission/PermissionManager.java b/core/java/android/permission/PermissionManager.java
index 0bd211d..8308bb3 100644
--- a/core/java/android/permission/PermissionManager.java
+++ b/core/java/android/permission/PermissionManager.java
@@ -40,11 +40,13 @@
 import android.util.Slog;
 
 import com.android.internal.annotations.Immutable;
+import com.android.internal.util.CollectionUtils;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
+import java.util.Set;
 import java.util.concurrent.Executor;
 import java.util.function.Consumer;
 
@@ -299,6 +301,46 @@
         }
     }
 
+    /**
+     * Gets the list of packages that have permissions that specified
+     * {@code requestDontAutoRevokePermissions=true} in their
+     * {@code application} manifest declaration.
+     *
+     * @return the list of packages for current user
+     * @hide
+     */
+    @SystemApi
+    @NonNull
+    @RequiresPermission(Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY)
+    public Set<String> getAutoRevokeExemptionRequestedPackages() {
+        try {
+            return CollectionUtils.toSet(mPermissionManager.getAutoRevokeExemptionRequestedPackages(
+                    mContext.getUser().getIdentifier()));
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
+    /**
+     * Gets the list of packages that have permissions that specified
+     * {@code allowDontAutoRevokePermissions=true} in their
+     * {@code application} manifest declaration.
+     *
+     * @return the list of packages for current user
+     * @hide
+     */
+    @SystemApi
+    @NonNull
+    @RequiresPermission(Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY)
+    public Set<String> getAutoRevokeExemptionGrantedPackages() {
+        try {
+            return CollectionUtils.toSet(mPermissionManager.getAutoRevokeExemptionGrantedPackages(
+                    mContext.getUser().getIdentifier()));
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
     private List<SplitPermissionInfo> splitPermissionInfoListToNonParcelableList(
             List<SplitPermissionInfoParcelable> parcelableList) {
         final int size = parcelableList.size();
diff --git a/core/java/android/permission/Permissions.md b/core/java/android/permission/Permissions.md
new file mode 100644
index 0000000..e62bd0a
--- /dev/null
+++ b/core/java/android/permission/Permissions.md
@@ -0,0 +1,832 @@
+<!--
+  Copyright (C) 2020 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
+  -->
+
+# Android permissions for system developers
+
+This document targets system developers. App developers should refer to the [public
+ documentation](https://developer.android.com/guide/topics/permissions/overview).
+
+## Definitions
+
+Each app (often called package) has a unique name called package name. Each package has a manifest
+file describing properties of the package. The android system server is in a special package named
+"android".
+
+When a package gets installed the package is (usually) assigned a unique identifier called [uid
+](../os/Users.md#int-uid).
+This is the same as a uid in Linux, but this often leads to confusion. It is easiest to see a uid
+as a unique identifier for a package.
+
+Usually an app is running in a container called a process. Each process has a unique id called
+pid, but unlike the uid the pid changes each time the process is restarted and app that are not
+currently running don't have a pid. The process container makes sure that other apps cannot
+negatively interact with an app. Processes can only interact via controlled interactions called
+remote procedure calls (RPCs). Android’s RPC mechanism is called _Binder_.
+
+As no app code can be trusted the permission need to be checked on the receiving side of the
+Binder call.
+
+For more details please take a look at [Android's security model](../os/Users.md#security-model).
+
+## Permissions for regular apps
+
+### Install time permissions
+
+The purpose of install time permissions is to control access to APIs where it does not makes sense
+to involve the user. This can be either because the API is not sensitive, or because additional
+checks exist.
+
+#### Defining a permission
+
+Any package can define a permission. For that it simply adds an entry in the manifest file
+`<permission android:name="com.example.myapp.myfirstpermission" />`
+
+Any package can do this, including the system package. When talking about [permissions for system
+ apps](#permissions-for-system-apps) we will see that it is important which package defines a
+permission.
+
+It is common good practice to prefix the permission name with the package name to avoid collisions.
+
+#### Requesting a permission
+
+Any app can request any permission via adding an entry in the manifest file like
+`<uses-permission android:name="com.example.myapp.myfirstpermission" />`
+
+A requested permission does not necessarily mean that the permission is granted. When and how a
+permission is granted depends on the protection level of the permission. If no protection level is
+set, the permission will always be granted. Such "normal" permissions can still be useful as it
+will be easy to find apps using a certain functionality on app stores and by checking `dumpsys
+package`.
+
+#### Checking a permission
+
+`Context.checkPermission(permission, pid, uid)` returns if the pid/uid has the permission. By far
+the most common case is to check the permission on the receiving end of a binder call. In this case
+the pid can be read as `Binder.callingPid()` and the uid as `Binder.callingUid()`. The uid is a
+mandatory argument as permissions are maintained per uid. The pid can be set to -1
+if not pid is available. The context class contains handy wrappers for `checkPermission`, such as
+`enforeCallingPermission` which calls checkPermission with `Binder.callingPid`/`Binder.callingUid`
+and throws a SecurityException when the permission is not granted.
+
+#### Verifying an app has an install time permission
+
+In `dumpsys package my.package.name` there are two sections. In requested permissions all
+permissions of the `uses-permission` tags are listed. In install permission the permissions with
+their grant state are listed. If an install time permission is not listed here, it is not granted.
+
+```
+Packages:
+  Package [com.android.packageinstaller] (2eb7062):
+    userId=10071
+    [...]
+    requested permissions:
+      android.permission.MANAGE_USERS
+      android.permission.INSTALL_PACKAGES
+      android.permission.DELETE_PACKAGES
+      android.permission.READ_INSTALL_SESSIONS
+      android.permission.RECEIVE_BOOT_COMPLETED
+      android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS
+      android.permission.USE_RESERVED_DISK
+      android.permission.UPDATE_APP_OPS_STATS
+      android.permission.MANAGE_APP_OPS_MODES
+      android.permission.INTERACT_ACROSS_USERS_FULL
+      android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME
+      android.permission.PACKAGE_USAGE_STATS
+    install permissions:
+      android.permission.USE_RESERVED_DISK: granted=true
+      android.permission.INSTALL_PACKAGES: granted=true
+      android.permission.RECEIVE_BOOT_COMPLETED: granted=true
+      android.permission.INTERACT_ACROSS_USERS_FULL: granted=true
+      android.permission.PACKAGE_USAGE_STATS: granted=true
+      android.permission.SUBSTITUTE_NOTIFICATION_APP_NAME: granted=true
+      android.permission.READ_INSTALL_SESSIONS: granted=true
+      android.permission.MANAGE_USERS: granted=true
+      android.permission.HIDE_NON_SYSTEM_OVERLAY_WINDOWS: granted=true
+      android.permission.MANAGE_APP_OPS_MODES: granted=true
+      android.permission.UPDATE_APP_OPS_STATS: granted=true
+      android.permission.DELETE_PACKAGES: granted=true
+```
+
+#### End-to-end: Protecting an RPC call via a permission
+
+##### Service Manifest
+
+```xml
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.example.myservice">
+    <!-- Define a permission -->
+    <permission android:name="com.android.example.myservice.MY_PERMISSION" />
+    <application>
+        <service android:name=".MyService" android:exported="true" />
+    </application>
+</manifest>
+```
+
+##### Service code
+
+```kotlin
+class MyService : Service() {
+    override fun onBind(intent: Intent?): IBinder? {
+        return object : IMyService.Stub() {
+            override fun doSomething() {
+                // Verify that calling UID has the permission
+                enforceCallingPermission(
+                    "com.android.example.myservice.MY_PERMISSION",
+                    "Need to hold permission"
+                )
+                // do something
+            }
+        }.asBinder()
+    }
+}
+```
+
+##### Caller Manifest
+
+```xml
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.example.myapp">
+    <!-- request a permission -->
+    <uses-permission android:name="com.android.example.myservice.MY_PERMISSION" />
+    <application />
+</manifest>
+```
+
+### Runtime permissions
+
+Runtime permission must be granted by the user during runtime. This is needed if the API protects
+data or functionality that is sensitive for the user. E.g. the users current location is protected
+by a runtime permission.
+
+Users want a system that is secure and privacy focused by default. User can also often not make a
+good choice when asked at the wrong time without enough context. Hence in general runtime
+permissions should be avoided and the API should be built in a way where no private data needs to be
+leaked.
+
+#### Defining a runtime permission
+
+Runtime permissions are defined in the same way as install time permissions. To tag them as runtime
+permissions the `protectionLevel` needs to be set to dangerous. Dangerous is a synonym for
+runtime permissions in the Android platform.
+
+```xml
+<uses-permission android:name="com.example.myapp.myfirstruntimepermission"
+    android:protectionLevel="dangerous" />
+```
+
+#### Requesting a runtime permission
+
+Similar to install time permissions any app can request a runtime permission by adding the 
+`<uses-permission android:name="com.example.myapp.myfirstruntimepermission" />`
+to the manifest.
+
+By default runtime permissions are not granted. The app needs to call `Activity.requestPermissions`
+during runtime to ask the user for the permission. The user might then grant or deny and once the
+decision is made the activity is called by via `Activity.onPermissionGranted`.
+
+During development and testing a runtime permission can be granted via the `pm` shell command or by
+using the `UiAutomator.grantRuntimePermission` API call. Please note that this does _not_ grant the
+[app-op](#runtime-permissions-and-app-ops) synchronously. Unless the app needs to test the actual
+permission grant flow it is recommended to grant the runtime permissions during install using
+`adb install -g /my/package.apk`.
+
+#### Checking a runtime permission
+
+For runtime permissions defined by a 3rd party apps it is fine to check a runtime
+permission like an install time permission. For system defined permissions you need to check all
+runtime permissions by using the `PermissionChecker` utility. It is good practice to use the tool
+anywhere possible.
+
+The permission checker might return `PERMISSION_DENIED_APP_OP` which should lead to a silent
+failure. This can only happen for system defined runtime permissions.
+
+##### Runtime permissions and app-ops
+
+> See [App-ops](../app/AppOps.md).
+
+The PermissionChecker code fundamentally looks like this:
+
+```kotlin
+class PermissionChecker {
+    fun checkCallingPermission(context: Context, permission: String) {
+        if (isRuntimePermission(permission)) {
+            if (context.checkPermission(uid, permission) == DENIED) {
+                 return PERMISSION_DENIED
+            }
+
+            val appOpOfPermission = AppOpsManager.permissionToOp(permission)
+            if (appOpOfPermission == null) {
+                // not platform defined
+                return PERMISSION_GRANTED
+            }
+
+            val appOpMode = appOpsManager.noteOp(appOpOfPermission)
+            if (appOpMode == AppOpsManager.MODE_ALLOWED) {
+                return PERMISSION_GRANTED
+            } else {
+                return PERMISSION_DENIED_APP_OP
+            }
+        } else {
+            return PERMISSION_DENIED
+        }
+    }
+}
+```
+
+For each platform defined runtime permission there is a matching app-op. When calling
+`AppOpsManager.noteOp` this returns either `MODE_ALLOWED` or `MODE_IGNORED`.
+
+This value is then used to decide between `PERMISSION_DENIED_APP_OP` and `PERMISSION_GRANTED`.
+
+The primary purpose of the special `PERMISSION_DENIED_APP_OP` state was to support apps targeting an
+SDK lower than 23. These apps do not understand the concept of denied runtime permissions. Hence
+they would crash when getting a `SecurityException`. To protect the users' privacy while still not
+crashing the app the special `PERMISSION_DENIED_APP_OP` mandates that the API should somehow
+silently fail.
+
+A secondary use case of the `AppOpsManager.noteOp` calls is to
+[track](../app/AppOps.md#Appops-for-tracking) which apps perform what runtime protected actions.
+
+#### Verifying an app has a runtime time permission
+
+In `dumpsys package my.package.name` the runtime permissions are listed per uid. I.e. different
+users might have different runtime permission grants and shared uids share a grant-set. If a runtime
+permission is listed as requested but not in the runtime permission section it is in it’s initial
+state, i.e. not granted.
+
+```
+Packages:
+  Package [com.google.android.GoogleCamera] (ccb6af):
+    userId=10181
+    [...]
+    requested permissions:
+      android.permission.ACCESS_COARSE_LOCATION
+      android.permission.ACCESS_FINE_LOCATION
+      android.permission.ACCESS_NETWORK_STATE
+      android.permission.ACCESS_NOTIFICATION_POLICY
+      android.permission.ACCESS_WIFI_STATE
+      android.permission.BIND_WALLPAPER
+      android.permission.CAMERA
+      android.permission.CHANGE_WIFI_STATE
+      android.permission.INTERNET
+      android.permission.GET_PACKAGE_SIZE
+      android.permission.NFC
+      android.permission.READ_SYNC_SETTINGS
+      android.permission.RECEIVE_BOOT_COMPLETED
+      android.permission.RECORD_AUDIO
+      android.permission.SET_WALLPAPER
+      android.permission.USE_CREDENTIALS
+      android.permission.VIBRATE
+      android.permission.WAKE_LOCK
+      android.permission.WRITE_EXTERNAL_STORAGE [ ... ]
+      android.permission.WRITE_SETTINGS
+      android.permission.WRITE_SYNC_SETTINGS
+      com.google.android.elmyra.permission.CONFIGURE_ASSIST_GESTURE
+      com.google.android.providers.gsf.permission.READ_GSERVICES
+      android.permission.FOREGROUND_SERVICE
+      com.google.android.googlequicksearchbox.permission.LENSVIEW_BROADCAST
+      android.permission.READ_EXTERNAL_STORAGE [ ... ]
+    [...]
+    User 0: [ ... ]
+    overlay paths:
+      runtime permissions:
+        android.permission.ACCESS_FINE_LOCATION: granted=false [ ... ]
+        android.permission.READ_EXTERNAL_STORAGE: granted=true [ ... ]
+        android.permission.ACCESS_COARSE_LOCATION: granted=false [ ... ]
+        android.permission.CAMERA: granted=true [ ... ]
+        android.permission.WRITE_EXTERNAL_STORAGE: granted=true [ ... ]
+        android.permission.RECORD_AUDIO: granted=true[ ... ]
+```
+
+#### End-to-end: Protecting an RPC call via a runtime permission
+
+##### Service Manifest
+
+```xml
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.example.myservice">
+    <!-- Define a runtime permission -->
+    <permission android:name="com.android.example.myservice.MY_RUNTIME_PERMISSION"
+        android:protectionLevel="dangerous" />
+    <application>
+        <service android:name=".MyService" android:exported="true" />
+    </application>
+</manifest>
+```
+
+##### Service code
+
+```kotlin
+class MyService : Service() {
+    override fun onBind(intent: Intent?): IBinder? {
+        return object : IMyService.Stub() {
+            override fun doSomething(callingPackage: String?, callingFeatureId: String?) {
+                Objects.requireNonNull(callingPackageName)
+
+                // Verify that calling UID has the permission
+                when (run {
+                    PermissionChecker.checkCallingPermission(
+                        this@MyService,
+                         "com.android.example.myservice.MY_RUNTIME_PERMISSION",
+                        callingPackageName,
+                        callingFeatureId,
+                        "Did something"
+                    )
+                }) {
+                    PERMISSION_GRANTED -> /* do something */
+                    PERMISSION_DENIED_APP_OP -> /* silent failure, do nothing */
+                    else -> throw SecurityException(
+                        "Cannot do something as caller is missing "
+                                + "com.android.example.myservice.MY_RUNTIME_PERMISSION"
+                    )
+                }
+            }
+        }.asBinder()
+    }
+}
+```
+
+##### Caller Manifest
+
+```xml
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.example.myapp">
+    <!-- request a permission -->
+    <uses-permission android:name="com.android.example.myservice.MY_RUNTIME_PERMISSION" />
+    <application />
+</manifest>
+```
+
+##### Caller code
+
+```kotlin
+class MyActivity : Activity {
+    fun callDoSomething() {
+        if (checkSelfPermission("com.android.example.myservice.MY_RUNTIME_PERMISSION") == PERMISSION_DENIED) {
+            // Interrupt operation and request permission
+            requestPermissions(arrayOf("com.android.example.myservice.MY_RUNTIME_PERMISSION"), 23)
+        } else {
+            myService.doSomething(this@MyActivity.opPackageName, this@MyActivity.featureId)
+        }
+    }
+
+    override fun onRequestPermissionsResult(
+        requestCode: Int,
+        permissions: Array<String>,
+        grantResults: IntArray
+    ) {
+        if (requestCode == 23 && grantResults[0] == PERMISSION_GRANTED) {
+            // Finish operation
+            callDoSomething()
+        }
+    }
+}
+```
+
+#### Restricted permissions
+
+Some runtime permissions are restricted. They are annotated in the platforms `AndroidManifest.xml`
+has `hardRestricted` or `softRestricted`.
+
+Restricted permissions behave uncommon when not whitelisted. When whitelisted the permissions
+behave normally. What uncommon means depends on the whether they are hard or soft restricted.
+
+They can either be whitelisted during upgrade P->Q, but the system or need to be whitelisted by the
+installer via `PackageInstaller.SessionParams.setWhitelistedRestrictedPermissions`. If this method
+is not used all permissions will be whitelisted.
+
+Afterwards the app that originally installed the app can change the whitelisting state via
+`PackageManager.addWhitelistedRestrictedPermission` and
+`PackageManager.removeWhitelistedRestrictedPermission`.
+
+The system tracks the source of the whitelisting by having three different flags
+ `RESTRICTION_SYSTEM_EXEMPT`, `RESTRICTION_UPGRADE_EXEMPT`, and `RESTRICTION_INSTALLER_EXEMPT`,
+
+The flags can be checked in `dumpsys package my.package.name`
+
+```
+User 0:
+  [...]
+  runtime permissions:
+    android.permission.READ_EXTERNAL_STORAGE: granted=false, flags=[ RESTRICTION_UPGRADE_EXEMPT ]
+    android.permission.ACCESS_FINE_LOCATION: granted=true, flags=[ RESTRICTION_SYSTEM_EXEMPT|RESTRICTION_UPGRADE_EXEMPT ]
+```
+
+##### Hard restricted
+
+Hard restricted permissions need to be whitelisted to be grant-able.
+
+##### Soft restricted
+
+The behavior of non-whitelisted soft restricted permissions is not uniform. The behavior is
+defined in the `SoftRestrictedPermissionPolicy`.
+
+#### System fixed permission
+
+Some runtime permissions are required for normal operation of the device. In this case the system
+can grant the permission as `SYSTEM_FIXED`. In this case the permission can be seen in the
+[permission management settings](#settings) but cannot be revoked by the user.
+
+The flag can be checked in `dumpsys package my.package.name`
+```
+User 0:
+  [...]
+  runtime permissions:
+    android.permission.READ_EXTERNAL_STORAGE: granted=true, flags=[ SYSTEM_FIXED|GRANTED_BY_DEFAULT ]
+```
+
+#### Background access
+
+Whether the app is currently visible to the user is reflected in the `ActivityManager`'s proc state.
+There is a lot of granularity to this, but runtime permissions are using the [app-ops services'
+](../app/AppOps.md) definition of foreground and background.
+
+Most runtime permissions are not affected by foreground/background-ness. Microphone and Camera are
+foreground-only while Location is usually foreground-only, but background access can be added by
+granting the `ACCESS_BACKGROUND_LOCATION` modifier runtime permission.
+
+##### Microphone and Camera
+
+Currently these only allow access while in the app is in foreground. There is a manual whitelist
+for e.g. the voice interaction service.
+
+This is currently (Mar 2020) reworked and will behave like [location](#location) soon.
+
+##### Location
+
+As described [above](#runtime-permissions-and-app-ops) the app-op mode for granted permissions is
+`MODE_ALLOWED` to allow access or `MODE_IGNORED` to suppress access.
+
+The important case is the case where the permission is granted and the app-op is `MODE_IGNORED`. In
+the case of location this state causes the `LocationManagerService` to stop delivering locations to
+the app. This is not a breaking behavior as the same scenarios happens if e.g. no satellites
+could be found.
+
+This behavior is used to implement the foregound/background behavior for location. If the app is
+in the foreground the app-op mode is `MODE_ALLOWED` and works normally. If the app goes into
+background the app-op mode changes to `MODE_IGNORED`. This means that locations are delivered while
+the app is in foreground and while the app is background, the app won't get any locations.
+
+The automatic switching between `MODE_ALLOWED` and `MODE_IGNORED` is done inside of
+ [`AppOpsManager`](../app/AppOps.md#foreground).
+
+Background access can be enabled by also granting the `ACCESS_BACKGROUND_LOCATION` to the app. In
+this case the app-op mode will always be `MODE_ALLOWED`.
+
+#### UI
+
+##### Granting
+
+An app following the best practices does not ask for any runtime permissions until absolutely
+needed. Once needed the request should be made in context. I.e. the user should understand from the
+current state of the app and the user's action why the request is made. E.g. if the user presses
+a "show me the next ATM"-button the user is most likely expecting a request for the location
+permission.
+
+This is central premise to the runtime permission UI. It is the app's responsibility to avoid
+showing permission requests dialogs to the user which might get denied. These dialogs are not
+meant to be user-choices, they are meant to be user-confirmations.
+
+Hence any denied permission dialog is probably due to the app asking for permissions the user
+does not expect. If too many permission requests get denied the app is apparently trying to get
+more than the user wants to give to the app. In this case the permission gets permanently denied
+and all future requests will be denied automatically without showing a UI.
+
+`Context.requestPermission` calls for more than one permission are allowed and might result in
+multiple dialogs in sequence. This might make sense for e.g. getting microphone and camera
+permission when starting a video call.
+
+Each time the the user makes a choice (either to grant or the deny) a permission request the
+permission is marked as `USER_SET`. If a permission gets permanently denied the permission is marked
+as `USER_FIXED`.
+
+This can be found in `dumpsys package my.package.name`
+```
+User 0:
+  [...]
+  runtime permissions:
+    android.permission.READ_EXTERNAL_STORAGE: granted=false, flags=[ USER_SET|USER_FIXED ]
+    android.permission.ACCESS_FINE_LOCATION: granted=true, flags=[ USER_SET ]
+```
+
+##### Settings
+
+By far most interactions with the permission system are via the [permission grant flow](#granting).
+The main purpose of the permission settings is to show the user the previous choices and allow
+the user to revisit previous choices. In reality few users do that.
+
+##### Grouping
+
+There are too many runtime permissions for the user to individually manage. Hence the UI bundles the
+permissions into groups. **Apps should never assume the grouping**. The grouping might change
+with SDK updates, but also at any other time. Certain form factors or locales might use other
+permission models and sometimes some of the permissions of a group cannot be granted for various
+reasons. The grouping is defined inside the permission controller app.
+
+If two permissions belong to a group and the first permission is already granted the second one
+will be granted on request of the app without user interaction. For that reason a permission
+group with at least one individual permission granted will show up as granted in the UI.
+
+##### Alternate permission management
+
+It is not allowed to build alternate permission management UIs. While restricting innovation is not
+a good choice this is a required one to enforce a consistent, predictable, but flexible permission
+model for users and app developers.
+
+Further some data needed for permission management (e.g. the grouping) is not available outside
+the permission controller app.
+
+Hence all permission management UI needs to be integrated with AOSP.
+
+#### Pre granting
+
+Runtime permissions protect user private data. It is a violation of user trust to give the data
+to an app without explicit user consent (i.e. the user [granting](#granting) the permission
+). Still the user expects certain functionality (e.g. receiving a phone call) to work out of the
+box.
+
+Hence the `DefaultPermissionGrantPolicy` and roles allow to grant permission without the user
+. The default permission grant policy grants permissions for three categories of apps
+- Apps running in well defined [uids](../os/Users.md#int-uid) as they are considered as part of
+ the platform
+- Apps that are in certain predefined categories, e.g. the browser and the SMS app. This is
+ meant for the most basic phone functionality, not for all pre-installed apps.
+- Apps that are explicitly mentioned as a pre-grant-exceptions. This is meant to be used for setup
+ and other highly critical use cases, not to improve the user experience. The exceptions are listed
+ in xml files in `etc/` and follow the following syntax
+```xml
+<exceptions>
+    <exception package="my.package.name">
+        <permission name="android.permission.ACCESS_FINE_LOCATION" fixed="false"/>
+    </exception>
+</exceptions>
+```
+
+Pre-granted runtime permissions can still be revoked by the user in [settings](#settings) unless
+they are granted as `SYSTEM_FIXED`.
+
+Whether a permission was granted by the default can be checked in the permission flags of
+`dumpsys package my.package.name`
+
+```
+User 0:
+  [...]
+  runtime permissions:
+    android.permission.ACCESS_FINE_LOCATION: granted=true, flags=[ GRANTED_BY_DEFAULT ]
+```
+
+### Permission restricted components
+
+As [publicly documented](https://developer.android.com/guide/topics/permissions/overview#permission_enforcement)
+it is possible to restrict starting an activity/binding to a service by using permission. It is
+a common pattern to
+
+- define a permission in the platform as `signature`
+- protect a service in an app by this permission using the `android:permission` attribute of the
+ `<service>` tag
+
+Then it is guaranteed that only the system can bind to such service. This is used for services
+that provide extensions to platform functionality, such as auto-fill services, print services, and
+accessibility services.
+
+This does not work for app-op or runtime permissions as the way to check these permissions is
+more complex than install time permissions.
+
+## Permissions for system apps
+
+System apps need to integrate deeper with the system than regular apps. Hence they need to be
+able to call APIs not available to other apps. This is implemented by granting permissions to
+these system apps and then enforcing the permissions in the API similar to other [install time
+permissions](#checking-a-permission).
+
+System apps are not different from regular apps, but the protection levels (e.g.
+[privileged](#privileged-permissions), [preinstalled](#preinstalled-permissions)) mentioned in this
+section are more commonly used by system apps.
+
+### Multiple permission levels
+
+It is possible to assign multiple protection levels to a permission. Very common combinations are
+for example adding `signature` to all permissions to make sure the platform signed apps can be
+granted the permission, e.g. `privileged|signature`.
+
+The permission will be granted if the app qualifies for _any_ of the permission levels.
+
+### App-op permissions
+
+> See [App-ops](../app/AppOps.md).
+
+App-op permissions are user-switchable permissions that are not runtime permissions. This should
+be used for permissions that are really only meant to be ever granted to a very small amount of
+apps. Traditionally granting these permissions is intentionally very heavy weight so that the
+user really needs to understand the use case. For example one use case is the
+`INTERACT_ACROSS_PROFILES` permission that allows apps of different
+[user profiles](../os/Users.md#user-profile) to interact. Of course this is breaking a very basic
+security container and hence should only every be granted with a lot of care.
+
+**Warning:** Most app-op permissions follow this logic, but most of them also have exceptions
+and special behavior. Hence this section is a guideline, not a rule.
+
+#### Defining an app-op permission
+
+Only the platform can reasonably define an app-op permission. The permission is defined in the
+platforms manifest using the `appop` protection level
+
+```xml
+<manifest package="android">
+    <permission android:name="android.permission.MY_APPOP_PERMISSION"
+        android:protectionLevel="appop|signature" />
+</manifest>
+```
+
+Almost always the protection level is app-op | something else, like
+[signature](#signature-permissions) (in the case above) or [privileged](#privileged-permissions).
+
+#### Checking a app-op permission
+
+The `PermissionChecker` utility can check app-op permissions with the [same syntax as runtime
+permissions](#checking-a-runtime-permission).
+
+The permission checker internally follows this flow
+
+```kotlin
+class PermissionChecker {
+    fun checkCallingPermission(context: Context, permission: String) {
+        if (isAppOpPermission(permission)) {
+            val appopOfPermission = AppOpsManager.permissionToOp(permission)
+            if (appopOfPermission == null) {
+                // not platform defined
+                return PERMISSION_DENIED
+            }
+
+            val appopMode = appOpsManager.noteOp(appopOfPermission)
+            when (appopMode) {
+                AppOpsManager.MODE_ALLOWED -> return PERMISSION_GRANTED
+                AppOpsManager.MODE_IGNORED -> return PERMISSION_DENIED
+                AppOpsManager.MODE_DEFAULT -> {
+                    if (context.checkPermission(uid, permission) == GRANTED) {
+                        return PERMISSION_GRANTED
+                    } else {
+                        return PERMISSION_DENIED
+                    }
+                }
+            }
+        } else {
+            return PERMISSION_DENIED
+        }
+    }
+}
+```
+
+#### Granting a app-op permission
+
+The permission's grant state is only considered if the app-op's mode is `MODE_DEFAULT`. This
+allows to have default grants while still being overridden by the app-op.
+
+The permission is then granted by setting the app-op mode. This is usually done via dedicated APIs
+for each use cases. Similarly whether and how an app can request the permission is different for
+each app-op permission.
+
+When implementing a new app-op permission, make sure to set the app-op mode using `AppOpsManager
+.setUidMode` to make sure the permission is granted on the uid as this is the security domain.
+
+During development app-ops can be grated to app via the `appops set` shell command. E.g.
+
+```
+adb shell appops set 10187 INTERACT_ACROSS_PROFILES allow
+```
+
+sets the `INTERACT_ACROSS_PROFILES` app-op for uid 10187 to allow thereby granting apps in this
+uid the ability to interact across profiles.
+
+##### UI
+
+Most UIs for app-op permissions are in the "Special app access" section of the settings app.
+
+In most cases the permission should only be granted with the user's explicit agreement, usually by
+allowing the app to directly open the "Special app access" page for this permission and app.
+
+To repeat: this is a guideline for app-op permissions and there are many exceptions.
+
+### Signature permissions
+
+Only apps signed with the defining app's certificate will be granted the permission. This is
+used to restrict APIs to apps of the same developer.
+
+This is frequently used to restrict permissions defined by the platform to apps also signed with
+the platform's certificate. As this is a very tight restriction this is recommended for
+permissions that are only used by apps built out of AOSP which are signed with the platform
+certificate.
+
+Please note that OEMs sign their platform them self. I.e. OEMs can implement new apps using these
+permissions. It is unlikely that 3rd party apps will be able to use APIs protected by signature
+permissions as they are usually not signed with the platform certificate.
+
+Such permissions are defined and checked like an install time permission.
+
+### Preinstalled permissions
+
+This means that the app has to be pre-installed. There is no restriction what apps are pre-installed
+on a particular device install there. Hence it can be really any app including 3rd party apps.
+
+Hence this permission level is discouraged unless there are
+[further restrictions](#restricted-by-tests).
+
+Such permissions are defined and checked like an install time permission.
+
+### Privileged permissions
+
+This means that the app has to be pre-installed and in the `system/priv` directory in the
+filesystem. There is no restriction what apps are in this directory on a particular device
+install there. Hence it can be really any app including 3rd party apps.
+
+An app is only ever granted privileged permissions requested by the pre-installed apk. I.e.
+privileged permissions added in updates will never be granted.
+
+Hence this permission level is discouraged unless there are
+[further restrictions](#restricted-by-tests).
+
+Such permissions are defined and checked like an install time permission.
+
+#### Restricted by tests
+
+As all apps that might get preinstalled or privilidged permissions need to be pre-installed and new
+images need to pass compliance tests it is possible to use a test to whitelist the apps that can
+request the permission.
+
+Example of such a test:
+```kotlin
+/* Add new whitelisted packages to this list */
+private val whitelistedPkgs = listOf("my.whitelisted.package")
+
+@Test
+fun onlySomeAppsAreAllowedToHavePermissionGranted() {
+    assertThat(whitelistedPkgs).containsAllIn(
+            context.packageManager.getInstalledPackages(MATCH_ALL)
+                    .filter { pkg ->
+                        context.checkPermission(android.Manifest.permission.MY_PRIVILEGED_PERMISSION, -1,
+                                pkg.applicationInfo.uid) == PERMISSION_GRANTED
+                    /* The permission is defined by the system and hence granted to it */
+                    }.filter { pkg -> pkg.applicationInfo.uid != SYSTEM_UID }
+                    .map { it.packageName }
+    )
+}
+```
+
+#### Whitelist
+
+As mentioned above it is not suggested, but still common practice to install 3rd party apps as
+privilidged. To verify and restrict which privilidged permissions those apps get granted all
+privilidged permissions need to be explicitly whitelisted in a file `/etc`.
+
+```xml
+<permissions>
+    <privapp-permissions package="my.privileged.package">
+        <!-- allow the app to request a permission -->
+        <permission name="android.permission.MY_PRIVILEGED_PERMISSION"/>
+
+        <!-- Even though the app requests the permission, do not grant it -->
+        <deny-permission name="android.permission.MY_OTHER_PRIVILEGED_PERMISSION"/>
+    </privapp-permissions>
+</permissions>
+```
+
+If the pre-installed apk of app requests a privileged permission that is not mentioned in any
+whitelist or that is not denied the system will refuse to boot. As mentioned above privileged
+permissions added in updates to the pre-installed app will never be granted.
+
+### Limited permissions
+
+E.g. installer, wellbeing, documenter, etc... This allows the system to restrict the permission to a
+well defined app or set of apps. It is possible to add new types in `PackageManagerService`.
+
+Which apps qualify for such a permission level is flexible and custom for each such level. Usually
+they refer to a single or small set of apps, usually - but not always - apps defined in AOSP.
+
+These permissions are defined and checked like an install time permission.
+
+### Development permissions
+
+> Not recommended
+
+By adding the `development` protection level to any permissions the permission can be granted via
+the `pm grant` shell command. This appears to be useful for development and testing, but it is very
+highly discouraged. Any user can grant them permanently via adb, hence adding this tag removes
+all guarantees the permission might otherwise provide.
+
+### Other protection levels
+
+There are other levels (such as `runtime`) but they are for special purposes on should not be
+used by platform developers.
diff --git a/core/java/android/provider/DeviceConfig.java b/core/java/android/provider/DeviceConfig.java
index aa511cc..fb81d67 100644
--- a/core/java/android/provider/DeviceConfig.java
+++ b/core/java/android/provider/DeviceConfig.java
@@ -399,6 +399,13 @@
     public static final String NAMESPACE_CONNECTIVITY_THERMAL_POWER_MANAGER =
             "connectivity_thermal_power_manager";
 
+    /**
+     * Namespace for configuration related features.
+     *
+     * @hide
+     */
+    public static final String NAMESPACE_CONFIGURATION = "configuration";
+
     private static final Object sLock = new Object();
     @GuardedBy("sLock")
     private static ArrayMap<OnPropertiesChangedListener, Pair<String, Executor>> sListeners =
diff --git a/core/java/android/provider/DocumentsProvider.java b/core/java/android/provider/DocumentsProvider.java
index a80153d..327bca2 100644
--- a/core/java/android/provider/DocumentsProvider.java
+++ b/core/java/android/provider/DocumentsProvider.java
@@ -1081,7 +1081,7 @@
             // signed with platform signature can hold MANAGE_DOCUMENTS, we are going to check for
             // MANAGE_DOCUMENTS or associated URI permission here instead
             final Uri rootUri = extras.getParcelable(DocumentsContract.EXTRA_URI);
-            enforceWritePermissionInner(rootUri, getCallingPackage(), getCallingFeatureId(),
+            enforceWritePermissionInner(rootUri, getCallingPackage(), getCallingAttributionTag(),
                     null);
 
             final String rootId = DocumentsContract.getRootId(rootUri);
@@ -1103,8 +1103,8 @@
         enforceTree(documentUri);
 
         if (METHOD_IS_CHILD_DOCUMENT.equals(method)) {
-            enforceReadPermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
+            enforceReadPermissionInner(documentUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
 
             final Uri childUri = extras.getParcelable(DocumentsContract.EXTRA_TARGET_URI);
             final String childAuthority = childUri.getAuthority();
@@ -1116,8 +1116,8 @@
                             && isChildDocument(documentId, childId));
 
         } else if (METHOD_CREATE_DOCUMENT.equals(method)) {
-            enforceWritePermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
+            enforceWritePermissionInner(documentUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
 
             final String mimeType = extras.getString(Document.COLUMN_MIME_TYPE);
             final String displayName = extras.getString(Document.COLUMN_DISPLAY_NAME);
@@ -1131,8 +1131,8 @@
             out.putParcelable(DocumentsContract.EXTRA_URI, newDocumentUri);
 
         } else if (METHOD_CREATE_WEB_LINK_INTENT.equals(method)) {
-            enforceWritePermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
+            enforceWritePermissionInner(documentUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
 
             final Bundle options = extras.getBundle(DocumentsContract.EXTRA_OPTIONS);
             final IntentSender intentSender = createWebLinkIntent(documentId, options);
@@ -1140,8 +1140,8 @@
             out.putParcelable(DocumentsContract.EXTRA_RESULT, intentSender);
 
         } else if (METHOD_RENAME_DOCUMENT.equals(method)) {
-            enforceWritePermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
+            enforceWritePermissionInner(documentUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
 
             final String displayName = extras.getString(Document.COLUMN_DISPLAY_NAME);
             final String newDocumentId = renameDocument(documentId, displayName);
@@ -1165,8 +1165,8 @@
             }
 
         } else if (METHOD_DELETE_DOCUMENT.equals(method)) {
-            enforceWritePermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
+            enforceWritePermissionInner(documentUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
             deleteDocument(documentId);
 
             // Document no longer exists, clean up any grants.
@@ -1176,9 +1176,9 @@
             final Uri targetUri = extras.getParcelable(DocumentsContract.EXTRA_TARGET_URI);
             final String targetId = DocumentsContract.getDocumentId(targetUri);
 
-            enforceReadPermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
-            enforceWritePermissionInner(targetUri, getCallingPackage(), getCallingFeatureId(),
+            enforceReadPermissionInner(documentUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
+            enforceWritePermissionInner(targetUri, getCallingPackage(), getCallingAttributionTag(),
                     null);
 
             final String newDocumentId = copyDocument(documentId, targetId);
@@ -1202,11 +1202,11 @@
             final Uri targetUri = extras.getParcelable(DocumentsContract.EXTRA_TARGET_URI);
             final String targetId = DocumentsContract.getDocumentId(targetUri);
 
-            enforceWritePermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
-            enforceReadPermissionInner(parentSourceUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
-            enforceWritePermissionInner(targetUri, getCallingPackage(), getCallingFeatureId(),
+            enforceWritePermissionInner(documentUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
+            enforceReadPermissionInner(parentSourceUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
+            enforceWritePermissionInner(targetUri, getCallingPackage(), getCallingAttributionTag(),
                     null);
 
             final String newDocumentId = moveDocument(documentId, parentSourceId, targetId);
@@ -1228,10 +1228,10 @@
             final Uri parentSourceUri = extras.getParcelable(DocumentsContract.EXTRA_PARENT_URI);
             final String parentSourceId = DocumentsContract.getDocumentId(parentSourceUri);
 
-            enforceReadPermissionInner(parentSourceUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
-            enforceWritePermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                    null);
+            enforceReadPermissionInner(parentSourceUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
+            enforceWritePermissionInner(documentUri, getCallingPackage(),
+                    getCallingAttributionTag(), null);
             removeDocument(documentId, parentSourceId);
 
             // It's responsibility of the provider to revoke any grants, as the document may be
@@ -1240,8 +1240,8 @@
             final boolean isTreeUri = isTreeUri(documentUri);
 
             if (isTreeUri) {
-                enforceReadPermissionInner(documentUri, getCallingPackage(), getCallingFeatureId(),
-                        null);
+                enforceReadPermissionInner(documentUri, getCallingPackage(),
+                        getCallingAttributionTag(), null);
             } else {
                 getContext().enforceCallingPermission(Manifest.permission.MANAGE_DOCUMENTS, null);
             }
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 23c074c..ce9b449 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -2624,7 +2624,7 @@
                     arg.putBoolean(CALL_METHOD_OVERRIDEABLE_BY_RESTORE_KEY, true);
                 }
                 IContentProvider cp = mProviderHolder.getProvider(cr);
-                cp.call(cr.getPackageName(), cr.getFeatureId(),
+                cp.call(cr.getPackageName(), cr.getAttributionTag(),
                         mProviderHolder.mUri.getAuthority(), mCallSetCommand, name, arg);
             } catch (RemoteException e) {
                 Log.w(TAG, "Can't set key " + name + " in " + mUri, e);
@@ -2644,7 +2644,7 @@
                 args.putString(CALL_METHOD_PREFIX_KEY, prefix);
                 args.putSerializable(CALL_METHOD_FLAGS_KEY, keyValues);
                 IContentProvider cp = mProviderHolder.getProvider(cr);
-                Bundle bundle = cp.call(cr.getPackageName(), cr.getFeatureId(),
+                Bundle bundle = cp.call(cr.getPackageName(), cr.getAttributionTag(),
                         mProviderHolder.mUri.getAuthority(),
                         mCallSetAllCommand, null, args);
                 return bundle.getBoolean(KEY_CONFIG_SET_RETURN);
@@ -2719,14 +2719,14 @@
                     if (Settings.isInSystemServer() && Binder.getCallingUid() != Process.myUid()) {
                         final long token = Binder.clearCallingIdentity();
                         try {
-                            b = cp.call(cr.getPackageName(), cr.getFeatureId(),
+                            b = cp.call(cr.getPackageName(), cr.getAttributionTag(),
                                     mProviderHolder.mUri.getAuthority(), mCallGetCommand, name,
                                     args);
                         } finally {
                             Binder.restoreCallingIdentity(token);
                         }
                     } else {
-                        b = cp.call(cr.getPackageName(), cr.getFeatureId(),
+                        b = cp.call(cr.getPackageName(), cr.getAttributionTag(),
                                 mProviderHolder.mUri.getAuthority(), mCallGetCommand, name, args);
                     }
                     if (b != null) {
@@ -2796,13 +2796,13 @@
                 if (Settings.isInSystemServer() && Binder.getCallingUid() != Process.myUid()) {
                     final long token = Binder.clearCallingIdentity();
                     try {
-                        c = cp.query(cr.getPackageName(), cr.getFeatureId(), mUri,
+                        c = cp.query(cr.getPackageName(), cr.getAttributionTag(), mUri,
                                 SELECT_VALUE_PROJECTION, queryArgs, null);
                     } finally {
                         Binder.restoreCallingIdentity(token);
                     }
                 } else {
-                    c = cp.query(cr.getPackageName(), cr.getFeatureId(), mUri,
+                    c = cp.query(cr.getPackageName(), cr.getAttributionTag(), mUri,
                             SELECT_VALUE_PROJECTION, queryArgs, null);
                 }
                 if (c == null) {
@@ -2895,7 +2895,7 @@
                 }
 
                 // Fetch all flags for the namespace at once for caching purposes
-                Bundle b = cp.call(cr.getPackageName(), cr.getFeatureId(),
+                Bundle b = cp.call(cr.getPackageName(), cr.getAttributionTag(),
                         mProviderHolder.mUri.getAuthority(), mCallListCommand, null, args);
                 if (b == null) {
                     // Invalid response, return an empty map
@@ -5540,7 +5540,7 @@
                 }
                 arg.putInt(CALL_METHOD_RESET_MODE_KEY, mode);
                 IContentProvider cp = sProviderHolder.getProvider(resolver);
-                cp.call(resolver.getPackageName(), resolver.getFeatureId(),
+                cp.call(resolver.getPackageName(), resolver.getAttributionTag(),
                         sProviderHolder.mUri.getAuthority(), CALL_METHOD_RESET_SECURE, null, arg);
             } catch (RemoteException e) {
                 Log.w(TAG, "Can't reset do defaults for " + CONTENT_URI, e);
@@ -6090,10 +6090,7 @@
          * device is removed from this mode.
          * <p>
          * Type: int (0 for false, 1 for true)
-         *
-         * @hide
          */
-        @SystemApi
         public static final String SECURE_FRP_MODE = "secure_frp_mode";
 
         /**
@@ -13386,7 +13383,7 @@
                 }
                 arg.putInt(CALL_METHOD_RESET_MODE_KEY, mode);
                 IContentProvider cp = sProviderHolder.getProvider(resolver);
-                cp.call(resolver.getPackageName(), resolver.getFeatureId(),
+                cp.call(resolver.getPackageName(), resolver.getAttributionTag(),
                         sProviderHolder.mUri.getAuthority(), CALL_METHOD_RESET_GLOBAL, null, arg);
             } catch (RemoteException e) {
                 Log.w(TAG, "Can't reset do defaults for " + CONTENT_URI, e);
@@ -14361,7 +14358,7 @@
                     arg.putString(Settings.CALL_METHOD_PREFIX_KEY, createPrefix(namespace));
                 }
                 IContentProvider cp = sProviderHolder.getProvider(resolver);
-                cp.call(resolver.getPackageName(), resolver.getFeatureId(),
+                cp.call(resolver.getPackageName(), resolver.getAttributionTag(),
                         sProviderHolder.mUri.getAuthority(), CALL_METHOD_RESET_CONFIG, null, arg);
             } catch (RemoteException e) {
                 Log.w(TAG, "Can't reset to defaults for " + DeviceConfig.CONTENT_URI, e);
@@ -14390,7 +14387,7 @@
                 arg.putInt(CALL_METHOD_USER_KEY, userHandle);
                 arg.putParcelable(CALL_METHOD_MONITOR_CALLBACK_KEY, callback);
                 IContentProvider cp = sProviderHolder.getProvider(resolver);
-                cp.call(resolver.getPackageName(), resolver.getFeatureId(),
+                cp.call(resolver.getPackageName(), resolver.getAttributionTag(),
                         sProviderHolder.mUri.getAuthority(),
                         CALL_METHOD_REGISTER_MONITOR_CALLBACK_CONFIG, null, arg);
             } catch (RemoteException e) {
diff --git a/core/java/android/provider/Telephony.java b/core/java/android/provider/Telephony.java
index 03b38ab..e7b360d 100644
--- a/core/java/android/provider/Telephony.java
+++ b/core/java/android/provider/Telephony.java
@@ -3551,7 +3551,6 @@
          * can manage DPC-owned APNs.
          * @hide
          */
-        @SystemApi
         public static final @NonNull Uri DPC_URI = Uri.parse("content://telephony/carriers/dpc");
 
         /**
@@ -3864,7 +3863,6 @@
          * Integer value denoting an invalid APN id
          * @hide
          */
-        @SystemApi
         public static final int INVALID_APN_ID = -1;
 
         /**
diff --git a/core/java/android/service/autofill/Dataset.java b/core/java/android/service/autofill/Dataset.java
index 886b433..08aa534 100644
--- a/core/java/android/service/autofill/Dataset.java
+++ b/core/java/android/service/autofill/Dataset.java
@@ -232,22 +232,6 @@
          * Creates a new builder.
          *
          * @param presentation The presentation used to visualize this dataset.
-         * @param inlinePresentation The {@link InlinePresentation} used to visualize this dataset
-         *              as inline suggestions. If the dataset supports inline suggestions,
-         *              this should not be null.
-         */
-        public Builder(@NonNull RemoteViews presentation,
-                @NonNull InlinePresentation inlinePresentation) {
-            Preconditions.checkNotNull(presentation, "presentation must be non-null");
-            Preconditions.checkNotNull(inlinePresentation, "inlinePresentation must be non-null");
-            mPresentation = presentation;
-            mInlinePresentation = inlinePresentation;
-        }
-
-        /**
-         * Creates a new builder.
-         *
-         * @param presentation The presentation used to visualize this dataset.
          */
         public Builder(@NonNull RemoteViews presentation) {
             Preconditions.checkNotNull(presentation, "presentation must be non-null");
@@ -282,6 +266,22 @@
         }
 
         /**
+         * Sets the {@link InlinePresentation} used to visualize this dataset as inline suggestions.
+         * If the dataset supports inline suggestions this should not be null.
+         *
+         * @throws IllegalStateException if {@link #build()} was already called.
+         *
+         * @return this builder.
+         */
+        public @NonNull Builder setInlinePresentation(
+                @NonNull InlinePresentation inlinePresentation) {
+            throwIfDestroyed();
+            Preconditions.checkNotNull(inlinePresentation, "inlinePresentation must be non-null");
+            mInlinePresentation = inlinePresentation;
+            return this;
+        }
+
+        /**
          * Triggers a custom UI before before autofilling the screen with the contents of this
          * dataset.
          *
@@ -600,7 +600,7 @@
          */
         @SystemApi
         @TestApi
-        public @NonNull Builder setInlinePresentation(@NonNull AutofillId id,
+        public @NonNull Builder setFieldInlinePresentation(@NonNull AutofillId id,
                 @Nullable AutofillValue value, @Nullable Pattern filter,
                 @NonNull InlinePresentation inlinePresentation) {
             throwIfDestroyed();
@@ -700,7 +700,7 @@
             final Builder builder = presentation != null
                     ? inlinePresentation == null
                             ? new Builder(presentation)
-                            : new Builder(presentation, inlinePresentation)
+                            : new Builder(presentation).setInlinePresentation(inlinePresentation)
                     : inlinePresentation == null
                             ? new Builder()
                             : new Builder(inlinePresentation);
diff --git a/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl b/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl
index 1011651..1bcc76b 100644
--- a/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl
+++ b/core/java/android/service/autofill/IInlineSuggestionUiCallback.aidl
@@ -25,7 +25,8 @@
  * @hide
  */
 oneway interface IInlineSuggestionUiCallback {
-    void onAutofill();
+    void onClick();
+    void onLongClick();
     void onContent(in SurfaceControlViewHost.SurfacePackage surface);
     void onError();
     void onTransferTouchFocusToImeWindow(in IBinder sourceInputToken, int displayId);
diff --git a/core/java/android/service/autofill/InlineSuggestionRenderService.java b/core/java/android/service/autofill/InlineSuggestionRenderService.java
index ee15283..b6cc62d 100644
--- a/core/java/android/service/autofill/InlineSuggestionRenderService.java
+++ b/core/java/android/service/autofill/InlineSuggestionRenderService.java
@@ -97,12 +97,21 @@
             host.addView(suggestionRoot, lp);
             suggestionRoot.setOnClickListener((v) -> {
                 try {
-                    callback.onAutofill();
+                    callback.onClick();
                 } catch (RemoteException e) {
-                    Log.w(TAG, "RemoteException calling onAutofill()");
+                    Log.w(TAG, "RemoteException calling onClick()");
                 }
             });
 
+            suggestionRoot.setOnLongClickListener((v) -> {
+                try {
+                    callback.onLongClick();
+                } catch (RemoteException e) {
+                    Log.w(TAG, "RemoteException calling onLongClick()");
+                }
+                return true;
+            });
+
             sendResult(callback, host.getSurfacePackage());
         } finally {
             updateDisplay(Display.DEFAULT_DISPLAY);
diff --git a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
index ed27dd5..5b08ae2 100644
--- a/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
+++ b/core/java/android/service/autofill/augmented/AugmentedAutofillService.java
@@ -488,7 +488,8 @@
                 ids.add(pair.first);
                 values.add(pair.second);
             }
-            mClient.autofill(mSessionId, ids, values);
+            final boolean hideHighlight = size == 1 && ids.get(0).equals(mFocusedId);
+            mClient.autofill(mSessionId, ids, values, hideHighlight);
         }
 
         public void setFillWindow(@NonNull FillWindow fillWindow) {
diff --git a/core/java/android/service/voice/VoiceInteractionSession.java b/core/java/android/service/voice/VoiceInteractionSession.java
index 8e6f77b..4a0dd87 100644
--- a/core/java/android/service/voice/VoiceInteractionSession.java
+++ b/core/java/android/service/voice/VoiceInteractionSession.java
@@ -1314,7 +1314,8 @@
             intent.migrateExtraStreamToClipData();
             intent.prepareToLeaveProcess(mContext);
             int res = mSystemService.startVoiceActivity(mToken, intent,
-                    intent.resolveType(mContext.getContentResolver()), mContext.getFeatureId());
+                    intent.resolveType(mContext.getContentResolver()),
+                    mContext.getAttributionTag());
             Instrumentation.checkStartActivityResult(res, intent);
         } catch (RemoteException e) {
         }
@@ -1342,7 +1343,8 @@
             intent.migrateExtraStreamToClipData();
             intent.prepareToLeaveProcess(mContext);
             int res = mSystemService.startAssistantActivity(mToken, intent,
-                    intent.resolveType(mContext.getContentResolver()), mContext.getFeatureId());
+                    intent.resolveType(mContext.getContentResolver()),
+                    mContext.getAttributionTag());
             Instrumentation.checkStartActivityResult(res, intent);
         } catch (RemoteException e) {
         }
diff --git a/core/java/android/speech/SpeechRecognizer.java b/core/java/android/speech/SpeechRecognizer.java
index e93ba16..92f3538 100644
--- a/core/java/android/speech/SpeechRecognizer.java
+++ b/core/java/android/speech/SpeechRecognizer.java
@@ -342,7 +342,7 @@
         }
         try {
             mService.startListening(recognizerIntent, mListener, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
             if (DBG) Log.d(TAG, "service start listening command succeded");
         } catch (final RemoteException e) {
             Log.e(TAG, "startListening() failed", e);
@@ -357,7 +357,7 @@
         }
         try {
             mService.stopListening(mListener, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
             if (DBG) Log.d(TAG, "service stop listening command succeded");
         } catch (final RemoteException e) {
             Log.e(TAG, "stopListening() failed", e);
@@ -371,7 +371,7 @@
             return;
         }
         try {
-            mService.cancel(mListener, mContext.getOpPackageName(), mContext.getFeatureId());
+            mService.cancel(mListener, mContext.getOpPackageName(), mContext.getAttributionTag());
             if (DBG) Log.d(TAG, "service cancel command succeded");
         } catch (final RemoteException e) {
             Log.e(TAG, "cancel() failed", e);
@@ -400,7 +400,8 @@
     public void destroy() {
         if (mService != null) {
             try {
-                mService.cancel(mListener, mContext.getOpPackageName(), mContext.getFeatureId());
+                mService.cancel(mListener, mContext.getOpPackageName(),
+                        mContext.getAttributionTag());
             } catch (final RemoteException e) {
                 // Not important
             }
diff --git a/core/java/android/telephony/TelephonyRegistryManager.java b/core/java/android/telephony/TelephonyRegistryManager.java
index 7238b12..ab9df56 100644
--- a/core/java/android/telephony/TelephonyRegistryManager.java
+++ b/core/java/android/telephony/TelephonyRegistryManager.java
@@ -116,7 +116,7 @@
         mSubscriptionChangedListenerMap.put(listener, callback);
         try {
             sRegistry.addOnSubscriptionsChangedListener(mContext.getOpPackageName(),
-                    mContext.getFeatureId(), callback);
+                    mContext.getAttributionTag(), callback);
         } catch (RemoteException ex) {
             // system server crash
         }
@@ -175,7 +175,7 @@
         mOpportunisticSubscriptionChangedListenerMap.put(listener, callback);
         try {
             sRegistry.addOnOpportunisticSubscriptionsChangedListener(mContext.getOpPackageName(),
-                    mContext.getFeatureId(), callback);
+                    mContext.getAttributionTag(), callback);
         } catch (RemoteException ex) {
             // system server crash
         }
diff --git a/core/java/android/util/apk/ApkSignatureSchemeV3Verifier.java b/core/java/android/util/apk/ApkSignatureSchemeV3Verifier.java
index abd04cc..79eb9f6 100644
--- a/core/java/android/util/apk/ApkSignatureSchemeV3Verifier.java
+++ b/core/java/android/util/apk/ApkSignatureSchemeV3Verifier.java
@@ -16,6 +16,8 @@
 
 package android.util.apk;
 
+import static android.util.apk.ApkSigningBlockUtils.CONTENT_DIGEST_CHUNKED_SHA256;
+import static android.util.apk.ApkSigningBlockUtils.CONTENT_DIGEST_CHUNKED_SHA512;
 import static android.util.apk.ApkSigningBlockUtils.CONTENT_DIGEST_VERITY_CHUNKED_SHA256;
 import static android.util.apk.ApkSigningBlockUtils.compareSignatureAlgorithm;
 import static android.util.apk.ApkSigningBlockUtils.getContentDigestAlgorithmJcaDigestAlgorithm;
@@ -211,6 +213,12 @@
                     verityDigest, apk.length(), signatureInfo);
         }
 
+        if (contentDigests.containsKey(CONTENT_DIGEST_CHUNKED_SHA512)) {
+            result.digest = contentDigests.get(CONTENT_DIGEST_CHUNKED_SHA512);
+        } else if (contentDigests.containsKey(CONTENT_DIGEST_CHUNKED_SHA256)) {
+            result.digest = contentDigests.get(CONTENT_DIGEST_CHUNKED_SHA256);
+        }
+
         return result;
     }
 
@@ -568,6 +576,7 @@
         public final VerifiedProofOfRotation por;
 
         public byte[] verityRootHash;
+        public byte[] digest;
 
         public VerifiedSigner(X509Certificate[] certs, VerifiedProofOfRotation por) {
             this.certs = certs;
diff --git a/core/java/android/util/apk/ApkSignatureSchemeV4Verifier.java b/core/java/android/util/apk/ApkSignatureSchemeV4Verifier.java
index b6b8089..8c240d9 100644
--- a/core/java/android/util/apk/ApkSignatureSchemeV4Verifier.java
+++ b/core/java/android/util/apk/ApkSignatureSchemeV4Verifier.java
@@ -16,13 +16,32 @@
 
 package android.util.apk;
 
+import static android.util.apk.ApkSigningBlockUtils.getSignatureAlgorithmJcaKeyAlgorithm;
+import static android.util.apk.ApkSigningBlockUtils.getSignatureAlgorithmJcaSignatureAlgorithm;
+import static android.util.apk.ApkSigningBlockUtils.isSupportedSignatureAlgorithm;
+
 import android.os.incremental.IncrementalManager;
+import android.os.incremental.V4Signature;
+import android.util.Pair;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.KeyFactory;
+import java.security.NoSuchAlgorithmException;
+import java.security.PublicKey;
+import java.security.Signature;
+import java.security.SignatureException;
 import java.security.cert.Certificate;
-
-import sun.security.pkcs.PKCS7;
-import sun.security.pkcs.ParsingException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.X509EncodedKeySpec;
+import java.util.Arrays;
 
 /**
  * APK Signature Scheme v4 verifier.
@@ -30,24 +49,118 @@
  * @hide for internal use only.
  */
 public class ApkSignatureSchemeV4Verifier {
+    /**
+     * Extracts and verifies APK Signature Scheme v4 signatures of the provided APK and returns the
+     * certificates associated with each signer.
+     */
+    public static VerifiedSigner extractCertificates(String apkFile)
+            throws SignatureNotFoundException, SecurityException {
+        final File apk = new File(apkFile);
+        final byte[] signatureBytes = IncrementalManager.unsafeGetFileSignature(
+                apk.getAbsolutePath());
+        if (signatureBytes == null || signatureBytes.length == 0) {
+            throw new SignatureNotFoundException("Failed to obtain signature bytes from IncFS.");
+        }
+
+        final V4Signature signature;
+        final V4Signature.HashingInfo hashingInfo;
+        final V4Signature.SigningInfo signingInfo;
+        try {
+            signature = V4Signature.readFrom(signatureBytes);
+
+            if (!signature.isVersionSupported()) {
+                throw new SecurityException(
+                        "v4 signature version " + signature.version + " is not supported");
+            }
+
+            hashingInfo = V4Signature.HashingInfo.fromByteArray(signature.hashingInfo);
+            signingInfo = V4Signature.SigningInfo.fromByteArray(signature.signingInfo);
+        } catch (IOException e) {
+            throw new SignatureNotFoundException("Failed to read V4 signature.", e);
+        }
+
+        final byte[] signedData = V4Signature.getSigningData(apk.length(), hashingInfo,
+                signingInfo);
+
+        return verifySigner(signingInfo, signedData);
+    }
+
+    private static VerifiedSigner verifySigner(V4Signature.SigningInfo signingInfo,
+            final byte[] signedData) throws SecurityException {
+        if (!isSupportedSignatureAlgorithm(signingInfo.signatureAlgorithmId)) {
+            throw new SecurityException("No supported signatures found");
+        }
+
+        final int signatureAlgorithmId = signingInfo.signatureAlgorithmId;
+        final byte[] signatureBytes = signingInfo.signature;
+        final byte[] publicKeyBytes = signingInfo.publicKey;
+        final byte[] encodedCert = signingInfo.certificate;
+
+        String keyAlgorithm = getSignatureAlgorithmJcaKeyAlgorithm(signatureAlgorithmId);
+        Pair<String, ? extends AlgorithmParameterSpec> signatureAlgorithmParams =
+                getSignatureAlgorithmJcaSignatureAlgorithm(signatureAlgorithmId);
+        String jcaSignatureAlgorithm = signatureAlgorithmParams.first;
+        AlgorithmParameterSpec jcaSignatureAlgorithmParams = signatureAlgorithmParams.second;
+        boolean sigVerified;
+        try {
+            PublicKey publicKey =
+                    KeyFactory.getInstance(keyAlgorithm)
+                            .generatePublic(new X509EncodedKeySpec(publicKeyBytes));
+            Signature sig = Signature.getInstance(jcaSignatureAlgorithm);
+            sig.initVerify(publicKey);
+            if (jcaSignatureAlgorithmParams != null) {
+                sig.setParameter(jcaSignatureAlgorithmParams);
+            }
+            sig.update(signedData);
+            sigVerified = sig.verify(signatureBytes);
+        } catch (NoSuchAlgorithmException | InvalidKeySpecException | InvalidKeyException
+                | InvalidAlgorithmParameterException | SignatureException e) {
+            throw new SecurityException(
+                    "Failed to verify " + jcaSignatureAlgorithm + " signature", e);
+        }
+        if (!sigVerified) {
+            throw new SecurityException(jcaSignatureAlgorithm + " signature did not verify");
+        }
+
+        // Signature over signedData has verified.
+        CertificateFactory certFactory;
+        try {
+            certFactory = CertificateFactory.getInstance("X.509");
+        } catch (CertificateException e) {
+            throw new RuntimeException("Failed to obtain X.509 CertificateFactory", e);
+        }
+
+        X509Certificate certificate;
+        try {
+            certificate = (X509Certificate)
+                    certFactory.generateCertificate(new ByteArrayInputStream(encodedCert));
+        } catch (CertificateException e) {
+            throw new SecurityException("Failed to decode certificate", e);
+        }
+        certificate = new VerbatimX509Certificate(certificate, encodedCert);
+
+        byte[] certificatePublicKeyBytes = certificate.getPublicKey().getEncoded();
+        if (!Arrays.equals(publicKeyBytes, certificatePublicKeyBytes)) {
+            throw new SecurityException(
+                    "Public key mismatch between certificate and signature record");
+        }
+
+        return new VerifiedSigner(new Certificate[]{certificate}, signingInfo.v3Digest);
+    }
 
     /**
-     * Extracts APK Signature Scheme v4 signatures of the provided APK and returns the certificates
-     * associated with each signer.
+     * Verified APK Signature Scheme v4 signer, including V3 digest.
+     *
+     * @hide for internal use only.
      */
-    public static Certificate[] extractCertificates(String apkFile)
-            throws SignatureNotFoundException, SecurityException {
-        final byte[] rawSignature = IncrementalManager.unsafeGetFileSignature(
-                new File(apkFile).getAbsolutePath());
-        if (rawSignature == null || rawSignature.length == 0) {
-            throw new SignatureNotFoundException("Failed to obtain raw signature from IncFS.");
+    public static class VerifiedSigner {
+        public final Certificate[] certs;
+        public byte[] v3Digest;
+
+        public VerifiedSigner(Certificate[] certs, byte[] v3Digest) {
+            this.certs = certs;
+            this.v3Digest = v3Digest;
         }
 
-        try {
-            PKCS7 pkcs7 = new PKCS7(rawSignature);
-            return pkcs7.getCertificates();
-        } catch (ParsingException e) {
-            throw new SecurityException("Failed to parse signature and extract certificates", e);
-        }
     }
 }
diff --git a/core/java/android/util/apk/ApkSignatureVerifier.java b/core/java/android/util/apk/ApkSignatureVerifier.java
index f325c21..c1cee48 100644
--- a/core/java/android/util/apk/ApkSignatureVerifier.java
+++ b/core/java/android/util/apk/ApkSignatureVerifier.java
@@ -168,7 +168,7 @@
     /**
      * Verifies the provided APK using V4 schema.
      *
-     * @param verifyFull whether to verify all contents of this APK or just collect certificates.
+     * @param verifyFull whether to verify (V4 vs V3) or just collect certificates.
      * @return the certificates associated with each signer.
      * @throws SignatureNotFoundException if there are no V4 signatures in the APK
      * @throws PackageParserException     if there was a problem collecting certificates
@@ -178,30 +178,34 @@
             throws SignatureNotFoundException, PackageParserException {
         Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, verifyFull ? "verifyV4" : "certsOnlyV4");
         try {
-            Certificate[] certs = ApkSignatureSchemeV4Verifier.extractCertificates(apkPath);
-            Certificate[][] signerCerts = new Certificate[][]{certs};
+            ApkSignatureSchemeV4Verifier.VerifiedSigner vSigner =
+                    ApkSignatureSchemeV4Verifier.extractCertificates(apkPath);
+            Certificate[][] signerCerts = new Certificate[][]{vSigner.certs};
             Signature[] signerSigs = convertToSignatures(signerCerts);
 
             if (verifyFull) {
-                // v4 is an add-on and requires v2/v3 signature to validate against its certificates
-                final PackageParser.SigningDetails nonstreaming = verifyV3AndBelowSignatures(
-                        apkPath, minSignatureSchemeVersion, false);
-                if (nonstreaming.signatureSchemeVersion <= SignatureSchemeVersion.JAR) {
+                // v4 is an add-on and requires v3 signature to validate against its certificates
+                ApkSignatureSchemeV3Verifier.VerifiedSigner nonstreaming =
+                        ApkSignatureSchemeV3Verifier.unsafeGetCertsWithoutVerification(apkPath);
+                Certificate[][] nonstreamingCerts = new Certificate[][]{nonstreaming.certs};
+                Signature[] nonstreamingSigs = convertToSignatures(nonstreamingCerts);
+
+                if (nonstreamingSigs.length != signerSigs.length) {
                     throw new SecurityException(
-                            "V4 signing block can only be verified along with V2 and above.");
-                }
-                if (nonstreaming.signatures.length == 0
-                        || nonstreaming.signatures.length != signerSigs.length) {
-                    throw new SecurityException("Invalid number of signatures in "
-                            + nonstreaming.signatureSchemeVersion);
+                            "Invalid number of certificates: " + nonstreaming.certs.length);
                 }
 
                 for (int i = 0, size = signerSigs.length; i < size; ++i) {
-                    if (!nonstreaming.signatures[i].equals(signerSigs[i])) {
-                        throw new SecurityException("V4 signature certificate does not match "
-                                + nonstreaming.signatureSchemeVersion);
+                    if (!nonstreamingSigs[i].equals(signerSigs[i])) {
+                        throw new SecurityException("V4 signature certificate does not match V3");
                     }
                 }
+
+                // TODO(b/151240006): add support for v2 digest and make it mandatory.
+                if (!ArrayUtils.isEmpty(vSigner.v3Digest) && !ArrayUtils.equals(vSigner.v3Digest,
+                        nonstreaming.digest, vSigner.v3Digest.length)) {
+                    throw new SecurityException("V3 digest in V4 signature does not match V3");
+                }
             }
 
             return new PackageParser.SigningDetails(signerSigs,
diff --git a/core/java/android/util/apk/SourceStampVerifier.java b/core/java/android/util/apk/SourceStampVerifier.java
index 759c864..70e4a51 100644
--- a/core/java/android/util/apk/SourceStampVerifier.java
+++ b/core/java/android/util/apk/SourceStampVerifier.java
@@ -82,25 +82,34 @@
     public static SourceStampVerificationResult verify(String apkFile) {
         try (RandomAccessFile apk = new RandomAccessFile(apkFile, "r")) {
             return verify(apk);
-        } catch (Exception e) {
-            // Any exception in the SourceStamp verification returns a non-verified SourceStamp
-            // outcome without affecting the outcome of any of the other signature schemes.
-            return SourceStampVerificationResult.notVerified();
+        } catch (IOException e) {
+            // Any exception in reading the APK returns a non-present SourceStamp outcome
+            // without affecting the outcome of any of the other signature schemes.
+            return SourceStampVerificationResult.notPresent();
         }
     }
 
-    private static SourceStampVerificationResult verify(RandomAccessFile apk)
-            throws IOException, SignatureNotFoundException {
-        byte[] sourceStampCertificateDigest = getSourceStampCertificateDigest(apk);
-        if (sourceStampCertificateDigest == null) {
-            // SourceStamp certificate hash file not found, which means that there is not
-            // SourceStamp present.
+    private static SourceStampVerificationResult verify(RandomAccessFile apk) {
+        byte[] sourceStampCertificateDigest;
+        try {
+            sourceStampCertificateDigest = getSourceStampCertificateDigest(apk);
+            if (sourceStampCertificateDigest == null) {
+                // SourceStamp certificate hash file not found, which means that there is not
+                // SourceStamp present.
+                return SourceStampVerificationResult.notPresent();
+            }
+        } catch (IOException e) {
             return SourceStampVerificationResult.notPresent();
         }
-        SignatureInfo signatureInfo =
-                ApkSigningBlockUtils.findSignature(apk, SOURCE_STAMP_BLOCK_ID);
-        Map<Integer, byte[]> apkContentDigests = getApkContentDigests(apk);
-        return verify(signatureInfo, apkContentDigests, sourceStampCertificateDigest);
+
+        try {
+            SignatureInfo signatureInfo =
+                    ApkSigningBlockUtils.findSignature(apk, SOURCE_STAMP_BLOCK_ID);
+            Map<Integer, byte[]> apkContentDigests = getApkContentDigests(apk);
+            return verify(signatureInfo, apkContentDigests, sourceStampCertificateDigest);
+        } catch (IOException | SignatureNotFoundException e) {
+            return SourceStampVerificationResult.notVerified();
+        }
     }
 
     private static SourceStampVerificationResult verify(
diff --git a/core/java/android/view/ImeFocusController.java b/core/java/android/view/ImeFocusController.java
index 74fac2b..6784cf7 100644
--- a/core/java/android/view/ImeFocusController.java
+++ b/core/java/android/view/ImeFocusController.java
@@ -165,10 +165,16 @@
         if (!getImmDelegate().isCurrentRootView(view.getViewRootImpl())) {
             return;
         }
-        if (mServedView == view || !view.hasImeFocus() || !view.hasWindowFocus()) {
+        if (!view.hasImeFocus() || !view.hasWindowFocus()) {
             return;
         }
-        mNextServedView = hasFocus ? view : null;
+        if (DEBUG) Log.d(TAG, "onViewFocusChanged, view=" + view + ", mServedView=" + mServedView);
+
+        if (hasFocus) {
+            mNextServedView = view;
+        } else if (view == mServedView) {
+            mNextServedView = null;
+        }
         mViewRootImpl.dispatchCheckFocus();
     }
 
diff --git a/core/java/android/view/InsetsAnimationControlCallbacks.java b/core/java/android/view/InsetsAnimationControlCallbacks.java
index a15d6c7..4227f78 100644
--- a/core/java/android/view/InsetsAnimationControlCallbacks.java
+++ b/core/java/android/view/InsetsAnimationControlCallbacks.java
@@ -56,4 +56,10 @@
      *               apply.
      */
     void applySurfaceParams(SyncRtSurfaceTransactionApplier.SurfaceParams... params);
+
+    /**
+     * Post a message to release the Surface, guaranteed to happen after all
+     * previous calls to applySurfaceParams.
+     */
+    void releaseSurfaceControlFromRt(SurfaceControl sc);
 }
diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java
index 2b30c2d..baee412 100644
--- a/core/java/android/view/InsetsAnimationControlImpl.java
+++ b/core/java/android/view/InsetsAnimationControlImpl.java
@@ -180,10 +180,19 @@
         mAnimation.setAlpha(mPendingAlpha);
         if (mFinished) {
             mController.notifyFinished(this, mShownOnFinish);
+            releaseLeashes();
         }
         return mFinished;
     }
 
+    private void releaseLeashes() {
+        for (int i = mControls.size() - 1; i >= 0; i--) {
+            final InsetsSourceControl c = mControls.valueAt(i);
+            if (c == null) continue;
+            c.release(mController::releaseSurfaceControlFromRt);
+        }
+    }
+
     @Override
     public void finish(boolean shown) {
         if (mCancelled || mFinished) {
@@ -191,6 +200,7 @@
         }
         setInsetsAndAlpha(shown ? mShownInsets : mHiddenInsets, 1f /* alpha */, 1f /* fraction */);
         mFinished = true;
+
         mShownOnFinish = shown;
     }
 
@@ -207,6 +217,8 @@
         }
         mCancelled = true;
         mListener.onCancelled();
+
+        releaseLeashes();
     }
 
     public boolean isCancelled() {
diff --git a/core/java/android/view/InsetsAnimationThreadControlRunner.java b/core/java/android/view/InsetsAnimationThreadControlRunner.java
index 9c27802..13b4cd8 100644
--- a/core/java/android/view/InsetsAnimationThreadControlRunner.java
+++ b/core/java/android/view/InsetsAnimationThreadControlRunner.java
@@ -75,6 +75,12 @@
             t.apply();
             t.close();
         }
+
+        @Override
+        public void releaseSurfaceControlFromRt(SurfaceControl sc) {
+            // Since we don't push the SurfaceParams to the RT we can release directly
+            sc.release();
+        }
     };
 
     @UiThread
diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java
index c1763d6..88e7f2e 100644
--- a/core/java/android/view/InsetsController.java
+++ b/core/java/android/view/InsetsController.java
@@ -704,7 +704,7 @@
             }
             final InsetsSourceControl control = consumer.getControl();
             if (control != null) {
-                controls.put(consumer.getType(), control);
+                controls.put(consumer.getType(), new InsetsSourceControl(control));
                 typesReady |= toPublicType(consumer.getType());
             } else if (animationType == ANIMATION_TYPE_SHOW) {
 
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java
index 8ec5df8..18e0132 100644
--- a/core/java/android/view/NotificationHeaderView.java
+++ b/core/java/android/view/NotificationHeaderView.java
@@ -35,6 +35,7 @@
 
 import com.android.internal.R;
 import com.android.internal.widget.CachingIconView;
+import com.android.internal.widget.NotificationExpandButton;
 
 import java.util.ArrayList;
 
@@ -56,7 +57,7 @@
     private OnClickListener mAppOpsListener;
     private HeaderTouchListener mTouchListener = new HeaderTouchListener();
     private LinearLayout mTransferChip;
-    private ImageView mExpandButton;
+    private NotificationExpandButton mExpandButton;
     private CachingIconView mIcon;
     private View mProfileBadge;
     private View mOverlayIcon;
@@ -65,7 +66,6 @@
     private View mAppOps;
     private View mAudiblyAlertedIcon;
     private int mIconColor;
-    private int mOriginalNotificationColor;
     private boolean mExpanded;
     private boolean mShowExpandButtonAtEnd;
     private boolean mShowWorkBadgeAtEnd;
@@ -324,13 +324,8 @@
         return mIconColor;
     }
 
-    @RemotableViewMethod
-    public void setOriginalNotificationColor(int color) {
-        mOriginalNotificationColor = color;
-    }
-
     public int getOriginalNotificationColor() {
-        return mOriginalNotificationColor;
+        return mExpandButton.getOriginalNotificationColor();
     }
 
     @RemotableViewMethod
@@ -371,7 +366,7 @@
             contentDescriptionId = R.string.expand_button_content_description_collapsed;
         }
         mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
-        mExpandButton.setColorFilter(mOriginalNotificationColor);
+        mExpandButton.setColorFilter(getOriginalNotificationColor());
         mExpandButton.setContentDescription(mContext.getText(contentDescriptionId));
     }
 
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 879f284..708a094 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -3318,7 +3318,7 @@
      * Flag indicating that the view is autofilled
      *
      * @see #isAutofilled()
-     * @see #setAutofilled(boolean)
+     * @see #setAutofilled(boolean, boolean)
      */
     private static final int PFLAG3_IS_AUTOFILLED = 0x10000;
 
@@ -3428,6 +3428,7 @@
      *                         1        PFLAG4_CONTENT_CAPTURE_IMPORTANCE_CACHED_VALUE
      *                         11       PFLAG4_CONTENT_CAPTURE_IMPORTANCE_MASK
      *                        1         PFLAG4_FRAMEWORK_OPTIONAL_FITS_SYSTEM_WINDOWS
+     *                       1          PFLAG4_AUTOFILL_HIDE_HIGHLIGHT
      * |-------|-------|-------|-------|
      */
 
@@ -3470,6 +3471,11 @@
      */
     static final int PFLAG4_FRAMEWORK_OPTIONAL_FITS_SYSTEM_WINDOWS = 0x000000100;
 
+    /**
+     * Flag indicating the field should not have yellow highlight when autofilled.
+     */
+    private static final int PFLAG4_AUTOFILL_HIDE_HIGHLIGHT = 0x100;
+
     /* End of masks for mPrivateFlags4 */
 
     /** @hide */
@@ -9170,6 +9176,13 @@
     }
 
     /**
+     * @hide
+     */
+    public boolean hideAutofillHighlight() {
+        return (mPrivateFlags4 & PFLAG4_AUTOFILL_HIDE_HIGHLIGHT) != 0;
+    }
+
+    /**
      * Gets the {@link View}'s current autofill value.
      *
      * <p>By default returns {@code null}, but subclasses should override it and return an
@@ -11750,7 +11763,7 @@
      * @hide
      */
     @TestApi
-    public void setAutofilled(boolean isAutofilled) {
+    public void setAutofilled(boolean isAutofilled, boolean hideHighlight) {
         boolean wasChanged = isAutofilled != isAutofilled();
 
         if (wasChanged) {
@@ -11760,6 +11773,12 @@
                 mPrivateFlags3 &= ~PFLAG3_IS_AUTOFILLED;
             }
 
+            if (hideHighlight) {
+                mPrivateFlags4 |= PFLAG4_AUTOFILL_HIDE_HIGHLIGHT;
+            } else {
+                mPrivateFlags4 &= ~PFLAG4_AUTOFILL_HIDE_HIGHLIGHT;
+            }
+
             invalidate();
         }
     }
@@ -20578,6 +20597,7 @@
 
             state.mStartActivityRequestWhoSaved = mStartActivityRequestWho;
             state.mIsAutofilled = isAutofilled();
+            state.mHideHighlight = hideAutofillHighlight();
             state.mAutofillViewId = mAutofillViewId;
             return state;
         }
@@ -20654,7 +20674,7 @@
                 mStartActivityRequestWho = baseState.mStartActivityRequestWhoSaved;
             }
             if ((baseState.mSavedData & BaseSavedState.IS_AUTOFILLED) != 0) {
-                setAutofilled(baseState.mIsAutofilled);
+                setAutofilled(baseState.mIsAutofilled, baseState.mHideHighlight);
             }
             if ((baseState.mSavedData & BaseSavedState.AUTOFILL_ID) != 0) {
                 // It can happen that views have the same view id and the restoration path will not
@@ -24087,12 +24107,13 @@
     }
 
     /**
-     * Draw {@link View#isAutofilled()} highlight over view if the view is autofilled.
+     * Draw {@link View#isAutofilled()} highlight over view if the view is autofilled, unless
+     * {@link #PFLAG4_AUTOFILL_HIDE_HIGHLIGHT} is enabled.
      *
      * @param canvas The canvas to draw on
      */
     private void drawAutofilledHighlight(@NonNull Canvas canvas) {
-        if (isAutofilled()) {
+        if (isAutofilled() && !hideAutofillHighlight()) {
             Drawable autofilledHighlight = getAutofilledDrawable();
 
             if (autofilledHighlight != null) {
@@ -28535,6 +28556,7 @@
         int mSavedData;
         String mStartActivityRequestWhoSaved;
         boolean mIsAutofilled;
+        boolean mHideHighlight;
         int mAutofillViewId;
 
         /**
@@ -28558,6 +28580,7 @@
             mSavedData = source.readInt();
             mStartActivityRequestWhoSaved = source.readString();
             mIsAutofilled = source.readBoolean();
+            mHideHighlight = source.readBoolean();
             mAutofillViewId = source.readInt();
         }
 
@@ -28577,6 +28600,7 @@
             out.writeInt(mSavedData);
             out.writeString(mStartActivityRequestWhoSaved);
             out.writeBoolean(mIsAutofilled);
+            out.writeBoolean(mHideHighlight);
             out.writeInt(mAutofillViewId);
         }
 
@@ -29075,8 +29099,33 @@
             mTreeObserver = new ViewTreeObserver(context);
         }
 
+        @Nullable
+        ContentCaptureManager getContentCaptureManager(@NonNull Context context) {
+            if (mContentCaptureManager != null) {
+                return mContentCaptureManager;
+            }
+            mContentCaptureManager = context.getSystemService(ContentCaptureManager.class);
+            return mContentCaptureManager;
+        }
+
+        void delayNotifyContentCaptureInsetsEvent(@NonNull Insets insets) {
+            if (mContentCaptureManager == null) {
+                return;
+            }
+
+            ArrayList<Object> events = ensureEvents(
+                        mContentCaptureManager.getMainContentCaptureSession());
+            events.add(insets);
+        }
+
         private void delayNotifyContentCaptureEvent(@NonNull ContentCaptureSession session,
                 @NonNull View view, boolean appeared) {
+            ArrayList<Object> events = ensureEvents(session);
+            events.add(appeared ? view : view.getAutofillId());
+        }
+
+        @NonNull
+        private ArrayList<Object> ensureEvents(@NonNull ContentCaptureSession session) {
             if (mContentCaptureEvents == null) {
                 // Most of the time there will be just one session, so intial capacity is 1
                 mContentCaptureEvents = new SparseArray<>(1);
@@ -29088,16 +29137,8 @@
                 events = new ArrayList<>();
                 mContentCaptureEvents.put(sessionId, events);
             }
-            events.add(appeared ? view : view.getAutofillId());
-        }
 
-        @Nullable
-        ContentCaptureManager getContentCaptureManager(@NonNull Context context) {
-            if (mContentCaptureManager != null) {
-                return mContentCaptureManager;
-            }
-            mContentCaptureManager = context.getSystemService(ContentCaptureManager.class);
-            return mContentCaptureManager;
+            return events;
         }
     }
 
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 26ac4fc..dd34bcb 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -81,6 +81,7 @@
 import android.graphics.Color;
 import android.graphics.FrameInfo;
 import android.graphics.HardwareRenderer.FrameDrawingCallback;
+import android.graphics.Insets;
 import android.graphics.Matrix;
 import android.graphics.PixelFormat;
 import android.graphics.Point;
@@ -2254,6 +2255,7 @@
             insets = insets.consumeDisplayCutout();
         }
         host.dispatchApplyWindowInsets(insets);
+        mAttachInfo.delayNotifyContentCaptureInsetsEvent(insets.getInsets(Type.all()));
         Trace.traceEnd(Trace.TRACE_TAG_VIEW);
     }
 
@@ -3118,6 +3120,8 @@
                         ViewStructure structure = session.newViewStructure(view);
                         view.onProvideContentCaptureStructure(structure, /* flags= */ 0);
                         session.notifyViewAppeared(structure);
+                    } else if (event instanceof Insets) {
+                        mainSession.notifyViewInsetsChanged(sessionId, (Insets) event);
                     } else {
                         Log.w(mTag, "invalid content capture event: " + event);
                     }
diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java
index dda4e8b..39a9ed4 100644
--- a/core/java/android/view/autofill/AutofillManager.java
+++ b/core/java/android/view/autofill/AutofillManager.java
@@ -1236,7 +1236,7 @@
             // If the session is gone some fields might still be highlighted, hence we have to
             // remove the isAutofilled property even if no sessions are active.
             if (mLastAutofilledData == null) {
-                view.setAutofilled(false);
+                view.setAutofilled(false, false);
             } else {
                 id = view.getAutofillId();
                 if (mLastAutofilledData.containsKey(id)) {
@@ -1244,13 +1244,13 @@
                     valueWasRead = true;
 
                     if (Objects.equals(mLastAutofilledData.get(id), value)) {
-                        view.setAutofilled(true);
+                        view.setAutofilled(true, false);
                     } else {
-                        view.setAutofilled(false);
+                        view.setAutofilled(false, false);
                         mLastAutofilledData.remove(id);
                     }
                 } else {
-                    view.setAutofilled(false);
+                    view.setAutofilled(false, false);
                 }
             }
 
@@ -2166,7 +2166,8 @@
      * @param view The view that is to be autofilled
      * @param targetValue The value we want to fill into view
      */
-    private void setAutofilledIfValuesIs(@NonNull View view, @Nullable AutofillValue targetValue) {
+    private void setAutofilledIfValuesIs(@NonNull View view, @Nullable AutofillValue targetValue,
+            boolean hideHighlight) {
         AutofillValue currentValue = view.getAutofillValue();
         if (Objects.equals(currentValue, targetValue)) {
             synchronized (mLock) {
@@ -2175,11 +2176,12 @@
                 }
                 mLastAutofilledData.put(view.getAutofillId(), targetValue);
             }
-            view.setAutofilled(true);
+            view.setAutofilled(true, hideHighlight);
         }
     }
 
-    private void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) {
+    private void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values,
+            boolean hideHighlight) {
         synchronized (mLock) {
             if (sessionId != mSessionId) {
                 return;
@@ -2238,7 +2240,7 @@
                     // synchronously.
                     // If autofill happens async, the view is set to autofilled in
                     // notifyValueChanged.
-                    setAutofilledIfValuesIs(view, value);
+                    setAutofilledIfValuesIs(view, value, hideHighlight);
 
                     numApplied++;
                 }
@@ -3256,10 +3258,11 @@
         }
 
         @Override
-        public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) {
+        public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values,
+                boolean hideHighlight) {
             final AutofillManager afm = mAfm.get();
             if (afm != null) {
-                afm.post(() -> afm.autofill(sessionId, ids, values));
+                afm.post(() -> afm.autofill(sessionId, ids, values, hideHighlight));
             }
         }
 
@@ -3397,10 +3400,11 @@
         }
 
         @Override
-        public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values) {
+        public void autofill(int sessionId, List<AutofillId> ids, List<AutofillValue> values,
+                boolean hideHighlight) {
             final AutofillManager afm = mAfm.get();
             if (afm != null) {
-                afm.post(() -> afm.autofill(sessionId, ids, values));
+                afm.post(() -> afm.autofill(sessionId, ids, values, hideHighlight));
             }
         }
 
diff --git a/core/java/android/view/autofill/IAugmentedAutofillManagerClient.aidl b/core/java/android/view/autofill/IAugmentedAutofillManagerClient.aidl
index 03054df..8526c1e 100644
--- a/core/java/android/view/autofill/IAugmentedAutofillManagerClient.aidl
+++ b/core/java/android/view/autofill/IAugmentedAutofillManagerClient.aidl
@@ -38,7 +38,8 @@
     /**
      * Autofills the activity with the contents of the values.
      */
-    void autofill(int sessionId, in List<AutofillId> ids, in List<AutofillValue> values);
+    void autofill(int sessionId, in List<AutofillId> ids, in List<AutofillValue> values,
+            boolean hideHighlight);
 
     /**
       * Requests showing the fill UI.
diff --git a/core/java/android/view/autofill/IAutoFillManagerClient.aidl b/core/java/android/view/autofill/IAutoFillManagerClient.aidl
index 3903665..4371b3c 100644
--- a/core/java/android/view/autofill/IAutoFillManagerClient.aidl
+++ b/core/java/android/view/autofill/IAutoFillManagerClient.aidl
@@ -44,7 +44,8 @@
     /**
       * Autofills the activity with the contents of a dataset.
       */
-    void autofill(int sessionId, in List<AutofillId> ids, in List<AutofillValue> values);
+    void autofill(int sessionId, in List<AutofillId> ids, in List<AutofillValue> values,
+            boolean hideHighlight);
 
     /**
       * Authenticates a fill response or a data set.
diff --git a/core/java/android/view/contentcapture/ChildContentCaptureSession.java b/core/java/android/view/contentcapture/ChildContentCaptureSession.java
index 7487ec4..44b4353 100644
--- a/core/java/android/view/contentcapture/ChildContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ChildContentCaptureSession.java
@@ -17,6 +17,7 @@
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
+import android.graphics.Insets;
 import android.view.autofill.AutofillId;
 import android.view.contentcapture.ViewNode.ViewStructureImpl;
 
@@ -84,6 +85,11 @@
     }
 
     @Override
+    void internalNotifyViewInsetsChanged(@NonNull Insets viewInsets) {
+        getMainCaptureSession().notifyViewInsetsChanged(mId, viewInsets);
+    }
+
+    @Override
     public void internalNotifyViewTreeEvent(boolean started) {
         getMainCaptureSession().notifyViewTreeEvent(mId, started);
     }
diff --git a/core/java/android/view/contentcapture/ContentCaptureEvent.java b/core/java/android/view/contentcapture/ContentCaptureEvent.java
index c29d251..ea34d94 100644
--- a/core/java/android/view/contentcapture/ContentCaptureEvent.java
+++ b/core/java/android/view/contentcapture/ContentCaptureEvent.java
@@ -23,6 +23,7 @@
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
 import android.annotation.TestApi;
+import android.graphics.Insets;
 import android.os.Parcel;
 import android.os.Parcelable;
 import android.util.Log;
@@ -112,6 +113,11 @@
      */
     public static final int TYPE_SESSION_PAUSED = 8;
 
+    /**
+     * Called when the view's insets are changed. The new insets associated with the
+     * event may then be retrieved by calling {@link #getInsets()}
+     */
+    public static final int TYPE_VIEW_INSETS_CHANGED = 9;
 
     /** @hide */
     @IntDef(prefix = { "TYPE_" }, value = {
@@ -122,7 +128,8 @@
             TYPE_VIEW_TREE_APPEARED,
             TYPE_CONTEXT_UPDATED,
             TYPE_SESSION_PAUSED,
-            TYPE_SESSION_RESUMED
+            TYPE_SESSION_RESUMED,
+            TYPE_VIEW_INSETS_CHANGED
     })
     @Retention(RetentionPolicy.SOURCE)
     public @interface EventType{}
@@ -136,6 +143,7 @@
     private @Nullable CharSequence mText;
     private int mParentSessionId = NO_SESSION_ID;
     private @Nullable ContentCaptureContext mClientContext;
+    private @Nullable Insets mInsets;
 
     /** @hide */
     public ContentCaptureEvent(int sessionId, int type, long eventTime) {
@@ -242,6 +250,13 @@
         return this;
     }
 
+    /** @hide */
+    @NonNull
+    public ContentCaptureEvent setInsets(@NonNull Insets insets) {
+        mInsets = insets;
+        return this;
+    }
+
     /**
      * Gets the type of the event.
      *
@@ -305,6 +320,16 @@
     }
 
     /**
+     * Gets the rectangle of the insets associated with the event. Valid insets will only be
+     * returned if the type of the event is {@link #TYPE_VIEW_INSETS_CHANGED}, otherwise they
+     * will be null.
+     */
+    @Nullable
+    public Insets getInsets() {
+        return mInsets;
+    }
+
+    /**
      * Merges event of the same type, either {@link #TYPE_VIEW_TEXT_CHANGED}
      * or {@link #TYPE_VIEW_DISAPPEARED}.
      *
@@ -369,7 +394,9 @@
         }
         if (mClientContext != null) {
             pw.print(", context="); mClientContext.dump(pw); pw.println();
-
+        }
+        if (mInsets != null) {
+            pw.print(", insets="); pw.println(mInsets);
         }
     }
 
@@ -401,6 +428,9 @@
         if (mClientContext != null) {
             string.append(", context=").append(mClientContext);
         }
+        if (mInsets != null) {
+            string.append(", insets=").append(mInsets);
+        }
         return string.append(']').toString();
     }
 
@@ -424,6 +454,9 @@
         if (mType == TYPE_SESSION_STARTED || mType == TYPE_CONTEXT_UPDATED) {
             parcel.writeParcelable(mClientContext, flags);
         }
+        if (mType == TYPE_VIEW_INSETS_CHANGED) {
+            parcel.writeParcelable(mInsets, flags);
+        }
     }
 
     public static final @android.annotation.NonNull Parcelable.Creator<ContentCaptureEvent> CREATOR =
@@ -455,6 +488,9 @@
             if (type == TYPE_SESSION_STARTED || type == TYPE_CONTEXT_UPDATED) {
                 event.setClientContext(parcel.readParcelable(null));
             }
+            if (type == TYPE_VIEW_INSETS_CHANGED) {
+                event.setInsets(parcel.readParcelable(null));
+            }
             return event;
         }
 
@@ -488,6 +524,8 @@
                 return "VIEW_TREE_APPEARED";
             case TYPE_CONTEXT_UPDATED:
                 return "CONTEXT_UPDATED";
+            case TYPE_VIEW_INSETS_CHANGED:
+                return "VIEW_INSETS_CHANGED";
             default:
                 return "UKNOWN_TYPE: " + type;
         }
diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java
index 2134dab..012f5e6 100644
--- a/core/java/android/view/contentcapture/ContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/ContentCaptureSession.java
@@ -23,6 +23,7 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.SystemApi;
+import android.graphics.Insets;
 import android.util.DebugUtils;
 import android.util.Log;
 import android.view.View;
@@ -440,6 +441,19 @@
     abstract void internalNotifyViewTextChanged(@NonNull AutofillId id,
             @Nullable CharSequence text);
 
+    /**
+     * Notifies the Intelligence Service that the insets of a view have changed.
+     */
+    public final void notifyViewInsetsChanged(@NonNull Insets viewInsets) {
+        Preconditions.checkNotNull(viewInsets);
+
+        if (!isContentCaptureEnabled()) return;
+
+        internalNotifyViewInsetsChanged(viewInsets);
+    }
+
+    abstract void internalNotifyViewInsetsChanged(@NonNull Insets viewInsets);
+
     /** @hide */
     public abstract void internalNotifyViewTreeEvent(boolean started);
 
diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java
index 96f224f..893d38d 100644
--- a/core/java/android/view/contentcapture/MainContentCaptureSession.java
+++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java
@@ -22,6 +22,7 @@
 import static android.view.contentcapture.ContentCaptureEvent.TYPE_SESSION_STARTED;
 import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_APPEARED;
 import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_DISAPPEARED;
+import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_INSETS_CHANGED;
 import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_TEXT_CHANGED;
 import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_TREE_APPEARED;
 import static android.view.contentcapture.ContentCaptureEvent.TYPE_VIEW_TREE_APPEARING;
@@ -36,6 +37,7 @@
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.ParceledListSlice;
+import android.graphics.Insets;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.IBinder;
@@ -578,6 +580,11 @@
     }
 
     @Override
+    void internalNotifyViewInsetsChanged(@NonNull Insets viewInsets) {
+        notifyViewInsetsChanged(mId, viewInsets);
+    }
+
+    @Override
     public void internalNotifyViewTreeEvent(boolean started) {
         notifyViewTreeEvent(mId, started);
     }
@@ -642,6 +649,12 @@
     }
 
     /** Public because is also used by ViewRootImpl */
+    public void notifyViewInsetsChanged(int sessionId, @NonNull Insets viewInsets) {
+        sendEvent(new ContentCaptureEvent(sessionId, TYPE_VIEW_INSETS_CHANGED)
+                .setInsets(viewInsets));
+    }
+
+    /** Public because is also used by ViewRootImpl */
     public void notifyViewTreeEvent(int sessionId, boolean started) {
         final int type = started ? TYPE_VIEW_TREE_APPEARING : TYPE_VIEW_TREE_APPEARED;
         sendEvent(new ContentCaptureEvent(sessionId, type), FORCE_FLUSH);
diff --git a/core/java/android/view/inputmethod/InlineSuggestion.java b/core/java/android/view/inputmethod/InlineSuggestion.java
index 6500613..dd1738a 100644
--- a/core/java/android/view/inputmethod/InlineSuggestion.java
+++ b/core/java/android/view/inputmethod/InlineSuggestion.java
@@ -16,6 +16,7 @@
 
 package android.view.inputmethod;
 
+import android.annotation.BinderThread;
 import android.annotation.CallbackExecutor;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -94,19 +95,21 @@
     }
 
 
-
     /**
      * Inflates a view with the content of this suggestion at a specific size.
      * The size must be between the {@link InlinePresentationSpec#getMinSize() min size}
      * and the {@link InlinePresentationSpec#getMaxSize() max size} of the presentation
      * spec returned by {@link InlineSuggestionInfo#getPresentationSpec()}.
      *
-     * @param context Context in which to inflate the view.
-     * @param size The size at which to inflate the suggestion.
-     * @param callback Callback for receiving the inflated view.
+     * <p> The caller can attach an {@link View.OnClickListener} and/or an
+     * {@link View.OnLongClickListener} to the view in the {@code callback} to receive click and
+     * long click events on the view.
      *
+     * @param context  Context in which to inflate the view.
+     * @param size     The size at which to inflate the suggestion.
+     * @param callback Callback for receiving the inflated view.
      * @throws IllegalArgumentException If an invalid argument is passed.
-     * @throws IllegalStateException if this method is already called.
+     * @throws IllegalStateException    If this method is already called.
      */
     public void inflate(@NonNull Context context, @NonNull Size size,
             @NonNull @CallbackExecutor Executor callbackExecutor,
@@ -151,12 +154,31 @@
         }
 
         @Override
+        @BinderThread
         public void onContent(SurfaceControlViewHost.SurfacePackage content) {
             final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get();
             if (callbackImpl != null) {
                 callbackImpl.onContent(content);
             }
         }
+
+        @Override
+        @BinderThread
+        public void onClick() {
+            final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get();
+            if (callbackImpl != null) {
+                callbackImpl.onClick();
+            }
+        }
+
+        @Override
+        @BinderThread
+        public void onLongClick() {
+            final InlineContentCallbackImpl callbackImpl = mCallbackImpl.get();
+            if (callbackImpl != null) {
+                callbackImpl.onLongClick();
+            }
+        }
     }
 
     private static final class InlineContentCallbackImpl {
@@ -164,6 +186,7 @@
         private final @NonNull Context mContext;
         private final @NonNull Executor mCallbackExecutor;
         private final @NonNull Consumer<View> mCallback;
+        private @Nullable View mView;
 
         InlineContentCallbackImpl(@NonNull Context context,
                 @NonNull @CallbackExecutor Executor callbackExecutor,
@@ -173,12 +196,27 @@
             mCallback = callback;
         }
 
+        @BinderThread
         public void onContent(SurfaceControlViewHost.SurfacePackage content) {
             if (content == null) {
                 mCallbackExecutor.execute(() -> mCallback.accept(/* view */null));
             } else {
-                mCallbackExecutor.execute(
-                        () -> mCallback.accept(new InlineContentView(mContext, content)));
+                mView = new InlineContentView(mContext, content);
+                mCallbackExecutor.execute(() -> mCallback.accept(mView));
+            }
+        }
+
+        @BinderThread
+        public void onClick() {
+            if (mView != null && mView.hasOnClickListeners()) {
+                mView.callOnClick();
+            }
+        }
+
+        @BinderThread
+        public void onLongClick() {
+            if (mView != null && mView.hasOnLongClickListeners()) {
+                mView.performLongClick();
             }
         }
     }
@@ -201,7 +239,7 @@
 
 
 
-    // Code below generated by codegen v1.0.14.
+    // Code below generated by codegen v1.0.15.
     //
     // DO NOT MODIFY!
     // CHECKSTYLE:OFF Generated code
@@ -360,8 +398,8 @@
     };
 
     @DataClass.Generated(
-            time = 1581929285156L,
-            codegenVersion = "1.0.14",
+            time = 1583889058241L,
+            codegenVersion = "1.0.15",
             sourceFile = "frameworks/base/core/java/android/view/inputmethod/InlineSuggestion.java",
             inputSignatures = "private static final  java.lang.String TAG\nprivate final @android.annotation.NonNull android.view.inputmethod.InlineSuggestionInfo mInfo\nprivate final @android.annotation.Nullable com.android.internal.view.inline.IInlineContentProvider mContentProvider\nprivate @com.android.internal.util.DataClass.ParcelWith(android.view.inputmethod.InlineSuggestion.InlineContentCallbackImplParceling.class) @android.annotation.Nullable android.view.inputmethod.InlineSuggestion.InlineContentCallbackImpl mInlineContentCallback\npublic static @android.annotation.TestApi @android.annotation.NonNull android.view.inputmethod.InlineSuggestion newInlineSuggestion(android.view.inputmethod.InlineSuggestionInfo)\npublic  void inflate(android.content.Context,android.util.Size,java.util.concurrent.Executor,java.util.function.Consumer<android.view.View>)\nprivate synchronized  android.view.inputmethod.InlineSuggestion.InlineContentCallbackImpl getInlineContentCallback(android.content.Context,java.util.concurrent.Executor,java.util.function.Consumer<android.view.View>)\nclass InlineSuggestion extends java.lang.Object implements [android.os.Parcelable]\n@com.android.internal.util.DataClass(genEqualsHashCode=true, genToString=true, genHiddenConstDefs=true, genHiddenConstructor=true)")
     @Deprecated
diff --git a/core/java/android/view/textclassifier/ConversationActions.java b/core/java/android/view/textclassifier/ConversationActions.java
index 6246b50..842ba29 100644
--- a/core/java/android/view/textclassifier/ConversationActions.java
+++ b/core/java/android/view/textclassifier/ConversationActions.java
@@ -21,15 +21,12 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.annotation.StringDef;
-import android.annotation.UserIdInt;
 import android.app.Person;
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.os.UserHandle;
 import android.text.SpannedString;
 
-import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.util.Preconditions;
 
 import java.lang.annotation.Retention;
@@ -317,13 +314,9 @@
         @NonNull
         @Hint
         private final List<String> mHints;
-        @Nullable
-        private String mCallingPackageName;
-        @UserIdInt
-        private int mUserId = UserHandle.USER_NULL;
         @NonNull
         private Bundle mExtras;
-        private boolean mUseDefaultTextClassifier;
+        @Nullable private SystemTextClassifierMetadata mSystemTcMetadata;
 
         private Request(
                 @NonNull List<Message> conversation,
@@ -345,10 +338,8 @@
             int maxSuggestions = in.readInt();
             List<String> hints = new ArrayList<>();
             in.readStringList(hints);
-            String callingPackageName = in.readString();
-            int userId = in.readInt();
             Bundle extras = in.readBundle();
-            boolean useDefaultTextClassifier = in.readBoolean();
+            SystemTextClassifierMetadata systemTcMetadata = in.readParcelable(null);
 
             Request request = new Request(
                     conversation,
@@ -356,9 +347,7 @@
                     maxSuggestions,
                     hints,
                     extras);
-            request.setCallingPackageName(callingPackageName);
-            request.setUserId(userId);
-            request.setUseDefaultTextClassifier(useDefaultTextClassifier);
+            request.setSystemTextClassifierMetadata(systemTcMetadata);
             return request;
         }
 
@@ -368,10 +357,8 @@
             parcel.writeParcelable(mTypeConfig, flags);
             parcel.writeInt(mMaxSuggestions);
             parcel.writeStringList(mHints);
-            parcel.writeString(mCallingPackageName);
-            parcel.writeInt(mUserId);
             parcel.writeBundle(mExtras);
-            parcel.writeBoolean(mUseDefaultTextClassifier);
+            parcel.writeParcelable(mSystemTcMetadata, flags);
         }
 
         @Override
@@ -421,62 +408,31 @@
         }
 
         /**
-         * Sets the name of the package that is sending this request.
-         * <p>
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
-        public void setCallingPackageName(@Nullable String callingPackageName) {
-            mCallingPackageName = callingPackageName;
-        }
-
-        /**
          * Returns the name of the package that sent this request.
          * This returns {@code null} if no calling package name is set.
          */
         @Nullable
         public String getCallingPackageName() {
-            return mCallingPackageName;
+            return mSystemTcMetadata != null ? mSystemTcMetadata.getCallingPackageName() : null;
         }
 
         /**
-         * Sets the id of the user that sent this request.
-         * <p>
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        void setUserId(@UserIdInt int userId) {
-            mUserId = userId;
-        }
-
-        /**
-         * Returns the id of the user that sent this request.
-         * @hide
-         */
-        @UserIdInt
-        public int getUserId() {
-            return mUserId;
-        }
-
-        /**
-         * Sets whether to use the default text classifier to handle this request.
-         * This will be ignored if it is not the system text classifier to handle this request.
+         * Sets the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        void setUseDefaultTextClassifier(boolean useDefaultTextClassifier) {
-            mUseDefaultTextClassifier = useDefaultTextClassifier;
+        void setSystemTextClassifierMetadata(@Nullable SystemTextClassifierMetadata systemTcData) {
+            mSystemTcMetadata = systemTcData;
         }
 
         /**
-         * Returns whether to use the default text classifier to handle this request. This
-         * will be ignored if it is not the system text classifier to handle this request.
+         * Returns the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        public boolean getUseDefaultTextClassifier() {
-            return mUseDefaultTextClassifier;
+        @Nullable
+        public SystemTextClassifierMetadata getSystemTextClassifierMetadata() {
+            return mSystemTcMetadata;
         }
 
         /**
diff --git a/core/java/android/view/textclassifier/SelectionEvent.java b/core/java/android/view/textclassifier/SelectionEvent.java
index e0f29a9..9a54544 100644
--- a/core/java/android/view/textclassifier/SelectionEvent.java
+++ b/core/java/android/view/textclassifier/SelectionEvent.java
@@ -19,10 +19,8 @@
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.annotation.UserIdInt;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.os.UserHandle;
 import android.view.textclassifier.TextClassifier.EntityType;
 import android.view.textclassifier.TextClassifier.WidgetType;
 
@@ -129,7 +127,6 @@
     private String mWidgetType = TextClassifier.WIDGET_TYPE_UNKNOWN;
     private @InvocationMethod int mInvocationMethod;
     @Nullable private String mWidgetVersion;
-    private @UserIdInt int mUserId = UserHandle.USER_NULL;
     @Nullable private String mResultId;
     private long mEventTime;
     private long mDurationSinceSessionStart;
@@ -140,7 +137,7 @@
     private int mEnd;
     private int mSmartStart;
     private int mSmartEnd;
-    private boolean mUseDefaultTextClassifier;
+    @Nullable private SystemTextClassifierMetadata mSystemTcMetadata;
 
     SelectionEvent(
             int start, int end,
@@ -161,6 +158,7 @@
         mEventType = in.readInt();
         mEntityType = in.readString();
         mWidgetVersion = in.readInt() > 0 ? in.readString() : null;
+        // TODO: remove mPackageName once aiai does not need it
         mPackageName = in.readString();
         mWidgetType = in.readString();
         mInvocationMethod = in.readInt();
@@ -175,8 +173,7 @@
         mEnd = in.readInt();
         mSmartStart = in.readInt();
         mSmartEnd = in.readInt();
-        mUserId = in.readInt();
-        mUseDefaultTextClassifier = in.readBoolean();
+        mSystemTcMetadata = in.readParcelable(null);
     }
 
     @Override
@@ -189,6 +186,7 @@
         if (mWidgetVersion != null) {
             dest.writeString(mWidgetVersion);
         }
+        // TODO: remove mPackageName once aiai does not need it
         dest.writeString(mPackageName);
         dest.writeString(mWidgetType);
         dest.writeInt(mInvocationMethod);
@@ -205,8 +203,7 @@
         dest.writeInt(mEnd);
         dest.writeInt(mSmartStart);
         dest.writeInt(mSmartEnd);
-        dest.writeInt(mUserId);
-        dest.writeBoolean(mUseDefaultTextClassifier);
+        dest.writeParcelable(mSystemTcMetadata, flags);
     }
 
     @Override
@@ -409,45 +406,26 @@
      */
     @NonNull
     public String getPackageName() {
-        return mPackageName;
+        return mSystemTcMetadata != null ? mSystemTcMetadata.getCallingPackageName() : "";
     }
 
     /**
-     * Sets the id of this event's user.
-     * <p>
-     * Package-private for SystemTextClassifier's use.
-     */
-    void setUserId(@UserIdInt int userId) {
-        mUserId = userId;
-    }
-
-    /**
-     * Returns the id of this event's user.
-     * @hide
-     */
-    @UserIdInt
-    public int getUserId() {
-        return mUserId;
-    }
-
-    /**
-     * Sets whether to use the default text classifier to handle this request.
-     * This will be ignored if it is not the system text classifier to handle this request.
+     * Sets the information about the {@link SystemTextClassifier} that sent this request.
      *
      * @hide
      */
-    void setUseDefaultTextClassifier(boolean useDefaultTextClassifier) {
-        mUseDefaultTextClassifier = useDefaultTextClassifier;
+    void setSystemTextClassifierMetadata(@Nullable SystemTextClassifierMetadata systemTcMetadata) {
+        mSystemTcMetadata = systemTcMetadata;
     }
 
     /**
-     * Returns whether to use the default text classifier to handle this request. This
-     * will be ignored if it is not the system text classifier to handle this request.
+     * Returns the information about the {@link SystemTextClassifier} that sent this request.
      *
      * @hide
      */
-    public boolean getUseDefaultTextClassifier() {
-        return mUseDefaultTextClassifier;
+    @Nullable
+    public SystemTextClassifierMetadata getSystemTextClassifierMetadata() {
+        return mSystemTcMetadata;
     }
 
     /**
@@ -476,7 +454,7 @@
         mPackageName = context.getPackageName();
         mWidgetType = context.getWidgetType();
         mWidgetVersion = context.getWidgetVersion();
-        mUserId = context.getUserId();
+        mSystemTcMetadata = context.getSystemTextClassifierMetadata();
     }
 
     /**
@@ -663,10 +641,9 @@
     @Override
     public int hashCode() {
         return Objects.hash(mAbsoluteStart, mAbsoluteEnd, mEventType, mEntityType,
-                mWidgetVersion, mPackageName, mUserId, mWidgetType, mInvocationMethod, mResultId,
+                mWidgetVersion, mPackageName, mWidgetType, mInvocationMethod, mResultId,
                 mEventTime, mDurationSinceSessionStart, mDurationSincePreviousEvent,
-                mEventIndex, mSessionId, mStart, mEnd, mSmartStart, mSmartEnd,
-                mUseDefaultTextClassifier);
+                mEventIndex, mSessionId, mStart, mEnd, mSmartStart, mSmartEnd, mSystemTcMetadata);
     }
 
     @Override
@@ -685,7 +662,6 @@
                 && Objects.equals(mEntityType, other.mEntityType)
                 && Objects.equals(mWidgetVersion, other.mWidgetVersion)
                 && Objects.equals(mPackageName, other.mPackageName)
-                && mUserId == other.mUserId
                 && Objects.equals(mWidgetType, other.mWidgetType)
                 && mInvocationMethod == other.mInvocationMethod
                 && Objects.equals(mResultId, other.mResultId)
@@ -698,7 +674,7 @@
                 && mEnd == other.mEnd
                 && mSmartStart == other.mSmartStart
                 && mSmartEnd == other.mSmartEnd
-                && mUseDefaultTextClassifier == other.mUseDefaultTextClassifier;
+                && mSystemTcMetadata == other.mSystemTcMetadata;
     }
 
     @Override
@@ -706,15 +682,14 @@
         return String.format(Locale.US,
                 "SelectionEvent {absoluteStart=%d, absoluteEnd=%d, eventType=%d, entityType=%s, "
                         + "widgetVersion=%s, packageName=%s, widgetType=%s, invocationMethod=%s, "
-                        + "userId=%d, resultId=%s, eventTime=%d, durationSinceSessionStart=%d, "
+                        + "resultId=%s, eventTime=%d, durationSinceSessionStart=%d, "
                         + "durationSincePreviousEvent=%d, eventIndex=%d,"
                         + "sessionId=%s, start=%d, end=%d, smartStart=%d, smartEnd=%d, "
-                        + "mUseDefaultTextClassifier=%b}",
+                        + "systemTcMetadata=%s}",
                 mAbsoluteStart, mAbsoluteEnd, mEventType, mEntityType,
                 mWidgetVersion, mPackageName, mWidgetType, mInvocationMethod,
-                mUserId, mResultId, mEventTime, mDurationSinceSessionStart,
-                mDurationSincePreviousEvent, mEventIndex,
-                mSessionId, mStart, mEnd, mSmartStart, mSmartEnd, mUseDefaultTextClassifier);
+                mResultId, mEventTime, mDurationSinceSessionStart, mDurationSincePreviousEvent,
+                mEventIndex, mSessionId, mStart, mEnd, mSmartStart, mSmartEnd, mSystemTcMetadata);
     }
 
     public static final @android.annotation.NonNull Creator<SelectionEvent> CREATOR = new Creator<SelectionEvent>() {
diff --git a/core/java/android/view/textclassifier/SystemTextClassifier.java b/core/java/android/view/textclassifier/SystemTextClassifier.java
index fe5e8d6..86ef4e1 100644
--- a/core/java/android/view/textclassifier/SystemTextClassifier.java
+++ b/core/java/android/view/textclassifier/SystemTextClassifier.java
@@ -18,7 +18,6 @@
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.annotation.UserIdInt;
 import android.annotation.WorkerThread;
 import android.content.Context;
 import android.os.Bundle;
@@ -39,7 +38,8 @@
 import java.util.concurrent.TimeUnit;
 
 /**
- * Proxy to the system's default TextClassifier.
+ * proxy to the request to TextClassifierService via the TextClassificationManagerService.
+ *
  * @hide
  */
 @VisibleForTesting(visibility = Visibility.PACKAGE)
@@ -50,14 +50,19 @@
     private final ITextClassifierService mManagerService;
     private final TextClassificationConstants mSettings;
     private final TextClassifier mFallback;
-    private final String mPackageName;
-    // NOTE: Always set this before sending a request to the manager service otherwise the manager
-    // service will throw a remote exception.
-    @UserIdInt
-    private final int mUserId;
-    private final boolean mUseDefault;
     private TextClassificationSessionId mSessionId;
+    // NOTE: Always set this before sending a request to the manager service otherwise the
+    // manager service will throw a remote exception.
+    @NonNull
+    private final SystemTextClassifierMetadata mSystemTcMetadata;
 
+    /**
+     * Constructor of {@link SystemTextClassifier}
+     *
+     * @param context the context of the request.
+     * @param settings TextClassifier specific settings.
+     * @param useDefault whether to use the default text classifier to handle this request
+     */
     public SystemTextClassifier(
             Context context,
             TextClassificationConstants settings,
@@ -66,9 +71,11 @@
                 ServiceManager.getServiceOrThrow(Context.TEXT_CLASSIFICATION_SERVICE));
         mSettings = Objects.requireNonNull(settings);
         mFallback = TextClassifier.NO_OP;
-        mPackageName = Objects.requireNonNull(context.getOpPackageName());
-        mUserId = context.getUserId();
-        mUseDefault = useDefault;
+        // NOTE: Always set this before sending a request to the manager service otherwise the
+        // manager service will throw a remote exception.
+        mSystemTcMetadata = new SystemTextClassifierMetadata(
+                Objects.requireNonNull(context.getOpPackageName()), context.getUserId(),
+                useDefault);
     }
 
     /**
@@ -80,9 +87,7 @@
         Objects.requireNonNull(request);
         Utils.checkMainThread();
         try {
-            request.setCallingPackageName(mPackageName);
-            request.setUserId(mUserId);
-            request.setUseDefaultTextClassifier(mUseDefault);
+            request.setSystemTextClassifierMetadata(mSystemTcMetadata);
             final BlockingCallback<TextSelection> callback =
                     new BlockingCallback<>("textselection");
             mManagerService.onSuggestSelection(mSessionId, request, callback);
@@ -105,9 +110,7 @@
         Objects.requireNonNull(request);
         Utils.checkMainThread();
         try {
-            request.setCallingPackageName(mPackageName);
-            request.setUserId(mUserId);
-            request.setUseDefaultTextClassifier(mUseDefault);
+            request.setSystemTextClassifierMetadata(mSystemTcMetadata);
             final BlockingCallback<TextClassification> callback =
                     new BlockingCallback<>("textclassification");
             mManagerService.onClassifyText(mSessionId, request, callback);
@@ -137,9 +140,7 @@
         }
 
         try {
-            request.setCallingPackageName(mPackageName);
-            request.setUserId(mUserId);
-            request.setUseDefaultTextClassifier(mUseDefault);
+            request.setSystemTextClassifierMetadata(mSystemTcMetadata);
             final BlockingCallback<TextLinks> callback =
                     new BlockingCallback<>("textlinks");
             mManagerService.onGenerateLinks(mSessionId, request, callback);
@@ -159,8 +160,7 @@
         Utils.checkMainThread();
 
         try {
-            event.setUserId(mUserId);
-            event.setUseDefaultTextClassifier(mUseDefault);
+            event.setSystemTextClassifierMetadata(mSystemTcMetadata);
             mManagerService.onSelectionEvent(mSessionId, event);
         } catch (RemoteException e) {
             Log.e(LOG_TAG, "Error reporting selection event.", e);
@@ -173,12 +173,11 @@
         Utils.checkMainThread();
 
         try {
-            final TextClassificationContext tcContext = event.getEventContext() == null
-                    ? new TextClassificationContext.Builder(mPackageName, WIDGET_TYPE_UNKNOWN)
-                            .build()
-                    : event.getEventContext();
-            tcContext.setUserId(mUserId);
-            tcContext.setUseDefaultTextClassifier(mUseDefault);
+            final TextClassificationContext tcContext =
+                    event.getEventContext() == null ? new TextClassificationContext.Builder(
+                            mSystemTcMetadata.getCallingPackageName(), WIDGET_TYPE_UNKNOWN).build()
+                            : event.getEventContext();
+            tcContext.setSystemTextClassifierMetadata(mSystemTcMetadata);
             event.setEventContext(tcContext);
             mManagerService.onTextClassifierEvent(mSessionId, event);
         } catch (RemoteException e) {
@@ -192,9 +191,7 @@
         Utils.checkMainThread();
 
         try {
-            request.setCallingPackageName(mPackageName);
-            request.setUserId(mUserId);
-            request.setUseDefaultTextClassifier(mUseDefault);
+            request.setSystemTextClassifierMetadata(mSystemTcMetadata);
             final BlockingCallback<TextLanguage> callback =
                     new BlockingCallback<>("textlanguage");
             mManagerService.onDetectLanguage(mSessionId, request, callback);
@@ -214,9 +211,7 @@
         Utils.checkMainThread();
 
         try {
-            request.setCallingPackageName(mPackageName);
-            request.setUserId(mUserId);
-            request.setUseDefaultTextClassifier(mUseDefault);
+            request.setSystemTextClassifierMetadata(mSystemTcMetadata);
             final BlockingCallback<ConversationActions> callback =
                     new BlockingCallback<>("conversation-actions");
             mManagerService.onSuggestConversationActions(mSessionId, request, callback);
@@ -256,10 +251,8 @@
         printWriter.println("SystemTextClassifier:");
         printWriter.increaseIndent();
         printWriter.printPair("mFallback", mFallback);
-        printWriter.printPair("mPackageName", mPackageName);
         printWriter.printPair("mSessionId", mSessionId);
-        printWriter.printPair("mUserId", mUserId);
-        printWriter.printPair("mUseDefault",  mUseDefault);
+        printWriter.printPair("mSystemTcMetadata",  mSystemTcMetadata);
         printWriter.decreaseIndent();
         printWriter.println();
     }
@@ -275,7 +268,7 @@
             @NonNull TextClassificationSessionId sessionId) {
         mSessionId = Objects.requireNonNull(sessionId);
         try {
-            classificationContext.setUserId(mUserId);
+            classificationContext.setSystemTextClassifierMetadata(mSystemTcMetadata);
             mManagerService.onCreateTextClassificationSession(classificationContext, mSessionId);
         } catch (RemoteException e) {
             Log.e(LOG_TAG, "Error starting a new classification session.", e);
diff --git a/core/java/android/os/incremental/IncrementalSignature.aidl b/core/java/android/view/textclassifier/SystemTextClassifierMetadata.aidl
similarity index 63%
rename from core/java/android/os/incremental/IncrementalSignature.aidl
rename to core/java/android/view/textclassifier/SystemTextClassifierMetadata.aidl
index 729e8e5..4d4e90a 100644
--- a/core/java/android/os/incremental/IncrementalSignature.aidl
+++ b/core/java/android/view/textclassifier/SystemTextClassifierMetadata.aidl
@@ -14,18 +14,6 @@
  * limitations under the License.
  */
 
-package android.os.incremental;
+package android.view.textclassifier;
 
-/** {@hide} */
-parcelable IncrementalSignature {
-    /*
-     * Stable AIDL doesn't support constants, but here's the possible values
-     *   const int HASH_ALGO_NONE = 0;
-     *   const int HASH_ALGO_SHA256 = 1;
-    */
-
-    int hashAlgorithm = 0;
-    byte[] rootHash;
-    byte[] additionalData;
-    byte[] signature;
-}
+parcelable SystemTextClassifierMetadata;
\ No newline at end of file
diff --git a/core/java/android/view/textclassifier/SystemTextClassifierMetadata.java b/core/java/android/view/textclassifier/SystemTextClassifierMetadata.java
new file mode 100644
index 0000000..971e3e2
--- /dev/null
+++ b/core/java/android/view/textclassifier/SystemTextClassifierMetadata.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2020 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 android.annotation.NonNull;
+import android.annotation.UserIdInt;
+import android.os.Parcel;
+import android.os.Parcelable;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.annotations.VisibleForTesting.Visibility;
+
+import java.util.Locale;
+import java.util.Objects;
+
+/**
+ * SystemTextClassifier specific information.
+ * <p>
+ * This contains information requires for the TextClassificationManagerService to process the
+ * requests from the application, e.g. user id, calling package name and etc. Centrialize the data
+ * into this class helps to extend the scalability if we want to add new fields.
+ * @hide
+ */
+@VisibleForTesting(visibility = Visibility.PACKAGE)
+public final class SystemTextClassifierMetadata implements Parcelable {
+
+    /* The name of the package that sent the TC request. */
+    @NonNull
+    private final String mCallingPackageName;
+    /* The id of the user that sent the TC request. */
+    @UserIdInt
+    private final int mUserId;
+    /* Whether to use the default text classifier to handle the request. */
+    private final boolean mUseDefaultTextClassifier;
+
+    public SystemTextClassifierMetadata(@NonNull String packageName, @UserIdInt int userId,
+            boolean useDefaultTextClassifier) {
+        Objects.requireNonNull(packageName);
+        mCallingPackageName = packageName;
+        mUserId = userId;
+        mUseDefaultTextClassifier = useDefaultTextClassifier;
+    }
+
+    /**
+     * Returns the id of the user that sent the TC request.
+     */
+    @UserIdInt
+    public int getUserId() {
+        return mUserId;
+    }
+
+    /**
+     * Returns the name of the package that sent the TC request.
+     * This returns {@code null} if no calling package name is set.
+     */
+    @NonNull
+    public String getCallingPackageName() {
+        return mCallingPackageName;
+    }
+
+    /**
+     * Returns whether to use the default text classifier to handle TC request.
+     */
+    public boolean useDefaultTextClassifier() {
+        return mUseDefaultTextClassifier;
+    }
+
+    @Override
+    public String toString() {
+        return String.format(Locale.US,
+                "SystemTextClassifierMetadata {callingPackageName=%s, userId=%d, "
+                        + "useDefaultTextClassifier=%b}",
+                mCallingPackageName, mUserId, mUseDefaultTextClassifier);
+    }
+
+    private static SystemTextClassifierMetadata readFromParcel(Parcel in) {
+        final String packageName = in.readString();
+        final int userId = in.readInt();
+        final boolean useDefaultTextClassifier = in.readBoolean();
+        return new SystemTextClassifierMetadata(packageName, userId, useDefaultTextClassifier);
+    }
+
+    @Override
+    public int describeContents() {
+        return 0;
+    }
+
+    @Override
+    public void writeToParcel(Parcel dest, int flags) {
+        dest.writeString(mCallingPackageName);
+        dest.writeInt(mUserId);
+        dest.writeBoolean(mUseDefaultTextClassifier);
+    }
+
+    public static final @NonNull Creator<SystemTextClassifierMetadata> CREATOR =
+            new Creator<SystemTextClassifierMetadata>() {
+        @Override
+        public SystemTextClassifierMetadata createFromParcel(Parcel in) {
+            return readFromParcel(in);
+        }
+
+        @Override
+        public SystemTextClassifierMetadata[] newArray(int size) {
+            return new SystemTextClassifierMetadata[size];
+        }
+    };
+}
diff --git a/core/java/android/view/textclassifier/TextClassification.java b/core/java/android/view/textclassifier/TextClassification.java
index 00f762b..8b9d129 100644
--- a/core/java/android/view/textclassifier/TextClassification.java
+++ b/core/java/android/view/textclassifier/TextClassification.java
@@ -21,7 +21,6 @@
 import android.annotation.IntRange;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.annotation.UserIdInt;
 import android.app.PendingIntent;
 import android.app.RemoteAction;
 import android.content.Context;
@@ -36,7 +35,6 @@
 import android.os.LocaleList;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.os.UserHandle;
 import android.text.SpannedString;
 import android.util.ArrayMap;
 import android.view.View.OnClickListener;
@@ -552,10 +550,7 @@
         @Nullable private final LocaleList mDefaultLocales;
         @Nullable private final ZonedDateTime mReferenceTime;
         @NonNull private final Bundle mExtras;
-        @Nullable private String mCallingPackageName;
-        @UserIdInt
-        private int mUserId = UserHandle.USER_NULL;
-        private boolean mUseDefaultTextClassifier;
+        @Nullable private SystemTextClassifierMetadata mSystemTcMetadata;
 
         private Request(
                 CharSequence text,
@@ -616,62 +611,33 @@
         }
 
         /**
-         * Sets the name of the package that is sending this request.
-         * <p>
-         * For SystemTextClassifier's use.
-         * @hide
-         */
-        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
-        public void setCallingPackageName(@Nullable String callingPackageName) {
-            mCallingPackageName = callingPackageName;
-        }
-
-        /**
          * Returns the name of the package that sent this request.
          * This returns {@code null} if no calling package name is set.
          */
         @Nullable
         public String getCallingPackageName() {
-            return mCallingPackageName;
+            return mSystemTcMetadata != null ? mSystemTcMetadata.getCallingPackageName() : null;
         }
 
         /**
-         * Sets the id of the user that sent this request.
-         * <p>
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        void setUserId(@UserIdInt int userId) {
-            mUserId = userId;
-        }
-
-        /**
-         * Returns the id of the user that sent this request.
-         * @hide
-         */
-        @UserIdInt
-        public int getUserId() {
-            return mUserId;
-        }
-
-        /**
-         * Sets whether to use the default text classifier to handle this request.
-         * This will be ignored if it is not the system text classifier to handle this request.
+         * Sets the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        void setUseDefaultTextClassifier(boolean useDefaultTextClassifier) {
-            mUseDefaultTextClassifier = useDefaultTextClassifier;
+        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+        public void setSystemTextClassifierMetadata(
+                @Nullable SystemTextClassifierMetadata systemTcMetadata) {
+            mSystemTcMetadata = systemTcMetadata;
         }
 
         /**
-         * Returns whether to use the default text classifier to handle this request. This
-         * will be ignored if it is not the system text classifier to handle this request.
+         * Returns the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        public boolean getUseDefaultTextClassifier() {
-            return mUseDefaultTextClassifier;
+        @Nullable
+        public SystemTextClassifierMetadata getSystemTextClassifierMetadata() {
+            return mSystemTcMetadata;
         }
 
         /**
@@ -773,10 +739,8 @@
             dest.writeInt(mEndIndex);
             dest.writeParcelable(mDefaultLocales, flags);
             dest.writeString(mReferenceTime == null ? null : mReferenceTime.toString());
-            dest.writeString(mCallingPackageName);
-            dest.writeInt(mUserId);
             dest.writeBundle(mExtras);
-            dest.writeBoolean(mUseDefaultTextClassifier);
+            dest.writeParcelable(mSystemTcMetadata, flags);
         }
 
         private static Request readFromParcel(Parcel in) {
@@ -787,16 +751,12 @@
             final String referenceTimeString = in.readString();
             final ZonedDateTime referenceTime = referenceTimeString == null
                     ? null : ZonedDateTime.parse(referenceTimeString);
-            final String callingPackageName = in.readString();
-            final int userId = in.readInt();
             final Bundle extras = in.readBundle();
-            final boolean useDefaultTextClassifier = in.readBoolean();
+            final SystemTextClassifierMetadata systemTcMetadata = in.readParcelable(null);
 
             final Request request = new Request(text, startIndex, endIndex,
                     defaultLocales, referenceTime, extras);
-            request.setCallingPackageName(callingPackageName);
-            request.setUserId(userId);
-            request.setUseDefaultTextClassifier(useDefaultTextClassifier);
+            request.setSystemTextClassifierMetadata(systemTcMetadata);
             return request;
         }
 
diff --git a/core/java/android/view/textclassifier/TextClassificationContext.java b/core/java/android/view/textclassifier/TextClassificationContext.java
index d58d175..f2323c6 100644
--- a/core/java/android/view/textclassifier/TextClassificationContext.java
+++ b/core/java/android/view/textclassifier/TextClassificationContext.java
@@ -18,10 +18,8 @@
 
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.annotation.UserIdInt;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.os.UserHandle;
 import android.view.textclassifier.TextClassifier.WidgetType;
 
 import java.util.Locale;
@@ -33,12 +31,11 @@
  */
 public final class TextClassificationContext implements Parcelable {
 
-    private final String mPackageName;
+    // NOTE: Modify packageName only in the constructor or in setSystemTextClassifierMetadata()
+    private String mPackageName;
     private final String mWidgetType;
     @Nullable private final String mWidgetVersion;
-    @UserIdInt
-    private int mUserId = UserHandle.USER_NULL;
-    private boolean mUseDefaultTextClassifier;
+    private SystemTextClassifierMetadata mSystemTcMetadata;
 
     private TextClassificationContext(
             String packageName,
@@ -58,42 +55,26 @@
     }
 
     /**
-     * Sets the id of this context's user.
-     * <p>
-     * Package-private for SystemTextClassifier's use.
+     * Sets the information about the {@link SystemTextClassifier} that sent this request.
+     *
+     * <p><b>NOTE: </b>This will override the value returned in {@link getPackageName()}.
      * @hide
      */
-    void setUserId(@UserIdInt int userId) {
-        mUserId = userId;
+    void setSystemTextClassifierMetadata(@Nullable SystemTextClassifierMetadata systemTcMetadata) {
+        mSystemTcMetadata = systemTcMetadata;
+        if (mSystemTcMetadata != null) {
+            mPackageName = mSystemTcMetadata.getCallingPackageName();
+        }
     }
 
     /**
-     * Returns the id of this context's user.
-     * @hide
-     */
-    @UserIdInt
-    public int getUserId() {
-        return mUserId;
-    }
-
-    /**
-     * Sets whether to use the default text classifier to handle this request.
-     * This will be ignored if it is not the system text classifier to handle this request.
+     * Returns the information about the {@link SystemTextClassifier} that sent this request.
      *
      * @hide
      */
-    void setUseDefaultTextClassifier(boolean useDefaultTextClassifier) {
-        mUseDefaultTextClassifier = useDefaultTextClassifier;
-    }
-
-    /**
-     * Returns whether to use the default text classifier to handle this request. This
-     * will be ignored if it is not the system text classifier to handle this request.
-     *
-     * @hide
-     */
-    public boolean getUseDefaultTextClassifier() {
-        return mUseDefaultTextClassifier;
+    @Nullable
+    public SystemTextClassifierMetadata getSystemTextClassifierMetadata() {
+        return mSystemTcMetadata;
     }
 
     /**
@@ -118,8 +99,8 @@
     @Override
     public String toString() {
         return String.format(Locale.US, "TextClassificationContext{"
-                + "packageName=%s, widgetType=%s, widgetVersion=%s, userId=%d}",
-                mPackageName, mWidgetType, mWidgetVersion, mUserId);
+                + "packageName=%s, widgetType=%s, widgetVersion=%s, systemTcMetadata=%s}",
+                mPackageName, mWidgetType, mWidgetVersion, mSystemTcMetadata);
     }
 
     /**
@@ -176,16 +157,14 @@
         parcel.writeString(mPackageName);
         parcel.writeString(mWidgetType);
         parcel.writeString(mWidgetVersion);
-        parcel.writeInt(mUserId);
-        parcel.writeBoolean(mUseDefaultTextClassifier);
+        parcel.writeParcelable(mSystemTcMetadata, flags);
     }
 
     private TextClassificationContext(Parcel in) {
         mPackageName = in.readString();
         mWidgetType = in.readString();
         mWidgetVersion = in.readString();
-        mUserId = in.readInt();
-        mUseDefaultTextClassifier = in.readBoolean();
+        mSystemTcMetadata = in.readParcelable(null);
     }
 
     public static final @android.annotation.NonNull Parcelable.Creator<TextClassificationContext> CREATOR =
diff --git a/core/java/android/view/textclassifier/TextLanguage.java b/core/java/android/view/textclassifier/TextLanguage.java
index 58024dc..1e8253d 100644
--- a/core/java/android/view/textclassifier/TextLanguage.java
+++ b/core/java/android/view/textclassifier/TextLanguage.java
@@ -20,12 +20,10 @@
 import android.annotation.IntRange;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.annotation.UserIdInt;
 import android.icu.util.ULocale;
 import android.os.Bundle;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.os.UserHandle;
 import android.util.ArrayMap;
 
 import com.android.internal.annotations.VisibleForTesting;
@@ -227,10 +225,7 @@
 
         private final CharSequence mText;
         private final Bundle mExtra;
-        @Nullable private String mCallingPackageName;
-        @UserIdInt
-        private int mUserId = UserHandle.USER_NULL;
-        private boolean mUseDefaultTextClassifier;
+        @Nullable private SystemTextClassifierMetadata mSystemTcMetadata;
 
         private Request(CharSequence text, Bundle bundle) {
             mText = text;
@@ -246,61 +241,33 @@
         }
 
         /**
-         * Sets the name of the package that is sending this request.
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
-        public void setCallingPackageName(@Nullable String callingPackageName) {
-            mCallingPackageName = callingPackageName;
-        }
-
-        /**
          * Returns the name of the package that sent this request.
          * This returns null if no calling package name is set.
          */
         @Nullable
         public String getCallingPackageName() {
-            return mCallingPackageName;
+            return mSystemTcMetadata != null ? mSystemTcMetadata.getCallingPackageName() : null;
         }
 
         /**
-         * Sets the id of the user that sent this request.
-         * <p>
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        void setUserId(@UserIdInt int userId) {
-            mUserId = userId;
-        }
-
-        /**
-         * Returns the id of the user that sent this request.
-         * @hide
-         */
-        @UserIdInt
-        public int getUserId() {
-            return mUserId;
-        }
-
-        /**
-         * Sets whether to use the default text classifier to handle this request.
-         * This will be ignored if it is not the system text classifier to handle this request.
+         * Sets the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        void setUseDefaultTextClassifier(boolean useDefaultTextClassifier) {
-            mUseDefaultTextClassifier = useDefaultTextClassifier;
+        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+        public void setSystemTextClassifierMetadata(
+                @Nullable SystemTextClassifierMetadata systemTcMetadata) {
+            mSystemTcMetadata = systemTcMetadata;
         }
 
         /**
-         * Returns whether to use the default text classifier to handle this request. This
-         * will be ignored if it is not the system text classifier to handle this request.
+         * Returns the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        public boolean getUseDefaultTextClassifier() {
-            return mUseDefaultTextClassifier;
+        @Nullable
+        public SystemTextClassifierMetadata getSystemTextClassifierMetadata() {
+            return mSystemTcMetadata;
         }
 
         /**
@@ -321,23 +288,17 @@
         @Override
         public void writeToParcel(Parcel dest, int flags) {
             dest.writeCharSequence(mText);
-            dest.writeString(mCallingPackageName);
-            dest.writeInt(mUserId);
             dest.writeBundle(mExtra);
-            dest.writeBoolean(mUseDefaultTextClassifier);
+            dest.writeParcelable(mSystemTcMetadata, flags);
         }
 
         private static Request readFromParcel(Parcel in) {
             final CharSequence text = in.readCharSequence();
-            final String callingPackageName = in.readString();
-            final int userId = in.readInt();
             final Bundle extra = in.readBundle();
-            final boolean useDefaultTextClassifier = in.readBoolean();
+            final SystemTextClassifierMetadata systemTcMetadata = in.readParcelable(null);
 
             final Request request = new Request(text, extra);
-            request.setCallingPackageName(callingPackageName);
-            request.setUserId(userId);
-            request.setUseDefaultTextClassifier(useDefaultTextClassifier);
+            request.setSystemTextClassifierMetadata(systemTcMetadata);
             return request;
         }
 
diff --git a/core/java/android/view/textclassifier/TextLinks.java b/core/java/android/view/textclassifier/TextLinks.java
index 7430cb3..dea3a90 100644
--- a/core/java/android/view/textclassifier/TextLinks.java
+++ b/core/java/android/view/textclassifier/TextLinks.java
@@ -20,13 +20,11 @@
 import android.annotation.IntDef;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.annotation.UserIdInt;
 import android.content.Context;
 import android.os.Bundle;
 import android.os.LocaleList;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.os.UserHandle;
 import android.text.Spannable;
 import android.text.method.MovementMethod;
 import android.text.style.ClickableSpan;
@@ -340,12 +338,9 @@
         @Nullable private final LocaleList mDefaultLocales;
         @Nullable private final EntityConfig mEntityConfig;
         private final boolean mLegacyFallback;
-        @Nullable private String mCallingPackageName;
         private final Bundle mExtras;
         @Nullable private final ZonedDateTime mReferenceTime;
-        @UserIdInt
-        private int mUserId = UserHandle.USER_NULL;
-        private boolean mUseDefaultTextClassifier;
+        @Nullable private SystemTextClassifierMetadata mSystemTcMetadata;
 
         private Request(
                 CharSequence text,
@@ -409,62 +404,33 @@
         }
 
         /**
-         * Sets the name of the package that is sending this request.
-         * <p>
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
-        public void setCallingPackageName(@Nullable String callingPackageName) {
-            mCallingPackageName = callingPackageName;
-        }
-
-        /**
          * Returns the name of the package that sent this request.
          * This returns {@code null} if no calling package name is set.
          */
         @Nullable
         public String getCallingPackageName() {
-            return mCallingPackageName;
+            return mSystemTcMetadata != null ? mSystemTcMetadata.getCallingPackageName() : null;
         }
 
         /**
-         * Sets the id of the user that sent this request.
-         * <p>
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        void setUserId(@UserIdInt int userId) {
-            mUserId = userId;
-        }
-
-        /**
-         * Returns the id of the user that sent this request.
-         * @hide
-         */
-        @UserIdInt
-        public int getUserId() {
-            return mUserId;
-        }
-
-        /**
-         * Sets whether to use the default text classifier to handle this request.
-         * This will be ignored if it is not the system text classifier to handle this request.
+         * Sets the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        void setUseDefaultTextClassifier(boolean useDefaultTextClassifier) {
-            mUseDefaultTextClassifier = useDefaultTextClassifier;
+        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+        public void setSystemTextClassifierMetadata(
+                @Nullable SystemTextClassifierMetadata systemTcMetadata) {
+            mSystemTcMetadata = systemTcMetadata;
         }
 
         /**
-         * Returns whether to use the default text classifier to handle this request. This
-         * will be ignored if it is not the system text classifier to handle this request.
+         * Returns the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        public boolean getUseDefaultTextClassifier() {
-            return mUseDefaultTextClassifier;
+        @Nullable
+        public SystemTextClassifierMetadata getSystemTextClassifierMetadata() {
+            return mSystemTcMetadata;
         }
 
         /**
@@ -585,30 +551,24 @@
             dest.writeString(mText.toString());
             dest.writeParcelable(mDefaultLocales, flags);
             dest.writeParcelable(mEntityConfig, flags);
-            dest.writeString(mCallingPackageName);
-            dest.writeInt(mUserId);
             dest.writeBundle(mExtras);
             dest.writeString(mReferenceTime == null ? null : mReferenceTime.toString());
-            dest.writeBoolean(mUseDefaultTextClassifier);
+            dest.writeParcelable(mSystemTcMetadata, flags);
         }
 
         private static Request readFromParcel(Parcel in) {
             final String text = in.readString();
             final LocaleList defaultLocales = in.readParcelable(null);
             final EntityConfig entityConfig = in.readParcelable(null);
-            final String callingPackageName = in.readString();
-            final int userId = in.readInt();
             final Bundle extras = in.readBundle();
             final String referenceTimeString = in.readString();
             final ZonedDateTime referenceTime = referenceTimeString == null
                     ? null : ZonedDateTime.parse(referenceTimeString);
-            final boolean useDefaultTextClassifier = in.readBoolean();
+            final SystemTextClassifierMetadata systemTcMetadata = in.readParcelable(null);
 
             final Request request = new Request(text, defaultLocales, entityConfig,
                     /* legacyFallback= */ true, referenceTime, extras);
-            request.setCallingPackageName(callingPackageName);
-            request.setUserId(userId);
-            request.setUseDefaultTextClassifier(useDefaultTextClassifier);
+            request.setSystemTextClassifierMetadata(systemTcMetadata);
             return request;
         }
 
diff --git a/core/java/android/view/textclassifier/TextSelection.java b/core/java/android/view/textclassifier/TextSelection.java
index 575a072..d8a632d 100644
--- a/core/java/android/view/textclassifier/TextSelection.java
+++ b/core/java/android/view/textclassifier/TextSelection.java
@@ -20,12 +20,10 @@
 import android.annotation.IntRange;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.annotation.UserIdInt;
 import android.os.Bundle;
 import android.os.LocaleList;
 import android.os.Parcel;
 import android.os.Parcelable;
-import android.os.UserHandle;
 import android.text.SpannedString;
 import android.util.ArrayMap;
 import android.view.textclassifier.TextClassifier.EntityType;
@@ -213,10 +211,7 @@
         @Nullable private final LocaleList mDefaultLocales;
         private final boolean mDarkLaunchAllowed;
         private final Bundle mExtras;
-        @Nullable private String mCallingPackageName;
-        @UserIdInt
-        private int mUserId = UserHandle.USER_NULL;
-        private boolean mUseDefaultTextClassifier;
+        @Nullable private SystemTextClassifierMetadata mSystemTcMetadata;
 
         private Request(
                 CharSequence text,
@@ -278,62 +273,33 @@
         }
 
         /**
-         * Sets the name of the package that is sending this request.
-         * <p>
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
-        public void setCallingPackageName(@Nullable String callingPackageName) {
-            mCallingPackageName = callingPackageName;
-        }
-
-        /**
          * Returns the name of the package that sent this request.
          * This returns {@code null} if no calling package name is set.
          */
         @Nullable
         public String getCallingPackageName() {
-            return mCallingPackageName;
+            return mSystemTcMetadata != null ? mSystemTcMetadata.getCallingPackageName() : null;
         }
 
         /**
-         * Sets the id of the user that sent this request.
-         * <p>
-         * Package-private for SystemTextClassifier's use.
-         * @hide
-         */
-        void setUserId(@UserIdInt int userId) {
-            mUserId = userId;
-        }
-
-        /**
-         * Returns the id of the user that sent this request.
-         * @hide
-         */
-        @UserIdInt
-        public int getUserId() {
-            return mUserId;
-        }
-
-        /**
-         * Sets whether to use the default text classifier to handle this request.
-         * This will be ignored if it is not the system text classifier to handle this request.
+         * Sets the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        void setUseDefaultTextClassifier(boolean useDefaultTextClassifier) {
-            mUseDefaultTextClassifier = useDefaultTextClassifier;
+        @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE)
+        public void setSystemTextClassifierMetadata(
+                @Nullable SystemTextClassifierMetadata systemTcMetadata) {
+            mSystemTcMetadata = systemTcMetadata;
         }
 
         /**
-         * Returns whether to use the default text classifier to handle this request. This
-         * will be ignored if it is not the system text classifier to handle this request.
+         * Returns the information about the {@link SystemTextClassifier} that sent this request.
          *
          * @hide
          */
-        public boolean getUseDefaultTextClassifier() {
-            return mUseDefaultTextClassifier;
+        @Nullable
+        public SystemTextClassifierMetadata getSystemTextClassifierMetadata() {
+            return mSystemTcMetadata;
         }
 
         /**
@@ -438,10 +404,8 @@
             dest.writeInt(mStartIndex);
             dest.writeInt(mEndIndex);
             dest.writeParcelable(mDefaultLocales, flags);
-            dest.writeString(mCallingPackageName);
-            dest.writeInt(mUserId);
             dest.writeBundle(mExtras);
-            dest.writeBoolean(mUseDefaultTextClassifier);
+            dest.writeParcelable(mSystemTcMetadata, flags);
         }
 
         private static Request readFromParcel(Parcel in) {
@@ -449,16 +413,12 @@
             final int startIndex = in.readInt();
             final int endIndex = in.readInt();
             final LocaleList defaultLocales = in.readParcelable(null);
-            final String callingPackageName = in.readString();
-            final int userId = in.readInt();
             final Bundle extras = in.readBundle();
-            final boolean systemTextClassifierType = in.readBoolean();
+            final SystemTextClassifierMetadata systemTcMetadata = in.readParcelable(null);
 
             final Request request = new Request(text, startIndex, endIndex, defaultLocales,
                     /* darkLaunchAllowed= */ false, extras);
-            request.setCallingPackageName(callingPackageName);
-            request.setUserId(userId);
-            request.setUseDefaultTextClassifier(systemTextClassifierType);
+            request.setSystemTextClassifierMetadata(systemTcMetadata);
             return request;
         }
 
diff --git a/core/java/com/android/internal/app/AbstractResolverComparator.java b/core/java/com/android/internal/app/AbstractResolverComparator.java
index eb74612..e0bbc04 100644
--- a/core/java/com/android/internal/app/AbstractResolverComparator.java
+++ b/core/java/com/android/internal/app/AbstractResolverComparator.java
@@ -221,6 +221,12 @@
      */
     abstract float getScore(ComponentName name);
 
+    /**
+     * Returns the list of top K component names which have highest
+     * {@link #getScore(ComponentName)}
+     */
+    abstract List<ComponentName> getTopComponentNames(int topK);
+
     /** Handles result message sent to mHandler. */
     abstract void handleResultMessage(Message message);
 
diff --git a/core/java/com/android/internal/app/AppPredictionServiceResolverComparator.java b/core/java/com/android/internal/app/AppPredictionServiceResolverComparator.java
index 04ad7e9..ba8c7b3 100644
--- a/core/java/com/android/internal/app/AppPredictionServiceResolverComparator.java
+++ b/core/java/com/android/internal/app/AppPredictionServiceResolverComparator.java
@@ -36,7 +36,9 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.concurrent.Executors;
+import java.util.stream.Collectors;
 
 /**
  * Uses an {@link AppPredictor} to sort Resolver targets. If the AppPredictionService appears to be
@@ -160,6 +162,15 @@
     }
 
     @Override
+    List<ComponentName> getTopComponentNames(int topK) {
+        return mTargetRanks.entrySet().stream()
+                .sorted(Entry.comparingByValue())
+                .limit(topK)
+                .map(Entry::getKey)
+                .collect(Collectors.toList());
+    }
+
+    @Override
     void updateModel(ComponentName componentName) {
         if (mResolverRankerService != null) {
             mResolverRankerService.updateModel(componentName);
diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java
index 5620bff..188041e 100644
--- a/core/java/com/android/internal/app/ChooserActivity.java
+++ b/core/java/com/android/internal/app/ChooserActivity.java
@@ -223,6 +223,11 @@
             SystemUiDeviceConfigFlags.HASH_SALT_MAX_DAYS,
             DEFAULT_SALT_EXPIRATION_DAYS);
 
+    private boolean mAppendDirectShareEnabled = DeviceConfig.getBoolean(
+            DeviceConfig.NAMESPACE_SYSTEMUI,
+            SystemUiDeviceConfigFlags.APPEND_DIRECT_SHARE_ENABLED,
+            false);
+
     private Bundle mReplacementExtras;
     private IntentSender mChosenComponentSender;
     private IntentSender mRefinementIntentSender;
@@ -409,6 +414,11 @@
         private static final int WATCHDOG_TIMEOUT_MAX_MILLIS = 10000;
         private static final int WATCHDOG_TIMEOUT_MIN_MILLIS = 3000;
 
+        private static final int DEFAULT_DIRECT_SHARE_TIMEOUT_MILLIS = 1500;
+        private int mDirectShareTimeout = DeviceConfig.getInt(DeviceConfig.NAMESPACE_SYSTEMUI,
+                SystemUiDeviceConfigFlags.SHARE_SHEET_DIRECT_SHARE_TIMEOUT,
+                DEFAULT_DIRECT_SHARE_TIMEOUT_MILLIS);
+
         private boolean mMinTimeoutPassed = false;
 
         private void removeAllMessages() {
@@ -427,15 +437,14 @@
 
             if (DEBUG) {
                 Log.d(TAG, "queryTargets setting watchdog timer for "
-                        + WATCHDOG_TIMEOUT_MIN_MILLIS + "-"
+                        + mDirectShareTimeout + "-"
                         + WATCHDOG_TIMEOUT_MAX_MILLIS + "ms");
             }
 
             sendEmptyMessageDelayed(CHOOSER_TARGET_SERVICE_WATCHDOG_MIN_TIMEOUT,
                     WATCHDOG_TIMEOUT_MIN_MILLIS);
             sendEmptyMessageDelayed(CHOOSER_TARGET_SERVICE_WATCHDOG_MAX_TIMEOUT,
-                    WATCHDOG_TIMEOUT_MAX_MILLIS);
-
+                    mAppendDirectShareEnabled ? mDirectShareTimeout : WATCHDOG_TIMEOUT_MAX_MILLIS);
         }
 
         private void maybeStopServiceRequestTimer() {
@@ -463,6 +472,7 @@
                     final ServiceResultInfo sri = (ServiceResultInfo) msg.obj;
                     if (!mServiceConnections.contains(sri.connection)) {
                         Log.w(TAG, "ChooserTargetServiceConnection " + sri.connection
+                                + sri.originalTarget.getResolveInfo().activityInfo.packageName
                                 + " returned after being removed from active connections."
                                 + " Have you considered returning results faster?");
                         break;
@@ -474,7 +484,7 @@
                         if (adapterForUserHandle != null) {
                             adapterForUserHandle.addServiceResults(sri.originalTarget,
                                     sri.resultTargets, TARGET_TYPE_CHOOSER_TARGET,
-                                    /* directShareShortcutInfoCache */ null);
+                                    /* directShareShortcutInfoCache */ null, mServiceConnections);
                         }
                     }
                     unbindService(sri.connection);
@@ -489,6 +499,7 @@
                     break;
 
                 case CHOOSER_TARGET_SERVICE_WATCHDOG_MAX_TIMEOUT:
+                    mMinTimeoutPassed = true;
                     unbindRemainingServices();
                     maybeStopServiceRequestTimer();
                     break;
@@ -513,7 +524,7 @@
                         if (adapterForUserHandle != null) {
                             adapterForUserHandle.addServiceResults(
                                     resultInfo.originalTarget, resultInfo.resultTargets, msg.arg1,
-                                    mDirectShareShortcutInfoCache);
+                                    mDirectShareShortcutInfoCache, mServiceConnections);
                         }
                     }
                     break;
@@ -1481,7 +1492,7 @@
                     /* origTarget */ null,
                     Lists.newArrayList(mCallerChooserTargets),
                     TARGET_TYPE_DEFAULT,
-                    /* directShareShortcutInfoCache */ null);
+                    /* directShareShortcutInfoCache */ null, mServiceConnections);
         }
     }
 
@@ -3584,6 +3595,10 @@
                     ? mOriginalTarget.getResolveInfo().activityInfo.toString()
                     : "<connection destroyed>") + "}";
         }
+
+        public ComponentName getComponentName() {
+            return mOriginalTarget.getResolveInfo().activityInfo.getComponentName();
+        }
     }
 
     static class ServiceResultInfo {
diff --git a/core/java/com/android/internal/app/ChooserListAdapter.java b/core/java/com/android/internal/app/ChooserListAdapter.java
index 74ae291..0ea855a 100644
--- a/core/java/com/android/internal/app/ChooserListAdapter.java
+++ b/core/java/com/android/internal/app/ChooserListAdapter.java
@@ -32,8 +32,10 @@
 import android.os.AsyncTask;
 import android.os.UserHandle;
 import android.os.UserManager;
+import android.provider.DeviceConfig;
 import android.service.chooser.ChooserTarget;
 import android.util.Log;
+import android.util.Pair;
 import android.view.View;
 import android.view.ViewGroup;
 
@@ -44,17 +46,26 @@
 import com.android.internal.app.chooser.MultiDisplayResolveInfo;
 import com.android.internal.app.chooser.SelectableTargetInfo;
 import com.android.internal.app.chooser.TargetInfo;
+import com.android.internal.config.sysui.SystemUiDeviceConfigFlags;
 
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
 
 public class ChooserListAdapter extends ResolverListAdapter {
     private static final String TAG = "ChooserListAdapter";
     private static final boolean DEBUG = false;
 
+    private boolean mAppendDirectShareEnabled = DeviceConfig.getBoolean(
+            DeviceConfig.NAMESPACE_SYSTEMUI,
+            SystemUiDeviceConfigFlags.APPEND_DIRECT_SHARE_ENABLED,
+            false);
+
     private boolean mEnableStackedApps = true;
 
     public static final int NO_POSITION = -1;
@@ -84,6 +95,11 @@
     // Reserve spots for incoming direct share targets by adding placeholders
     private ChooserTargetInfo
             mPlaceHolderTargetInfo = new ChooserActivity.PlaceHolderTargetInfo();
+    private int mValidServiceTargetsNum = 0;
+    private final Map<ComponentName, Pair<List<ChooserTargetInfo>, Integer>>
+            mParkingDirectShareTargets = new HashMap<>();
+    private Set<ComponentName> mPendingChooserTargetService = new HashSet<>();
+    private Set<ComponentName> mShortcutComponents = new HashSet<>();
     private final List<ChooserTargetInfo> mServiceTargets = new ArrayList<>();
     private final List<TargetInfo> mCallerTargets = new ArrayList<>();
 
@@ -189,6 +205,9 @@
 
     void refreshListView() {
         if (mListViewDataChanged) {
+            if (mAppendDirectShareEnabled) {
+                appendServiceTargetsWithQuota();
+            }
             super.notifyDataSetChanged();
         }
         mListViewDataChanged = false;
@@ -198,6 +217,10 @@
     private void createPlaceHolders() {
         mNumShortcutResults = 0;
         mServiceTargets.clear();
+        mValidServiceTargetsNum = 0;
+        mParkingDirectShareTargets.clear();
+        mPendingChooserTargetService.clear();
+        mShortcutComponents.clear();
         for (int i = 0; i < MAX_SERVICE_TARGETS; i++) {
             mServiceTargets.add(mPlaceHolderTargetInfo);
         }
@@ -393,12 +416,19 @@
      */
     public void addServiceResults(DisplayResolveInfo origTarget, List<ChooserTarget> targets,
             @ChooserActivity.ShareTargetType int targetType,
-            Map<ChooserTarget, ShortcutInfo> directShareToShortcutInfos) {
+            Map<ChooserTarget, ShortcutInfo> directShareToShortcutInfos,
+            List<ChooserActivity.ChooserTargetServiceConnection>
+                    pendingChooserTargetServiceConnections) {
         if (DEBUG) {
-            Log.d(TAG, "addServiceResults " + origTarget + ", " + targets.size()
+            Log.d(TAG, "addServiceResults " + origTarget.getResolvedComponentName() + ", "
+                    + targets.size()
                     + " targets");
         }
-
+        if (mAppendDirectShareEnabled) {
+            parkTargetIntoMemory(origTarget, targets, targetType, directShareToShortcutInfos,
+                    pendingChooserTargetServiceConnections);
+            return;
+        }
         if (targets.size() == 0) {
             return;
         }
@@ -449,6 +479,126 @@
         }
     }
 
+    /**
+     * Park {@code targets} into memory for the moment to surface them later when view is refreshed.
+     * Components pending on ChooserTargetService query are also recorded.
+     */
+    private void parkTargetIntoMemory(DisplayResolveInfo origTarget, List<ChooserTarget> targets,
+            @ChooserActivity.ShareTargetType int targetType,
+            Map<ChooserTarget, ShortcutInfo> directShareToShortcutInfos,
+            List<ChooserActivity.ChooserTargetServiceConnection>
+                    pendingChooserTargetServiceConnections) {
+        ComponentName origComponentName = origTarget.getResolvedComponentName();
+        mPendingChooserTargetService = pendingChooserTargetServiceConnections.stream()
+                .map(ChooserActivity.ChooserTargetServiceConnection::getComponentName)
+                .filter(componentName -> !componentName.equals(origComponentName))
+                .collect(Collectors.toSet());
+        // Park targets in memory
+        if (!targets.isEmpty() && !mParkingDirectShareTargets.containsKey(origComponentName)) {
+            final boolean isShortcutResult =
+                    (targetType == TARGET_TYPE_SHORTCUTS_FROM_SHORTCUT_MANAGER
+                            || targetType == TARGET_TYPE_SHORTCUTS_FROM_PREDICTION_SERVICE);
+            Context contextAsUser = mContext.createContextAsUser(getUserHandle(),
+                    0 /* flags */);
+            List<ChooserTargetInfo> parkingTargetInfos = targets.stream()
+                    .map(target ->
+                            new SelectableTargetInfo(
+                                    contextAsUser, origTarget, target, target.getScore(),
+                                    mSelectableTargetInfoComunicator,
+                                    (isShortcutResult ? directShareToShortcutInfos.get(target)
+                                            : null))
+                    )
+                    .collect(Collectors.toList());
+            mParkingDirectShareTargets.put(origComponentName,
+                    new Pair<>(parkingTargetInfos, 0));
+            if (isShortcutResult) {
+                mShortcutComponents.add(origComponentName);
+            }
+        }
+        notifyDataSetChanged();
+    }
+
+    /**
+     * Append targets of top ranked share app into direct share row with quota limit. Remove
+     * appended ones from memory.
+     */
+    private void appendServiceTargetsWithQuota() {
+        int maxRankedTargets = mChooserListCommunicator.getMaxRankedTargets();
+        List<ComponentName> topComponentNames = getTopComponentNames(maxRankedTargets);
+        int appRank = 0;
+        for (ComponentName component : topComponentNames) {
+            if (!mPendingChooserTargetService.contains(component)
+                    && !mParkingDirectShareTargets.containsKey(component)) {
+                continue;
+            }
+            appRank++;
+            Pair<List<ChooserTargetInfo>, Integer> parkingTargetsItem =
+                    mParkingDirectShareTargets.get(component);
+            if (parkingTargetsItem != null && parkingTargetsItem.second == 0) {
+                List<ChooserTargetInfo> parkingTargets = parkingTargetsItem.first;
+                int initTargetsQuota = appRank <= maxRankedTargets / 2 ? 2 : 1;
+                int insertedNum = 0;
+                while (insertedNum < initTargetsQuota && !parkingTargets.isEmpty()) {
+                    if (!checkDuplicateTarget(parkingTargets.get(0))) {
+                        mServiceTargets.add(mValidServiceTargetsNum, parkingTargets.get(0));
+                        mValidServiceTargetsNum++;
+                        insertedNum++;
+                    }
+                    parkingTargets.remove(0);
+                }
+                mParkingDirectShareTargets.put(component, new Pair<>(parkingTargets, insertedNum));
+                if (mShortcutComponents.contains(component)) {
+                    mNumShortcutResults += insertedNum;
+                }
+            }
+        }
+    }
+
+    /**
+     * Append all remaining targets (parking in memory) into direct share row as per their ranking.
+     */
+    private void fillAllServiceTargets() {
+        int maxRankedTargets = mChooserListCommunicator.getMaxRankedTargets();
+        List<ComponentName> topComponentNames = getTopComponentNames(maxRankedTargets);
+        // Append all remaining targets of top recommended components into direct share row.
+        for (ComponentName component : topComponentNames) {
+            if (!mParkingDirectShareTargets.containsKey(component)) {
+                continue;
+            }
+            mParkingDirectShareTargets.get(component).first.stream()
+                    .filter(target -> !checkDuplicateTarget(target))
+                    .forEach(target -> {
+                        if (mShortcutComponents.contains(component)) {
+                            mNumShortcutResults++;
+                        }
+                        mServiceTargets.add(target);
+                    });
+            mParkingDirectShareTargets.remove(component);
+        }
+        // Append all remaining shortcuts targets into direct share row.
+        List<ChooserTargetInfo> remainingTargets = new ArrayList<>();
+        mParkingDirectShareTargets.entrySet().stream()
+                .filter(entry -> mShortcutComponents.contains(entry.getKey()))
+                .map(entry -> entry.getValue())
+                .map(pair -> pair.first)
+                .forEach(remainingTargets::addAll);
+        remainingTargets.sort(
+                (t1, t2) -> -Float.compare(t1.getModifiedScore(), t2.getModifiedScore()));
+        mServiceTargets.addAll(remainingTargets);
+        mNumShortcutResults += remainingTargets.size();
+        mParkingDirectShareTargets.clear();
+    }
+
+    private boolean checkDuplicateTarget(ChooserTargetInfo chooserTargetInfo) {
+        // Check for duplicates and abort if found
+        for (ChooserTargetInfo otherTargetInfo : mServiceTargets) {
+            if (chooserTargetInfo.isSimilar(otherTargetInfo)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
     int getNumShortcutResults() {
         return mNumShortcutResults;
     }
@@ -487,7 +637,9 @@
      */
     public void completeServiceTargetLoading() {
         mServiceTargets.removeIf(o -> o instanceof ChooserActivity.PlaceHolderTargetInfo);
-
+        if (mAppendDirectShareEnabled) {
+            fillAllServiceTargets();
+        }
         if (mServiceTargets.isEmpty()) {
             mServiceTargets.add(new ChooserActivity.EmptyTargetInfo());
         }
diff --git a/core/java/com/android/internal/app/IAppOpsService.aidl b/core/java/com/android/internal/app/IAppOpsService.aidl
index 907ea55..9218823 100644
--- a/core/java/com/android/internal/app/IAppOpsService.aidl
+++ b/core/java/com/android/internal/app/IAppOpsService.aidl
@@ -34,14 +34,14 @@
     // be kept in sync with frameworks/native/libs/binder/include/binder/IAppOpsService.h
     // and not be reordered
     int checkOperation(int code, int uid, String packageName);
-    int noteOperation(int code, int uid, String packageName, @nullable String featureId,
+    int noteOperation(int code, int uid, String packageName, @nullable String attributionTag,
             boolean shouldCollectAsyncNotedOp, String message);
     int startOperation(IBinder clientId, int code, int uid, String packageName,
-            @nullable String featureId, boolean startIfModeDefault,
+            @nullable String attributionTag, boolean startIfModeDefault,
             boolean shouldCollectAsyncNotedOp, String message);
     @UnsupportedAppUsage
     void finishOperation(IBinder clientId, int code, int uid, String packageName,
-            @nullable String featureId);
+            @nullable String attributionTag);
     void startWatchingMode(int op, String packageName, IAppOpsCallback callback);
     void stopWatchingMode(IAppOpsCallback callback);
     int permissionToOpCode(String permission);
@@ -52,8 +52,8 @@
     // Any new method exposed to native must be added after the last one, do not reorder
 
     int noteProxyOperation(int code, int proxiedUid, String proxiedPackageName,
-            String proxiedFeatureId, int proxyUid, String proxyPackageName,
-            String proxyFeatureId, boolean shouldCollectAsyncNotedOp, String message);
+            String proxiedAttributionTag, int proxyUid, String proxyPackageName,
+            String proxyAttributionTag, boolean shouldCollectAsyncNotedOp, String message);
 
     // Remaining methods are only used in Java.
     int checkPackage(int uid, String packageName);
@@ -64,10 +64,10 @@
     List<AppOpsManager.PackageOps> getPackagesForOps(in int[] ops);
     @UnsupportedAppUsage
     List<AppOpsManager.PackageOps> getOpsForPackage(int uid, String packageName, in int[] ops);
-    void getHistoricalOps(int uid, String packageName, String featureId, in List<String> ops,
+    void getHistoricalOps(int uid, String packageName, String attributionTag, in List<String> ops,
             int filter, long beginTimeMillis, long endTimeMillis, int flags,
             in RemoteCallback callback);
-    void getHistoricalOpsFromDiskRaw(int uid, String packageName, String featureId,
+    void getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag,
             in List<String> ops, int filter, long beginTimeMillis, long endTimeMillis, int flags,
             in RemoteCallback callback);
     void offsetHistory(long duration);
diff --git a/core/java/com/android/internal/app/ResolverListAdapter.java b/core/java/com/android/internal/app/ResolverListAdapter.java
index 61a404e..579abee 100644
--- a/core/java/com/android/internal/app/ResolverListAdapter.java
+++ b/core/java/com/android/internal/app/ResolverListAdapter.java
@@ -153,6 +153,14 @@
         return mResolverListController.getScore(target);
     }
 
+    /**
+     * Returns the list of top K component names which have highest
+     * {@link #getScore(DisplayResolveInfo)}
+     */
+    public List<ComponentName> getTopComponentNames(int topK) {
+        return mResolverListController.getTopComponentNames(topK);
+    }
+
     public void updateModel(ComponentName componentName) {
         mResolverListController.updateModel(componentName);
     }
diff --git a/core/java/com/android/internal/app/ResolverListController.java b/core/java/com/android/internal/app/ResolverListController.java
index 022aded..51dce55 100644
--- a/core/java/com/android/internal/app/ResolverListController.java
+++ b/core/java/com/android/internal/app/ResolverListController.java
@@ -367,6 +367,14 @@
         return mResolverComparator.getScore(target.getResolvedComponentName());
     }
 
+    /**
+     * Returns the list of top K component names which have highest
+     * {@link #getScore(DisplayResolveInfo)}
+     */
+    public List<ComponentName> getTopComponentNames(int topK) {
+        return mResolverComparator.getTopComponentNames(topK);
+    }
+
     public void updateModel(ComponentName componentName) {
         mResolverComparator.updateModel(componentName);
     }
diff --git a/core/java/com/android/internal/app/ResolverRankerServiceResolverComparator.java b/core/java/com/android/internal/app/ResolverRankerServiceResolverComparator.java
index 01e0622..2869450 100644
--- a/core/java/com/android/internal/app/ResolverRankerServiceResolverComparator.java
+++ b/core/java/com/android/internal/app/ResolverRankerServiceResolverComparator.java
@@ -48,6 +48,7 @@
 import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
 
 /**
  * Ranks and compares packages based on usage stats and uses the {@link ResolverRankerService}.
@@ -252,6 +253,15 @@
         return 0;
     }
 
+    @Override
+    List<ComponentName> getTopComponentNames(int topK) {
+        return mTargetsDict.entrySet().stream()
+                .sorted((o1, o2) -> -Float.compare(getScore(o1.getKey()), getScore(o2.getKey())))
+                .limit(topK)
+                .map(Map.Entry::getKey)
+                .collect(Collectors.toList());
+    }
+
     // update ranking model when the connection to it is valid.
     @Override
     public void updateModel(ComponentName componentName) {
diff --git a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java
index 086b9d8..837cc46 100644
--- a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java
+++ b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java
@@ -378,6 +378,17 @@
             "nav_bar_handle_show_over_lockscreen";
 
     /**
+     * (int) Timeout threshold, in millisecond, that Sharesheet waits for direct share targets.
+     */
+    public static final String SHARE_SHEET_DIRECT_SHARE_TIMEOUT =
+            "share_sheet_direct_share_timeout";
+
+    /**
+     * (boolean) Whether append direct share on Sharesheet is enabled.
+     */
+    public static final String APPEND_DIRECT_SHARE_ENABLED = "append_direct_share_enabled";
+
+    /**
      * (boolean) Whether to enable user-drag resizing for PIP.
      */
     public static final String PIP_USER_RESIZE = "pip_user_resize";
diff --git a/core/java/com/android/internal/os/ZygoteInit.java b/core/java/com/android/internal/os/ZygoteInit.java
index 54cf693..ec1f516 100644
--- a/core/java/com/android/internal/os/ZygoteInit.java
+++ b/core/java/com/android/internal/os/ZygoteInit.java
@@ -125,12 +125,6 @@
 
     private static boolean sPreloadComplete;
 
-    /**
-     * Cached classloader to use for the system server. Will only be populated in the system
-     * server process.
-     */
-    private static ClassLoader sCachedSystemServerClassLoader = null;
-
     static void preload(TimingsTraceLog bootTimingsTraceLog) {
         Log.d(TAG, "begin preload");
         bootTimingsTraceLog.traceBegin("BeginPreload");
@@ -508,13 +502,7 @@
 
         final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
         if (systemServerClasspath != null) {
-            if (performSystemServerDexOpt(systemServerClasspath)) {
-                // Throw away the cached classloader. If we compiled here, the classloader would
-                // not have had AoT-ed artifacts.
-                // Note: This only works in a very special environment where selinux enforcement is
-                // disabled, e.g., Mac builds.
-                sCachedSystemServerClassLoader = null;
-            }
+            performSystemServerDexOpt(systemServerClasspath);
             // Capturing profiles is only supported for debug or eng builds since selinux normally
             // prevents it.
             if (shouldProfileSystemServer() && (Build.IS_USERDEBUG || Build.IS_ENG)) {
@@ -546,9 +534,10 @@
 
             throw new IllegalStateException("Unexpected return from WrapperInit.execApplication");
         } else {
-            createSystemServerClassLoader();
-            ClassLoader cl = sCachedSystemServerClassLoader;
-            if (cl != null) {
+            ClassLoader cl = null;
+            if (systemServerClasspath != null) {
+                cl = createPathClassLoader(systemServerClasspath, parsedArgs.mTargetSdkVersion);
+
                 Thread.currentThread().setContextClassLoader(cl);
             }
 
@@ -564,24 +553,6 @@
     }
 
     /**
-     * Create the classloader for the system server and store it in
-     * {@link sCachedSystemServerClassLoader}. This function may be called through JNI in
-     * system server startup, when the runtime is in a critically low state. Do not do
-     * extended computation etc here.
-     */
-    private static void createSystemServerClassLoader() {
-        if (sCachedSystemServerClassLoader != null) {
-            return;
-        }
-        final String systemServerClasspath = Os.getenv("SYSTEMSERVERCLASSPATH");
-        // TODO: Should we run optimization here?
-        if (systemServerClasspath != null) {
-            sCachedSystemServerClassLoader = createPathClassLoader(systemServerClasspath,
-                    VMRuntime.SDK_VERSION_CUR_DEVELOPMENT);
-        }
-    }
-
-    /**
      * Note that preparing the profiles for system server does not require special selinux
      * permissions. From the installer perspective the system server is a regular package which can
      * capture profile information.
@@ -645,16 +616,15 @@
 
     /**
      * Performs dex-opt on the elements of {@code classPath}, if needed. We choose the instruction
-     * set of the current runtime. If something was compiled, return true.
+     * set of the current runtime.
      */
-    private static boolean performSystemServerDexOpt(String classPath) {
+    private static void performSystemServerDexOpt(String classPath) {
         final String[] classPathElements = classPath.split(":");
         final IInstalld installd = IInstalld.Stub
                 .asInterface(ServiceManager.getService("installd"));
         final String instructionSet = VMRuntime.getRuntime().vmInstructionSet();
 
         String classPathForElement = "";
-        boolean compiledSomething = false;
         for (String classPathElement : classPathElements) {
             // We default to the verify filter because the compilation will happen on /data and
             // system server cannot load executable code outside /system.
@@ -695,7 +665,6 @@
                             uuid, classLoaderContext, seInfo, false /* downgrade */,
                             targetSdkVersion, /*profileName*/ null, /*dexMetadataPath*/ null,
                             "server-dexopt");
-                    compiledSomething = true;
                 } catch (RemoteException | ServiceSpecificException e) {
                     // Ignore (but log), we need this on the classpath for fallback mode.
                     Log.w(TAG, "Failed compiling classpath element for system server: "
@@ -706,8 +675,6 @@
             classPathForElement = encodeSystemServerClassPath(
                     classPathForElement, classPathElement);
         }
-
-        return compiledSomething;
     }
 
     /**
@@ -794,6 +761,10 @@
              * this is present in all ARMv8 CPUs; this flag has no effect on other platforms. */
             parsedArgs.mRuntimeFlags |= Zygote.MEMORY_TAG_LEVEL_TBI;
 
+            /* Enable gwp-asan on the system server with a small probability. This is the same
+             * policy as applied to native processes and system apps. */
+            parsedArgs.mRuntimeFlags |= Zygote.GWP_ASAN_LEVEL_LOTTERY;
+
             if (shouldProfileSystemServer()) {
                 parsedArgs.mRuntimeFlags |= Zygote.PROFILE_SYSTEM_SERVER;
             }
diff --git a/core/java/com/android/internal/statusbar/IStatusBar.aidl b/core/java/com/android/internal/statusbar/IStatusBar.aidl
index 380a20c..5b79b18 100644
--- a/core/java/com/android/internal/statusbar/IStatusBar.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBar.aidl
@@ -136,7 +136,8 @@
 
     // Used to show the authentication dialog (Biometrics, Device Credential)
     void showAuthenticationDialog(in Bundle bundle, IBiometricServiceReceiverInternal receiver,
-            int biometricModality, boolean requireConfirmation, int userId, String opPackageName);
+            int biometricModality, boolean requireConfirmation, int userId, String opPackageName,
+            long operationId);
     // Used to notify the authentication dialog that a biometric has been authenticated
     void onBiometricAuthenticated();
     // Used to set a temporary message, e.g. fingerprint not recognized, finger moved too fast, etc
diff --git a/core/java/com/android/internal/statusbar/IStatusBarService.aidl b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
index 9907b99..1dbd69c 100644
--- a/core/java/com/android/internal/statusbar/IStatusBarService.aidl
+++ b/core/java/com/android/internal/statusbar/IStatusBarService.aidl
@@ -105,7 +105,8 @@
 
     // Used to show the authentication dialog (Biometrics, Device Credential)
     void showAuthenticationDialog(in Bundle bundle, IBiometricServiceReceiverInternal receiver,
-            int biometricModality, boolean requireConfirmation, int userId, String opPackageName);
+            int biometricModality, boolean requireConfirmation, int userId, String opPackageName,
+            long operationId);
     // Used to notify the authentication dialog that a biometric has been authenticated
     void onBiometricAuthenticated();
     // Used to set a temporary message, e.g. fingerprint not recognized, finger moved too fast, etc
diff --git a/core/java/com/android/internal/util/CollectionUtils.java b/core/java/com/android/internal/util/CollectionUtils.java
index 9b2bcfb..488b18d 100644
--- a/core/java/com/android/internal/util/CollectionUtils.java
+++ b/core/java/com/android/internal/util/CollectionUtils.java
@@ -16,6 +16,8 @@
 
 package com.android.internal.util;
 
+import static java.util.Collections.emptySet;
+
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.util.ArrayMap;
@@ -67,7 +69,7 @@
      */
     public static @NonNull <T> Set<T> filter(@Nullable Set<T> set,
             java.util.function.Predicate<? super T> predicate) {
-        if (set == null || set.size() == 0) return Collections.emptySet();
+        if (set == null || set.size() == 0) return emptySet();
         ArraySet<T> result = null;
         if (set instanceof ArraySet) {
             ArraySet<T> arraySet = (ArraySet<T>) set;
@@ -123,7 +125,7 @@
      */
     public static @NonNull <I, O> Set<O> map(@Nullable Set<I> cur,
             Function<? super I, ? extends O> f) {
-        if (isEmpty(cur)) return Collections.emptySet();
+        if (isEmpty(cur)) return emptySet();
         ArraySet<O> result = new ArraySet<>();
         if (cur instanceof ArraySet) {
             ArraySet<I> arraySet = (ArraySet<I>) cur;
@@ -182,7 +184,7 @@
      * @see Collections#emptySet
      */
     public static @NonNull <T> Set<T> emptyIfNull(@Nullable Set<T> cur) {
-        return cur == null ? Collections.emptySet() : cur;
+        return cur == null ? emptySet() : cur;
     }
 
     /**
@@ -325,9 +327,9 @@
      */
     public static @NonNull <T> Set<T> addAll(@Nullable Set<T> cur, @Nullable Collection<T> val) {
         if (isEmpty(val)) {
-            return cur != null ? cur : Collections.emptySet();
+            return cur != null ? cur : emptySet();
         }
-        if (cur == null || cur == Collections.emptySet()) {
+        if (cur == null || cur == emptySet()) {
             cur = new ArraySet<>();
         }
         cur.addAll(val);
@@ -338,7 +340,7 @@
      * @see #add(List, Object)
      */
     public static @NonNull <T> Set<T> add(@Nullable Set<T> cur, T val) {
-        if (cur == null || cur == Collections.emptySet()) {
+        if (cur == null || cur == emptySet()) {
             cur = new ArraySet<>();
         }
         cur.add(val);
@@ -390,7 +392,14 @@
      * @return a list that will not be affected by mutations to the given original list.
      */
     public static @NonNull <T> Set<T> copyOf(@Nullable Set<T> cur) {
-        return isEmpty(cur) ? Collections.emptySet() : new ArraySet<>(cur);
+        return isEmpty(cur) ? emptySet() : new ArraySet<>(cur);
+    }
+
+    /**
+     * @return a {@link Set} representing the given collection.
+     */
+    public static @NonNull <T> Set<T> toSet(@Nullable Collection<T> cur) {
+        return isEmpty(cur) ? emptySet() : new ArraySet<>(cur);
     }
 
     /**
diff --git a/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl b/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl
index 29bdf56..feb3f02 100644
--- a/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl
+++ b/core/java/com/android/internal/view/inline/IInlineContentCallback.aidl
@@ -24,4 +24,6 @@
  */
 oneway interface IInlineContentCallback {
     void onContent(in SurfaceControlViewHost.SurfacePackage content);
+    void onClick();
+    void onLongClick();
 }
diff --git a/core/java/com/android/internal/widget/CachingIconView.java b/core/java/com/android/internal/widget/CachingIconView.java
index 74ad815..bd0623e 100644
--- a/core/java/com/android/internal/widget/CachingIconView.java
+++ b/core/java/com/android/internal/widget/CachingIconView.java
@@ -32,6 +32,7 @@
 import android.widget.RemoteViews;
 
 import java.util.Objects;
+import java.util.function.Consumer;
 
 /**
  * An ImageView for displaying an Icon. Avoids reloading the Icon when possible.
@@ -44,6 +45,7 @@
     private boolean mInternalSetDrawable;
     private boolean mForceHidden;
     private int mDesiredVisibility;
+    private Consumer<Integer> mOnVisibilityChangedListener;
 
     @UnsupportedAppUsage
     public CachingIconView(Context context, @Nullable AttributeSet attrs) {
@@ -198,6 +200,13 @@
     private void updateVisibility() {
         int visibility = mDesiredVisibility == VISIBLE && mForceHidden ? INVISIBLE
                 : mDesiredVisibility;
+        if (mOnVisibilityChangedListener != null) {
+            mOnVisibilityChangedListener.accept(visibility);
+        }
         super.setVisibility(visibility);
     }
+
+    public void setOnVisibilityChangedListener(Consumer<Integer> listener) {
+        mOnVisibilityChangedListener = listener;
+    }
 }
diff --git a/core/java/com/android/internal/widget/ConversationLayout.java b/core/java/com/android/internal/widget/ConversationLayout.java
new file mode 100644
index 0000000..07be113
--- /dev/null
+++ b/core/java/com/android/internal/widget/ConversationLayout.java
@@ -0,0 +1,866 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+import android.annotation.AttrRes;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.annotation.StyleRes;
+import android.app.Notification;
+import android.app.Person;
+import android.app.RemoteInputHistoryItem;
+import android.content.Context;
+import android.content.res.ColorStateList;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.Rect;
+import android.graphics.drawable.Icon;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.text.TextUtils;
+import android.util.ArrayMap;
+import android.util.AttributeSet;
+import android.util.DisplayMetrics;
+import android.view.Gravity;
+import android.view.RemotableViewMethod;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.ViewTreeObserver;
+import android.view.animation.Interpolator;
+import android.view.animation.PathInterpolator;
+import android.widget.FrameLayout;
+import android.widget.ImageView;
+import android.widget.RemoteViews;
+import android.widget.TextView;
+
+import com.android.internal.R;
+import com.android.internal.graphics.ColorUtils;
+import com.android.internal.util.ContrastColorUtil;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Consumer;
+import java.util.regex.Pattern;
+
+/**
+ * A custom-built layout for the Notification.MessagingStyle allows dynamic addition and removal
+ * messages and adapts the layout accordingly.
+ */
+@RemoteViews.RemoteView
+public class ConversationLayout extends FrameLayout
+        implements ImageMessageConsumer, IMessagingLayout {
+
+    public static final boolean CONVERSATION_LAYOUT_ENABLED = true;
+    private static final float COLOR_SHIFT_AMOUNT = 60;
+    /**
+     *  Pattren for filter some ingonable characters.
+     *  p{Z} for any kind of whitespace or invisible separator.
+     *  p{C} for any kind of punctuation character.
+     */
+    private static final Pattern IGNORABLE_CHAR_PATTERN
+            = Pattern.compile("[\\p{C}\\p{Z}]");
+    private static final Pattern SPECIAL_CHAR_PATTERN
+            = Pattern.compile ("[!@#$%&*()_+=|<>?{}\\[\\]~-]");
+    private static final Consumer<MessagingMessage> REMOVE_MESSAGE
+            = MessagingMessage::removeMessage;
+    public static final Interpolator LINEAR_OUT_SLOW_IN = new PathInterpolator(0f, 0f, 0.2f, 1f);
+    public static final Interpolator FAST_OUT_LINEAR_IN = new PathInterpolator(0.4f, 0f, 1f, 1f);
+    public static final Interpolator FAST_OUT_SLOW_IN = new PathInterpolator(0.4f, 0f, 0.2f, 1f);
+    public static final OnLayoutChangeListener MESSAGING_PROPERTY_ANIMATOR
+            = new MessagingPropertyAnimator();
+    private List<MessagingMessage> mMessages = new ArrayList<>();
+    private List<MessagingMessage> mHistoricMessages = new ArrayList<>();
+    private MessagingLinearLayout mMessagingLinearLayout;
+    private boolean mShowHistoricMessages;
+    private ArrayList<MessagingGroup> mGroups = new ArrayList<>();
+    private TextView mTitleView;
+    private int mLayoutColor;
+    private int mSenderTextColor;
+    private int mMessageTextColor;
+    private int mAvatarSize;
+    private Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
+    private Paint mTextPaint = new Paint();
+    private Icon mAvatarReplacement;
+    private boolean mIsOneToOne;
+    private ArrayList<MessagingGroup> mAddedGroups = new ArrayList<>();
+    private Person mUser;
+    private CharSequence mNameReplacement;
+    private boolean mIsCollapsed;
+    private ImageResolver mImageResolver;
+    private ImageView mConversationIcon;
+    private TextView mConversationText;
+    private View mConversationIconBadge;
+    private Icon mLargeIcon;
+    private View mExpandButtonContainer;
+    private ViewGroup mExpandButtonAndContentContainer;
+    private NotificationExpandButton mExpandButton;
+    private int mExpandButtonExpandedTopMargin;
+    private int mBadgedSideMargins;
+    private int mIconSizeBadged;
+    private int mIconSizeCentered;
+    private CachingIconView mIcon;
+    private int mExpandedGroupTopMargin;
+    private int mExpandButtonExpandedSize;
+    private View mConversationFacePile;
+    private int mNotificationBackgroundColor;
+    private CharSequence mFallbackChatName;
+    private CharSequence mFallbackGroupChatName;
+    private CharSequence mConversationTitle;
+
+    public ConversationLayout(@NonNull Context context) {
+        super(context);
+    }
+
+    public ConversationLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
+        super(context, attrs);
+    }
+
+    public ConversationLayout(@NonNull Context context, @Nullable AttributeSet attrs,
+            @AttrRes int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+    }
+
+    public ConversationLayout(@NonNull Context context, @Nullable AttributeSet attrs,
+            @AttrRes int defStyleAttr, @StyleRes int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+    }
+
+    @Override
+    protected void onFinishInflate() {
+        super.onFinishInflate();
+        mMessagingLinearLayout = findViewById(R.id.notification_messaging);
+        mMessagingLinearLayout.setMessagingLayout(this);
+        // We still want to clip, but only on the top, since views can temporarily out of bounds
+        // during transitions.
+        DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
+        int size = Math.max(displayMetrics.widthPixels, displayMetrics.heightPixels);
+        Rect rect = new Rect(0, 0, size, size);
+        mMessagingLinearLayout.setClipBounds(rect);
+        mTitleView = findViewById(R.id.title);
+        mAvatarSize = getResources().getDimensionPixelSize(R.dimen.messaging_avatar_size);
+        mTextPaint.setTextAlign(Paint.Align.CENTER);
+        mTextPaint.setAntiAlias(true);
+        mConversationIcon = findViewById(R.id.conversation_icon);
+        mIcon = findViewById(R.id.icon);
+        mConversationIconBadge = findViewById(R.id.conversation_icon_badge);
+        mIcon.setOnVisibilityChangedListener((visibility) -> {
+            // Always keep the badge visibility in sync with the icon. This is necessary in cases
+            // Where the icon is being hidden externally like in group children.
+            mConversationIconBadge.setVisibility(visibility);
+        });
+        mConversationText = findViewById(R.id.conversation_text);
+        mExpandButtonContainer = findViewById(R.id.expand_button_container);
+        mExpandButtonAndContentContainer = findViewById(R.id.expand_button_and_content_container);
+        mExpandButton = findViewById(R.id.expand_button);
+        mExpandButtonExpandedTopMargin = getResources().getDimensionPixelSize(
+                R.dimen.conversation_expand_button_top_margin_expanded);
+        mExpandButtonExpandedSize = getResources().getDimensionPixelSize(
+                R.dimen.conversation_expand_button_expanded_size);
+        mBadgedSideMargins = getResources().getDimensionPixelSize(
+                R.dimen.conversation_badge_side_margin);
+        mIconSizeBadged = getResources().getDimensionPixelSize(
+                R.dimen.conversation_icon_size_badged);
+        mIconSizeCentered = getResources().getDimensionPixelSize(
+                R.dimen.conversation_icon_size_centered);
+        mExpandedGroupTopMargin = getResources().getDimensionPixelSize(
+                R.dimen.conversation_icon_margin_top_centered);
+        mConversationFacePile = findViewById(R.id.conversation_face_pile);
+        mFallbackChatName = getResources().getString(
+                R.string.conversation_title_fallback_one_to_one);
+        mFallbackGroupChatName = getResources().getString(
+                R.string.conversation_title_fallback_group_chat);
+    }
+
+    @RemotableViewMethod
+    public void setAvatarReplacement(Icon icon) {
+        mAvatarReplacement = icon;
+    }
+
+    @RemotableViewMethod
+    public void setNameReplacement(CharSequence nameReplacement) {
+        mNameReplacement = nameReplacement;
+    }
+
+    /**
+     * Set this layout to show the collapsed representation.
+     *
+     * @param isCollapsed is it collapsed
+     */
+    @RemotableViewMethod
+    public void setIsCollapsed(boolean isCollapsed) {
+        mIsCollapsed = isCollapsed;
+        mMessagingLinearLayout.setMaxDisplayedLines(isCollapsed ? 1 : Integer.MAX_VALUE);
+        updateExpandButton();
+    }
+
+    @RemotableViewMethod
+    public void setData(Bundle extras) {
+        Parcelable[] messages = extras.getParcelableArray(Notification.EXTRA_MESSAGES);
+        List<Notification.MessagingStyle.Message> newMessages
+                = Notification.MessagingStyle.Message.getMessagesFromBundleArray(messages);
+        Parcelable[] histMessages = extras.getParcelableArray(Notification.EXTRA_HISTORIC_MESSAGES);
+        List<Notification.MessagingStyle.Message> newHistoricMessages
+                = Notification.MessagingStyle.Message.getMessagesFromBundleArray(histMessages);
+
+        // mUser now set (would be nice to avoid the side effect but WHATEVER)
+        setUser(extras.getParcelable(Notification.EXTRA_MESSAGING_PERSON));
+
+
+        // Append remote input history to newMessages (again, side effect is lame but WHATEVS)
+        RemoteInputHistoryItem[] history = (RemoteInputHistoryItem[])
+                extras.getParcelableArray(Notification.EXTRA_REMOTE_INPUT_HISTORY_ITEMS);
+        addRemoteInputHistoryToMessages(newMessages, history);
+
+        boolean showSpinner =
+                extras.getBoolean(Notification.EXTRA_SHOW_REMOTE_INPUT_SPINNER, false);
+
+        // bind it, baby
+        bind(newMessages, newHistoricMessages, showSpinner);
+    }
+
+    @Override
+    public void setImageResolver(ImageResolver resolver) {
+        mImageResolver = resolver;
+    }
+
+    private void addRemoteInputHistoryToMessages(
+            List<Notification.MessagingStyle.Message> newMessages,
+            RemoteInputHistoryItem[] remoteInputHistory) {
+        if (remoteInputHistory == null || remoteInputHistory.length == 0) {
+            return;
+        }
+        for (int i = remoteInputHistory.length - 1; i >= 0; i--) {
+            RemoteInputHistoryItem historyMessage = remoteInputHistory[i];
+            Notification.MessagingStyle.Message message = new Notification.MessagingStyle.Message(
+                    historyMessage.getText(), 0, (Person) null, true /* remoteHistory */);
+            if (historyMessage.getUri() != null) {
+                message.setData(historyMessage.getMimeType(), historyMessage.getUri());
+            }
+            newMessages.add(message);
+        }
+    }
+
+    private void bind(List<Notification.MessagingStyle.Message> newMessages,
+            List<Notification.MessagingStyle.Message> newHistoricMessages,
+            boolean showSpinner) {
+        // convert MessagingStyle.Message to MessagingMessage, re-using ones from a previous binding
+        // if they exist
+        List<MessagingMessage> historicMessages = createMessages(newHistoricMessages,
+                true /* isHistoric */);
+        List<MessagingMessage> messages = createMessages(newMessages, false /* isHistoric */);
+
+        // Copy our groups, before they get clobbered
+        ArrayList<MessagingGroup> oldGroups = new ArrayList<>(mGroups);
+
+        // Add our new MessagingMessages to groups
+        List<List<MessagingMessage>> groups = new ArrayList<>();
+        List<Person> senders = new ArrayList<>();
+
+        // Lets first find the groups (populate `groups` and `senders`)
+        findGroups(historicMessages, messages, groups, senders);
+
+        // Let's now create the views and reorder them accordingly
+        //   side-effect: updates mGroups, mAddedGroups
+        createGroupViews(groups, senders, showSpinner);
+
+        // Let's first check which groups were removed altogether and remove them in one animation
+        removeGroups(oldGroups);
+
+        // Let's remove the remaining messages
+        mMessages.forEach(REMOVE_MESSAGE);
+        mHistoricMessages.forEach(REMOVE_MESSAGE);
+
+        mMessages = messages;
+        mHistoricMessages = historicMessages;
+
+        updateHistoricMessageVisibility();
+        updateTitleAndNamesDisplay();
+
+        updateConversationLayout();
+
+    }
+
+    /**
+     * Update the layout according to the data provided (i.e mIsOneToOne, expanded etc);
+     */
+    private void updateConversationLayout() {
+        // TODO: resolve this from shortcuts
+        // Set avatar and name
+        CharSequence conversationText = mConversationTitle;
+        // TODO: display the secondary text somewhere
+        if (mIsOneToOne) {
+            // Let's resolve the icon / text from the last sender
+            mConversationIcon.setVisibility(VISIBLE);
+            mConversationFacePile.setVisibility(GONE);
+            CharSequence userKey = getKey(mUser);
+            for (int i = mGroups.size() - 1; i >= 0; i--) {
+                MessagingGroup messagingGroup = mGroups.get(i);
+                Person messageSender = messagingGroup.getSender();
+                if ((messageSender != null && !TextUtils.equals(userKey, getKey(messageSender)))
+                        || i == 0) {
+                    if (TextUtils.isEmpty(conversationText)) {
+                        // We use the sendername as header text if no conversation title is provided
+                        // (This usually happens for most 1:1 conversations)
+                        conversationText = messagingGroup.getSenderName();
+                    }
+                    Icon avatarIcon = messagingGroup.getAvatarIcon();
+                    if (avatarIcon == null) {
+                        avatarIcon = createAvatarSymbol(conversationText, "", mLayoutColor);
+                    }
+                    mConversationIcon.setImageIcon(avatarIcon);
+                    break;
+                }
+            }
+        } else {
+            if (mIsCollapsed) {
+                if (mLargeIcon != null) {
+                    mConversationIcon.setVisibility(VISIBLE);
+                    mConversationFacePile.setVisibility(GONE);
+                    mConversationIcon.setImageIcon(mLargeIcon);
+                } else {
+                    mConversationIcon.setVisibility(GONE);
+                    // This will also inflate it!
+                    mConversationFacePile.setVisibility(VISIBLE);
+                    mConversationFacePile = findViewById(R.id.conversation_face_pile);
+                    bindFacePile();
+                }
+            } else {
+                mConversationFacePile.setVisibility(GONE);
+                mConversationIcon.setVisibility(GONE);
+            }
+        }
+        if (TextUtils.isEmpty(conversationText)) {
+            conversationText = mIsOneToOne ? mFallbackChatName : mFallbackGroupChatName;
+        }
+        mConversationText.setText(conversationText);
+        // Update if the groups can hide the sender if they are first (applies to 1:1 conversations)
+        // This needs to happen after all of the above o update all of the groups
+        for (int i = mGroups.size() - 1; i >= 0; i--) {
+            MessagingGroup messagingGroup = mGroups.get(i);
+            CharSequence messageSender = messagingGroup.getSenderName();
+            boolean canHide = mIsOneToOne
+                    && TextUtils.equals(conversationText, messageSender);
+            messagingGroup.setCanHideSenderIfFirst(canHide);
+        }
+        updateIconPositionAndSize();
+    }
+
+    private void bindFacePile() {
+        // Let's bind the face pile
+        View bottomBackground = mConversationFacePile.findViewById(
+                R.id.conversation_face_pile_bottom_background);
+        applyNotificationBackgroundColor(bottomBackground);
+        ImageView bottomView = mConversationFacePile.findViewById(
+                R.id.conversation_face_pile_bottom);
+        ImageView topView = mConversationFacePile.findViewById(
+                R.id.conversation_face_pile_top);
+        // Let's find the two last conversations:
+        Icon secondLastIcon = null;
+        CharSequence lastKey = null;
+        Icon lastIcon = null;
+        CharSequence userKey = getKey(mUser);
+        for (int i = mGroups.size() - 1; i >= 0; i--) {
+            MessagingGroup messagingGroup = mGroups.get(i);
+            Person messageSender = messagingGroup.getSender();
+            boolean notUser = messageSender != null
+                    && !TextUtils.equals(userKey, getKey(messageSender));
+            boolean notIncluded = messageSender != null
+                    && !TextUtils.equals(lastKey, getKey(messageSender));
+            if ((notUser && notIncluded)
+                    || (i == 0 && lastKey == null)) {
+                if (lastIcon == null) {
+                    lastIcon = messagingGroup.getAvatarIcon();
+                    lastKey = getKey(messageSender);
+                } else {
+                    secondLastIcon = messagingGroup.getAvatarIcon();
+                    break;
+                }
+            }
+        }
+        if (lastIcon == null) {
+            lastIcon = createAvatarSymbol(" ", "", mLayoutColor);
+        }
+        bottomView.setImageIcon(lastIcon);
+        if (secondLastIcon == null) {
+            secondLastIcon = createAvatarSymbol("", "", mLayoutColor);
+        }
+        topView.setImageIcon(secondLastIcon);
+    }
+
+    /**
+     * update the icon position and sizing
+     */
+    private void updateIconPositionAndSize() {
+        int gravity;
+        int marginStart;
+        int marginTop;
+        int iconSize;
+        if (mIsOneToOne || mIsCollapsed) {
+            // Baded format
+            gravity = Gravity.LEFT;
+            marginStart = mBadgedSideMargins;
+            marginTop = mBadgedSideMargins;
+            iconSize = mIconSizeBadged;
+        } else {
+            gravity = Gravity.CENTER_HORIZONTAL;
+            marginStart = 0;
+            marginTop = mExpandedGroupTopMargin;
+            iconSize = mIconSizeCentered;
+        }
+        LayoutParams layoutParams =
+                (LayoutParams) mConversationIconBadge.getLayoutParams();
+        layoutParams.gravity = gravity;
+        layoutParams.topMargin = marginTop;
+        layoutParams.setMarginStart(marginStart);
+        mConversationIconBadge.setLayoutParams(layoutParams);
+        ViewGroup.LayoutParams iconParams = mIcon.getLayoutParams();
+        iconParams.width = iconSize;
+        iconParams.height = iconSize;
+        mIcon.setLayoutParams(iconParams);
+    }
+
+    @RemotableViewMethod
+    public void setLargeIcon(Icon largeIcon) {
+        mLargeIcon = largeIcon;
+    }
+
+    /**
+     * Sets the conversation title of this conversation.
+     *
+     * @param conversationTitle the conversation title
+     */
+    @RemotableViewMethod
+    public void setConversationTitle(CharSequence conversationTitle) {
+        mConversationTitle = conversationTitle;
+    }
+
+    private void removeGroups(ArrayList<MessagingGroup> oldGroups) {
+        int size = oldGroups.size();
+        for (int i = 0; i < size; i++) {
+            MessagingGroup group = oldGroups.get(i);
+            if (!mGroups.contains(group)) {
+                List<MessagingMessage> messages = group.getMessages();
+                Runnable endRunnable = () -> {
+                    mMessagingLinearLayout.removeTransientView(group);
+                    group.recycle();
+                };
+
+                boolean wasShown = group.isShown();
+                mMessagingLinearLayout.removeView(group);
+                if (wasShown && !MessagingLinearLayout.isGone(group)) {
+                    mMessagingLinearLayout.addTransientView(group, 0);
+                    group.removeGroupAnimated(endRunnable);
+                } else {
+                    endRunnable.run();
+                }
+                mMessages.removeAll(messages);
+                mHistoricMessages.removeAll(messages);
+            }
+        }
+    }
+
+    private void updateTitleAndNamesDisplay() {
+        ArrayMap<CharSequence, String> uniqueNames = new ArrayMap<>();
+        ArrayMap<Character, CharSequence> uniqueCharacters = new ArrayMap<>();
+        for (int i = 0; i < mGroups.size(); i++) {
+            MessagingGroup group = mGroups.get(i);
+            CharSequence senderName = group.getSenderName();
+            if (!group.needsGeneratedAvatar() || TextUtils.isEmpty(senderName)) {
+                continue;
+            }
+            if (!uniqueNames.containsKey(senderName)) {
+                // Only use visible characters to get uniqueNames
+                String pureSenderName = IGNORABLE_CHAR_PATTERN
+                        .matcher(senderName).replaceAll("" /* replacement */);
+                char c = pureSenderName.charAt(0);
+                if (uniqueCharacters.containsKey(c)) {
+                    // this character was already used, lets make it more unique. We first need to
+                    // resolve the existing character if it exists
+                    CharSequence existingName = uniqueCharacters.get(c);
+                    if (existingName != null) {
+                        uniqueNames.put(existingName, findNameSplit((String) existingName));
+                        uniqueCharacters.put(c, null);
+                    }
+                    uniqueNames.put(senderName, findNameSplit((String) senderName));
+                } else {
+                    uniqueNames.put(senderName, Character.toString(c));
+                    uniqueCharacters.put(c, pureSenderName);
+                }
+            }
+        }
+
+        // Now that we have the correct symbols, let's look what we have cached
+        ArrayMap<CharSequence, Icon> cachedAvatars = new ArrayMap<>();
+        for (int i = 0; i < mGroups.size(); i++) {
+            // Let's now set the avatars
+            MessagingGroup group = mGroups.get(i);
+            boolean isOwnMessage = group.getSender() == mUser;
+            CharSequence senderName = group.getSenderName();
+            if (!group.needsGeneratedAvatar() || TextUtils.isEmpty(senderName)
+                    || (mIsOneToOne && mAvatarReplacement != null && !isOwnMessage)) {
+                continue;
+            }
+            String symbol = uniqueNames.get(senderName);
+            Icon cachedIcon = group.getAvatarSymbolIfMatching(senderName,
+                    symbol, mLayoutColor);
+            if (cachedIcon != null) {
+                cachedAvatars.put(senderName, cachedIcon);
+            }
+        }
+
+        for (int i = 0; i < mGroups.size(); i++) {
+            // Let's now set the avatars
+            MessagingGroup group = mGroups.get(i);
+            CharSequence senderName = group.getSenderName();
+            if (!group.needsGeneratedAvatar() || TextUtils.isEmpty(senderName)) {
+                continue;
+            }
+            if (mIsOneToOne && mAvatarReplacement != null && group.getSender() != mUser) {
+                group.setAvatar(mAvatarReplacement);
+            } else {
+                Icon cachedIcon = cachedAvatars.get(senderName);
+                if (cachedIcon == null) {
+                    cachedIcon = createAvatarSymbol(senderName, uniqueNames.get(senderName),
+                            mLayoutColor);
+                    cachedAvatars.put(senderName, cachedIcon);
+                }
+                group.setCreatedAvatar(cachedIcon, senderName, uniqueNames.get(senderName),
+                        mLayoutColor);
+            }
+        }
+    }
+
+    private Icon createAvatarSymbol(CharSequence senderName, String symbol, int layoutColor) {
+        if (symbol.isEmpty() || TextUtils.isDigitsOnly(symbol) ||
+                SPECIAL_CHAR_PATTERN.matcher(symbol).find()) {
+            Icon avatarIcon = Icon.createWithResource(getContext(),
+                    R.drawable.messaging_user);
+            avatarIcon.setTint(findColor(senderName, layoutColor));
+            return avatarIcon;
+        } else {
+            Bitmap bitmap = Bitmap.createBitmap(mAvatarSize, mAvatarSize, Bitmap.Config.ARGB_8888);
+            Canvas canvas = new Canvas(bitmap);
+            float radius = mAvatarSize / 2.0f;
+            int color = findColor(senderName, layoutColor);
+            mPaint.setColor(color);
+            canvas.drawCircle(radius, radius, radius, mPaint);
+            boolean needDarkText = ColorUtils.calculateLuminance(color) > 0.5f;
+            mTextPaint.setColor(needDarkText ? Color.BLACK : Color.WHITE);
+            mTextPaint.setTextSize(symbol.length() == 1 ? mAvatarSize * 0.5f : mAvatarSize * 0.3f);
+            int yPos = (int) (radius - ((mTextPaint.descent() + mTextPaint.ascent()) / 2));
+            canvas.drawText(symbol, radius, yPos, mTextPaint);
+            return Icon.createWithBitmap(bitmap);
+        }
+    }
+
+    private int findColor(CharSequence senderName, int layoutColor) {
+        double luminance = ContrastColorUtil.calculateLuminance(layoutColor);
+        float shift = Math.abs(senderName.hashCode()) % 5 / 4.0f - 0.5f;
+
+        // we need to offset the range if the luminance is too close to the borders
+        shift += Math.max(COLOR_SHIFT_AMOUNT / 2.0f / 100 - luminance, 0);
+        shift -= Math.max(COLOR_SHIFT_AMOUNT / 2.0f / 100 - (1.0f - luminance), 0);
+        return ContrastColorUtil.getShiftedColor(layoutColor,
+                (int) (shift * COLOR_SHIFT_AMOUNT));
+    }
+
+    private String findNameSplit(String existingName) {
+        String[] split = existingName.split(" ");
+        if (split.length > 1) {
+            return Character.toString(split[0].charAt(0))
+                    + Character.toString(split[1].charAt(0));
+        }
+        return existingName.substring(0, 1);
+    }
+
+    @RemotableViewMethod
+    public void setLayoutColor(int color) {
+        mLayoutColor = color;
+    }
+
+    @RemotableViewMethod
+    public void setIsOneToOne(boolean oneToOne) {
+        mIsOneToOne = oneToOne;
+    }
+
+    @RemotableViewMethod
+    public void setSenderTextColor(int color) {
+        mSenderTextColor = color;
+    }
+
+    /**
+     * @param color the color of the notification background
+     */
+    @RemotableViewMethod
+    public void setNotificationBackgroundColor(int color) {
+        mNotificationBackgroundColor = color;
+        applyNotificationBackgroundColor(mConversationIconBadge);
+    }
+
+    private void applyNotificationBackgroundColor(View view) {
+        view.setBackgroundTintList(ColorStateList.valueOf(mNotificationBackgroundColor));
+    }
+
+    @RemotableViewMethod
+    public void setMessageTextColor(int color) {
+        mMessageTextColor = color;
+    }
+
+    private void setUser(Person user) {
+        mUser = user;
+        if (mUser.getIcon() == null) {
+            Icon userIcon = Icon.createWithResource(getContext(),
+                    R.drawable.messaging_user);
+            userIcon.setTint(mLayoutColor);
+            mUser = mUser.toBuilder().setIcon(userIcon).build();
+        }
+    }
+
+    private void createGroupViews(List<List<MessagingMessage>> groups,
+            List<Person> senders, boolean showSpinner) {
+        mGroups.clear();
+        for (int groupIndex = 0; groupIndex < groups.size(); groupIndex++) {
+            List<MessagingMessage> group = groups.get(groupIndex);
+            MessagingGroup newGroup = null;
+            // we'll just take the first group that exists or create one there is none
+            for (int messageIndex = group.size() - 1; messageIndex >= 0; messageIndex--) {
+                MessagingMessage message = group.get(messageIndex);
+                newGroup = message.getGroup();
+                if (newGroup != null) {
+                    break;
+                }
+            }
+            // Create a new group, adding it to the linear layout as well
+            if (newGroup == null) {
+                newGroup = MessagingGroup.createGroup(mMessagingLinearLayout);
+                mAddedGroups.add(newGroup);
+            }
+            newGroup.setDisplayImagesAtEnd(mIsCollapsed);
+            newGroup.setLayoutColor(mLayoutColor);
+            newGroup.setTextColors(mSenderTextColor, mMessageTextColor);
+            Person sender = senders.get(groupIndex);
+            CharSequence nameOverride = null;
+            if (sender != mUser && mNameReplacement != null) {
+                nameOverride = mNameReplacement;
+            }
+            newGroup.setShowingAvatar(!mIsOneToOne && !mIsCollapsed);
+            newGroup.setSingleLine(mIsCollapsed);
+            newGroup.setSender(sender, nameOverride);
+            newGroup.setSending(groupIndex == (groups.size() - 1) && showSpinner);
+            mGroups.add(newGroup);
+
+            // Reposition to the correct place (if we're re-using a group)
+            if (mMessagingLinearLayout.indexOfChild(newGroup) != groupIndex) {
+                mMessagingLinearLayout.removeView(newGroup);
+                mMessagingLinearLayout.addView(newGroup, groupIndex);
+            }
+            newGroup.setMessages(group);
+        }
+    }
+
+    private void findGroups(List<MessagingMessage> historicMessages,
+            List<MessagingMessage> messages, List<List<MessagingMessage>> groups,
+            List<Person> senders) {
+        CharSequence currentSenderKey = null;
+        List<MessagingMessage> currentGroup = null;
+        int histSize = historicMessages.size();
+        for (int i = 0; i < histSize + messages.size(); i++) {
+            MessagingMessage message;
+            if (i < histSize) {
+                message = historicMessages.get(i);
+            } else {
+                message = messages.get(i - histSize);
+            }
+            boolean isNewGroup = currentGroup == null;
+            Person sender = message.getMessage().getSenderPerson();
+            CharSequence key = getKey(sender);
+            isNewGroup |= !TextUtils.equals(key, currentSenderKey);
+            if (isNewGroup) {
+                currentGroup = new ArrayList<>();
+                groups.add(currentGroup);
+                if (sender == null) {
+                    sender = mUser;
+                }
+                senders.add(sender);
+                currentSenderKey = key;
+            }
+            currentGroup.add(message);
+        }
+    }
+
+    private CharSequence getKey(Person person) {
+        return person == null ? null : person.getKey() == null ? person.getName() : person.getKey();
+    }
+
+    /**
+     * Creates new messages, reusing existing ones if they are available.
+     *
+     * @param newMessages the messages to parse.
+     */
+    private List<MessagingMessage> createMessages(
+            List<Notification.MessagingStyle.Message> newMessages, boolean historic) {
+        List<MessagingMessage> result = new ArrayList<>();
+        for (int i = 0; i < newMessages.size(); i++) {
+            Notification.MessagingStyle.Message m = newMessages.get(i);
+            MessagingMessage message = findAndRemoveMatchingMessage(m);
+            if (message == null) {
+                message = MessagingMessage.createMessage(this, m, mImageResolver);
+            }
+            message.setIsHistoric(historic);
+            result.add(message);
+        }
+        return result;
+    }
+
+    private MessagingMessage findAndRemoveMatchingMessage(Notification.MessagingStyle.Message m) {
+        for (int i = 0; i < mMessages.size(); i++) {
+            MessagingMessage existing = mMessages.get(i);
+            if (existing.sameAs(m)) {
+                mMessages.remove(i);
+                return existing;
+            }
+        }
+        for (int i = 0; i < mHistoricMessages.size(); i++) {
+            MessagingMessage existing = mHistoricMessages.get(i);
+            if (existing.sameAs(m)) {
+                mHistoricMessages.remove(i);
+                return existing;
+            }
+        }
+        return null;
+    }
+
+    public void showHistoricMessages(boolean show) {
+        mShowHistoricMessages = show;
+        updateHistoricMessageVisibility();
+    }
+
+    private void updateHistoricMessageVisibility() {
+        int numHistoric = mHistoricMessages.size();
+        for (int i = 0; i < numHistoric; i++) {
+            MessagingMessage existing = mHistoricMessages.get(i);
+            existing.setVisibility(mShowHistoricMessages ? VISIBLE : GONE);
+        }
+        int numGroups = mGroups.size();
+        for (int i = 0; i < numGroups; i++) {
+            MessagingGroup group = mGroups.get(i);
+            int visibleChildren = 0;
+            List<MessagingMessage> messages = group.getMessages();
+            int numGroupMessages = messages.size();
+            for (int j = 0; j < numGroupMessages; j++) {
+                MessagingMessage message = messages.get(j);
+                if (message.getVisibility() != GONE) {
+                    visibleChildren++;
+                }
+            }
+            if (visibleChildren > 0 && group.getVisibility() == GONE) {
+                group.setVisibility(VISIBLE);
+            } else if (visibleChildren == 0 && group.getVisibility() != GONE)   {
+                group.setVisibility(GONE);
+            }
+        }
+    }
+
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
+        if (!mAddedGroups.isEmpty()) {
+            getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
+                @Override
+                public boolean onPreDraw() {
+                    for (MessagingGroup group : mAddedGroups) {
+                        if (!group.isShown()) {
+                            continue;
+                        }
+                        MessagingPropertyAnimator.fadeIn(group.getAvatar());
+                        MessagingPropertyAnimator.fadeIn(group.getSenderView());
+                        MessagingPropertyAnimator.startLocalTranslationFrom(group,
+                                group.getHeight(), LINEAR_OUT_SLOW_IN);
+                    }
+                    mAddedGroups.clear();
+                    getViewTreeObserver().removeOnPreDrawListener(this);
+                    return true;
+                }
+            });
+        }
+    }
+
+    public MessagingLinearLayout getMessagingLinearLayout() {
+        return mMessagingLinearLayout;
+    }
+
+    public ArrayList<MessagingGroup> getMessagingGroups() {
+        return mGroups;
+    }
+
+    private void updateExpandButton() {
+        int drawableId;
+        int contentDescriptionId;
+        int gravity;
+        int topMargin = 0;
+        ViewGroup newContainer;
+        int newContainerHeight;
+        if (mIsCollapsed) {
+            drawableId = R.drawable.ic_expand_notification;
+            contentDescriptionId = R.string.expand_button_content_description_collapsed;
+            gravity = Gravity.CENTER;
+            newContainer = mExpandButtonAndContentContainer;
+            newContainerHeight = LayoutParams.MATCH_PARENT;
+        } else {
+            drawableId = R.drawable.ic_collapse_notification;
+            contentDescriptionId = R.string.expand_button_content_description_expanded;
+            gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
+            topMargin = mExpandButtonExpandedTopMargin;
+            newContainer = this;
+            newContainerHeight = mExpandButtonExpandedSize;
+        }
+        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
+        mExpandButton.setColorFilter(mExpandButton.getOriginalNotificationColor());
+
+        // We need to make sure that the expand button is in the linearlayout pushing over the
+        // content when collapsed, but allows the content to flow under it when expanded.
+        if (newContainer != mExpandButtonContainer.getParent()) {
+            ((ViewGroup) mExpandButtonContainer.getParent()).removeView(mExpandButtonContainer);
+            newContainer.addView(mExpandButtonContainer);
+            MarginLayoutParams layoutParams =
+                    (MarginLayoutParams) mExpandButtonContainer.getLayoutParams();
+            layoutParams.height = newContainerHeight;
+            mExpandButtonContainer.setLayoutParams(layoutParams);
+        }
+
+        // update if the expand button is centered
+        FrameLayout.LayoutParams layoutParams = (LayoutParams) mExpandButton.getLayoutParams();
+        layoutParams.gravity = gravity;
+        layoutParams.topMargin = topMargin;
+        mExpandButton.setLayoutParams(layoutParams);
+
+        mExpandButtonContainer.setContentDescription(mContext.getText(contentDescriptionId));
+
+    }
+
+    public void updateExpandability(boolean expandable, @Nullable OnClickListener onClickListener) {
+        if (expandable) {
+            mExpandButtonContainer.setVisibility(VISIBLE);
+            mExpandButtonContainer.setOnClickListener(onClickListener);
+        } else {
+            // TODO: handle content paddings to end of layout
+            mExpandButtonContainer.setVisibility(GONE);
+        }
+    }
+}
diff --git a/core/java/com/android/internal/widget/IMessagingLayout.java b/core/java/com/android/internal/widget/IMessagingLayout.java
new file mode 100644
index 0000000..149d056
--- /dev/null
+++ b/core/java/com/android/internal/widget/IMessagingLayout.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.internal.widget;
+
+import android.content.Context;
+
+import java.util.ArrayList;
+
+/**
+ * An interface for a MessagingLayout
+ */
+public interface IMessagingLayout {
+
+    /**
+     * @return the layout containing the messages
+     */
+    MessagingLinearLayout getMessagingLinearLayout();
+
+    /**
+     * @return the context of this view
+     */
+    Context getContext();
+
+    /**
+     * @return the list of messaging groups
+     */
+    ArrayList<MessagingGroup> getMessagingGroups();
+}
diff --git a/core/java/com/android/internal/widget/MessagingGroup.java b/core/java/com/android/internal/widget/MessagingGroup.java
index c9a9161..9977903 100644
--- a/core/java/com/android/internal/widget/MessagingGroup.java
+++ b/core/java/com/android/internal/widget/MessagingGroup.java
@@ -55,8 +55,9 @@
     private static Pools.SimplePool<MessagingGroup> sInstancePool
             = new Pools.SynchronizedPool<>(10);
     private MessagingLinearLayout mMessageContainer;
-    private ImageFloatingTextView mSenderName;
+    ImageFloatingTextView mSenderView;
     private ImageView mAvatarView;
+    private View mAvatarContainer;
     private String mAvatarSymbol = "";
     private int mLayoutColor;
     private CharSequence mAvatarName = "";
@@ -72,10 +73,18 @@
     private boolean mImagesAtEnd;
     private ViewGroup mImageContainer;
     private MessagingImageMessage mIsolatedMessage;
-    private boolean mTransformingImages;
+    private boolean mClippingDisabled;
     private Point mDisplaySize = new Point();
     private ProgressBar mSendingSpinner;
     private View mSendingSpinnerContainer;
+    private boolean mShowingAvatar = true;
+    private CharSequence mSenderName;
+    private boolean mSingleLine = false;
+    private LinearLayout mContentContainer;
+    private int mRequestedMaxDisplayedLines = Integer.MAX_VALUE;
+    private int mSenderTextPaddingSingleLine;
+    private boolean mIsFirstGroupInLayout = true;
+    private boolean mCanHideSenderIfFirst;
 
     public MessagingGroup(@NonNull Context context) {
         super(context);
@@ -99,26 +108,34 @@
     protected void onFinishInflate() {
         super.onFinishInflate();
         mMessageContainer = findViewById(R.id.group_message_container);
-        mSenderName = findViewById(R.id.message_name);
+        mSenderView = findViewById(R.id.message_name);
         mAvatarView = findViewById(R.id.message_icon);
         mImageContainer = findViewById(R.id.messaging_group_icon_container);
         mSendingSpinner = findViewById(R.id.messaging_group_sending_progress);
+        mContentContainer = findViewById(R.id.messaging_group_content_container);
         mSendingSpinnerContainer = findViewById(R.id.messaging_group_sending_progress_container);
         DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
         mDisplaySize.x = displayMetrics.widthPixels;
         mDisplaySize.y = displayMetrics.heightPixels;
+        mSenderTextPaddingSingleLine = getResources().getDimensionPixelSize(
+                R.dimen.messaging_group_singleline_sender_padding_end);
     }
 
     public void updateClipRect() {
         // We want to clip to the senderName if it's available, otherwise our images will come
         // from a weird position
         Rect clipRect;
-        if (mSenderName.getVisibility() != View.GONE && !mTransformingImages) {
-            ViewGroup parent = (ViewGroup) mSenderName.getParent();
-            int top = getDistanceFromParent(mSenderName, parent) - getDistanceFromParent(
-                    mMessageContainer, parent) + mSenderName.getHeight();
+        if (mSenderView.getVisibility() != View.GONE && !mClippingDisabled) {
+            int top;
+            if (mSingleLine) {
+                top = 0;
+            } else {
+                top = getDistanceFromParent(mSenderView, mContentContainer)
+                        - getDistanceFromParent(mMessageContainer, mContentContainer)
+                        + mSenderView.getHeight();
+            }
             int size = Math.max(mDisplaySize.x, mDisplaySize.y);
-            clipRect = new Rect(0, top, size, size);
+            clipRect = new Rect(-size, top, size, size);
         } else {
             clipRect = null;
         }
@@ -140,17 +157,31 @@
         if (nameOverride == null) {
             nameOverride = sender.getName();
         }
-        mSenderName.setText(nameOverride);
+        mSenderName = nameOverride;
+        if (mSingleLine && !TextUtils.isEmpty(nameOverride)) {
+            nameOverride = mContext.getResources().getString(
+                    R.string.conversation_single_line_name_display, nameOverride);
+        }
+        mSenderView.setText(nameOverride);
         mNeedsGeneratedAvatar = sender.getIcon() == null;
         if (!mNeedsGeneratedAvatar) {
             setAvatar(sender.getIcon());
         }
-        mAvatarView.setVisibility(VISIBLE);
-        mSenderName.setVisibility(TextUtils.isEmpty(nameOverride) ? GONE : VISIBLE);
+        updateSenderVisibility();
+    }
+
+    /**
+     * Should the avatar be shown for this view.
+     *
+     * @param showingAvatar should it be shown
+     */
+    public void setShowingAvatar(boolean showingAvatar) {
+        mAvatarView.setVisibility(showingAvatar ? VISIBLE : GONE);
+        mShowingAvatar = showingAvatar;
     }
 
     public void setSending(boolean sending) {
-        int visibility = sending ? View.VISIBLE : View.GONE;
+        int visibility = sending ? VISIBLE : GONE;
         if (mSendingSpinnerContainer.getVisibility() != visibility) {
             mSendingSpinnerContainer.setVisibility(visibility);
             updateMessageColor();
@@ -171,7 +202,9 @@
 
     public void setAvatar(Icon icon) {
         mAvatarIcon = icon;
-        mAvatarView.setImageIcon(icon);
+        if (mShowingAvatar || icon == null) {
+            mAvatarView.setImageIcon(icon);
+        }
         mAvatarSymbol = "";
         mAvatarName = "";
     }
@@ -220,13 +253,20 @@
         setAvatar(null);
         mAvatarView.setAlpha(1.0f);
         mAvatarView.setTranslationY(0.0f);
-        mSenderName.setAlpha(1.0f);
-        mSenderName.setTranslationY(0.0f);
+        mSenderView.setAlpha(1.0f);
+        mSenderView.setTranslationY(0.0f);
         setAlpha(1.0f);
         mIsolatedMessage = null;
         mMessages = null;
+        mSenderName = null;
         mAddedMessages.clear();
         mFirstLayout = true;
+        setCanHideSenderIfFirst(false);
+        setIsFirstInLayout(true);
+
+        setMaxDisplayedLines(Integer.MAX_VALUE);
+        setSingleLine(false);
+        setShowingAvatar(true);
         MessagingPropertyAnimator.recycle(this);
         sInstancePool.release(MessagingGroup.this);
     }
@@ -252,7 +292,7 @@
     }
 
     public CharSequence getSenderName() {
-        return mSenderName.getText();
+        return mSenderName;
     }
 
     public static void dropCache() {
@@ -310,7 +350,12 @@
 
     @Override
     public void setMaxDisplayedLines(int lines) {
-        mMessageContainer.setMaxDisplayedLines(lines);
+        mRequestedMaxDisplayedLines = lines;
+        updateMaxDisplayedLines();
+    }
+
+    private void updateMaxDisplayedLines() {
+        mMessageContainer.setMaxDisplayedLines(mSingleLine ? 1 : mRequestedMaxDisplayedLines);
     }
 
     @Override
@@ -324,6 +369,35 @@
         return mIsHidingAnimated;
     }
 
+    @Override
+    public void setIsFirstInLayout(boolean first) {
+        if (first != mIsFirstGroupInLayout) {
+            mIsFirstGroupInLayout = first;
+            updateSenderVisibility();
+        }
+    }
+
+    /**
+     * @param canHide true if the sender can be hidden if it is first
+     */
+    public void setCanHideSenderIfFirst(boolean canHide) {
+        if (mCanHideSenderIfFirst != canHide) {
+            mCanHideSenderIfFirst = canHide;
+            updateSenderVisibility();
+        }
+    }
+
+    private void updateSenderVisibility() {
+        boolean hidden = (mIsFirstGroupInLayout || mSingleLine) && mCanHideSenderIfFirst
+                || TextUtils.isEmpty(mSenderName);
+        mSenderView.setVisibility(hidden ? GONE : VISIBLE);
+    }
+
+    @Override
+    public boolean hasDifferentHeightWhenFirst() {
+        return mCanHideSenderIfFirst && !mSingleLine && !TextUtils.isEmpty(mSenderName);
+    }
+
     private void setIsHidingAnimated(boolean isHiding) {
         ViewParent parent = getParent();
         mIsHidingAnimated = isHiding;
@@ -362,7 +436,7 @@
         mTextColor = messageTextColor;
         mSendingTextColor = calculateSendingTextColor();
         updateMessageColor();
-        mSenderName.setTextColor(senderTextColor);
+        mSenderView.setTextColor(senderTextColor);
     }
 
     public void setLayoutColor(int layoutColor) {
@@ -506,13 +580,17 @@
     }
 
     public View getSenderView() {
-        return mSenderName;
+        return mSenderView;
     }
 
     public View getAvatar() {
         return mAvatarView;
     }
 
+    public Icon getAvatarIcon() {
+        return mAvatarIcon;
+    }
+
     public MessagingLinearLayout getMessageContainer() {
         return mMessageContainer;
     }
@@ -529,8 +607,8 @@
         return mSender;
     }
 
-    public void setTransformingImages(boolean transformingImages) {
-        mTransformingImages = transformingImages;
+    public void setClippingDisabled(boolean disabled) {
+        mClippingDisabled = disabled;
     }
 
     public void setDisplayImagesAtEnd(boolean atEnd) {
@@ -543,4 +621,27 @@
     public List<MessagingMessage> getMessages() {
         return mMessages;
     }
+
+    /**
+     * Set this layout to be single line and therefore displaying both the sender and the text on
+     * the same line.
+     *
+     * @param singleLine should be layout be single line
+     */
+    public void setSingleLine(boolean singleLine) {
+        if (singleLine != mSingleLine) {
+            mSingleLine = singleLine;
+            mContentContainer.setOrientation(
+                    singleLine ? LinearLayout.HORIZONTAL : LinearLayout.VERTICAL);
+            MarginLayoutParams layoutParams = (MarginLayoutParams) mSenderView.getLayoutParams();
+            layoutParams.setMarginEnd(singleLine ? mSenderTextPaddingSingleLine : 0);
+            updateMaxDisplayedLines();
+            updateClipRect();
+            updateSenderVisibility();
+        }
+    }
+
+    public boolean isSingleLine() {
+        return mSingleLine;
+    }
 }
diff --git a/core/java/com/android/internal/widget/MessagingImageMessage.java b/core/java/com/android/internal/widget/MessagingImageMessage.java
index 64650a7..c243f3b 100644
--- a/core/java/com/android/internal/widget/MessagingImageMessage.java
+++ b/core/java/com/android/internal/widget/MessagingImageMessage.java
@@ -120,7 +120,7 @@
         return true;
     }
 
-    static MessagingMessage createMessage(MessagingLayout layout,
+    static MessagingMessage createMessage(IMessagingLayout layout,
             Notification.MessagingStyle.Message m, ImageResolver resolver) {
         MessagingLinearLayout messagingLinearLayout = layout.getMessagingLinearLayout();
         MessagingImageMessage createdMessage = sInstancePool.acquire();
diff --git a/core/java/com/android/internal/widget/MessagingLayout.java b/core/java/com/android/internal/widget/MessagingLayout.java
index f608958..503f3f1 100644
--- a/core/java/com/android/internal/widget/MessagingLayout.java
+++ b/core/java/com/android/internal/widget/MessagingLayout.java
@@ -58,7 +58,8 @@
  * messages and adapts the layout accordingly.
  */
 @RemoteViews.RemoteView
-public class MessagingLayout extends FrameLayout implements ImageMessageConsumer {
+public class MessagingLayout extends FrameLayout
+        implements ImageMessageConsumer, IMessagingLayout {
 
     private static final float COLOR_SHIFT_AMOUNT = 60;
     /**
@@ -143,9 +144,29 @@
         mNameReplacement = nameReplacement;
     }
 
+    /**
+     * Set this layout to show the collapsed representation.
+     *
+     * @param isCollapsed is it collapsed
+     */
     @RemotableViewMethod
-    public void setDisplayImagesAtEnd(boolean atEnd) {
-        mDisplayImagesAtEnd = atEnd;
+    public void setIsCollapsed(boolean isCollapsed) {
+        mDisplayImagesAtEnd = isCollapsed;
+    }
+
+    @RemotableViewMethod
+    public void setLargeIcon(Icon largeIcon) {
+        // Unused
+    }
+
+    /**
+     * Sets the conversation title of this conversation.
+     *
+     * @param conversationTitle the conversation title
+     */
+    @RemotableViewMethod
+    public void setConversationTitle(CharSequence conversationTitle) {
+        // Unused
     }
 
     @RemotableViewMethod
@@ -371,6 +392,15 @@
         mSenderTextColor = color;
     }
 
+
+    /**
+     * @param color the color of the notification background
+     */
+    @RemotableViewMethod
+    public void setNotificationBackgroundColor(int color) {
+        // Nothing to do with this
+    }
+
     @RemotableViewMethod
     public void setMessageTextColor(int color) {
         mMessageTextColor = color;
diff --git a/core/java/com/android/internal/widget/MessagingLinearLayout.java b/core/java/com/android/internal/widget/MessagingLinearLayout.java
index 0c8613b..ac04862 100644
--- a/core/java/com/android/internal/widget/MessagingLinearLayout.java
+++ b/core/java/com/android/internal/widget/MessagingLinearLayout.java
@@ -43,7 +43,7 @@
 
     private int mMaxDisplayedLines = Integer.MAX_VALUE;
 
-    private MessagingLayout mMessagingLayout;
+    private IMessagingLayout mMessagingLayout;
 
     public MessagingLinearLayout(Context context, @Nullable AttributeSet attrs) {
         super(context, attrs);
@@ -84,6 +84,11 @@
             final View child = getChildAt(i);
             final LayoutParams lp = (LayoutParams) child.getLayoutParams();
             lp.hide = true;
+            if (child instanceof MessagingChild) {
+                MessagingChild messagingChild = (MessagingChild) child;
+                // Whenever we encounter the message first, it's always first in the layout
+                messagingChild.setIsFirstInLayout(true);
+            }
         }
 
         totalHeight = mPaddingTop + mPaddingBottom;
@@ -91,6 +96,11 @@
         int linesRemaining = mMaxDisplayedLines;
         // Starting from the bottom: we measure every view as if it were the only one. If it still
         // fits, we take it, otherwise we stop there.
+        MessagingChild previousChild = null;
+        View previousView = null;
+        int previousChildHeight = 0;
+        int previousTotalHeight = 0;
+        int previousLinesConsumed = 0;
         for (int i = count - 1; i >= 0 && totalHeight < targetHeight; i--) {
             if (getChildAt(i).getVisibility() == GONE) {
                 continue;
@@ -99,7 +109,16 @@
             LayoutParams lp = (LayoutParams) getChildAt(i).getLayoutParams();
             MessagingChild messagingChild = null;
             int spacing = mSpacing;
+            int previousChildIncrease = 0;
             if (child instanceof MessagingChild) {
+                // We need to remeasure the previous child again if it's not the first anymore
+                if (previousChild != null && previousChild.hasDifferentHeightWhenFirst()) {
+                    previousChild.setIsFirstInLayout(false);
+                    measureChildWithMargins(previousView, widthMeasureSpec, 0, heightMeasureSpec,
+                            previousTotalHeight - previousChildHeight);
+                    previousChildIncrease = previousView.getMeasuredHeight() - previousChildHeight;
+                    linesRemaining -= previousChild.getConsumedLines() - previousLinesConsumed;
+                }
                 messagingChild = (MessagingChild) child;
                 messagingChild.setMaxDisplayedLines(linesRemaining);
                 spacing += messagingChild.getExtraSpacing();
@@ -110,18 +129,26 @@
 
             final int childHeight = child.getMeasuredHeight();
             int newHeight = Math.max(totalHeight, totalHeight + childHeight + lp.topMargin +
-                    lp.bottomMargin + spacing);
+                    lp.bottomMargin + spacing + previousChildIncrease);
             int measureType = MessagingChild.MEASURED_NORMAL;
             if (messagingChild != null) {
                 measureType = messagingChild.getMeasuredType();
-                linesRemaining -= messagingChild.getConsumedLines();
             }
 
             // We never measure the first item as too small, we want to at least show something.
             boolean isTooSmall = measureType == MessagingChild.MEASURED_TOO_SMALL && !first;
             boolean isShortened = measureType == MessagingChild.MEASURED_SHORTENED
                     || measureType == MessagingChild.MEASURED_TOO_SMALL && first;
-            if (newHeight <= targetHeight && !isTooSmall) {
+            boolean showView = newHeight <= targetHeight && !isTooSmall;
+            if (showView) {
+                if (messagingChild != null) {
+                    previousLinesConsumed = messagingChild.getConsumedLines();
+                    linesRemaining -= previousLinesConsumed;
+                    previousChild = messagingChild;
+                    previousView = child;
+                    previousChildHeight = childHeight;
+                    previousTotalHeight = totalHeight;
+                }
                 totalHeight = newHeight;
                 measuredWidth = Math.max(measuredWidth,
                         child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin
@@ -131,6 +158,16 @@
                     break;
                 }
             } else {
+                // We now became too short, let's make sure to reset any previous views to be first
+                // and remeasure it.
+                if (previousChild != null && previousChild.hasDifferentHeightWhenFirst()) {
+                    previousChild.setIsFirstInLayout(true);
+                    // We need to remeasure the previous child again since it became first
+                    measureChildWithMargins(previousView, widthMeasureSpec, 0, heightMeasureSpec,
+                            previousTotalHeight - previousChildHeight);
+                    // The totalHeight is already correct here since we only set it during the
+                    // first pass
+                }
                 break;
             }
             first = false;
@@ -255,11 +292,11 @@
         mMaxDisplayedLines = numberLines;
     }
 
-    public void setMessagingLayout(MessagingLayout layout) {
+    public void setMessagingLayout(IMessagingLayout layout) {
         mMessagingLayout = layout;
     }
 
-    public MessagingLayout getMessagingLayout() {
+    public IMessagingLayout getMessagingLayout() {
         return mMessagingLayout;
     }
 
@@ -273,6 +310,20 @@
         void setMaxDisplayedLines(int lines);
         void hideAnimated();
         boolean isHidingAnimated();
+
+        /**
+         * Set that this view is first in layout. Relevant and only set if
+         * {@link #hasDifferentHeightWhenFirst()}.
+         * @param first is this first?
+         */
+        default void setIsFirstInLayout(boolean first) {}
+
+        /**
+         * @return if this layout has different height it is first in the layout
+         */
+        default boolean hasDifferentHeightWhenFirst() {
+            return false;
+        }
         default int getExtraSpacing() {
             return 0;
         }
diff --git a/core/java/com/android/internal/widget/MessagingMessage.java b/core/java/com/android/internal/widget/MessagingMessage.java
index c32d370..8c84379 100644
--- a/core/java/com/android/internal/widget/MessagingMessage.java
+++ b/core/java/com/android/internal/widget/MessagingMessage.java
@@ -32,7 +32,7 @@
      **/
     String IMAGE_MIME_TYPE_PREFIX = "image/";
 
-    static MessagingMessage createMessage(MessagingLayout layout,
+    static MessagingMessage createMessage(IMessagingLayout layout,
             Notification.MessagingStyle.Message m, ImageResolver resolver) {
         if (hasImage(m) && !ActivityManager.isLowRamDeviceStatic()) {
             return MessagingImageMessage.createMessage(layout, m, resolver);
diff --git a/core/java/com/android/internal/widget/MessagingTextMessage.java b/core/java/com/android/internal/widget/MessagingTextMessage.java
index 4081a86..d778c59 100644
--- a/core/java/com/android/internal/widget/MessagingTextMessage.java
+++ b/core/java/com/android/internal/widget/MessagingTextMessage.java
@@ -26,14 +26,10 @@
 import android.util.AttributeSet;
 import android.util.Pools;
 import android.view.LayoutInflater;
-import android.view.ViewGroup;
-import android.view.ViewParent;
 import android.widget.RemoteViews;
 
 import com.android.internal.R;
 
-import java.util.Objects;
-
 /**
  * A message of a {@link MessagingLayout}.
  */
@@ -74,7 +70,7 @@
         return true;
     }
 
-    static MessagingMessage createMessage(MessagingLayout layout,
+    static MessagingMessage createMessage(IMessagingLayout layout,
             Notification.MessagingStyle.Message m) {
         MessagingLinearLayout messagingLinearLayout = layout.getMessagingLinearLayout();
         MessagingTextMessage createdMessage = sInstancePool.acquire();
diff --git a/core/java/com/android/internal/widget/NotificationExpandButton.java b/core/java/com/android/internal/widget/NotificationExpandButton.java
index 39f82a5..a499806 100644
--- a/core/java/com/android/internal/widget/NotificationExpandButton.java
+++ b/core/java/com/android/internal/widget/NotificationExpandButton.java
@@ -20,7 +20,7 @@
 import android.content.Context;
 import android.graphics.Rect;
 import android.util.AttributeSet;
-import android.view.View;
+import android.view.RemotableViewMethod;
 import android.view.accessibility.AccessibilityNodeInfo;
 import android.widget.Button;
 import android.widget.ImageView;
@@ -32,6 +32,8 @@
 @RemoteViews.RemoteView
 public class NotificationExpandButton extends ImageView {
 
+    private int mOriginalNotificationColor;
+
     public NotificationExpandButton(Context context) {
         super(context);
     }
@@ -56,6 +58,15 @@
         extendRectToMinTouchSize(outRect);
     }
 
+    @RemotableViewMethod
+    public void setOriginalNotificationColor(int color) {
+        mOriginalNotificationColor = color;
+    }
+
+    public int getOriginalNotificationColor() {
+        return mOriginalNotificationColor;
+    }
+
     private void extendRectToMinTouchSize(Rect rect) {
         int touchTargetSize = (int) (getResources().getDisplayMetrics().density * 48);
         rect.left = rect.centerX() - touchTargetSize / 2;
diff --git a/core/java/com/android/internal/widget/RemeasuringLinearLayout.java b/core/java/com/android/internal/widget/RemeasuringLinearLayout.java
index e352b45..7b154a5 100644
--- a/core/java/com/android/internal/widget/RemeasuringLinearLayout.java
+++ b/core/java/com/android/internal/widget/RemeasuringLinearLayout.java
@@ -23,6 +23,8 @@
 import android.widget.LinearLayout;
 import android.widget.RemoteViews;
 
+import java.util.ArrayList;
+
 /**
  * A LinearLayout that sets it's height again after the last measure pass. This is needed for
  * MessagingLayouts where groups need to be able to snap it's height to.
@@ -30,6 +32,8 @@
 @RemoteViews.RemoteView
 public class RemeasuringLinearLayout extends LinearLayout {
 
+    private ArrayList<View> mMatchParentViews = new ArrayList<>();
+
     public RemeasuringLinearLayout(Context context) {
         super(context);
     }
@@ -53,6 +57,8 @@
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
         int count = getChildCount();
         int height = 0;
+        boolean isVertical = getOrientation() == LinearLayout.VERTICAL;
+        boolean isWrapContent = getLayoutParams().height == LayoutParams.WRAP_CONTENT;
         for (int i = 0; i < count; ++i) {
             final View child = getChildAt(i);
             if (child == null || child.getVisibility() == View.GONE) {
@@ -60,9 +66,25 @@
             }
 
             final LayoutParams lp = (LayoutParams) child.getLayoutParams();
-            height = Math.max(height, height + child.getMeasuredHeight() + lp.topMargin +
-                    lp.bottomMargin);
+            if (!isWrapContent || lp.height != LayoutParams.MATCH_PARENT || isVertical) {
+                int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
+                height = Math.max(height, isVertical ? height + childHeight : childHeight);
+            } else {
+                // We have match parent children in a wrap content view, let's measure the
+                // view properly
+                mMatchParentViews.add(child);
+            }
         }
+        if (mMatchParentViews.size() > 0) {
+            int exactHeightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
+            for (View child : mMatchParentViews) {
+                child.measure(getChildMeasureSpec(
+                        widthMeasureSpec, getPaddingStart() + getPaddingEnd(),
+                        child.getLayoutParams().width),
+                        exactHeightSpec);
+            }
+        }
+        mMatchParentViews.clear();
         setMeasuredDimension(getMeasuredWidth(), height);
     }
 }
diff --git a/core/jni/com_android_internal_os_Zygote.cpp b/core/jni/com_android_internal_os_Zygote.cpp
index f9885e2..dafb377 100644
--- a/core/jni/com_android_internal_os_Zygote.cpp
+++ b/core/jni/com_android_internal_os_Zygote.cpp
@@ -121,16 +121,11 @@
 static pid_t gSystemServerPid = 0;
 
 static constexpr const char* kPropFuse = "persist.sys.fuse";
-static constexpr const char* kZygoteClassName = "com/android/internal/os/Zygote";
-
+static const char kZygoteClassName[] = "com/android/internal/os/Zygote";
 static jclass gZygoteClass;
 static jmethodID gCallPostForkSystemServerHooks;
 static jmethodID gCallPostForkChildHooks;
 
-static constexpr const char* kZygoteInitClassName = "com/android/internal/os/ZygoteInit";
-static jclass gZygoteInitClass;
-static jmethodID gCreateSystemServerClassLoader;
-
 static bool gIsSecurityEnforced = true;
 
 /**
@@ -1796,15 +1791,6 @@
       fail_fn("Error calling post fork system server hooks.");
     }
 
-    // Prefetch the classloader for the system server. This is done early to
-    // allow a tie-down of the proper system server selinux domain.
-    env->CallStaticVoidMethod(gZygoteInitClass, gCreateSystemServerClassLoader);
-    if (env->ExceptionCheck()) {
-      // Be robust here. The Java code will attempt to create the classloader
-      // at a later point (but may not have rights to use AoT artifacts).
-      env->ExceptionClear();
-    }
-
     // TODO(oth): Remove hardcoded label here (b/117874058).
     static const char* kSystemServerLabel = "u:r:system_server:s0";
     if (selinux_android_setcon(kSystemServerLabel) != 0) {
@@ -2482,13 +2468,6 @@
   gCallPostForkChildHooks = GetStaticMethodIDOrDie(env, gZygoteClass, "callPostForkChildHooks",
                                                    "(IZZLjava/lang/String;)V");
 
-  gZygoteInitClass = MakeGlobalRefOrDie(env, FindClassOrDie(env, kZygoteInitClassName));
-  gCreateSystemServerClassLoader = GetStaticMethodIDOrDie(env, gZygoteInitClass,
-                                                          "createSystemServerClassLoader",
-                                                          "()V");
-
-  RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods));
-
-  return JNI_OK;
+  return RegisterMethodsOrDie(env, "com/android/internal/os/Zygote", gMethods, NELEM(gMethods));
 }
 }  // namespace android
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 071bb11..4001def 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -5003,15 +5003,15 @@
     <permission android:name="android.permission.ACCESS_LOCUS_ID_USAGE_STATS"
                 android:protectionLevel="signature|appPredictor" />
 
-    <!-- Feature Id for Country Detector. -->
-    <feature android:featureId="CountryDetector" android:label="@string/country_detector"/>
-    <!-- Feature Id for Location service. -->
-    <feature android:featureId="LocationService" android:label="@string/location_service"/>
-    <!-- Feature Id for Sensor Notification service. -->
-    <feature android:featureId="SensorNotificationService"
+    <!-- Attribution for Country Detector. -->
+    <attribution android:tag="CountryDetector" android:label="@string/country_detector"/>
+    <!-- Attribution for Location service. -->
+    <attribution android:tag="LocationService" android:label="@string/location_service"/>
+    <!-- Attribution for Sensor Notification service. -->
+    <attribution android:tag="SensorNotificationService"
              android:label="@string/sensor_notification_service"/>
     <!-- Feature Id for Twilight service. -->
-    <feature android:featureId="TwilightService" android:label="@string/twilight_service"/>
+    <attribution android:tag="TwilightService" android:label="@string/twilight_service"/>
 
     <application android:process="system"
                  android:persistent="true"
diff --git a/core/res/res/drawable/conversation_badge_background.xml b/core/res/res/drawable/conversation_badge_background.xml
new file mode 100644
index 0000000..0dd0dcd
--- /dev/null
+++ b/core/res/res/drawable/conversation_badge_background.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 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
+  -->
+
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="oval">
+
+    <solid
+        android:color="#ffffff"/>
+
+    <size
+        android:width="26dp"
+        android:height="26dp"/>
+</shape>
+
diff --git a/core/res/res/drawable/ic_collapse_notification.xml b/core/res/res/drawable/ic_collapse_notification.xml
index 124e99e..ca4f0ed 100644
--- a/core/res/res/drawable/ic_collapse_notification.xml
+++ b/core/res/res/drawable/ic_collapse_notification.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-Copyright (C) 2015 The Android Open Source Project
+Copyright (C) 2020 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.
@@ -15,11 +15,14 @@
     limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:width="14.0dp"
-        android:height="14.0dp"
-        android:viewportWidth="24.0"
-        android:viewportHeight="24.0">
+    android:width="22.0dp"
+    android:height="22.0dp"
+    android:viewportWidth="24.0"
+    android:viewportHeight="24.0">
     <path
         android:fillColor="#FF000000"
-        android:pathData="M12.0,8.0l-6.0,6.0l1.4,1.4l4.6,-4.6l4.6,4.6L18.0,14.0L12.0,8.0z"/>
-</vector>
+        android:pathData="M18.59,16.41L20.0,15.0l-8.0,-8.0 -8.0,8.0 1.41,1.41L12.0,9.83"/>
+    <path
+        android:pathData="M0 0h24v24H0V0z"
+        android:fillColor="#00000000"/>
+</vector>
\ No newline at end of file
diff --git a/core/res/res/drawable/ic_expand_notification.xml b/core/res/res/drawable/ic_expand_notification.xml
index 847e326..a080ce4 100644
--- a/core/res/res/drawable/ic_expand_notification.xml
+++ b/core/res/res/drawable/ic_expand_notification.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
-Copyright (C) 2015 The Android Open Source Project
+Copyright (C) 2014 The Android Open Source Project
 
    Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
@@ -15,11 +15,14 @@
     limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-        android:width="14.0dp"
-        android:height="14.0dp"
-        android:viewportWidth="24.0"
-        android:viewportHeight="24.0">
+    android:width="22.0dp"
+    android:height="22.0dp"
+    android:viewportWidth="24.0"
+    android:viewportHeight="24.0">
     <path
         android:fillColor="#FF000000"
-        android:pathData="M16.6,8.6L12.0,13.2L7.4,8.6L6.0,10.0l6.0,6.0l6.0,-6.0L16.6,8.6z"/>
-</vector>
+        android:pathData="M5.41,7.59L4.0,9.0l8.0,8.0 8.0,-8.0 -1.41,-1.41L12.0,14.17"/>
+    <path
+        android:pathData="M24 24H0V0h24v24z"
+        android:fillColor="#00000000"/>
+</vector>
\ No newline at end of file
diff --git a/core/res/res/layout/conversation_face_pile_layout.xml b/core/res/res/layout/conversation_face_pile_layout.xml
new file mode 100644
index 0000000..1db3870
--- /dev/null
+++ b/core/res/res/layout/conversation_face_pile_layout.xml
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 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
+  -->
+<FrameLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/conversation_face_pile"
+    android:layout_width="@dimen/conversation_avatar_size"
+    android:layout_height="@dimen/conversation_avatar_size"
+    android:forceHasOverlappingRendering="false"
+    >
+    <ImageView
+        android:id="@+id/conversation_face_pile_top"
+        android:layout_width="36dp"
+        android:layout_height="36dp"
+        android:scaleType="centerCrop"
+        android:layout_gravity="end|top"
+        />
+    <FrameLayout
+        android:id="@+id/conversation_face_pile_bottom_background"
+        android:layout_width="40dp"
+        android:layout_height="40dp"
+        android:layout_gravity="start|bottom"
+        android:background="@drawable/conversation_badge_background">
+        <ImageView
+            android:id="@+id/conversation_face_pile_bottom"
+            android:layout_width="36dp"
+            android:layout_height="36dp"
+            android:scaleType="centerCrop"
+            android:layout_gravity="center"
+            />
+    </FrameLayout>
+</FrameLayout>
diff --git a/core/res/res/layout/notification_template_header.xml b/core/res/res/layout/notification_template_header.xml
index f5fa1b6a..6f36aae 100644
--- a/core/res/res/layout/notification_template_header.xml
+++ b/core/res/res/layout/notification_template_header.xml
@@ -91,7 +91,6 @@
         android:textAppearance="@style/TextAppearance.Material.Notification.Time"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_gravity="center"
         android:layout_marginStart="@dimen/notification_header_separating_margin"
         android:layout_marginEnd="@dimen/notification_header_separating_margin"
         android:showRelative="true"
diff --git a/core/res/res/layout/notification_template_material_conversation.xml b/core/res/res/layout/notification_template_material_conversation.xml
new file mode 100644
index 0000000..dc52e97
--- /dev/null
+++ b/core/res/res/layout/notification_template_material_conversation.xml
@@ -0,0 +1,205 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Copyright (C) 2020 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
+  -->
+<com.android.internal.widget.ConversationLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/status_bar_latest_event_content"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:clipChildren="false"
+    android:tag="conversation"
+    android:theme="@style/Theme.DeviceDefault.Notification"
+    >
+
+    <FrameLayout
+        android:layout_width="@dimen/conversation_content_start"
+        android:layout_height="wrap_content"
+        android:gravity="start|top"
+        android:clipChildren="false"
+        android:clipToPadding="false"
+        android:paddingTop="12dp"
+    >
+
+        <FrameLayout
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="top|center_horizontal"
+        >
+
+            <!-- Big icon: 52x52, 12dp padding left + top, 16dp padding right -->
+            <ImageView
+                android:id="@+id/conversation_icon"
+                android:layout_width="@dimen/conversation_avatar_size"
+                android:layout_height="@dimen/conversation_avatar_size"
+                android:scaleType="centerCrop"
+                android:importantForAccessibility="no"
+            />
+
+            <ViewStub
+                android:layout="@layout/conversation_face_pile_layout"
+                android:layout_width="@dimen/conversation_avatar_size"
+                android:layout_height="@dimen/conversation_avatar_size"
+                android:id="@+id/conversation_face_pile"
+                />
+
+            <FrameLayout
+                android:id="@+id/conversation_icon_badge"
+                android:layout_width="20dp"
+                android:layout_height="20dp"
+                android:layout_marginLeft="@dimen/conversation_badge_side_margin"
+                android:layout_marginTop="@dimen/conversation_badge_side_margin"
+                android:background="@drawable/conversation_badge_background" >
+                <!-- Badge: 20x20, 48dp padding left + top -->
+                <com.android.internal.widget.CachingIconView
+                    android:id="@+id/icon"
+                    android:layout_width="@dimen/conversation_icon_size_badged"
+                    android:layout_height="@dimen/conversation_icon_size_badged"
+                    android:layout_gravity="center"
+                />
+            </FrameLayout>
+        </FrameLayout>
+    </FrameLayout>
+
+    <!-- Wraps entire "expandable" notification -->
+    <com.android.internal.widget.RemeasuringLinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_gravity="top"
+        android:clipToPadding="false"
+        android:clipChildren="false"
+        android:orientation="vertical"
+        >
+        <!-- LinearLayout for Expand Button-->
+        <com.android.internal.widget.RemeasuringLinearLayout
+            android:id="@+id/expand_button_and_content_container"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_weight="1"
+            android:gravity="start|top"
+            android:orientation="horizontal"
+            android:clipChildren="false"
+            android:clipToPadding="false">
+            <!--TODO: move this into a separate layout and share logic with the header to bring back app opps etc-->
+            <FrameLayout
+                android:id="@+id/notification_action_list_margin_target"
+                android:layout_width="0dp"
+                android:layout_height="wrap_content"
+                android:layout_weight="1">
+
+                <!-- Header -->
+                <LinearLayout
+                    android:id="@+id/conversation_header"
+                    android:layout_width="wrap_content"
+                    android:layout_height="wrap_content"
+                    android:orientation="horizontal"
+                    android:paddingTop="16dp"
+                    android:paddingStart="@dimen/conversation_content_start"
+                >
+                    <TextView
+                        android:id="@+id/conversation_text"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_marginEnd="@dimen/notification_header_separating_margin"
+                        android:textAppearance="@style/TextAppearance.DeviceDefault.Notification.Title"
+                        android:textSize="16sp"
+                        android:singleLine="true"
+                        />
+
+                    <TextView
+                        android:id="@+id/time_divider"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:textAppearance="?attr/notificationHeaderTextAppearance"
+                        android:layout_marginStart="@dimen/notification_header_separating_margin"
+                        android:layout_marginEnd="@dimen/notification_header_separating_margin"
+                        android:text="@string/notification_header_divider_symbol"
+                        android:layout_gravity="center"
+                        android:paddingTop="1sp"
+                        android:singleLine="true"
+                        android:visibility="gone"
+                    />
+
+                    <DateTimeView
+                        android:id="@+id/time"
+                        android:textAppearance="@style/TextAppearance.Material.Notification.Time"
+                        android:layout_width="wrap_content"
+                        android:layout_height="wrap_content"
+                        android:layout_gravity="center"
+                        android:layout_marginStart="@dimen/notification_header_separating_margin"
+                        android:paddingTop="1sp"
+                        android:showRelative="true"
+                        android:singleLine="true"
+                        android:visibility="gone"
+                    />
+
+                    <ImageView
+                        android:id="@+id/profile_badge"
+                        android:layout_width="@dimen/notification_badge_size"
+                        android:layout_height="@dimen/notification_badge_size"
+                        android:layout_gravity="center"
+                        android:layout_marginStart="4dp"
+                        android:paddingTop="2dp"
+                        android:scaleType="fitCenter"
+                        android:visibility="gone"
+                        android:contentDescription="@string/notification_work_profile_content_description"
+                    />
+                </LinearLayout>
+
+                <!-- Messages -->
+                <com.android.internal.widget.MessagingLinearLayout
+                    android:id="@+id/notification_messaging"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:layout_marginTop="40dp"
+                    android:spacing="@dimen/notification_messaging_spacing"
+                    android:clipToPadding="false"
+                    android:clipChildren="false"
+                    />
+            </FrameLayout>
+            <!-- Unread Count -->
+            <!-- <TextView /> -->
+
+            <!-- This is where the expand button will be placed when collapsed-->
+        </com.android.internal.widget.RemeasuringLinearLayout>
+
+        <include layout="@layout/notification_template_smart_reply_container"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginTop="@dimen/notification_content_margin"
+            android:layout_marginStart="@dimen/conversation_content_start"
+            android:layout_marginEnd="@dimen/notification_content_margin_end" />
+        <include layout="@layout/notification_material_action_list" />
+    </com.android.internal.widget.RemeasuringLinearLayout>
+
+    <!--This is dynamically placed between here and at the end of the layout-->
+    <FrameLayout
+        android:id="@+id/expand_button_container"
+        android:layout_width="wrap_content"
+        android:layout_height="@dimen/conversation_expand_button_expanded_size"
+        android:layout_gravity="end|top"
+        android:paddingStart="16dp"
+        android:paddingEnd="@dimen/notification_content_margin_end">
+        <com.android.internal.widget.NotificationExpandButton
+            android:id="@+id/expand_button"
+            android:layout_width="@dimen/notification_header_expand_icon_size"
+            android:layout_height="@dimen/notification_header_expand_icon_size"
+            android:layout_gravity="center"
+            android:drawable="@drawable/ic_expand_notification"
+            android:clickable="false"
+            android:importantForAccessibility="no"
+            />
+    </FrameLayout>
+</com.android.internal.widget.ConversationLayout>
diff --git a/core/res/res/layout/notification_template_messaging_group.xml b/core/res/res/layout/notification_template_messaging_group.xml
index 483b479..15146c0 100644
--- a/core/res/res/layout/notification_template_messaging_group.xml
+++ b/core/res/res/layout/notification_template_messaging_group.xml
@@ -20,14 +20,19 @@
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:orientation="horizontal" >
-    <ImageView
-        android:id="@+id/message_icon"
-        android:layout_width="@dimen/messaging_avatar_size"
-        android:layout_height="@dimen/messaging_avatar_size"
-        android:layout_marginEnd="12dp"
-        android:scaleType="centerCrop"
-        android:importantForAccessibility="no" />
+    <FrameLayout
+        android:layout_width="@dimen/conversation_content_start"
+        android:layout_height="wrap_content">         <!--TODO: make sure to make this padding dynamic-->
+        <ImageView
+            android:layout_gravity="top|center_horizontal"
+            android:id="@+id/message_icon"
+            android:layout_width="@dimen/messaging_avatar_size"
+            android:layout_height="@dimen/messaging_avatar_size"
+            android:scaleType="centerCrop"
+            android:importantForAccessibility="no" />
+    </FrameLayout>
     <com.android.internal.widget.RemeasuringLinearLayout
+        android:id="@+id/messaging_group_content_container"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_weight="1"
@@ -43,7 +48,7 @@
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:layout_marginTop="@dimen/notification_text_margin_top"
-            android:spacing="2dp"/>
+            android:spacing="2dp" />
     </com.android.internal.widget.RemeasuringLinearLayout>
     <FrameLayout
         android:id="@+id/messaging_group_icon_container"
diff --git a/core/res/res/values/attrs_manifest.xml b/core/res/res/values/attrs_manifest.xml
index ba939ea..f3ca5ac 100644
--- a/core/res/res/values/attrs_manifest.xml
+++ b/core/res/res/values/attrs_manifest.xml
@@ -1574,7 +1574,7 @@
          <code>com.google.app.<em>appname</em></code>
 
          <p>Inside of the manifest tag, may appear the following tags
-         in any order: {@link #AndroidManifestFeature feature},
+         in any order: {@link #AndroidManifestAttribution attribution},
          {@link #AndroidManifestPermission permission},
          {@link #AndroidManifestPermissionGroup permission-group},
          {@link #AndroidManifestPermissionTree permission-tree},
@@ -1831,31 +1831,48 @@
 
         <attr name="enableGwpAsan" />
 
+        <!-- If {@code true} allow requesting that its permissions don't get automatically
+             revoked when the app is unused for an extended amount of time.
+
+             The default value is {@code false}. -->
+        <attr name="requestDontAutoRevokePermissions" format="boolean" />
+
+        <!-- If {@code true} its permissions shouldn't get automatically
+             revoked when the app is unused for an extended amount of time.
+
+             This implies {@code requestDontAutoRevokePermissions=true}
+
+             The default value is {@code false}. -->
+        <attr name="allowDontAutoRevokePermissions" format="boolean" />
     </declare-styleable>
 
-    <!-- The <code>feature</code> tag declares a feature. A feature is a logical part of an app.
-    E.g. photo sharing app might include a direct messaging component. To tag certain code as
-    belonging to a feature, use a context created via
-    {@link android.content.Context#createFeatureContext(String)} for any interaction with the
+    <!-- An attribution is a logical part of an app and is identified by a tag.
+    E.g. a photo sharing app might include a direct messaging component. To tag certain code as
+    belonging to an attribution, use a context created via
+    {@link android.content.Context#createAttributionContext(String)} for any interaction with the
     system.
 
     <p>This appears as a child tag of the root {@link #AndroidManifest manifest} tag.
 
-    <p>In case this feature inherits from another feature, this tag can contain one or multiple
-    {@link #AndroidManifestFeatureInheritFrom inherit-from} tags. -->
-    <declare-styleable name="AndroidManifestFeature" parent="AndroidManifest">
-        <!-- Required identifier for a feature. Can be passed to
-        {@link android.content.Context#createFeatureContext} to create a context for this feature
-        -->
+    <p>In case this attribution inherits from another attribution, this tag can contain one or
+    multiple {@link #AndroidManifestAttributionInheritFrom inherit-from} tags. -->
+    <declare-styleable name="AndroidManifestAttribution" parent="AndroidManifest">
+        <!-- TODO moltmann: Remove -->
         <attr name="featureId" format="string" />
-        <!-- Required user visible label for a feature. -->
+        <!-- Required identifier for a attribution. Can be passed to
+        {@link android.content.Context#createAttributionContext} to create a context tagged with
+        this attribution
+        -->
+        <attr name="tag" format="string" />
+        <!-- Required user visible label for a attribution. -->
         <attr name="label" format="string" />
     </declare-styleable>
 
     <!-- Declares previously declared features this feature inherits from. -->
-    <declare-styleable name="AndroidManifestFeatureInheritFrom" parent="AndroidManifestFeature">
-        <!-- Identifier of the feature this feature inherits from -->
-        <attr name="featureId" format="string" />
+    <declare-styleable name="AndroidManifestAttributionInheritFrom"
+                       parent="AndroidManifestAttribution">
+        <!-- Identifier of the attribution this attribution inherits from -->
+        <attr name="tag" format="string" />
     </declare-styleable>
 
     <!-- The <code>permission</code> tag declares a security permission that can be
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index 2faa0c9..e3fe982 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -682,7 +682,25 @@
     <!-- The size of the right icon image when on low ram -->
     <dimen name="notification_right_icon_size_low_ram">@dimen/notification_right_icon_size</dimen>
 
-    <dimen name="messaging_avatar_size">52dp</dimen>
+    <dimen name="messaging_avatar_size">@dimen/notification_right_icon_size</dimen>
+    <dimen name="conversation_avatar_size">52dp</dimen>
+    <!-- Start of the content in the conversation template -->
+    <dimen name="conversation_content_start">80dp</dimen>
+    <!-- Size of the expand button when expanded -->
+    <dimen name="conversation_expand_button_expanded_size">80dp</dimen>
+    <!-- Top margin of the expand button for conversations when expanded -->
+    <dimen name="conversation_expand_button_top_margin_expanded">18dp</dimen>
+    <!-- Side margins of the conversation badge in relation to the conversation icon -->
+    <dimen name="conversation_badge_side_margin">36dp</dimen>
+    <!-- size of the notification icon when badged in a conversation -->
+    <dimen name="conversation_icon_size_badged">15dp</dimen>
+    <!-- size of the notification icon when centered in a conversation -->
+    <dimen name="conversation_icon_size_centered">20dp</dimen>
+    <!-- margin on the top when the icon is centered for group conversations -->
+    <dimen name="conversation_icon_margin_top_centered">5dp</dimen>
+
+    <!-- Padding between text and sender when singleline -->
+    <dimen name="messaging_group_singleline_sender_padding_end">4dp</dimen>
 
     <dimen name="messaging_group_sending_progress_size">24dp</dimen>
 
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index a823e52..7230cc4 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -3004,6 +3004,7 @@
       <public name="animatedImageDrawable"/>
       <public name="htmlDescription"/>
       <public name="preferMinimalPostProcessing"/>
+      <!-- @removed -->
       <public name="featureId" />
       <public name="supportsInlineSuggestions" />
       <public name="crossProfile" />
@@ -3013,6 +3014,8 @@
       <!-- @hide @SystemApi -->
       <public name="minExtensionVersion" />
       <public name="allowNativeHeapPointerTagging" />
+      <public name="requestDontAutoRevokePermissions" />
+      <public name="allowDontAutoRevokePermissions" />
       <public name="preserveLegacyExternalStorage" />
       <public name="mimeGroup" />
       <public name="enableGwpAsan" />
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 789628d..f101f59 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -5440,6 +5440,15 @@
     <string name="as_app_forced_to_restricted_bucket">
         <xliff:g id="package_name" example="com.android.example">%1$s</xliff:g> has been put into the RESTRICTED bucket</string>
 
+    <!-- The way a conversation name is displayed when single line. The text will be displayed to the end of this text with some spacing -->
+    <string name="conversation_single_line_name_display"><xliff:g id="sender_name" example="Sara">%1$s</xliff:g>:</string>
+
+    <!-- Conversation Title fallback if the there is no name provided in a 1:1 conversation [CHAR LIMIT=40]-->
+    <string name="conversation_title_fallback_one_to_one">Conversation</string>
+
+    <!-- Conversation Title fallback if the there is no name provided in a group chat conversation [CHAR LIMIT=40]-->
+    <string name="conversation_title_fallback_group_chat">Group Conversation</string>
+
     <!-- ResolverActivity - profile tabs -->
     <!-- Label of a tab on a screen. A user can tap this tap to switch to the 'Personal' view (that shows their personal content) if they have a work profile on their device. [CHAR LIMIT=NONE] -->
     <string name="resolver_personal_tab">Personal</string>
diff --git a/core/res/res/values/styles_device_defaults.xml b/core/res/res/values/styles_device_defaults.xml
index 966f495..64768cf 100644
--- a/core/res/res/values/styles_device_defaults.xml
+++ b/core/res/res/values/styles_device_defaults.xml
@@ -146,7 +146,7 @@
         <item name="textAppearance">@style/TextAppearance.DeviceDefault.Notification</item>
     </style>
     <style name="Widget.DeviceDefault.Notification.MessagingName" parent="Widget.Material.Notification.MessagingName">
-        <item name="textAppearance">@style/TextAppearance.DeviceDefault.Notification.MessagingName</item>
+        <item name="textAppearance">@style/TextAppearance.DeviceDefault.Notification.Title</item>
     </style>
     <style name="Widget.DeviceDefault.PreferenceFrameLayout" parent="Widget.Material.PreferenceFrameLayout"/>
     <style name="Widget.DeviceDefault.ProgressBar.Inverse" parent="Widget.Material.ProgressBar.Inverse"/>
@@ -290,9 +290,6 @@
     <style name="TextAppearance.DeviceDefault.Notification.Title" parent="TextAppearance.Material.Notification.Title">
         <item name="fontFamily">@string/config_headlineFontFamilyMedium</item>
     </style>
-    <style name="TextAppearance.DeviceDefault.Notification.MessagingName" parent="TextAppearance.DeviceDefault.Notification.Title">
-        <item name="textSize">16sp</item>
-    </style>
     <style name="TextAppearance.DeviceDefault.Notification.Reply" parent="TextAppearance.Material.Notification.Reply">
         <item name="fontFamily">@string/config_bodyFontFamily</item>
     </style>
diff --git a/core/res/res/values/styles_material.xml b/core/res/res/values/styles_material.xml
index 63ac0e6..2415837 100644
--- a/core/res/res/values/styles_material.xml
+++ b/core/res/res/values/styles_material.xml
@@ -504,7 +504,7 @@
     <style name="Widget.Material.Notification.MessagingText" parent="Widget.Material.Notification.Text">
         <item name="layout_width">wrap_content</item>
         <item name="layout_height">wrap_content</item>
-        <item name="ellipsize">end</item>z
+        <item name="ellipsize">end</item>
     </style>
 
     <style name="Widget.Material.Notification.MessagingName" parent="Widget.Material.Light.TextView">
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index a9008d7..49a0f17 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -3876,6 +3876,30 @@
   <java-symbol type="array" name="config_defaultImperceptibleKillingExemptionPkgs" />
   <java-symbol type="array" name="config_defaultImperceptibleKillingExemptionProcStates" />
 
+  <java-symbol type="string" name="conversation_single_line_name_display" />
+  <java-symbol type="string" name="conversation_title_fallback_one_to_one" />
+  <java-symbol type="string" name="conversation_title_fallback_group_chat" />
+  <java-symbol type="id" name="conversation_icon" />
+  <java-symbol type="id" name="conversation_icon_badge" />
+  <java-symbol type="id" name="expand_button_container" />
+  <java-symbol type="id" name="messaging_group_content_container" />
+  <java-symbol type="id" name="expand_button_and_content_container" />
+  <java-symbol type="id" name="conversation_header" />
+  <java-symbol type="id" name="conversation_face_pile_bottom_background" />
+  <java-symbol type="id" name="conversation_face_pile_bottom" />
+  <java-symbol type="id" name="conversation_face_pile_top" />
+  <java-symbol type="id" name="conversation_face_pile" />
+  <java-symbol type="id" name="conversation_text" />
+  <java-symbol type="dimen" name="conversation_expand_button_top_margin_expanded" />
+  <java-symbol type="dimen" name="conversation_expand_button_expanded_size" />
+  <java-symbol type="dimen" name="messaging_group_singleline_sender_padding_end" />
+  <java-symbol type="dimen" name="conversation_badge_side_margin" />
+  <java-symbol type="dimen" name="conversation_icon_size_badged" />
+  <java-symbol type="dimen" name="conversation_icon_size_centered" />
+  <java-symbol type="dimen" name="conversation_icon_margin_top_centered" />
+  <java-symbol type="layout" name="notification_template_material_conversation" />
+  <java-symbol type="layout" name="conversation_face_pile_layout" />
+
   <!-- Intent resolver and share sheet -->
   <java-symbol type="color" name="resolver_tabs_active_color" />
   <java-symbol type="color" name="resolver_tabs_inactive_color" />
diff --git a/core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java b/core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java
index 02a88fc..5ea0718 100644
--- a/core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java
+++ b/core/tests/coretests/src/android/view/contentcapture/ContentCaptureSessionTest.java
@@ -20,6 +20,7 @@
 
 import static org.testng.Assert.assertThrows;
 
+import android.graphics.Insets;
 import android.view.View;
 import android.view.ViewStructure;
 import android.view.autofill.AutofillId;
@@ -172,6 +173,11 @@
         }
 
         @Override
+        void internalNotifyViewInsetsChanged(Insets viewInsets) {
+            throw new UnsupportedOperationException("should not have been called");
+        }
+
+        @Override
         public void updateContentCaptureContext(ContentCaptureContext context) {
             throw new UnsupportedOperationException("should not have been called");
         }
diff --git a/core/tests/coretests/src/android/view/textclassifier/SystemTextClassifierMetadataTest.java b/core/tests/coretests/src/android/view/textclassifier/SystemTextClassifierMetadataTest.java
new file mode 100644
index 0000000..e4cfc53
--- /dev/null
+++ b/core/tests/coretests/src/android/view/textclassifier/SystemTextClassifierMetadataTest.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2020 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 android.os.Parcel;
+
+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 SystemTextClassifierMetadataTest {
+
+    @Test
+    public void testInvalidPackageNameThrowsException() {
+        assertThrows(NullPointerException.class,
+                () -> new SystemTextClassifierMetadata(/* packageName= */ null, /* userId= */
+                        1, /* useDefaultTextClassifier= */ false));
+    }
+
+    @Test
+    public void testParcel() {
+        SystemTextClassifierMetadata sysTcMetadata = new SystemTextClassifierMetadata(
+                "package", /* userId= */ 1, /* useDefaultTextClassifier= */ false);
+
+        Parcel p = Parcel.obtain();
+        sysTcMetadata.writeToParcel(p, 0);
+        p.setDataPosition(0);
+
+        SystemTextClassifierMetadata targetSysTcMetadata =
+                SystemTextClassifierMetadata.CREATOR.createFromParcel(p);
+
+        assertThat(targetSysTcMetadata.getUserId()).isEqualTo(sysTcMetadata.getUserId());
+        assertThat(targetSysTcMetadata.getCallingPackageName()).isEqualTo(
+                sysTcMetadata.getCallingPackageName());
+        assertThat(targetSysTcMetadata.useDefaultTextClassifier()).isEqualTo(
+                sysTcMetadata.useDefaultTextClassifier());
+    }
+}
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextClassificationTest.java b/core/tests/coretests/src/android/view/textclassifier/TextClassificationTest.java
index d544029..39ededa 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextClassificationTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextClassificationTest.java
@@ -17,6 +17,7 @@
 package android.view.textclassifier;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 
@@ -199,7 +200,9 @@
                         .setReferenceTime(referenceTime)
                         .setExtras(BUNDLE)
                         .build();
-        reference.setCallingPackageName(packageName);
+        final SystemTextClassifierMetadata systemTcMetadata =
+                new SystemTextClassifierMetadata(packageName, 1, false);
+        reference.setSystemTextClassifierMetadata(systemTcMetadata);
 
         // Parcel and unparcel.
         final Parcel parcel = Parcel.obtain();
@@ -216,5 +219,11 @@
         assertEquals(referenceTime, result.getReferenceTime());
         assertEquals(BUNDLE_VALUE, result.getExtras().getString(BUNDLE_KEY));
         assertEquals(packageName, result.getCallingPackageName());
+        final SystemTextClassifierMetadata resultSystemTcMetadata =
+                result.getSystemTextClassifierMetadata();
+        assertNotNull(resultSystemTcMetadata);
+        assertEquals(packageName, resultSystemTcMetadata.getCallingPackageName());
+        assertEquals(1, resultSystemTcMetadata.getUserId());
+        assertFalse(resultSystemTcMetadata.useDefaultTextClassifier());
     }
 }
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextLanguageTest.java b/core/tests/coretests/src/android/view/textclassifier/TextLanguageTest.java
index d0d32e3..31f8029 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextLanguageTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextLanguageTest.java
@@ -17,6 +17,8 @@
 package android.view.textclassifier;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 
 import android.icu.util.ULocale;
 import android.os.Bundle;
@@ -75,7 +77,9 @@
         final TextLanguage.Request reference = new TextLanguage.Request.Builder(text)
                 .setExtras(bundle)
                 .build();
-        reference.setCallingPackageName(packageName);
+        final SystemTextClassifierMetadata systemTcMetadata =
+                new SystemTextClassifierMetadata(packageName, 1, false);
+        reference.setSystemTextClassifierMetadata(systemTcMetadata);
 
         final Parcel parcel = Parcel.obtain();
         reference.writeToParcel(parcel, 0);
@@ -85,5 +89,11 @@
         assertEquals(text, result.getText());
         assertEquals("bundle", result.getExtras().getString(bundleKey));
         assertEquals(packageName, result.getCallingPackageName());
+        final SystemTextClassifierMetadata resultSystemTcMetadata =
+                result.getSystemTextClassifierMetadata();
+        assertNotNull(resultSystemTcMetadata);
+        assertEquals(packageName, resultSystemTcMetadata.getCallingPackageName());
+        assertEquals(1, resultSystemTcMetadata.getUserId());
+        assertFalse(resultSystemTcMetadata.useDefaultTextClassifier());
     }
 }
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextLinksTest.java b/core/tests/coretests/src/android/view/textclassifier/TextLinksTest.java
index ec5813f..4f0b44b 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextLinksTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextLinksTest.java
@@ -17,6 +17,8 @@
 package android.view.textclassifier;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 
 import android.os.Bundle;
 import android.os.LocaleList;
@@ -115,7 +117,9 @@
                 .setExtras(BUNDLE)
                 .setReferenceTime(referenceTime)
                 .build();
-        reference.setCallingPackageName(packageName);
+        final SystemTextClassifierMetadata systemTcMetadata =
+                new SystemTextClassifierMetadata(packageName, 1, false);
+        reference.setSystemTextClassifierMetadata(systemTcMetadata);
 
         // Parcel and unparcel.
         final Parcel parcel = Parcel.obtain();
@@ -132,5 +136,11 @@
         assertEquals(BUNDLE_VALUE, result.getExtras().getString(BUNDLE_KEY));
         assertEquals(packageName, result.getCallingPackageName());
         assertEquals(referenceTime, result.getReferenceTime());
+        final SystemTextClassifierMetadata resultSystemTcMetadata =
+                result.getSystemTextClassifierMetadata();
+        assertNotNull(resultSystemTcMetadata);
+        assertEquals(packageName, resultSystemTcMetadata.getCallingPackageName());
+        assertEquals(1, resultSystemTcMetadata.getUserId());
+        assertFalse(resultSystemTcMetadata.useDefaultTextClassifier());
     }
 }
diff --git a/core/tests/coretests/src/android/view/textclassifier/TextSelectionTest.java b/core/tests/coretests/src/android/view/textclassifier/TextSelectionTest.java
index 30cc4e8..82788c8 100644
--- a/core/tests/coretests/src/android/view/textclassifier/TextSelectionTest.java
+++ b/core/tests/coretests/src/android/view/textclassifier/TextSelectionTest.java
@@ -17,6 +17,8 @@
 package android.view.textclassifier;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
 
 import android.os.Bundle;
 import android.os.LocaleList;
@@ -82,7 +84,9 @@
                         .setDefaultLocales(new LocaleList(Locale.US, Locale.GERMANY))
                         .setExtras(BUNDLE)
                         .build();
-        reference.setCallingPackageName(packageName);
+        final SystemTextClassifierMetadata systemTcMetadata =
+                new SystemTextClassifierMetadata(packageName, 1, false);
+        reference.setSystemTextClassifierMetadata(systemTcMetadata);
 
         // Parcel and unparcel.
         final Parcel parcel = Parcel.obtain();
@@ -96,5 +100,11 @@
         assertEquals("en-US,de-DE", result.getDefaultLocales().toLanguageTags());
         assertEquals(BUNDLE_VALUE, result.getExtras().getString(BUNDLE_KEY));
         assertEquals(packageName, result.getCallingPackageName());
+        final SystemTextClassifierMetadata resultSystemTcMetadata =
+                result.getSystemTextClassifierMetadata();
+        assertNotNull(resultSystemTcMetadata);
+        assertEquals(packageName, resultSystemTcMetadata.getCallingPackageName());
+        assertEquals(1, resultSystemTcMetadata.getUserId());
+        assertFalse(resultSystemTcMetadata.useDefaultTextClassifier());
     }
 }
diff --git a/core/tests/coretests/src/com/android/internal/app/AbstractResolverComparatorTest.java b/core/tests/coretests/src/com/android/internal/app/AbstractResolverComparatorTest.java
index 36dd3e4..03ed68c 100644
--- a/core/tests/coretests/src/com/android/internal/app/AbstractResolverComparatorTest.java
+++ b/core/tests/coretests/src/com/android/internal/app/AbstractResolverComparatorTest.java
@@ -98,6 +98,11 @@
 
             @Override
             void handleResultMessage(Message message) {}
+
+            @Override
+            List<ComponentName> getTopComponentNames(int topK) {
+                return null;
+            }
         };
         return testComparator;
     }
diff --git a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java
index 24e96d4..a6cbc1a 100644
--- a/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java
+++ b/core/tests/coretests/src/com/android/internal/app/ChooserActivityTest.java
@@ -987,7 +987,8 @@
                                 /* resolveInfoPresentationGetter */ null),
                         serviceTargets,
                         TARGET_TYPE_CHOOSER_TARGET,
-                        directShareToShortcutInfos)
+                        directShareToShortcutInfos,
+                        null)
         );
 
         // Thread.sleep shouldn't be a thing in an integration test but it's
@@ -1058,7 +1059,8 @@
                                 /* resolveInfoPresentationGetter */ null),
                         serviceTargets,
                         TARGET_TYPE_CHOOSER_TARGET,
-                        directShareToShortcutInfos)
+                        directShareToShortcutInfos,
+                        null)
         );
         // Thread.sleep shouldn't be a thing in an integration test but it's
         // necessary here because of the way the code is structured
@@ -1145,7 +1147,8 @@
                                 /* resolveInfoPresentationGetter */ null),
                         serviceTargets,
                         TARGET_TYPE_CHOOSER_TARGET,
-                        directShareToShortcutInfos)
+                        directShareToShortcutInfos,
+                        null)
         );
         // Thread.sleep shouldn't be a thing in an integration test but it's
         // necessary here because of the way the code is structured
diff --git a/data/etc/car/com.google.android.car.kitchensink.xml b/data/etc/car/com.google.android.car.kitchensink.xml
index 61281ee..efe658a 100644
--- a/data/etc/car/com.google.android.car.kitchensink.xml
+++ b/data/etc/car/com.google.android.car.kitchensink.xml
@@ -33,6 +33,7 @@
         <permission name="android.permission.MODIFY_AUDIO_ROUTING"/>
         <permission name="android.permission.MODIFY_DAY_NIGHT_MODE"/>
         <permission name="android.permission.MODIFY_PHONE_STATE"/>
+        <permission name="android.permission.MONITOR_INPUT"/>
         <permission name="android.permission.PROVIDE_TRUST_AGENT"/>
         <permission name="android.permission.OVERRIDE_WIFI_CONFIG"/>
         <permission name="android.permission.REAL_GET_TASKS"/>
diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java
index 550e41f..ff7049e 100644
--- a/location/java/android/location/LocationManager.java
+++ b/location/java/android/location/LocationManager.java
@@ -612,7 +612,7 @@
     public Location getLastLocation() {
         try {
             return mService.getLastLocation(null, mContext.getPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -645,7 +645,7 @@
 
         try {
             return mService.getLastLocation(request, mContext.getPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -742,7 +742,7 @@
 
         try {
             if (mService.getCurrentLocation(currentLocationRequest, remoteCancellationSignal,
-                    listenerTransport, mContext.getPackageName(), mContext.getFeatureId(),
+                    listenerTransport, mContext.getPackageName(), mContext.getAttributionTag(),
                     getListenerIdentifier(consumer))) {
                 listenerTransport.register(mContext.getSystemService(AlarmManager.class),
                         remoteCancellationSignal);
@@ -1189,7 +1189,7 @@
             boolean registered = false;
             try {
                 mService.requestLocationUpdates(locationRequest, transport, null,
-                        mContext.getPackageName(), mContext.getFeatureId(),
+                        mContext.getPackageName(), mContext.getAttributionTag(),
                         getListenerIdentifier(listener));
                 registered = true;
             } catch (RemoteException e) {
@@ -1235,7 +1235,7 @@
 
         try {
             mService.requestLocationUpdates(locationRequest, null, pendingIntent,
-                    mContext.getPackageName(), mContext.getFeatureId(),
+                    mContext.getPackageName(), mContext.getAttributionTag(),
                     getListenerIdentifier(pendingIntent));
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
@@ -1711,7 +1711,7 @@
         LocationRequest request = new LocationRequest().setExpireIn(expiration);
         try {
             mService.requestGeofence(request, fence, intent, mContext.getPackageName(),
-                    mContext.getFeatureId(), getListenerIdentifier(intent));
+                    mContext.getAttributionTag(), getListenerIdentifier(intent));
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -1798,7 +1798,7 @@
 
         try {
             mService.requestGeofence(request, fence, intent, mContext.getPackageName(),
-                    mContext.getFeatureId(), getListenerIdentifier(intent));
+                    mContext.getAttributionTag(), getListenerIdentifier(intent));
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -2946,7 +2946,7 @@
 
             GnssStatusListener transport = new GnssStatusListener();
             if (mService.registerGnssStatusCallback(transport, mContext.getPackageName(),
-                    mContext.getFeatureId())) {
+                    mContext.getAttributionTag())) {
                 mListenerTransport = transport;
                 return true;
             } else {
@@ -3012,7 +3012,7 @@
 
             GnssMeasurementsListener transport = new GnssMeasurementsListener();
             if (mService.addGnssMeasurementsListener(request, transport, mContext.getPackageName(),
-                    mContext.getFeatureId(), "gnss measurement callback")) {
+                    mContext.getAttributionTag(), "gnss measurement callback")) {
                 mListenerTransport = transport;
                 return true;
             } else {
@@ -3065,7 +3065,7 @@
 
             GnssNavigationMessageListener transport = new GnssNavigationMessageListener();
             if (mService.addGnssNavigationMessageListener(transport, mContext.getPackageName(),
-                    mContext.getFeatureId(), "gnss navigation callback")) {
+                    mContext.getAttributionTag(), "gnss navigation callback")) {
                 mListenerTransport = transport;
                 return true;
             } else {
@@ -3106,7 +3106,7 @@
 
             GnssAntennaInfoListener transport = new GnssAntennaInfoListener();
             if (mService.addGnssAntennaInfoListener(transport, mContext.getPackageName(),
-                    mContext.getFeatureId(), "gnss antenna info callback")) {
+                    mContext.getAttributionTag(), "gnss antenna info callback")) {
                 mListenerTransport = transport;
                 return true;
             } else {
@@ -3143,7 +3143,7 @@
 
             BatchedLocationCallback transport = new BatchedLocationCallback();
             if (mService.addGnssBatchingCallback(transport, mContext.getPackageName(),
-                    mContext.getFeatureId(), "batched location callback")) {
+                    mContext.getAttributionTag(), "batched location callback")) {
                 mListenerTransport = transport;
                 return true;
             } else {
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
index 6354ccd..ebd7658 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraBinderTest.java
@@ -284,12 +284,12 @@
             ICameraDeviceCallbacks dummyCallbacks = new DummyCameraDeviceCallbacks();
 
             String clientPackageName = getContext().getPackageName();
-            String clientFeatureId = getContext().getFeatureId();
+            String clientAttributionTag = getContext().getAttributionTag();
 
             ICameraDeviceUser cameraUser =
                     mUtils.getCameraService().connectDevice(
                         dummyCallbacks, String.valueOf(cameraId),
-                        clientPackageName, clientFeatureId,
+                        clientPackageName, clientAttributionTag,
                         ICameraService.USE_CALLING_UID);
             assertNotNull(String.format("Camera %s was null", cameraId), cameraUser);
 
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
index 466c5f4..bf3e746 100644
--- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
+++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/integration/CameraDeviceBinderTest.java
@@ -238,12 +238,12 @@
         ICameraDeviceCallbacks.Stub dummyCallbacks = new DummyCameraDeviceCallbacks();
 
         String clientPackageName = getContext().getPackageName();
-        String clientFeatureId = getContext().getFeatureId();
+        String clientAttributionTag = getContext().getAttributionTag();
 
         mMockCb = spy(dummyCallbacks);
 
         mCameraUser = mUtils.getCameraService().connectDevice(mMockCb, mCameraId,
-                clientPackageName, clientFeatureId, ICameraService.USE_CALLING_UID);
+                clientPackageName, clientAttributionTag, ICameraService.USE_CALLING_UID);
         assertNotNull(String.format("Camera %s was null", mCameraId), mCameraUser);
         mHandlerThread = new HandlerThread(TAG);
         mHandlerThread.start();
diff --git a/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java b/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java
index f93faeb..ace50f3 100644
--- a/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java
+++ b/packages/SettingsLib/Tile/src/com/android/settingslib/drawer/TileUtils.java
@@ -545,7 +545,7 @@
             bundle.putString(META_DATA_PREFERENCE_KEYHINT, key);
         }
         try {
-            return provider.call(context.getPackageName(), context.getFeatureId(),
+            return provider.call(context.getPackageName(), context.getAttributionTag(),
                     uri.getAuthority(), method, uri.toString(), bundle);
         } catch (RemoteException e) {
             return null;
diff --git a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java
index 90f55dd6..4a0d16c 100644
--- a/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java
+++ b/packages/SettingsLib/src/com/android/settingslib/media/LocalMediaManager.java
@@ -108,14 +108,12 @@
                 new InfoMediaManager(context, packageName, notification, mLocalBluetoothManager);
     }
 
-    @VisibleForTesting
-    LocalMediaManager(Context context, LocalBluetoothManager localBluetoothManager,
+    public LocalMediaManager(Context context, LocalBluetoothManager localBluetoothManager,
             InfoMediaManager infoMediaManager, String packageName) {
         mContext = context;
         mLocalBluetoothManager = localBluetoothManager;
         mInfoMediaManager = infoMediaManager;
         mPackageName = packageName;
-
     }
 
     /**
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/location/RecentLocationAccessesTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/location/RecentLocationAccessesTest.java
index 68a3729..245b7843 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/location/RecentLocationAccessesTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/location/RecentLocationAccessesTest.java
@@ -8,7 +8,6 @@
 
 import android.app.AppOpsManager;
 import android.app.AppOpsManager.OpEntry;
-import android.app.AppOpsManager.OpFeatureEntry;
 import android.app.AppOpsManager.PackageOps;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
@@ -163,6 +162,6 @@
             AppOpsManager.OP_FLAG_SELF), new AppOpsManager.NoteOpEvent(time, -1, null));
 
         return new OpEntry(op, AppOpsManager.MODE_ALLOWED, Collections.singletonMap(null,
-                new OpFeatureEntry(op, false, accessEvents, null)));
+                new AppOpsManager.AttributedOpEntry(op, false, accessEvents, null)));
     }
 }
diff --git a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/location/RecentLocationAppsTest.java b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/location/RecentLocationAppsTest.java
index 3f8d758..cc9b931 100644
--- a/packages/SettingsLib/tests/robotests/src/com/android/settingslib/location/RecentLocationAppsTest.java
+++ b/packages/SettingsLib/tests/robotests/src/com/android/settingslib/location/RecentLocationAppsTest.java
@@ -7,7 +7,7 @@
 
 import android.app.AppOpsManager;
 import android.app.AppOpsManager.OpEntry;
-import android.app.AppOpsManager.OpFeatureEntry;
+import android.app.AppOpsManager.AttributedOpEntry;
 import android.app.AppOpsManager.PackageOps;
 import android.content.Context;
 import android.content.pm.ApplicationInfo;
@@ -18,8 +18,6 @@
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.util.LongSparseArray;
-import android.util.LongSparseLongArray;
-import android.util.Pair;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -164,6 +162,6 @@
                 AppOpsManager.OP_FLAG_SELF), new AppOpsManager.NoteOpEvent(time, duration, null));
 
         return new OpEntry(op, AppOpsManager.MODE_ALLOWED, Collections.singletonMap(null,
-                new OpFeatureEntry(op, false, accessEvents, null)));
+                new AttributedOpEntry(op, false, accessEvents, null)));
     }
 }
diff --git a/packages/SystemUI/res/color/control_background.xml b/packages/SystemUI/res/color/control_background.xml
deleted file mode 100644
index 977310c..0000000
--- a/packages/SystemUI/res/color/control_background.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-  <item android:state_enabled="false"
-        android:color="@color/control_default_background" />
-  <item android:color="@color/GM2_blue_200"
-        android:alpha="0.2" />
-</selector>
diff --git a/packages/SystemUI/res/color/light_background.xml b/packages/SystemUI/res/color/light_background.xml
deleted file mode 100644
index 1299464..0000000
--- a/packages/SystemUI/res/color/light_background.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-  <item android:state_enabled="false"
-        android:color="@color/control_default_background" />
-  <item android:color="@color/GM2_yellow_200"
-        android:alpha="0.2" />
-</selector>
diff --git a/packages/SystemUI/res/color/thermo_cool_background.xml b/packages/SystemUI/res/color/thermo_cool_background.xml
deleted file mode 100644
index 977310c..0000000
--- a/packages/SystemUI/res/color/thermo_cool_background.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-  <item android:state_enabled="false"
-        android:color="@color/control_default_background" />
-  <item android:color="@color/GM2_blue_200"
-        android:alpha="0.2" />
-</selector>
diff --git a/packages/SystemUI/res/color/thermo_heat_background.xml b/packages/SystemUI/res/color/thermo_heat_background.xml
deleted file mode 100644
index 2709ebe..0000000
--- a/packages/SystemUI/res/color/thermo_heat_background.xml
+++ /dev/null
@@ -1,7 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<selector xmlns:android="http://schemas.android.com/apk/res/android">
-  <item android:state_enabled="false"
-        android:color="@color/control_default_background" />
-  <item android:color="@color/GM2_red_200"
-        android:alpha="0.2" />
-</selector>
diff --git a/packages/SystemUI/res/drawable/ic_bubble_overflow_button.xml b/packages/SystemUI/res/drawable/ic_bubble_overflow_button.xml
index 64b57c5..3acebc1 100644
--- a/packages/SystemUI/res/drawable/ic_bubble_overflow_button.xml
+++ b/packages/SystemUI/res/drawable/ic_bubble_overflow_button.xml
@@ -14,10 +14,11 @@
 limitations under the License.
 -->
 <vector xmlns:android="http://schemas.android.com/apk/res/android"
-    android:viewportHeight="24"
-    android:viewportWidth="24"
-    android:height="52dp"
-    android:width="52dp">
-    <path android:fillColor="#1A73E8"
-          android:pathData="M6,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM18,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2zM12,10c-1.1,0 -2,0.9 -2,2s0.9,2 2,2 2,-0.9 2,-2 -0.9,-2 -2,-2z"/>
-</vector>
\ No newline at end of file
+  android:viewportWidth="24"
+  android:viewportHeight="24"
+  android:width="24dp"
+  android:height="24dp">
+  <path
+      android:fillColor="#1A73E8"
+      android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z"/>
+</vector>
diff --git a/packages/SystemUI/res/layout/controls_base_item.xml b/packages/SystemUI/res/layout/controls_base_item.xml
index 374e3b1..c58f572 100644
--- a/packages/SystemUI/res/layout/controls_base_item.xml
+++ b/packages/SystemUI/res/layout/controls_base_item.xml
@@ -21,8 +21,9 @@
     android:layout_weight="1"
     android:layout_height="@dimen/control_height"
     android:padding="@dimen/control_padding"
-    android:clickable="true"
+    android:clickable="false"
     android:focusable="true"
+    android:screenReaderFocusable="true"
     android:layout_marginLeft="@dimen/control_base_item_margin"
     android:layout_marginRight="@dimen/control_base_item_margin"
     android:background="@drawable/control_background">
@@ -32,6 +33,8 @@
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:paddingTop="@dimen/control_padding_adjustment"
+        android:clickable="false"
+        android:focusable="false"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintTop_toTopOf="parent" />
 
@@ -42,6 +45,8 @@
         android:textAppearance="@style/TextAppearance.Control.Status"
         android:paddingTop="@dimen/control_padding_adjustment"
         android:paddingStart="@dimen/control_status_padding"
+        android:clickable="false"
+        android:focusable="false"
         app:layout_constraintBottom_toBottomOf="@+id/icon"
         app:layout_constraintStart_toEndOf="@+id/icon" />
 
@@ -52,6 +57,8 @@
         android:textAppearance="@style/TextAppearance.Control.Status"
         android:paddingTop="@dimen/control_padding_adjustment"
         android:paddingStart="@dimen/control_status_padding"
+        android:clickable="false"
+        android:focusable="false"
         app:layout_constraintBottom_toBottomOf="@+id/icon"
         app:layout_constraintStart_toEndOf="@+id/status" />
 
@@ -62,6 +69,8 @@
         android:textAppearance="@style/TextAppearance.Control.Title"
         android:paddingLeft="@dimen/control_padding_adjustment"
         android:paddingRight="@dimen/control_padding_adjustment"
+        android:clickable="false"
+        android:focusable="false"
         app:layout_constraintBottom_toTopOf="@+id/subtitle"
         app:layout_constraintStart_toStartOf="parent" />
 
@@ -73,6 +82,8 @@
         android:paddingLeft="@dimen/control_padding_adjustment"
         android:paddingRight="@dimen/control_padding_adjustment"
         android:paddingBottom="@dimen/control_padding_adjustment"
+        android:clickable="false"
+        android:focusable="false"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintStart_toStartOf="parent"/>
 
diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml
index 80c1ac8..56e2b06 100644
--- a/packages/SystemUI/res/values/colors.xml
+++ b/packages/SystemUI/res/values/colors.xml
@@ -225,4 +225,8 @@
     <color name="control_default_background">@color/GM2_grey_900</color>
     <color name="control_list_popup_background">@*android:color/background_floating_material_dark</color>
     <color name="control_spinner_dropdown">@*android:color/foreground_material_dark</color>
+    <color name="control_enabled_light_background">@color/GM2_yellow_200</color>
+    <color name="control_enabled_thermo_heat_background">@color/GM2_red_200</color>
+    <color name="control_enabled_thermo_cool_background">@color/GM2_blue_200</color>
+    <color name="control_enabled_default_background">@color/GM2_blue_200</color>
 </resources>
diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml
index 20cafd0..c8b0d99 100644
--- a/packages/SystemUI/res/values/config.xml
+++ b/packages/SystemUI/res/values/config.xml
@@ -468,12 +468,18 @@
     <!-- On debuggable builds, alert the user if SystemUI PSS goes over this number (in kb) -->
     <integer name="watch_heap_limit">256000</integer>
 
+    <!-- Animation duration for resizing of PIP when entering/exiting. -->
+    <integer name="config_pipResizeAnimationDuration">425</integer>
+
     <!-- Allow dragging the PIP to a location to close it -->
     <bool name="config_pipEnableDismissDragToEdge">true</bool>
 
     <!-- Allow PIP to resize to a slightly bigger state upon touch/showing the menu -->
     <bool name="config_pipEnableResizeForMenu">true</bool>
 
+    <!-- Allow PIP to enable round corner, see also R.dimen.pip_corner_radius -->
+    <bool name="config_pipEnableRoundCorner">false</bool>
+
     <!-- SystemUI Plugins that can be loaded on user builds. -->
     <string-array name="config_pluginWhitelist" translatable="false">
         <item>com.android.systemui</item>
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 291db65..e45cbec 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -124,9 +124,6 @@
     <!-- Increased height of a collapsed media notification in the status bar -->
     <dimen name="notification_min_height_media">160dp</dimen>
 
-    <!-- Increased height of a collapsed messaging notification in the status bar -->
-    <dimen name="notification_min_height_messaging">118dp</dimen>
-
     <!-- Height of a small notification in the status bar which was used before android N -->
     <dimen name="notification_min_height_legacy">64dp</dimen>
 
@@ -1234,7 +1231,7 @@
     <dimen name="control_height">106dp</dimen>
     <dimen name="control_padding">12dp</dimen>
     <dimen name="control_padding_adjustment">4dp</dimen>
-    <dimen name="control_status_normal">12sp</dimen>
+    <dimen name="control_status_normal">14sp</dimen>
     <dimen name="control_status_expanded">18sp</dimen>
     <dimen name="control_base_item_margin">2dp</dimen>
     <dimen name="control_status_padding">3dp</dimen>
diff --git a/packages/SystemUI/res/values/styles.xml b/packages/SystemUI/res/values/styles.xml
index 4770910..20b88a1 100644
--- a/packages/SystemUI/res/values/styles.xml
+++ b/packages/SystemUI/res/values/styles.xml
@@ -677,7 +677,7 @@
 
     <style name="TextAppearance.Control.Status">
         <item name="android:fontFamily">@*android:string/config_headlineFontFamilyMedium</item>
-        <item name="android:textSize">@dimen/control_text_size</item>
+        <item name="android:textSize">@dimen/control_status_normal</item>
         <item name="android:textColor">@color/control_primary_text</item>
     </style>
 
diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
index 3cf07d1..ba8a1a9 100644
--- a/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
+++ b/packages/SystemUI/src/com/android/keyguard/KeyguardSecurityContainer.java
@@ -19,9 +19,7 @@
 import static android.view.ViewRootImpl.sNewInsetsMode;
 import static android.view.WindowInsets.Type.ime;
 import static android.view.WindowInsets.Type.systemBars;
-
 import static com.android.systemui.DejankUtils.whitelistIpcs;
-
 import static java.lang.Integer.max;
 
 import android.app.Activity;
@@ -30,6 +28,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.ColorStateList;
+import android.graphics.Rect;
 import android.metrics.LogMaker;
 import android.os.Handler;
 import android.os.Looper;
@@ -512,8 +511,6 @@
         boolean finish = false;
         boolean strongAuth = false;
         int eventSubtype = -1;
-        mCurrentSecuritySelection = whitelistIpcs(() ->
-                mSecurityModel.getSecurityMode(targetUserId));
         if (mUpdateMonitor.getUserHasTrust(targetUserId)) {
             finish = true;
             eventSubtype = BOUNCER_DISMISS_EXTENDED_ACCESS;
@@ -521,8 +518,13 @@
             finish = true;
             eventSubtype = BOUNCER_DISMISS_BIOMETRIC;
         } else if (SecurityMode.None == mCurrentSecuritySelection) {
-            finish = true; // no security required
-            eventSubtype = BOUNCER_DISMISS_NONE_SECURITY;
+            SecurityMode securityMode = mSecurityModel.getSecurityMode(targetUserId);
+            if (SecurityMode.None == securityMode) {
+                finish = true; // no security required
+                eventSubtype = BOUNCER_DISMISS_NONE_SECURITY;
+            } else {
+                showSecurityScreen(securityMode); // switch to the alternate security view
+            }
         } else if (authenticated) {
             switch (mCurrentSecuritySelection) {
                 case Pattern:
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
index cbb1982..0018d33 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthContainerView.java
@@ -99,6 +99,8 @@
 
     // Non-null only if the dialog is in the act of dismissing and has not sent the reason yet.
     @Nullable @AuthDialogCallback.DismissedReason Integer mPendingCallbackReason;
+    // HAT received from LockSettingsService when credential is verified.
+    @Nullable byte[] mCredentialAttestation;
 
     static class Config {
         Context mContext;
@@ -109,6 +111,7 @@
         String mOpPackageName;
         int mModalityMask;
         boolean mSkipIntro;
+        long mOperationId;
     }
 
     public static class Builder {
@@ -149,6 +152,11 @@
             return this;
         }
 
+        public Builder setOperationId(long operationId) {
+            mConfig.mOperationId = operationId;
+            return this;
+        }
+
         public AuthContainerView build(int modalityMask) {
             mConfig.mModalityMask = modalityMask;
             return new AuthContainerView(mConfig, new Injector());
@@ -224,7 +232,8 @@
 
     final class CredentialCallback implements AuthCredentialView.Callback {
         @Override
-        public void onCredentialMatched() {
+        public void onCredentialMatched(byte[] attestation) {
+            mCredentialAttestation = attestation;
             animateAway(AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED);
         }
     }
@@ -341,6 +350,7 @@
 
         mCredentialView.setContainerView(this);
         mCredentialView.setUserId(mConfig.mUserId);
+        mCredentialView.setOperationId(mConfig.mOperationId);
         mCredentialView.setEffectiveUserId(mEffectiveUserId);
         mCredentialView.setCredentialType(credentialType);
         mCredentialView.setCallback(mCredentialCallback);
@@ -558,7 +568,7 @@
     private void sendPendingCallbackIfNotNull() {
         Log.d(TAG, "pendingCallback: " + mPendingCallbackReason);
         if (mPendingCallbackReason != null) {
-            mConfig.mCallback.onDismissed(mPendingCallbackReason);
+            mConfig.mCallback.onDismissed(mPendingCallbackReason, mCredentialAttestation);
             mPendingCallbackReason = null;
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
index 6149b0b..c30477c 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
@@ -20,6 +20,7 @@
 import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT;
 import static android.hardware.biometrics.BiometricManager.Authenticators;
 
+import android.annotation.Nullable;
 import android.app.ActivityManager;
 import android.app.ActivityTaskManager;
 import android.app.IActivityTaskManager;
@@ -99,7 +100,8 @@
 
                 try {
                     if (mReceiver != null) {
-                        mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
+                        mReceiver.onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL,
+                                null /* credentialAttestation */);
                         mReceiver = null;
                     }
                 } catch (RemoteException e) {
@@ -124,7 +126,8 @@
                         mCurrentDialog = null;
                         if (mReceiver != null) {
                             mReceiver.onDialogDismissed(
-                                    BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
+                                    BiometricPrompt.DISMISSED_REASON_USER_CANCEL,
+                                    null /* credentialAttestation */);
                             mReceiver = null;
                         }
                     }
@@ -162,35 +165,42 @@
     }
 
     @Override
-    public void onDismissed(@DismissedReason int reason) {
+    public void onDismissed(@DismissedReason int reason, @Nullable byte[] credentialAttestation) {
         switch (reason) {
             case AuthDialogCallback.DISMISSED_USER_CANCELED:
-                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
+                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_USER_CANCEL,
+                        credentialAttestation);
                 break;
 
             case AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE:
-                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_NEGATIVE);
+                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_NEGATIVE,
+                        credentialAttestation);
                 break;
 
             case AuthDialogCallback.DISMISSED_BUTTON_POSITIVE:
-                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED);
+                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED,
+                        credentialAttestation);
                 break;
 
             case AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED:
                 sendResultAndCleanUp(
-                        BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED);
+                        BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED,
+                        credentialAttestation);
                 break;
 
             case AuthDialogCallback.DISMISSED_ERROR:
-                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_ERROR);
+                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_ERROR,
+                        credentialAttestation);
                 break;
 
             case AuthDialogCallback.DISMISSED_BY_SYSTEM_SERVER:
-                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_SERVER_REQUESTED);
+                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_SERVER_REQUESTED,
+                        credentialAttestation);
                 break;
 
             case AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED:
-                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED);
+                sendResultAndCleanUp(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED,
+                        credentialAttestation);
                 break;
 
             default:
@@ -199,13 +209,14 @@
         }
     }
 
-    private void sendResultAndCleanUp(@DismissedReason int reason) {
+    private void sendResultAndCleanUp(@DismissedReason int reason,
+            @Nullable byte[] credentialAttestation) {
         if (mReceiver == null) {
             Log.e(TAG, "sendResultAndCleanUp: Receiver is null");
             return;
         }
         try {
-            mReceiver.onDialogDismissed(reason);
+            mReceiver.onDialogDismissed(reason, credentialAttestation);
         } catch (RemoteException e) {
             Log.w(TAG, "Remote exception", e);
         }
@@ -251,13 +262,15 @@
 
     @Override
     public void showAuthenticationDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver,
-            int biometricModality, boolean requireConfirmation, int userId, String opPackageName) {
+            int biometricModality, boolean requireConfirmation, int userId, String opPackageName,
+            long operationId) {
         final int authenticators = Utils.getAuthenticators(bundle);
 
         if (DEBUG) {
             Log.d(TAG, "showAuthenticationDialog, authenticators: " + authenticators
                     + ", biometricModality: " + biometricModality
-                    + ", requireConfirmation: " + requireConfirmation);
+                    + ", requireConfirmation: " + requireConfirmation
+                    + ", operationId: " + operationId);
         }
         SomeArgs args = SomeArgs.obtain();
         args.arg1 = bundle;
@@ -266,6 +279,7 @@
         args.arg3 = requireConfirmation;
         args.argi2 = userId;
         args.arg4 = opPackageName;
+        args.arg5 = operationId;
 
         boolean skipAnimation = false;
         if (mCurrentDialog != null) {
@@ -354,6 +368,7 @@
         final boolean requireConfirmation = (boolean) args.arg3;
         final int userId = args.argi2;
         final String opPackageName = (String) args.arg4;
+        final long operationId = (long) args.arg5;
 
         // Create a new dialog but do not replace the current one yet.
         final AuthDialog newDialog = buildDialog(
@@ -362,7 +377,8 @@
                 userId,
                 type,
                 opPackageName,
-                skipAnimation);
+                skipAnimation,
+                operationId);
 
         if (newDialog == null) {
             Log.e(TAG, "Unsupported type: " + type);
@@ -429,7 +445,7 @@
     }
 
     protected AuthDialog buildDialog(Bundle biometricPromptBundle, boolean requireConfirmation,
-            int userId, int type, String opPackageName, boolean skipIntro) {
+            int userId, int type, String opPackageName, boolean skipIntro, long operationId) {
         return new AuthContainerView.Builder(mContext)
                 .setCallback(this)
                 .setBiometricPromptBundle(biometricPromptBundle)
@@ -437,6 +453,7 @@
                 .setUserId(userId)
                 .setOpPackageName(opPackageName)
                 .setSkipIntro(skipIntro)
+                .setOperationId(operationId)
                 .build(type);
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialPasswordView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialPasswordView.java
index 82c8a46..b986f6c 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialPasswordView.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialPasswordView.java
@@ -103,14 +103,16 @@
                 return;
             }
 
-            mPendingLockCheck = LockPatternChecker.checkCredential(mLockPatternUtils,
-                    password, mEffectiveUserId, this::onCredentialChecked);
+            mPendingLockCheck = LockPatternChecker.verifyCredential(mLockPatternUtils,
+                    password, mOperationId, mEffectiveUserId, this::onCredentialVerified);
         }
     }
 
     @Override
-    protected void onCredentialChecked(boolean matched, int timeoutMs) {
-        super.onCredentialChecked(matched, timeoutMs);
+    protected void onCredentialVerified(byte[] attestation, int timeoutMs) {
+        super.onCredentialVerified(attestation, timeoutMs);
+
+        final boolean matched = attestation != null;
 
         if (matched) {
             mImm.hideSoftInputFromWindow(getWindowToken(), 0 /* flags */);
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialPatternView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialPatternView.java
index 03136a4..6d16f43 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialPatternView.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialPatternView.java
@@ -61,21 +61,22 @@
 
             if (pattern.size() < LockPatternUtils.MIN_PATTERN_REGISTER_FAIL) {
                 // Pattern size is less than the minimum, do not count it as a failed attempt.
-                onPatternChecked(false /* matched */, 0 /* timeoutMs */);
+                onPatternVerified(null /* attestation */, 0 /* timeoutMs */);
                 return;
             }
 
             try (LockscreenCredential credential = LockscreenCredential.createPattern(pattern)) {
-                mPendingLockCheck = LockPatternChecker.checkCredential(
+                mPendingLockCheck = LockPatternChecker.verifyCredential(
                         mLockPatternUtils,
                         credential,
+                        mOperationId,
                         mEffectiveUserId,
-                        this::onPatternChecked);
+                        this::onPatternVerified);
             }
         }
 
-        private void onPatternChecked(boolean matched, int timeoutMs) {
-            AuthCredentialPatternView.this.onCredentialChecked(matched, timeoutMs);
+        private void onPatternVerified(byte[] attestation, int timeoutMs) {
+            AuthCredentialPatternView.this.onCredentialVerified(attestation, timeoutMs);
             if (timeoutMs > 0) {
                 mLockPatternView.setEnabled(false);
             } else {
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialView.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialView.java
index 48c6621..0d9d426 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialView.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthCredentialView.java
@@ -42,7 +42,7 @@
 
 /**
  * Abstract base class for Pin, Pattern, or Password authentication, for
- * {@link BiometricPrompt.Builder#setDeviceCredentialAllowed(boolean)}
+ * {@link BiometricPrompt.Builder#setAllowedAuthenticators(int)}}
  */
 public abstract class AuthCredentialView extends LinearLayout {
 
@@ -70,11 +70,12 @@
     protected Callback mCallback;
     protected AsyncTask<?, ?, ?> mPendingLockCheck;
     protected int mUserId;
+    protected long mOperationId;
     protected int mEffectiveUserId;
     protected ErrorTimer mErrorTimer;
 
     interface Callback {
-        void onCredentialMatched();
+        void onCredentialMatched(byte[] attestation);
     }
 
     protected static class ErrorTimer extends CountDownTimer {
@@ -148,6 +149,10 @@
         mUserId = userId;
     }
 
+    void setOperationId(long operationId) {
+        mOperationId = operationId;
+    }
+
     void setEffectiveUserId(int effectiveUserId) {
         mEffectiveUserId = effectiveUserId;
     }
@@ -245,10 +250,13 @@
 
     protected void onErrorTimeoutFinish() {}
 
-    protected void onCredentialChecked(boolean matched, int timeoutMs) {
+    protected void onCredentialVerified(byte[] attestation, int timeoutMs) {
+
+        final boolean matched = attestation != null;
+
         if (matched) {
             mClearErrorRunnable.run();
-            mCallback.onCredentialMatched();
+            mCallback.onCredentialMatched(attestation);
         } else {
             if (timeoutMs > 0) {
                 mHandler.removeCallbacks(mClearErrorRunnable);
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthDialogCallback.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthDialogCallback.java
index 12bb122..a47621d 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthDialogCallback.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthDialogCallback.java
@@ -17,6 +17,7 @@
 package com.android.systemui.biometrics;
 
 import android.annotation.IntDef;
+import android.annotation.Nullable;
 
 /**
  * Callback interface for dialog views. These should be implemented by the controller (e.g.
@@ -44,8 +45,9 @@
     /**
      * Invoked when the dialog is dismissed
      * @param reason
+     * @param credentialAttestation the HAT received from LockSettingsService upon verification
      */
-    void onDismissed(@DismissedReason int reason);
+    void onDismissed(@DismissedReason int reason, @Nullable byte[] credentialAttestation);
 
     /**
      * Invoked when the "try again" button is clicked
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleData.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleData.java
index 39abc21..54b83c0 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleData.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleData.java
@@ -207,12 +207,13 @@
 
         // Preserve new order for next repack, which sorts by last updated time.
         bubble.markUpdatedAt(mTimeSource.currentTimeMillis());
-        setSelectedBubbleInternal(bubble);
         mOverflowBubbles.remove(bubble);
-
         bubble.inflate(
-                b -> notificationEntryUpdated(bubble, /* suppressFlyout */
-                        false, /* showInShade */ true),
+                b -> {
+                    notificationEntryUpdated(bubble, /* suppressFlyout */
+                            false, /* showInShade */ true);
+                    setSelectedBubbleInternal(bubble);
+                },
                 mContext, stack, factory);
         dispatchPendingChanges();
     }
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
index 0b7dbd2..0778d5b 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
@@ -424,6 +424,7 @@
 
     private int mOrientation = Configuration.ORIENTATION_UNDEFINED;
 
+    @Nullable
     private BubbleOverflow mBubbleOverflow;
 
     private boolean mShouldShowUserEducation;
@@ -1387,7 +1388,7 @@
             Log.d(TAG, "onBubbleDragStart: bubble=" + bubble);
         }
 
-        if (bubble.equals(mBubbleOverflow.getIconView())) {
+        if (mBubbleOverflow != null && bubble.equals(mBubbleOverflow.getIconView())) {
             return;
         }
 
@@ -1403,7 +1404,8 @@
 
     /** Called with the coordinates to which an individual bubble has been dragged. */
     public void onBubbleDragged(View bubble, float x, float y) {
-        if (!mIsExpanded || mIsExpansionAnimating || bubble.equals(mBubbleOverflow.getIconView())) {
+        if (!mIsExpanded || mIsExpansionAnimating
+                || (mBubbleOverflow != null && bubble.equals(mBubbleOverflow.getIconView()))) {
             return;
         }
 
@@ -1418,7 +1420,8 @@
             Log.d(TAG, "onBubbleDragFinish: bubble=" + bubble);
         }
 
-        if (!mIsExpanded || mIsExpansionAnimating || bubble.equals(mBubbleOverflow.getIconView())) {
+        if (!mIsExpanded || mIsExpansionAnimating
+                || (mBubbleOverflow != null && bubble.equals(mBubbleOverflow.getIconView()))) {
             return;
         }
 
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt
index fc5663f..b439206 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt
@@ -17,8 +17,8 @@
 package com.android.systemui.controls.ui
 
 import android.content.Context
-import android.graphics.BlendMode
 import android.graphics.drawable.ClipDrawable
+import android.graphics.drawable.GradientDrawable
 import android.graphics.drawable.LayerDrawable
 import android.service.controls.Control
 import android.service.controls.actions.ControlAction
@@ -39,6 +39,8 @@
 import kotlin.reflect.KClass
 
 private const val UPDATE_DELAY_IN_MILLIS = 3000L
+private const val ALPHA_ENABLED = (255.0 * 0.2).toInt()
+private const val ALPHA_DISABLED = 255
 
 class ControlViewHolder(
     val layout: ViewGroup,
@@ -69,7 +71,7 @@
 
         cancelUpdate?.run()
 
-        val (status, template) = cws.control?.let {
+        val (controlStatus, template) = cws.control?.let {
             title.setText(it.getTitle())
             subtitle.setText(it.getSubtitle())
             Pair(it.getStatus(), it.getControlTemplate())
@@ -80,20 +82,28 @@
         }
 
         cws.control?.let {
+            layout.setClickable(true)
             layout.setOnLongClickListener(View.OnLongClickListener() {
                 ControlActionCoordinator.longPress(this@ControlViewHolder)
                 true
             })
         }
 
-        val clazz = findBehavior(status, template)
+        val clazz = findBehavior(controlStatus, template)
         if (behavior == null || behavior!!::class != clazz) {
             // Behavior changes can signal a change in template from the app or
             // first time setup
             behavior = clazz.java.newInstance()
             behavior?.initialize(this)
+
+            // let behaviors define their own, if necessary, and clear any existing ones
+            layout.setAccessibilityDelegate(null)
         }
+
         behavior?.bind(cws)
+
+        layout.setContentDescription(
+            "${title.text} ${subtitle.text} ${status.text} ${statusExtra.text}")
     }
 
     fun actionResponse(@ControlAction.ResponseResult response: Int) {
@@ -136,16 +146,21 @@
         val ri = RenderInfo.lookup(context, cws.componentName, deviceType, enabled, offset)
 
         val fg = context.getResources().getColorStateList(ri.foreground, context.getTheme())
-        val bg = context.getResources().getColorStateList(ri.background, context.getTheme())
+        val (bg, alpha) = if (enabled) {
+            Pair(ri.enabledBackground, ALPHA_ENABLED)
+        } else {
+            Pair(R.color.control_default_background, ALPHA_DISABLED)
+        }
+
         status.setTextColor(fg)
         statusExtra.setTextColor(fg)
 
         icon.setImageDrawable(ri.icon)
         icon.setImageTintList(fg)
 
-        clipLayer.getDrawable().apply {
-            setTintBlendMode(BlendMode.HUE)
-            setTintList(bg)
+        (clipLayer.getDrawable() as GradientDrawable).apply {
+            setColor(context.getResources().getColor(bg, context.getTheme()))
+            setAlpha(alpha)
         }
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
index bde966c..138cd47 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlsUiControllerImpl.kt
@@ -406,7 +406,7 @@
             setText(item.getTitle())
         }
         view.requireViewById<ImageView>(R.id.app_icon).apply {
-            setContentDescription(item.getTitle())
+            setContentDescription(item.appName)
             setImageDrawable(item.icon)
         }
         return view
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt
index 56267be..27e4649 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt
@@ -16,6 +16,7 @@
 
 package com.android.systemui.controls.ui
 
+import android.annotation.ColorRes
 import android.annotation.MainThread
 import android.content.ComponentName
 import android.content.Context
@@ -37,8 +38,11 @@
     }
 }
 
-data class RenderInfo(val icon: Drawable, val foreground: Int, val background: Int) {
-
+data class RenderInfo(
+    val icon: Drawable,
+    val foreground: Int,
+    @ColorRes val enabledBackground: Int
+) {
     companion object {
         const val APP_ICON_ID = -1
         private val iconMap = SparseArray<Drawable>()
@@ -72,6 +76,7 @@
                 icon = iconMap.get(resourceId)
                 if (icon == null) {
                     icon = context.resources.getDrawable(resourceId, null)
+                    icon.mutate()
                     iconMap.put(resourceId, icon)
                 }
             }
@@ -94,12 +99,13 @@
 
 private val deviceColorMap = mapOf<Int, Pair<Int, Int>>(
     (THERMOSTAT_RANGE + TemperatureControlTemplate.MODE_HEAT) to
-        Pair(R.color.thermo_heat_foreground, R.color.thermo_heat_background),
+        Pair(R.color.thermo_heat_foreground, R.color.control_enabled_thermo_heat_background),
     (THERMOSTAT_RANGE + TemperatureControlTemplate.MODE_COOL) to
-        Pair(R.color.thermo_cool_foreground, R.color.thermo_cool_background),
-    DeviceTypes.TYPE_LIGHT to Pair(R.color.light_foreground, R.color.light_background)
+        Pair(R.color.thermo_cool_foreground, R.color.control_enabled_thermo_cool_background),
+    DeviceTypes.TYPE_LIGHT
+        to Pair(R.color.light_foreground, R.color.control_enabled_light_background)
 ).withDefault {
-        Pair(R.color.control_foreground, R.color.control_background)
+        Pair(R.color.control_foreground, R.color.control_enabled_default_background)
 }
 
 private val deviceIconMap = mapOf<Int, IconState>(
diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt
index 6595b55..c495c58 100644
--- a/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt
+++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt
@@ -16,6 +16,7 @@
 
 package com.android.systemui.controls.ui
 
+import android.os.Bundle
 import android.content.Context
 import android.graphics.drawable.Drawable
 import android.graphics.drawable.LayerDrawable
@@ -24,6 +25,9 @@
 import android.view.GestureDetector.SimpleOnGestureListener
 import android.view.MotionEvent
 import android.view.View
+import android.view.ViewGroup
+import android.view.accessibility.AccessibilityEvent
+import android.view.accessibility.AccessibilityNodeInfo
 import android.widget.TextView
 import android.service.controls.Control
 import android.service.controls.actions.FloatAction
@@ -94,6 +98,71 @@
         updateRange(currentRatio, checked)
 
         cvh.applyRenderInfo(checked)
+
+        /*
+         * This is custom widget behavior, so add a new accessibility delegate to
+         * handle clicks and range events. Present as a seek bar control.
+         */
+        cvh.layout.setAccessibilityDelegate(object : View.AccessibilityDelegate() {
+            override fun onInitializeAccessibilityNodeInfo(
+                host: View,
+                info: AccessibilityNodeInfo
+            ) {
+                super.onInitializeAccessibilityNodeInfo(host, info)
+
+                val min = levelToRangeValue(MIN_LEVEL)
+                val current = levelToRangeValue(clipLayer.getLevel())
+                val max = levelToRangeValue(MAX_LEVEL)
+
+                val step = rangeTemplate.getStepValue().toDouble()
+                val type = if (step == Math.floor(step)) {
+                    AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT
+                } else {
+                    AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_FLOAT
+                }
+
+                val rangeInfo = AccessibilityNodeInfo.RangeInfo.obtain(type, min, max, current)
+                info.setRangeInfo(rangeInfo)
+                info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_PROGRESS)
+            }
+
+            override fun performAccessibilityAction(
+                host: View,
+                action: Int,
+                arguments: Bundle?
+            ): Boolean {
+                val handled = when (action) {
+                    AccessibilityNodeInfo.ACTION_CLICK -> {
+                        ControlActionCoordinator.toggle(cvh, template.getTemplateId(),
+                            template.isChecked())
+                        true
+                    }
+                    AccessibilityNodeInfo.AccessibilityAction.ACTION_SET_PROGRESS.getId() -> {
+                        if (arguments == null || !arguments.containsKey(
+                                AccessibilityNodeInfo.ACTION_ARGUMENT_PROGRESS_VALUE)) {
+                            false
+                        } else {
+                            val value = arguments.getFloat(
+                                AccessibilityNodeInfo.ACTION_ARGUMENT_PROGRESS_VALUE)
+                            val ratioDiff = (value - rangeTemplate.getCurrentValue()) /
+                                (rangeTemplate.getMaxValue() - rangeTemplate.getMinValue())
+                            updateRange(ratioDiff, template.isChecked())
+                            endUpdateRange()
+                            true
+                        }
+                    }
+                    else -> false
+                }
+
+                return handled || super.performAccessibilityAction(host, action, arguments)
+            }
+
+            override fun onRequestSendAccessibilityEvent(
+                host: ViewGroup,
+                child: View,
+                event: AccessibilityEvent
+            ): Boolean = false
+        })
     }
 
     fun beginUpdateRange() {
@@ -108,7 +177,7 @@
         clipLayer.setLevel(newLevel)
 
         if (checked) {
-            val newValue = levelToRangeValue()
+            val newValue = levelToRangeValue(clipLayer.getLevel())
             val formattedNewValue = format(rangeTemplate.getFormatString().toString(),
                     DEFAULT_FORMAT, newValue)
 
@@ -133,8 +202,8 @@
         }
     }
 
-    private fun levelToRangeValue(): Float {
-        val ratio = clipLayer.getLevel().toFloat() / MAX_LEVEL
+    private fun levelToRangeValue(i: Int): Float {
+        val ratio = i.toFloat() / MAX_LEVEL
         return rangeTemplate.getMinValue() +
             (ratio * (rangeTemplate.getMaxValue() - rangeTemplate.getMinValue()))
     }
@@ -143,7 +212,8 @@
         statusExtra.setTextSize(TypedValue.COMPLEX_UNIT_PX, context.getResources()
                 .getDimensionPixelSize(R.dimen.control_status_normal).toFloat())
         status.setVisibility(View.VISIBLE)
-        cvh.action(FloatAction(rangeTemplate.getTemplateId(), findNearestStep(levelToRangeValue())))
+        cvh.action(FloatAction(rangeTemplate.getTemplateId(),
+            findNearestStep(levelToRangeValue(clipLayer.getLevel()))))
     }
 
     fun findNearestStep(value: Float): Float {
diff --git a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
index 27c81ce..59b28b4 100644
--- a/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
+++ b/packages/SystemUI/src/com/android/systemui/globalactions/GlobalActionsDialog.java
@@ -99,7 +99,7 @@
 import com.android.systemui.plugins.ActivityStarter;
 import com.android.systemui.plugins.GlobalActions.GlobalActionsManager;
 import com.android.systemui.plugins.GlobalActionsPanelPlugin;
-import com.android.systemui.statusbar.BlurUtils;
+import com.android.systemui.statusbar.NotificationShadeDepthController;
 import com.android.systemui.statusbar.phone.NotificationShadeWindowController;
 import com.android.systemui.statusbar.phone.ScrimController;
 import com.android.systemui.statusbar.policy.ConfigurationController;
@@ -162,7 +162,7 @@
     private final IActivityManager mIActivityManager;
     private final TelecomManager mTelecomManager;
     private final MetricsLogger mMetricsLogger;
-    private final BlurUtils mBlurUtils;
+    private final NotificationShadeDepthController mDepthController;
 
     private ArrayList<Action> mItems;
     private ActionsDialog mDialog;
@@ -207,7 +207,7 @@
             KeyguardStateController keyguardStateController, UserManager userManager,
             TrustManager trustManager, IActivityManager iActivityManager,
             @Nullable TelecomManager telecomManager, MetricsLogger metricsLogger,
-            BlurUtils blurUtils, SysuiColorExtractor colorExtractor,
+            NotificationShadeDepthController depthController, SysuiColorExtractor colorExtractor,
             IStatusBarService statusBarService,
             NotificationShadeWindowController notificationShadeWindowController,
             ControlsUiController controlsUiController, IWindowManager iWindowManager,
@@ -229,7 +229,7 @@
         mIActivityManager = iActivityManager;
         mTelecomManager = telecomManager;
         mMetricsLogger = metricsLogger;
-        mBlurUtils = blurUtils;
+        mDepthController = depthController;
         mSysuiColorExtractor = colorExtractor;
         mStatusBarService = statusBarService;
         mNotificationShadeWindowController = notificationShadeWindowController;
@@ -437,7 +437,7 @@
                         : null;
 
         ActionsDialog dialog = new ActionsDialog(mContext, mAdapter, panelViewController,
-                mBlurUtils, mSysuiColorExtractor, mStatusBarService,
+                mDepthController, mSysuiColorExtractor, mStatusBarService,
                 mNotificationShadeWindowController,
                 shouldShowControls() ? mControlsUiController : null);
         dialog.setCanceledOnTouchOutside(false); // Handled by the custom class.
@@ -1570,20 +1570,21 @@
         private ResetOrientationData mResetOrientationData;
         private boolean mHadTopUi;
         private final NotificationShadeWindowController mNotificationShadeWindowController;
-        private final BlurUtils mBlurUtils;
+        private final NotificationShadeDepthController mDepthController;
 
         private ControlsUiController mControlsUiController;
         private ViewGroup mControlsView;
 
         ActionsDialog(Context context, MyAdapter adapter,
-                GlobalActionsPanelPlugin.PanelViewController plugin, BlurUtils blurUtils,
+                GlobalActionsPanelPlugin.PanelViewController plugin,
+                NotificationShadeDepthController depthController,
                 SysuiColorExtractor sysuiColorExtractor, IStatusBarService statusBarService,
                 NotificationShadeWindowController notificationShadeWindowController,
                 ControlsUiController controlsUiController) {
             super(context, com.android.systemui.R.style.Theme_SystemUI_Dialog_GlobalActions);
             mContext = context;
             mAdapter = adapter;
-            mBlurUtils = blurUtils;
+            mDepthController = depthController;
             mColorExtractor = sysuiColorExtractor;
             mStatusBarService = statusBarService;
             mNotificationShadeWindowController = notificationShadeWindowController;
@@ -1792,8 +1793,8 @@
                         float animatedValue = animation.getAnimatedFraction();
                         int alpha = (int) (animatedValue * mScrimAlpha * 255);
                         mBackgroundDrawable.setAlpha(alpha);
-                        mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
-                                mBlurUtils.blurRadiusOfRatio(animatedValue));
+                        mDepthController.updateGlobalDialogVisibility(animatedValue,
+                                mGlobalActionsLayout);
                     })
                     .start();
             if (mControlsUiController != null) {
@@ -1822,8 +1823,8 @@
                         float animatedValue = 1f - animation.getAnimatedFraction();
                         int alpha = (int) (animatedValue * mScrimAlpha * 255);
                         mBackgroundDrawable.setAlpha(alpha);
-                        mBlurUtils.applyBlur(mGlobalActionsLayout.getViewRootImpl(),
-                                mBlurUtils.blurRadiusOfRatio(animatedValue));
+                        mDepthController.updateGlobalDialogVisibility(animatedValue,
+                                mGlobalActionsLayout);
                     })
                     .start();
             dismissPanel();
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java b/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java
index ae380b7..c281ece 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/WorkLockActivityController.java
@@ -93,7 +93,7 @@
             return mIatm.startActivityAsUser(
                     mContext.getIApplicationThread() /*caller*/,
                     mContext.getBasePackageName() /*callingPackage*/,
-                    mContext.getFeatureId() /*callingFeatureId*/,
+                    mContext.getAttributionTag() /*callingAttributionTag*/,
                     intent /*intent*/,
                     intent.resolveTypeIfNeeded(mContext.getContentResolver()) /*resolvedType*/,
                     null /*resultTo*/,
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipAnimationController.java b/packages/SystemUI/src/com/android/systemui/pip/PipAnimationController.java
index 67802bc..4bfcf22 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipAnimationController.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipAnimationController.java
@@ -30,6 +30,8 @@
 import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 
+import javax.inject.Inject;
+
 /**
  * Controller class of PiP animations (both from and to PiP mode).
  */
@@ -37,7 +39,6 @@
     private static final float FRACTION_START = 0f;
     private static final float FRACTION_END = 1f;
 
-    public static final int DURATION_DEFAULT_MS = 425;
     public static final int ANIM_TYPE_BOUNDS = 0;
     public static final int ANIM_TYPE_ALPHA = 1;
 
@@ -63,12 +64,15 @@
     @interface TransitionDirection {}
 
     private final Interpolator mFastOutSlowInInterpolator;
+    private final PipSurfaceTransactionHelper mSurfaceTransactionHelper;
 
     private PipTransitionAnimator mCurrentAnimator;
 
-    PipAnimationController(Context context) {
+    @Inject
+    PipAnimationController(Context context, PipSurfaceTransactionHelper helper) {
         mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                 com.android.internal.R.interpolator.fast_out_slow_in);
+        mSurfaceTransactionHelper = helper;
     }
 
     @SuppressWarnings("unchecked")
@@ -111,6 +115,7 @@
     }
 
     private PipTransitionAnimator setupPipTransitionAnimator(PipTransitionAnimator animator) {
+        animator.setSurfaceTransactionHelper(mSurfaceTransactionHelper);
         animator.setInterpolator(mFastOutSlowInInterpolator);
         animator.setFloatValues(FRACTION_START, FRACTION_END);
         return animator;
@@ -152,9 +157,10 @@
         private T mEndValue;
         private T mCurrentValue;
         private PipAnimationCallback mPipAnimationCallback;
-        private SurfaceControlTransactionFactory mSurfaceControlTransactionFactory;
+        private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
+                mSurfaceControlTransactionFactory;
+        private PipSurfaceTransactionHelper mSurfaceTransactionHelper;
         private @TransitionDirection int mTransitionDirection;
-        private int mCornerRadius;
 
         private PipTransitionAnimator(SurfaceControl leash, @AnimationType int animationType,
                 Rect destinationBounds, T startValue, T endValue) {
@@ -243,15 +249,6 @@
             mCurrentValue = value;
         }
 
-        int getCornerRadius() {
-            return mCornerRadius;
-        }
-
-        PipTransitionAnimator<T> setCornerRadius(int cornerRadius) {
-            mCornerRadius = cornerRadius;
-            return this;
-        }
-
         boolean shouldApplyCornerRadius() {
             return mTransitionDirection != TRANSITION_DIRECTION_TO_FULLSCREEN;
         }
@@ -274,10 +271,19 @@
         }
 
         @VisibleForTesting
-        void setSurfaceControlTransactionFactory(SurfaceControlTransactionFactory factory) {
+        void setSurfaceControlTransactionFactory(
+                PipSurfaceTransactionHelper.SurfaceControlTransactionFactory factory) {
             mSurfaceControlTransactionFactory = factory;
         }
 
+        PipSurfaceTransactionHelper getSurfaceTransactionHelper() {
+            return mSurfaceTransactionHelper;
+        }
+
+        void setSurfaceTransactionHelper(PipSurfaceTransactionHelper helper) {
+            mSurfaceTransactionHelper = helper;
+        }
+
         abstract void applySurfaceControlTransaction(SurfaceControl leash,
                 SurfaceControl.Transaction tx, float fraction);
 
@@ -290,14 +296,11 @@
                         SurfaceControl.Transaction tx, float fraction) {
                     final float alpha = getStartValue() * (1 - fraction) + getEndValue() * fraction;
                     setCurrentValue(alpha);
-                    tx.setAlpha(leash, alpha);
+                    getSurfaceTransactionHelper().alpha(tx, leash, alpha);
                     if (Float.compare(fraction, FRACTION_START) == 0) {
-                        // Ensure the start condition
-                        final Rect bounds = getDestinationBounds();
-                        tx.setPosition(leash, bounds.left, bounds.top)
-                                .setWindowCrop(leash, bounds.width(), bounds.height());
-                        tx.setCornerRadius(leash,
-                                shouldApplyCornerRadius() ? getCornerRadius() : 0);
+                        getSurfaceTransactionHelper()
+                                .crop(tx, leash, getDestinationBounds())
+                                .round(tx, leash, shouldApplyCornerRadius());
                     }
                     tx.apply();
                 }
@@ -326,21 +329,16 @@
                             getCastedFractionValue(start.right, end.right, fraction),
                             getCastedFractionValue(start.bottom, end.bottom, fraction));
                     setCurrentValue(mTmpRect);
-                    tx.setPosition(leash, mTmpRect.left, mTmpRect.top)
-                            .setWindowCrop(leash, mTmpRect.width(), mTmpRect.height());
+                    getSurfaceTransactionHelper().crop(tx, leash, mTmpRect);
                     if (Float.compare(fraction, FRACTION_START) == 0) {
                         // Ensure the start condition
-                        tx.setAlpha(leash, 1f);
-                        tx.setCornerRadius(leash,
-                                shouldApplyCornerRadius() ? getCornerRadius() : 0);
+                        getSurfaceTransactionHelper()
+                                .alpha(tx, leash, 1f)
+                                .round(tx, leash, shouldApplyCornerRadius());
                     }
                     tx.apply();
                 }
             };
         }
     }
-
-    interface SurfaceControlTransactionFactory {
-        SurfaceControl.Transaction getTransaction();
-    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipSurfaceTransactionHelper.java b/packages/SystemUI/src/com/android/systemui/pip/PipSurfaceTransactionHelper.java
new file mode 100644
index 0000000..21f9301
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipSurfaceTransactionHelper.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.pip;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Rect;
+import android.view.SurfaceControl;
+
+import com.android.systemui.R;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+/**
+ * Abstracts the common operations on {@link SurfaceControl.Transaction} for PiP transition.
+ */
+@Singleton
+public class PipSurfaceTransactionHelper {
+
+    private final boolean mEnableCornerRadius;
+    private final int mCornerRadius;
+
+    @Inject
+    public PipSurfaceTransactionHelper(Context context) {
+        final Resources res = context.getResources();
+        mEnableCornerRadius = res.getBoolean(R.bool.config_pipEnableRoundCorner);
+        mCornerRadius = res.getDimensionPixelSize(R.dimen.pip_corner_radius);
+    }
+
+    /**
+     * Operates the alpha on a given transaction and leash
+     * @return same {@link PipSurfaceTransactionHelper} instance for method chaining
+     */
+    PipSurfaceTransactionHelper alpha(SurfaceControl.Transaction tx, SurfaceControl leash,
+            float alpha) {
+        tx.setAlpha(leash, alpha);
+        return this;
+    }
+
+    /**
+     * Operates the crop (and position) on a given transaction and leash
+     * @return same {@link PipSurfaceTransactionHelper} instance for method chaining
+     */
+    PipSurfaceTransactionHelper crop(SurfaceControl.Transaction tx, SurfaceControl leash,
+            Rect destinationBounds) {
+        tx.setWindowCrop(leash, destinationBounds.width(), destinationBounds.height())
+                .setPosition(leash, destinationBounds.left, destinationBounds.top);
+        return this;
+    }
+
+    /**
+     * Operates the round corner radius on a given transaction and leash
+     * @return same {@link PipSurfaceTransactionHelper} instance for method chaining
+     */
+    PipSurfaceTransactionHelper round(SurfaceControl.Transaction tx, SurfaceControl leash,
+            boolean applyCornerRadius) {
+        if (mEnableCornerRadius) {
+            tx.setCornerRadius(leash, applyCornerRadius ? mCornerRadius : 0);
+        }
+        return this;
+    }
+
+    interface SurfaceControlTransactionFactory {
+        SurfaceControl.Transaction getTransaction();
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
index 51113ac..4a4a638 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/PipTaskOrganizer.java
@@ -18,7 +18,6 @@
 
 import static com.android.systemui.pip.PipAnimationController.ANIM_TYPE_ALPHA;
 import static com.android.systemui.pip.PipAnimationController.ANIM_TYPE_BOUNDS;
-import static com.android.systemui.pip.PipAnimationController.DURATION_DEFAULT_MS;
 import static com.android.systemui.pip.PipAnimationController.TRANSITION_DIRECTION_NONE;
 import static com.android.systemui.pip.PipAnimationController.TRANSITION_DIRECTION_SAME;
 import static com.android.systemui.pip.PipAnimationController.TRANSITION_DIRECTION_TO_FULLSCREEN;
@@ -33,7 +32,6 @@
 import android.content.Context;
 import android.graphics.Rect;
 import android.os.Handler;
-import android.os.IBinder;
 import android.os.Looper;
 import android.os.RemoteException;
 import android.util.Log;
@@ -47,9 +45,7 @@
 import com.android.systemui.pip.phone.PipUpdateThread;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 import java.util.Objects;
 import java.util.function.Consumer;
 
@@ -79,8 +75,8 @@
     private final PipAnimationController mPipAnimationController;
     private final List<PipTransitionCallback> mPipTransitionCallbacks = new ArrayList<>();
     private final Rect mLastReportedBounds = new Rect();
-    private final int mCornerRadius;
-    private final Map<IBinder, Rect> mBoundsToRestore = new HashMap<>();
+    private final int mEnterExitAnimationDuration;
+    private final PipSurfaceTransactionHelper mSurfaceTransactionHelper;
 
     // These callbacks are called on the update thread
     private final PipAnimationController.PipAnimationCallback mPipAnimationCallback =
@@ -172,14 +168,20 @@
     private SurfaceControl mLeash;
     private boolean mInPip;
     private @PipAnimationController.AnimationType int mOneShotAnimationType = ANIM_TYPE_BOUNDS;
+    private PipSurfaceTransactionHelper.SurfaceControlTransactionFactory
+            mSurfaceControlTransactionFactory;
 
-    public PipTaskOrganizer(Context context, @NonNull PipBoundsHandler boundsHandler) {
+    public PipTaskOrganizer(Context context, @NonNull PipBoundsHandler boundsHandler,
+            @NonNull PipSurfaceTransactionHelper surfaceTransactionHelper) {
         mMainHandler = new Handler(Looper.getMainLooper());
         mUpdateHandler = new Handler(PipUpdateThread.get().getLooper(), mUpdateCallbacks);
         mTaskOrganizerController = ActivityTaskManager.getTaskOrganizerController();
         mPipBoundsHandler = boundsHandler;
-        mPipAnimationController = new PipAnimationController(context);
-        mCornerRadius = context.getResources().getDimensionPixelSize(R.dimen.pip_corner_radius);
+        mEnterExitAnimationDuration = context.getResources()
+                .getInteger(R.integer.config_pipResizeAnimationDuration);
+        mSurfaceTransactionHelper = surfaceTransactionHelper;
+        mPipAnimationController = new PipAnimationController(context, surfaceTransactionHelper);
+        mSurfaceControlTransactionFactory = SurfaceControl.Transaction::new;
     }
 
     public Handler getUpdateHandler() {
@@ -232,17 +234,15 @@
             throw new RuntimeException("Unable to get leash", e);
         }
         final Rect currentBounds = mTaskInfo.configuration.windowConfiguration.getBounds();
-        mBoundsToRestore.put(mToken.asBinder(), currentBounds);
         if (mOneShotAnimationType == ANIM_TYPE_BOUNDS) {
             scheduleAnimateResizePip(currentBounds, destinationBounds,
-                    TRANSITION_DIRECTION_TO_PIP, DURATION_DEFAULT_MS, null);
+                    TRANSITION_DIRECTION_TO_PIP, mEnterExitAnimationDuration, null);
         } else if (mOneShotAnimationType == ANIM_TYPE_ALPHA) {
             mUpdateHandler.post(() -> mPipAnimationController
                     .getAnimator(mLeash, destinationBounds, 0f, 1f)
                     .setTransitionDirection(TRANSITION_DIRECTION_TO_PIP)
-                    .setCornerRadius(mCornerRadius)
                     .setPipAnimationCallback(mPipAnimationCallback)
-                    .setDuration(DURATION_DEFAULT_MS)
+                    .setDuration(mEnterExitAnimationDuration)
                     .start());
             mOneShotAnimationType = ANIM_TYPE_BOUNDS;
         } else {
@@ -258,9 +258,9 @@
             Log.wtf(TAG, "Unrecognized token: " + token);
             return;
         }
-        final Rect boundsToRestore = mBoundsToRestore.remove(mToken.asBinder());
-        scheduleAnimateResizePip(mLastReportedBounds, boundsToRestore,
-                TRANSITION_DIRECTION_TO_FULLSCREEN, DURATION_DEFAULT_MS, null);
+        scheduleAnimateResizePip(mLastReportedBounds,
+                info.configuration.windowConfiguration.getBounds(),
+                TRANSITION_DIRECTION_TO_FULLSCREEN, mEnterExitAnimationDuration, null);
         mInPip = false;
     }
 
@@ -278,7 +278,7 @@
         final Rect destinationBounds = mPipBoundsHandler.getDestinationBounds(
                 getAspectRatioOrDefault(newParams), null /* bounds */);
         Objects.requireNonNull(destinationBounds, "Missing destination bounds");
-        scheduleAnimateResizePip(destinationBounds, DURATION_DEFAULT_MS, null);
+        scheduleAnimateResizePip(destinationBounds, mEnterExitAnimationDuration, null);
     }
 
     /**
@@ -305,7 +305,6 @@
     private void scheduleAnimateResizePip(Rect currentBounds, Rect destinationBounds,
             @PipAnimationController.TransitionDirection int direction, int durationMs,
             Consumer<Rect> updateBoundsCallback) {
-        Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
         if (!mInPip) {
             // Ignore animation when we are no longer in PIP
             return;
@@ -324,7 +323,6 @@
      * {@link WindowContainerTransaction} until {@link #scheduleFinishResizePip} is called.
      */
     public void scheduleResizePip(Rect toBounds, Consumer<Rect> updateBoundsCallback) {
-        Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
         SomeArgs args = SomeArgs.obtain();
         args.arg1 = updateBoundsCallback;
         args.arg2 = toBounds;
@@ -332,22 +330,20 @@
     }
 
     /**
-     * Finish a intermediate resize operation. This is expected to be called after
+     * Finish an intermediate resize operation. This is expected to be called after
      * {@link #scheduleResizePip}.
      */
     public void scheduleFinishResizePip(Rect destinationBounds) {
-        Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
-        SurfaceControl.Transaction tx = new SurfaceControl.Transaction()
-                .setPosition(mLeash, destinationBounds.left, destinationBounds.top)
-                .setWindowCrop(mLeash, destinationBounds.width(), destinationBounds.height())
-                .setCornerRadius(mLeash, mInPip ? mCornerRadius : 0);
+        final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
+        mSurfaceTransactionHelper
+                .crop(tx, mLeash, destinationBounds)
+                .round(tx, mLeash, mInPip);
         scheduleFinishResizePip(tx, destinationBounds, TRANSITION_DIRECTION_NONE, null);
     }
 
     private void scheduleFinishResizePip(SurfaceControl.Transaction tx,
             Rect destinationBounds, @PipAnimationController.TransitionDirection int direction,
             Consumer<Rect> updateBoundsCallback) {
-        Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
         SomeArgs args = SomeArgs.obtain();
         args.arg1 = updateBoundsCallback;
         args.arg2 = tx;
@@ -365,7 +361,6 @@
             // Ignore offsets when we are no longer in PIP
             return;
         }
-        Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
         SomeArgs args = SomeArgs.obtain();
         args.arg1 = updateBoundsCallback;
         args.arg2 = originalBounds;
@@ -394,17 +389,16 @@
             throw new RuntimeException("Callers should call scheduleResizePip() instead of this "
                     + "directly");
         }
-        Objects.requireNonNull(mToken, "Requires valid IWindowContainer");
         // Could happen when dismissPip
         if (mToken == null || mLeash == null) {
             Log.w(TAG, "Abort animation, invalid leash");
             return;
         }
-        new SurfaceControl.Transaction()
-                .setPosition(mLeash, destinationBounds.left, destinationBounds.top)
-                .setWindowCrop(mLeash, destinationBounds.width(), destinationBounds.height())
-                .setCornerRadius(mLeash, mInPip ? mCornerRadius : 0)
-                .apply();
+        final SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
+        mSurfaceTransactionHelper
+                .crop(tx, mLeash, destinationBounds)
+                .round(tx, mLeash, mInPip);
+        tx.apply();
     }
 
     private void finishResize(SurfaceControl.Transaction tx, Rect destinationBounds,
@@ -447,7 +441,6 @@
         mUpdateHandler.post(() -> mPipAnimationController
                 .getAnimator(mLeash, currentBounds, destinationBounds)
                 .setTransitionDirection(direction)
-                .setCornerRadius(mCornerRadius)
                 .setPipAnimationCallback(mPipAnimationCallback)
                 .setDuration(durationMs)
                 .start());
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
index 32e9a03..020627a 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipManager.java
@@ -42,6 +42,7 @@
 import com.android.systemui.pip.BasePipManager;
 import com.android.systemui.pip.PipBoundsHandler;
 import com.android.systemui.pip.PipSnapAlgorithm;
+import com.android.systemui.pip.PipSurfaceTransactionHelper;
 import com.android.systemui.pip.PipTaskOrganizer;
 import com.android.systemui.shared.recents.IPinnedStackAnimationListener;
 import com.android.systemui.shared.system.ActivityManagerWrapper;
@@ -210,7 +211,8 @@
             FloatingContentCoordinator floatingContentCoordinator,
             DeviceConfigProxy deviceConfig,
             PipBoundsHandler pipBoundsHandler,
-            PipSnapAlgorithm pipSnapAlgorithm) {
+            PipSnapAlgorithm pipSnapAlgorithm,
+            PipSurfaceTransactionHelper surfaceTransactionHelper) {
         mContext = context;
         mActivityManager = ActivityManager.getService();
 
@@ -224,7 +226,8 @@
 
         final IActivityTaskManager activityTaskManager = ActivityTaskManager.getService();
         mPipBoundsHandler = pipBoundsHandler;
-        mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler);
+        mPipTaskOrganizer = new PipTaskOrganizer(context, pipBoundsHandler,
+                surfaceTransactionHelper);
         mPipTaskOrganizer.registerPipTransitionCallback(this);
         mInputConsumerController = InputConsumerController.getPipInputConsumer();
         mMediaController = new PipMediaController(context, mActivityManager, broadcastDispatcher);
@@ -237,6 +240,12 @@
                 mTouchHandler.getMotionHelper());
         displayController.addDisplayChangingController(mRotationController);
 
+        // Ensure that we have the display info in case we get calls to update the bounds before the
+        // listener calls back
+        final DisplayInfo displayInfo = new DisplayInfo();
+        context.getDisplay().getDisplayInfo(displayInfo);
+        mPipBoundsHandler.onDisplayInfoChanged(displayInfo);
+
         try {
             ActivityTaskManager.getTaskOrganizerController().registerTaskOrganizer(
                     mPipTaskOrganizer, WINDOWING_MODE_PINNED);
diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
index 33760be..15a0088 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipMotionHelper.java
@@ -78,10 +78,10 @@
     private final Rect mBounds = new Rect();
 
     /** The bounds within which PIP's top-left coordinate is allowed to move. */
-    private Rect mMovementBounds = new Rect();
+    private final Rect mMovementBounds = new Rect();
 
     /** The region that all of PIP must stay within. */
-    private Rect mFloatingAllowedArea = new Rect();
+    private final Rect mFloatingAllowedArea = new Rect();
 
     /**
      * Bounds that are animated using the physics animator.
@@ -89,7 +89,7 @@
     private final Rect mAnimatedBounds = new Rect();
 
     /** The destination bounds to which PIP is animating. */
-    private Rect mAnimatingToBounds = new Rect();
+    private final Rect mAnimatingToBounds = new Rect();
 
     /** Coordinator instance for resolving conflicts with other floating content. */
     private FloatingContentCoordinator mFloatingContentCoordinator;
@@ -120,7 +120,7 @@
                 new PhysicsAnimator.SpringConfig(
                         SpringForce.STIFFNESS_LOW, SpringForce.DAMPING_RATIO_LOW_BOUNCY);
 
-    private final Consumer<Rect> mUpdateBoundsCallback = (toBounds) -> mBounds.set(toBounds);
+    private final Consumer<Rect> mUpdateBoundsCallback = mBounds::set;
 
     public PipMotionHelper(Context context, IActivityTaskManager activityTaskManager,
             PipTaskOrganizer pipTaskOrganizer, PipMenuActivityController menuController,
@@ -437,7 +437,7 @@
      * {@link FloatingContentCoordinator.FloatingContent#getFloatingBoundsOnScreen()}.
      */
     private void setAnimatingToBounds(Rect bounds) {
-        mAnimatingToBounds = bounds;
+        mAnimatingToBounds.set(bounds);
         mFloatingContentCoordinator.onContentMoved(this);
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
index 0c5a4d7..050acd5 100644
--- a/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
+++ b/packages/SystemUI/src/com/android/systemui/pip/tv/PipManager.java
@@ -20,8 +20,6 @@
 import static android.app.WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
 import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
 
-import static com.android.systemui.pip.PipAnimationController.DURATION_DEFAULT_MS;
-
 import android.app.ActivityManager.RunningTaskInfo;
 import android.app.ActivityManager.StackInfo;
 import android.app.ActivityTaskManager;
@@ -53,6 +51,7 @@
 import com.android.systemui.broadcast.BroadcastDispatcher;
 import com.android.systemui.pip.BasePipManager;
 import com.android.systemui.pip.PipBoundsHandler;
+import com.android.systemui.pip.PipSurfaceTransactionHelper;
 import com.android.systemui.pip.PipTaskOrganizer;
 import com.android.systemui.shared.system.ActivityManagerWrapper;
 import com.android.systemui.shared.system.PinnedStackListenerForwarder.PinnedStackListener;
@@ -136,6 +135,7 @@
     private String[] mLastPackagesResourceGranted;
     private PipNotification mPipNotification;
     private ParceledListSlice mCustomActions;
+    private int mResizeAnimationDuration;
 
     // Used to calculate the movement bounds
     private final DisplayInfo mTmpDisplayInfo = new DisplayInfo();
@@ -230,7 +230,8 @@
 
     @Inject
     public PipManager(Context context, BroadcastDispatcher broadcastDispatcher,
-            PipBoundsHandler pipBoundsHandler) {
+            PipBoundsHandler pipBoundsHandler,
+            PipSurfaceTransactionHelper surfaceTransactionHelper) {
         if (mInitialized) {
             return;
         }
@@ -238,7 +239,10 @@
         mInitialized = true;
         mContext = context;
         mPipBoundsHandler = pipBoundsHandler;
-        mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler);
+        mResizeAnimationDuration = context.getResources()
+                .getInteger(R.integer.config_pipResizeAnimationDuration);
+        mPipTaskOrganizer = new PipTaskOrganizer(mContext, mPipBoundsHandler,
+                surfaceTransactionHelper);
         mPipTaskOrganizer.registerPipTransitionCallback(this);
         mActivityTaskManager = ActivityTaskManager.getService();
         ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener);
@@ -436,7 +440,8 @@
                 mCurrentPipBounds = mPipBounds;
                 break;
         }
-        mPipTaskOrganizer.scheduleAnimateResizePip(mCurrentPipBounds, DURATION_DEFAULT_MS, null);
+        mPipTaskOrganizer.scheduleAnimateResizePip(mCurrentPipBounds, mResizeAnimationDuration,
+                null);
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
index 9ab4714..bf72b33 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSPanel.java
@@ -44,6 +44,8 @@
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.settingslib.Utils;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.media.InfoMediaManager;
 import com.android.settingslib.media.LocalMediaManager;
 import com.android.settingslib.media.MediaDevice;
 import com.android.systemui.Dependency;
@@ -98,6 +100,7 @@
     private final LinearLayout mMediaCarousel;
     private final ArrayList<QSMediaPlayer> mMediaPlayers = new ArrayList<>();
     private final NotificationMediaManager mNotificationMediaManager;
+    private final LocalBluetoothManager mLocalBluetoothManager;
     private final Executor mBackgroundExecutor;
     private LocalMediaManager mLocalMediaManager;
     private MediaDevice mDevice;
@@ -157,7 +160,8 @@
             BroadcastDispatcher broadcastDispatcher,
             QSLogger qsLogger,
             NotificationMediaManager notificationMediaManager,
-            @Background Executor backgroundExecutor
+            @Background Executor backgroundExecutor,
+            @Nullable LocalBluetoothManager localBluetoothManager
     ) {
         super(context, attrs);
         mContext = context;
@@ -165,6 +169,7 @@
         mDumpManager = dumpManager;
         mNotificationMediaManager = notificationMediaManager;
         mBackgroundExecutor = backgroundExecutor;
+        mLocalBluetoothManager = localBluetoothManager;
 
         setOrientation(VERTICAL);
 
@@ -286,7 +291,9 @@
 
             // Set up listener for device changes
             // TODO: integrate with MediaTransferManager?
-            mLocalMediaManager = new LocalMediaManager(mContext, null, null);
+            InfoMediaManager imm =
+                    new InfoMediaManager(mContext, null, null, mLocalBluetoothManager);
+            mLocalMediaManager = new LocalMediaManager(mContext, mLocalBluetoothManager, imm, null);
             mLocalMediaManager.startScan();
             mDevice = mLocalMediaManager.getCurrentConnectedDevice();
             mLocalMediaManager.registerCallback(mDeviceCallback);
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
index 3da767e..6654b7a 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QuickQSPanel.java
@@ -18,6 +18,7 @@
 
 import static com.android.systemui.util.InjectionInflationController.VIEW_CONTEXT;
 
+import android.annotation.Nullable;
 import android.content.Context;
 import android.content.res.Configuration;
 import android.graphics.Rect;
@@ -26,6 +27,7 @@
 import android.view.View;
 import android.widget.LinearLayout;
 
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
 import com.android.systemui.Dependency;
 import com.android.systemui.R;
 import com.android.systemui.broadcast.BroadcastDispatcher;
@@ -77,10 +79,11 @@
             BroadcastDispatcher broadcastDispatcher,
             QSLogger qsLogger,
             NotificationMediaManager notificationMediaManager,
-            @Background Executor backgroundExecutor
+            @Background Executor backgroundExecutor,
+            @Nullable LocalBluetoothManager localBluetoothManager
     ) {
         super(context, attrs, dumpManager, broadcastDispatcher, qsLogger, notificationMediaManager,
-                backgroundExecutor);
+                backgroundExecutor, localBluetoothManager);
         if (mFooter != null) {
             removeView(mFooter.getView());
         }
@@ -155,8 +158,6 @@
         Dependency.get(TunerService.class).removeTunable(mNumTiles);
     }
 
-
-
     @Override
     protected String getDumpableTag() {
         return TAG;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
index 3fe348f..94afde78 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/CommandQueue.java
@@ -262,7 +262,8 @@
 
         default void showAuthenticationDialog(Bundle bundle,
                 IBiometricServiceReceiverInternal receiver, int biometricModality,
-                boolean requireConfirmation, int userId, String opPackageName) { }
+                boolean requireConfirmation, int userId, String opPackageName,
+                long operationId) { }
         default void onBiometricAuthenticated() { }
         default void onBiometricHelp(String message) { }
         default void onBiometricError(int modality, int error, int vendorCode) { }
@@ -780,7 +781,8 @@
 
     @Override
     public void showAuthenticationDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver,
-            int biometricModality, boolean requireConfirmation, int userId, String opPackageName) {
+            int biometricModality, boolean requireConfirmation, int userId, String opPackageName,
+            long operationId) {
         synchronized (mLock) {
             SomeArgs args = SomeArgs.obtain();
             args.arg1 = bundle;
@@ -789,6 +791,7 @@
             args.arg3 = requireConfirmation;
             args.argi2 = userId;
             args.arg4 = opPackageName;
+            args.arg5 = operationId;
             mHandler.obtainMessage(MSG_BIOMETRIC_SHOW, args)
                     .sendToTarget();
         }
@@ -1164,7 +1167,8 @@
                                 someArgs.argi1 /* biometricModality */,
                                 (boolean) someArgs.arg3 /* requireConfirmation */,
                                 someArgs.argi2 /* userId */,
-                                (String) someArgs.arg4 /* opPackageName */);
+                                (String) someArgs.arg4 /* opPackageName */,
+                                (long) someArgs.arg5 /* operationId */);
                     }
                     someArgs.recycle();
                     break;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/MediaTransferManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/MediaTransferManager.java
index 18574f0..ac3523b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/MediaTransferManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/MediaTransferManager.java
@@ -32,6 +32,8 @@
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
+import com.android.settingslib.media.InfoMediaManager;
 import com.android.settingslib.media.LocalMediaManager;
 import com.android.settingslib.media.MediaDevice;
 import com.android.settingslib.media.MediaOutputSliceConstants;
@@ -106,7 +108,9 @@
     public MediaTransferManager(Context context) {
         mContext = context;
         mActivityStarter = Dependency.get(ActivityStarter.class);
-        mLocalMediaManager = new LocalMediaManager(mContext, null, null);
+        LocalBluetoothManager lbm = Dependency.get(LocalBluetoothManager.class);
+        InfoMediaManager imm = new InfoMediaManager(mContext, null, null, lbm);
+        mLocalMediaManager = new LocalMediaManager(mContext, lbm, imm, null);
     }
 
     /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java
index 0bfcdbd..4759d56 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java
@@ -23,6 +23,7 @@
 import android.text.TextUtils;
 import android.view.NotificationHeaderView;
 import android.view.View;
+import android.view.ViewGroup;
 import android.widget.ImageView;
 import android.widget.TextView;
 
@@ -182,24 +183,24 @@
 
     private void sanitizeChild(View child) {
         if (child != null) {
-            NotificationHeaderView header = (NotificationHeaderView) child.findViewById(
+            ViewGroup header = child.findViewById(
                     com.android.internal.R.id.notification_header);
             sanitizeHeader(header);
         }
     }
 
-    private void sanitizeHeader(NotificationHeaderView rowHeader) {
+    private void sanitizeHeader(ViewGroup rowHeader) {
         if (rowHeader == null) {
             return;
         }
         final int childCount = rowHeader.getChildCount();
         View time = rowHeader.findViewById(com.android.internal.R.id.time);
         boolean hasVisibleText = false;
-        for (int i = 1; i < childCount - 1 ; i++) {
+        for (int i = 0; i < childCount; i++) {
             View child = rowHeader.getChildAt(i);
             if (child instanceof TextView
                     && child.getVisibility() != View.GONE
-                    && !mDividers.contains(Integer.valueOf(child.getId()))
+                    && !mDividers.contains(child.getId())
                     && child != time) {
                 hasVisibleText = true;
                 break;
@@ -212,14 +213,14 @@
         time.setVisibility(timeVisibility);
         View left = null;
         View right;
-        for (int i = 1; i < childCount - 1 ; i++) {
+        for (int i = 0; i < childCount; i++) {
             View child = rowHeader.getChildAt(i);
-            if (mDividers.contains(Integer.valueOf(child.getId()))) {
+            if (mDividers.contains(child.getId())) {
                 boolean visible = false;
                 // Lets find the item to the right
-                for (i++; i < childCount - 1; i++) {
+                for (i++; i < childCount; i++) {
                     right = rowHeader.getChildAt(i);
-                    if (mDividers.contains(Integer.valueOf(right.getId()))) {
+                    if (mDividers.contains(right.getId())) {
                         // A divider was found, this needs to be hidden
                         i--;
                         break;
@@ -276,14 +277,18 @@
             if (!mApply) {
                 return;
             }
-            NotificationHeaderView header = row.getContractedNotificationHeader();
-            if (header == null) {
-                // No header found. We still consider this to be the same to avoid weird flickering
+            View contractedChild = row.getPrivateLayout().getContractedChild();
+            if (contractedChild == null) {
+                return;
+            }
+            View ownView = contractedChild.findViewById(mId);
+            if (ownView == null) {
+                // No view found. We still consider this to be the same to avoid weird flickering
                 // when for example showing an undo notification
                 return;
             }
             Object childData = mExtractor == null ? null : mExtractor.extractData(row);
-            mApply = mComparator.compare(mParentView, header.findViewById(mId),
+            mApply = mComparator.compare(mParentView, ownView,
                     mParentData, childData);
         }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
index 901ed3f..eb8526d 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt
@@ -58,6 +58,7 @@
     }
 
     lateinit var root: View
+    private var blurRoot: View? = null
     private var keyguardAnimator: Animator? = null
     private var notificationAnimator: Animator? = null
     private var updateScheduled: Boolean = false
@@ -72,6 +73,7 @@
             return shadeBlurRadius.toFloat()
         }
     })
+    private val zoomInterpolator = Interpolators.ACCELERATE_DECELERATE
     private var shadeBlurRadius = 0
         set(value) {
             if (field == value) return
@@ -84,6 +86,7 @@
             field = value
             scheduleUpdate()
         }
+    private var globalDialogVisibility = 0f
 
     /**
      * Callback that updates the window blur value and is called only once per frame.
@@ -91,9 +94,12 @@
     private val updateBlurCallback = Choreographer.FrameCallback {
         updateScheduled = false
 
-        val blur = max(shadeBlurRadius, wakeAndUnlockBlurRadius)
-        blurUtils.applyBlur(root.viewRootImpl, blur)
-        wallpaperManager.setWallpaperZoomOut(root.windowToken, blurUtils.ratioOfBlurRadius(blur))
+        val blur = max(shadeBlurRadius,
+                max(wakeAndUnlockBlurRadius, blurUtils.blurRadiusOfRatio(globalDialogVisibility)))
+        blurUtils.applyBlur(blurRoot?.viewRootImpl ?: root.viewRootImpl, blur)
+        val rawZoom = max(blurUtils.ratioOfBlurRadius(blur), globalDialogVisibility)
+        wallpaperManager.setWallpaperZoomOut(root.windowToken,
+                zoomInterpolator.getInterpolation(rawZoom))
     }
 
     /**
@@ -162,14 +168,23 @@
         shadeSpring.animateToFinalPosition(newBlur.toFloat())
     }
 
-    private fun scheduleUpdate() {
+    private fun scheduleUpdate(viewToBlur: View? = null) {
         if (updateScheduled) {
             return
         }
         updateScheduled = true
+        blurRoot = viewToBlur
         choreographer.postFrameCallback(updateBlurCallback)
     }
 
+    fun updateGlobalDialogVisibility(visibility: Float, dialogView: View) {
+        if (visibility == globalDialogVisibility) {
+            return
+        }
+        globalDialogVisibility = visibility
+        scheduleUpdate(dialogView)
+    }
+
     override fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<out String>) {
         IndentingPrintWriter(pw, "  ").let {
             it.println("StatusBarWindowBlurController:")
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ViewTransformationHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/ViewTransformationHelper.java
index 7b5a70e..2a45bc2 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ViewTransformationHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/ViewTransformationHelper.java
@@ -41,6 +41,7 @@
     private static final int TAG_CONTAINS_TRANSFORMED_VIEW = R.id.contains_transformed_view;
 
     private ArrayMap<Integer, View> mTransformedViews = new ArrayMap<>();
+    private ArraySet<Integer> mKeysTransformingToSimilar = new ArraySet<>();
     private ArrayMap<Integer, CustomTransformation> mCustomTransformations = new ArrayMap<>();
     private ValueAnimator mViewTransformationAnimation;
 
@@ -48,8 +49,22 @@
         mTransformedViews.put(key, transformedView);
     }
 
+    /**
+     * Add a view that transforms to a similar sibling, meaning that we should consider any mapping
+     * found treated as the same viewType. This is useful for imageViews, where it's hard to compare
+     * if the source images are the same when they are bitmap based.
+     *
+     * @param key The key how this is added
+     * @param transformedView the view that is added
+     */
+    public void addViewTransformingToSimilar(int key, View transformedView) {
+        addTransformedView(key, transformedView);
+        mKeysTransformingToSimilar.add(key);
+    }
+
     public void reset() {
         mTransformedViews.clear();
+        mKeysTransformingToSimilar.clear();
     }
 
     public void setCustomTransformation(CustomTransformation transformation, int viewType) {
@@ -60,7 +75,11 @@
     public TransformState getCurrentState(int fadingView) {
         View view = mTransformedViews.get(fadingView);
         if (view != null && view.getVisibility() != View.GONE) {
-            return TransformState.createFrom(view, this);
+            TransformState transformState = TransformState.createFrom(view, this);
+            if (mKeysTransformingToSimilar.contains(fadingView)) {
+                transformState.setIsSameAsAnyView(true);
+            }
+            return transformState;
         }
         return null;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/MessagingLayoutTransformState.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/MessagingLayoutTransformState.java
index b732966..9383f53 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/MessagingLayoutTransformState.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/MessagingLayoutTransformState.java
@@ -21,9 +21,9 @@
 import android.view.View;
 import android.view.ViewGroup;
 
+import com.android.internal.widget.IMessagingLayout;
 import com.android.internal.widget.MessagingGroup;
 import com.android.internal.widget.MessagingImageMessage;
-import com.android.internal.widget.MessagingLayout;
 import com.android.internal.widget.MessagingLinearLayout;
 import com.android.internal.widget.MessagingMessage;
 import com.android.internal.widget.MessagingPropertyAnimator;
@@ -41,7 +41,7 @@
     private static Pools.SimplePool<MessagingLayoutTransformState> sInstancePool
             = new Pools.SimplePool<>(40);
     private MessagingLinearLayout mMessageContainer;
-    private MessagingLayout mMessagingLayout;
+    private IMessagingLayout mMessagingLayout;
     private HashMap<MessagingGroup, MessagingGroup> mGroupMap = new HashMap<>();
     private float mRelativeTranslationOffset;
 
@@ -266,8 +266,9 @@
             transformView(transformationAmount, to, child, otherChild, false, /* sameAsAny */
                     useLinearTransformation);
             boolean otherIsIsolated = otherGroup.getIsolatedMessage() == otherChild;
-            if (transformationAmount == 0.0f && otherIsIsolated) {
-                ownGroup.setTransformingImages(true);
+            if (transformationAmount == 0.0f
+                    && (otherIsIsolated || otherGroup.isSingleLine())) {
+                ownGroup.setClippingDisabled(true);
             }
             if (otherChild == null) {
                 child.setTranslationY(previousTranslation);
@@ -291,11 +292,20 @@
         if (useLinearTransformation) {
             ownState.setDefaultInterpolator(Interpolators.LINEAR);
         }
-        ownState.setIsSameAsAnyView(sameAsAny);
+        ownState.setIsSameAsAnyView(sameAsAny && !isGone(otherView));
         if (to) {
             if (otherView != null) {
                 TransformState otherState = TransformState.createFrom(otherView, mTransformInfo);
-                ownState.transformViewTo(otherState, transformationAmount);
+                if (!isGone(otherView)) {
+                    ownState.transformViewTo(otherState, transformationAmount);
+                } else {
+                    if (!isGone(ownView)) {
+                        ownState.disappear(transformationAmount, null);
+                    }
+                    // We still want to transform vertically if the view is gone,
+                    // since avatars serve as anchors for the rest of the layout transition
+                    ownState.transformViewVerticalTo(otherState, transformationAmount);
+                }
                 otherState.recycle();
             } else {
                 ownState.disappear(transformationAmount, null);
@@ -303,7 +313,16 @@
         } else {
             if (otherView != null) {
                 TransformState otherState = TransformState.createFrom(otherView, mTransformInfo);
-                ownState.transformViewFrom(otherState, transformationAmount);
+                if (!isGone(otherView)) {
+                    ownState.transformViewFrom(otherState, transformationAmount);
+                } else {
+                    if (!isGone(ownView)) {
+                        ownState.appear(transformationAmount, null);
+                    }
+                    // We still want to transform vertically if the view is gone,
+                    // since avatars serve as anchors for the rest of the layout transition
+                    ownState.transformViewVerticalFrom(otherState, transformationAmount);
+                }
                 otherState.recycle();
             } else {
                 ownState.appear(transformationAmount, null);
@@ -337,6 +356,9 @@
     }
 
     private boolean isGone(View view) {
+        if (view == null) {
+            return true;
+        }
         if (view.getVisibility() == View.GONE) {
             return true;
         }
@@ -408,7 +430,7 @@
                 ownGroup.getMessageContainer().setTranslationY(0);
                 ownGroup.getSenderView().setTranslationY(0);
             }
-            ownGroup.setTransformingImages(false);
+            ownGroup.setClippingDisabled(false);
             ownGroup.updateClipRect();
         }
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
index 9a4e789..f61fe98 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ExpandableNotificationRow.java
@@ -31,7 +31,6 @@
 import android.animation.ValueAnimator.AnimatorUpdateListener;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
-import android.app.Notification;
 import android.app.NotificationChannel;
 import android.content.Context;
 import android.content.pm.PackageInfo;
@@ -151,7 +150,6 @@
     private int mNotificationMinHeight;
     private int mNotificationMinHeightLarge;
     private int mNotificationMinHeightMedia;
-    private int mNotificationMinHeightMessaging;
     private int mNotificationMaxHeight;
     private int mIncreasedPaddingBetweenElements;
     private int mNotificationLaunchHeight;
@@ -640,16 +638,10 @@
                 && expandedView.findViewById(com.android.internal.R.id.media_actions) != null;
         boolean showCompactMediaSeekbar = mMediaManager.getShowCompactMediaSeekbar();
 
-        Class<? extends Notification.Style> style =
-                mEntry.getSbn().getNotification().getNotificationStyle();
-        boolean isMessagingLayout = Notification.MessagingStyle.class.equals(style);
-
         if (customView && beforeP && !mIsSummaryWithChildren) {
             minHeight = beforeN ? mNotificationMinHeightBeforeN : mNotificationMinHeightBeforeP;
         } else if (isMediaLayout && showCompactMediaSeekbar) {
             minHeight = mNotificationMinHeightMedia;
-        } else if (isMessagingLayout) {
-            minHeight = mNotificationMinHeightMessaging;
         } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) {
             minHeight = mNotificationMinHeightLarge;
         } else {
@@ -1057,19 +1049,6 @@
         return getShowingLayout().getVisibleNotificationHeader();
     }
 
-
-    /**
-     * @return the contracted notification header. This can be different from
-     * {@link #getNotificationHeader()} and also {@link #getVisibleNotificationHeader()} and only
-     * returns the contracted version.
-     */
-    public NotificationHeaderView getContractedNotificationHeader() {
-        if (mIsSummaryWithChildren) {
-            return mChildrenContainer.getHeaderView();
-        }
-        return mPrivateLayout.getContractedNotificationHeader();
-    }
-
     public void setLongPressListener(LongPressListener longPressListener) {
         mLongPressListener = longPressListener;
     }
@@ -1654,8 +1633,6 @@
                 R.dimen.notification_min_height_increased);
         mNotificationMinHeightMedia = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_min_height_media);
-        mNotificationMinHeightMessaging = NotificationUtils.getFontScaledHeight(mContext,
-                R.dimen.notification_min_height_messaging);
         mNotificationMaxHeight = NotificationUtils.getFontScaledHeight(mContext,
                 R.dimen.notification_max_height);
         mMaxHeadsUpHeightBeforeN = NotificationUtils.getFontScaledHeight(mContext,
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java
index 6dd4ff9..91cf285 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentInflater.java
@@ -25,6 +25,8 @@
 import android.annotation.Nullable;
 import android.app.Notification;
 import android.content.Context;
+import android.content.ContextWrapper;
+import android.content.pm.ApplicationInfo;
 import android.os.AsyncTask;
 import android.os.CancellationSignal;
 import android.service.notification.StatusBarNotification;
@@ -716,6 +718,10 @@
                         sbn.getNotification());
 
                 Context packageContext = sbn.getPackageContext(mContext);
+                if (recoveredBuilder.usesTemplate()) {
+                    // For all of our templates, we want it to be RTL
+                    packageContext = new RtlEnabledContext(packageContext);
+                }
                 Notification notification = sbn.getNotification();
                 if (notification.isMediaNotification()) {
                     MediaNotificationProcessor processor = new MediaNotificationProcessor(mContext,
@@ -782,6 +788,19 @@
             // try to purge unnecessary cached entries.
             mRow.getImageResolver().purgeCache();
         }
+
+        private class RtlEnabledContext extends ContextWrapper {
+            private RtlEnabledContext(Context packageContext) {
+                super(packageContext);
+            }
+
+            @Override
+            public ApplicationInfo getApplicationInfo() {
+                ApplicationInfo applicationInfo = super.getApplicationInfo();
+                applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
+                return applicationInfo;
+            }
+        }
     }
 
     @VisibleForTesting
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
index 27fd1b2..8b8a901 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
@@ -1492,13 +1492,6 @@
         }
     }
 
-    public NotificationHeaderView getContractedNotificationHeader() {
-        if (mContractedChild != null) {
-            return mContractedWrapper.getNotificationHeader();
-        }
-        return null;
-    }
-
     public NotificationHeaderView getVisibleNotificationHeader() {
         NotificationViewWrapper wrapper = getVisibleWrapper(mVisibleType);
         return wrapper == null ? null : wrapper.getNotificationHeader();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationConversationTemplateViewWrapper.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationConversationTemplateViewWrapper.kt
new file mode 100644
index 0000000..1e2571b5
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationConversationTemplateViewWrapper.kt
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.systemui.statusbar.notification.row.wrapper
+
+import android.content.Context
+import android.view.View
+
+import com.android.internal.widget.ConversationLayout
+import com.android.internal.widget.MessagingLinearLayout
+import com.android.systemui.R
+import com.android.systemui.statusbar.notification.NotificationUtils
+import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
+
+/**
+ * Wraps a notification containing a converation template
+ */
+class NotificationConversationTemplateViewWrapper constructor(
+    ctx: Context,
+    view: View,
+    row: ExpandableNotificationRow
+)
+    : NotificationTemplateViewWrapper(ctx, view, row) {
+
+    private val minHeightWithActions: Int
+    private val conversationLayout: ConversationLayout
+    private var conversationIcon: View? = null
+    private var conversationBadge: View? = null
+    private var expandButton: View? = null
+    private var messagingLinearLayout: MessagingLinearLayout? = null
+
+    init {
+        conversationLayout = view as ConversationLayout
+        minHeightWithActions = NotificationUtils.getFontScaledHeight(ctx,
+                R.dimen.notification_messaging_actions_min_height)
+    }
+
+    private fun resolveViews() {
+        messagingLinearLayout = conversationLayout.messagingLinearLayout
+        conversationIcon = conversationLayout.requireViewById(
+                com.android.internal.R.id.conversation_icon)
+        conversationBadge = conversationLayout.requireViewById(
+                com.android.internal.R.id.conversation_icon_badge)
+        expandButton = conversationLayout.requireViewById(
+                com.android.internal.R.id.expand_button)
+    }
+
+    override fun onContentUpdated(row: ExpandableNotificationRow) {
+        // Reinspect the notification. Before the super call, because the super call also updates
+        // the transformation types and we need to have our values set by then.
+        resolveViews()
+        super.onContentUpdated(row)
+    }
+
+    override fun updateTransformedTypes() {
+        // This also clears the existing types
+        super.updateTransformedTypes()
+        messagingLinearLayout?.let {
+            mTransformationHelper.addTransformedView(it.id, it)
+        }
+        conversationIcon?.let {
+            mTransformationHelper.addViewTransformingToSimilar(it.id, it)
+        }
+        conversationBadge?.let {
+            mTransformationHelper.addViewTransformingToSimilar(it.id, it)
+        }
+        expandButton?.let {
+            mTransformationHelper.addViewTransformingToSimilar(it.id, it)
+        }
+    }
+
+    override fun setRemoteInputVisible(visible: Boolean) {
+        conversationLayout.showHistoricMessages(visible)
+    }
+
+    override fun updateExpandability(expandable: Boolean, onClickListener: View.OnClickListener?) {
+        conversationLayout.updateExpandability(expandable, onClickListener)
+    }
+
+    override fun getMinLayoutHeight(): Int {
+        if (mActionsContainer != null && mActionsContainer.visibility != View.GONE) {
+            return minHeightWithActions
+        } else {
+            return super.getMinLayoutHeight()
+        }
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java
index 5e52c0a..1d06198 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationHeaderViewWrapper.java
@@ -53,12 +53,13 @@
     protected final ViewTransformationHelper mTransformationHelper;
 
     protected int mColor;
-    private ImageView mIcon;
 
+    private ImageView mIcon;
     private NotificationExpandButton mExpandButton;
     protected NotificationHeaderView mNotificationHeader;
     private TextView mHeaderText;
     private ImageView mWorkProfileImage;
+
     private boolean mIsLowPriority;
     private boolean mTransformLowPriorityTitle;
     private boolean mShowExpandButtonAtEnd;
@@ -105,12 +106,16 @@
         mExpandButton = mView.findViewById(com.android.internal.R.id.expand_button);
         mWorkProfileImage = mView.findViewById(com.android.internal.R.id.profile_badge);
         mNotificationHeader = mView.findViewById(com.android.internal.R.id.notification_header);
-        mNotificationHeader.setShowExpandButtonAtEnd(mShowExpandButtonAtEnd);
-        mColor = mNotificationHeader.getOriginalIconColor();
+        if (mNotificationHeader != null) {
+            mNotificationHeader.setShowExpandButtonAtEnd(mShowExpandButtonAtEnd);
+            mColor = mNotificationHeader.getOriginalIconColor();
+        }
     }
 
     private void addAppOpsOnClickListener(ExpandableNotificationRow row) {
-        mNotificationHeader.setAppOpsOnClickListener(row.getAppOpsOnClickListener());
+        if (mNotificationHeader != null) {
+            mNotificationHeader.setAppOpsOnClickListener(row.getAppOpsOnClickListener());
+        }
     }
 
     @Override
@@ -127,9 +132,11 @@
         updateCropToPaddingForImageViews();
         Notification notification = row.getEntry().getSbn().getNotification();
         mIcon.setTag(ImageTransformState.ICON_TAG, notification.getSmallIcon());
-        // The work profile image is always the same lets just set the icon tag for it not to
-        // animate
-        mWorkProfileImage.setTag(ImageTransformState.ICON_TAG, notification.getSmallIcon());
+        if (mWorkProfileImage != null) {
+            // The work profile image is always the same lets just set the icon tag for it not to
+            // animate
+            mWorkProfileImage.setTag(ImageTransformState.ICON_TAG, notification.getSmallIcon());
+        }
 
         // We need to reset all views that are no longer transforming in case a view was previously
         // transformed, but now we decided to transform its container instead.
@@ -174,8 +181,9 @@
 
     protected void updateTransformedTypes() {
         mTransformationHelper.reset();
-        mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_ICON, mIcon);
-        if (mIsLowPriority) {
+        mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_ICON,
+                mIcon);
+        if (mIsLowPriority && mHeaderText != null) {
             mTransformationHelper.addTransformedView(TransformableView.TRANSFORMING_VIEW_TITLE,
                     mHeaderText);
         }
@@ -184,7 +192,9 @@
     @Override
     public void updateExpandability(boolean expandable, View.OnClickListener onClickListener) {
         mExpandButton.setVisibility(expandable ? View.VISIBLE : View.GONE);
-        mNotificationHeader.setOnClickListener(expandable ? onClickListener : null);
+        if (mNotificationHeader != null) {
+            mNotificationHeader.setOnClickListener(expandable ? onClickListener : null);
+        }
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationTemplateViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationTemplateViewWrapper.java
index 0a1a2fe..d41f5af 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationTemplateViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationTemplateViewWrapper.java
@@ -353,8 +353,12 @@
     @Override
     public void setHeaderVisibleAmount(float headerVisibleAmount) {
         super.setHeaderVisibleAmount(headerVisibleAmount);
-        mNotificationHeader.setAlpha(headerVisibleAmount);
-        mHeaderTranslation = (1.0f - headerVisibleAmount) * mFullHeaderTranslation;
+        float headerTranslation = 0f;
+        if (mNotificationHeader != null) {
+            mNotificationHeader.setAlpha(headerVisibleAmount);
+            headerTranslation = (1.0f - headerVisibleAmount) * mFullHeaderTranslation;
+        }
+        mHeaderTranslation = headerTranslation;
         mView.setTranslationY(mHeaderTranslation);
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapper.java
index c2eff8a..c834e4b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/wrapper/NotificationViewWrapper.java
@@ -35,6 +35,7 @@
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.graphics.ColorUtils;
 import com.android.internal.util.ContrastColorUtil;
+import com.android.internal.widget.ConversationLayout;
 import com.android.systemui.statusbar.CrossFadeHelper;
 import com.android.systemui.statusbar.TransformableView;
 import com.android.systemui.statusbar.notification.TransformState;
@@ -61,6 +62,9 @@
                 return new NotificationMediaTemplateViewWrapper(ctx, v, row);
             } else if ("messaging".equals(v.getTag())) {
                 return new NotificationMessagingTemplateViewWrapper(ctx, v, row);
+            } else if ("conversation".equals(v.getTag())) {
+                return new NotificationConversationTemplateViewWrapper(ctx, (ConversationLayout) v,
+                        row);
             }
             Class<? extends Notification.Style> style =
                     row.getEntry().getSbn().getNotification().getNotificationStyle();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
index ee31300..90bc075b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java
@@ -492,7 +492,7 @@
                     try {
                         result = ActivityTaskManager.getService().startActivityAsUser(
                                 null, getContext().getBasePackageName(),
-                                getContext().getFeatureId(), intent,
+                                getContext().getAttributionTag(), intent,
                                 intent.resolveTypeIfNeeded(getContext().getContentResolver()),
                                 null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null, o.toBundle(),
                                 UserHandle.CURRENT.getIdentifier());
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
index e6f24c2..d343090 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java
@@ -2602,7 +2602,7 @@
             }
             try {
                 result = ActivityTaskManager.getService().startActivityAsUser(
-                        null, mContext.getBasePackageName(), mContext.getFeatureId(),
+                        null, mContext.getBasePackageName(), mContext.getAttributionTag(),
                         intent,
                         intent.resolveTypeIfNeeded(mContext.getContentResolver()),
                         null, null, 0, Intent.FLAG_ACTIVITY_NEW_TASK, null,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
index c6c7b87..1db8e4c 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
@@ -78,7 +78,9 @@
 
         mAuthContainer.mBiometricCallback.onAction(
                 AuthBiometricView.Callback.ACTION_AUTHENTICATED);
-        verify(mCallback).onDismissed(eq(AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED));
+        verify(mCallback).onDismissed(
+                eq(AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
@@ -87,7 +89,9 @@
 
         mAuthContainer.mBiometricCallback.onAction(
                 AuthBiometricView.Callback.ACTION_USER_CANCELED);
-        verify(mCallback).onDismissed(eq(AuthDialogCallback.DISMISSED_USER_CANCELED));
+        verify(mCallback).onDismissed(
+                eq(AuthDialogCallback.DISMISSED_USER_CANCELED),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
@@ -96,7 +100,9 @@
 
         mAuthContainer.mBiometricCallback.onAction(
                 AuthBiometricView.Callback.ACTION_BUTTON_NEGATIVE);
-        verify(mCallback).onDismissed(eq(AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE));
+        verify(mCallback).onDismissed(
+                eq(AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
@@ -114,7 +120,9 @@
 
         mAuthContainer.mBiometricCallback.onAction(
                 AuthBiometricView.Callback.ACTION_ERROR);
-        verify(mCallback).onDismissed(AuthDialogCallback.DISMISSED_ERROR);
+        verify(mCallback).onDismissed(
+                eq(AuthDialogCallback.DISMISSED_ERROR),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
@@ -219,7 +227,8 @@
 
         @Override
         public void animateAway(int reason) {
-            mConfig.mCallback.onDismissed(reason);
+            // TODO: Credential attestation should be testable/tested
+            mConfig.mCallback.onDismissed(reason, null /* credentialAttestation */);
         }
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
index 65399bf..fc1ddf7 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
@@ -57,12 +57,14 @@
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.AdditionalMatchers;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Random;
 
 @RunWith(AndroidTestingRunner.class)
 @RunWithLooper
@@ -110,52 +112,75 @@
     @Test
     public void testSendsReasonUserCanceled_whenDismissedByUserCancel() throws Exception {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED);
-        verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED,
+                null /* credentialAttestation */);
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_USER_CANCEL),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
     public void testSendsReasonNegative_whenDismissedByButtonNegative() throws Exception {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE);
-        verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_NEGATIVE);
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE,
+                null /* credentialAttestation */);
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_NEGATIVE),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
     public void testSendsReasonConfirmed_whenDismissedByButtonPositive() throws Exception {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BUTTON_POSITIVE);
-        verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED);
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BUTTON_POSITIVE,
+                null /* credentialAttestation */);
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
     public void testSendsReasonConfirmNotRequired_whenDismissedByAuthenticated() throws Exception {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED);
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED,
+                null /* credentialAttestation */);
         verify(mReceiver).onDialogDismissed(
-                BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED);
+                eq(BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
     public void testSendsReasonError_whenDismissedByError() throws Exception {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_ERROR);
-        verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_ERROR);
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_ERROR,
+                null /* credentialAttestation */);
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_ERROR),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
     public void testSendsReasonServerRequested_whenDismissedByServer() throws Exception {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BY_SYSTEM_SERVER);
-        verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_SERVER_REQUESTED);
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BY_SYSTEM_SERVER,
+                null /* credentialAttestation */);
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_SERVER_REQUESTED),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
     public void testSendsReasonCredentialConfirmed_whenDeviceCredentialAuthenticated()
             throws Exception {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED);
-        verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED);
+
+        final byte[] credentialAttestation = generateRandomHAT();
+
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED,
+                credentialAttestation);
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED),
+                AdditionalMatchers.aryEq(credentialAttestation));
     }
 
     // Statusbar tests
@@ -302,8 +327,13 @@
         showDialog(Authenticators.DEVICE_CREDENTIAL, BiometricPrompt.TYPE_NONE);
         verify(mDialog1).show(any(), any());
 
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED);
-        verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED);
+        final byte[] credentialAttestation = generateRandomHAT();
+
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED,
+                credentialAttestation);
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED),
+                AdditionalMatchers.aryEq(credentialAttestation));
 
         mAuthController.hideAuthenticationDialog();
     }
@@ -395,20 +425,24 @@
         assertNull(mAuthController.mCurrentDialog);
         assertNull(mAuthController.mReceiver);
         verify(mDialog1).dismissWithoutCallback(true /* animate */);
-        verify(mReceiver).onDialogDismissed(eq(BiometricPrompt.DISMISSED_REASON_USER_CANCEL));
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_USER_CANCEL),
+                eq(null) /* credentialAttestation */);
     }
 
     @Test
     public void testDoesNotCrash_whenTryAgainPressedAfterDismissal() {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED);
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED,
+                null /* credentialAttestation */);
         mAuthController.onTryAgainPressed();
     }
 
     @Test
     public void testDoesNotCrash_whenDeviceCredentialPressedAfterDismissal() {
         showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
-        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED);
+        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED,
+                null /* credentialAttestation */);
         mAuthController.onDeviceCredentialPressed();
     }
 
@@ -422,7 +456,9 @@
         assertNull(mAuthController.mCurrentDialog);
         assertNull(mAuthController.mReceiver);
         verify(mDialog1).dismissWithoutCallback(true /* animate */);
-        verify(mReceiver).onDialogDismissed(eq(BiometricPrompt.DISMISSED_REASON_USER_CANCEL));
+        verify(mReceiver).onDialogDismissed(
+                eq(BiometricPrompt.DISMISSED_REASON_USER_CANCEL),
+                eq(null) /* credentialAttestation */);
     }
 
     // Helpers
@@ -433,7 +469,8 @@
                 biometricModality,
                 true /* requireConfirmation */,
                 0 /* userId */,
-                "testPackage");
+                "testPackage",
+                0 /* operationId */);
     }
 
     private Bundle createTestDialogBundle(int authenticators) {
@@ -453,6 +490,13 @@
         return bundle;
     }
 
+    private byte[] generateRandomHAT() {
+        byte[] HAT = new byte[69];
+        Random random = new Random();
+        random.nextBytes(HAT);
+        return HAT;
+    }
+
     private final class TestableAuthController extends AuthController {
         private int mBuildCount = 0;
         private Bundle mLastBiometricPromptBundle;
@@ -464,7 +508,7 @@
         @Override
         protected AuthDialog buildDialog(Bundle biometricPromptBundle,
                 boolean requireConfirmation, int userId, int type, String opPackageName,
-                boolean skipIntro) {
+                boolean skipIntro, long operationId) {
 
             mLastBiometricPromptBundle = biometricPromptBundle;
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/pip/PipAnimationControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/pip/PipAnimationControllerTest.java
index a2ab784..b863f14 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/pip/PipAnimationControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/pip/PipAnimationControllerTest.java
@@ -58,7 +58,8 @@
 
     @Before
     public void setUp() throws Exception {
-        mPipAnimationController = new PipAnimationController(mContext);
+        mPipAnimationController = new PipAnimationController(
+                mContext, new PipSurfaceTransactionHelper(mContext));
         MockitoAnnotations.initMocks(this);
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java
index 616399a..ac30421 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/qs/QSPanelTest.java
@@ -35,6 +35,7 @@
 
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settingslib.bluetooth.LocalBluetoothManager;
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.broadcast.BroadcastDispatcher;
 import com.android.systemui.dump.DumpManager;
@@ -85,6 +86,8 @@
     private NotificationMediaManager mNotificationMediaManager;
     @Mock
     private Executor mBackgroundExecutor;
+    @Mock
+    private LocalBluetoothManager mLocalBluetoothManager;
 
     @Before
     public void setup() throws Exception {
@@ -94,7 +97,8 @@
         mTestableLooper.runWithLooper(() -> {
             mMetricsLogger = mDependency.injectMockDependency(MetricsLogger.class);
             mQsPanel = new QSPanel(mContext, null, mDumpManager, mBroadcastDispatcher,
-                    mQSLogger, mNotificationMediaManager, mBackgroundExecutor);
+                    mQSLogger, mNotificationMediaManager, mBackgroundExecutor,
+                    mLocalBluetoothManager);
             // Provides a parent with non-zero size for QSPanel
             mParentView = new FrameLayout(mContext);
             mParentView.addView(mQsPanel);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/CommandQueueTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/CommandQueueTest.java
index 7c6da63..cffcabb 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/CommandQueueTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/CommandQueueTest.java
@@ -409,11 +409,12 @@
     public void testShowAuthenticationDialog() {
         Bundle bundle = new Bundle();
         String packageName = "test";
+        final long operationId = 1;
         mCommandQueue.showAuthenticationDialog(bundle, null /* receiver */, 1, true, 3,
-                packageName);
+                packageName, operationId);
         waitForIdleSync();
         verify(mCallbacks).showAuthenticationDialog(eq(bundle), eq(null), eq(1), eq(true), eq(3),
-                eq(packageName));
+                eq(packageName), eq(operationId));
     }
 
     @Test
diff --git a/services/autofill/java/com/android/server/autofill/InlineSuggestionSession.java b/services/autofill/java/com/android/server/autofill/InlineSuggestionSession.java
index 7fe086d..3376f2b 100644
--- a/services/autofill/java/com/android/server/autofill/InlineSuggestionSession.java
+++ b/services/autofill/java/com/android/server/autofill/InlineSuggestionSession.java
@@ -23,6 +23,7 @@
 import android.annotation.Nullable;
 import android.content.ComponentName;
 import android.os.Bundle;
+import android.os.Handler;
 import android.os.RemoteException;
 import android.util.Log;
 import android.util.Slog;
@@ -38,11 +39,8 @@
 
 import java.util.Collections;
 import java.util.Optional;
-import java.util.concurrent.CancellationException;
 import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
+import java.util.function.Consumer;
 
 /**
  * Maintains an autofill inline suggestion session that communicates with the IME.
@@ -69,7 +67,7 @@
 final class InlineSuggestionSession {
 
     private static final String TAG = "AfInlineSuggestionSession";
-    private static final int INLINE_REQUEST_TIMEOUT_MS = 1000;
+    private static final int INLINE_REQUEST_TIMEOUT_MS = 200;
 
     @NonNull
     private final InputMethodManagerInternal mInputMethodManagerInternal;
@@ -80,6 +78,8 @@
     private final Object mLock;
     @NonNull
     private final ImeStatusListener mImeStatusListener;
+    @NonNull
+    private final Handler mHandler;
 
     /**
      * To avoid the race condition, one should not access {@code mPendingImeResponse} without
@@ -105,10 +105,11 @@
     private boolean mImeInputViewStarted = false;
 
     InlineSuggestionSession(InputMethodManagerInternal inputMethodManagerInternal,
-            int userId, ComponentName componentName) {
+            int userId, ComponentName componentName, Handler handler) {
         mInputMethodManagerInternal = inputMethodManagerInternal;
         mUserId = userId;
         mComponentName = componentName;
+        mHandler = handler;
         mLock = new Object();
         mImeStatusListener = new ImeStatusListener() {
             @Override
@@ -137,7 +138,8 @@
         };
     }
 
-    public void onCreateInlineSuggestionsRequest(@NonNull AutofillId autofillId) {
+    public void onCreateInlineSuggestionsRequest(@NonNull AutofillId autofillId,
+            @NonNull Consumer<InlineSuggestionsRequest> requestConsumer) {
         if (sDebug) Log.d(TAG, "onCreateInlineSuggestionsRequest called for " + autofillId);
 
         synchronized (mLock) {
@@ -154,26 +156,16 @@
                     mUserId,
                     new InlineSuggestionsRequestInfo(mComponentName, autofillId, new Bundle()),
                     new InlineSuggestionsRequestCallbackImpl(mPendingImeResponse,
-                            mImeStatusListener));
+                            mImeStatusListener, requestConsumer, mHandler, mLock));
         }
     }
 
-    public Optional<InlineSuggestionsRequest> waitAndGetInlineSuggestionsRequest() {
+    public Optional<InlineSuggestionsRequest> getInlineSuggestionsRequest() {
         final CompletableFuture<ImeResponse> pendingImeResponse = getPendingImeResponse();
-        if (pendingImeResponse == null) {
+        if (pendingImeResponse == null || !pendingImeResponse.isDone()) {
             return Optional.empty();
         }
-        try {
-            return Optional.ofNullable(pendingImeResponse.get(INLINE_REQUEST_TIMEOUT_MS,
-                    TimeUnit.MILLISECONDS)).map(ImeResponse::getRequest);
-        } catch (TimeoutException e) {
-            Log.w(TAG, "Exception getting inline suggestions request in time: " + e);
-        } catch (CancellationException e) {
-            Log.w(TAG, "Inline suggestions request cancelled");
-        } catch (InterruptedException | ExecutionException e) {
-            throw new RuntimeException(e);
-        }
-        return Optional.empty();
+        return Optional.ofNullable(pendingImeResponse.getNow(null)).map(ImeResponse::getRequest);
     }
 
     public boolean hideInlineSuggestionsUi(@NonNull AutofillId autofillId) {
@@ -200,8 +192,7 @@
             if (sDebug) Log.d(TAG, "onInlineSuggestionsResponseLocked without IMS request");
             return false;
         }
-        // There is no need to wait on the CompletableFuture since it should have been completed
-        // when {@link #waitAndGetInlineSuggestionsRequest()} was called.
+        // There is no need to wait on the CompletableFuture since it should have been completed.
         ImeResponse imeResponse = completedImsResponse.getNow(null);
         if (imeResponse == null) {
             if (sDebug) Log.d(TAG, "onInlineSuggestionsResponseLocked with pending IMS response");
@@ -249,20 +240,50 @@
     private static final class InlineSuggestionsRequestCallbackImpl
             extends IInlineSuggestionsRequestCallback.Stub {
 
+        private final Object mLock;
+        @GuardedBy("mLock")
         private final CompletableFuture<ImeResponse> mResponse;
+        @GuardedBy("mLock")
+        private final Consumer<InlineSuggestionsRequest> mRequestConsumer;
         private final ImeStatusListener mImeStatusListener;
+        private final Handler mHandler;
+        private final Runnable mTimeoutCallback;
 
         private InlineSuggestionsRequestCallbackImpl(CompletableFuture<ImeResponse> response,
-                ImeStatusListener imeStatusListener) {
+                ImeStatusListener imeStatusListener,
+                Consumer<InlineSuggestionsRequest> requestConsumer,
+                Handler handler, Object lock) {
             mResponse = response;
             mImeStatusListener = imeStatusListener;
+            mRequestConsumer = requestConsumer;
+            mLock = lock;
+
+            mHandler = handler;
+            mTimeoutCallback = () -> {
+                Log.w(TAG, "Timed out waiting for IME callback InlineSuggestionsRequest.");
+                synchronized (mLock) {
+                    completeIfNotLocked(null);
+                }
+            };
+            mHandler.postDelayed(mTimeoutCallback, INLINE_REQUEST_TIMEOUT_MS);
+        }
+
+        private void completeIfNotLocked(@Nullable ImeResponse response) {
+            if (mResponse.isDone()) {
+                return;
+            }
+            mResponse.complete(response);
+            mRequestConsumer.accept(response == null ? null : response.mRequest);
+            mHandler.removeCallbacks(mTimeoutCallback);
         }
 
         @BinderThread
         @Override
         public void onInlineSuggestionsUnsupported() throws RemoteException {
             if (sDebug) Log.d(TAG, "onInlineSuggestionsUnsupported() called.");
-            mResponse.complete(null);
+            synchronized (mLock) {
+                completeIfNotLocked(null);
+            }
         }
 
         @BinderThread
@@ -281,9 +302,13 @@
                 mImeStatusListener.onInputMethodFinishInputView(imeFieldId);
             }
             if (request != null && callback != null) {
-                mResponse.complete(new ImeResponse(request, callback));
+                synchronized (mLock) {
+                    completeIfNotLocked(new ImeResponse(request, callback));
+                }
             } else {
-                mResponse.complete(null);
+                synchronized (mLock) {
+                    completeIfNotLocked(null);
+                }
             }
         }
 
diff --git a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
index e73f9ce..53afa6e 100644
--- a/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
+++ b/services/autofill/java/com/android/server/autofill/RemoteAugmentedAutofillService.java
@@ -57,6 +57,7 @@
 import com.android.internal.os.IResultReceiver;
 import com.android.server.autofill.ui.InlineSuggestionFactory;
 
+import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.TimeUnit;
@@ -255,8 +256,12 @@
                             mCallbacks.logAugmentedAutofillSelected(sessionId,
                                     dataset.getId());
                             try {
-                                client.autofill(sessionId, dataset.getFieldIds(),
-                                        dataset.getFieldValues());
+                                final ArrayList<AutofillId> fieldIds = dataset.getFieldIds();
+                                final int size = fieldIds.size();
+                                final boolean hideHighlight = size == 1
+                                        && fieldIds.get(0).equals(focusedId);
+                                client.autofill(sessionId, fieldIds, dataset.getFieldValues(),
+                                        hideHighlight);
                             } catch (RemoteException e) {
                                 Slog.w(TAG, "Encounter exception autofilling the values");
                             }
diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java
index 8265009..5064663 100644
--- a/services/autofill/java/com/android/server/autofill/Session.java
+++ b/services/autofill/java/com/android/server/autofill/Session.java
@@ -114,7 +114,9 @@
 import java.util.List;
 import java.util.Objects;
 import java.util.Optional;
+import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Consumer;
 
 /**
  * A session for a given activity.
@@ -307,7 +309,47 @@
     /**
      * Receiver of assist data from the app's {@link Activity}.
      */
-    private final IAssistDataReceiver mAssistReceiver = new IAssistDataReceiver.Stub() {
+    private final AssistDataReceiverImpl mAssistReceiver = new AssistDataReceiverImpl();
+
+    private final class AssistDataReceiverImpl extends IAssistDataReceiver.Stub {
+
+        @GuardedBy("mLock")
+        private InlineSuggestionsRequest mPendingInlineSuggestionsRequest;
+        @GuardedBy("mLock")
+        private FillRequest mPendingFillRequest;
+        @GuardedBy("mLock")
+        private CountDownLatch mCountDownLatch;
+
+        @Nullable Consumer<InlineSuggestionsRequest> newAutofillRequestLocked(
+                boolean isInlineRequest) {
+            mCountDownLatch = new CountDownLatch(isInlineRequest ? 2 : 1);
+            mPendingFillRequest = null;
+            mPendingInlineSuggestionsRequest = null;
+            return isInlineRequest ? (inlineSuggestionsRequest) -> {
+                synchronized (mLock) {
+                    mPendingInlineSuggestionsRequest = inlineSuggestionsRequest;
+                    mCountDownLatch.countDown();
+                    maybeRequestFillLocked();
+                }
+            } : null;
+        }
+
+        void maybeRequestFillLocked() {
+            if (mCountDownLatch == null || mCountDownLatch.getCount() > 0
+                    || mPendingFillRequest == null) {
+                return;
+            }
+            if (mPendingInlineSuggestionsRequest != null) {
+                mPendingFillRequest = new FillRequest(mPendingFillRequest.getId(),
+                        mPendingFillRequest.getFillContexts(), mPendingFillRequest.getClientState(),
+                        mPendingFillRequest.getFlags(), mPendingInlineSuggestionsRequest);
+            }
+            mRemoteFillService.onFillRequest(mPendingFillRequest);
+            mPendingInlineSuggestionsRequest = null;
+            mPendingFillRequest = null;
+            mCountDownLatch = null;
+        }
+
         @Override
         public void onHandleAssistData(Bundle resultData) throws RemoteException {
             if (mRemoteFillService == null) {
@@ -402,17 +444,17 @@
 
                 final ArrayList<FillContext> contexts =
                         mergePreviousSessionLocked(/* forSave= */ false);
-
-                final Optional<InlineSuggestionsRequest> inlineSuggestionsRequest =
-                        mInlineSuggestionSession.waitAndGetInlineSuggestionsRequest();
                 request = new FillRequest(requestId, contexts, mClientState, flags,
-                        inlineSuggestionsRequest.orElse(null));
+                        /*inlineSuggestionsRequest=*/null);
+
+                mPendingFillRequest = request;
+                mCountDownLatch.countDown();
+                maybeRequestFillLocked();
             }
 
             if (mActivityToken != null) {
                 mService.sendActivityAssistDataToContentCapture(mActivityToken, resultData);
             }
-            mRemoteFillService.onFillRequest(request);
         }
 
         @Override
@@ -605,9 +647,15 @@
     private void maybeRequestInlineSuggestionsRequestThenFillLocked(@NonNull ViewState viewState,
             int newState, int flags) {
         if (isInlineSuggestionsEnabledLocked()) {
-            mInlineSuggestionSession.onCreateInlineSuggestionsRequest(mCurrentViewId);
+            Consumer<InlineSuggestionsRequest> inlineSuggestionsRequestConsumer =
+                    mAssistReceiver.newAutofillRequestLocked(/*isInlineRequest=*/ true);
+            if (inlineSuggestionsRequestConsumer != null) {
+                mInlineSuggestionSession.onCreateInlineSuggestionsRequest(mCurrentViewId,
+                        inlineSuggestionsRequestConsumer);
+            }
+        } else {
+            mAssistReceiver.newAutofillRequestLocked(/*isInlineRequest=*/ false);
         }
-
         requestNewFillResponseLocked(viewState, newState, flags);
     }
 
@@ -708,7 +756,7 @@
         setClientLocked(client);
 
         mInlineSuggestionSession = new InlineSuggestionSession(inputMethodManagerInternal, userId,
-                componentName);
+                componentName, handler);
 
         mMetricsLogger.write(newLogMaker(MetricsEvent.AUTOFILL_SESSION_STARTED)
                 .addTaggedData(MetricsEvent.FIELD_AUTOFILL_FLAGS, flags));
@@ -2663,7 +2711,7 @@
     private boolean requestShowInlineSuggestionsLocked(@NonNull FillResponse response,
             @Nullable String filterText) {
         final Optional<InlineSuggestionsRequest> inlineSuggestionsRequest =
-                mInlineSuggestionSession.waitAndGetInlineSuggestionsRequest();
+                mInlineSuggestionSession.getInlineSuggestionsRequest();
         if (!inlineSuggestionsRequest.isPresent()) {
             Log.w(TAG, "InlineSuggestionsRequest unavailable");
             return false;
@@ -2896,6 +2944,9 @@
     /**
      * Tries to trigger Augmented Autofill when the standard service could not fulfill a request.
      *
+     * <p> The request may not have been sent when this method returns as it may be waiting for
+     * the inline suggestion request asynchronously.
+     *
      * @return callback to destroy the autofill UI, or {@code null} if not supported.
      */
     // TODO(b/123099468): might need to call it in other places, like when the service returns a
@@ -2978,6 +3029,21 @@
 
         final AutofillId focusedId = AutofillId.withoutSession(mCurrentViewId);
 
+        final Consumer<InlineSuggestionsRequest> requestAugmentedAutofill =
+                (inlineSuggestionsRequest) -> {
+                    remoteService.onRequestAutofillLocked(id, mClient, taskId, mComponentName,
+                            focusedId,
+                            currentValue, inlineSuggestionsRequest,
+                            /*inlineSuggestionsCallback=*/
+                            response -> mInlineSuggestionSession.onInlineSuggestionsResponse(
+                                    mCurrentViewId, response),
+                            /*onErrorCallback=*/ () -> {
+                                synchronized (mLock) {
+                                    cancelAugmentedAutofillLocked();
+                                }
+                            }, mService.getRemoteInlineSuggestionRenderServiceLocked());
+                };
+
         // There are 3 cases when augmented autofill should ask IME for a new request:
         // 1. standard autofill provider is None
         // 2. standard autofill provider doesn't support inline (and returns null response)
@@ -2985,21 +3051,12 @@
         // doesn't want autofill
         if (mForAugmentedAutofillOnly || !isInlineSuggestionsEnabledLocked()) {
             if (sDebug) Slog.d(TAG, "Create inline request for augmented autofill");
-            mInlineSuggestionSession.onCreateInlineSuggestionsRequest(mCurrentViewId);
+            mInlineSuggestionSession.onCreateInlineSuggestionsRequest(mCurrentViewId,
+                    /*requestConsumer=*/ requestAugmentedAutofill);
+        } else {
+            requestAugmentedAutofill.accept(
+                    mInlineSuggestionSession.getInlineSuggestionsRequest().orElse(null));
         }
-
-        Optional<InlineSuggestionsRequest> inlineSuggestionsRequest =
-                mInlineSuggestionSession.waitAndGetInlineSuggestionsRequest();
-        remoteService.onRequestAutofillLocked(id, mClient, taskId, mComponentName, focusedId,
-                currentValue, inlineSuggestionsRequest.orElse(null),
-                response -> mInlineSuggestionSession.onInlineSuggestionsResponse(
-                        mCurrentViewId, response),
-                () -> {
-                    synchronized (mLock) {
-                        cancelAugmentedAutofillLocked();
-                    }
-                }, mService.getRemoteInlineSuggestionRenderServiceLocked());
-
         if (mAugmentedAutofillDestroyer == null) {
             mAugmentedAutofillDestroyer = () -> remoteService.onDestroyAutofillWindowsRequest();
         }
@@ -3382,6 +3439,8 @@
                 final List<AutofillId> ids = new ArrayList<>(entryCount);
                 final List<AutofillValue> values = new ArrayList<>(entryCount);
                 boolean waitingDatasetAuth = false;
+                boolean hideHighlight = (entryCount == 1
+                        && dataset.getFieldIds().get(0).equals(mCurrentViewId));
                 for (int i = 0; i < entryCount; i++) {
                     if (dataset.getFieldValues().get(i) == null) {
                         continue;
@@ -3405,7 +3464,7 @@
                     }
                     if (sDebug) Slog.d(TAG, "autoFillApp(): the buck is on the app: " + dataset);
 
-                    mClient.autofill(id, ids, values);
+                    mClient.autofill(id, ids, values, hideHighlight);
                     if (dataset.getId() != null) {
                         if (mSelectedDatasetIds == null) {
                             mSelectedDatasetIds = new ArrayList<>();
diff --git a/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java b/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java
index ee59d89..0ca9dd9 100644
--- a/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java
+++ b/services/autofill/java/com/android/server/autofill/ui/InlineSuggestionFactory.java
@@ -329,8 +329,14 @@
             @NonNull Runnable onErrorCallback) {
         return new IInlineSuggestionUiCallback.Stub() {
             @Override
-            public void onAutofill() throws RemoteException {
+            public void onClick() throws RemoteException {
                 onAutofillCallback.run();
+                callback.onClick();
+            }
+
+            @Override
+            public void onLongClick() throws RemoteException {
+                callback.onLongClick();
             }
 
             @Override
diff --git a/services/core/java/com/android/server/ConnectivityService.java b/services/core/java/com/android/server/ConnectivityService.java
index 7287a44..ecf1f13 100644
--- a/services/core/java/com/android/server/ConnectivityService.java
+++ b/services/core/java/com/android/server/ConnectivityService.java
@@ -7803,12 +7803,15 @@
     private void handleNetworkTestedWithExtras(
             @NonNull ConnectivityReportEvent reportEvent, @NonNull PersistableBundle extras) {
         final NetworkAgentInfo nai = reportEvent.mNai;
+        final NetworkCapabilities networkCapabilities =
+                new NetworkCapabilities(nai.networkCapabilities);
+        clearNetworkCapabilitiesUids(networkCapabilities);
         final ConnectivityReport report =
                 new ConnectivityReport(
                         reportEvent.mNai.network,
                         reportEvent.mTimestampMillis,
                         nai.linkProperties,
-                        nai.networkCapabilities,
+                        networkCapabilities,
                         extras);
         final List<IConnectivityDiagnosticsCallback> results =
                 getMatchingPermissionedCallbacks(nai);
@@ -7824,13 +7827,16 @@
     private void handleDataStallSuspected(
             @NonNull NetworkAgentInfo nai, long timestampMillis, int detectionMethod,
             @NonNull PersistableBundle extras) {
+        final NetworkCapabilities networkCapabilities =
+                new NetworkCapabilities(nai.networkCapabilities);
+        clearNetworkCapabilitiesUids(networkCapabilities);
         final DataStallReport report =
                 new DataStallReport(
                         nai.network,
                         timestampMillis,
                         detectionMethod,
                         nai.linkProperties,
-                        nai.networkCapabilities,
+                        networkCapabilities,
                         extras);
         final List<IConnectivityDiagnosticsCallback> results =
                 getMatchingPermissionedCallbacks(nai);
@@ -7856,6 +7862,12 @@
         }
     }
 
+    private void clearNetworkCapabilitiesUids(@NonNull NetworkCapabilities nc) {
+        nc.setUids(null);
+        nc.setAdministratorUids(Collections.EMPTY_LIST);
+        nc.setOwnerUid(Process.INVALID_UID);
+    }
+
     private List<IConnectivityDiagnosticsCallback> getMatchingPermissionedCallbacks(
             @NonNull NetworkAgentInfo nai) {
         final List<IConnectivityDiagnosticsCallback> results = new ArrayList<>();
diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java
index acd4039..d814b9c 100644
--- a/services/core/java/com/android/server/LocationManagerService.java
+++ b/services/core/java/com/android/server/LocationManagerService.java
@@ -200,7 +200,7 @@
     // time
     private static final int MAX_PROVIDER_SCHEDULING_JITTER_MS = 100;
 
-    private static final String FEATURE_ID = "LocationService";
+    private static final String ATTRIBUTION_TAG = "LocationService";
 
     private static final LocationRequest DEFAULT_LOCATION_REQUEST = new LocationRequest();
 
@@ -246,7 +246,7 @@
     private int mBatterySaverMode;
 
     private LocationManagerService(Context context) {
-        mContext = context.createFeatureContext(FEATURE_ID);
+        mContext = context.createAttributionContext(ATTRIBUTION_TAG);
         mHandler = FgThread.getHandler();
         mLocalService = new LocalService();
 
diff --git a/services/core/java/com/android/server/RescueParty.java b/services/core/java/com/android/server/RescueParty.java
index 80036bb..808d322 100644
--- a/services/core/java/com/android/server/RescueParty.java
+++ b/services/core/java/com/android/server/RescueParty.java
@@ -99,6 +99,8 @@
     private static final String PROP_DISABLE_RESCUE = "persist.sys.disable_rescue";
     private static final String PROP_VIRTUAL_DEVICE = "ro.hardware.virtual_device";
 
+    private static final String DEVICE_CONFIG_DISABLE_FLAG = "disable_rescue_party";
+
     private static final int PERSISTENT_MASK = ApplicationInfo.FLAG_PERSISTENT
             | ApplicationInfo.FLAG_SYSTEM;
 
@@ -114,6 +116,14 @@
             return false;
         }
 
+        // We're disabled if the DeviceConfig disable flag is set to true.
+        // This is in case that an emergency rollback of the feature is needed.
+        if (DeviceConfig.getBoolean(
+                DeviceConfig.NAMESPACE_CONFIGURATION, DEVICE_CONFIG_DISABLE_FLAG, false)) {
+            Slog.v(TAG, "Disabled because of DeviceConfig flag");
+            return true;
+        }
+
         // We're disabled on all engineering devices
         if (Build.IS_ENG) {
             Slog.v(TAG, "Disabled because of eng build");
diff --git a/services/core/java/com/android/server/SensorNotificationService.java b/services/core/java/com/android/server/SensorNotificationService.java
index 9082dca..db3db0c 100644
--- a/services/core/java/com/android/server/SensorNotificationService.java
+++ b/services/core/java/com/android/server/SensorNotificationService.java
@@ -48,7 +48,7 @@
 
     private static final long MILLIS_2010_1_1 = 1262358000000l;
 
-    private static final String FEATURE_ID = "SensorNotificationService";
+    private static final String ATTRIBUTION_TAG = "SensorNotificationService";
 
     private Context mContext;
     private SensorManager mSensorManager;
@@ -59,7 +59,7 @@
     private long mLocalGeomagneticFieldUpdateTime = -LOCATION_MIN_TIME;
 
     public SensorNotificationService(Context context) {
-        super(context.createFeatureContext(FEATURE_ID));
+        super(context.createAttributionContext(ATTRIBUTION_TAG));
         mContext = getContext();
     }
 
diff --git a/services/core/java/com/android/server/UiModeManagerService.java b/services/core/java/com/android/server/UiModeManagerService.java
index eace86b..12a1a95 100644
--- a/services/core/java/com/android/server/UiModeManagerService.java
+++ b/services/core/java/com/android/server/UiModeManagerService.java
@@ -1318,9 +1318,9 @@
             if (Sandman.shouldStartDockApp(getContext(), homeIntent)) {
                 try {
                     int result = ActivityTaskManager.getService().startActivityWithConfig(
-                            null, getContext().getBasePackageName(), getContext().getFeatureId(),
-                            homeIntent, null, null, null, 0, 0, mConfiguration, null,
-                            UserHandle.USER_CURRENT);
+                            null, getContext().getBasePackageName(),
+                            getContext().getAttributionTag(), homeIntent, null, null, null, 0, 0,
+                            mConfiguration, null, UserHandle.USER_CURRENT);
                     if (ActivityManager.isStartResultSuccessful(result)) {
                         dockAppStarted = true;
                     } else if (result != ActivityManager.START_INTENT_NOT_RESOLVED) {
diff --git a/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java b/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
index 0a8e70c..bac7565 100644
--- a/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
+++ b/services/core/java/com/android/server/am/SettingsToPropertiesMapper.java
@@ -80,6 +80,7 @@
     @VisibleForTesting
     static final String[] sDeviceConfigScopes = new String[] {
         DeviceConfig.NAMESPACE_ACTIVITY_MANAGER_NATIVE_BOOT,
+        DeviceConfig.NAMESPACE_CONFIGURATION,
         DeviceConfig.NAMESPACE_INPUT_NATIVE_BOOT,
         DeviceConfig.NAMESPACE_INTELLIGENCE_CONTENT_SUGGESTIONS,
         DeviceConfig.NAMESPACE_MEDIA_NATIVE,
diff --git a/services/core/java/com/android/server/appop/AppOpsService.java b/services/core/java/com/android/server/appop/AppOpsService.java
index 87e1dbc..310664e 100644
--- a/services/core/java/com/android/server/appop/AppOpsService.java
+++ b/services/core/java/com/android/server/appop/AppOpsService.java
@@ -20,7 +20,7 @@
 import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_LOCATION;
 import static android.app.ActivityManager.PROCESS_CAPABILITY_FOREGROUND_MICROPHONE;
 import static android.app.AppOpsManager.CALL_BACK_ON_SWITCHED_OP;
-import static android.app.AppOpsManager.FILTER_BY_FEATURE_ID;
+import static android.app.AppOpsManager.FILTER_BY_ATTRIBUTION_TAG;
 import static android.app.AppOpsManager.FILTER_BY_OP_NAMES;
 import static android.app.AppOpsManager.FILTER_BY_PACKAGE_NAME;
 import static android.app.AppOpsManager.FILTER_BY_UID;
@@ -80,7 +80,7 @@
 import android.app.AppOpsManager.HistoricalOps;
 import android.app.AppOpsManager.Mode;
 import android.app.AppOpsManager.OpEntry;
-import android.app.AppOpsManager.OpFeatureEntry;
+import android.app.AppOpsManager.AttributedOpEntry;
 import android.app.AppOpsManager.OpFlags;
 import android.app.AppOpsManagerInternal;
 import android.app.AppOpsManagerInternal.CheckOpsDelegate;
@@ -97,7 +97,7 @@
 import android.content.pm.PackageManagerInternal;
 import android.content.pm.PermissionInfo;
 import android.content.pm.UserInfo;
-import android.content.pm.parsing.component.ParsedFeature;
+import android.content.pm.parsing.component.ParsedAttribution;
 import android.database.ContentObserver;
 import android.hardware.camera2.CameraDevice.CAMERA_AUDIO_RESTRICTION;
 import android.net.Uri;
@@ -371,14 +371,14 @@
         }
 
         OpEventProxyInfo acquire(@IntRange(from = 0) int uid, @Nullable String packageName,
-                @Nullable String featureId) {
+                @Nullable String attributionTag) {
             OpEventProxyInfo recycled = acquire();
             if (recycled != null) {
-                recycled.reinit(uid, packageName, featureId);
+                recycled.reinit(uid, packageName, attributionTag);
                 return recycled;
             }
 
-            return new OpEventProxyInfo(uid, packageName, featureId);
+            return new OpEventProxyInfo(uid, packageName, attributionTag);
         }
     }
 
@@ -671,8 +671,8 @@
          */
         @Nullable RestrictionBypass bypass;
 
-        /** Lazily populated cache of featureIds of this package */
-        final @NonNull ArraySet<String> knownFeatureIds = new ArraySet<>();
+        /** Lazily populated cache of attributionTags of this package */
+        final @NonNull ArraySet<String> knownAttributionTags = new ArraySet<>();
 
         Ops(String _packageName, UidState _uidState) {
             packageName = _packageName;
@@ -776,8 +776,8 @@
         }
     }
 
-    private final class FeatureOp {
-        public final @Nullable String featureId;
+    private final class AttributedOp {
+        public final @Nullable String tag;
         public final @NonNull Op parent;
 
         /**
@@ -804,8 +804,8 @@
         @GuardedBy("AppOpsService.this")
         private @Nullable ArrayMap<IBinder, InProgressStartOpEvent> mInProgressEvents;
 
-        FeatureOp(@Nullable String featureId, @NonNull Op parent) {
-            this.featureId = featureId;
+        AttributedOp(@Nullable String tag, @NonNull Op parent) {
+            this.tag = tag;
             this.parent = parent;
         }
 
@@ -814,18 +814,18 @@
          *
          * @param proxyUid The uid of the proxy
          * @param proxyPackageName The package name of the proxy
-         * @param proxyFeatureId the featureId in the proxies package
+         * @param proxyAttributionTag the attributionTag in the proxies package
          * @param uidState UID state of the app noteOp/startOp was called for
          * @param flags OpFlags of the call
          */
         public void accessed(int proxyUid, @Nullable String proxyPackageName,
-                @Nullable String proxyFeatureId, @AppOpsManager.UidState int uidState,
+                @Nullable String proxyAttributionTag, @AppOpsManager.UidState int uidState,
                 @OpFlags int flags) {
             accessed(System.currentTimeMillis(), -1, proxyUid, proxyPackageName,
-                    proxyFeatureId, uidState, flags);
+                    proxyAttributionTag, uidState, flags);
 
             mHistoricalRegistry.incrementOpAccessedCount(parent.op, parent.uid, parent.packageName,
-                    featureId, uidState, flags);
+                    tag, uidState, flags);
         }
 
         /**
@@ -835,12 +835,12 @@
          * @param duration The duration of the event
          * @param proxyUid The uid of the proxy
          * @param proxyPackageName The package name of the proxy
-         * @param proxyFeatureId the featureId in the proxies package
+         * @param proxyAttributionTag the attributionTag in the proxies package
          * @param uidState UID state of the app noteOp/startOp was called for
          * @param flags OpFlags of the call
          */
         public void accessed(long noteTime, long duration, int proxyUid,
-                @Nullable String proxyPackageName, @Nullable String proxyFeatureId,
+                @Nullable String proxyPackageName, @Nullable String proxyAttributionTag,
                 @AppOpsManager.UidState int uidState, @OpFlags int flags) {
             long key = makeKey(uidState, flags);
 
@@ -851,7 +851,7 @@
             OpEventProxyInfo proxyInfo = null;
             if (proxyUid != Process.INVALID_UID) {
                 proxyInfo = mOpEventProxyInfoPool.acquire(proxyUid, proxyPackageName,
-                        proxyFeatureId);
+                        proxyAttributionTag);
             }
 
             NoteOpEvent existingEvent = mAccessEvents.get(key);
@@ -872,7 +872,7 @@
             rejected(System.currentTimeMillis(), uidState, flags);
 
             mHistoricalRegistry.incrementOpRejected(parent.op, parent.uid, parent.packageName,
-                    featureId, uidState, flags);
+                    tag, uidState, flags);
         }
 
         /**
@@ -938,7 +938,7 @@
 
             // startOp events don't support proxy, hence use flags==SELF
             mHistoricalRegistry.incrementOpAccessedCount(parent.op, parent.uid, parent.packageName,
-                    featureId, uidState, OP_FLAG_SELF);
+                    tag, uidState, OP_FLAG_SELF);
         }
 
         /**
@@ -978,7 +978,7 @@
                 mAccessEvents.put(makeKey(event.getUidState(), OP_FLAG_SELF), finishedEvent);
 
                 mHistoricalRegistry.increaseOpAccessDuration(parent.op, parent.uid,
-                        parent.packageName, featureId, event.getUidState(),
+                        parent.packageName, tag, event.getUidState(),
                         AppOpsManager.OP_FLAG_SELF, finishedEvent.getDuration());
 
                 mInProgressStartOpEventPool.release(event);
@@ -986,7 +986,7 @@
                 if (mInProgressEvents.isEmpty()) {
                     mInProgressEvents = null;
 
-                    // TODO moltmann: Also callback for single feature activity changes
+                    // TODO moltmann: Also callback for single attribution tag activity changes
                     if (triggerCallbackIfNeeded && !parent.isRunning()) {
                         scheduleOpActiveChangedIfNeededLocked(parent.op, parent.uid,
                                 parent.packageName, false);
@@ -1077,14 +1077,14 @@
         }
 
         /**
-         * Add all data from the {@code featureToAdd} to this op.
+         * Add all data from the {@code opToAdd} to this op.
          *
          * <p>If there is an event for the same key in both the later event is retained.
          * <p>{@code opToAdd} should not be used after this method is called.
          *
          * @param opToAdd The op to add
          */
-        public void add(@NonNull FeatureOp opToAdd) {
+        public void add(@NonNull AttributedOp opToAdd) {
             if (opToAdd.mInProgressEvents != null) {
                 Slog.w(TAG, "Ignoring " + opToAdd.mInProgressEvents.size() + " running app-ops");
 
@@ -1128,7 +1128,7 @@
             return clone;
         }
 
-        @NonNull OpFeatureEntry createFeatureEntryLocked() {
+        @NonNull AttributedOpEntry createAttributedOpEntryLocked() {
             LongSparseArray<NoteOpEvent> accessEvents = deepClone(mAccessEvents);
 
             // Add in progress events as access events
@@ -1152,7 +1152,7 @@
 
             LongSparseArray<NoteOpEvent> rejectEvents = deepClone(mRejectEvents);
 
-            return new OpFeatureEntry(parent.op, isRunning(), accessEvents, rejectEvents);
+            return new AttributedOpEntry(parent.op, isRunning(), accessEvents, rejectEvents);
         }
     }
 
@@ -1164,8 +1164,8 @@
 
         private @Mode int mode;
 
-        /** featureId -> FeatureOp */
-        final ArrayMap<String, FeatureOp> mFeatures = new ArrayMap<>(1);
+        /** attributionTag -> AttributedOp */
+        final ArrayMap<String, AttributedOp> mAttributions = new ArrayMap<>(1);
 
         Op(UidState uidState, String packageName, int op, int uid) {
             this.op = op;
@@ -1183,58 +1183,59 @@
             return uidState.evalMode(op, mode);
         }
 
-        void removeFeaturesWithNoTime() {
-            for (int i = mFeatures.size() - 1; i >= 0; i--) {
-                if (!mFeatures.valueAt(i).hasAnyTime()) {
-                    mFeatures.removeAt(i);
+        void removeAttributionsWithNoTime() {
+            for (int i = mAttributions.size() - 1; i >= 0; i--) {
+                if (!mAttributions.valueAt(i).hasAnyTime()) {
+                    mAttributions.removeAt(i);
                 }
             }
         }
 
-        private @NonNull FeatureOp getOrCreateFeature(@NonNull Op parent,
-                @Nullable String featureId) {
-            FeatureOp featureOp;
+        private @NonNull AttributedOp getOrCreateAttribution(@NonNull Op parent,
+                @Nullable String attributionTag) {
+            AttributedOp attributedOp;
 
-            featureOp = mFeatures.get(featureId);
-            if (featureOp == null) {
-                featureOp = new FeatureOp(featureId, parent);
-                mFeatures.put(featureId, featureOp);
+            attributedOp = mAttributions.get(attributionTag);
+            if (attributedOp == null) {
+                attributedOp = new AttributedOp(attributionTag, parent);
+                mAttributions.put(attributionTag, attributedOp);
             }
 
-            return featureOp;
+            return attributedOp;
         }
 
         @NonNull OpEntry createEntryLocked() {
-            final int numFeatures = mFeatures.size();
+            final int numAttributions = mAttributions.size();
 
-            final ArrayMap<String, OpFeatureEntry> featureEntries = new ArrayMap<>(numFeatures);
-            for (int i = 0; i < numFeatures; i++) {
-                featureEntries.put(mFeatures.keyAt(i),
-                        mFeatures.valueAt(i).createFeatureEntryLocked());
+            final ArrayMap<String, AppOpsManager.AttributedOpEntry> attributionEntries =
+                    new ArrayMap<>(numAttributions);
+            for (int i = 0; i < numAttributions; i++) {
+                attributionEntries.put(mAttributions.keyAt(i),
+                        mAttributions.valueAt(i).createAttributedOpEntryLocked());
             }
 
-            return new OpEntry(op, mode, featureEntries);
+            return new OpEntry(op, mode, attributionEntries);
         }
 
-        @NonNull OpEntry createSingleFeatureEntryLocked(@Nullable String featureId) {
-            final int numFeatures = mFeatures.size();
+        @NonNull OpEntry createSingleAttributionEntryLocked(@Nullable String attributionTag) {
+            final int numAttributions = mAttributions.size();
 
-            final ArrayMap<String, OpFeatureEntry> featureEntries = new ArrayMap<>(1);
-            for (int i = 0; i < numFeatures; i++) {
-                if (Objects.equals(mFeatures.keyAt(i), featureId)) {
-                    featureEntries.put(mFeatures.keyAt(i),
-                            mFeatures.valueAt(i).createFeatureEntryLocked());
+            final ArrayMap<String, AttributedOpEntry> attributionEntries = new ArrayMap<>(1);
+            for (int i = 0; i < numAttributions; i++) {
+                if (Objects.equals(mAttributions.keyAt(i), attributionTag)) {
+                    attributionEntries.put(mAttributions.keyAt(i),
+                            mAttributions.valueAt(i).createAttributedOpEntryLocked());
                     break;
                 }
             }
 
-            return new OpEntry(op, mode, featureEntries);
+            return new OpEntry(op, mode, attributionEntries);
         }
 
         boolean isRunning() {
-            final int numFeatures = mFeatures.size();
-            for (int i = 0; i < numFeatures; i++) {
-                if (mFeatures.valueAt(i).isRunning()) {
+            final int numAttributions = mAttributions.size();
+            for (int i = 0; i < numAttributions; i++) {
+                if (mAttributions.valueAt(i).isRunning()) {
                     return true;
                 }
             }
@@ -1407,10 +1408,11 @@
     }
 
     /**
-     * Call {@link FeatureOp#onClientDeath featureOp.onClientDeath(clientId)}.
+     * Call {@link AttributedOp#onClientDeath attributedOp.onClientDeath(clientId)}.
      */
-    private static void onClientDeath(@NonNull FeatureOp featureOp, @NonNull IBinder clientId) {
-        featureOp.onClientDeath(clientId);
+    private static void onClientDeath(@NonNull AttributedOp attributedOp,
+            @NonNull IBinder clientId) {
+        attributedOp.onClientDeath(clientId);
     }
 
 
@@ -1492,20 +1494,21 @@
                     return;
                 }
 
-                ArrayMap<String, String> dstFeatureIds = new ArrayMap<>();
-                ArraySet<String> featureIds = new ArraySet<>();
-                featureIds.add(null);
-                if (pkg.getFeatures() != null) {
-                    int numFeatures = pkg.getFeatures().size();
-                    for (int featureNum = 0; featureNum < numFeatures; featureNum++) {
-                        ParsedFeature feature = pkg.getFeatures().get(featureNum);
-                        featureIds.add(feature.id);
+                ArrayMap<String, String> dstAttributionTags = new ArrayMap<>();
+                ArraySet<String> attributionTags = new ArraySet<>();
+                attributionTags.add(null);
+                if (pkg.getAttributions() != null) {
+                    int numAttributions = pkg.getAttributions().size();
+                    for (int attributionNum = 0; attributionNum < numAttributions;
+                            attributionNum++) {
+                        ParsedAttribution attribution = pkg.getAttributions().get(attributionNum);
+                        attributionTags.add(attribution.tag);
 
-                        int numInheritFrom = feature.inheritFrom.size();
+                        int numInheritFrom = attribution.inheritFrom.size();
                         for (int inheritFromNum = 0; inheritFromNum < numInheritFrom;
                                 inheritFromNum++) {
-                            dstFeatureIds.put(feature.inheritFrom.get(inheritFromNum),
-                                    feature.id);
+                            dstAttributionTags.put(attribution.inheritFrom.get(inheritFromNum),
+                                    attribution.tag);
                         }
                     }
                 }
@@ -1523,27 +1526,30 @@
 
                     // Reset cached package properties to re-initialize when needed
                     ops.bypass = null;
-                    ops.knownFeatureIds.clear();
+                    ops.knownAttributionTags.clear();
 
-                    // Merge data collected for removed features into their successor features
+                    // Merge data collected for removed attributions into their successor
+                    // attributions
                     int numOps = ops.size();
                     for (int opNum = 0; opNum < numOps; opNum++) {
                         Op op = ops.valueAt(opNum);
 
-                        int numFeatures = op.mFeatures.size();
-                        for (int featureNum = numFeatures - 1; featureNum >= 0; featureNum--) {
-                            String featureId = op.mFeatures.keyAt(featureNum);
+                        int numAttributions = op.mAttributions.size();
+                        for (int attributionNum = numAttributions - 1; attributionNum >= 0;
+                                attributionNum--) {
+                            String attributionTag = op.mAttributions.keyAt(attributionNum);
 
-                            if (featureIds.contains(featureId)) {
-                                // feature still exist after upgrade
+                            if (attributionTags.contains(attributionTag)) {
+                                // attribution still exist after upgrade
                                 continue;
                             }
 
-                            String newFeatureId = dstFeatureIds.get(featureId);
+                            String newAttributionTag = dstAttributionTags.get(attributionTag);
 
-                            FeatureOp newFeatureOp = op.getOrCreateFeature(op, newFeatureId);
-                            newFeatureOp.add(op.mFeatures.valueAt(featureNum));
-                            op.mFeatures.removeAt(featureNum);
+                            AttributedOp newAttributedOp = op.getOrCreateAttribution(op,
+                                    newAttributionTag);
+                            newAttributedOp.add(op.mAttributions.valueAt(attributionNum));
+                            op.mAttributions.removeAt(attributionNum);
 
                             scheduleFastWriteLocked();
                         }
@@ -1743,12 +1749,13 @@
                 for (int opNum = 0; opNum < numOps; opNum++) {
                     final Op op = ops.valueAt(opNum);
 
-                    final int numFeatures = op.mFeatures.size();
-                    for (int featureNum = 0; featureNum < numFeatures; featureNum++) {
-                        FeatureOp featureOp = op.mFeatures.valueAt(featureNum);
+                    final int numAttributions = op.mAttributions.size();
+                    for (int attributionNum = 0; attributionNum < numAttributions;
+                            attributionNum++) {
+                        AttributedOp attributedOp = op.mAttributions.valueAt(attributionNum);
 
-                        while (featureOp.mInProgressEvents != null) {
-                            featureOp.finished(featureOp.mInProgressEvents.keyAt(0));
+                        while (attributedOp.mInProgressEvents != null) {
+                            attributedOp.finished(attributedOp.mInProgressEvents.keyAt(0));
                         }
                     }
                 }
@@ -1828,11 +1835,13 @@
                         for (int opNum = 0; opNum < numOps; opNum++) {
                             Op op = ops.valueAt(opNum);
 
-                            int numFeatures = op.mFeatures.size();
-                            for (int featureNum = 0; featureNum < numFeatures; featureNum++) {
-                                FeatureOp featureOp = op.mFeatures.valueAt(featureNum);
+                            int numAttributions = op.mAttributions.size();
+                            for (int attributionNum = 0; attributionNum < numAttributions;
+                                    attributionNum++) {
+                                AttributedOp attributedOp = op.mAttributions.valueAt(
+                                        attributionNum);
 
-                                featureOp.onUidStateChanged(newState);
+                                attributedOp.onUidStateChanged(newState);
                             }
                         }
                     }
@@ -1978,9 +1987,9 @@
     /**
      * Verify that historical appop request arguments are valid.
      */
-    private void ensureHistoricalOpRequestIsValid(int uid, String packageName, String featureId,
-            List<String> opNames, int filter, long beginTimeMillis, long endTimeMillis,
-            int flags) {
+    private void ensureHistoricalOpRequestIsValid(int uid, String packageName,
+            String attributionTag, List<String> opNames, int filter, long beginTimeMillis,
+            long endTimeMillis, int flags) {
         if ((filter & FILTER_BY_UID) != 0) {
             Preconditions.checkArgument(uid != Process.INVALID_UID);
         } else {
@@ -1993,8 +2002,8 @@
             Preconditions.checkArgument(packageName == null);
         }
 
-        if ((filter & FILTER_BY_FEATURE_ID) == 0) {
-            Preconditions.checkArgument(featureId == null);
+        if ((filter & FILTER_BY_ATTRIBUTION_TAG) == 0) {
+            Preconditions.checkArgument(attributionTag == null);
         }
 
         if ((filter & FILTER_BY_OP_NAMES) != 0) {
@@ -2004,17 +2013,18 @@
         }
 
         Preconditions.checkFlagsArgument(filter,
-                FILTER_BY_UID | FILTER_BY_PACKAGE_NAME | FILTER_BY_FEATURE_ID | FILTER_BY_OP_NAMES);
+                FILTER_BY_UID | FILTER_BY_PACKAGE_NAME | FILTER_BY_ATTRIBUTION_TAG
+                        | FILTER_BY_OP_NAMES);
         Preconditions.checkArgumentNonnegative(beginTimeMillis);
         Preconditions.checkArgument(endTimeMillis > beginTimeMillis);
         Preconditions.checkFlagsArgument(flags, OP_FLAGS_ALL);
     }
 
     @Override
-    public void getHistoricalOps(int uid, String packageName, String featureId,
+    public void getHistoricalOps(int uid, String packageName, String attributionTag,
             List<String> opNames, int filter, long beginTimeMillis, long endTimeMillis,
             int flags, RemoteCallback callback) {
-        ensureHistoricalOpRequestIsValid(uid, packageName, featureId, opNames, filter,
+        ensureHistoricalOpRequestIsValid(uid, packageName, attributionTag, opNames, filter,
                 beginTimeMillis, endTimeMillis, flags);
         Objects.requireNonNull(callback, "callback cannot be null");
 
@@ -2035,15 +2045,15 @@
 
         // Must not hold the appops lock
         mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOps,
-                mHistoricalRegistry, uid, packageName, featureId, opNamesArray, filter,
+                mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray, filter,
                 beginTimeMillis, endTimeMillis, flags, callback).recycleOnUse());
     }
 
     @Override
-    public void getHistoricalOpsFromDiskRaw(int uid, String packageName, String featureId,
+    public void getHistoricalOpsFromDiskRaw(int uid, String packageName, String attributionTag,
             List<String> opNames, int filter, long beginTimeMillis, long endTimeMillis,
             int flags, RemoteCallback callback) {
-        ensureHistoricalOpRequestIsValid(uid, packageName, featureId, opNames, filter,
+        ensureHistoricalOpRequestIsValid(uid, packageName, attributionTag, opNames, filter,
                 beginTimeMillis, endTimeMillis, flags);
         Objects.requireNonNull(callback, "callback cannot be null");
 
@@ -2055,7 +2065,7 @@
 
         // Must not hold the appops lock
         mHandler.post(PooledLambda.obtainRunnable(HistoricalRegistry::getHistoricalOpsFromDiskRaw,
-                mHistoricalRegistry, uid, packageName, featureId, opNamesArray,
+                mHistoricalRegistry, uid, packageName, attributionTag, opNamesArray,
                 filter, beginTimeMillis, endTimeMillis, flags, callback).recycleOnUse());
     }
 
@@ -2089,9 +2099,9 @@
     }
 
     private void pruneOpLocked(Op op, int uid, String packageName) {
-        op.removeFeaturesWithNoTime();
+        op.removeAttributionsWithNoTime();
 
-        if (op.mFeatures.size() == 0) {
+        if (op.mAttributions.isEmpty()) {
             Ops ops = getOpsLocked(uid, packageName, null, null, false /* edit */);
             if (ops != null) {
                 ops.remove(op.op);
@@ -2610,8 +2620,8 @@
                             callbacks = addCallbacks(callbacks, curOp.op, uid, packageName,
                                     mPackageModeWatchers.get(packageName));
 
-                            curOp.removeFeaturesWithNoTime();
-                            if (curOp.mFeatures.size() == 0) {
+                            curOp.removeAttributionsWithNoTime();
+                            if (curOp.mAttributions.isEmpty()) {
                                 pkgOps.removeAt(j);
                             }
                         }
@@ -2895,8 +2905,8 @@
 
     @Override
     public int noteProxyOperation(int code, int proxiedUid, String proxiedPackageName,
-            String proxiedFeatureId, int proxyUid, String proxyPackageName,
-            String proxyFeatureId, boolean shouldCollectAsyncNotedOp, String message) {
+            String proxiedAttributionTag, int proxyUid, String proxyPackageName,
+            String proxyAttributionTag, boolean shouldCollectAsyncNotedOp, String message) {
         verifyIncomingUid(proxyUid);
         verifyIncomingOp(code);
 
@@ -2912,7 +2922,7 @@
         final int proxyFlags = isProxyTrusted ? AppOpsManager.OP_FLAG_TRUSTED_PROXY
                 : AppOpsManager.OP_FLAG_UNTRUSTED_PROXY;
         final int proxyMode = noteOperationUnchecked(code, proxyUid, resolveProxyPackageName,
-                proxyFeatureId, Process.INVALID_UID, null, null, proxyFlags,
+                proxyAttributionTag, Process.INVALID_UID, null, null, proxyFlags,
                 !isProxyTrusted, "proxy " + message);
         if (proxyMode != AppOpsManager.MODE_ALLOWED || Binder.getCallingUid() == proxiedUid) {
             return proxyMode;
@@ -2925,27 +2935,27 @@
         final int proxiedFlags = isProxyTrusted ? AppOpsManager.OP_FLAG_TRUSTED_PROXIED
                 : AppOpsManager.OP_FLAG_UNTRUSTED_PROXIED;
         return noteOperationUnchecked(code, proxiedUid, resolveProxiedPackageName,
-                proxiedFeatureId, proxyUid, resolveProxyPackageName, proxyFeatureId,
+                proxiedAttributionTag, proxyUid, resolveProxyPackageName, proxyAttributionTag,
                 proxiedFlags, shouldCollectAsyncNotedOp, message);
     }
 
     @Override
-    public int noteOperation(int code, int uid, String packageName, String featureId,
+    public int noteOperation(int code, int uid, String packageName, String attributionTag,
             boolean shouldCollectAsyncNotedOp, String message) {
         final CheckOpsDelegate delegate;
         synchronized (this) {
             delegate = mCheckOpsDelegate;
         }
         if (delegate == null) {
-            return noteOperationImpl(code, uid, packageName, featureId, shouldCollectAsyncNotedOp,
-                    message);
+            return noteOperationImpl(code, uid, packageName, attributionTag,
+                    shouldCollectAsyncNotedOp, message);
         }
-        return delegate.noteOperation(code, uid, packageName, featureId, shouldCollectAsyncNotedOp,
-                message, AppOpsService.this::noteOperationImpl);
+        return delegate.noteOperation(code, uid, packageName, attributionTag,
+                shouldCollectAsyncNotedOp, message, AppOpsService.this::noteOperationImpl);
     }
 
     private int noteOperationImpl(int code, int uid, @Nullable String packageName,
-            @Nullable String featureId, boolean shouldCollectAsyncNotedOp,
+            @Nullable String attributionTag, boolean shouldCollectAsyncNotedOp,
             @Nullable String message) {
         verifyIncomingUid(uid);
         verifyIncomingOp(code);
@@ -2953,25 +2963,26 @@
         if (resolvedPackageName == null) {
             return AppOpsManager.MODE_IGNORED;
         }
-        return noteOperationUnchecked(code, uid, resolvedPackageName, featureId,
+        return noteOperationUnchecked(code, uid, resolvedPackageName, attributionTag,
                 Process.INVALID_UID, null, null, AppOpsManager.OP_FLAG_SELF,
                 shouldCollectAsyncNotedOp, message);
     }
 
     private int noteOperationUnchecked(int code, int uid, @NonNull String packageName,
-            @Nullable String featureId, int proxyUid, String proxyPackageName,
-            @Nullable String proxyFeatureId, @OpFlags int flags, boolean shouldCollectAsyncNotedOp,
-            @Nullable String message) {
+            @Nullable String attributionTag, int proxyUid, String proxyPackageName,
+            @Nullable String proxyAttributionTag, @OpFlags int flags,
+            boolean shouldCollectAsyncNotedOp, @Nullable String message) {
         RestrictionBypass bypass;
         try {
-            bypass = verifyAndGetBypass(uid, packageName, featureId);
+            bypass = verifyAndGetBypass(uid, packageName, attributionTag);
         } catch (SecurityException e) {
             Slog.e(TAG, "noteOperation", e);
             return AppOpsManager.MODE_ERRORED;
         }
 
         synchronized (this) {
-            final Ops ops = getOpsLocked(uid, packageName, featureId, bypass, true /* edit */);
+            final Ops ops = getOpsLocked(uid, packageName, attributionTag, bypass,
+                    true /* edit */);
             if (ops == null) {
                 scheduleOpNotedIfNeededLocked(code, uid, packageName,
                         AppOpsManager.MODE_IGNORED);
@@ -2980,17 +2991,17 @@
                 return AppOpsManager.MODE_ERRORED;
             }
             final Op op = getOpLocked(ops, code, uid, true);
-            final FeatureOp featureOp = op.getOrCreateFeature(op, featureId);
+            final AttributedOp attributedOp = op.getOrCreateAttribution(op, attributionTag);
             if (isOpRestrictedLocked(uid, code, packageName, bypass)) {
                 scheduleOpNotedIfNeededLocked(code, uid, packageName,
                         AppOpsManager.MODE_IGNORED);
                 return AppOpsManager.MODE_IGNORED;
             }
             final UidState uidState = ops.uidState;
-            if (featureOp.isRunning()) {
+            if (attributedOp.isRunning()) {
                 Slog.w(TAG, "Noting op not finished: uid " + uid + " pkg " + packageName + " code "
                         + code + " startTime of in progress event="
-                        + featureOp.mInProgressEvents.valueAt(0).getStartTime());
+                        + attributedOp.mInProgressEvents.valueAt(0).getStartTime());
             }
 
             final int switchCode = AppOpsManager.opToSwitch(code);
@@ -3002,7 +3013,7 @@
                     if (DEBUG) Slog.d(TAG, "noteOperation: uid reject #" + uidMode + " for code "
                             + switchCode + " (" + code + ") uid " + uid + " package "
                             + packageName);
-                    featureOp.rejected(uidState.state, flags);
+                    attributedOp.rejected(uidState.state, flags);
                     scheduleOpNotedIfNeededLocked(code, uid, packageName, uidMode);
                     return uidMode;
                 }
@@ -3014,26 +3025,31 @@
                     if (DEBUG) Slog.d(TAG, "noteOperation: reject #" + mode + " for code "
                             + switchCode + " (" + code + ") uid " + uid + " package "
                             + packageName);
-                    featureOp.rejected(uidState.state, flags);
+                    attributedOp.rejected(uidState.state, flags);
                     scheduleOpNotedIfNeededLocked(code, uid, packageName, mode);
                     return mode;
                 }
             }
-            if (DEBUG) Slog.d(TAG, "noteOperation: allowing code " + code + " uid " + uid
-                    + " package " + packageName + (featureId == null ? "" : "." + featureId));
-            featureOp.accessed(proxyUid, proxyPackageName, proxyFeatureId, uidState.state, flags);
+            if (DEBUG) {
+                Slog.d(TAG,
+                        "noteOperation: allowing code " + code + " uid " + uid + " package "
+                                + packageName + (attributionTag == null ? ""
+                                : "." + attributionTag));
+            }
+            attributedOp.accessed(proxyUid, proxyPackageName, proxyAttributionTag, uidState.state,
+                    flags);
             scheduleOpNotedIfNeededLocked(code, uid, packageName,
                     AppOpsManager.MODE_ALLOWED);
 
             if (shouldCollectAsyncNotedOp) {
-                collectAsyncNotedOp(uid, packageName, code, featureId, message);
+                collectAsyncNotedOp(uid, packageName, code, attributionTag, message);
             }
 
             return AppOpsManager.MODE_ALLOWED;
         }
     }
 
-    // TODO moltmann: Allow watching for feature ops
+    // TODO moltmann: Allow watching for attribution ops
     @Override
     public void startWatchingActive(int[] ops, IAppOpsActiveCallback callback) {
         int watchedUid = -1;
@@ -3131,11 +3147,11 @@
      * @param uid The uid the op was noted for
      * @param packageName The package the op was noted for
      * @param opCode The code of the op noted
-     * @param featureId The id of the feature to op was noted for
+     * @param attributionTag attribution tag the op was noted for
      * @param message The message for the op noting
      */
     private void collectAsyncNotedOp(int uid, @NonNull String packageName, int opCode,
-            @Nullable String featureId, @NonNull String message) {
+            @Nullable String attributionTag, @NonNull String message) {
         Objects.requireNonNull(message);
 
         int callingUid = Binder.getCallingUid();
@@ -3147,10 +3163,10 @@
 
                 RemoteCallbackList<IAppOpsAsyncNotedCallback> callbacks = mAsyncOpWatchers.get(key);
                 AsyncNotedAppOp asyncNotedOp = new AsyncNotedAppOp(opCode, callingUid,
-                        featureId, message, System.currentTimeMillis());
+                        attributionTag, message, System.currentTimeMillis());
                 final boolean[] wasNoteForwarded = {false};
 
-                reportRuntimeAppOpAccessMessageAsyncLocked(uid, packageName, opCode, featureId,
+                reportRuntimeAppOpAccessMessageAsyncLocked(uid, packageName, opCode, attributionTag,
                         message);
 
                 if (callbacks != null) {
@@ -3161,7 +3177,7 @@
                         } catch (RemoteException e) {
                             Slog.e(TAG,
                                     "Could not forward noteOp of " + opCode + " to " + packageName
-                                            + "/" + uid + "(" + featureId + ")", e);
+                                            + "/" + uid + "(" + attributionTag + ")", e);
                         }
                     });
                 }
@@ -3263,7 +3279,7 @@
 
     @Override
     public int startOperation(IBinder clientId, int code, int uid, String packageName,
-            String featureId, boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp,
+            String attributionTag, boolean startIfModeDefault, boolean shouldCollectAsyncNotedOp,
             String message) {
         verifyIncomingUid(uid);
         verifyIncomingOp(code);
@@ -3274,14 +3290,14 @@
 
         RestrictionBypass bypass;
         try {
-            bypass = verifyAndGetBypass(uid, packageName, featureId);
+            bypass = verifyAndGetBypass(uid, packageName, attributionTag);
         } catch (SecurityException e) {
             Slog.e(TAG, "startOperation", e);
             return AppOpsManager.MODE_ERRORED;
         }
 
         synchronized (this) {
-            final Ops ops = getOpsLocked(uid, resolvedPackageName, featureId, bypass,
+            final Ops ops = getOpsLocked(uid, resolvedPackageName, attributionTag, bypass,
                     true /* edit */);
             if (ops == null) {
                 if (DEBUG) Slog.d(TAG, "startOperation: no op for code " + code + " uid " + uid
@@ -3292,7 +3308,7 @@
             if (isOpRestrictedLocked(uid, code, resolvedPackageName, bypass)) {
                 return AppOpsManager.MODE_IGNORED;
             }
-            final FeatureOp featureOp = op.getOrCreateFeature(op, featureId);
+            final AttributedOp attributedOp = op.getOrCreateAttribution(op, attributionTag);
             final int switchCode = AppOpsManager.opToSwitch(code);
             final UidState uidState = ops.uidState;
             // If there is a non-default per UID policy (we set UID op mode only if
@@ -3305,7 +3321,7 @@
                     if (DEBUG) Slog.d(TAG, "noteOperation: uid reject #" + uidMode + " for code "
                             + switchCode + " (" + code + ") uid " + uid + " package "
                             + resolvedPackageName);
-                    featureOp.rejected(uidState.state, AppOpsManager.OP_FLAG_SELF);
+                    attributedOp.rejected(uidState.state, AppOpsManager.OP_FLAG_SELF);
                     return uidMode;
                 }
             } else {
@@ -3317,21 +3333,21 @@
                     if (DEBUG) Slog.d(TAG, "startOperation: reject #" + mode + " for code "
                             + switchCode + " (" + code + ") uid " + uid + " package "
                             + resolvedPackageName);
-                    featureOp.rejected(uidState.state, AppOpsManager.OP_FLAG_SELF);
+                    attributedOp.rejected(uidState.state, AppOpsManager.OP_FLAG_SELF);
                     return mode;
                 }
             }
             if (DEBUG) Slog.d(TAG, "startOperation: allowing code " + code + " uid " + uid
                     + " package " + resolvedPackageName);
             try {
-                featureOp.started(clientId, uidState.state);
+                attributedOp.started(clientId, uidState.state);
             } catch (RemoteException e) {
                 throw new RuntimeException(e);
             }
         }
 
         if (shouldCollectAsyncNotedOp) {
-            collectAsyncNotedOp(uid, packageName, code, featureId, message);
+            collectAsyncNotedOp(uid, packageName, code, attributionTag, message);
         }
 
         return AppOpsManager.MODE_ALLOWED;
@@ -3339,7 +3355,7 @@
 
     @Override
     public void finishOperation(IBinder clientId, int code, int uid, String packageName,
-            String featureId) {
+            String attributionTag) {
         verifyIncomingUid(uid);
         verifyIncomingOp(code);
         String resolvedPackageName = resolvePackageName(uid, packageName);
@@ -3349,24 +3365,24 @@
 
         RestrictionBypass bypass;
         try {
-            bypass = verifyAndGetBypass(uid, packageName, featureId);
+            bypass = verifyAndGetBypass(uid, packageName, attributionTag);
         } catch (SecurityException e) {
             Slog.e(TAG, "Cannot finishOperation", e);
             return;
         }
 
         synchronized (this) {
-            Op op = getOpLocked(code, uid, resolvedPackageName, featureId, bypass, true);
+            Op op = getOpLocked(code, uid, resolvedPackageName, attributionTag, bypass, true);
             if (op == null) {
                 return;
             }
-            final FeatureOp featureOp = op.mFeatures.get(featureId);
-            if (featureOp == null) {
+            final AttributedOp attributedOp = op.mAttributions.get(attributionTag);
+            if (attributedOp == null) {
                 return;
             }
 
             try {
-                featureOp.finished(clientId);
+                attributedOp.finished(clientId);
             } catch (IllegalStateException e) {
                 Slog.e(TAG, "Operation not started: uid=" + uid + " pkg="
                         + packageName + " op=" + AppOpsManager.opToName(code), e);
@@ -3636,25 +3652,25 @@
      *
      * @param uid The uid the package belongs to
      * @param packageName The package the might belong to the uid
-     * @param featureId The feature in the package or {@code null} if no need to verify
+     * @param attributionTag attribution tag or {@code null} if no need to verify
      *
      * @return {@code true} iff the package is privileged
      */
     private @Nullable RestrictionBypass verifyAndGetBypass(int uid, String packageName,
-            @Nullable String featureId) {
+            @Nullable String attributionTag) {
         if (uid == Process.ROOT_UID) {
             // For backwards compatibility, don't check package name for root UID.
             return null;
         }
 
-        // Do not check if uid/packageName/featureId is already known
+        // Do not check if uid/packageName/attributionTag is already known
         synchronized (this) {
             UidState uidState = mUidStates.get(uid);
             if (uidState != null && uidState.pkgOps != null) {
                 Ops ops = uidState.pkgOps.get(packageName);
 
-                if (ops != null && (featureId == null || ops.knownFeatureIds.contains(featureId))
-                        && ops.bypass != null) {
+                if (ops != null && (attributionTag == null || ops.knownAttributionTags.contains(
+                        attributionTag)) && ops.bypass != null) {
                     return ops.bypass;
                 }
             }
@@ -3666,17 +3682,17 @@
             int pkgUid;
             AndroidPackage pkg = LocalServices.getService(PackageManagerInternal.class).getPackage(
                     packageName);
-            boolean isFeatureIdValid = false;
+            boolean isAttributionTagValid = false;
 
             if (pkg != null) {
-                if (featureId == null) {
-                    isFeatureIdValid = true;
+                if (attributionTag == null) {
+                    isAttributionTagValid = true;
                 } else {
-                    if (pkg.getFeatures() != null) {
-                        int numFeatures = pkg.getFeatures().size();
-                        for (int i = 0; i < numFeatures; i++) {
-                            if (pkg.getFeatures().get(i).id.equals(featureId)) {
-                                isFeatureIdValid = true;
+                    if (pkg.getAttributions() != null) {
+                        int numAttributions = pkg.getAttributions().size();
+                        for (int i = 0; i < numAttributions; i++) {
+                            if (pkg.getAttributions().get(i).tag.equals(attributionTag)) {
+                                isAttributionTagValid = true;
                             }
                         }
                     }
@@ -3686,8 +3702,8 @@
                         UserHandle.getUserId(uid), UserHandle.getAppId(pkg.getUid()));
                 bypass = getBypassforPackage(pkg);
             } else {
-                // Allow any feature id for resolvable uids
-                isFeatureIdValid = true;
+                // Allow any attribution tag for resolvable uids
+                isAttributionTagValid = true;
 
                 pkgUid = resolveUid(packageName);
                 if (pkgUid >= 0) {
@@ -3699,9 +3715,9 @@
                         + " but it is really " + pkgUid);
             }
 
-            if (!isFeatureIdValid) {
+            if (!isAttributionTagValid) {
                 // TODO moltmann: Switch from logging to enforcement
-                Slog.e(TAG, "featureId " + featureId + " not declared in manifest of "
+                Slog.e(TAG, "attributionTag " + attributionTag + " not declared in manifest of "
                         + packageName);
             }
         } finally {
@@ -3716,13 +3732,13 @@
      *
      * @param uid The uid the package belongs to
      * @param packageName The name of the package
-     * @param featureId The feature in the package
+     * @param attributionTag attribution tag
      * @param bypass When to bypass certain op restrictions (can be null if edit == false)
      * @param edit If an ops does not exist, create the ops?
 
      * @return The ops
      */
-    private Ops getOpsLocked(int uid, String packageName, @Nullable String featureId,
+    private Ops getOpsLocked(int uid, String packageName, @Nullable String attributionTag,
             @Nullable RestrictionBypass bypass, boolean edit) {
         UidState uidState = getUidStateLocked(uid, edit);
         if (uidState == null) {
@@ -3750,8 +3766,8 @@
                 ops.bypass = bypass;
             }
 
-            if (featureId != null) {
-                ops.knownFeatureIds.add(featureId);
+            if (attributionTag != null) {
+                ops.knownAttributionTags.add(attributionTag);
             }
         }
 
@@ -3780,15 +3796,15 @@
      * @param code The code of the op
      * @param uid The uid the of the package
      * @param packageName The package name for which to get the state for
-     * @param featureId The feature in the package
+     * @param attributionTag The attribution tag
      * @param bypass When to bypass certain op restrictions (can be null if edit == false)
      * @param edit Iff {@code true} create the {@link Op} object if not yet created
      *
      * @return The {@link Op state} of the op
      */
     private @Nullable Op getOpLocked(int code, int uid, @NonNull String packageName,
-            @Nullable String featureId, @Nullable RestrictionBypass bypass, boolean edit) {
-        Ops ops = getOpsLocked(uid, packageName, featureId, bypass, edit);
+            @Nullable String attributionTag, @Nullable RestrictionBypass bypass, boolean edit) {
+        Ops ops = getOpsLocked(uid, packageName, attributionTag, bypass, edit);
         if (ops == null) {
             return null;
         }
@@ -4045,9 +4061,9 @@
         uidState.evalForegroundOps(mOpModeWatchers);
     }
 
-    private void readFeatureOp(XmlPullParser parser, @NonNull Op parent,
-            @Nullable String feature) throws NumberFormatException, IOException {
-        final FeatureOp featureOp = parent.getOrCreateFeature(parent, feature);
+    private void readAttributionOp(XmlPullParser parser, @NonNull Op parent,
+            @Nullable String attribution) throws NumberFormatException, IOException {
+        final AttributedOp attributedOp = parent.getOrCreateAttribution(parent, attribution);
 
         final long key = XmlUtils.readLongAttribute(parser, "n");
         final int uidState = extractUidStateFromKey(key);
@@ -4058,14 +4074,14 @@
         final long accessDuration = XmlUtils.readLongAttribute(parser, "d", -1);
         final String proxyPkg = XmlUtils.readStringAttribute(parser, "pp");
         final int proxyUid = XmlUtils.readIntAttribute(parser, "pu", Process.INVALID_UID);
-        final String proxyFeatureId = XmlUtils.readStringAttribute(parser, "pc");
+        final String proxyAttributionTag = XmlUtils.readStringAttribute(parser, "pc");
 
         if (accessTime > 0) {
-            featureOp.accessed(accessTime, accessDuration, proxyUid, proxyPkg, proxyFeatureId,
-                    uidState, opFlags);
+            attributedOp.accessed(accessTime, accessDuration, proxyUid, proxyPkg,
+                    proxyAttributionTag, uidState, opFlags);
         }
         if (rejectTime > 0) {
-            featureOp.rejected(rejectTime, uidState, opFlags);
+            attributedOp.rejected(rejectTime, uidState, opFlags);
         }
     }
 
@@ -4091,7 +4107,7 @@
             }
             String tagName = parser.getName();
             if (tagName.equals("st")) {
-                readFeatureOp(parser, op, XmlUtils.readStringAttribute(parser, "id"));
+                readAttributionOp(parser, op, XmlUtils.readStringAttribute(parser, "id"));
             } else {
                 Slog.w(TAG, "Unknown element under <op>: "
                         + parser.getName());
@@ -4205,11 +4221,11 @@
                                 out.attribute(null, "m", Integer.toString(op.getMode()));
                             }
 
-                            for (String featureId : op.getFeatures().keySet()) {
-                                final OpFeatureEntry feature = op.getFeatures().get(
-                                        featureId);
+                            for (String attributionTag : op.getAttributedOpEntries().keySet()) {
+                                final AttributedOpEntry attribution =
+                                        op.getAttributedOpEntries().get(attributionTag);
 
-                                final ArraySet<Long> keys = feature.collectKeys();
+                                final ArraySet<Long> keys = attribution.collectKeys();
 
                                 final int keyCount = keys.size();
                                 for (int k = 0; k < keyCount; k++) {
@@ -4218,14 +4234,14 @@
                                     final int uidState = AppOpsManager.extractUidStateFromKey(key);
                                     final int flags = AppOpsManager.extractFlagsFromKey(key);
 
-                                    final long accessTime = feature.getLastAccessTime(uidState,
+                                    final long accessTime = attribution.getLastAccessTime(uidState,
                                             uidState, flags);
-                                    final long rejectTime = feature.getLastRejectTime(uidState,
+                                    final long rejectTime = attribution.getLastRejectTime(uidState,
                                             uidState, flags);
-                                    final long accessDuration = feature.getLastDuration(uidState,
-                                            uidState, flags);
+                                    final long accessDuration = attribution.getLastDuration(
+                                            uidState, uidState, flags);
                                     // Proxy information for rejections is not backed up
-                                    final OpEventProxyInfo proxy = feature.getLastProxyInfo(
+                                    final OpEventProxyInfo proxy = attribution.getLastProxyInfo(
                                             uidState, uidState, flags);
 
                                     if (accessTime <= 0 && rejectTime <= 0 && accessDuration <= 0
@@ -4234,17 +4250,17 @@
                                     }
 
                                     String proxyPkg = null;
-                                    String proxyFeatureId = null;
+                                    String proxyAttributionTag = null;
                                     int proxyUid = Process.INVALID_UID;
                                     if (proxy != null) {
                                         proxyPkg = proxy.getPackageName();
-                                        proxyFeatureId = proxy.getFeatureId();
+                                        proxyAttributionTag = proxy.getAttributionTag();
                                         proxyUid = proxy.getUid();
                                     }
 
                                     out.startTag(null, "st");
-                                    if (featureId != null) {
-                                        out.attribute(null, "id", featureId);
+                                    if (attributionTag != null) {
+                                        out.attribute(null, "id", attributionTag);
                                     }
                                     out.attribute(null, "n", Long.toString(key));
                                     if (accessTime > 0) {
@@ -4259,8 +4275,8 @@
                                     if (proxyPkg != null) {
                                         out.attribute(null, "pp", proxyPkg);
                                     }
-                                    if (proxyFeatureId != null) {
-                                        out.attribute(null, "pc", proxyFeatureId);
+                                    if (proxyAttributionTag != null) {
+                                        out.attribute(null, "pc", proxyAttributionTag);
                                     }
                                     if (proxyUid >= 0) {
                                         out.attribute(null, "pu", Integer.toString(proxyUid));
@@ -4294,7 +4310,7 @@
 
         int userId = UserHandle.USER_SYSTEM;
         String packageName;
-        String featureId;
+        String attributionTag;
         String opStr;
         String modeStr;
         int op;
@@ -4396,8 +4412,8 @@
                     userId = UserHandle.parseUserArg(getNextArgRequired());
                 } else if ("--uid".equals(argument)) {
                     targetsUid = true;
-                } else if ("--feature".equals(argument)) {
-                    featureId = getNextArgRequired();
+                } else if ("--attribution".equals(argument)) {
+                    attributionTag = getNextArgRequired();
                 } else {
                     if (packageName == null) {
                         packageName = argument;
@@ -4492,13 +4508,16 @@
         pw.println("AppOps service (appops) commands:");
         pw.println("  help");
         pw.println("    Print this help text.");
-        pw.println("  start [--user <USER_ID>] [--feature <FEATURE_ID>] <PACKAGE | UID> <OP> ");
+        pw.println("  start [--user <USER_ID>] [--attribution <ATTRIBUTION_TAG>] <PACKAGE | UID> "
+                + "<OP> ");
         pw.println("    Starts a given operation for a particular application.");
-        pw.println("  stop [--user <USER_ID>] [--feature <FEATURE_ID>] <PACKAGE | UID> <OP> ");
+        pw.println("  stop [--user <USER_ID>] [--attribution <ATTRIBUTION_TAG>] <PACKAGE | UID> "
+                + "<OP> ");
         pw.println("    Stops a given operation for a particular application.");
         pw.println("  set [--user <USER_ID>] <[--uid] PACKAGE | UID> <OP> <MODE>");
         pw.println("    Set the mode for a particular application and operation.");
-        pw.println("  get [--user <USER_ID>] [--feature <FEATURE_ID>] <PACKAGE | UID> [<OP>]");
+        pw.println("  get [--user <USER_ID>] [--attribution <ATTRIBUTION_TAG>] <PACKAGE | UID> "
+                + "[<OP>]");
         pw.println("    Return the mode for a particular application and optional operation.");
         pw.println("  query-op [--user <USER_ID>] <OP> [<MODE>]");
         pw.println("    Print all packages that currently have the given op in the given mode.");
@@ -4512,8 +4531,8 @@
         pw.println("    <PACKAGE> an Android package name or its UID if prefixed by --uid");
         pw.println("    <OP>      an AppOps operation.");
         pw.println("    <MODE>    one of allow, ignore, deny, or default");
-        pw.println("    <USER_ID> the user id under which the package is installed. If --user is not");
-        pw.println("              specified, the current user is assumed.");
+        pw.println("    <USER_ID> the user id under which the package is installed. If --user is");
+        pw.println("              not specified, the current user is assumed.");
     }
 
     static int onShellCommand(Shell shell, String cmd) {
@@ -4602,7 +4621,7 @@
                             pw.print(AppOpsManager.opToName(ent.getOp()));
                             pw.print(": ");
                             pw.print(AppOpsManager.modeToName(ent.getMode()));
-                            if (shell.featureId == null) {
+                            if (shell.attributionTag == null) {
                                 if (ent.getLastAccessTime(OP_FLAGS_ALL) != -1) {
                                     pw.print("; time=");
                                     TimeUtils.formatDuration(
@@ -4622,29 +4641,30 @@
                                     TimeUtils.formatDuration(ent.getLastDuration(OP_FLAGS_ALL), pw);
                                 }
                             } else {
-                                final OpFeatureEntry featureEnt = ent.getFeatures().get(
-                                        shell.featureId);
-                                if (featureEnt != null) {
-                                    if (featureEnt.getLastAccessTime(OP_FLAGS_ALL) != -1) {
+                                final AppOpsManager.AttributedOpEntry attributionEnt =
+                                        ent.getAttributedOpEntries().get(shell.attributionTag);
+                                if (attributionEnt != null) {
+                                    if (attributionEnt.getLastAccessTime(OP_FLAGS_ALL) != -1) {
                                         pw.print("; time=");
-                                        TimeUtils.formatDuration(now - featureEnt.getLastAccessTime(
-                                                OP_FLAGS_ALL), pw);
+                                        TimeUtils.formatDuration(
+                                                now - attributionEnt.getLastAccessTime(
+                                                        OP_FLAGS_ALL), pw);
                                         pw.print(" ago");
                                     }
-                                    if (featureEnt.getLastRejectTime(OP_FLAGS_ALL) != -1) {
+                                    if (attributionEnt.getLastRejectTime(OP_FLAGS_ALL) != -1) {
                                         pw.print("; rejectTime=");
                                         TimeUtils.formatDuration(
-                                                now - featureEnt.getLastRejectTime(OP_FLAGS_ALL),
-                                                pw);
+                                                now - attributionEnt.getLastRejectTime(
+                                                        OP_FLAGS_ALL), pw);
                                         pw.print(" ago");
                                     }
-                                    if (featureEnt.isRunning()) {
+                                    if (attributionEnt.isRunning()) {
                                         pw.print(" (running)");
-                                    } else if (featureEnt.getLastDuration(OP_FLAGS_ALL)
+                                    } else if (attributionEnt.getLastDuration(OP_FLAGS_ALL)
                                             != -1) {
                                         pw.print("; duration=");
                                         TimeUtils.formatDuration(
-                                                featureEnt.getLastDuration(OP_FLAGS_ALL), pw);
+                                                attributionEnt.getLastDuration(OP_FLAGS_ALL), pw);
                                     }
                                 }
                             }
@@ -4752,7 +4772,7 @@
 
                     if (shell.packageName != null) {
                         shell.mInterface.startOperation(shell.mToken, shell.op, shell.packageUid,
-                                shell.packageName, shell.featureId, true, true,
+                                shell.packageName, shell.attributionTag, true, true,
                                 "appops start shell command");
                     } else {
                         return -1;
@@ -4766,8 +4786,8 @@
                     }
 
                     if (shell.packageName != null) {
-                        shell.mInterface.finishOperation(shell.mToken,
-                                shell.op, shell.packageUid, shell.packageName, shell.featureId);
+                        shell.mInterface.finishOperation(shell.mToken, shell.op, shell.packageUid,
+                                shell.packageName, shell.attributionTag);
                     } else {
                         return -1;
                     }
@@ -4792,35 +4812,35 @@
         pw.println("    Limit output to data associated with the given app op mode.");
         pw.println("  --package [PACKAGE]");
         pw.println("    Limit output to data associated with the given package name.");
-        pw.println("  --featureId [featureId]");
-        pw.println("    Limit output to data associated with the given feature id.");
+        pw.println("  --attributionTag [attributionTag]");
+        pw.println("    Limit output to data associated with the given attribution tag.");
         pw.println("  --watchers");
         pw.println("    Only output the watcher sections.");
     }
 
-    private void dumpStatesLocked(@NonNull PrintWriter pw, @Nullable String filterFeatureId,
+    private void dumpStatesLocked(@NonNull PrintWriter pw, @Nullable String filterAttributionTag,
             @HistoricalOpsRequestFilter int filter, long nowElapsed, @NonNull Op op, long now,
             @NonNull SimpleDateFormat sdf, @NonNull Date date, @NonNull String prefix) {
-        final int numFeatures = op.mFeatures.size();
-        for (int i = 0; i < numFeatures; i++) {
-            if ((filter & FILTER_BY_FEATURE_ID) != 0 && !Objects.equals(op.mFeatures.keyAt(i),
-                    filterFeatureId)) {
+        final int numAttributions = op.mAttributions.size();
+        for (int i = 0; i < numAttributions; i++) {
+            if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(
+                    op.mAttributions.keyAt(i), filterAttributionTag)) {
                 continue;
             }
 
-            pw.print(prefix + op.mFeatures.keyAt(i) + "=[\n");
-            dumpStatesLocked(pw, nowElapsed, op, op.mFeatures.keyAt(i), now, sdf, date,
+            pw.print(prefix + op.mAttributions.keyAt(i) + "=[\n");
+            dumpStatesLocked(pw, nowElapsed, op, op.mAttributions.keyAt(i), now, sdf, date,
                     prefix + "  ");
             pw.print(prefix + "]\n");
         }
     }
 
     private void dumpStatesLocked(@NonNull PrintWriter pw, long nowElapsed, @NonNull Op op,
-            @Nullable String featureId, long now, @NonNull SimpleDateFormat sdf,
+            @Nullable String attributionTag, long now, @NonNull SimpleDateFormat sdf,
             @NonNull Date date, @NonNull String prefix) {
 
-        final OpFeatureEntry entry = op.createSingleFeatureEntryLocked(
-                featureId).getFeatures().get(featureId);
+        final AttributedOpEntry entry = op.createSingleAttributionEntryLocked(
+                attributionTag).getAttributedOpEntries().get(attributionTag);
 
         final ArraySet<Long> keys = entry.collectKeys();
 
@@ -4837,11 +4857,11 @@
             final OpEventProxyInfo proxy = entry.getLastProxyInfo(uidState, uidState, flags);
 
             String proxyPkg = null;
-            String proxyFeatureId = null;
+            String proxyAttributionTag = null;
             int proxyUid = Process.INVALID_UID;
             if (proxy != null) {
                 proxyPkg = proxy.getPackageName();
-                proxyFeatureId = proxy.getFeatureId();
+                proxyAttributionTag = proxy.getAttributionTag();
                 proxyUid = proxy.getUid();
             }
 
@@ -4865,8 +4885,8 @@
                     pw.print(proxyUid);
                     pw.print(", pkg=");
                     pw.print(proxyPkg);
-                    pw.print(", feature=");
-                    pw.print(proxyFeatureId);
+                    pw.print(", attributionTag=");
+                    pw.print(proxyAttributionTag);
                     pw.print("]");
                 }
                 pw.println();
@@ -4887,21 +4907,21 @@
                     pw.print(proxyUid);
                     pw.print(", pkg=");
                     pw.print(proxyPkg);
-                    pw.print(", feature=");
-                    pw.print(proxyFeatureId);
+                    pw.print(", attributionTag=");
+                    pw.print(proxyAttributionTag);
                     pw.print("]");
                 }
                 pw.println();
             }
         }
 
-        final FeatureOp featureOp = op.mFeatures.get(featureId);
-        if (featureOp.isRunning()) {
+        final AttributedOp attributedOp = op.mAttributions.get(attributionTag);
+        if (attributedOp.isRunning()) {
             long earliestElapsedTime = Long.MAX_VALUE;
             long maxNumStarts = 0;
-            int numInProgressEvents = featureOp.mInProgressEvents.size();
+            int numInProgressEvents = attributedOp.mInProgressEvents.size();
             for (int i = 0; i < numInProgressEvents; i++) {
-                InProgressStartOpEvent event = featureOp.mInProgressEvents.valueAt(i);
+                InProgressStartOpEvent event = attributedOp.mInProgressEvents.valueAt(i);
 
                 earliestElapsedTime = Math.min(earliestElapsedTime, event.getStartElapsedTime());
                 maxNumStarts = Math.max(maxNumStarts, event.numUnfinishedStarts);
@@ -4924,7 +4944,7 @@
 
         int dumpOp = OP_NONE;
         String dumpPackage = null;
-        String dumpFeatureId = null;
+        String dumpAttributionTag = null;
         int dumpUid = Process.INVALID_UID;
         int dumpMode = -1;
         boolean dumpWatchers = false;
@@ -4971,14 +4991,14 @@
                     }
                     dumpUid = UserHandle.getAppId(dumpUid);
                     dumpFilter |= FILTER_BY_UID;
-                } else if ("--featureId".equals(arg)) {
+                } else if ("--attributionTag".equals(arg)) {
                     i++;
                     if (i >= args.length) {
-                        pw.println("No argument for --featureId option");
+                        pw.println("No argument for --attributionTag option");
                         return;
                     }
-                    dumpFeatureId = args[i];
-                    dumpFilter |= FILTER_BY_FEATURE_ID;
+                    dumpAttributionTag = args[i];
+                    dumpFilter |= FILTER_BY_ATTRIBUTION_TAG;
                 } else if ("--mode".equals(arg)) {
                     i++;
                     if (i >= args.length) {
@@ -5317,8 +5337,8 @@
                             pw.print("="); pw.print(AppOpsManager.modeToName(mode));
                         }
                         pw.println("): ");
-                        dumpStatesLocked(pw, dumpFeatureId, dumpFilter, nowElapsed, op, now, sdf,
-                                date, "        ");
+                        dumpStatesLocked(pw, dumpAttributionTag, dumpFilter, nowElapsed, op, now,
+                                sdf, date, "        ");
                     }
                 }
             }
@@ -5417,7 +5437,7 @@
 
         // Must not hold the appops lock
         if (dumpHistory && !dumpWatchers) {
-            mHistoricalRegistry.dump("  ", pw, dumpUid, dumpPackage, dumpFeatureId, dumpOp,
+            mHistoricalRegistry.dump("  ", pw, dumpUid, dumpPackage, dumpAttributionTag, dumpOp,
                     dumpFilter);
         }
     }
@@ -5522,7 +5542,7 @@
         if (resolvedPackageName == null) {
             return false;
         }
-        // TODO moltmann: Allow to check for feature op activeness
+        // TODO moltmann: Allow to check for attribution op activeness
         synchronized (AppOpsService.this) {
             Ops pkgOps = getOpsLocked(uid, resolvedPackageName, null, null, false);
             if (pkgOps == null) {
@@ -5583,7 +5603,7 @@
      * Report runtime access to AppOp together with message (including stack trace)
      *
      * @param packageName The package which reported the op
-     * @param notedAppOp contains code of op and featureId provided by developer
+     * @param notedAppOp contains code of op and attributionTag provided by developer
      * @param message Message describing AppOp access (can be stack trace)
      *
      * @return Config for future sampling to reduce amount of reporting
@@ -5605,7 +5625,7 @@
 
             reportRuntimeAppOpAccessMessageInternalLocked(uid, packageName,
                     AppOpsManager.strOpToOp(notedAppOp.getOp()),
-                    notedAppOp.getFeatureId(), message);
+                    notedAppOp.getAttributionTag(), message);
 
             return new MessageSamplingConfig(mSampledAppOpCode, mAcceptableLeftDistance,
                     Instant.now().plus(1, ChronoUnit.HOURS).toEpochMilli());
@@ -5618,17 +5638,18 @@
      * @param uid Uid of the package which reported the op
      * @param packageName The package which reported the op
      * @param opCode Code of AppOp
-     * @param featureId FeautreId of AppOp reported
+     * @param attributionTag FeautreId of AppOp reported
      * @param message Message describing AppOp access (can be stack trace)
      */
     private void reportRuntimeAppOpAccessMessageAsyncLocked(int uid,
-            @NonNull String packageName, int opCode, @Nullable String featureId,
+            @NonNull String packageName, int opCode, @Nullable String attributionTag,
             @NonNull String message) {
         switchPackageIfRarelyUsedLocked(packageName);
         if (!Objects.equals(mSampledPackage, packageName)) {
             return;
         }
-        reportRuntimeAppOpAccessMessageInternalLocked(uid, packageName, opCode, featureId, message);
+        reportRuntimeAppOpAccessMessageInternalLocked(uid, packageName, opCode, attributionTag,
+                message);
     }
 
     /**
@@ -5636,7 +5657,7 @@
      * reporting uniformly at random across all received messages.
      */
     private void reportRuntimeAppOpAccessMessageInternalLocked(int uid,
-            @NonNull String packageName, int opCode, @Nullable String featureId,
+            @NonNull String packageName, int opCode, @Nullable String attributionTag,
             @NonNull String message) {
         int newLeftDistance = AppOpsManager.leftCircularDistance(opCode,
                 mSampledAppOpCode, _NUM_OP);
@@ -5653,7 +5674,7 @@
         mMessagesCollectedCount += 1.0f;
         if (ThreadLocalRandom.current().nextFloat() <= 1.0f / mMessagesCollectedCount) {
             mCollectedRuntimePermissionMessage = new RuntimeAppOpAccessMessage(uid, opCode,
-                    packageName, featureId, message, mSamplingStrategy);
+                    packageName, attributionTag, message, mSamplingStrategy);
         }
         return;
     }
diff --git a/services/core/java/com/android/server/appop/HistoricalRegistry.java b/services/core/java/com/android/server/appop/HistoricalRegistry.java
index cd450d4..ed45069 100644
--- a/services/core/java/com/android/server/appop/HistoricalRegistry.java
+++ b/services/core/java/com/android/server/appop/HistoricalRegistry.java
@@ -15,7 +15,7 @@
  */
 package com.android.server.appop;
 
-import static android.app.AppOpsManager.FILTER_BY_FEATURE_ID;
+import static android.app.AppOpsManager.FILTER_BY_ATTRIBUTION_TAG;
 import static android.app.AppOpsManager.FILTER_BY_OP_NAMES;
 import static android.app.AppOpsManager.FILTER_BY_PACKAGE_NAME;
 import static android.app.AppOpsManager.FILTER_BY_UID;
@@ -23,7 +23,6 @@
 import android.annotation.NonNull;
 import android.annotation.Nullable;
 import android.app.AppOpsManager;
-import android.app.AppOpsManager.HistoricalFeatureOps;
 import android.app.AppOpsManager.HistoricalMode;
 import android.app.AppOpsManager.HistoricalOp;
 import android.app.AppOpsManager.HistoricalOps;
@@ -282,7 +281,7 @@
     }
 
     void dump(String prefix, PrintWriter pw, int filterUid, @Nullable String filterPackage,
-            @Nullable String filterFeatureId, int filterOp,
+            @Nullable String filterAttributionTag, int filterOp,
             @HistoricalOpsRequestFilter int filter) {
         if (!isApiEnabled()) {
             return;
@@ -298,7 +297,7 @@
                 pw.println(AppOpsManager.historicalModeToString(mMode));
 
                 final StringDumpVisitor visitor = new StringDumpVisitor(prefix + "  ",
-                        pw, filterUid, filterPackage, filterFeatureId, filterOp, filter);
+                        pw, filterUid, filterPackage, filterAttributionTag, filterOp, filter);
                 final long nowMillis = System.currentTimeMillis();
 
                 // Dump in memory state first
@@ -338,7 +337,7 @@
     }
 
     void getHistoricalOpsFromDiskRaw(int uid, @NonNull String packageName,
-            @Nullable String featureId, @Nullable String[] opNames,
+            @Nullable String attributionTag, @Nullable String[] opNames,
             @HistoricalOpsRequestFilter int filter, long beginTimeMillis, long endTimeMillis,
             @OpFlags int flags, @NonNull RemoteCallback callback) {
         if (!isApiEnabled()) {
@@ -354,7 +353,7 @@
                     return;
                 }
                 final HistoricalOps result = new HistoricalOps(beginTimeMillis, endTimeMillis);
-                mPersistence.collectHistoricalOpsDLocked(result, uid, packageName, featureId,
+                mPersistence.collectHistoricalOpsDLocked(result, uid, packageName, attributionTag,
                         opNames, filter, beginTimeMillis, endTimeMillis, flags);
                 final Bundle payload = new Bundle();
                 payload.putParcelable(AppOpsManager.KEY_HISTORICAL_OPS, result);
@@ -363,7 +362,7 @@
         }
     }
 
-    void getHistoricalOps(int uid, @NonNull String packageName, @Nullable String featureId,
+    void getHistoricalOps(int uid, @NonNull String packageName, @Nullable String attributionTag,
             @Nullable String[] opNames, @HistoricalOpsRequestFilter int filter,
             long beginTimeMillis, long endTimeMillis, @OpFlags int flags,
             @NonNull RemoteCallback callback) {
@@ -401,7 +400,7 @@
                         || inMemoryAdjEndTimeMillis <= currentOps.getBeginTimeMillis())) {
                     // Some of the current batch falls into the query, so extract that.
                     final HistoricalOps currentOpsCopy = new HistoricalOps(currentOps);
-                    currentOpsCopy.filter(uid, packageName, featureId, opNames, filter,
+                    currentOpsCopy.filter(uid, packageName, attributionTag, opNames, filter,
                             inMemoryAdjBeginTimeMillis, inMemoryAdjEndTimeMillis);
                     result.merge(currentOpsCopy);
                 }
@@ -421,7 +420,7 @@
                         - onDiskAndInMemoryOffsetMillis, 0);
                 final long onDiskAdjEndTimeMillis = Math.max(inMemoryAdjEndTimeMillis
                         - onDiskAndInMemoryOffsetMillis, 0);
-                mPersistence.collectHistoricalOpsDLocked(result, uid, packageName, featureId,
+                mPersistence.collectHistoricalOpsDLocked(result, uid, packageName, attributionTag,
                         opNames, filter, onDiskAdjBeginTimeMillis, onDiskAdjEndTimeMillis, flags);
             }
 
@@ -436,7 +435,7 @@
     }
 
     void incrementOpAccessedCount(int op, int uid, @NonNull String packageName,
-            @Nullable String featureId, @UidState int uidState, @OpFlags int flags) {
+            @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags) {
         synchronized (mInMemoryLock) {
             if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
                 if (!isPersistenceInitializedMLocked()) {
@@ -445,13 +444,13 @@
                 }
                 getUpdatedPendingHistoricalOpsMLocked(
                         System.currentTimeMillis()).increaseAccessCount(op, uid, packageName,
-                        featureId, uidState, flags, 1);
+                        attributionTag, uidState, flags, 1);
             }
         }
     }
 
     void incrementOpRejected(int op, int uid, @NonNull String packageName,
-            @Nullable String featureId, @UidState int uidState, @OpFlags int flags) {
+            @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags) {
         synchronized (mInMemoryLock) {
             if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
                 if (!isPersistenceInitializedMLocked()) {
@@ -460,13 +459,13 @@
                 }
                 getUpdatedPendingHistoricalOpsMLocked(
                         System.currentTimeMillis()).increaseRejectCount(op, uid, packageName,
-                        featureId, uidState, flags, 1);
+                        attributionTag, uidState, flags, 1);
             }
         }
     }
 
     void increaseOpAccessDuration(int op, int uid, @NonNull String packageName,
-            @Nullable String featureId, @UidState int uidState, @OpFlags int flags,
+            @Nullable String attributionTag, @UidState int uidState, @OpFlags int flags,
             long increment) {
         synchronized (mInMemoryLock) {
             if (mMode == AppOpsManager.HISTORICAL_MODE_ENABLED_ACTIVE) {
@@ -476,7 +475,7 @@
                 }
                 getUpdatedPendingHistoricalOpsMLocked(
                         System.currentTimeMillis()).increaseAccessDuration(op, uid, packageName,
-                        featureId, uidState, flags, increment);
+                        attributionTag, uidState, flags, increment);
             }
         }
     }
@@ -728,7 +727,7 @@
         private static final String TAG_OPS = "ops";
         private static final String TAG_UID = "uid";
         private static final String TAG_PACKAGE = "pkg";
-        private static final String TAG_FEATURE = "ftr";
+        private static final String TAG_ATTRIBUTION = "ftr";
         private static final String TAG_OP = "op";
         private static final String TAG_STATE = "st";
 
@@ -807,9 +806,9 @@
 
         @Nullable List<HistoricalOps> readHistoryRawDLocked() {
             return collectHistoricalOpsBaseDLocked(Process.INVALID_UID /*filterUid*/,
-                    null /*filterPackageName*/, null /*filterFeatureId*/, null /*filterOpNames*/,
-                    0 /*filter*/, 0 /*filterBeginTimeMills*/, Long.MAX_VALUE /*filterEndTimeMills*/,
-                    AppOpsManager.OP_FLAGS_ALL);
+                    null /*filterPackageName*/, null /*filterAttributionTag*/,
+                    null /*filterOpNames*/, 0 /*filter*/, 0 /*filterBeginTimeMills*/,
+                    Long.MAX_VALUE /*filterEndTimeMills*/, AppOpsManager.OP_FLAGS_ALL);
         }
 
         @Nullable List<HistoricalOps> readHistoryDLocked() {
@@ -861,13 +860,13 @@
             return 0;
         }
 
-        private void collectHistoricalOpsDLocked(@NonNull HistoricalOps currentOps,
-                int filterUid, @Nullable String filterPackageName, @Nullable String filterFeatureId,
+        private void collectHistoricalOpsDLocked(@NonNull HistoricalOps currentOps, int filterUid,
+                @Nullable String filterPackageName, @Nullable String filterAttributionTag,
                 @Nullable String[] filterOpNames, @HistoricalOpsRequestFilter int filter,
                 long filterBeingMillis, long filterEndMillis, @OpFlags int filterFlags) {
             final List<HistoricalOps> readOps = collectHistoricalOpsBaseDLocked(filterUid,
-                    filterPackageName, filterFeatureId, filterOpNames, filter, filterBeingMillis,
-                    filterEndMillis, filterFlags);
+                    filterPackageName, filterAttributionTag, filterOpNames, filter,
+                    filterBeingMillis, filterEndMillis, filterFlags);
             if (readOps != null) {
                 final int readCount = readOps.size();
                 for (int i = 0; i < readCount; i++) {
@@ -877,8 +876,8 @@
              }
         }
 
-        private @Nullable LinkedList<HistoricalOps> collectHistoricalOpsBaseDLocked(
-                int filterUid, @Nullable String filterPackageName, @Nullable String filterFeatureId,
+        private @Nullable LinkedList<HistoricalOps> collectHistoricalOpsBaseDLocked(int filterUid,
+                @Nullable String filterPackageName, @Nullable String filterAttributionTag,
                 @Nullable String[] filterOpNames, @HistoricalOpsRequestFilter int filter,
                 long filterBeginTimeMillis, long filterEndTimeMillis, @OpFlags int filterFlags) {
             File baseDir = null;
@@ -892,7 +891,7 @@
                 final Set<String> historyFiles = getHistoricalFileNames(baseDir);
                 final long[] globalContentOffsetMillis = {0};
                 final LinkedList<HistoricalOps> ops = collectHistoricalOpsRecursiveDLocked(
-                        baseDir, filterUid, filterPackageName, filterFeatureId, filterOpNames,
+                        baseDir, filterUid, filterPackageName, filterAttributionTag, filterOpNames,
                         filter, filterBeginTimeMillis, filterEndTimeMillis, filterFlags,
                         globalContentOffsetMillis, null /*outOps*/, 0 /*depth*/, historyFiles);
                 if (DEBUG) {
@@ -909,7 +908,7 @@
 
         private @Nullable LinkedList<HistoricalOps> collectHistoricalOpsRecursiveDLocked(
                 @NonNull File baseDir, int filterUid, @Nullable String filterPackageName,
-                @Nullable String filterFeatureId, @Nullable String[] filterOpNames,
+                @Nullable String filterAttributionTag, @Nullable String[] filterOpNames,
                 @HistoricalOpsRequestFilter int filter, long filterBeginTimeMillis,
                 long filterEndTimeMillis, @OpFlags int filterFlags,
                 @NonNull long[] globalContentOffsetMillis,
@@ -927,7 +926,7 @@
             // Read historical data at this level
             final List<HistoricalOps> readOps = readHistoricalOpsLocked(baseDir,
                     previousIntervalEndMillis, currentIntervalEndMillis, filterUid,
-                    filterPackageName, filterFeatureId, filterOpNames, filter,
+                    filterPackageName, filterAttributionTag, filterOpNames, filter,
                     filterBeginTimeMillis, filterEndTimeMillis, filterFlags,
                     globalContentOffsetMillis, depth, historyFiles);
             // Empty is a special signal to stop diving
@@ -937,7 +936,7 @@
 
             // Collect older historical data from subsequent levels
             outOps = collectHistoricalOpsRecursiveDLocked(baseDir, filterUid, filterPackageName,
-                    filterFeatureId, filterOpNames, filter, filterBeginTimeMillis,
+                    filterAttributionTag, filterOpNames, filter, filterBeginTimeMillis,
                     filterEndTimeMillis, filterFlags, globalContentOffsetMillis, outOps, depth + 1,
                     historyFiles);
 
@@ -1006,7 +1005,7 @@
             final List<HistoricalOps> existingOps = readHistoricalOpsLocked(oldBaseDir,
                     previousIntervalEndMillis, currentIntervalEndMillis,
                     Process.INVALID_UID /*filterUid*/, null /*filterPackageName*/,
-                    null /*filterFeatureId*/, null /*filterOpNames*/, 0 /*filter*/,
+                    null /*filterAttributionTag*/, null /*filterOpNames*/, 0 /*filter*/,
                     Long.MIN_VALUE /*filterBeginTimeMillis*/,
                     Long.MAX_VALUE /*filterEndTimeMillis*/, AppOpsManager.OP_FLAGS_ALL, null, depth,
                     null /*historyFiles*/);
@@ -1120,7 +1119,7 @@
 
         private @Nullable List<HistoricalOps> readHistoricalOpsLocked(File baseDir,
                 long intervalBeginMillis, long intervalEndMillis, int filterUid,
-                @Nullable String filterPackageName, @Nullable String filterFeatureId,
+                @Nullable String filterPackageName, @Nullable String filterAttributionTag,
                 @Nullable String[] filterOpNames, @HistoricalOpsRequestFilter int filter,
                 long filterBeginTimeMillis, long filterEndTimeMillis, @OpFlags int filterFlags,
                 @Nullable long[] cumulativeOverflowMillis, int depth,
@@ -1147,15 +1146,16 @@
                     return null;
                 }
             }
-            return readHistoricalOpsLocked(file, filterUid, filterPackageName, filterFeatureId,
+            return readHistoricalOpsLocked(file, filterUid, filterPackageName, filterAttributionTag,
                     filterOpNames, filter, filterBeginTimeMillis, filterEndTimeMillis, filterFlags,
                     cumulativeOverflowMillis);
         }
 
-        private @Nullable List<HistoricalOps> readHistoricalOpsLocked(@NonNull File file,
-                int filterUid, @Nullable String filterPackageName, @Nullable String filterFeatureId,
-                @Nullable String[] filterOpNames, @HistoricalOpsRequestFilter int filter,
-                long filterBeginTimeMillis, long filterEndTimeMillis, @OpFlags int filterFlags,
+        private @Nullable  List<HistoricalOps> readHistoricalOpsLocked(@NonNull File file,
+                int filterUid, @Nullable String filterPackageName,
+                @Nullable String filterAttributionTag, @Nullable String[] filterOpNames,
+                @HistoricalOpsRequestFilter int filter, long filterBeginTimeMillis,
+                long filterEndTimeMillis, @OpFlags int filterFlags,
                 @Nullable long[] cumulativeOverflowMillis)
                 throws IOException, XmlPullParserException {
             if (DEBUG) {
@@ -1180,7 +1180,7 @@
                 while (XmlUtils.nextElementWithin(parser, depth)) {
                     if (TAG_OPS.equals(parser.getName())) {
                         final HistoricalOps ops = readeHistoricalOpsDLocked(parser, filterUid,
-                                filterPackageName, filterFeatureId, filterOpNames, filter,
+                                filterPackageName, filterAttributionTag, filterOpNames, filter,
                                 filterBeginTimeMillis, filterEndTimeMillis, filterFlags,
                                 cumulativeOverflowMillis);
                         if (ops == null) {
@@ -1215,7 +1215,7 @@
 
         private @Nullable HistoricalOps readeHistoricalOpsDLocked(
                 @NonNull XmlPullParser parser, int filterUid, @Nullable String filterPackageName,
-                @Nullable String filterFeatureId, @Nullable String[] filterOpNames,
+                @Nullable String filterAttributionTag, @Nullable String[] filterOpNames,
                 @HistoricalOpsRequestFilter int filter, long filterBeginTimeMillis,
                 long filterEndTimeMillis, @OpFlags int filterFlags,
                 @Nullable long[] cumulativeOverflowMillis)
@@ -1245,8 +1245,8 @@
             while (XmlUtils.nextElementWithin(parser, depth)) {
                 if (TAG_UID.equals(parser.getName())) {
                     final HistoricalOps returnedOps = readHistoricalUidOpsDLocked(ops, parser,
-                            filterUid, filterPackageName, filterFeatureId, filterOpNames, filter,
-                            filterFlags, filterScale);
+                            filterUid, filterPackageName, filterAttributionTag, filterOpNames,
+                            filter, filterFlags, filterScale);
                     if (ops == null) {
                         ops = returnedOps;
                     }
@@ -1260,7 +1260,7 @@
 
         private @Nullable HistoricalOps readHistoricalUidOpsDLocked(
                 @Nullable HistoricalOps ops, @NonNull XmlPullParser parser, int filterUid,
-                @Nullable String filterPackageName, @Nullable String filterFeatureId,
+                @Nullable String filterPackageName, @Nullable String filterAttributionTag,
                 @Nullable String[] filterOpNames, @HistoricalOpsRequestFilter int filter,
                 @OpFlags int filterFlags, double filterScale)
                 throws IOException, XmlPullParserException {
@@ -1272,8 +1272,8 @@
             final int depth = parser.getDepth();
             while (XmlUtils.nextElementWithin(parser, depth)) {
                 if (TAG_PACKAGE.equals(parser.getName())) {
-                    final HistoricalOps returnedOps = readHistoricalPackageOpsDLocked(ops,
-                            uid, parser, filterPackageName, filterFeatureId, filterOpNames, filter,
+                    final HistoricalOps returnedOps = readHistoricalPackageOpsDLocked(ops, uid,
+                            parser, filterPackageName, filterAttributionTag, filterOpNames, filter,
                             filterFlags, filterScale);
                     if (ops == null) {
                         ops = returnedOps;
@@ -1285,7 +1285,7 @@
 
         private @Nullable HistoricalOps readHistoricalPackageOpsDLocked(
                 @Nullable HistoricalOps ops, int uid, @NonNull XmlPullParser parser,
-                @Nullable String filterPackageName, @Nullable String filterFeatureId,
+                @Nullable String filterPackageName, @Nullable String filterAttributionTag,
                 @Nullable String[] filterOpNames, @HistoricalOpsRequestFilter int filter,
                 @OpFlags int filterFlags, double filterScale)
                 throws IOException, XmlPullParserException {
@@ -1296,9 +1296,9 @@
             }
             final int depth = parser.getDepth();
             while (XmlUtils.nextElementWithin(parser, depth)) {
-                if (TAG_FEATURE.equals(parser.getName())) {
-                    final HistoricalOps returnedOps = readHistoricalFeatureOpsDLocked(ops, uid,
-                            packageName, parser, filterFeatureId, filterOpNames, filter,
+                if (TAG_ATTRIBUTION.equals(parser.getName())) {
+                    final HistoricalOps returnedOps = readHistoricalAttributionOpsDLocked(ops, uid,
+                            packageName, parser, filterAttributionTag, filterOpNames, filter,
                             filterFlags, filterScale);
                     if (ops == null) {
                         ops = returnedOps;
@@ -1308,15 +1308,15 @@
             return ops;
         }
 
-        private @Nullable HistoricalOps readHistoricalFeatureOpsDLocked(@Nullable HistoricalOps ops,
-                int uid, String packageName, @NonNull XmlPullParser parser,
-                @Nullable String filterFeatureId, @Nullable String[] filterOpNames,
-                @HistoricalOpsRequestFilter int filter, @OpFlags int filterFlags,
-                double filterScale)
+        private @Nullable HistoricalOps readHistoricalAttributionOpsDLocked(
+                @Nullable HistoricalOps ops, int uid, String packageName,
+                @NonNull XmlPullParser parser, @Nullable String filterAttributionTag,
+                @Nullable String[] filterOpNames, @HistoricalOpsRequestFilter int filter,
+                @OpFlags int filterFlags, double filterScale)
                 throws IOException, XmlPullParserException {
-            final String featureId = XmlUtils.readStringAttribute(parser, ATTR_NAME);
-            if ((filter & FILTER_BY_FEATURE_ID) != 0 && !Objects.equals(filterFeatureId,
-                    featureId)) {
+            final String attributionTag = XmlUtils.readStringAttribute(parser, ATTR_NAME);
+            if ((filter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(filterAttributionTag,
+                    attributionTag)) {
                 XmlUtils.skipCurrentTag(parser);
                 return null;
             }
@@ -1324,7 +1324,8 @@
             while (XmlUtils.nextElementWithin(parser, depth)) {
                 if (TAG_OP.equals(parser.getName())) {
                     final HistoricalOps returnedOps = readHistoricalOpDLocked(ops, uid, packageName,
-                            featureId, parser, filterOpNames, filter, filterFlags, filterScale);
+                            attributionTag, parser, filterOpNames, filter, filterFlags,
+                            filterScale);
                     if (ops == null) {
                         ops = returnedOps;
                     }
@@ -1334,7 +1335,7 @@
         }
 
         private @Nullable HistoricalOps readHistoricalOpDLocked(@Nullable HistoricalOps ops,
-                int uid, @NonNull String packageName, @Nullable String featureId,
+                int uid, @NonNull String packageName, @Nullable String attributionTag,
                 @NonNull XmlPullParser parser, @Nullable String[] filterOpNames,
                 @HistoricalOpsRequestFilter int filter, @OpFlags int filterFlags,
                 double filterScale)
@@ -1349,7 +1350,7 @@
             while (XmlUtils.nextElementWithin(parser, depth)) {
                 if (TAG_STATE.equals(parser.getName())) {
                     final HistoricalOps returnedOps = readStateDLocked(ops, uid,
-                            packageName, featureId, op, parser, filterFlags, filterScale);
+                            packageName, attributionTag, op, parser, filterFlags, filterScale);
                     if (ops == null) {
                         ops = returnedOps;
                     }
@@ -1359,7 +1360,7 @@
         }
 
         private @Nullable HistoricalOps readStateDLocked(@Nullable HistoricalOps ops,
-                int uid, @NonNull String packageName, @Nullable String featureId, int op,
+                int uid, @NonNull String packageName, @Nullable String attributionTag, int op,
                 @NonNull XmlPullParser parser, @OpFlags int filterFlags, double filterScale)
                 throws IOException {
             final long key = XmlUtils.readLongAttribute(parser, ATTR_NAME);
@@ -1377,7 +1378,7 @@
                 if (ops == null) {
                     ops = new HistoricalOps(0, 0);
                 }
-                ops.increaseAccessCount(op, uid, packageName, featureId, uidState, flags,
+                ops.increaseAccessCount(op, uid, packageName, attributionTag, uidState, flags,
                         accessCount);
             }
             long rejectCount = XmlUtils.readLongAttribute(parser, ATTR_REJECT_COUNT, 0);
@@ -1389,7 +1390,7 @@
                 if (ops == null) {
                     ops = new HistoricalOps(0, 0);
                 }
-                ops.increaseRejectCount(op, uid, packageName, featureId, uidState, flags,
+                ops.increaseRejectCount(op, uid, packageName, attributionTag, uidState, flags,
                         rejectCount);
             }
             long accessDuration =  XmlUtils.readLongAttribute(parser, ATTR_ACCESS_DURATION, 0);
@@ -1401,7 +1402,7 @@
                 if (ops == null) {
                     ops = new HistoricalOps(0, 0);
                 }
-                ops.increaseAccessDuration(op, uid, packageName, featureId, uidState, flags,
+                ops.increaseAccessDuration(op, uid, packageName, attributionTag, uidState, flags,
                         accessDuration);
             }
             return ops;
@@ -1467,24 +1468,25 @@
                 @NonNull XmlSerializer serializer) throws IOException {
             serializer.startTag(null, TAG_PACKAGE);
             serializer.attribute(null, ATTR_NAME, packageOps.getPackageName());
-            final int numFeatures = packageOps.getFeatureCount();
-            for (int i = 0; i < numFeatures; i++) {
-                final HistoricalFeatureOps op = packageOps.getFeatureOpsAt(i);
-                writeHistoricalFeatureOpsDLocked(op, serializer);
+            final int numAttributions = packageOps.getAttributedOpsCount();
+            for (int i = 0; i < numAttributions; i++) {
+                final AppOpsManager.AttributedHistoricalOps op = packageOps.getAttributedOpsAt(i);
+                writeHistoricalAttributionOpsDLocked(op, serializer);
             }
             serializer.endTag(null, TAG_PACKAGE);
         }
 
-        private void writeHistoricalFeatureOpsDLocked(@NonNull HistoricalFeatureOps featureOps,
+        private void writeHistoricalAttributionOpsDLocked(
+                @NonNull AppOpsManager.AttributedHistoricalOps attributionOps,
                 @NonNull XmlSerializer serializer) throws IOException {
-            serializer.startTag(null, TAG_FEATURE);
-            XmlUtils.writeStringAttribute(serializer, ATTR_NAME, featureOps.getFeatureId());
-            final int opCount = featureOps.getOpCount();
+            serializer.startTag(null, TAG_ATTRIBUTION);
+            XmlUtils.writeStringAttribute(serializer, ATTR_NAME, attributionOps.getTag());
+            final int opCount = attributionOps.getOpCount();
             for (int i = 0; i < opCount; i++) {
-                final HistoricalOp op = featureOps.getOpAt(i);
+                final HistoricalOp op = attributionOps.getOpAt(i);
                 writeHistoricalOpDLocked(op, serializer);
             }
-            serializer.endTag(null, TAG_FEATURE);
+            serializer.endTag(null, TAG_ATTRIBUTION);
         }
 
         private void writeHistoricalOpDLocked(@NonNull HistoricalOp op,
@@ -1718,29 +1720,29 @@
         private final @NonNull String mOpsPrefix;
         private final @NonNull String mUidPrefix;
         private final @NonNull String mPackagePrefix;
-        private final @NonNull String mFeaturePrefix;
+        private final @NonNull String mAttributionPrefix;
         private final @NonNull String mEntryPrefix;
         private final @NonNull String mUidStatePrefix;
         private final @NonNull PrintWriter mWriter;
         private final int mFilterUid;
         private final String mFilterPackage;
-        private final String mFilterFeatureId;
+        private final String mFilterAttributionTag;
         private final int mFilterOp;
         private final @HistoricalOpsRequestFilter int mFilter;
 
         StringDumpVisitor(@NonNull String prefix, @NonNull PrintWriter writer, int filterUid,
-                @Nullable String filterPackage, @Nullable String filterFeatureId, int filterOp,
+                @Nullable String filterPackage, @Nullable String filterAttributionTag, int filterOp,
                 @HistoricalOpsRequestFilter int filter) {
             mOpsPrefix = prefix + "  ";
             mUidPrefix = mOpsPrefix + "  ";
             mPackagePrefix = mUidPrefix + "  ";
-            mFeaturePrefix = mPackagePrefix + "  ";
-            mEntryPrefix = mFeaturePrefix + "  ";
+            mAttributionPrefix = mPackagePrefix + "  ";
+            mEntryPrefix = mAttributionPrefix + "  ";
             mUidStatePrefix = mEntryPrefix + "  ";
             mWriter = writer;
             mFilterUid = filterUid;
             mFilterPackage = filterPackage;
-            mFilterFeatureId = filterFeatureId;
+            mFilterAttributionTag = filterAttributionTag;
             mFilterOp = filterOp;
             mFilter = filter;
         }
@@ -1791,14 +1793,14 @@
         }
 
         @Override
-        public void visitHistoricalFeatureOps(HistoricalFeatureOps ops) {
-            if ((mFilter & FILTER_BY_FEATURE_ID) != 0 && !Objects.equals(mFilterPackage,
-                    ops.getFeatureId())) {
+        public void visitHistoricalAttributionOps(AppOpsManager.AttributedHistoricalOps ops) {
+            if ((mFilter & FILTER_BY_ATTRIBUTION_TAG) != 0 && !Objects.equals(mFilterPackage,
+                    ops.getTag())) {
                 return;
             }
-            mWriter.print(mFeaturePrefix);
-            mWriter.print("Feature ");
-            mWriter.print(ops.getFeatureId());
+            mWriter.print(mAttributionPrefix);
+            mWriter.print("Attribution ");
+            mWriter.print(ops.getTag());
             mWriter.println(":");
         }
 
diff --git a/services/core/java/com/android/server/biometrics/BiometricService.java b/services/core/java/com/android/server/biometrics/BiometricService.java
index ecdafb0..e7c09ba 100644
--- a/services/core/java/com/android/server/biometrics/BiometricService.java
+++ b/services/core/java/com/android/server/biometrics/BiometricService.java
@@ -24,6 +24,7 @@
 import static android.hardware.biometrics.BiometricManager.Authenticators;
 
 import android.annotation.IntDef;
+import android.annotation.Nullable;
 import android.app.ActivityManager;
 import android.app.IActivityManager;
 import android.app.UserSwitchObserver;
@@ -296,7 +297,7 @@
                 }
 
                 case MSG_ON_DISMISSED: {
-                    handleOnDismissed(msg.arg1);
+                    handleOnDismissed(msg.arg1, (byte[]) msg.obj);
                     break;
                 }
 
@@ -611,8 +612,12 @@
         }
 
         @Override
-        public void onDialogDismissed(int reason) throws RemoteException {
-            mHandler.obtainMessage(MSG_ON_DISMISSED, reason, 0 /* arg2 */).sendToTarget();
+        public void onDialogDismissed(int reason, @Nullable byte[] credentialAttestation)
+                throws RemoteException {
+            mHandler.obtainMessage(MSG_ON_DISMISSED,
+                    reason,
+                    0 /* arg2 */,
+                    credentialAttestation /* obj */).sendToTarget();
         }
 
         @Override
@@ -1422,7 +1427,8 @@
                                 0 /* biometricModality */,
                                 false /* requireConfirmation */,
                                 mCurrentAuthSession.mUserId,
-                                mCurrentAuthSession.mOpPackageName);
+                                mCurrentAuthSession.mOpPackageName,
+                                mCurrentAuthSession.mSessionId);
                     } else {
                         mPendingAuthSession.mClientReceiver.onError(modality, error, vendorCode);
                         mPendingAuthSession = null;
@@ -1458,7 +1464,7 @@
         }
     }
 
-    private void handleOnDismissed(int reason) {
+    private void handleOnDismissed(int reason, @Nullable byte[] credentialAttestation) {
         if (mCurrentAuthSession == null) {
             Slog.e(TAG, "onDismissed: " + reason + ", auth session null");
             return;
@@ -1469,6 +1475,7 @@
         try {
             switch (reason) {
                 case BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED:
+                    mKeyStore.addAuthToken(credentialAttestation);
                 case BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED:
                 case BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED:
                     if (mCurrentAuthSession.mTokenEscrow != null) {
@@ -1616,7 +1623,8 @@
                 try {
                     mStatusBarService.showAuthenticationDialog(mCurrentAuthSession.mBundle,
                             mInternalReceiver, modality, requireConfirmation, userId,
-                            mCurrentAuthSession.mOpPackageName);
+                            mCurrentAuthSession.mOpPackageName,
+                            mCurrentAuthSession.mSessionId);
                 } catch (RemoteException e) {
                     Slog.e(TAG, "Remote exception", e);
                 }
@@ -1701,7 +1709,8 @@
                         0 /* biometricModality */,
                         false /* requireConfirmation */,
                         mCurrentAuthSession.mUserId,
-                        mCurrentAuthSession.mOpPackageName);
+                        mCurrentAuthSession.mOpPackageName,
+                        sessionId);
             } else {
                 mPendingAuthSession.mState = STATE_AUTH_CALLED;
                 for (AuthenticatorWrapper authenticator : mAuthenticators) {
diff --git a/services/core/java/com/android/server/compat/CompatChange.java b/services/core/java/com/android/server/compat/CompatChange.java
index 7bdeb59..2e9818d 100644
--- a/services/core/java/com/android/server/compat/CompatChange.java
+++ b/services/core/java/com/android/server/compat/CompatChange.java
@@ -151,6 +151,15 @@
         return true;
     }
 
+    /**
+     * Checks whether a change has an override for a package.
+     * @param packageName name of the package
+     * @return true if there is such override
+     */
+    boolean hasOverride(String packageName) {
+        return mPackageOverrides != null && mPackageOverrides.containsKey(packageName);
+    }
+
     @Override
     public String toString() {
         StringBuilder sb = new StringBuilder("ChangeId(")
diff --git a/services/core/java/com/android/server/compat/CompatConfig.java b/services/core/java/com/android/server/compat/CompatConfig.java
index b2ea311..aeaa1fe 100644
--- a/services/core/java/com/android/server/compat/CompatConfig.java
+++ b/services/core/java/com/android/server/compat/CompatConfig.java
@@ -247,11 +247,13 @@
             CompatChange c = mChanges.get(changeId);
             try {
                 if (c != null) {
-                    OverrideAllowedState allowedState =
-                            mOverrideValidator.getOverrideAllowedState(changeId, packageName);
-                    allowedState.enforce(changeId, packageName);
-                    overrideExists = true;
-                    c.removePackageOverride(packageName);
+                    overrideExists = c.hasOverride(packageName);
+                    if (overrideExists) {
+                        OverrideAllowedState allowedState =
+                                mOverrideValidator.getOverrideAllowedState(changeId, packageName);
+                        allowedState.enforce(changeId, packageName);
+                        c.removePackageOverride(packageName);
+                    }
                 }
             } catch (RemoteException e) {
                 // Should never occur, since validator is in the same process.
@@ -298,12 +300,14 @@
             for (int i = 0; i < mChanges.size(); ++i) {
                 try {
                     CompatChange change = mChanges.valueAt(i);
-                    OverrideAllowedState allowedState =
-                            mOverrideValidator.getOverrideAllowedState(change.getId(),
-                                                                       packageName);
-                    allowedState.enforce(change.getId(), packageName);
-                    if (change != null) {
-                        mChanges.valueAt(i).removePackageOverride(packageName);
+                    if (change.hasOverride(packageName)) {
+                        OverrideAllowedState allowedState =
+                                mOverrideValidator.getOverrideAllowedState(change.getId(),
+                                        packageName);
+                        allowedState.enforce(change.getId(), packageName);
+                        if (change != null) {
+                            mChanges.valueAt(i).removePackageOverride(packageName);
+                        }
                     }
                 } catch (RemoteException e) {
                     // Should never occur, since validator is in the same process.
diff --git a/services/core/java/com/android/server/connectivity/Vpn.java b/services/core/java/com/android/server/connectivity/Vpn.java
index 7c3cab1..20ffd9f 100644
--- a/services/core/java/com/android/server/connectivity/Vpn.java
+++ b/services/core/java/com/android/server/connectivity/Vpn.java
@@ -2563,7 +2563,7 @@
         public void exitIfOuterInterfaceIs(String interfaze) {
             if (interfaze.equals(mOuterInterface)) {
                 Log.i(TAG, "Legacy VPN is going down with " + interfaze);
-                exit();
+                exitVpnRunner();
             }
         }
 
@@ -2572,6 +2572,10 @@
         public void exitVpnRunner() {
             // We assume that everything is reset after stopping the daemons.
             interrupt();
+
+            // Always disconnect. This may be called again in cleanupVpnStateLocked() if
+            // exitVpnRunner() was called from exit(), but it will be a no-op.
+            agentDisconnect();
             try {
                 mContext.unregisterReceiver(mBroadcastReceiver);
             } catch (IllegalArgumentException e) {}
@@ -2794,7 +2798,7 @@
             } catch (Exception e) {
                 Log.i(TAG, "Aborting", e);
                 updateState(DetailedState.FAILED, e.getMessage());
-                exit();
+                exitVpnRunner();
             }
         }
 
diff --git a/services/core/java/com/android/server/location/CountryDetectorBase.java b/services/core/java/com/android/server/location/CountryDetectorBase.java
index b158388..682b104 100644
--- a/services/core/java/com/android/server/location/CountryDetectorBase.java
+++ b/services/core/java/com/android/server/location/CountryDetectorBase.java
@@ -31,7 +31,7 @@
  * @hide
  */
 public abstract class CountryDetectorBase {
-    private static final String FEATURE_ID = "CountryDetector";
+    private static final String ATTRIBUTION_TAG = "CountryDetector";
 
     protected final Handler mHandler;
     protected final Context mContext;
@@ -39,7 +39,7 @@
     protected Country mDetectedCountry;
 
     public CountryDetectorBase(Context context) {
-        mContext = context.createFeatureContext(FEATURE_ID);
+        mContext = context.createAttributionContext(ATTRIBUTION_TAG);
         mHandler = new Handler();
     }
 
diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index 799ce65..ca2e240 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -24,6 +24,8 @@
 import static android.Manifest.permission.REQUEST_DELETE_PACKAGES;
 import static android.Manifest.permission.SET_HARMFUL_APP_WARNINGS;
 import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;
+import static android.app.AppOpsManager.MODE_ALLOWED;
+import static android.app.AppOpsManager.MODE_IGNORED;
 import static android.content.Intent.ACTION_MAIN;
 import static android.content.Intent.CATEGORY_DEFAULT;
 import static android.content.Intent.CATEGORY_HOME;
@@ -11514,8 +11516,8 @@
                             "Static shared libs cannot declare permission groups");
                 }
 
-                // Static shared libs cannot declare features
-                if (!pkg.getFeatures().isEmpty()) {
+                // Static shared libs cannot declare attributions
+                if (!pkg.getAttributions().isEmpty()) {
                     throw new PackageManagerException(
                             "Static shared libs cannot declare features");
                 }
@@ -24361,6 +24363,24 @@
     }
 
     @Override
+    public boolean isAutoRevokeWhitelisted(String packageName) {
+        int mode = mInjector.getAppOpsManager().checkOpNoThrow(
+                AppOpsManager.OP_AUTO_REVOKE_PERMISSIONS_IF_UNUSED,
+                Binder.getCallingUid(), packageName);
+        if (mode == MODE_ALLOWED) {
+            return false;
+        } else if (mode == MODE_IGNORED) {
+            return true;
+        } else {
+            synchronized (mLock) {
+                boolean manifestWhitelisted =
+                        mPackages.get(packageName).isAllowDontAutoRevokePermmissions();
+                return manifestWhitelisted;
+            }
+        }
+    }
+
+    @Override
     public int getInstallReason(String packageName, int userId) {
         final int callingUid = Binder.getCallingUid();
         mPermissionManager.enforceCrossUserPermission(callingUid, userId,
diff --git a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java
index 7929579..46b08df 100644
--- a/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java
+++ b/services/core/java/com/android/server/pm/parsing/pkg/AndroidPackage.java
@@ -25,7 +25,7 @@
 import android.content.pm.PermissionGroupInfo;
 import android.content.pm.SharedLibraryInfo;
 import android.content.pm.parsing.ParsingPackageRead;
-import android.content.pm.parsing.component.ParsedFeature;
+import android.content.pm.parsing.component.ParsedAttribution;
 import android.content.pm.parsing.component.ParsedIntentInfo;
 import android.content.pm.parsing.component.ParsedPermissionGroup;
 import android.os.Bundle;
@@ -147,7 +147,7 @@
     List<ParsedPermissionGroup> getPermissionGroups();
 
     @NonNull
-    List<ParsedFeature> getFeatures();
+    List<ParsedAttribution> getAttributions();
 
     /**
      * Used to determine the default preferred handler of an {@link Intent}.
diff --git a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
index 85da559..5141191 100644
--- a/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
+++ b/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
@@ -3093,6 +3093,36 @@
         }
     }
 
+    @Override
+    public List<String> getAutoRevokeExemptionRequestedPackages(int userId) {
+        mContext.enforceCallingPermission(Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY,
+                "Must hold " + Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY);
+
+        List<String> result = new ArrayList<>();
+        mPackageManagerInt.forEachInstalledPackage(pkg -> {
+            if (pkg.isDontAutoRevokePermmissions()) {
+                result.add(pkg.getPackageName());
+            }
+        }, userId);
+
+        return result;
+    }
+
+    @Override
+    public List<String> getAutoRevokeExemptionGrantedPackages(int userId) {
+        mContext.enforceCallingPermission(Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY,
+                "Must hold " + Manifest.permission.ADJUST_RUNTIME_PERMISSIONS_POLICY);
+
+        List<String> result = new ArrayList<>();
+        mPackageManagerInt.forEachInstalledPackage(pkg -> {
+            if (pkg.isAllowDontAutoRevokePermmissions()) {
+                result.add(pkg.getPackageName());
+            }
+        }, userId);
+
+        return result;
+    }
+
     private boolean isNewPlatformPermissionForPackage(String perm, AndroidPackage pkg) {
         boolean allowed = false;
         final int NP = PackageParser.NEW_PERMISSIONS.length;
diff --git a/services/core/java/com/android/server/policy/PermissionPolicyService.java b/services/core/java/com/android/server/policy/PermissionPolicyService.java
index d589353..161f304 100644
--- a/services/core/java/com/android/server/policy/PermissionPolicyService.java
+++ b/services/core/java/com/android/server/policy/PermissionPolicyService.java
@@ -32,6 +32,7 @@
 import android.app.AppOpsManagerInternal;
 import android.content.Context;
 import android.content.Intent;
+import android.content.IntentFilter;
 import android.content.pm.ApplicationInfo;
 import android.content.pm.PackageInfo;
 import android.content.pm.PackageManager;
@@ -173,6 +174,65 @@
         } catch (RemoteException doesNotHappen) {
             Slog.wtf(LOG_TAG, "Cannot set up app-ops listener");
         }
+
+        IntentFilter intentFilter = new IntentFilter();
+        intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
+        intentFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
+        intentFilter.addDataScheme("package");
+
+
+        /* TODO ntmyren: enable receiver when test flakes are fixed
+        getContext().registerReceiverAsUser(new BroadcastReceiver() {
+            final List<Integer> mUserSetupUids = new ArrayList<>(200);
+            final Map<UserHandle, PermissionControllerManager> mPermControllerManagers =
+                    new HashMap<>();
+
+            @Override
+            public void onReceive(Context context, Intent intent) {
+                boolean hasSetupRun = true;
+                try {
+                    hasSetupRun = Settings.Secure.getInt(getContext().getContentResolver(),
+                            Settings.Secure.USER_SETUP_COMPLETE) != 0;
+                } catch (Settings.SettingNotFoundException e) {
+                    // Ignore error, assume setup has run
+                }
+                int uid = intent.getIntExtra(Intent.EXTRA_UID, -1);
+                // If there is no valid package for the given UID, return immediately
+                if (packageManagerInternal.getPackage(uid) == null) {
+                    return;
+                }
+
+                if (hasSetupRun) {
+                    if (!mUserSetupUids.isEmpty()) {
+                        synchronized (mUserSetupUids) {
+                            for (int i = mUserSetupUids.size() - 1; i >= 0; i--) {
+                                updateUid(mUserSetupUids.get(i));
+                            }
+                            mUserSetupUids.clear();
+                        }
+                    }
+                    updateUid(uid);
+                } else {
+                    synchronized (mUserSetupUids) {
+                        if (!mUserSetupUids.contains(uid)) {
+                            mUserSetupUids.add(uid);
+                        }
+                    }
+                }
+            }
+
+            private void updateUid(int uid) {
+                UserHandle user = UserHandle.getUserHandleForUid(uid);
+                PermissionControllerManager manager = mPermControllerManagers.get(user);
+                if (manager == null) {
+                    manager = new PermissionControllerManager(
+                            getUserContext(getContext(), user), FgThread.getHandler());
+                    mPermControllerManagers.put(user, manager);
+                }
+                manager.updateUserSensitiveForApp(uid);
+            }
+        }, UserHandle.ALL, intentFilter, null, null);
+         */
     }
 
     /**
@@ -182,7 +242,6 @@
      * {@link AppOpsManager#sOpToSwitch share an op} to control the access.
      *
      * @param permission The permission
-     *
      * @return The op that controls the access of the permission
      */
     private static int getSwitchOp(@NonNull String permission) {
diff --git a/services/core/java/com/android/server/policy/PhoneWindowManager.java b/services/core/java/com/android/server/policy/PhoneWindowManager.java
index 1b5cc6a..64edacd 100644
--- a/services/core/java/com/android/server/policy/PhoneWindowManager.java
+++ b/services/core/java/com/android/server/policy/PhoneWindowManager.java
@@ -5202,7 +5202,7 @@
                     if (dock != null) {
                         int result = ActivityTaskManager.getService()
                                 .startActivityAsUser(null, mContext.getBasePackageName(),
-                                        mContext.getFeatureId(), dock,
+                                        mContext.getAttributionTag(), dock,
                                         dock.resolveTypeIfNeeded(mContext.getContentResolver()),
                                         null, null, 0,
                                         ActivityManager.START_FLAG_ONLY_IF_NEEDED,
@@ -5214,7 +5214,7 @@
                 }
                 int result = ActivityTaskManager.getService()
                         .startActivityAsUser(null, mContext.getBasePackageName(),
-                                mContext.getFeatureId(), mHomeIntent,
+                                mContext.getAttributionTag(), mHomeIntent,
                                 mHomeIntent.resolveTypeIfNeeded(mContext.getContentResolver()),
                                 null, null, 0,
                                 ActivityManager.START_FLAG_ONLY_IF_NEEDED,
diff --git a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
index 98579af..7f7d668 100644
--- a/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
+++ b/services/core/java/com/android/server/stats/pull/StatsPullAtomService.java
@@ -406,8 +406,8 @@
                     case FrameworkStatsLog.BATTERY_VOLTAGE:
                     case FrameworkStatsLog.BATTERY_CYCLE_COUNT:
                         return pullHealthHal(atomTag, data);
-                    case FrameworkStatsLog.APP_FEATURES_OPS:
-                        return pullAppFeaturesOps(atomTag, data);
+                    case FrameworkStatsLog.ATTRIBUTED_APP_OPS:
+                        return pullAttributedAppOps(atomTag, data);
                     default:
                         throw new UnsupportedOperationException("Unknown tagId=" + atomTag);
                 }
@@ -562,7 +562,7 @@
         registerAppsOnExternalStorageInfo();
         registerFaceSettings();
         registerAppOps();
-        registerAppFeaturesOps();
+        registerAttributedAppOps();
         registerRuntimeAppOpAccessMessage();
         registerNotificationRemoteViews();
         registerDangerousPermissionState();
@@ -2898,8 +2898,8 @@
         return StatsManager.PULL_SUCCESS;
     }
 
-    private void registerAppFeaturesOps() {
-        int tagId = FrameworkStatsLog.APP_FEATURES_OPS;
+    private void registerAttributedAppOps() {
+        int tagId = FrameworkStatsLog.ATTRIBUTED_APP_OPS;
         mStatsManager.setPullAtomCallback(
                 tagId,
                 null, // use default PullAtomMetadata values
@@ -2908,7 +2908,7 @@
         );
     }
 
-    int pullAppFeaturesOps(int atomTag, List<StatsEvent> pulledData) {
+    int pullAttributedAppOps(int atomTag, List<StatsEvent> pulledData) {
         final long token = Binder.clearCallingIdentity();
         try {
             AppOpsManager appOps = mContext.getSystemService(AppOpsManager.class);
@@ -2946,7 +2946,7 @@
         appOps.getHistoricalOps(histOpsRequest, mContext.getMainExecutor(), ops::complete);
         HistoricalOps histOps = ops.get(EXTERNAL_STATS_SYNC_TIMEOUT_MILLIS,
                 TimeUnit.MILLISECONDS);
-        return processHistoricalOps(histOps, FrameworkStatsLog.APP_FEATURES_OPS, null);
+        return processHistoricalOps(histOps, FrameworkStatsLog.ATTRIBUTED_APP_OPS, null);
     }
 
     int processHistoricalOps(HistoricalOps histOps, int atomTag, List<StatsEvent> pulledData) {
@@ -2956,15 +2956,15 @@
             final int uid = uidOps.getUid();
             for (int pkgIdx = 0; pkgIdx < uidOps.getPackageCount(); pkgIdx++) {
                 final HistoricalPackageOps packageOps = uidOps.getPackageOpsAt(pkgIdx);
-                if (atomTag == FrameworkStatsLog.APP_FEATURES_OPS) {
-                    for (int featureIdx = 0; featureIdx < packageOps.getFeatureCount();
-                            featureIdx++) {
-                        final AppOpsManager.HistoricalFeatureOps featureOps =
-                                packageOps.getFeatureOpsAt(featureIdx);
-                        for (int opIdx = 0; opIdx < featureOps.getOpCount(); opIdx++) {
-                            final AppOpsManager.HistoricalOp op = featureOps.getOpAt(opIdx);
+                if (atomTag == FrameworkStatsLog.ATTRIBUTED_APP_OPS) {
+                    for (int attributionIdx = 0;
+                            attributionIdx < packageOps.getAttributedOpsCount(); attributionIdx++) {
+                        final AppOpsManager.AttributedHistoricalOps attributedOps =
+                                packageOps.getAttributedOpsAt(attributionIdx);
+                        for (int opIdx = 0; opIdx < attributedOps.getOpCount(); opIdx++) {
+                            final AppOpsManager.HistoricalOp op = attributedOps.getOpAt(opIdx);
                             counter += processHistoricalOp(op, atomTag, pulledData, uid,
-                                    packageOps.getPackageName(), featureOps.getFeatureId());
+                                    packageOps.getPackageName(), attributedOps.getTag());
                         }
                     }
                 } else if (atomTag == FrameworkStatsLog.APP_OPS) {
@@ -2981,18 +2981,19 @@
 
     private int processHistoricalOp(AppOpsManager.HistoricalOp op, int atomTag,
             @Nullable List<StatsEvent> pulledData, int uid, String packageName,
-            @Nullable String feature) {
-        if (atomTag == FrameworkStatsLog.APP_FEATURES_OPS) {
+            @Nullable String attributionTag) {
+        if (atomTag == FrameworkStatsLog.ATTRIBUTED_APP_OPS) {
             if (pulledData == null) { // this is size estimation call
                 if (op.getForegroundAccessCount(OP_FLAGS_PULLED) + op.getBackgroundAccessCount(
                         OP_FLAGS_PULLED) == 0) {
                     return 0;
                 } else {
-                    return 32 + packageName.length() + (feature == null ? 1 : feature.length());
+                    return 32 + packageName.length() + (attributionTag == null ? 1
+                            : attributionTag.length());
                 }
             } else {
-                if (abs((op.getOpCode() + feature + packageName).hashCode() + RANDOM_SEED) % 100
-                        >= mAppOpsSamplingRate) {
+                if (abs((op.getOpCode() + attributionTag + packageName).hashCode() + RANDOM_SEED)
+                        % 100 >= mAppOpsSamplingRate) {
                     return 0;
                 }
             }
@@ -3002,10 +3003,10 @@
         e.setAtomId(atomTag);
         e.writeInt(uid);
         e.writeString(packageName);
-        if (atomTag == FrameworkStatsLog.APP_FEATURES_OPS) {
-            e.writeString(feature);
+        if (atomTag == FrameworkStatsLog.ATTRIBUTED_APP_OPS) {
+            e.writeString(attributionTag);
         }
-        if (atomTag == FrameworkStatsLog.APP_FEATURES_OPS) {
+        if (atomTag == FrameworkStatsLog.ATTRIBUTED_APP_OPS) {
             e.writeString(op.getOpName());
         } else {
             e.writeInt(op.getOpCode());
@@ -3032,7 +3033,7 @@
                 e.writeBoolean(false);
             }
         }
-        if (atomTag == FrameworkStatsLog.APP_FEATURES_OPS) {
+        if (atomTag == FrameworkStatsLog.ATTRIBUTED_APP_OPS) {
             e.writeInt(mAppOpsSamplingRate);
         }
         pulledData.add(e.build());
@@ -3055,10 +3056,10 @@
             e.writeInt(message.getUid());
             e.writeString(message.getPackageName());
             e.writeString(message.getOp());
-            if (message.getFeatureId() == null) {
+            if (message.getAttributionTag() == null) {
                 e.writeString("");
             } else {
-                e.writeString(message.getFeatureId());
+                e.writeString(message.getAttributionTag());
             }
             e.writeString(message.getMessage());
             e.writeInt(message.getSamplingStrategy());
diff --git a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
index 84cd4cf..78ef68c 100644
--- a/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
+++ b/services/core/java/com/android/server/statusbar/StatusBarManagerService.java
@@ -664,12 +664,13 @@
 
     @Override
     public void showAuthenticationDialog(Bundle bundle, IBiometricServiceReceiverInternal receiver,
-            int biometricModality, boolean requireConfirmation, int userId, String opPackageName) {
+            int biometricModality, boolean requireConfirmation, int userId, String opPackageName,
+            long operationId) {
         enforceBiometricDialog();
         if (mBar != null) {
             try {
                 mBar.showAuthenticationDialog(bundle, receiver, biometricModality,
-                        requireConfirmation, userId, opPackageName);
+                        requireConfirmation, userId, opPackageName, operationId);
             } catch (RemoteException ex) {
             }
         }
diff --git a/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java b/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java
index 8164526..74a6383 100644
--- a/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java
+++ b/services/core/java/com/android/server/textclassifier/TextClassificationManagerService.java
@@ -41,6 +41,7 @@
 import android.util.SparseArray;
 import android.view.textclassifier.ConversationActions;
 import android.view.textclassifier.SelectionEvent;
+import android.view.textclassifier.SystemTextClassifierMetadata;
 import android.view.textclassifier.TextClassification;
 import android.view.textclassifier.TextClassificationConstants;
 import android.view.textclassifier.TextClassificationContext;
@@ -179,12 +180,12 @@
             TextSelection.Request request, ITextClassifierCallback callback)
             throws RemoteException {
         Objects.requireNonNull(request);
+        Objects.requireNonNull(request.getSystemTextClassifierMetadata());
 
         handleRequest(
-                request.getUserId(),
-                request.getCallingPackageName(),
+                request.getSystemTextClassifierMetadata(),
+                /* verifyCallingPackage= */ true,
                 /* attemptToBind= */ true,
-                request.getUseDefaultTextClassifier(),
                 service -> service.onSuggestSelection(sessionId, request, callback),
                 "onSuggestSelection",
                 callback);
@@ -196,12 +197,12 @@
             TextClassification.Request request, ITextClassifierCallback callback)
             throws RemoteException {
         Objects.requireNonNull(request);
+        Objects.requireNonNull(request.getSystemTextClassifierMetadata());
 
         handleRequest(
-                request.getUserId(),
-                request.getCallingPackageName(),
+                request.getSystemTextClassifierMetadata(),
+                /* verifyCallingPackage= */ true,
                 /* attemptToBind= */ true,
-                request.getUseDefaultTextClassifier(),
                 service -> service.onClassifyText(sessionId, request, callback),
                 "onClassifyText",
                 callback);
@@ -213,12 +214,12 @@
             TextLinks.Request request, ITextClassifierCallback callback)
             throws RemoteException {
         Objects.requireNonNull(request);
+        Objects.requireNonNull(request.getSystemTextClassifierMetadata());
 
         handleRequest(
-                request.getUserId(),
-                request.getCallingPackageName(),
+                request.getSystemTextClassifierMetadata(),
+                /* verifyCallingPackage= */ true,
                 /* attemptToBind= */ true,
-                request.getUseDefaultTextClassifier(),
                 service -> service.onGenerateLinks(sessionId, request, callback),
                 "onGenerateLinks",
                 callback);
@@ -229,12 +230,12 @@
             @Nullable TextClassificationSessionId sessionId, SelectionEvent event)
             throws RemoteException {
         Objects.requireNonNull(event);
+        Objects.requireNonNull(event.getSystemTextClassifierMetadata());
 
         handleRequest(
-                event.getUserId(),
-                /* callingPackageName= */ null,
+                event.getSystemTextClassifierMetadata(),
+                /* verifyCallingPackage= */ false,
                 /* attemptToBind= */ false,
-                event.getUseDefaultTextClassifier(),
                 service -> service.onSelectionEvent(sessionId, event),
                 "onSelectionEvent",
                 NO_OP_CALLBACK);
@@ -246,18 +247,14 @@
             TextClassifierEvent event) throws RemoteException {
         Objects.requireNonNull(event);
 
-        final int userId = event.getEventContext() == null
-                ? UserHandle.getCallingUserId()
-                : event.getEventContext().getUserId();
-        final boolean useDefaultTextClassifier =
-                event.getEventContext() != null
-                        ? event.getEventContext().getUseDefaultTextClassifier()
-                        : true;
+        final TextClassificationContext eventContext = event.getEventContext();
+        final SystemTextClassifierMetadata systemTcMetadata =
+                eventContext != null ? eventContext.getSystemTextClassifierMetadata() : null;
+
         handleRequest(
-                userId,
-                /* callingPackageName= */ null,
+                systemTcMetadata,
+                /* verifyCallingPackage= */ false,
                 /* attemptToBind= */ false,
-                useDefaultTextClassifier,
                 service -> service.onTextClassifierEvent(sessionId, event),
                 "onTextClassifierEvent",
                 NO_OP_CALLBACK);
@@ -269,12 +266,12 @@
             TextLanguage.Request request,
             ITextClassifierCallback callback) throws RemoteException {
         Objects.requireNonNull(request);
+        Objects.requireNonNull(request.getSystemTextClassifierMetadata());
 
         handleRequest(
-                request.getUserId(),
-                request.getCallingPackageName(),
+                request.getSystemTextClassifierMetadata(),
+                /* verifyCallingPackage= */ true,
                 /* attemptToBind= */ true,
-                request.getUseDefaultTextClassifier(),
                 service -> service.onDetectLanguage(sessionId, request, callback),
                 "onDetectLanguage",
                 callback);
@@ -286,12 +283,12 @@
             ConversationActions.Request request,
             ITextClassifierCallback callback) throws RemoteException {
         Objects.requireNonNull(request);
+        Objects.requireNonNull(request.getSystemTextClassifierMetadata());
 
         handleRequest(
-                request.getUserId(),
-                request.getCallingPackageName(),
+                request.getSystemTextClassifierMetadata(),
+                /* verifyCallingPackage= */ true,
                 /* attemptToBind= */ true,
-                request.getUseDefaultTextClassifier(),
                 service -> service.onSuggestConversationActions(sessionId, request, callback),
                 "onSuggestConversationActions",
                 callback);
@@ -303,13 +300,12 @@
             throws RemoteException {
         Objects.requireNonNull(sessionId);
         Objects.requireNonNull(classificationContext);
+        Objects.requireNonNull(classificationContext.getSystemTextClassifierMetadata());
 
-        final int userId = classificationContext.getUserId();
         handleRequest(
-                userId,
-                classificationContext.getPackageName(),
+                classificationContext.getSystemTextClassifierMetadata(),
+                /* verifyCallingPackage= */ true,
                 /* attemptToBind= */ false,
-                classificationContext.getUseDefaultTextClassifier(),
                 service -> {
                     service.onCreateTextClassificationSession(classificationContext, sessionId);
                     mSessionCache.put(sessionId, classificationContext);
@@ -333,11 +329,13 @@
                     textClassificationContext != null
                             ? textClassificationContext.useDefaultTextClassifier
                             : true;
+            final SystemTextClassifierMetadata sysTcMetadata = new SystemTextClassifierMetadata(
+                    "", userId, useDefaultTextClassifier);
+
             handleRequest(
-                    userId,
-                    /* callingPackageName= */ null,
+                    sysTcMetadata,
+                    /* verifyCallingPackage= */ false,
                     /* attemptToBind= */ false,
-                    useDefaultTextClassifier,
                     service -> {
                         service.onDestroyTextClassificationSession(sessionId);
                         mSessionCache.remove(sessionId);
@@ -412,10 +410,9 @@
     }
 
     private void handleRequest(
-            @UserIdInt int userId,
-            @Nullable String callingPackageName,
+            @Nullable SystemTextClassifierMetadata sysTcMetadata,
+            boolean verifyCallingPackage,
             boolean attemptToBind,
-            boolean useDefaultTextClassifier,
             @NonNull ThrowingConsumer<ITextClassifierService> textClassifierServiceConsumer,
             @NonNull String methodName,
             @NonNull ITextClassifierCallback callback) throws RemoteException {
@@ -423,8 +420,17 @@
         Objects.requireNonNull(methodName);
         Objects.requireNonNull(callback);
 
+        final int userId =
+                sysTcMetadata == null ? UserHandle.getCallingUserId() : sysTcMetadata.getUserId();
+        final String callingPackageName =
+                sysTcMetadata == null ? null : sysTcMetadata.getCallingPackageName();
+        final boolean useDefaultTextClassifier =
+                sysTcMetadata == null ? true : sysTcMetadata.useDefaultTextClassifier();
+
         try {
-            validateCallingPackage(callingPackageName);
+            if (verifyCallingPackage) {
+                validateCallingPackage(callingPackageName);
+            }
             validateUser(userId);
         } catch (Exception e) {
             throw new RemoteException("Invalid request: " + e.getMessage(), e,
@@ -636,8 +642,10 @@
         public final boolean useDefaultTextClassifier;
 
         StrippedTextClassificationContext(TextClassificationContext textClassificationContext) {
-            userId = textClassificationContext.getUserId();
-            useDefaultTextClassifier = textClassificationContext.getUseDefaultTextClassifier();
+            SystemTextClassifierMetadata sysTcMetadata =
+                    textClassificationContext.getSystemTextClassifierMetadata();
+            userId = sysTcMetadata.getUserId();
+            useDefaultTextClassifier = sysTcMetadata.useDefaultTextClassifier();
         }
     }
 
diff --git a/services/core/java/com/android/server/tv/UinputBridge.java b/services/core/java/com/android/server/tv/UinputBridge.java
index 752aa66..a2fe5fc 100644
--- a/services/core/java/com/android/server/tv/UinputBridge.java
+++ b/services/core/java/com/android/server/tv/UinputBridge.java
@@ -28,7 +28,7 @@
 public final class UinputBridge {
     private final CloseGuard mCloseGuard = CloseGuard.get();
     private long mPtr;
-    private IBinder mToken = null;
+    private IBinder mToken;
 
     private static native long nativeOpen(String name, String uniqueId, int width, int height,
                                           int maxPointers);
@@ -39,6 +39,25 @@
     private static native void nativeSendPointerUp(long ptr, int pointerId);
     private static native void nativeSendPointerSync(long ptr);
 
+    /** Opens a gamepad - will support gamepad key and axis sending */
+    private static native long nativeGamepadOpen(String name, String uniqueId);
+
+    /** Marks the specified key up/down for a gamepad */
+    private static native void nativeSendGamepadKey(long ptr, int keyIndex, boolean down);
+
+    /**
+     * Gamepads pre-define the following axes:
+     *   - Left joystick X, axis == ABS_X == 0, range [0, 254]
+     *   - Left joystick Y, axis == ABS_Y == 1, range [0, 254]
+     *   - Right joystick X, axis == ABS_RX == 3, range [0, 254]
+     *   - Right joystick Y, axis == ABS_RY == 4, range [0, 254]
+     *   - Left trigger, axis == ABS_Z == 2, range [0, 254]
+     *   - Right trigger, axis == ABS_RZ == 5, range [0, 254]
+     *   - DPad X, axis == ABS_HAT0X == 0x10, range [-1, 1]
+     *   - DPad Y, axis == ABS_HAT0Y == 0x11, range [-1, 1]
+     */
+    private static native void nativeSendGamepadAxisValue(long ptr, int axis, int value);
+
     public UinputBridge(IBinder token, String name, int width, int height, int maxPointers)
                         throws IOException {
         if (width < 1 || height < 1) {
@@ -58,12 +77,31 @@
         mCloseGuard.open("close");
     }
 
+    /** Constructor used by static factory methods */
+    private UinputBridge(IBinder token, long ptr) {
+        mPtr = ptr;
+        mToken = token;
+        mCloseGuard.open("close");
+    }
+
+    /** Opens a UinputBridge that supports gamepad buttons and axes. */
+    public static UinputBridge openGamepad(IBinder token, String name)
+            throws IOException {
+        if (token == null) {
+            throw new IllegalArgumentException("Token cannot be null");
+        }
+        long ptr = nativeGamepadOpen(name, token.toString());
+        if (ptr == 0) {
+            throw new IOException("Could not open uinput device " + name);
+        }
+
+        return new UinputBridge(token, ptr);
+    }
+
     @Override
     protected void finalize() throws Throwable {
         try {
-            if (mCloseGuard != null) {
-                mCloseGuard.warnIfOpen();
-            }
+            mCloseGuard.warnIfOpen();
             close(mToken);
         } finally {
             mToken = null;
@@ -119,7 +157,35 @@
         if (isTokenValid(token)) {
             nativeSendPointerSync(mPtr);
         }
+    }
 
+    /** Send a gamepad key
+     *  @param keyIndex - the index of the w3-spec key
+     *  @param down - is the key pressed ?
+     */
+    public void sendGamepadKey(IBinder token, int keyIndex, boolean down) {
+        if (isTokenValid(token)) {
+            nativeSendGamepadKey(mPtr, keyIndex, down);
+        }
+    }
+
+    /** Send a gamepad axis value.
+     *   - Left joystick X, axis == ABS_X == 0, range [0, 254]
+     *   - Left joystick Y, axis == ABS_Y == 1, range [0, 254]
+     *   - Right joystick X, axis == ABS_RX == 3, range [0, 254]
+     *   - Right joystick Y, axis == ABS_RY == 4, range [0, 254]
+     *   - Left trigger, axis == ABS_Z == 2, range [0, 254]
+     *   - Right trigger, axis == ABS_RZ == 5, range [0, 254]
+     *   - DPad X, axis == ABS_HAT0X == 0x10, range [-1, 1]
+     *   - DPad Y, axis == ABS_HAT0Y == 0x11, range [-1, 1]
+     *
+     * @param axis is the axis index
+     * @param value is the value to set for that axis
+     */
+    public void sendGamepadAxisValue(IBinder token, int axis, int value) {
+        if (isTokenValid(token)) {
+            nativeSendGamepadAxisValue(mPtr, axis, value);
+        }
     }
 
     public void clear(IBinder token) {
diff --git a/services/core/java/com/android/server/twilight/TwilightService.java b/services/core/java/com/android/server/twilight/TwilightService.java
index 761fbf8..88a60dd 100644
--- a/services/core/java/com/android/server/twilight/TwilightService.java
+++ b/services/core/java/com/android/server/twilight/TwilightService.java
@@ -50,7 +50,7 @@
         implements AlarmManager.OnAlarmListener, Handler.Callback, LocationListener {
 
     private static final String TAG = "TwilightService";
-    private static final String FEATURE_ID = "TwilightService";
+    private static final String ATTRIBUTION_TAG = "TwilightService";
     private static final boolean DEBUG = false;
 
     private static final int MSG_START_LISTENING = 1;
@@ -74,7 +74,7 @@
     protected TwilightState mLastTwilightState;
 
     public TwilightService(Context context) {
-        super(context.createFeatureContext(FEATURE_ID));
+        super(context.createAttributionContext(ATTRIBUTION_TAG));
         mHandler = new Handler(Looper.getMainLooper(), this);
     }
 
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index b6ad241..e73c928 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -1589,6 +1589,11 @@
             info.taskAffinity = uid + ":" + info.taskAffinity;
         }
         taskAffinity = info.taskAffinity;
+        if (info.windowLayout != null && info.windowLayout.windowLayoutAffinity != null
+                && !info.windowLayout.windowLayoutAffinity.startsWith(uid)) {
+            info.windowLayout.windowLayoutAffinity =
+                    uid + ":" + info.windowLayout.windowLayoutAffinity;
+        }
         stateNotNeeded = (aInfo.flags & FLAG_STATE_NOT_NEEDED) != 0;
         nonLocalizedLabel = aInfo.nonLocalizedLabel;
         labelRes = aInfo.labelRes;
diff --git a/services/core/java/com/android/server/wm/ActivityStack.java b/services/core/java/com/android/server/wm/ActivityStack.java
index 9bad799..4ebb423 100644
--- a/services/core/java/com/android/server/wm/ActivityStack.java
+++ b/services/core/java/com/android/server/wm/ActivityStack.java
@@ -153,7 +153,6 @@
 import android.util.proto.ProtoOutputStream;
 import android.view.Display;
 import android.view.DisplayInfo;
-import android.view.ITaskOrganizer;
 import android.view.SurfaceControl;
 
 import com.android.internal.annotations.GuardedBy;
@@ -307,8 +306,6 @@
     // TODO(task-hierarchy): remove when tiles can be actual parents
     TaskTile mTile = null;
 
-    private int mLastTaskOrganizerWindowingMode = -1;
-
     private final Handler mHandler;
 
     private class ActivityStackHandler extends Handler {
@@ -635,8 +632,6 @@
 
         super.onConfigurationChanged(newParentConfig);
 
-        updateTaskOrganizerState();
-
         // Only need to update surface size here since the super method will handle updating
         // surface position.
         updateSurfaceSize(getPendingTransaction());
@@ -692,30 +687,6 @@
         }
     }
 
-    void updateTaskOrganizerState() {
-        if (!isRootTask()) {
-            return;
-        }
-
-        final int windowingMode = getWindowingMode();
-        if (windowingMode == mLastTaskOrganizerWindowingMode) {
-            // If our windowing mode hasn't actually changed, then just stick
-            // with our old organizer. This lets us implement the semantic
-            // where SysUI can continue to manage it's old tasks
-            // while CTS temporarily takes over the registration.
-            return;
-        }
-        /*
-         * Different windowing modes may be managed by different task organizers. If
-         * getTaskOrganizer returns null, we still call setTaskOrganizer to
-         * make sure we clear it.
-         */
-        final ITaskOrganizer org =
-            mWmService.mAtmService.mTaskOrganizerController.getTaskOrganizer(windowingMode);
-        setTaskOrganizer(org);
-        mLastTaskOrganizerWindowingMode = windowingMode;
-    }
-
     @Override
     public void setWindowingMode(int windowingMode) {
         // Calling Task#setWindowingMode() for leaf task since this is the a specialization of
diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java
index 958c8af..30912e5 100644
--- a/services/core/java/com/android/server/wm/InsetsPolicy.java
+++ b/services/core/java/com/android/server/wm/InsetsPolicy.java
@@ -409,6 +409,13 @@
                 t.close();
             }
 
+            // Since we don't push applySurfaceParams to a Handler-queue we don't need
+            // to push release in this case.
+            @Override
+            public void releaseSurfaceControlFromRt(SurfaceControl sc) {
+                sc.release();
+            }
+
             @Override
             public void startAnimation(InsetsAnimationControlImpl controller,
                     WindowInsetsAnimationControlListener listener, int types,
diff --git a/services/core/java/com/android/server/wm/LaunchParamsPersister.java b/services/core/java/com/android/server/wm/LaunchParamsPersister.java
index 660706e..9371c0e 100644
--- a/services/core/java/com/android/server/wm/LaunchParamsPersister.java
+++ b/services/core/java/com/android/server/wm/LaunchParamsPersister.java
@@ -16,7 +16,9 @@
 
 package com.android.server.wm;
 
+import android.annotation.Nullable;
 import android.content.ComponentName;
+import android.content.pm.ActivityInfo;
 import android.content.pm.PackageManagerInternal;
 import android.graphics.Rect;
 import android.os.Environment;
@@ -87,9 +89,17 @@
      * launching activity of tasks) to {@link PersistableLaunchParams} that stores launch metadata
      * that are stable across reboots.
      */
-    private final SparseArray<ArrayMap<ComponentName, PersistableLaunchParams>> mMap =
+    private final SparseArray<ArrayMap<ComponentName, PersistableLaunchParams>> mLaunchParamsMap =
             new SparseArray<>();
 
+    /**
+     * A map from {@link android.content.pm.ActivityInfo.WindowLayout#windowLayoutAffinity} to
+     * activity's component name for reverse queries from window layout affinities to activities.
+     * Used to decide if we should use another activity's record with the same affinity.
+     */
+    private final ArrayMap<String, ArraySet<ComponentName>> mWindowLayoutAffinityMap =
+            new ArrayMap<>();
+
     LaunchParamsPersister(PersisterQueue persisterQueue, ActivityStackSupervisor supervisor) {
         this(persisterQueue, supervisor, Environment::getDataSystemCeDirectory);
     }
@@ -112,7 +122,7 @@
     }
 
     void onCleanupUser(int userId) {
-        mMap.remove(userId);
+        mLaunchParamsMap.remove(userId);
     }
 
     private void loadLaunchParams(int userId) {
@@ -128,7 +138,7 @@
         final File[] paramsFiles = launchParamsFolder.listFiles();
         final ArrayMap<ComponentName, PersistableLaunchParams> map =
                 new ArrayMap<>(paramsFiles.length);
-        mMap.put(userId, map);
+        mLaunchParamsMap.put(userId, map);
 
         for (File paramsFile : paramsFiles) {
             if (!paramsFile.isFile()) {
@@ -179,10 +189,12 @@
                         continue;
                     }
 
-                    params.restoreFromXml(parser);
+                    params.restore(paramsFile, parser);
                 }
 
                 map.put(name, params);
+                addComponentNameToLaunchParamAffinityMapIfNotNull(
+                        name, params.mWindowLayoutAffinity);
             } catch (Exception e) {
                 Slog.w(TAG, "Failed to restore launch params for " + name, e);
                 filesToDelete.add(paramsFile);
@@ -204,19 +216,17 @@
         final ComponentName name = task.realActivity;
         final int userId = task.mUserId;
         PersistableLaunchParams params;
-        ArrayMap<ComponentName, PersistableLaunchParams> map = mMap.get(userId);
+        ArrayMap<ComponentName, PersistableLaunchParams> map = mLaunchParamsMap.get(userId);
         if (map == null) {
             map = new ArrayMap<>();
-            mMap.put(userId, map);
+            mLaunchParamsMap.put(userId, map);
         }
 
-        params = map.get(name);
-        if (params == null) {
-            params = new PersistableLaunchParams();
-            map.put(name, params);
-        }
+        params = map.computeIfAbsent(name, componentName -> new PersistableLaunchParams());
         final boolean changed = saveTaskToLaunchParam(task, display, params);
 
+        addComponentNameToLaunchParamAffinityMapIfNotNull(name, params.mWindowLayoutAffinity);
+
         if (changed) {
             mPersisterQueue.updateLastOrAddItem(
                     new LaunchParamsWriteQueueItem(userId, name, params),
@@ -243,19 +253,63 @@
             params.mBounds.setEmpty();
         }
 
+        String launchParamAffinity = task.mWindowLayoutAffinity;
+        changed |= Objects.equals(launchParamAffinity, params.mWindowLayoutAffinity);
+        params.mWindowLayoutAffinity = launchParamAffinity;
+
+        if (changed) {
+            params.mTimestamp = System.currentTimeMillis();
+        }
+
         return changed;
     }
 
+    private void addComponentNameToLaunchParamAffinityMapIfNotNull(
+            ComponentName name, String launchParamAffinity) {
+        if (launchParamAffinity == null) {
+            return;
+        }
+        mWindowLayoutAffinityMap.computeIfAbsent(launchParamAffinity, affinity -> new ArraySet<>())
+                .add(name);
+    }
+
     void getLaunchParams(Task task, ActivityRecord activity, LaunchParams outParams) {
         final ComponentName name = task != null ? task.realActivity : activity.mActivityComponent;
         final int userId = task != null ? task.mUserId : activity.mUserId;
+        final String windowLayoutAffinity;
+        if (task != null) {
+            windowLayoutAffinity = task.mWindowLayoutAffinity;
+        } else {
+            ActivityInfo.WindowLayout layout = activity.info.windowLayout;
+            windowLayoutAffinity = layout == null ? null : layout.windowLayoutAffinity;
+        }
 
         outParams.reset();
-        Map<ComponentName, PersistableLaunchParams> map = mMap.get(userId);
+        Map<ComponentName, PersistableLaunchParams> map = mLaunchParamsMap.get(userId);
         if (map == null) {
             return;
         }
-        final PersistableLaunchParams persistableParams = map.get(name);
+
+        // First use its own record as a reference.
+        PersistableLaunchParams persistableParams = map.get(name);
+        // Next we'll compare these params against all existing params with the same affinity and
+        // use the newest one.
+        if (windowLayoutAffinity != null
+                && mWindowLayoutAffinityMap.get(windowLayoutAffinity) != null) {
+            ArraySet<ComponentName> candidates = mWindowLayoutAffinityMap.get(windowLayoutAffinity);
+            for (int i = 0; i < candidates.size(); ++i) {
+                ComponentName candidate = candidates.valueAt(i);
+                final PersistableLaunchParams candidateParams = map.get(candidate);
+                if (candidateParams == null) {
+                    continue;
+                }
+
+                if (persistableParams == null
+                        || candidateParams.mTimestamp > persistableParams.mTimestamp) {
+                    persistableParams = candidateParams;
+                }
+            }
+        }
 
         if (persistableParams == null) {
             return;
@@ -272,10 +326,10 @@
 
     void removeRecordForPackage(String packageName) {
         final List<File> fileToDelete = new ArrayList<>();
-        for (int i = 0; i < mMap.size(); ++i) {
-            int userId = mMap.keyAt(i);
+        for (int i = 0; i < mLaunchParamsMap.size(); ++i) {
+            int userId = mLaunchParamsMap.keyAt(i);
             final File launchParamsFolder = getLaunchParamFolder(userId);
-            ArrayMap<ComponentName, PersistableLaunchParams> map = mMap.valueAt(i);
+            ArrayMap<ComponentName, PersistableLaunchParams> map = mLaunchParamsMap.valueAt(i);
             for (int j = map.size() - 1; j >= 0; --j) {
                 final ComponentName name = map.keyAt(j);
                 if (name.getPackageName().equals(packageName)) {
@@ -409,6 +463,7 @@
         private static final String ATTR_WINDOWING_MODE = "windowing_mode";
         private static final String ATTR_DISPLAY_UNIQUE_ID = "display_unique_id";
         private static final String ATTR_BOUNDS = "bounds";
+        private static final String ATTR_WINDOW_LAYOUT_AFFINITY = "window_layout_affinity";
 
         /** The bounds within the parent container. */
         final Rect mBounds = new Rect();
@@ -419,14 +474,29 @@
         /** The windowing mode to be in. */
         int mWindowingMode;
 
+        /**
+         * Last {@link android.content.pm.ActivityInfo.WindowLayout#windowLayoutAffinity} of the
+         * window.
+         */
+        @Nullable String mWindowLayoutAffinity;
+
+        /**
+         * Timestamp from {@link System#currentTimeMillis()} when this record is captured, or last
+         * modified time when the record is restored from storage.
+         */
+        long mTimestamp;
+
         void saveToXml(XmlSerializer serializer) throws IOException {
             serializer.attribute(null, ATTR_DISPLAY_UNIQUE_ID, mDisplayUniqueId);
             serializer.attribute(null, ATTR_WINDOWING_MODE,
                     Integer.toString(mWindowingMode));
             serializer.attribute(null, ATTR_BOUNDS, mBounds.flattenToString());
+            if (mWindowLayoutAffinity != null) {
+                serializer.attribute(null, ATTR_WINDOW_LAYOUT_AFFINITY, mWindowLayoutAffinity);
+            }
         }
 
-        void restoreFromXml(XmlPullParser parser) {
+        void restore(File xmlFile, XmlPullParser parser) {
             for (int i = 0; i < parser.getAttributeCount(); ++i) {
                 final String attrValue = parser.getAttributeValue(i);
                 switch (parser.getAttributeName(i)) {
@@ -443,16 +513,28 @@
                         }
                         break;
                     }
+                    case ATTR_WINDOW_LAYOUT_AFFINITY:
+                        mWindowLayoutAffinity = attrValue;
+                        break;
                 }
             }
+
+            // The modified time could be a few seconds later than the timestamp when the record is
+            // captured, which is a good enough estimate to the capture time after a reboot or a
+            // user switch.
+            mTimestamp = xmlFile.lastModified();
         }
 
         @Override
         public String toString() {
             final StringBuilder builder = new StringBuilder("PersistableLaunchParams{");
-            builder.append("windowingMode=" + mWindowingMode);
+            builder.append(" windowingMode=" + mWindowingMode);
             builder.append(" displayUniqueId=" + mDisplayUniqueId);
             builder.append(" bounds=" + mBounds);
+            if (mWindowLayoutAffinity != null) {
+                builder.append(" launchParamsAffinity=" + mWindowLayoutAffinity);
+            }
+            builder.append(" timestamp=" + mTimestamp);
             builder.append(" }");
             return builder.toString();
         }
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 5ed903e..5ab5fbc 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -199,6 +199,7 @@
     private static final String ATTR_MIN_WIDTH = "min_width";
     private static final String ATTR_MIN_HEIGHT = "min_height";
     private static final String ATTR_PERSIST_TASK_VERSION = "persist_task_version";
+    private static final String ATTR_WINDOW_LAYOUT_AFFINITY = "window_layout_affinity";
 
     // Current version of the task record we persist. Used to check if we need to run any upgrade
     // code.
@@ -233,6 +234,8 @@
 
     String affinity;        // The affinity name for this task, or null; may change identity.
     String rootAffinity;    // Initial base affinity, or null; does not change from initial root.
+    String mWindowLayoutAffinity; // Launch param affinity of this task or null. Used when saving
+                                // launch params of this task.
     IVoiceInteractionSession voiceSession;    // Voice interaction session driving task
     IVoiceInteractor voiceInteractor;         // Associated interactor to provide to app
     Intent intent;          // The original intent that started the task. Note that this value can
@@ -474,6 +477,7 @@
      * taskAppeared callback, and emit a taskRemoved callback when the Task is vanished.
      */
     ITaskOrganizer mTaskOrganizer;
+    private int mLastTaskOrganizerWindowingMode = -1;
 
     /**
      * Last Picture-in-Picture params applicable to the task. Updated when the app
@@ -1000,6 +1004,8 @@
                 origActivity = new ComponentName(info.packageName, info.name);
             }
         }
+        mWindowLayoutAffinity =
+                info.windowLayout == null ? null : info.windowLayout.windowLayoutAffinity;
 
         final int intentFlags = intent == null ? 0 : intent.getFlags();
         if ((intentFlags & Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED) != 0) {
@@ -1929,6 +1935,7 @@
         // TODO: Should also take care of Pip mode changes here.
 
         saveLaunchingStateIfNeeded();
+        updateTaskOrganizerState(false /* forceUpdate */);
     }
 
     /**
@@ -3408,6 +3415,9 @@
                 pw.println();
             }
         }
+        if (mWindowLayoutAffinity != null) {
+            pw.print(prefix); pw.print("windowLayoutAffinity="); pw.println(mWindowLayoutAffinity);
+        }
         if (voiceSession != null || voiceInteractor != null) {
             pw.print(prefix); pw.print("VOICE: session=0x");
             pw.print(Integer.toHexString(System.identityHashCode(voiceSession)));
@@ -3589,6 +3599,9 @@
         } else if (rootAffinity != null) {
             out.attribute(null, ATTR_ROOT_AFFINITY, rootAffinity != null ? rootAffinity : "@");
         }
+        if (mWindowLayoutAffinity != null) {
+            out.attribute(null, ATTR_WINDOW_LAYOUT_AFFINITY, mWindowLayoutAffinity);
+        }
         out.attribute(null, ATTR_ROOTHASRESET, String.valueOf(rootWasReset));
         out.attribute(null, ATTR_AUTOREMOVERECENTS, String.valueOf(autoRemoveRecents));
         out.attribute(null, ATTR_ASKEDCOMPATMODE, String.valueOf(askedCompatMode));
@@ -3746,6 +3759,7 @@
             String affinity = null;
             String rootAffinity = null;
             boolean hasRootAffinity = false;
+            String windowLayoutAffinity = null;
             boolean rootHasReset = false;
             boolean autoRemoveRecents = false;
             boolean askedCompatMode = false;
@@ -3798,6 +3812,9 @@
                         rootAffinity = attrValue;
                         hasRootAffinity = true;
                         break;
+                    case ATTR_WINDOW_LAYOUT_AFFINITY:
+                        windowLayoutAffinity = attrValue;
+                        break;
                     case ATTR_ROOTHASRESET:
                         rootHasReset = Boolean.parseBoolean(attrValue);
                         break;
@@ -3953,6 +3970,7 @@
                     realActivitySuspended, userSetupComplete, minWidth, minHeight, null /*stack*/);
             task.mLastNonFullscreenBounds = lastNonFullscreenBounds;
             task.setBounds(lastNonFullscreenBounds);
+            task.mWindowLayoutAffinity = windowLayoutAffinity;
 
             for (int activityNdx = activities.size() - 1; activityNdx >= 0; --activityNdx) {
                 task.addChild(activities.get(activityNdx));
@@ -4018,6 +4036,39 @@
     // Called on Binder death.
     void taskOrganizerDied() {
         mTaskOrganizer = null;
+        mLastTaskOrganizerWindowingMode = -1;
+    }
+
+    /**
+     * Called when the task state changes (ie. from windowing mode change) an the task organizer
+     * state should also be updated.
+     *
+     * @param forceUpdate Updates the task organizer to the one currently specified in the task
+     *                    org controller for the task's windowing mode, ignoring the cached
+     *                    windowing mode checks.
+     */
+    void updateTaskOrganizerState(boolean forceUpdate) {
+        if (!isRootTask()) {
+            return;
+        }
+
+        final int windowingMode = getWindowingMode();
+        if (!forceUpdate && windowingMode == mLastTaskOrganizerWindowingMode) {
+            // If our windowing mode hasn't actually changed, then just stick
+            // with our old organizer. This lets us implement the semantic
+            // where SysUI can continue to manage it's old tasks
+            // while CTS temporarily takes over the registration.
+            return;
+        }
+        /*
+         * Different windowing modes may be managed by different task organizers. If
+         * getTaskOrganizer returns null, we still call setTaskOrganizer to
+         * make sure we clear it.
+         */
+        final ITaskOrganizer org =
+                mWmService.mAtmService.mTaskOrganizerController.getTaskOrganizer(windowingMode);
+        setTaskOrganizer(org);
+        mLastTaskOrganizerWindowingMode = windowingMode;
     }
 
     @Override
diff --git a/services/core/java/com/android/server/wm/TaskOrganizerController.java b/services/core/java/com/android/server/wm/TaskOrganizerController.java
index cfb5706..9cbc9ee 100644
--- a/services/core/java/com/android/server/wm/TaskOrganizerController.java
+++ b/services/core/java/com/android/server/wm/TaskOrganizerController.java
@@ -105,7 +105,7 @@
 
 
         TaskOrganizerState(ITaskOrganizer organizer, int windowingMode,
-                TaskOrganizerState replacing) {
+                @Nullable TaskOrganizerState replacing) {
             mOrganizer = organizer;
             mDeathRecipient = new DeathRecipient(organizer, windowingMode);
             try {
@@ -203,10 +203,27 @@
         final long origId = Binder.clearCallingIdentity();
         try {
             synchronized (mGlobalLock) {
+                if (getTaskOrganizer(windowingMode) != null) {
+                    Slog.w(TAG, "Task organizer already exists for windowing mode: "
+                            + windowingMode);
+                }
+                final TaskOrganizerState previousState =
+                        mTaskOrganizersForWindowingMode.get(windowingMode);
                 final TaskOrganizerState state = new TaskOrganizerState(organizer, windowingMode,
-                        mTaskOrganizersForWindowingMode.get(windowingMode));
+                        previousState);
                 mTaskOrganizersForWindowingMode.put(windowingMode, state);
                 mTaskOrganizerStates.put(organizer.asBinder(), state);
+
+                if (previousState == null) {
+                    // Only in the case where this is the root task organizer for the given
+                    // windowing mode, we add report all existing tasks in that mode to the new
+                    // task organizer.
+                    mService.mRootWindowContainer.forAllTasks((task) -> {
+                        if (task.getWindowingMode() == windowingMode) {
+                            task.updateTaskOrganizerState(true /* forceUpdate */);
+                        }
+                    });
+                }
             }
         } finally {
             Binder.restoreCallingIdentity(origId);
diff --git a/services/core/jni/com_android_server_pm_PackageManagerShellCommandDataLoader.cpp b/services/core/jni/com_android_server_pm_PackageManagerShellCommandDataLoader.cpp
index 6f9d012..b96fbf5 100644
--- a/services/core/jni/com_android_server_pm_PackageManagerShellCommandDataLoader.cpp
+++ b/services/core/jni/com_android_server_pm_PackageManagerShellCommandDataLoader.cpp
@@ -172,26 +172,25 @@
 
 BlockHeader readHeader(std::span<uint8_t>& data);
 
-static inline int32_t readBEInt32(borrowed_fd fd) {
+static inline int32_t readLEInt32(borrowed_fd fd) {
     int32_t result;
     ReadFully(fd, &result, sizeof(result));
-    result = int32_t(be32toh(result));
+    result = int32_t(le32toh(result));
     return result;
 }
 
 static inline std::vector<char> readBytes(borrowed_fd fd) {
-    int32_t size = readBEInt32(fd);
+    int32_t size = readLEInt32(fd);
     std::vector<char> result(size);
     ReadFully(fd, result.data(), size);
     return result;
 }
 
 static inline int32_t skipIdSigHeaders(borrowed_fd fd) {
-    readBEInt32(fd);        // version
-    readBytes(fd);          // verityRootHash
-    readBytes(fd);          // v3Digest
-    readBytes(fd);          // pkcs7SignatureBlock
-    return readBEInt32(fd); // size of the verity tree
+    readLEInt32(fd);        // version
+    readBytes(fd);          // hashingInfo
+    readBytes(fd);          // signingInfo
+    return readLEInt32(fd); // size of the verity tree
 }
 
 static inline IncFsSize verityTreeSizeForFile(IncFsSize fileSize) {
diff --git a/services/core/jni/com_android_server_tv_GamepadKeys.h b/services/core/jni/com_android_server_tv_GamepadKeys.h
new file mode 100644
index 0000000..11fc903
--- /dev/null
+++ b/services/core/jni/com_android_server_tv_GamepadKeys.h
@@ -0,0 +1,79 @@
+#ifndef ANDROIDTVREMOTE_SERVICE_JNI_GAMEPAD_KEYS_H_
+#define ANDROIDTVREMOTE_SERVICE_JNI_GAMEPAD_KEYS_H_
+
+#include <linux/input.h>
+
+namespace android {
+
+// Follows the W3 spec for gamepad buttons and their corresponding mapping into
+// Linux keycodes. Note that gamepads are generally not very well standardized
+// and various controllers will result in different buttons. This mapping tries
+// to be reasonable.
+//
+// W3 Button spec: https://www.w3.org/TR/gamepad/#remapping
+//
+// Standard gamepad keycodes are added plus 2 additional buttons (e.g. Stadia
+// has "Assistant" and "Share", PS4 has the touchpad button).
+//
+// To generate this list, PS4, XBox, Stadia and Nintendo Switch Pro were tested.
+static const int GAMEPAD_KEY_CODES[19] = {
+        // Right-side buttons. A/B/X/Y or circle/triangle/square/X or similar
+        BTN_A, // "South", A, GAMEPAD and SOUTH have the same constant
+        BTN_B, // "East", BTN_B, BTN_EAST have the same constant
+        BTN_X, // "West", Note that this maps to X and NORTH in constants
+        BTN_Y, // "North", Note that this maps to Y and WEST in constants
+
+        BTN_TL, // "Left Bumper" / "L1" - Nintendo sends BTN_WEST instead
+        BTN_TR, // "Right Bumper" / "R1" - Nintendo sends BTN_Z instead
+
+        // For triggers, gamepads vary:
+        //   - Stadia sends analog values over ABS_GAS/ABS_BRAKE and sends
+        //     TriggerHappy3/4 as digital presses
+        //   - PS4 and Xbox send analog values as ABS_Z/ABS_RZ
+        //   - Nintendo Pro sends BTN_TL/BTN_TR (since bumpers behave differently)
+        // As placeholders we chose the stadia trigger-happy values since TL/TR are
+        // sent for bumper button presses
+        BTN_TRIGGER_HAPPY4, // "Left Trigger" / "L2"
+        BTN_TRIGGER_HAPPY3, // "Right Trigger" / "R2"
+
+        BTN_SELECT, // "Select/Back". Often "options" or similar
+        BTN_START,  // "Start/forward". Often "hamburger" icon
+
+        BTN_THUMBL, // "Left Joystick Pressed"
+        BTN_THUMBR, // "Right Joystick Pressed"
+
+        // For DPads, gamepads generally only send axis changes
+        // on ABS_HAT0X and ABS_HAT0Y.
+        KEY_UP,    // "Digital Pad up"
+        KEY_DOWN,  // "Digital Pad down"
+        KEY_LEFT,  // "Digital Pad left"
+        KEY_RIGHT, // "Digital Pad right"
+
+        BTN_MODE, // "Main button" (Stadia/PS/XBOX/Home)
+
+        BTN_TRIGGER_HAPPY1, // Extra button: "Assistant" for Stadia
+        BTN_TRIGGER_HAPPY2, // Extra button: "Share" for Stadia
+};
+
+// Defines information for an axis.
+struct Axis {
+    int number;
+    int rangeMin;
+    int rangeMax;
+};
+
+// List of all axes supported by a gamepad
+static const Axis GAMEPAD_AXES[] = {
+        {ABS_X, 0, 254},    // Left joystick X
+        {ABS_Y, 0, 254},    // Left joystick Y
+        {ABS_RX, 0, 254},   // Right joystick X
+        {ABS_RY, 0, 254},   // Right joystick Y
+        {ABS_Z, 0, 254},    // Left trigger
+        {ABS_RZ, 0, 254},   // Right trigger
+        {ABS_HAT0X, -1, 1}, // DPad X
+        {ABS_HAT0Y, -1, 1}, // DPad Y
+};
+
+} // namespace android
+
+#endif // ANDROIDTVREMOTE_SERVICE_JNI_GAMEPAD_KEYS_H_
diff --git a/services/core/jni/com_android_server_tv_TvKeys.h b/services/core/jni/com_android_server_tv_TvKeys.h
index 4895f34..7eacdf6 100644
--- a/services/core/jni/com_android_server_tv_TvKeys.h
+++ b/services/core/jni/com_android_server_tv_TvKeys.h
@@ -110,4 +110,4 @@
 
 } // namespace android
 
-#endif // SERVICE_JNI_KEYS_H_
+#endif // ANDROIDTVREMOTE_SERVICE_JNI_KEYS_H_
diff --git a/services/core/jni/com_android_server_tv_TvUinputBridge.cpp b/services/core/jni/com_android_server_tv_TvUinputBridge.cpp
index c832c18..0e96bd7 100644
--- a/services/core/jni/com_android_server_tv_TvUinputBridge.cpp
+++ b/services/core/jni/com_android_server_tv_TvUinputBridge.cpp
@@ -16,6 +16,7 @@
 
 #define LOG_TAG "TvRemote-native-uiBridge"
 
+#include "com_android_server_tv_GamepadKeys.h"
 #include "com_android_server_tv_TvKeys.h"
 
 #include "jni.h"
@@ -92,27 +93,156 @@
     }
 }
 
+static const int kInvalidFileDescriptor = -1;
+
+// Convenience class to manage an opened /dev/uinput device
+class UInputDescriptor {
+public:
+    UInputDescriptor() : mFd(kInvalidFileDescriptor) {
+        memset(&mUinputDescriptor, 0, sizeof(mUinputDescriptor));
+    }
+
+    // Auto-closes any open /dev/uinput descriptor unless detached.
+    ~UInputDescriptor();
+
+    // Open /dev/uinput and prepare to register
+    // the device with the given name and unique Id
+    bool Open(const char* name, const char* uniqueId);
+
+    // Checks if the current file descriptor is valid
+    bool IsValid() const { return mFd != kInvalidFileDescriptor; }
+
+    void EnableKey(int keyCode);
+
+    void EnableAxesEvents();
+    void EnableAxis(int axis, int rangeMin, int rangeMax);
+
+    bool Create();
+
+    // Detaches from the current file descriptor
+    // Returns the file descriptor for /dev/uniput
+    int Detach();
+
+private:
+    int mFd;
+    struct uinput_user_dev mUinputDescriptor;
+};
+
+UInputDescriptor::~UInputDescriptor() {
+    if (mFd != kInvalidFileDescriptor) {
+        close(mFd);
+        mFd = kInvalidFileDescriptor;
+    }
+}
+
+int UInputDescriptor::Detach() {
+    int fd = mFd;
+    mFd = kInvalidFileDescriptor;
+    return fd;
+}
+
+bool UInputDescriptor::Open(const char* name, const char* uniqueId) {
+    if (IsValid()) {
+        ALOGE("UInput device already open");
+        return false;
+    }
+
+    mFd = ::open("/dev/uinput", O_WRONLY | O_NDELAY);
+    if (mFd < 0) {
+        ALOGE("Cannot open /dev/uinput: %s.", strerror(errno));
+        mFd = kInvalidFileDescriptor;
+        return false;
+    }
+
+    // write device unique id to the phys property
+    ioctl(mFd, UI_SET_PHYS, uniqueId);
+
+    memset(&mUinputDescriptor, 0, sizeof(mUinputDescriptor));
+    strlcpy(mUinputDescriptor.name, name, UINPUT_MAX_NAME_SIZE);
+    mUinputDescriptor.id.version = 1;
+    mUinputDescriptor.id.bustype = BUS_VIRTUAL;
+
+    // All UInput devices we use process keys
+    ioctl(mFd, UI_SET_EVBIT, EV_KEY);
+
+    return true;
+}
+
+void UInputDescriptor::EnableKey(int keyCode) {
+    ioctl(mFd, UI_SET_KEYBIT, keyCode);
+}
+
+void UInputDescriptor::EnableAxesEvents() {
+    ioctl(mFd, UI_SET_EVBIT, EV_ABS);
+}
+
+void UInputDescriptor::EnableAxis(int axis, int rangeMin, int rangeMax) {
+    if ((axis < 0) || (axis >= NELEM(mUinputDescriptor.absmin))) {
+        ALOGE("Invalid axis number: %d", axis);
+        return;
+    }
+
+    if (ioctl(mFd, UI_SET_ABSBIT, axis) != 0) {
+        ALOGE("Failed to set absbit for %d", axis);
+    }
+
+    mUinputDescriptor.absmin[axis] = rangeMin;
+    mUinputDescriptor.absmax[axis] = rangeMax;
+    mUinputDescriptor.absfuzz[axis] = 0;
+    mUinputDescriptor.absflat[axis] = 0;
+}
+
+bool UInputDescriptor::Create() {
+    // register the input device
+    if (write(mFd, &mUinputDescriptor, sizeof(mUinputDescriptor)) != sizeof(mUinputDescriptor)) {
+        ALOGE("Cannot write uinput_user_dev to fd %d: %s.", mFd, strerror(errno));
+        return false;
+    }
+
+    if (ioctl(mFd, UI_DEV_CREATE) != 0) {
+        ALOGE("Unable to create uinput device: %s.", strerror(errno));
+        return false;
+    }
+
+    ALOGV("Created uinput device, fd=%d.", mFd);
+
+    return true;
+}
+
 class NativeConnection {
 public:
+    enum class ConnectionType {
+        kRemoteDevice,
+        kGamepadDevice,
+    };
+
     ~NativeConnection();
 
     static NativeConnection* open(const char* name, const char* uniqueId,
             int32_t width, int32_t height, int32_t maxPointerId);
 
+    static NativeConnection* openGamepad(const char* name, const char* uniqueId);
+
     void sendEvent(int32_t type, int32_t code, int32_t value);
 
     int32_t getMaxPointers() const { return mMaxPointers; }
 
+    ConnectionType getType() const { return mType; }
+
+    bool IsGamepad() const { return getType() == ConnectionType::kGamepadDevice; }
+
+    bool IsRemote() const { return getType() == ConnectionType::kRemoteDevice; }
+
 private:
-    NativeConnection(int fd, int32_t maxPointers);
+    NativeConnection(int fd, int32_t maxPointers, ConnectionType type);
 
     const int mFd;
     const int32_t mMaxPointers;
+    const ConnectionType mType;
 };
 
-NativeConnection::NativeConnection(int fd, int32_t maxPointers) :
-        mFd(fd), mMaxPointers(maxPointers) {
-}
+NativeConnection::NativeConnection(int fd, int32_t maxPointers, ConnectionType type)
+      : mFd(fd), mMaxPointers(maxPointers), mType(type) {}
 
 NativeConnection::~NativeConnection() {
     ALOGI("Un-Registering uinput device %d.", mFd);
@@ -125,44 +255,50 @@
     ALOGI("Registering uinput device %s: touch pad size %dx%d, "
             "max pointers %d.", name, width, height, maxPointers);
 
-    int fd = ::open("/dev/uinput", O_WRONLY | O_NDELAY);
-    if (fd < 0) {
-        ALOGE("Cannot open /dev/uinput: %s.", strerror(errno));
-        return nullptr;
-    }
-
-    struct uinput_user_dev uinp;
-    memset(&uinp, 0, sizeof(struct uinput_user_dev));
-    strlcpy(uinp.name, name, UINPUT_MAX_NAME_SIZE);
-    uinp.id.version = 1;
-    uinp.id.bustype = BUS_VIRTUAL;
-
-    // initialize keymap
     initKeysMap();
 
-    // write device unique id to the phys property
-    ioctl(fd, UI_SET_PHYS, uniqueId);
-
-    // set the keys mapped
-    ioctl(fd, UI_SET_EVBIT, EV_KEY);
-    for (size_t i = 0; i < NELEM(KEYS); i++) {
-        ioctl(fd, UI_SET_KEYBIT, KEYS[i].linuxKeyCode);
-    }
-
-    // register the input device
-    if (write(fd, &uinp, sizeof(uinp)) != sizeof(uinp)) {
-        ALOGE("Cannot write uinput_user_dev to fd %d: %s.", fd, strerror(errno));
-        close(fd);
-        return NULL;
-    }
-    if (ioctl(fd, UI_DEV_CREATE) != 0) {
-        ALOGE("Unable to create uinput device: %s.", strerror(errno));
-        close(fd);
+    UInputDescriptor descriptor;
+    if (!descriptor.Open(name, uniqueId)) {
         return nullptr;
     }
 
-    ALOGV("Created uinput device, fd=%d.", fd);
-    return new NativeConnection(fd, maxPointers);
+    // set the keys mapped
+    for (size_t i = 0; i < NELEM(KEYS); i++) {
+        descriptor.EnableKey(KEYS[i].linuxKeyCode);
+    }
+
+    if (!descriptor.Create()) {
+        return nullptr;
+    }
+
+    return new NativeConnection(descriptor.Detach(), maxPointers, ConnectionType::kRemoteDevice);
+}
+
+NativeConnection* NativeConnection::openGamepad(const char* name, const char* uniqueId) {
+    ALOGI("Registering uinput device %s: gamepad", name);
+
+    UInputDescriptor descriptor;
+    if (!descriptor.Open(name, uniqueId)) {
+        return nullptr;
+    }
+
+    // set the keys mapped for gamepads
+    for (size_t i = 0; i < NELEM(GAMEPAD_KEY_CODES); i++) {
+        descriptor.EnableKey(GAMEPAD_KEY_CODES[i]);
+    }
+
+    // define the axes that are required
+    descriptor.EnableAxesEvents();
+    for (size_t i = 0; i < NELEM(GAMEPAD_AXES); i++) {
+        const Axis& axis = GAMEPAD_AXES[i];
+        descriptor.EnableAxis(axis.number, axis.rangeMin, axis.rangeMax);
+    }
+
+    if (!descriptor.Create()) {
+        return nullptr;
+    }
+
+    return new NativeConnection(descriptor.Detach(), 0, ConnectionType::kGamepadDevice);
 }
 
 void NativeConnection::sendEvent(int32_t type, int32_t code, int32_t value) {
@@ -174,7 +310,6 @@
     write(mFd, &iev, sizeof(iev));
 }
 
-
 static jlong nativeOpen(JNIEnv* env, jclass clazz,
         jstring nameStr, jstring uniqueIdStr,
         jint width, jint height, jint maxPointers) {
@@ -186,6 +321,14 @@
     return reinterpret_cast<jlong>(connection);
 }
 
+static jlong nativeGamepadOpen(JNIEnv* env, jclass clazz, jstring nameStr, jstring uniqueIdStr) {
+    ScopedUtfChars name(env, nameStr);
+    ScopedUtfChars uniqueId(env, uniqueIdStr);
+
+    NativeConnection* connection = NativeConnection::openGamepad(name.c_str(), uniqueId.c_str());
+    return reinterpret_cast<jlong>(connection);
+}
+
 static void nativeClose(JNIEnv* env, jclass clazz, jlong ptr) {
     NativeConnection* connection = reinterpret_cast<NativeConnection*>(ptr);
     delete connection;
@@ -194,6 +337,12 @@
 static void nativeSendKey(JNIEnv* env, jclass clazz, jlong ptr, jint keyCode, jboolean down) {
     int32_t code = getLinuxKeyCode(keyCode);
     NativeConnection* connection = reinterpret_cast<NativeConnection*>(ptr);
+
+    if (connection->IsGamepad()) {
+        ALOGE("Invalid key even for a gamepad - need to send gamepad events");
+        return;
+    }
+
     if (code != KEY_UNKNOWN) {
         connection->sendEvent(EV_KEY, code, down ? 1 : 0);
     } else {
@@ -201,10 +350,44 @@
     }
 }
 
+static void nativeSendGamepadKey(JNIEnv* env, jclass clazz, jlong ptr, jint keyIndex,
+                                 jboolean down) {
+    NativeConnection* connection = reinterpret_cast<NativeConnection*>(ptr);
+
+    if (!connection->IsGamepad()) {
+        ALOGE("Invalid gamepad key for non-gamepad device");
+        return;
+    }
+
+    if ((keyIndex < 0) || (keyIndex >= NELEM(GAMEPAD_KEY_CODES))) {
+        ALOGE("Invalid gamepad key index: %d", keyIndex);
+        return;
+    }
+
+    connection->sendEvent(EV_KEY, GAMEPAD_KEY_CODES[keyIndex], down ? 1 : 0);
+}
+
+static void nativeSendGamepadAxisValue(JNIEnv* env, jclass clazz, jlong ptr, jint axis,
+                                       jint value) {
+    NativeConnection* connection = reinterpret_cast<NativeConnection*>(ptr);
+
+    if (!connection->IsGamepad()) {
+        ALOGE("Invalid axis send for non-gamepad device");
+        return;
+    }
+
+    connection->sendEvent(EV_ABS, axis, value);
+}
+
 static void nativeSendPointerDown(JNIEnv* env, jclass clazz, jlong ptr,
         jint pointerId, jint x, jint y) {
     NativeConnection* connection = reinterpret_cast<NativeConnection*>(ptr);
 
+    if (connection->IsGamepad()) {
+        ALOGE("Invalid pointer down event for a gamepad.");
+        return;
+    }
+
     int32_t slot = findSlot(pointerId);
     if (slot == SLOT_UNKNOWN) {
         slot = assignSlot(pointerId);
@@ -221,6 +404,11 @@
         jint pointerId) {
     NativeConnection* connection = reinterpret_cast<NativeConnection*>(ptr);
 
+    if (connection->IsGamepad()) {
+        ALOGE("Invalid pointer up event for a gamepad.");
+        return;
+    }
+
     int32_t slot = findSlot(pointerId);
     if (slot != SLOT_UNKNOWN) {
         connection->sendEvent(EV_ABS, ABS_MT_SLOT, slot);
@@ -238,17 +426,34 @@
     NativeConnection* connection = reinterpret_cast<NativeConnection*>(ptr);
 
     // Clear keys.
-    for (size_t i = 0; i < NELEM(KEYS); i++) {
-        connection->sendEvent(EV_KEY, KEYS[i].linuxKeyCode, 0);
-    }
+    if (connection->IsRemote()) {
+        for (size_t i = 0; i < NELEM(KEYS); i++) {
+            connection->sendEvent(EV_KEY, KEYS[i].linuxKeyCode, 0);
+        }
 
-    // Clear pointers.
-    int32_t slot = SLOT_UNKNOWN;
-    for (int32_t i = 0; i < connection->getMaxPointers(); i++) {
-        slot = findSlot(i);
-        if (slot != SLOT_UNKNOWN) {
-            connection->sendEvent(EV_ABS, ABS_MT_SLOT, slot);
-            connection->sendEvent(EV_ABS, ABS_MT_TRACKING_ID, -1);
+        // Clear pointers.
+        int32_t slot = SLOT_UNKNOWN;
+        for (int32_t i = 0; i < connection->getMaxPointers(); i++) {
+            slot = findSlot(i);
+            if (slot != SLOT_UNKNOWN) {
+                connection->sendEvent(EV_ABS, ABS_MT_SLOT, slot);
+                connection->sendEvent(EV_ABS, ABS_MT_TRACKING_ID, -1);
+            }
+        }
+    } else {
+        for (size_t i = 0; i < NELEM(GAMEPAD_KEY_CODES); i++) {
+            connection->sendEvent(EV_KEY, GAMEPAD_KEY_CODES[i], 0);
+        }
+
+        for (size_t i = 0; i < NELEM(GAMEPAD_AXES); i++) {
+            const Axis& axis = GAMEPAD_AXES[i];
+            if ((axis.number == ABS_Z) || (axis.number == ABS_RZ)) {
+                // Mark triggers unpressed
+                connection->sendEvent(EV_ABS, axis.number, 0);
+            } else {
+                // Joysticks and dpad rests on center
+                connection->sendEvent(EV_ABS, axis.number, (axis.rangeMin + axis.rangeMax) / 2);
+            }
         }
     }
 
@@ -261,20 +466,16 @@
  */
 
 static JNINativeMethod gUinputBridgeMethods[] = {
-    { "nativeOpen", "(Ljava/lang/String;Ljava/lang/String;III)J",
-        (void*)nativeOpen },
-    { "nativeClose", "(J)V",
-        (void*)nativeClose },
-    { "nativeSendKey", "(JIZ)V",
-        (void*)nativeSendKey },
-    { "nativeSendPointerDown", "(JIII)V",
-        (void*)nativeSendPointerDown },
-    { "nativeSendPointerUp", "(JI)V",
-        (void*)nativeSendPointerUp },
-    { "nativeClear", "(J)V",
-        (void*)nativeClear },
-    { "nativeSendPointerSync", "(J)V",
-        (void*)nativeSendPointerSync },
+        {"nativeOpen", "(Ljava/lang/String;Ljava/lang/String;III)J", (void*)nativeOpen},
+        {"nativeGamepadOpen", "(Ljava/lang/String;Ljava/lang/String;)J", (void*)nativeGamepadOpen},
+        {"nativeClose", "(J)V", (void*)nativeClose},
+        {"nativeSendKey", "(JIZ)V", (void*)nativeSendKey},
+        {"nativeSendPointerDown", "(JIII)V", (void*)nativeSendPointerDown},
+        {"nativeSendPointerUp", "(JI)V", (void*)nativeSendPointerUp},
+        {"nativeClear", "(J)V", (void*)nativeClear},
+        {"nativeSendPointerSync", "(J)V", (void*)nativeSendPointerSync},
+        {"nativeSendGamepadKey", "(JIZ)V", (void*)nativeSendGamepadKey},
+        {"nativeSendGamepadAxisValue", "(JII)V", (void*)nativeSendGamepadAxisValue},
 };
 
 int register_android_server_tv_TvUinputBridge(JNIEnv* env) {
diff --git a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
index 312d2d2..6f41631 100644
--- a/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
+++ b/services/devicepolicy/java/com/android/server/devicepolicy/DevicePolicyManagerService.java
@@ -86,6 +86,7 @@
 import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_AWARE;
 import static android.content.pm.PackageManager.MATCH_DIRECT_BOOT_UNAWARE;
 import static android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES;
+import static android.net.NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK;
 import static android.provider.Settings.Global.PRIVATE_DNS_MODE;
 import static android.provider.Settings.Global.PRIVATE_DNS_SPECIFIER;
 import static android.provider.Telephony.Carriers.DPC_URI;
@@ -1198,7 +1199,7 @@
         // Whether the admin explicitly requires personal apps to be suspended
         boolean mSuspendPersonalApps = false;
         // Maximum time the profile owned by this admin can be off.
-        long mProfileMaximumTimeOff = 0;
+        long mProfileMaximumTimeOffMillis = 0;
         // Time by which the profile should be turned on according to System.currentTimeMillis().
         long mProfileOffDeadline = 0;
 
@@ -1439,10 +1440,11 @@
             if (mSuspendPersonalApps) {
                 writeAttributeValueToXml(out, TAG_SUSPEND_PERSONAL_APPS, mSuspendPersonalApps);
             }
-            if (mProfileMaximumTimeOff != 0) {
-                writeAttributeValueToXml(out, TAG_PROFILE_MAXIMUM_TIME_OFF, mProfileMaximumTimeOff);
+            if (mProfileMaximumTimeOffMillis != 0) {
+                writeAttributeValueToXml(out, TAG_PROFILE_MAXIMUM_TIME_OFF,
+                        mProfileMaximumTimeOffMillis);
             }
-            if (mProfileMaximumTimeOff != 0) {
+            if (mProfileMaximumTimeOffMillis != 0) {
                 writeAttributeValueToXml(out, TAG_PROFILE_OFF_DEADLINE, mProfileOffDeadline);
             }
             if (!TextUtils.isEmpty(mAlwaysOnVpnPackage)) {
@@ -1691,7 +1693,7 @@
                     mSuspendPersonalApps = Boolean.parseBoolean(
                             parser.getAttributeValue(null, ATTR_VALUE));
                 } else if (TAG_PROFILE_MAXIMUM_TIME_OFF.equals(tag)) {
-                    mProfileMaximumTimeOff =
+                    mProfileMaximumTimeOffMillis =
                             Long.parseLong(parser.getAttributeValue(null, ATTR_VALUE));
                 } else if (TAG_PROFILE_OFF_DEADLINE.equals(tag)) {
                     mProfileOffDeadline =
@@ -1929,8 +1931,8 @@
                 pw.println(mCrossProfilePackages);
             pw.print("mSuspendPersonalApps=");
                 pw.println(mSuspendPersonalApps);
-            pw.print("mProfileMaximumTimeOff=");
-                pw.println(mProfileMaximumTimeOff);
+            pw.print("mProfileMaximumTimeOffMillis=");
+                pw.println(mProfileMaximumTimeOffMillis);
             pw.print("mProfileOffDeadline=");
                 pw.println(mProfileOffDeadline);
             pw.print("mAlwaysOnVpnPackage=");
@@ -5874,6 +5876,14 @@
         }
     }
 
+    private void enforceNetworkStackOrProfileOrDeviceOwner(ComponentName who) {
+        if (mContext.checkCallingPermission(PERMISSION_MAINLINE_NETWORK_STACK)
+                == PackageManager.PERMISSION_GRANTED) {
+            return;
+        }
+        enforceProfileOrDeviceOwner(who);
+    }
+
     private void enforceDeviceOwnerOrProfileOwnerOnOrganizationOwnedDevice(ComponentName who) {
         synchronized (getLockObject()) {
             getActiveAdminForCallerLocked(
@@ -6870,7 +6880,7 @@
 
     @Override
     public boolean isAlwaysOnVpnLockdownEnabled(ComponentName admin) throws SecurityException {
-        enforceProfileOrDeviceOwner(admin);
+        enforceNetworkStackOrProfileOrDeviceOwner(admin);
 
         final int userId = mInjector.userHandleGetCallingUserId();
         return mInjector.binderWithCleanCallingIdentity(
@@ -7786,7 +7796,7 @@
      * Set whether auto time is enabled on the device.
      */
     @Override
-    public void setAutoTime(ComponentName who, boolean enabled) {
+    public void setAutoTimeEnabled(ComponentName who, boolean enabled) {
         if (!mHasFeature) {
             return;
         }
@@ -7807,7 +7817,7 @@
      * Returns whether auto time is used on the device or not.
      */
     @Override
-    public boolean getAutoTime(ComponentName who) {
+    public boolean getAutoTimeEnabled(ComponentName who) {
         if (!mHasFeature) {
             return false;
         }
@@ -7821,7 +7831,7 @@
      * Set whether auto time zone is enabled on the device.
      */
     @Override
-    public void setAutoTimeZone(ComponentName who, boolean enabled) {
+    public void setAutoTimeZoneEnabled(ComponentName who, boolean enabled) {
         if (!mHasFeature) {
             return;
         }
@@ -7842,7 +7852,7 @@
      * Returns whether auto time zone is used on the device or not.
      */
     @Override
-    public boolean getAutoTimeZone(ComponentName who) {
+    public boolean getAutoTimeZoneEnabled(ComponentName who) {
         if (!mHasFeature) {
             return false;
         }
@@ -15716,18 +15726,18 @@
         }
         boolean shouldSaveSettings = false;
         if (profileOwner.mProfileOffDeadline != 0
-                && (profileOwner.mProfileMaximumTimeOff == 0 || unlocked)) {
+                && (profileOwner.mProfileMaximumTimeOffMillis == 0 || unlocked)) {
             // There is a deadline but either there is no policy or the profile is unlocked -> clear
             // the deadline.
             Slog.i(LOG_TAG, "Profile off deadline is reset to zero");
             profileOwner.mProfileOffDeadline = 0;
             shouldSaveSettings = true;
         } else if (profileOwner.mProfileOffDeadline == 0
-                && (profileOwner.mProfileMaximumTimeOff != 0 && !unlocked)) {
+                && (profileOwner.mProfileMaximumTimeOffMillis != 0 && !unlocked)) {
             // There profile is locked and there is a policy, but the deadline is not set -> set the
             // deadline.
             Slog.i(LOG_TAG, "Profile off deadline is set.");
-            profileOwner.mProfileOffDeadline = now + profileOwner.mProfileMaximumTimeOff;
+            profileOwner.mProfileOffDeadline = now + profileOwner.mProfileMaximumTimeOffMillis;
             shouldSaveSettings = true;
         }
 
@@ -15828,7 +15838,7 @@
     }
 
     @Override
-    public void setManagedProfileMaximumTimeOff(ComponentName who, long timeoutMs) {
+    public void setManagedProfileMaximumTimeOff(ComponentName who, long timeoutMillis) {
         final int userId = mInjector.userHandleGetCallingUserId();
         synchronized (getLockObject()) {
             final ActiveAdmin admin = getActiveAdminForCallerLocked(who,
@@ -15837,10 +15847,10 @@
             // DO shouldn't be able to use this method.
             enforceProfileOwnerOfOrganizationOwnedDevice(admin);
             enforceHandlesCheckPolicyComplianceIntent(userId, admin.info.getPackageName());
-            if (admin.mProfileMaximumTimeOff == timeoutMs) {
+            if (admin.mProfileMaximumTimeOffMillis == timeoutMillis) {
                 return;
             }
-            admin.mProfileMaximumTimeOff = timeoutMs;
+            admin.mProfileMaximumTimeOffMillis = timeoutMillis;
             saveSettingsLocked(userId);
         }
 
@@ -15850,7 +15860,7 @@
         DevicePolicyEventLogger
                 .createEvent(DevicePolicyEnums.SET_MANAGED_PROFILE_MAXIMUM_TIME_OFF)
                 .setAdmin(who)
-                .setTimePeriod(timeoutMs)
+                .setTimePeriod(timeoutMillis)
                 .write();
     }
 
@@ -15874,7 +15884,7 @@
                     false /* parent */);
             // DO shouldn't be able to use this method.
             enforceProfileOwnerOfOrganizationOwnedDevice(admin);
-            return admin.mProfileMaximumTimeOff;
+            return admin.mProfileMaximumTimeOffMillis;
         }
     }
 
diff --git a/services/incremental/BinderIncrementalService.cpp b/services/incremental/BinderIncrementalService.cpp
index 3fcb57a..2dbbc5a 100644
--- a/services/incremental/BinderIncrementalService.cpp
+++ b/services/incremental/BinderIncrementalService.cpp
@@ -178,15 +178,9 @@
     nfp.size = params.size;
     nfp.metadata = {(const char*)params.metadata.data(), (IncFsSize)params.metadata.size()};
     if (!params.signature) {
-        nfp.verification = {};
+        nfp.signature = {};
     } else {
-        nfp.verification.hashAlgorithm = IncFsHashAlgortithm(params.signature->hashAlgorithm);
-        nfp.verification.rootHash = {(const char*)params.signature->rootHash.data(),
-                                     (IncFsSize)params.signature->rootHash.size()};
-        nfp.verification.additionalData = {(const char*)params.signature->additionalData.data(),
-                                           (IncFsSize)params.signature->additionalData.size()};
-        nfp.verification.signature = {(const char*)params.signature->signature.data(),
-                                      (IncFsSize)params.signature->signature.size()};
+        nfp.signature = {(const char*)params.signature->data(), (IncFsSize)params.signature->size()};
     }
     return {0, id, nfp};
 }
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp
index cccd0133..7275936 100644
--- a/services/incremental/IncrementalService.cpp
+++ b/services/incremental/IncrementalService.cpp
@@ -1155,7 +1155,7 @@
         // Create new lib file without signature info
         incfs::NewFileParams libFileParams{};
         libFileParams.size = uncompressedLen;
-        libFileParams.verification.hashAlgorithm = INCFS_HASH_NONE;
+        libFileParams.signature = {};
         // Metadata of the new lib file is its relative path
         IncFsSpan libFileMetadata;
         libFileMetadata.data = targetLibPath.c_str();
diff --git a/services/net/Android.bp b/services/net/Android.bp
index dbc2df8..c54102f 100644
--- a/services/net/Android.bp
+++ b/services/net/Android.bp
@@ -20,6 +20,44 @@
     ],
 }
 
+// Version of services.net for usage by the wifi mainline module.
+// Note: This is compiled against module_current.
+// TODO(b/145825329): This should be moved to networkstack-client,
+// with dependencies moved to frameworks/libs/net right.
+java_library {
+    name: "services.net-module-wifi",
+    srcs: [
+        ":framework-services-net-module-wifi-shared-srcs",
+        ":net-module-utils-srcs",
+        "java/android/net/ip/IpClientCallbacks.java",
+        "java/android/net/ip/IpClientManager.java",
+        "java/android/net/ip/IpClientUtil.java",
+        "java/android/net/util/KeepalivePacketDataUtil.java",
+        "java/android/net/util/NetworkConstants.java",
+        "java/android/net/IpMemoryStore.java",
+        "java/android/net/NetworkMonitorManager.java",
+        "java/android/net/TcpKeepalivePacketData.java",
+    ],
+    sdk_version: "module_current",
+    libs: [
+        "unsupportedappusage",
+    ],
+    static_libs: [
+        "dnsresolver_aidl_interface-V2-java",
+        "netd_aidl_interface-unstable-java",
+        "netlink-client",
+        "networkstack-client",
+        "net-utils-services-common",
+    ],
+    apex_available: [
+        "com.android.wifi",
+    ],
+    visibility: [
+        "//frameworks/opt/net/wifi/service",
+        "//frameworks/opt/net/wifi/tests/wifitests",
+    ],
+}
+
 filegroup {
     name: "services-tethering-shared-srcs",
     srcs: [
diff --git a/services/net/java/android/net/IpMemoryStore.java b/services/net/java/android/net/IpMemoryStore.java
index dcefb53..8df2e0d 100644
--- a/services/net/java/android/net/IpMemoryStore.java
+++ b/services/net/java/android/net/IpMemoryStore.java
@@ -18,6 +18,7 @@
 
 import android.annotation.NonNull;
 import android.content.Context;
+import android.net.networkstack.ModuleNetworkStackClient;
 import android.util.Log;
 
 import com.android.internal.annotations.VisibleForTesting;
@@ -41,7 +42,7 @@
         super(context);
         mService = new CompletableFuture<>();
         mTailNode = new AtomicReference<CompletableFuture<IIpMemoryStore>>(mService);
-        getNetworkStackClient().fetchIpMemoryStore(
+        getModuleNetworkStackClient(context).fetchIpMemoryStore(
                 new IIpMemoryStoreCallbacks.Stub() {
                     @Override
                     public void onIpMemoryStoreFetched(@NonNull final IIpMemoryStore memoryStore) {
@@ -85,8 +86,8 @@
     }
 
     @VisibleForTesting
-    protected NetworkStackClient getNetworkStackClient() {
-        return NetworkStackClient.getInstance();
+    protected ModuleNetworkStackClient getModuleNetworkStackClient(Context context) {
+        return ModuleNetworkStackClient.getInstance(context);
     }
 
     /** Gets an instance of the memory store */
diff --git a/services/net/java/android/net/TcpKeepalivePacketData.java b/services/net/java/android/net/TcpKeepalivePacketData.java
index aad75ae..fcf3a56 100644
--- a/services/net/java/android/net/TcpKeepalivePacketData.java
+++ b/services/net/java/android/net/TcpKeepalivePacketData.java
@@ -74,6 +74,19 @@
         ipTtl = tcpDetails.ttl;
     }
 
+    private TcpKeepalivePacketData(final InetAddress srcAddress, int srcPort,
+            final InetAddress dstAddress, int dstPort, final byte[] data, int tcpSeq,
+            int tcpAck, int tcpWnd, int tcpWndScale, int ipTos, int ipTtl)
+            throws InvalidPacketException {
+        super(srcAddress, srcPort, dstAddress, dstPort, data);
+        this.tcpSeq = tcpSeq;
+        this.tcpAck = tcpAck;
+        this.tcpWnd = tcpWnd;
+        this.tcpWndScale = tcpWndScale;
+        this.ipTos = ipTos;
+        this.ipTtl = ipTtl;
+    }
+
     /**
      * Factory method to create tcp keepalive packet structure.
      */
@@ -169,7 +182,11 @@
 
     /** Write to parcel. */
     public void writeToParcel(Parcel out, int flags) {
-        super.writeToParcel(out, flags);
+        out.writeString(srcAddress.getHostAddress());
+        out.writeString(dstAddress.getHostAddress());
+        out.writeInt(srcPort);
+        out.writeInt(dstPort);
+        out.writeByteArray(getPacket());
         out.writeInt(tcpSeq);
         out.writeInt(tcpAck);
         out.writeInt(tcpWnd);
@@ -178,21 +195,32 @@
         out.writeInt(ipTtl);
     }
 
-    private TcpKeepalivePacketData(Parcel in) {
-        super(in);
-        tcpSeq = in.readInt();
-        tcpAck = in.readInt();
-        tcpWnd = in.readInt();
-        tcpWndScale = in.readInt();
-        ipTos = in.readInt();
-        ipTtl = in.readInt();
+    private static TcpKeepalivePacketData readFromParcel(Parcel in) throws InvalidPacketException {
+        InetAddress srcAddress = InetAddresses.parseNumericAddress(in.readString());
+        InetAddress dstAddress = InetAddresses.parseNumericAddress(in.readString());
+        int srcPort = in.readInt();
+        int dstPort = in.readInt();
+        byte[] packet = in.createByteArray();
+        int tcpSeq = in.readInt();
+        int tcpAck = in.readInt();
+        int tcpWnd = in.readInt();
+        int tcpWndScale = in.readInt();
+        int ipTos = in.readInt();
+        int ipTtl = in.readInt();
+        return new TcpKeepalivePacketData(srcAddress, srcPort, dstAddress, dstPort, packet, tcpSeq,
+                tcpAck, tcpWnd, tcpWndScale, ipTos, ipTtl);
     }
 
     /** Parcelable Creator. */
     public static final @NonNull Parcelable.Creator<TcpKeepalivePacketData> CREATOR =
             new Parcelable.Creator<TcpKeepalivePacketData>() {
                 public TcpKeepalivePacketData createFromParcel(Parcel in) {
-                    return new TcpKeepalivePacketData(in);
+                    try {
+                        return readFromParcel(in);
+                    } catch (InvalidPacketException e) {
+                        throw new IllegalArgumentException(
+                                "Invalid NAT-T keepalive data: " + e.error);
+                    }
                 }
 
                 public TcpKeepalivePacketData[] newArray(int size) {
diff --git a/services/net/java/android/net/ip/IpClientUtil.java b/services/net/java/android/net/ip/IpClientUtil.java
index a3618b4..b329aee 100644
--- a/services/net/java/android/net/ip/IpClientUtil.java
+++ b/services/net/java/android/net/ip/IpClientUtil.java
@@ -22,7 +22,7 @@
 import android.net.DhcpResultsParcelable;
 import android.net.Layer2PacketParcelable;
 import android.net.LinkProperties;
-import android.net.NetworkStackClient;
+import android.net.networkstack.ModuleNetworkStackClient;
 import android.os.ConditionVariable;
 
 import java.io.FileDescriptor;
@@ -75,11 +75,11 @@
      *
      * <p>This is a convenience method to allow clients to use {@link IpClientCallbacks} instead of
      * {@link IIpClientCallbacks}.
-     * @see {@link NetworkStackClient#makeIpClient(String, IIpClientCallbacks)}
+     * @see {@link ModuleNetworkStackClient#makeIpClient(String, IIpClientCallbacks)}
      */
     public static void makeIpClient(Context context, String ifName, IpClientCallbacks callback) {
-        // TODO: migrate clients and remove context argument
-        NetworkStackClient.getInstance().makeIpClient(ifName, new IpClientCallbacksProxy(callback));
+        ModuleNetworkStackClient.getInstance(context)
+                .makeIpClient(ifName, new IpClientCallbacksProxy(callback));
     }
 
     /**
diff --git a/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java b/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java
index c94bb87..5c82200 100644
--- a/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/RescuePartyTest.java
@@ -79,6 +79,7 @@
     private static final String CALLING_PACKAGE2 = "com.package.name2";
     private static final String NAMESPACE1 = "namespace1";
     private static final String NAMESPACE2 = "namespace2";
+    private static final String DISABLE_RESCUE_PARTY_FLAG = "disable_rescue_party";
 
     private MockitoSession mSession;
     private HashMap<String, String> mSystemSettingsMap;
@@ -316,6 +317,13 @@
 
     @Test
     public void testExplicitlyEnablingAndDisablingRescue() {
+        // mock the DeviceConfig get call to avoid hitting
+        // android.permission.READ_DEVICE_CONFIG when calling real DeviceConfig.
+        doReturn(true)
+                .when(() -> DeviceConfig.getBoolean(
+                    eq(DeviceConfig.NAMESPACE_CONFIGURATION),
+                    eq(DISABLE_RESCUE_PARTY_FLAG),
+                    eq(false)));
         SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(false));
         SystemProperties.set(PROP_DISABLE_RESCUE, Boolean.toString(true));
         assertEquals(RescuePartyObserver.getInstance(mMockContext).execute(sFailingPackage,
@@ -327,6 +335,22 @@
     }
 
     @Test
+    public void testDisablingRescueByDeviceConfigFlag() {
+        doReturn(true)
+                .when(() -> DeviceConfig.getBoolean(
+                    eq(DeviceConfig.NAMESPACE_CONFIGURATION),
+                    eq(DISABLE_RESCUE_PARTY_FLAG),
+                    eq(false)));
+        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(false));
+
+        assertEquals(RescuePartyObserver.getInstance(mMockContext).execute(sFailingPackage,
+                PackageWatchdog.FAILURE_REASON_APP_NOT_RESPONDING), false);
+
+        // Restore the property value initalized in SetUp()
+        SystemProperties.set(RescueParty.PROP_ENABLE_RESCUE, Boolean.toString(true));
+    }
+
+    @Test
     public void testHealthCheckLevels() {
         RescuePartyObserver observer = RescuePartyObserver.getInstance(mMockContext);
 
diff --git a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
index 959dc05..de6f55b 100644
--- a/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
+++ b/services/tests/mockingservicestests/src/com/android/server/appop/AppOpsServiceTest.java
@@ -147,7 +147,7 @@
         AndroidPackage mockMyPkg = mock(AndroidPackage.class);
         when(mockMyPkg.isPrivileged()).thenReturn(false);
         when(mockMyPkg.getUid()).thenReturn(mMyUid);
-        when(mockMyPkg.getFeatures()).thenReturn(Collections.emptyList());
+        when(mockMyPkg.getAttributions()).thenReturn(Collections.emptyList());
 
         when(mockPackageManagerInternal.getPackage(sMyPackageName)).thenReturn(mockMyPkg);
         doReturn(mockPackageManagerInternal).when(
diff --git a/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java b/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java
index 164ee31..3ad9054 100644
--- a/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java
@@ -182,7 +182,8 @@
                 eq(0),
                 anyBoolean() /* requireConfirmation */,
                 anyInt() /* userId */,
-                eq(TEST_PACKAGE_NAME));
+                eq(TEST_PACKAGE_NAME),
+                anyLong() /* sessionId */);
     }
 
     @Test
@@ -264,7 +265,8 @@
                 eq(BiometricAuthenticator.TYPE_FACE),
                 eq(false) /* requireConfirmation */,
                 anyInt() /* userId */,
-                eq(TEST_PACKAGE_NAME));
+                eq(TEST_PACKAGE_NAME),
+                anyLong() /* sessionId */);
     }
 
     @Test
@@ -391,7 +393,8 @@
                 eq(BiometricAuthenticator.TYPE_FINGERPRINT),
                 anyBoolean() /* requireConfirmation */,
                 anyInt() /* userId */,
-                eq(TEST_PACKAGE_NAME));
+                eq(TEST_PACKAGE_NAME),
+                anyLong() /* sessionId */);
 
         // Hardware authenticated
         mBiometricService.mInternalReceiver.onAuthenticationSucceeded(
@@ -406,7 +409,8 @@
 
         // SystemUI sends callback with dismissed reason
         mBiometricService.mInternalReceiver.onDialogDismissed(
-                BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED);
+                BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED,
+                null /* credentialAttestation */);
         waitForIdle();
         // HAT sent to keystore
         verify(mBiometricService.mKeyStore).addAuthToken(any(byte[].class));
@@ -438,7 +442,8 @@
                 eq(0 /* biometricModality */),
                 anyBoolean() /* requireConfirmation */,
                 anyInt() /* userId */,
-                eq(TEST_PACKAGE_NAME));
+                eq(TEST_PACKAGE_NAME),
+                anyLong() /* sessionId */);
     }
 
     @Test
@@ -460,7 +465,8 @@
 
         // SystemUI sends confirm, HAT is sent to keystore and client is notified.
         mBiometricService.mInternalReceiver.onDialogDismissed(
-                BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED);
+                BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED,
+                null /* credentialAttestation */);
         waitForIdle();
         verify(mBiometricService.mKeyStore).addAuthToken(any(byte[].class));
         verify(mReceiver1).onAuthenticationSucceeded(
@@ -567,7 +573,8 @@
                 anyInt(),
                 anyBoolean() /* requireConfirmation */,
                 anyInt() /* userId */,
-                anyString());
+                anyString(),
+                anyLong() /* sessionId */);
     }
 
     @Test
@@ -627,8 +634,8 @@
         verify(mReceiver1, never()).onError(anyInt(), anyInt(), anyInt());
 
         // SystemUI animation completed, client is notified, auth session is over
-        mBiometricService.mInternalReceiver
-                .onDialogDismissed(BiometricPrompt.DISMISSED_REASON_ERROR);
+        mBiometricService.mInternalReceiver.onDialogDismissed(
+                BiometricPrompt.DISMISSED_REASON_ERROR, null /* credentialAttestation */);
         waitForIdle();
         verify(mReceiver1).onError(
                 eq(BiometricAuthenticator.TYPE_FINGERPRINT),
@@ -667,7 +674,8 @@
                 eq(0 /* biometricModality */),
                 anyBoolean() /* requireConfirmation */,
                 anyInt() /* userId */,
-                eq(TEST_PACKAGE_NAME));
+                eq(TEST_PACKAGE_NAME),
+                anyLong() /* sessionId */);
     }
 
     @Test
@@ -825,8 +833,8 @@
         invokeAuthenticateAndStart(mBiometricService.mImpl, mReceiver1,
                 false /* requireConfirmation */, null /* authenticators */);
 
-        mBiometricService.mInternalReceiver
-                .onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
+        mBiometricService.mInternalReceiver.onDialogDismissed(
+                BiometricPrompt.DISMISSED_REASON_USER_CANCEL, null /* credentialAttestation */);
         waitForIdle();
         verify(mReceiver1).onError(
                 eq(BiometricAuthenticator.TYPE_FINGERPRINT),
@@ -854,7 +862,7 @@
                 BiometricConstants.BIOMETRIC_ERROR_TIMEOUT,
                 0 /* vendorCode */);
         mBiometricService.mInternalReceiver.onDialogDismissed(
-                BiometricPrompt.DISMISSED_REASON_NEGATIVE);
+                BiometricPrompt.DISMISSED_REASON_NEGATIVE, null /* credentialAttestation */);
         waitForIdle();
 
         verify(mBiometricService.mAuthenticators.get(0).impl,
@@ -880,7 +888,7 @@
                 BiometricConstants.BIOMETRIC_ERROR_TIMEOUT,
                 0 /* vendorCode */);
         mBiometricService.mInternalReceiver.onDialogDismissed(
-                BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
+                BiometricPrompt.DISMISSED_REASON_USER_CANCEL, null /* credentialAttestation */);
         waitForIdle();
 
         verify(mBiometricService.mAuthenticators.get(0).impl,
@@ -903,7 +911,7 @@
                 true /* requireConfirmation */,
                 new byte[69] /* HAT */);
         mBiometricService.mInternalReceiver.onDialogDismissed(
-                BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
+                BiometricPrompt.DISMISSED_REASON_USER_CANCEL, null /* credentialAttestation */);
         waitForIdle();
 
         // doesn't send cancel to HAL
@@ -1160,7 +1168,8 @@
                 eq(BiometricAuthenticator.TYPE_FINGERPRINT /* biometricModality */),
                 anyBoolean() /* requireConfirmation */,
                 anyInt() /* userId */,
-                eq(TEST_PACKAGE_NAME));
+                eq(TEST_PACKAGE_NAME),
+                anyLong() /* sessionId */);
 
         // Requesting strong and credential, when credential is setup
         resetReceiver();
@@ -1179,7 +1188,8 @@
                 eq(BiometricAuthenticator.TYPE_NONE /* biometricModality */),
                 anyBoolean() /* requireConfirmation */,
                 anyInt() /* userId */,
-                eq(TEST_PACKAGE_NAME));
+                eq(TEST_PACKAGE_NAME),
+                anyLong() /* sessionId */);
 
         // Un-downgrading the authenticator allows successful strong auth
         for (BiometricService.AuthenticatorWrapper wrapper : mBiometricService.mAuthenticators) {
@@ -1201,7 +1211,8 @@
                 eq(BiometricAuthenticator.TYPE_FINGERPRINT /* biometricModality */),
                 anyBoolean() /* requireConfirmation */,
                 anyInt() /* userId */,
-                eq(TEST_PACKAGE_NAME));
+                eq(TEST_PACKAGE_NAME),
+                anyLong() /* sessionId */);
     }
 
     @Test(expected = IllegalStateException.class)
diff --git a/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java b/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java
index 2944643..8be9213 100644
--- a/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java
+++ b/services/tests/servicestests/src/com/android/server/compat/CompatConfigTest.java
@@ -251,6 +251,28 @@
     }
 
     @Test
+    public void testAllowRemoveOverrideNoOverride() throws Exception {
+        CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
+                .addDisabledChangeWithId(1234L)
+                .addLoggingOnlyChangeWithId(2L)
+                .build();
+        ApplicationInfo applicationInfo = ApplicationInfoBuilder.create()
+                .withPackageName("com.some.package")
+                .build();
+        when(mPackageManager.getApplicationInfo(eq("com.some.package"), anyInt()))
+                .thenReturn(applicationInfo);
+
+        // Reject all override attempts.
+        // Force the validator to prevent overriding the change by using a user build.
+        when(mBuildClassifier.isDebuggableBuild()).thenReturn(false);
+        when(mBuildClassifier.isFinalBuild()).thenReturn(true);
+        // Try to remove a non existing override, and it doesn't fail.
+        assertThat(compatConfig.removeOverride(1234L, "com.some.package")).isFalse();
+        assertThat(compatConfig.removeOverride(2L, "com.some.package")).isFalse();
+        compatConfig.removePackageOverrides("com.some.package");
+    }
+
+    @Test
     public void testRemovePackageOverride() throws Exception {
         CompatConfig compatConfig = CompatConfigBuilder.create(mBuildClassifier, mContext)
                 .addEnabledChangeWithId(1234L)
diff --git a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
index 2a6a24e..7571f09 100644
--- a/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
+++ b/services/tests/servicestests/src/com/android/server/devicepolicy/DevicePolicyManagerTest.java
@@ -3872,79 +3872,80 @@
             Settings.System.SCREEN_BRIGHTNESS, "0", DpmMockContext.CALLER_USER_HANDLE);
     }
 
-    public void testSetAutoTimeModifiesSetting() throws Exception {
+    public void testSetAutoTimeEnabledModifiesSetting() throws Exception {
         mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
         setupDeviceOwner();
-        dpm.setAutoTime(admin1, true);
+        dpm.setAutoTimeEnabled(admin1, true);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 1);
 
-        dpm.setAutoTime(admin1, false);
+        dpm.setAutoTimeEnabled(admin1, false);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 0);
     }
 
-    public void testSetAutoTimeWithPOOnUser0() throws Exception {
+    public void testSetAutoTimeEnabledWithPOOnUser0() throws Exception {
         mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
         setupProfileOwnerOnUser0();
-        dpm.setAutoTime(admin1, true);
+        dpm.setAutoTimeEnabled(admin1, true);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 1);
 
-        dpm.setAutoTime(admin1, false);
+        dpm.setAutoTimeEnabled(admin1, false);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 0);
     }
 
-    public void testSetAutoTimeFailWithPONotOnUser0() throws Exception {
+    public void testSetAutoTimeEnabledFailWithPONotOnUser0() throws Exception {
         setupProfileOwner();
-        assertExpectException(SecurityException.class, null, () -> dpm.setAutoTime(admin1, false));
+        assertExpectException(SecurityException.class, null,
+                () -> dpm.setAutoTimeEnabled(admin1, false));
         verify(getServices().settings, never()).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 0);
     }
 
-    public void testSetAutoTimeWithPOOfOrganizationOwnedDevice() throws Exception {
+    public void testSetAutoTimeEnabledWithPOOfOrganizationOwnedDevice() throws Exception {
         setupProfileOwner();
         configureProfileOwnerOfOrgOwnedDevice(admin1, DpmMockContext.CALLER_USER_HANDLE);
 
-        dpm.setAutoTime(admin1, true);
+        dpm.setAutoTimeEnabled(admin1, true);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 1);
 
-        dpm.setAutoTime(admin1, false);
+        dpm.setAutoTimeEnabled(admin1, false);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME, 0);
     }
 
-    public void testSetAutoTimeZoneModifiesSetting() throws Exception {
+    public void testSetAutoTimeZoneEnabledModifiesSetting() throws Exception {
         mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
         setupDeviceOwner();
-        dpm.setAutoTimeZone(admin1, true);
+        dpm.setAutoTimeZoneEnabled(admin1, true);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 1);
 
-        dpm.setAutoTimeZone(admin1, false);
+        dpm.setAutoTimeZoneEnabled(admin1, false);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 0);
     }
 
-    public void testSetAutoTimeZoneWithPOOnUser0() throws Exception {
+    public void testSetAutoTimeZoneEnabledWithPOOnUser0() throws Exception {
         mContext.binder.callingUid = DpmMockContext.CALLER_SYSTEM_USER_UID;
         setupProfileOwnerOnUser0();
-        dpm.setAutoTimeZone(admin1, true);
+        dpm.setAutoTimeZoneEnabled(admin1, true);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 1);
 
-        dpm.setAutoTimeZone(admin1, false);
+        dpm.setAutoTimeZoneEnabled(admin1, false);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 0);
     }
 
-    public void testSetAutoTimeZoneFailWithPONotOnUser0() throws Exception {
+    public void testSetAutoTimeZoneEnabledFailWithPONotOnUser0() throws Exception {
         setupProfileOwner();
         assertExpectException(SecurityException.class, null,
-                () -> dpm.setAutoTimeZone(admin1, false));
+                () -> dpm.setAutoTimeZoneEnabled(admin1, false));
         verify(getServices().settings, never()).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE,
                 0);
     }
 
-    public void testSetAutoTimeZoneWithPOOfOrganizationOwnedDevice() throws Exception {
+    public void testSetAutoTimeZoneEnabledWithPOOfOrganizationOwnedDevice() throws Exception {
         setupProfileOwner();
         configureProfileOwnerOfOrgOwnedDevice(admin1, DpmMockContext.CALLER_USER_HANDLE);
 
-        dpm.setAutoTimeZone(admin1, true);
+        dpm.setAutoTimeZoneEnabled(admin1, true);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 1);
 
-        dpm.setAutoTimeZone(admin1, false);
+        dpm.setAutoTimeZoneEnabled(admin1, false);
         verify(getServices().settings).settingsGlobalPutInt(Settings.Global.AUTO_TIME_ZONE, 0);
     }
 
diff --git a/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java b/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java
index 3dd1504..81545d4 100644
--- a/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java
+++ b/services/tests/servicestests/src/com/android/server/integrity/AppIntegrityManagerServiceImplTest.java
@@ -28,6 +28,7 @@
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyInt;
@@ -321,6 +322,11 @@
         // we cannot check installer cert because it seems to be device specific.
         assertEquals(VERSION_CODE, appInstallMetadata.getVersionCode());
         assertFalse(appInstallMetadata.isPreInstalled());
+        // Asserting source stamp not present.
+        assertFalse(appInstallMetadata.isStampPresent());
+        assertFalse(appInstallMetadata.isStampVerified());
+        assertFalse(appInstallMetadata.isStampTrusted());
+        assertNull(appInstallMetadata.getStampCertificateHash());
         // These are hardcoded in the test apk android manifest
         Map<String, String> allowedInstallers =
                 appInstallMetadata.getAllowedInstallersAndCertificates();
diff --git a/services/tests/wmtests/src/com/android/server/wm/LaunchParamsPersisterTests.java b/services/tests/wmtests/src/com/android/server/wm/LaunchParamsPersisterTests.java
index 12d89de..8f3ff52 100644
--- a/services/tests/wmtests/src/com/android/server/wm/LaunchParamsPersisterTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/LaunchParamsPersisterTests.java
@@ -37,8 +37,8 @@
 import android.os.UserHandle;
 import android.platform.test.annotations.Presubmit;
 
-import androidx.test.InstrumentationRegistry;
 import androidx.test.filters.MediumTest;
+import androidx.test.platform.app.InstrumentationRegistry;
 
 import com.android.server.LocalServices;
 import com.android.server.pm.PackageList;
@@ -72,6 +72,10 @@
             ComponentName.createRelative("com.android.foo", ".BarActivity");
     private static final ComponentName ALTERNATIVE_COMPONENT =
             ComponentName.createRelative("com.android.foo", ".AlternativeBarActivity");
+    private static final String TEST_WINDOW_LAYOUT_AFFINITY = "135:.Affinity";
+    private static final String TEST_ALTERNATIVE_WINDOW_LAYOUT_AFFINITY =
+            "246:.AlternativeAffinity";
+    private static final String TEST_DIFFERENT_AFFINITY_WITH_SAME_UID = "135:.DifferentAffinity";
 
     private static final int TEST_WINDOWING_MODE = WINDOWING_MODE_FREEFORM;
     private static final Rect TEST_BOUNDS = new Rect(100, 200, 300, 400);
@@ -99,11 +103,12 @@
     public void setUp() throws Exception {
         mPersisterQueue = new TestPersisterQueue();
 
-        final File cacheFolder = InstrumentationRegistry.getContext().getCacheDir();
+        final File cacheFolder =
+                InstrumentationRegistry.getInstrumentation().getContext().getCacheDir();
         mFolder = new File(cacheFolder, "launch_params_tests");
         deleteRecursively(mFolder);
 
-        mDisplayUniqueId = "test:" + Integer.toString(sNextUniqueId++);
+        mDisplayUniqueId = "test:" + sNextUniqueId++;
         mTestDisplay = new TestDisplayContent.Builder(mService, 1000, 1500)
                 .setUniqueId(mDisplayUniqueId).build();
         when(mRootWindowContainer.getDisplayContent(eq(mDisplayUniqueId)))
@@ -211,6 +216,61 @@
     }
 
     @Test
+    public void testUsesRecordWithSameWindowLayoutAffinityInSameInstance_NoPreviousRecord() {
+        mTestTask.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.saveTask(mTestTask);
+
+        mTaskWithDifferentComponent.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.getLaunchParams(mTaskWithDifferentComponent, null, mResult);
+
+        assertEquals(mTestDisplay.mDisplayId, mResult.mPreferredDisplayId);
+        assertEquals(TEST_WINDOWING_MODE, mResult.mWindowingMode);
+        assertEquals(TEST_BOUNDS, mResult.mBounds);
+    }
+
+    @Test
+    public void testUsesRecordWithSameWindowLayoutAffinityInSameInstance_HasOldPreviousRecord()
+            throws Exception {
+        mTaskWithDifferentComponent.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.saveTask(mTaskWithDifferentComponent);
+
+        Thread.sleep(1);  // Sleep 1ms so that the timestamp can for sure increase.
+
+        mTestTask.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.saveTask(mTestTask);
+
+        mTarget.getLaunchParams(mTaskWithDifferentComponent, null, mResult);
+
+        assertEquals(mTestDisplay.mDisplayId, mResult.mPreferredDisplayId);
+        assertEquals(TEST_WINDOWING_MODE, mResult.mWindowingMode);
+        assertEquals(TEST_BOUNDS, mResult.mBounds);
+    }
+
+    @Test
+    public void testReturnsEmptyLaunchParamsUidInLaunchAffinityMismatch() {
+        mTestTask.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.saveTask(mTestTask);
+
+        mTaskWithDifferentComponent.mWindowLayoutAffinity = TEST_DIFFERENT_AFFINITY_WITH_SAME_UID;
+        mResult.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
+        mTarget.getLaunchParams(mTaskWithDifferentComponent, null, mResult);
+
+        assertTrue("Result must be empty.", mResult.isEmpty());
+    }
+
+    @Test
+    public void testReturnsEmptyLaunchParamsWindowLayoutAffinityMismatch() {
+        mTestTask.affinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.saveTask(mTestTask);
+
+        mTaskWithDifferentComponent.mWindowLayoutAffinity = TEST_ALTERNATIVE_WINDOW_LAYOUT_AFFINITY;
+        mResult.mWindowingMode = WINDOWING_MODE_FULLSCREEN;
+        mTarget.getLaunchParams(mTaskWithDifferentComponent, null, mResult);
+
+        assertTrue("Result must be empty.", mResult.isEmpty());
+    }
+
+    @Test
     public void testSavesAndRestoresLaunchParamsAcrossInstances() {
         mTarget.saveTask(mTestTask);
         mPersisterQueue.flush();
@@ -228,6 +288,52 @@
     }
 
     @Test
+    public void testUsesRecordWithSameWindowLayoutAffinityAcrossInstances_NoPreviousRecord() {
+        mTestTask.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.saveTask(mTestTask);
+        mPersisterQueue.flush();
+
+        final LaunchParamsPersister target = new LaunchParamsPersister(mPersisterQueue, mSupervisor,
+                mUserFolderGetter);
+        target.onSystemReady();
+        target.onUnlockUser(TEST_USER_ID);
+
+        mTaskWithDifferentComponent.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        target.getLaunchParams(mTaskWithDifferentComponent, null, mResult);
+
+        assertEquals(mTestDisplay.mDisplayId, mResult.mPreferredDisplayId);
+        assertEquals(TEST_WINDOWING_MODE, mResult.mWindowingMode);
+        assertEquals(TEST_BOUNDS, mResult.mBounds);
+    }
+
+    @Test
+    public void testUsesRecordWithSameWindowLayoutAffinityAcrossInstances_HasOldPreviousRecord()
+            throws Exception {
+        mTaskWithDifferentComponent.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.saveTask(mTaskWithDifferentComponent);
+        mPersisterQueue.flush();
+
+        // Sleep 1s because many file systems only save last modified time as precise as 1s so we
+        // can for sure know the last modified time is different.
+        Thread.sleep(1000);
+
+        mTestTask.mWindowLayoutAffinity = TEST_WINDOW_LAYOUT_AFFINITY;
+        mTarget.saveTask(mTestTask);
+        mPersisterQueue.flush();
+
+        final LaunchParamsPersister target = new LaunchParamsPersister(mPersisterQueue, mSupervisor,
+                mUserFolderGetter);
+        target.onSystemReady();
+        target.onUnlockUser(TEST_USER_ID);
+
+        target.getLaunchParams(mTaskWithDifferentComponent, null, mResult);
+
+        assertEquals(mTestDisplay.mDisplayId, mResult.mPreferredDisplayId);
+        assertEquals(TEST_WINDOWING_MODE, mResult.mWindowingMode);
+        assertEquals(TEST_BOUNDS, mResult.mBounds);
+    }
+
+    @Test
     public void testClearsRecordsOfTheUserOnUserCleanUp() {
         mTarget.saveTask(mTestTask);
 
diff --git a/services/tests/wmtests/src/com/android/server/wm/TaskOrganizerTests.java b/services/tests/wmtests/src/com/android/server/wm/TaskOrganizerTests.java
index 251886a..19ed7a9 100644
--- a/services/tests/wmtests/src/com/android/server/wm/TaskOrganizerTests.java
+++ b/services/tests/wmtests/src/com/android/server/wm/TaskOrganizerTests.java
@@ -213,6 +213,16 @@
     }
 
     @Test
+    public void testRegisterTaskOrganizerWithExistingTasks() throws RemoteException {
+        final ActivityStack stack = createTaskStackOnDisplay(mDisplayContent);
+        final Task task = createTaskInStack(stack, 0 /* userId */);
+        stack.setWindowingMode(WINDOWING_MODE_PINNED);
+
+        final ITaskOrganizer organizer = registerMockOrganizer(WINDOWING_MODE_PINNED);
+        verify(organizer, times(1)).taskAppeared(any());
+    }
+
+    @Test
     public void testTaskTransaction() {
         removeGlobalMinSizeRestriction();
         final ActivityStack stack = new ActivityTestsBase.StackBuilder(mWm.mRoot)
diff --git a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
index ef9a73b..9d48955 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsDatabase.java
@@ -98,8 +98,7 @@
 
     // Persist versioned backup files.
     // Should be false, except when testing new versions
-    // STOPSHIP: b/139937606 this should be false on launch
-    static final boolean KEEP_BACKUP_DIR = true;
+    static final boolean KEEP_BACKUP_DIR = false;
 
     private static final String TAG = "UsageStatsDatabase";
     private static final boolean DEBUG = UsageStatsService.DEBUG;
@@ -412,6 +411,7 @@
         }
 
         if (mBackupsDir.exists() && !KEEP_BACKUP_DIR) {
+            mUpgradePerformed = true; // updated here to ensure that data is cleaned up
             deleteDirectory(mBackupsDir);
         }
     }
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java
index 0d1b352..bbe9851 100644
--- a/services/usage/java/com/android/server/usage/UsageStatsService.java
+++ b/services/usage/java/com/android/server/usage/UsageStatsService.java
@@ -137,8 +137,7 @@
     private static final File USAGE_STATS_LEGACY_DIR = new File(
             Environment.getDataSystemDirectory(), "usagestats");
     // For migration purposes, indicates whether to keep the legacy usage stats directory or not
-    // STOPSHIP: b/138323140 this should be false on launch
-    private static final boolean KEEP_LEGACY_DIR = true;
+    private static final boolean KEEP_LEGACY_DIR = false;
 
     private static final char TOKEN_DELIMITER = '/';
 
@@ -648,7 +647,7 @@
 
     private void deleteLegacyDir(int userId) {
         final File legacyUserDir = new File(USAGE_STATS_LEGACY_DIR, Integer.toString(userId));
-        if (!KEEP_LEGACY_DIR) {
+        if (!KEEP_LEGACY_DIR && legacyUserDir.exists()) {
             deleteRecursively(legacyUserDir);
             if (legacyUserDir.exists()) {
                 Slog.w(TAG, "Error occurred while attempting to delete legacy usage stats "
diff --git a/telecomm/java/android/telecom/TelecomManager.java b/telecomm/java/android/telecom/TelecomManager.java
index 2761127..1792256 100644
--- a/telecomm/java/android/telecom/TelecomManager.java
+++ b/telecomm/java/android/telecom/TelecomManager.java
@@ -937,8 +937,8 @@
      */
     public TelecomManager(Context context, ITelecomService telecomServiceImpl) {
         Context appContext = context.getApplicationContext();
-        if (appContext != null && Objects.equals(context.getFeatureId(),
-                appContext.getFeatureId())) {
+        if (appContext != null && Objects.equals(context.getAttributionTag(),
+                appContext.getAttributionTag())) {
             mContext = appContext;
         } else {
             mContext = context;
@@ -972,7 +972,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().getDefaultOutgoingPhoneAccount(uriScheme,
-                        mContext.getOpPackageName(), mContext.getFeatureId());
+                        mContext.getOpPackageName(), mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelecomService#getDefaultOutgoingPhoneAccount", e);
@@ -1170,7 +1170,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().getSelfManagedPhoneAccounts(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelecomService#getSelfManagedPhoneAccounts()", e);
@@ -1196,7 +1196,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().getCallCapablePhoneAccounts(includeDisabledAccounts,
-                        mContext.getOpPackageName(), mContext.getFeatureId());
+                        mContext.getOpPackageName(), mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelecomService#getCallCapablePhoneAccounts(" +
@@ -1500,7 +1500,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().isVoiceMailNumber(accountHandle, number,
-                        mContext.getOpPackageName(), mContext.getFeatureId());
+                        mContext.getOpPackageName(), mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException calling ITelecomService#isVoiceMailNumber.", e);
@@ -1522,7 +1522,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().getVoiceMailNumber(accountHandle,
-                        mContext.getOpPackageName(), mContext.getFeatureId());
+                        mContext.getOpPackageName(), mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException calling ITelecomService#hasVoiceMailNumber.", e);
@@ -1543,7 +1543,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().getLine1Number(accountHandle,
-                        mContext.getOpPackageName(), mContext.getFeatureId());
+                        mContext.getOpPackageName(), mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException calling ITelecomService#getLine1Number.", e);
@@ -1565,7 +1565,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().isInCall(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException calling isInCall().", e);
@@ -1591,7 +1591,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().isInManagedCall(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException calling isInManagedCall().", e);
@@ -1772,7 +1772,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().isTtySupported(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException attempting to get TTY supported state.", e);
@@ -1797,7 +1797,7 @@
         try {
             if (isServiceConnected()) {
                 return getTelecomService().getCurrentTtyMode(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "RemoteException attempting to get the current TTY mode.", e);
@@ -2027,7 +2027,7 @@
         if (service != null) {
             try {
                 service.showInCallScreen(showDialpad, mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             } catch (RemoteException e) {
                 Log.e(TAG, "Error calling ITelecomService#showCallScreen", e);
             }
@@ -2090,7 +2090,7 @@
             }
             try {
                 service.placeCall(address, extras == null ? new Bundle() : extras,
-                        mContext.getOpPackageName(), mContext.getFeatureId());
+                        mContext.getOpPackageName(), mContext.getAttributionTag());
             } catch (RemoteException e) {
                 Log.e(TAG, "Error calling ITelecomService#placeCall", e);
             }
diff --git a/telephony/java/android/telephony/CarrierConfigManager.java b/telephony/java/android/telephony/CarrierConfigManager.java
index c74043a..e2112a5 100755
--- a/telephony/java/android/telephony/CarrierConfigManager.java
+++ b/telephony/java/android/telephony/CarrierConfigManager.java
@@ -4162,7 +4162,7 @@
                 return null;
             }
             return loader.getConfigForSubIdWithFeature(subId, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             Rlog.e(TAG, "Error getting config for subId " + subId + ": "
                     + ex.toString());
diff --git a/telephony/java/android/telephony/NetworkService.java b/telephony/java/android/telephony/NetworkService.java
index 87d94bfd..c75de42 100644
--- a/telephony/java/android/telephony/NetworkService.java
+++ b/telephony/java/android/telephony/NetworkService.java
@@ -234,6 +234,9 @@
      * this method to facilitate the creation of {@link NetworkServiceProvider} instances. The system
      * will call this method after binding the network service for each active SIM slot id.
      *
+     * This methead is guaranteed to be invoked in {@link NetworkService}'s internal handler thread
+     * whose looper can be retrieved with {@link Looper.myLooper()} when override this method.
+     *
      * @param slotIndex SIM slot id the network service associated with.
      * @return Network service object. Null if failed to create the provider (e.g. invalid slot
      * index)
diff --git a/telephony/java/android/telephony/SubscriptionManager.java b/telephony/java/android/telephony/SubscriptionManager.java
index 5a840de..01a40f5 100644
--- a/telephony/java/android/telephony/SubscriptionManager.java
+++ b/telephony/java/android/telephony/SubscriptionManager.java
@@ -1144,7 +1144,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 subInfo = iSub.getActiveSubscriptionInfo(subId, mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -1178,7 +1178,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 result = iSub.getActiveSubscriptionInfoForIccId(iccId, mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -1212,7 +1212,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 result = iSub.getActiveSubscriptionInfoForSimSlotIndex(slotIndex,
-                        mContext.getOpPackageName(), mContext.getFeatureId());
+                        mContext.getOpPackageName(), mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -1236,7 +1236,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 result = iSub.getAllSubInfoList(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -1322,7 +1322,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 activeList = iSub.getActiveSubscriptionInfoList(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -1373,7 +1373,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 result = iSub.getAvailableSubscriptionInfoList(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -1491,7 +1491,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 result = iSub.getAllSubInfoCount(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -1520,7 +1520,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 result = iSub.getActiveSubInfoCount(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -2275,7 +2275,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 resultValue = iSub.getSubscriptionProperty(subId, propKey,
-                        context.getOpPackageName(), context.getFeatureId());
+                        context.getOpPackageName(), context.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -2439,7 +2439,7 @@
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
                 return iSub.isActiveSubId(subId, mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
         }
@@ -2702,13 +2702,14 @@
     @RequiresPermission(android.Manifest.permission.READ_PHONE_STATE)
     public @NonNull List<SubscriptionInfo> getOpportunisticSubscriptions() {
         String contextPkg = mContext != null ? mContext.getOpPackageName() : "<unknown>";
-        String contextFeature = mContext != null ? mContext.getFeatureId() : null;
+        String contextAttributionTag = mContext != null ? mContext.getAttributionTag() : null;
         List<SubscriptionInfo> subInfoList = null;
 
         try {
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
-                subInfoList = iSub.getOpportunisticSubscriptions(contextPkg, contextFeature);
+                subInfoList = iSub.getOpportunisticSubscriptions(contextPkg,
+                        contextAttributionTag);
             }
         } catch (RemoteException ex) {
             // ignore it
@@ -2947,7 +2948,7 @@
     public @NonNull List<SubscriptionInfo> getSubscriptionsInGroup(@NonNull ParcelUuid groupUuid) {
         Preconditions.checkNotNull(groupUuid, "groupUuid can't be null");
         String contextPkg = mContext != null ? mContext.getOpPackageName() : "<unknown>";
-        String contextFeature = mContext != null ? mContext.getFeatureId() : null;
+        String contextAttributionTag = mContext != null ? mContext.getAttributionTag() : null;
         if (VDBG) {
             logd("[getSubscriptionsInGroup]+ groupUuid:" + groupUuid);
         }
@@ -2956,7 +2957,8 @@
         try {
             ISub iSub = TelephonyManager.getSubscriptionService();
             if (iSub != null) {
-                result = iSub.getSubscriptionsInGroup(groupUuid, contextPkg, contextFeature);
+                result = iSub.getSubscriptionsInGroup(groupUuid, contextPkg,
+                        contextAttributionTag);
             } else {
                 if (!isSystemProcess()) {
                     throw new IllegalStateException("telephony service is null.");
diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java
index e84a87c..610ec5e 100644
--- a/telephony/java/android/telephony/TelephonyManager.java
+++ b/telephony/java/android/telephony/TelephonyManager.java
@@ -345,10 +345,10 @@
         mSubId = subId;
         Context appContext = context.getApplicationContext();
         if (appContext != null) {
-            if (Objects.equals(context.getFeatureId(), appContext.getFeatureId())) {
+            if (Objects.equals(context.getAttributionTag(), appContext.getAttributionTag())) {
                 mContext = appContext;
             } else {
-                mContext = appContext.createFeatureContext(context.getFeatureId());
+                mContext = appContext.createAttributionContext(context.getAttributionTag());
             }
         } else {
             mContext = context;
@@ -393,12 +393,12 @@
         }
     }
 
-    private String getFeatureId() {
+    private String getAttributionTag() {
         // For legacy reasons the TelephonyManager has API for getting
         // a static instance with no context set preventing us from
-        // getting the feature Id.
+        // getting the attribution tag.
         if (mContext != null) {
-            return mContext.getFeatureId();
+            return mContext.getAttributionTag();
         }
         return null;
     }
@@ -1896,7 +1896,7 @@
 
         try {
             return telephony.getDeviceSoftwareVersionForSlot(slotIndex, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -1938,7 +1938,7 @@
             if (telephony == null)
                 return null;
             return telephony.getDeviceIdWithFeature(mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -1983,7 +1983,7 @@
             if (info == null)
                 return null;
             return info.getDeviceIdForPhone(slotIndex, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -2041,7 +2041,7 @@
         if (telephony == null) return null;
 
         try {
-            return telephony.getImeiForSlot(slotIndex, getOpPackageName(), getFeatureId());
+            return telephony.getImeiForSlot(slotIndex, getOpPackageName(), getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -2135,7 +2135,8 @@
         if (telephony == null) return null;
 
         try {
-            String meid = telephony.getMeidForSlot(slotIndex, getOpPackageName(), getFeatureId());
+            String meid = telephony.getMeidForSlot(slotIndex, getOpPackageName(),
+                    getAttributionTag());
             if (TextUtils.isEmpty(meid)) {
                 Log.d(TAG, "getMeid: return null because MEID is not available");
                 return null;
@@ -2237,7 +2238,7 @@
             if (info == null)
                 return null;
             String nai = info.getNaiForSubscriber(subId, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
             if (Log.isLoggable(TAG, Log.VERBOSE)) {
                 Rlog.v(TAG, "Nai = " + nai);
             }
@@ -2271,7 +2272,7 @@
             }
 
             CellIdentity cellIdentity = telephony.getCellLocation(mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
             CellLocation cl = cellIdentity.asCellLocation();
             if (cl == null || cl.isEmpty()) {
                 Rlog.d(TAG, "getCellLocation returning null because CellLocation is empty or"
@@ -2355,7 +2356,7 @@
             if (telephony == null)
                 return null;
             return telephony.getNeighboringCellInfo(mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -2961,7 +2962,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.getNetworkTypeForSubscriber(subId, getOpPackageName(),
-                        getFeatureId());
+                        getAttributionTag());
             } else {
                 // This can happen when the ITelephony interface is not up yet.
                 return NETWORK_TYPE_UNKNOWN;
@@ -3026,7 +3027,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.getDataNetworkTypeForSubscriber(subId, getOpPackageName(),
-                        getFeatureId());
+                        getAttributionTag());
             } else {
                 // This can happen when the ITelephony interface is not up yet.
                 return NETWORK_TYPE_UNKNOWN;
@@ -3063,7 +3064,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.getVoiceNetworkTypeForSubscriber(subId, getOpPackageName(),
-                        getFeatureId());
+                        getAttributionTag());
             } else {
                 // This can happen when the ITelephony interface is not up yet.
                 return NETWORK_TYPE_UNKNOWN;
@@ -3849,7 +3850,7 @@
             if (info == null)
                 return null;
             return info.getIccSerialNumberForSubscriber(subId, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -3893,7 +3894,7 @@
             if (telephony == null)
                 return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
             return telephony.getLteOnCdmaModeForSubscriber(subId, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             // Assume no ICC card if remote exception which shouldn't happen
             return PhoneConstants.LTE_ON_CDMA_UNKNOWN;
@@ -4122,7 +4123,7 @@
             if (info == null)
                 return null;
             return info.getSubscriberIdForSubscriber(subId, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -4290,7 +4291,7 @@
             if (info == null)
                 return null;
             return info.getGroupIdLevel1ForSubscriber(getSubId(), mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -4314,7 +4315,7 @@
             if (info == null)
                 return null;
             return info.getGroupIdLevel1ForSubscriber(subId, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -4365,7 +4366,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null)
                 number = telephony.getLine1NumberForDisplay(subId, mContext.getOpPackageName(),
-                         mContext.getFeatureId());
+                         mContext.getAttributionTag());
         } catch (RemoteException ex) {
         } catch (NullPointerException ex) {
         }
@@ -4377,7 +4378,7 @@
             if (info == null)
                 return null;
             return info.getLine1NumberForSubscriber(subId, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -4456,7 +4457,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null)
                 alphaTag = telephony.getLine1AlphaTagForDisplay(subId,
-                        getOpPackageName(), getFeatureId());
+                        getOpPackageName(), getAttributionTag());
         } catch (RemoteException ex) {
         } catch (NullPointerException ex) {
         }
@@ -4468,7 +4469,7 @@
             if (info == null)
                 return null;
             return info.getLine1AlphaTagForSubscriber(subId, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -4498,7 +4499,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null)
                 return telephony.getMergedSubscriberIds(getSubId(), getOpPackageName(),
-                        getFeatureId());
+                        getAttributionTag());
         } catch (RemoteException ex) {
         } catch (NullPointerException ex) {
         }
@@ -4555,7 +4556,7 @@
             IPhoneSubInfo info = getSubscriberInfoService();
             if (info == null)
                 return null;
-            return info.getMsisdnForSubscriber(subId, getOpPackageName(), getFeatureId());
+            return info.getMsisdnForSubscriber(subId, getOpPackageName(), getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -4590,7 +4591,7 @@
             if (info == null)
                 return null;
             return info.getVoiceMailNumberForSubscriber(subId, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -4715,7 +4716,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.getVisualVoicemailPackageName(mContext.getOpPackageName(),
-                        getFeatureId(), getSubId());
+                        getAttributionTag(), getSubId());
             }
         } catch (RemoteException ex) {
         } catch (NullPointerException ex) {
@@ -5152,7 +5153,7 @@
             if (telephony == null)
                 return 0;
             return telephony.getVoiceMessageCountForSubscriber(subId, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             return 0;
         } catch (NullPointerException ex) {
@@ -5189,7 +5190,7 @@
             if (info == null)
                 return null;
             return info.getVoiceMailAlphaTagForSubscriber(subId, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -5572,7 +5573,7 @@
                 (TelephonyRegistryManager)
                         mContext.getSystemService(Context.TELEPHONY_REGISTRY_SERVICE);
         if (telephonyRegistry != null) {
-            telephonyRegistry.listenForSubscriber(mSubId, getOpPackageName(), getFeatureId(),
+            telephonyRegistry.listenForSubscriber(mSubId, getOpPackageName(), getAttributionTag(),
                     listener, events, notifyNow);
         } else {
             Rlog.w(TAG, "telephony registry not ready.");
@@ -5605,7 +5606,7 @@
             if (telephony == null)
                 return -1;
             return telephony.getCdmaEriIconIndexForSubscriber(subId, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             // the phone process is restarting.
             return -1;
@@ -5629,7 +5630,7 @@
             if (telephony == null)
                 return -1;
             return telephony.getCdmaEriIconModeForSubscriber(subId, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             // the phone process is restarting.
             return -1;
@@ -5661,7 +5662,7 @@
             if (telephony == null)
                 return null;
             return telephony.getCdmaEriTextForSubscriber(subId, getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             // the phone process is restarting.
             return null;
@@ -5753,7 +5754,7 @@
             ITelephony telephony = getITelephony();
             if (telephony == null)
                 return null;
-            return telephony.getAllCellInfo(getOpPackageName(), getFeatureId());
+            return telephony.getAllCellInfo(getOpPackageName(), getAttributionTag());
         } catch (RemoteException ex) {
         } catch (NullPointerException ex) {
         }
@@ -5853,7 +5854,7 @@
                                 Binder.restoreCallingIdentity(identity);
                             }
                         }
-                    }, getOpPackageName(), getFeatureId());
+                    }, getOpPackageName(), getAttributionTag());
         } catch (RemoteException ex) {
         }
     }
@@ -5904,7 +5905,7 @@
                                 Binder.restoreCallingIdentity(identity);
                             }
                         }
-                    }, getOpPackageName(), getFeatureId(), workSource);
+                    }, getOpPackageName(), getAttributionTag(), workSource);
         } catch (RemoteException ex) {
         }
     }
@@ -7190,7 +7191,7 @@
             if (telephony == null)
                 return null;
             return telephony.getForbiddenPlmns(subId, appType, mContext.getOpPackageName(),
-                    getFeatureId());
+                    getAttributionTag());
         } catch (RemoteException ex) {
             return null;
         } catch (NullPointerException ex) {
@@ -7224,7 +7225,7 @@
             ITelephony telephony = getITelephony();
             if (telephony == null) return -1;
             return telephony.setForbiddenPlmns(
-                    getSubId(), APPTYPE_USIM, fplmns, getOpPackageName(), getFeatureId());
+                    getSubId(), APPTYPE_USIM, fplmns, getOpPackageName(), getAttributionTag());
         } catch (RemoteException ex) {
             Rlog.e(TAG, "setForbiddenPlmns RemoteException: " + ex.getMessage());
         } catch (NullPointerException ex) {
@@ -7245,7 +7246,7 @@
             ITelephony telephony = getITelephony();
             if (telephony == null)
                 return new String[0];
-            return telephony.getPcscfAddress(apnType, getOpPackageName(), getFeatureId());
+            return telephony.getPcscfAddress(apnType, getOpPackageName(), getAttributionTag());
         } catch (RemoteException e) {
             return new String[0];
         }
@@ -7818,7 +7819,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.getCellNetworkScanResults(getSubId(), getOpPackageName(),
-                        getFeatureId());
+                        getAttributionTag());
             }
         } catch (RemoteException ex) {
             Rlog.e(TAG, "getAvailableNetworks RemoteException", ex);
@@ -7873,7 +7874,7 @@
             }
         }
         return mTelephonyScanManager.requestNetworkScan(getSubId(), request, executor, callback,
-                getOpPackageName(), getFeatureId());
+                getOpPackageName(), getAttributionTag());
     }
 
     /**
@@ -8627,7 +8628,7 @@
         try {
             ITelephony telephony = getITelephony();
             if (telephony != null)
-                return telephony.isRadioOnWithFeature(getOpPackageName(), getFeatureId());
+                return telephony.isRadioOnWithFeature(getOpPackageName(), getAttributionTag());
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelephony#isRadioOn", e);
         }
@@ -9001,7 +9002,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.getRadioPowerState(getSlotIndex(), mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             // This could happen if binder process crashes.
@@ -9392,7 +9393,7 @@
         try {
             ITelephony telephony = getITelephony();
             if (telephony != null)
-                return telephony.isVideoCallingEnabled(getOpPackageName(), getFeatureId());
+                return telephony.isVideoCallingEnabled(getOpPackageName(), getAttributionTag());
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelephony#isVideoCallingEnabled", e);
         }
@@ -9409,7 +9410,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.canChangeDtmfToneLength(mSubId, getOpPackageName(),
-                        getFeatureId());
+                        getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelephony#canChangeDtmfToneLength", e);
@@ -9428,7 +9429,7 @@
         try {
             ITelephony telephony = getITelephony();
             if (telephony != null) {
-                return telephony.isWorldPhone(mSubId, getOpPackageName(), getFeatureId());
+                return telephony.isWorldPhone(mSubId, getOpPackageName(), getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelephony#isWorldPhone", e);
@@ -10156,7 +10157,8 @@
             ITelephony service = getITelephony();
             if (service != null) {
                 retval = service.getSubIdForPhoneAccountHandle(
-                        phoneAccountHandle, mContext.getOpPackageName(), mContext.getFeatureId());
+                        phoneAccountHandle, mContext.getOpPackageName(),
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             Log.e(TAG, "getSubscriptionId RemoteException", ex);
@@ -10297,7 +10299,7 @@
             ITelephony service = getITelephony();
             if (service != null) {
                 return service.getServiceStateForSubscriber(subId, getOpPackageName(),
-                        getFeatureId());
+                        getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelephony#getServiceStateForSubscriber", e);
@@ -11018,7 +11020,8 @@
         try {
             ITelephony service = getITelephony();
             if (service != null) {
-                return service.getClientRequestStats(getOpPackageName(), getFeatureId(), subId);
+                return service.getClientRequestStats(getOpPackageName(), getAttributionTag(),
+                        subId);
             }
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling ITelephony#getClientRequestStats", e);
@@ -11304,7 +11307,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.getNumberOfModemsWithSimultaneousDataConnections(
-                        getSubId(), getOpPackageName(), getFeatureId());
+                        getSubId(), getOpPackageName(), getAttributionTag());
             }
         } catch (RemoteException ex) {
             // This could happen if binder process crashes.
@@ -11734,7 +11737,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.getEmergencyNumberList(mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             } else {
                 throw new IllegalStateException("telephony service is null.");
             }
@@ -11789,7 +11792,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 emergencyNumberList = telephony.getEmergencyNumberList(
-                        mContext.getOpPackageName(), mContext.getFeatureId());
+                        mContext.getOpPackageName(), mContext.getAttributionTag());
                 if (emergencyNumberList != null) {
                     for (Integer subscriptionId : emergencyNumberList.keySet()) {
                         List<EmergencyNumber> numberList = emergencyNumberList.get(subscriptionId);
@@ -12098,13 +12101,13 @@
     })
     public int getPreferredOpportunisticDataSubscription() {
         String packageName = mContext != null ? mContext.getOpPackageName() : "<unknown>";
-        String featureId = mContext != null ? mContext.getFeatureId() : null;
+        String attributionTag = mContext != null ? mContext.getAttributionTag() : null;
         int subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
         try {
             IOns iOpportunisticNetworkService = getIOns();
             if (iOpportunisticNetworkService != null) {
                 subId = iOpportunisticNetworkService.getPreferredDataSubscriptionId(
-                        packageName, featureId);
+                        packageName, attributionTag);
             }
         } catch (RemoteException ex) {
             Rlog.e(TAG, "getPreferredDataSubscriptionId RemoteException", ex);
@@ -12234,7 +12237,7 @@
             ITelephony telephony = getITelephony();
             if (telephony != null) {
                 return telephony.isModemEnabledForSlot(slotIndex, mContext.getOpPackageName(),
-                        mContext.getFeatureId());
+                        mContext.getAttributionTag());
             }
         } catch (RemoteException ex) {
             Log.e(TAG, "enableModem RemoteException", ex);
@@ -12339,7 +12342,7 @@
         try {
             ITelephony service = getITelephony();
             if (service != null) {
-                return service.isMultiSimSupported(getOpPackageName(), getFeatureId());
+                return service.isMultiSimSupported(getOpPackageName(), getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "isMultiSimSupported RemoteException", e);
@@ -12391,7 +12394,7 @@
             ITelephony service = getITelephony();
             if (service != null) {
                 return service.doesSwitchMultiSimConfigTriggerReboot(getSubId(),
-                        getOpPackageName(), getFeatureId());
+                        getOpPackageName(), getAttributionTag());
             }
         } catch (RemoteException e) {
             Log.e(TAG, "doesSwitchMultiSimConfigTriggerReboot RemoteException", e);
@@ -12460,7 +12463,6 @@
      * @throws {@link SecurityException} if the caller is not the system or phone process.
      * @hide
      */
-    @SystemApi
     @TestApi
     // TODO: add new permission tag indicating that this is system-only.
     public @NonNull List<ApnSetting> getDevicePolicyOverrideApns(@NonNull Context context) {
@@ -12491,7 +12493,6 @@
      * @throws {@link SecurityException} if the caller is not the system or phone process.
      * @hide
      */
-    @SystemApi
     @TestApi
     // TODO: add new permission tag indicating that this is system-only.
     public int addDevicePolicyOverrideApn(@NonNull Context context,
@@ -12522,7 +12523,6 @@
      * @throws {@link SecurityException} if the caller is not the system or phone process.
      * @hide
      */
-    @SystemApi
     @TestApi
     // TODO: add new permission tag indicating that this is system-only.
     public boolean modifyDevicePolicyOverrideApn(@NonNull Context context, int apnId,
diff --git a/telephony/java/android/telephony/data/DataService.java b/telephony/java/android/telephony/data/DataService.java
index 6c4e7ce..f56bbe1 100644
--- a/telephony/java/android/telephony/data/DataService.java
+++ b/telephony/java/android/telephony/data/DataService.java
@@ -458,6 +458,9 @@
      * this method to facilitate the creation of {@link DataServiceProvider} instances. The system
      * will call this method after binding the data service for each active SIM slot id.
      *
+     * This methead is guaranteed to be invoked in {@link DataService}'s internal handler thread
+     * whose looper can be retrieved with {@link Looper.myLooper()} when override this method.
+     *
      * @param slotIndex SIM slot id the data service associated with.
      * @return Data service object. Null if failed to create the provider (e.g. invalid slot index)
      */
diff --git a/telephony/java/android/telephony/ims/RcsUceAdapter.java b/telephony/java/android/telephony/ims/RcsUceAdapter.java
index 30306c7..05ab6bd 100644
--- a/telephony/java/android/telephony/ims/RcsUceAdapter.java
+++ b/telephony/java/android/telephony/ims/RcsUceAdapter.java
@@ -291,7 +291,7 @@
 
         try {
             imsRcsController.requestCapabilities(mSubId, mContext.getOpPackageName(),
-                    mContext.getFeatureId(), contactNumbers, internalCallback);
+                    mContext.getAttributionTag(), contactNumbers, internalCallback);
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling IImsRcsController#requestCapabilities", e);
             throw new ImsException("Remote IMS Service is not available",
@@ -352,7 +352,7 @@
         try {
             // Telephony.SimInfo#IMS_RCS_UCE_ENABLED can also be used to listen to changes to this.
             return imsRcsController.isUceSettingEnabled(mSubId, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException e) {
             Log.e(TAG, "Error calling IImsRcsController#isUceSettingEnabled", e);
             throw new ImsException("Remote IMS Service is not available",
diff --git a/telephony/java/android/telephony/ims/stub/ImsUtImplBase.java b/telephony/java/android/telephony/ims/stub/ImsUtImplBase.java
index f13371c..386a58e 100644
--- a/telephony/java/android/telephony/ims/stub/ImsUtImplBase.java
+++ b/telephony/java/android/telephony/ims/stub/ImsUtImplBase.java
@@ -44,52 +44,62 @@
 public class ImsUtImplBase {
     /**
      * Bar all incoming calls. (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_ALL_INCOMING = 1;
 
     /**
      * Bar all outgoing calls. (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_ALL_OUTGOING = 2;
 
     /**
      * Bar all outgoing international calls. (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_OUTGOING_INTL = 3;
 
     /**
      * Bar all outgoing international calls, excluding those to the home PLMN country
      * (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_OUTGOING_INTL_EXCL_HOME = 4;
 
     /**
      * Bar all incoming calls when roaming (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BLOCKING_INCOMING_WHEN_ROAMING = 5;
 
     /**
      * Enable Anonymous Communication Rejection (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_ANONYMOUS_INCOMING = 6;
 
     /**
      * Bar all incoming and outgoing calls. (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_ALL = 7;
 
     /**
      * Bar all outgoing service requests, including calls. (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_OUTGOING_ALL_SERVICES = 8;
 
     /**
      * Bar all incoming service requests, including calls. (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_INCOMING_ALL_SERVICES = 9;
 
     /**
      * Bar specific incoming calls. (See 3GPP TS 24.611)
+     * @hide
      */
     public static final int CALL_BARRING_SPECIFIC_INCOMING_CALLS = 10;
 
@@ -104,6 +114,7 @@
 
     /**
      * Constant used to denote an invalid return value.
+     * @hide
      */
     public static final int INVALID_RESULT = -1;
 
diff --git a/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java
index 5904916..c7e5a5e 100644
--- a/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java
+++ b/tests/MemoryUsage/src/com/android/tests/memoryusage/MemoryUsageTest.java
@@ -322,7 +322,7 @@
 
                 mAtm.startActivityAndWait(null,
                         getInstrumentation().getContext().getBasePackageName(),
-                        getInstrumentation().getContext().getFeatureId(), mLaunchIntent,
+                        getInstrumentation().getContext().getAttributionTag(), mLaunchIntent,
                         mimeType, null, null, 0, mLaunchIntent.getFlags(), null, null,
                         UserHandle.USER_CURRENT_OR_SELF);
             } catch (RemoteException e) {
diff --git a/tests/net/java/android/net/IpMemoryStoreTest.java b/tests/net/java/android/net/IpMemoryStoreTest.java
index b81ca36..442ac56 100644
--- a/tests/net/java/android/net/IpMemoryStoreTest.java
+++ b/tests/net/java/android/net/IpMemoryStoreTest.java
@@ -35,6 +35,7 @@
 import android.net.ipmemorystore.NetworkAttributes;
 import android.net.ipmemorystore.NetworkAttributesParcelable;
 import android.net.ipmemorystore.Status;
+import android.net.networkstack.ModuleNetworkStackClient;
 import android.os.RemoteException;
 
 import androidx.test.filters.SmallTest;
@@ -67,7 +68,7 @@
     @Mock
     Context mMockContext;
     @Mock
-    NetworkStackClient mNetworkStackClient;
+    ModuleNetworkStackClient mModuleNetworkStackClient;
     @Mock
     IIpMemoryStore mMockService;
     @Mock
@@ -90,14 +91,14 @@
                 ((IIpMemoryStoreCallbacks) invocation.getArgument(0))
                         .onIpMemoryStoreFetched(mMockService);
                 return null;
-            }).when(mNetworkStackClient).fetchIpMemoryStore(any());
+            }).when(mModuleNetworkStackClient).fetchIpMemoryStore(any());
         } else {
-            doNothing().when(mNetworkStackClient).fetchIpMemoryStore(mCbCaptor.capture());
+            doNothing().when(mModuleNetworkStackClient).fetchIpMemoryStore(mCbCaptor.capture());
         }
         mStore = new IpMemoryStore(mMockContext) {
             @Override
-            protected NetworkStackClient getNetworkStackClient() {
-                return mNetworkStackClient;
+            protected ModuleNetworkStackClient getModuleNetworkStackClient(Context ctx) {
+                return mModuleNetworkStackClient;
             }
         };
     }
diff --git a/tests/net/java/com/android/server/ConnectivityServiceTest.java b/tests/net/java/com/android/server/ConnectivityServiceTest.java
index 8c0c36b..6985415 100644
--- a/tests/net/java/com/android/server/ConnectivityServiceTest.java
+++ b/tests/net/java/com/android/server/ConnectivityServiceTest.java
@@ -23,8 +23,6 @@
 import static android.content.pm.PackageManager.MATCH_ANY_USER;
 import static android.content.pm.PackageManager.PERMISSION_DENIED;
 import static android.content.pm.PackageManager.PERMISSION_GRANTED;
-import static android.net.ConnectivityDiagnosticsManager.ConnectivityReport;
-import static android.net.ConnectivityDiagnosticsManager.DataStallReport;
 import static android.net.ConnectivityManager.ACTION_CAPTIVE_PORTAL_SIGN_IN;
 import static android.net.ConnectivityManager.CONNECTIVITY_ACTION;
 import static android.net.ConnectivityManager.CONNECTIVITY_ACTION_SUPL;
@@ -100,6 +98,7 @@
 import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.anyLong;
 import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.argThat;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.ArgumentMatchers.startsWith;
 import static org.mockito.Matchers.anyInt;
@@ -6870,8 +6869,13 @@
         HandlerUtilsKt.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
 
         // Verify onConnectivityReport fired
-        verify(mConnectivityDiagnosticsCallback)
-                .onConnectivityReport(any(ConnectivityReport.class));
+        verify(mConnectivityDiagnosticsCallback).onConnectivityReport(
+                argThat(report -> {
+                    final NetworkCapabilities nc = report.getNetworkCapabilities();
+                    return nc.getUids() == null
+                            && nc.getAdministratorUids().isEmpty()
+                            && nc.getOwnerUid() == Process.INVALID_UID;
+                }));
     }
 
     @Test
@@ -6886,7 +6890,13 @@
         HandlerUtilsKt.waitForIdle(mCsHandlerThread, TIMEOUT_MS);
 
         // Verify onDataStallSuspected fired
-        verify(mConnectivityDiagnosticsCallback).onDataStallSuspected(any(DataStallReport.class));
+        verify(mConnectivityDiagnosticsCallback).onDataStallSuspected(
+                argThat(report -> {
+                    final NetworkCapabilities nc = report.getNetworkCapabilities();
+                    return nc.getUids() == null
+                            && nc.getAdministratorUids().isEmpty()
+                            && nc.getOwnerUid() == Process.INVALID_UID;
+                }));
     }
 
     @Test
diff --git a/tools/aapt2/link/ManifestFixer.cpp b/tools/aapt2/link/ManifestFixer.cpp
index 5aa32f8..bcfce66 100644
--- a/tools/aapt2/link/ManifestFixer.cpp
+++ b/tools/aapt2/link/ManifestFixer.cpp
@@ -366,8 +366,12 @@
   });
   manifest_action["instrumentation"]["meta-data"] = meta_data_action;
 
+  // TODO moltmann: Remove
   manifest_action["feature"];
   manifest_action["feature"]["inherit-from"];
+
+  manifest_action["attribution"];
+  manifest_action["attribution"]["inherit-from"];
   manifest_action["original-package"];
   manifest_action["overlay"];
   manifest_action["protected-broadcast"];
diff --git a/wifi/jarjar-rules.txt b/wifi/jarjar-rules.txt
index 950361c..eeb006e 100644
--- a/wifi/jarjar-rules.txt
+++ b/wifi/jarjar-rules.txt
@@ -1,7 +1,32 @@
+# used by wifi-service
+rule android.net.DhcpResultsParcelable* @0
+rule android.net.DhcpResults* com.android.server.x.wifi.net.DhcpResults@1
 rule android.net.InterfaceConfigurationParcel* @0
 rule android.net.InterfaceConfiguration* com.android.server.x.wifi.net.InterfaceConfiguration@1
+rule android.net.IpMemoryStore* com.android.server.x.wifi.net.IpMemoryStore@1
+rule android.net.NetworkMonitorManager* com.android.server.x.wifi.net.NetworkMonitorManager@1
+rule android.net.TcpKeepalivePacketData* com.android.server.x.wifi.net.TcpKeepalivePacketData@1
 rule android.net.NetworkFactory* com.android.server.x.wifi.net.NetworkFactory@1
+rule android.net.ip.IpClientCallbacks* com.android.server.x.wifi.net.ip.IpClientCallbacks@1
+rule android.net.ip.IpClientManager* com.android.server.x.wifi.net.ip.IpClientManager@1
+rule android.net.ip.IpClientUtil* com.android.server.x.wifi.net.ip.IpClientUtil@1
+rule android.net.shared.InetAddressUtils* com.android.server.x.wifi.net.shared.InetAddressUtils@1
+rule android.net.shared.InitialConfiguration* com.android.server.x.wifi.net.shared.InitialConfiguration@1
+rule android.net.shared.IpConfigurationParcelableUtil* com.android.server.x.wifi.net.shared.IpConfigurationParcelableUtil@1
+rule android.net.shared.LinkPropertiesParcelableUtil* com.android.server.x.wifi.net.shared.LinkPropertiesParcelableUtil@1
+rule android.net.shared.ParcelableUtil* com.android.server.x.wifi.net.shared.ParcelableUtil@1
+rule android.net.shared.NetdUtils* com.android.server.x.wifi.net.shared.NetdUtils@1
+rule android.net.shared.NetworkMonitorUtils* com.android.server.x.wifi.net.shared.NetworkMonitorUtils@1
+rule android.net.shared.ParcelableUtil* com.android.server.x.wifi.net.shared.ParcelableUtil@1
+rule android.net.shared.PrivateDnsConfig* com.android.server.x.wifi.net.shared.PrivateDnsConfig@1
+rule android.net.shared.ProvisioningConfiguration* com.android.server.x.wifi.net.shared.ProvisioningConfiguration@1
+rule android.net.shared.RouteUtils* com.android.server.x.wifi.net.shared.RouteUtils@1
+rule android.net.util.KeepalivePacketDataUtil* com.android.server.x.wifi.net.util.KeepalivePacketDataUtil@1
+rule android.net.util.NetworkConstants* com.android.server.x.wifi.net.util.NetworkConstants@1
+rule android.net.util.InterfaceParams* com.android.server.x.wifi.net.util.InterfaceParams@1
+rule android.net.util.SharedLog* com.android.server.x.wifi.net.util.SharedLog@1
 rule android.net.util.NetUtils* com.android.server.x.wifi.net.util.NetUtils@1
+rule android.net.util.IpUtils* com.android.server.x.wifi.net.util.IpUtils@1
 
 # We don't jar-jar the entire package because, we still use some classes (like
 # AsyncChannel in com.android.internal.util) from these packages which are not
@@ -29,7 +54,6 @@
 # Use our statically linked PlatformProperties library
 rule android.sysprop.** com.android.server.x.wifi.sysprop.@1
 
-
 # used by both framework-wifi and wifi-service
 rule android.content.pm.BaseParceledListSlice* android.x.net.wifi.util.BaseParceledListSlice@1
 rule android.content.pm.ParceledListSlice* android.x.net.wifi.util.ParceledListSlice@1
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 5e60b26..e1acaf8 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -1353,7 +1353,7 @@
         try {
             ParceledListSlice<WifiConfiguration> parceledList =
                     mService.getConfiguredNetworks(mContext.getOpPackageName(),
-                            mContext.getFeatureId());
+                            mContext.getAttributionTag());
             if (parceledList == null) {
                 return Collections.emptyList();
             }
@@ -1370,7 +1370,7 @@
         try {
             ParceledListSlice<WifiConfiguration> parceledList =
                     mService.getPrivilegedConfiguredNetworks(mContext.getOpPackageName(),
-                            mContext.getFeatureId());
+                            mContext.getAttributionTag());
             if (parceledList == null) {
                 return Collections.emptyList();
             }
@@ -1899,7 +1899,7 @@
             @NonNull List<WifiNetworkSuggestion> networkSuggestions) {
         try {
             return mService.addNetworkSuggestions(
-                    networkSuggestions, mContext.getOpPackageName(), mContext.getFeatureId());
+                    networkSuggestions, mContext.getOpPackageName(), mContext.getAttributionTag());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -2681,8 +2681,8 @@
     public boolean startScan(WorkSource workSource) {
         try {
             String packageName = mContext.getOpPackageName();
-            String featureId = mContext.getFeatureId();
-            return mService.startScan(packageName, featureId);
+            String attributionTag = mContext.getAttributionTag();
+            return mService.startScan(packageName, attributionTag);
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -2714,7 +2714,7 @@
     public WifiInfo getConnectionInfo() {
         try {
             return mService.getConnectionInfo(mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -2729,7 +2729,7 @@
     public List<ScanResult> getScanResults() {
         try {
             return mService.getScanResults(mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -2760,7 +2760,7 @@
         try {
             return mService.getMatchingScanResults(
                     networkSuggestionsToMatch, scanResults,
-                    mContext.getOpPackageName(), mContext.getFeatureId());
+                    mContext.getOpPackageName(), mContext.getAttributionTag());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
@@ -3199,7 +3199,7 @@
                     new LocalOnlyHotspotCallbackProxy(this, executor, callback);
             try {
                 String packageName = mContext.getOpPackageName();
-                String featureId = mContext.getFeatureId();
+                String featureId = mContext.getAttributionTag();
                 int returnCode = mService.startLocalOnlyHotspot(proxy, packageName, featureId,
                         config);
                 if (returnCode != LocalOnlyHotspotCallback.REQUEST_REGISTERED) {
@@ -5891,7 +5891,7 @@
         try {
             mService.registerSuggestionConnectionStatusListener(new Binder(),
                     new SuggestionConnectionStatusListenerProxy(executor, listener),
-                    listener.hashCode(), mContext.getOpPackageName(), mContext.getFeatureId());
+                    listener.hashCode(), mContext.getOpPackageName(), mContext.getAttributionTag());
         } catch (RemoteException e) {
             throw e.rethrowFromSystemServer();
         }
diff --git a/wifi/java/android/net/wifi/WifiScanner.java b/wifi/java/android/net/wifi/WifiScanner.java
index 5e48919..d299cdc 100644
--- a/wifi/java/android/net/wifi/WifiScanner.java
+++ b/wifi/java/android/net/wifi/WifiScanner.java
@@ -182,7 +182,7 @@
     public List<Integer> getAvailableChannels(int band) {
         try {
             Bundle bundle = mService.getAvailableChannels(band, mContext.getOpPackageName(),
-                    mContext.getFeatureId());
+                    mContext.getAttributionTag());
             List<Integer> channels = bundle.getIntegerArrayList(GET_AVAILABLE_CHANNELS_EXTRA);
             return channels == null ? new ArrayList<>() : channels;
         } catch (RemoteException e) {
@@ -963,7 +963,7 @@
         scanParams.putParcelable(SCAN_PARAMS_SCAN_SETTINGS_KEY, settings);
         scanParams.putParcelable(SCAN_PARAMS_WORK_SOURCE_KEY, workSource);
         scanParams.putString(REQUEST_PACKAGE_NAME_KEY, mContext.getOpPackageName());
-        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getFeatureId());
+        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getAttributionTag());
         mAsyncChannel.sendMessage(CMD_START_BACKGROUND_SCAN, 0, key, scanParams);
     }
 
@@ -984,7 +984,7 @@
         validateChannel();
         Bundle scanParams = new Bundle();
         scanParams.putString(REQUEST_PACKAGE_NAME_KEY, mContext.getOpPackageName());
-        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getFeatureId());
+        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getAttributionTag());
         mAsyncChannel.sendMessage(CMD_STOP_BACKGROUND_SCAN, 0, key, scanParams);
     }
 
@@ -1001,7 +1001,7 @@
         validateChannel();
         Bundle scanParams = new Bundle();
         scanParams.putString(REQUEST_PACKAGE_NAME_KEY, mContext.getOpPackageName());
-        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getFeatureId());
+        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getAttributionTag());
         Message reply =
                 mAsyncChannel.sendMessageSynchronously(CMD_GET_SCAN_RESULTS, 0, 0, scanParams);
         return reply.what == CMD_OP_SUCCEEDED;
@@ -1056,7 +1056,7 @@
         scanParams.putParcelable(SCAN_PARAMS_SCAN_SETTINGS_KEY, settings);
         scanParams.putParcelable(SCAN_PARAMS_WORK_SOURCE_KEY, workSource);
         scanParams.putString(REQUEST_PACKAGE_NAME_KEY, mContext.getOpPackageName());
-        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getFeatureId());
+        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getAttributionTag());
         mAsyncChannel.sendMessage(CMD_START_SINGLE_SCAN, 0, key, scanParams);
     }
 
@@ -1073,7 +1073,7 @@
         validateChannel();
         Bundle scanParams = new Bundle();
         scanParams.putString(REQUEST_PACKAGE_NAME_KEY, mContext.getOpPackageName());
-        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getFeatureId());
+        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getAttributionTag());
         mAsyncChannel.sendMessage(CMD_STOP_SINGLE_SCAN, 0, key, scanParams);
     }
 
@@ -1086,7 +1086,7 @@
         validateChannel();
         Bundle scanParams = new Bundle();
         scanParams.putString(REQUEST_PACKAGE_NAME_KEY, mContext.getOpPackageName());
-        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getFeatureId());
+        scanParams.putString(REQUEST_FEATURE_ID_KEY, mContext.getAttributionTag());
         Message reply = mAsyncChannel.sendMessageSynchronously(CMD_GET_SINGLE_SCAN_RESULTS, 0, 0,
                 scanParams);
         if (reply.what == WifiScanner.CMD_OP_SUCCEEDED) {
diff --git a/wifi/java/android/net/wifi/aware/WifiAwareManager.java b/wifi/java/android/net/wifi/aware/WifiAwareManager.java
index 2ebaa18..c2ae17c 100644
--- a/wifi/java/android/net/wifi/aware/WifiAwareManager.java
+++ b/wifi/java/android/net/wifi/aware/WifiAwareManager.java
@@ -267,7 +267,7 @@
 
             try {
                 Binder binder = new Binder();
-                mService.connect(binder, mContext.getOpPackageName(), mContext.getFeatureId(),
+                mService.connect(binder, mContext.getOpPackageName(), mContext.getAttributionTag(),
                         new WifiAwareEventCallbackProxy(this, looper, binder, attachCallback,
                                 identityChangedListener), configRequest,
                         identityChangedListener != null);
@@ -298,7 +298,7 @@
         }
 
         try {
-            mService.publish(mContext.getOpPackageName(), mContext.getFeatureId(), clientId,
+            mService.publish(mContext.getOpPackageName(), mContext.getAttributionTag(), clientId,
                     publishConfig,
                     new WifiAwareDiscoverySessionCallbackProxy(this, looper, true, callback,
                             clientId));
@@ -336,7 +336,7 @@
         }
 
         try {
-            mService.subscribe(mContext.getOpPackageName(), mContext.getFeatureId(), clientId,
+            mService.subscribe(mContext.getOpPackageName(), mContext.getAttributionTag(), clientId,
                     subscribeConfig,
                     new WifiAwareDiscoverySessionCallbackProxy(this, looper, false, callback,
                             clientId));
diff --git a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
index a310ff6..724ccf0 100644
--- a/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
+++ b/wifi/java/android/net/wifi/p2p/WifiP2pManager.java
@@ -1180,7 +1180,7 @@
                 == AsyncChannel.STATUS_SUCCESSFUL) {
             Bundle bundle = new Bundle();
             bundle.putString(CALLING_PACKAGE, c.mContext.getOpPackageName());
-            bundle.putString(CALLING_FEATURE_ID, c.mContext.getFeatureId());
+            bundle.putString(CALLING_FEATURE_ID, c.mContext.getAttributionTag());
             bundle.putBinder(CALLING_BINDER, binder);
             c.mAsyncChannel.sendMessage(UPDATE_CHANNEL_INFO, 0,
                     c.putListener(null), bundle);
diff --git a/wifi/java/android/net/wifi/rtt/WifiRttManager.java b/wifi/java/android/net/wifi/rtt/WifiRttManager.java
index cb0c5d4..865702a 100644
--- a/wifi/java/android/net/wifi/rtt/WifiRttManager.java
+++ b/wifi/java/android/net/wifi/rtt/WifiRttManager.java
@@ -146,8 +146,8 @@
 
         Binder binder = new Binder();
         try {
-            mService.startRanging(binder, mContext.getOpPackageName(), mContext.getFeatureId(),
-                    workSource, request, new IRttCallback.Stub() {
+            mService.startRanging(binder, mContext.getOpPackageName(),
+                    mContext.getAttributionTag(), workSource, request, new IRttCallback.Stub() {
                         @Override
                         public void onRangingFailure(int status) throws RemoteException {
                             clearCallingIdentity();
diff --git a/wifi/tests/src/android/net/wifi/WifiScannerTest.java b/wifi/tests/src/android/net/wifi/WifiScannerTest.java
index 0cc76b6..4881200 100644
--- a/wifi/tests/src/android/net/wifi/WifiScannerTest.java
+++ b/wifi/tests/src/android/net/wifi/WifiScannerTest.java
@@ -267,7 +267,7 @@
         assertNull(messageBundle.getParcelable(WifiScanner.SCAN_PARAMS_WORK_SOURCE_KEY));
         assertEquals(mContext.getOpPackageName(),
                 messageBundle.getParcelable(WifiScanner.REQUEST_PACKAGE_NAME_KEY));
-        assertEquals(mContext.getFeatureId(),
+        assertEquals(mContext.getAttributionTag(),
                 messageBundle.getParcelable(WifiScanner.REQUEST_FEATURE_ID_KEY));
 
     }
@@ -297,7 +297,7 @@
         Bundle messageBundle = (Bundle) message.obj;
         assertEquals(mContext.getOpPackageName(),
                 messageBundle.getParcelable(WifiScanner.REQUEST_PACKAGE_NAME_KEY));
-        assertEquals(mContext.getFeatureId(),
+        assertEquals(mContext.getAttributionTag(),
                 messageBundle.getParcelable(WifiScanner.REQUEST_FEATURE_ID_KEY));
     }
 
diff --git a/wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java b/wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java
index a9dcde0..e6eae41 100644
--- a/wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java
+++ b/wifi/tests/src/android/net/wifi/rtt/WifiRttManagerTest.java
@@ -71,7 +71,7 @@
         mMockLooperExecutor = mMockLooper.getNewExecutor();
 
         when(mockContext.getOpPackageName()).thenReturn(packageName);
-        when(mockContext.getFeatureId()).thenReturn(featureId);
+        when(mockContext.getAttributionTag()).thenReturn(featureId);
     }
 
     /**