Merge "Import translations. DO NOT MERGE" into rvc-dev
diff --git a/cmds/statsd/Android.bp b/cmds/statsd/Android.bp
index 3dbe413..0617eb6 100644
--- a/cmds/statsd/Android.bp
+++ b/cmds/statsd/Android.bp
@@ -116,7 +116,6 @@
         "libcutils",
         "libgtest_prod",
         "libprotoutil",
-        "libstatsmetadata",
         "libstatslog_statsd",
         "libsysutils",
         "libutils",
@@ -129,51 +128,6 @@
     ],
 }
 
-// ================
-// libstatsmetadata
-// ================
-
-genrule {
-    name: "atoms_info.h",
-    tools: ["stats-log-api-gen"],
-    cmd: "$(location stats-log-api-gen) --atomsInfoHeader $(genDir)/atoms_info.h",
-    out: [
-        "atoms_info.h",
-    ],
-}
-
-genrule {
-    name: "atoms_info.cpp",
-    tools: ["stats-log-api-gen"],
-    cmd: "$(location stats-log-api-gen) --atomsInfoCpp $(genDir)/atoms_info.cpp",
-    out: [
-        "atoms_info.cpp",
-    ],
-}
-
-cc_library_static {
-    name: "libstatsmetadata",
-    host_supported: true,
-    generated_sources: [
-        "atoms_info.cpp",
-    ],
-    generated_headers: [
-        "atoms_info.h",
-    ],
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-    export_generated_headers: [
-        "atoms_info.h",
-    ],
-    apex_available: [
-        //TODO(b/149782403): Remove this once statsd no longer links against libstatsmetadata
-        "com.android.os.statsd",
-        "test_com.android.os.statsd",
-    ],
-}
-
 genrule {
     name: "statslog_statsd.h",
     tools: ["stats-log-api-gen"],
diff --git a/cmds/statsd/src/atom_field_options.proto b/cmds/statsd/src/atom_field_options.proto
index 8527185..ff5717e 100644
--- a/cmds/statsd/src/atom_field_options.proto
+++ b/cmds/statsd/src/atom_field_options.proto
@@ -110,8 +110,6 @@
 
     optional LogMode log_mode = 50002 [default = MODE_AUTOMATIC];
 
-    optional bool allow_from_any_uid = 50003 [default = false];
-
     repeated string module = 50004;
 
     optional bool truncate_timestamp = 50005 [default = false];
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 663f910..a5f0ac9 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -145,8 +145,7 @@
         PacketWakeupOccurred packet_wakeup_occurred = 44 [(module) = "framework"];
         WallClockTimeShifted wall_clock_time_shifted = 45 [(module) = "framework"];
         AnomalyDetected anomaly_detected = 46 [(module) = "statsd"];
-        AppBreadcrumbReported app_breadcrumb_reported =
-                47 [(allow_from_any_uid) = true, (module) = "statsd"];
+        AppBreadcrumbReported app_breadcrumb_reported = 47 [(module) = "statsd"];
         AppStartOccurred app_start_occurred = 48 [(module) = "framework", (module) = "statsdtest"];
         AppStartCanceled app_start_canceled = 49 [(module) = "framework"];
         AppStartFullyDrawn app_start_fully_drawn = 50 [(module) = "framework"];
@@ -157,7 +156,7 @@
         AppStartMemoryStateCaptured app_start_memory_state_captured = 55 [(module) = "framework"];
         ShutdownSequenceReported shutdown_sequence_reported = 56 [(module) = "framework"];
         BootSequenceReported boot_sequence_reported = 57;
-        DaveyOccurred davey_occurred = 58 [(allow_from_any_uid) = true, (module) = "statsd"];
+        DaveyOccurred davey_occurred = 58 [(module) = "statsd"];
         OverlayStateChanged overlay_state_changed =
                 59 [(module) = "framework", (module) = "statsdtest"];
         ForegroundServiceStateChanged foreground_service_state_changed
@@ -186,8 +185,7 @@
         WTFOccurred wtf_occurred = 80 [(module) = "framework"];
         LowMemReported low_mem_reported = 81 [(module) = "framework"];
         GenericAtom generic_atom = 82;
-        KeyValuePairsAtom key_value_pairs_atom =
-                83 [(allow_from_any_uid) = true, (module) = "framework", (module) = "statsd"];
+        KeyValuePairsAtom key_value_pairs_atom = 83 [(module) = "framework", (module) = "statsd"];
         VibratorStateChanged vibrator_state_changed = 84 [(module) = "framework"];
         DeferredJobStatsReported deferred_job_stats_reported = 85 [(module) = "framework"];
         ThermalThrottlingStateChanged thermal_throttling = 86 [deprecated=true];
@@ -317,7 +315,7 @@
         AssistGestureFeedbackReported assist_gesture_feedback_reported = 175 [(module) = "sysui"];
         AssistGestureProgressReported assist_gesture_progress_reported = 176 [(module) = "sysui"];
         TouchGestureClassified touch_gesture_classified = 177 [(module) = "framework"];
-        HiddenApiUsed hidden_api_used = 178 [(allow_from_any_uid) = true, (module) = "framework"];
+        HiddenApiUsed hidden_api_used = 178 [(module) = "framework"];
         StyleUIChanged style_ui_changed = 179 [(module) = "sysui"];
         PrivacyIndicatorsInteracted privacy_indicators_interacted =
                 180 [(module) = "permissioncontroller"];
@@ -383,7 +381,7 @@
         UpdateEngineSuccessfulUpdateReported update_engine_successful_update_reported = 226;
         CameraActionEvent camera_action_event = 227 [(module) = "framework"];
         AppCompatibilityChangeReported app_compatibility_change_reported =
-            228 [(allow_from_any_uid) = true, (module) = "framework"];
+                228 [(module) = "framework"];
         PerfettoUploaded perfetto_uploaded = 229 [(module) = "perfetto"];
         VmsClientConnectionStateChanged vms_client_connection_state_changed =
                 230 [(module) = "car"];
diff --git a/cmds/statsd/src/metrics/MetricsManager.cpp b/cmds/statsd/src/metrics/MetricsManager.cpp
index 7e825ef..60de1a2 100644
--- a/cmds/statsd/src/metrics/MetricsManager.cpp
+++ b/cmds/statsd/src/metrics/MetricsManager.cpp
@@ -21,7 +21,6 @@
 #include <private/android_filesystem_config.h>
 
 #include "CountMetricProducer.h"
-#include "atoms_info.h"
 #include "condition/CombinationConditionTracker.h"
 #include "condition/SimpleConditionTracker.h"
 #include "guardrail/StatsdStats.h"
@@ -372,13 +371,6 @@
 
 
 bool MetricsManager::checkLogCredentials(const LogEvent& event) {
-    // TODO(b/154856835): Remove this check once we get whitelist from the config.
-    if (android::util::AtomsInfo::kWhitelistedAtoms.find(event.GetTagId()) !=
-      android::util::AtomsInfo::kWhitelistedAtoms.end())
-    {
-        return true;
-    }
-
     if (mWhitelistedAtomIds.find(event.GetTagId()) != mWhitelistedAtomIds.end()) {
         return true;
     }
diff --git a/core/java/android/app/ActivityView.java b/core/java/android/app/ActivityView.java
index b749c35..98a23f2 100644
--- a/core/java/android/app/ActivityView.java
+++ b/core/java/android/app/ActivityView.java
@@ -33,7 +33,10 @@
 import android.os.Bundle;
 import android.os.UserHandle;
 import android.util.AttributeSet;
+import android.util.DisplayMetrics;
 import android.util.Log;
+import android.view.Display;
+import android.view.DisplayInfo;
 import android.view.IWindow;
 import android.view.IWindowManager;
 import android.view.KeyEvent;
@@ -407,6 +410,9 @@
     }
 
     private class SurfaceCallback implements SurfaceHolder.Callback {
+        private final DisplayInfo mTempDisplayInfo = new DisplayInfo();
+        private final DisplayMetrics mTempMetrics = new DisplayMetrics();
+
         @Override
         public void surfaceCreated(SurfaceHolder surfaceHolder) {
             if (!mTaskEmbedder.isInitialized()) {
@@ -415,13 +421,21 @@
                 mTmpTransaction.reparent(mTaskEmbedder.getSurfaceControl(),
                         mSurfaceView.getSurfaceControl()).apply();
             }
+            mTaskEmbedder.resizeTask(getWidth(), getHeight());
             mTaskEmbedder.start();
         }
 
         @Override
         public void surfaceChanged(SurfaceHolder surfaceHolder, int format, int width, int height) {
-            mTaskEmbedder.resizeTask(width, height);
-            mTaskEmbedder.notifyBoundsChanged();
+            final Display display = getVirtualDisplay().getDisplay();
+            if (!display.getDisplayInfo(mTempDisplayInfo)) {
+                return;
+            }
+            mTempDisplayInfo.getAppMetrics(mTempMetrics);
+            if (width != mTempMetrics.widthPixels || height != mTempMetrics.heightPixels) {
+                mTaskEmbedder.resizeTask(width, height);
+                mTaskEmbedder.notifyBoundsChanged();
+            }
         }
 
         @Override
diff --git a/core/java/android/app/DownloadManager.java b/core/java/android/app/DownloadManager.java
index 1278ff6..07194226 100644
--- a/core/java/android/app/DownloadManager.java
+++ b/core/java/android/app/DownloadManager.java
@@ -25,6 +25,7 @@
 import android.annotation.SystemService;
 import android.annotation.TestApi;
 import android.compat.annotation.UnsupportedAppUsage;
+import android.content.ClipDescription;
 import android.content.ContentProviderClient;
 import android.content.ContentResolver;
 import android.content.ContentUris;
@@ -50,11 +51,13 @@
 import android.text.TextUtils;
 import android.util.LongSparseArray;
 import android.util.Pair;
+import android.webkit.MimeTypeMap;
 
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Locale;
 
 /**
  * The download manager is a system service that handles long-running HTTP downloads. Clients may
@@ -1554,6 +1557,7 @@
         values.put(Downloads.Impl.COLUMN_DESTINATION,
                 Downloads.Impl.DESTINATION_NON_DOWNLOADMANAGER_DOWNLOAD);
         values.put(Downloads.Impl._DATA, path);
+        values.put(Downloads.Impl.COLUMN_MIME_TYPE, resolveMimeType(new File(path)));
         values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_SUCCESS);
         values.put(Downloads.Impl.COLUMN_TOTAL_BYTES, length);
         values.put(Downloads.Impl.COLUMN_MEDIA_SCANNED,
@@ -1569,6 +1573,58 @@
         return Long.parseLong(downloadUri.getLastPathSegment());
     }
 
+    /**
+     * Shamelessly borrowed from
+     * {@code packages/providers/MediaProvider/src/com/android/providers/media/util/MimeUtils.java}
+     *
+     * @hide
+     */
+    private static @NonNull String resolveMimeType(@NonNull File file) {
+        final String extension = extractFileExtension(file.getPath());
+        if (extension == null) return ClipDescription.MIMETYPE_UNKNOWN;
+
+        final String mimeType = MimeTypeMap.getSingleton()
+                .getMimeTypeFromExtension(extension.toLowerCase(Locale.ROOT));
+        if (mimeType == null) return ClipDescription.MIMETYPE_UNKNOWN;
+
+        return mimeType;
+    }
+
+    /**
+     * Shamelessly borrowed from
+     * {@code packages/providers/MediaProvider/src/com/android/providers/media/util/FileUtils.java}
+     *
+     * @hide
+     */
+    private static @Nullable String extractDisplayName(@Nullable String data) {
+        if (data == null) return null;
+        if (data.indexOf('/') == -1) {
+            return data;
+        }
+        if (data.endsWith("/")) {
+            data = data.substring(0, data.length() - 1);
+        }
+        return data.substring(data.lastIndexOf('/') + 1);
+    }
+
+    /**
+     * Shamelessly borrowed from
+     * {@code packages/providers/MediaProvider/src/com/android/providers/media/util/FileUtils.java}
+     *
+     * @hide
+     */
+    private static @Nullable String extractFileExtension(@Nullable String data) {
+        if (data == null) return null;
+        data = extractDisplayName(data);
+
+        final int lastDot = data.lastIndexOf('.');
+        if (lastDot == -1) {
+            return null;
+        } else {
+            return data.substring(lastDot + 1);
+        }
+    }
+
     private static final String NON_DOWNLOADMANAGER_DOWNLOAD =
             "non-dwnldmngr-download-dont-retry2download";
 
diff --git a/core/java/android/app/usage/UsageStatsManager.java b/core/java/android/app/usage/UsageStatsManager.java
index 2ce6a86..8a6cc95 100644
--- a/core/java/android/app/usage/UsageStatsManager.java
+++ b/core/java/android/app/usage/UsageStatsManager.java
@@ -154,6 +154,7 @@
      * been misbehaving in some manner.
      * Apps in this bucket will have the most restrictions, including network restrictions and
      * additional restrictions on jobs.
+     * <p> Note: this bucket is not enabled in {@link Build.VERSION_CODES#R}.
      * @see #getAppStandbyBucket()
      */
     public static final int STANDBY_BUCKET_RESTRICTED = 45;
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 4abb2c5..64d9c9d 100755
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -12009,7 +12009,7 @@
          * @see #ENABLE_RESTRICTED_BUCKET
          * @hide
          */
-        public static final int DEFAULT_ENABLE_RESTRICTED_BUCKET = 1;
+        public static final int DEFAULT_ENABLE_RESTRICTED_BUCKET = 0;
 
         /**
          * Whether or not app auto restriction is enabled. When it is enabled, settings app will
diff --git a/core/java/android/view/ImeInsetsSourceConsumer.java b/core/java/android/view/ImeInsetsSourceConsumer.java
index 8b5af29..ef9d990 100644
--- a/core/java/android/view/ImeInsetsSourceConsumer.java
+++ b/core/java/android/view/ImeInsetsSourceConsumer.java
@@ -21,6 +21,7 @@
 
 import android.annotation.Nullable;
 import android.inputmethodservice.InputMethodService;
+import android.os.IBinder;
 import android.os.Parcel;
 import android.text.TextUtils;
 import android.view.SurfaceControl.Transaction;
@@ -153,6 +154,15 @@
         return mIsRequestedVisibleAwaitingControl || isRequestedVisible();
     }
 
+    @Override
+    public void onPerceptible(boolean perceptible) {
+        super.onPerceptible(perceptible);
+        final IBinder window = mController.getHost().getWindowToken();
+        if (window != null) {
+            getImm().reportPerceptible(window, perceptible);
+        }
+    }
+
     private boolean isDummyOrEmptyEditor(EditorInfo info) {
         // TODO(b/123044812): Handle dummy input gracefully in IME Insets API
         return info == null || (info.fieldId <= 0 && info.inputType <= 0);
diff --git a/core/java/android/view/InsetsAnimationControlCallbacks.java b/core/java/android/view/InsetsAnimationControlCallbacks.java
index 74c1869..3431c3e 100644
--- a/core/java/android/view/InsetsAnimationControlCallbacks.java
+++ b/core/java/android/view/InsetsAnimationControlCallbacks.java
@@ -16,6 +16,7 @@
 
 package android.view;
 
+import android.view.WindowInsets.Type.InsetsType;
 import android.view.WindowInsetsAnimation.Bounds;
 
 /**
@@ -64,4 +65,15 @@
      * previous calls to applySurfaceParams.
      */
     void releaseSurfaceControlFromRt(SurfaceControl sc);
+
+    /**
+     * Reports that the perceptibility of the given types has changed to the given value.
+     *
+     * A type is perceptible if it is not (almost) entirely off-screen and not (almost) entirely
+     * transparent.
+     *
+     * @param types the (public) types whose perceptibility has changed
+     * @param perceptible true, if the types are now perceptible, false if they are not perceptible
+     */
+    void reportPerceptible(@InsetsType int types, boolean perceptible);
 }
diff --git a/core/java/android/view/InsetsAnimationControlImpl.java b/core/java/android/view/InsetsAnimationControlImpl.java
index baeae2f..31da83a 100644
--- a/core/java/android/view/InsetsAnimationControlImpl.java
+++ b/core/java/android/view/InsetsAnimationControlImpl.java
@@ -87,6 +87,7 @@
     private float mPendingAlpha = 1.0f;
     @VisibleForTesting(visibility = PACKAGE)
     public boolean mReadyDispatched;
+    private Boolean mPerceptible;
 
     @VisibleForTesting
     public InsetsAnimationControlImpl(SparseArray<InsetsSourceControl> controls, Rect frame,
@@ -121,6 +122,14 @@
                 new Bounds(mHiddenInsets, mShownInsets));
     }
 
+    private boolean calculatePerceptible(Insets currentInsets, float currentAlpha) {
+        return 100 * currentInsets.left >= 5 * (mShownInsets.left - mHiddenInsets.left)
+                && 100 * currentInsets.top >= 5 * (mShownInsets.top - mHiddenInsets.top)
+                && 100 * currentInsets.right >= 5 * (mShownInsets.right - mHiddenInsets.right)
+                && 100 * currentInsets.bottom >= 5 * (mShownInsets.bottom - mHiddenInsets.bottom)
+                && currentAlpha >= 0.5f;
+    }
+
     @Override
     public boolean hasZeroInsetsIme() {
         return mHasZeroInsetsIme;
@@ -175,6 +184,11 @@
         mPendingInsets = sanitize(insets);
         mPendingAlpha = sanitize(alpha);
         mController.scheduleApplyChangeInsets(this);
+        boolean perceptible = calculatePerceptible(mPendingInsets, mPendingAlpha);
+        if (mPerceptible == null || perceptible != mPerceptible) {
+            mController.reportPerceptible(mTypes, perceptible);
+            mPerceptible = perceptible;
+        }
     }
 
     @VisibleForTesting
diff --git a/core/java/android/view/InsetsAnimationThreadControlRunner.java b/core/java/android/view/InsetsAnimationThreadControlRunner.java
index 0e71b76..1236044 100644
--- a/core/java/android/view/InsetsAnimationThreadControlRunner.java
+++ b/core/java/android/view/InsetsAnimationThreadControlRunner.java
@@ -90,6 +90,11 @@
             // Since we don't push the SurfaceParams to the RT we can release directly
             sc.release();
         }
+
+        @Override
+        public void reportPerceptible(int types, boolean perceptible) {
+            mMainThreadHandler.post(() -> mOuterCallbacks.reportPerceptible(types, perceptible));
+        }
     };
 
     @UiThread
diff --git a/core/java/android/view/InsetsController.java b/core/java/android/view/InsetsController.java
index 5f99bfe..a3c88ba 100644
--- a/core/java/android/view/InsetsController.java
+++ b/core/java/android/view/InsetsController.java
@@ -35,6 +35,7 @@
 import android.graphics.Rect;
 import android.os.CancellationSignal;
 import android.os.Handler;
+import android.os.IBinder;
 import android.os.Trace;
 import android.util.ArraySet;
 import android.util.Log;
@@ -165,6 +166,12 @@
 
         /** @see ViewRootImpl#dipToPx */
         int dipToPx(int dips);
+
+        /**
+         * @return token associated with the host, if it has one.
+         */
+        @Nullable
+        IBinder getWindowToken();
     }
 
     private static final String TAG = "InsetsController";
@@ -1353,6 +1360,18 @@
         mHost.releaseSurfaceControlFromRt(sc);
     }
 
+    @Override
+    public void reportPerceptible(int types, boolean perceptible) {
+        final ArraySet<Integer> internalTypes = toInternalType(types);
+        final int size = mSourceConsumers.size();
+        for (int i = 0; i < size; i++) {
+            final InsetsSourceConsumer consumer = mSourceConsumers.valueAt(i);
+            if (internalTypes.contains(consumer.getType())) {
+                consumer.onPerceptible(perceptible);
+            }
+        }
+    }
+
     Host getHost() {
         return mHost;
     }
diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java
index 5658466..b62e67c 100644
--- a/core/java/android/view/InsetsSourceConsumer.java
+++ b/core/java/android/view/InsetsSourceConsumer.java
@@ -261,6 +261,15 @@
     }
 
     /**
+     * Reports that this source's perceptibility has changed
+     *
+     * @param perceptible true if the source is perceptible, false otherwise.
+     * @see InsetsAnimationControlCallbacks#reportPerceptible
+     */
+    public void onPerceptible(boolean perceptible) {
+    }
+
+    /**
      * Notify listeners that window is now hidden.
      */
     void notifyHidden() {
@@ -339,5 +348,6 @@
             t.hide(mSourceControl.getLeash());
         }
         t.apply();
+        onPerceptible(mRequestedVisible);
     }
 }
diff --git a/core/java/android/view/ViewRootInsetsControllerHost.java b/core/java/android/view/ViewRootInsetsControllerHost.java
index f7ca3c2..90a80ce 100644
--- a/core/java/android/view/ViewRootInsetsControllerHost.java
+++ b/core/java/android/view/ViewRootInsetsControllerHost.java
@@ -22,6 +22,7 @@
 
 import android.annotation.NonNull;
 import android.os.Handler;
+import android.os.IBinder;
 import android.os.RemoteException;
 import android.util.Log;
 import android.view.inputmethod.InputMethodManager;
@@ -236,4 +237,16 @@
         }
         return 0;
     }
+
+    @Override
+    public IBinder getWindowToken() {
+        if (mViewRoot == null) {
+            return null;
+        }
+        final View view = mViewRoot.getView();
+        if (view == null) {
+            return null;
+        }
+        return view.getWindowToken();
+    }
 }
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 821dd74..aedb59b 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -541,6 +541,19 @@
         return servedView.hasWindowFocus() || isAutofillUIShowing(servedView);
     }
 
+    /**
+     * Reports whether the IME is currently perceptible or not, according to the leash applied by
+     * {@link android.view.WindowInsetsController}.
+     * @hide
+     */
+    public void reportPerceptible(IBinder windowToken, boolean perceptible) {
+        try {
+            mService.reportPerceptible(windowToken, perceptible);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
+    }
+
     private final class DelegateImpl implements
             ImeFocusController.InputMethodManagerDelegate {
         /**
diff --git a/core/java/com/android/internal/view/IInputMethodManager.aidl b/core/java/com/android/internal/view/IInputMethodManager.aidl
index d22f942..8ec51b8 100644
--- a/core/java/com/android/internal/view/IInputMethodManager.aidl
+++ b/core/java/com/android/internal/view/IInputMethodManager.aidl
@@ -72,5 +72,6 @@
     void reportActivityView(in IInputMethodClient parentClient, int childDisplayId,
             in float[] matrixValues);
 
+    oneway void reportPerceptible(in IBinder windowToken, boolean perceptible);
     void removeImeSurface();
 }
diff --git a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java
index 8eca650..a2b1e3d 100644
--- a/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java
+++ b/core/tests/coretests/src/android/view/InsetsAnimationControlImplTest.java
@@ -234,6 +234,24 @@
         verify(mMockListener).onFinished(mController);
     }
 
+    @Test
+    public void testPerceptible_insets() {
+        mController.setInsetsAndAlpha(mController.getHiddenStateInsets(), 1f, 1f);
+        verify(mMockController).reportPerceptible(systemBars(), false);
+
+        mController.setInsetsAndAlpha(mController.getShownStateInsets(), 1f, 1f);
+        verify(mMockController).reportPerceptible(systemBars(), true);
+    }
+
+    @Test
+    public void testPerceptible_alpha() {
+        mController.setInsetsAndAlpha(mController.getShownStateInsets(), 0f, 1f);
+        verify(mMockController).reportPerceptible(systemBars(), false);
+
+        mController.setInsetsAndAlpha(mController.getShownStateInsets(), 1f, 1f);
+        verify(mMockController).reportPerceptible(systemBars(), true);
+    }
+
     private void assertPosition(Matrix m, Rect original, Rect transformed) {
         RectF rect = new RectF(original);
         rect.offsetTo(0, 0);
diff --git a/libs/androidfw/Idmap.cpp b/libs/androidfw/Idmap.cpp
index eb6ee95..5f231ff 100644
--- a/libs/androidfw/Idmap.cpp
+++ b/libs/androidfw/Idmap.cpp
@@ -157,7 +157,7 @@
   table_value->dataType = entry->type;
   table_value->data = entry->value;
 
-  return Result(ResTable_entry_handle::managed(table_entry));
+  return Result(ResTable_entry_handle::managed(table_entry, [](auto p) { free(p); }));
 }
 
 static bool is_word_aligned(const void* data) {
diff --git a/libs/androidfw/include/androidfw/ResourceTypes.h b/libs/androidfw/include/androidfw/ResourceTypes.h
index 21be81c..e351a46 100644
--- a/libs/androidfw/include/androidfw/ResourceTypes.h
+++ b/libs/androidfw/include/androidfw/ResourceTypes.h
@@ -1601,8 +1601,8 @@
       entry_ = handle.entry_;
     }
 
-    inline static ResTable_entry_handle managed(ResTable_entry* entry)  {
-      return ResTable_entry_handle(std::shared_ptr<const ResTable_entry>(entry));
+    inline static ResTable_entry_handle managed(ResTable_entry* entry, void (*deleter)(void *)) {
+      return ResTable_entry_handle(std::shared_ptr<const ResTable_entry>(entry, deleter));
     }
 
     inline static ResTable_entry_handle unmanaged(const ResTable_entry* entry)  {
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java
index ea7a556..3ac71b2 100755
--- a/media/java/android/media/AudioManager.java
+++ b/media/java/android/media/AudioManager.java
@@ -4599,6 +4599,12 @@
 
     /**
      * @hide
+     * Volume behavior for an audio device that has no particular volume behavior set. Invalid as
+     * an argument to {@link #setDeviceVolumeBehavior(int, String, int)}.
+     */
+    public static final int DEVICE_VOLUME_BEHAVIOR_UNSET = -1;
+    /**
+     * @hide
      * Volume behavior for an audio device where a software attenuation is applied
      * @see #setDeviceVolumeBehavior(int, String, int)
      */
@@ -4647,6 +4653,18 @@
     @Retention(RetentionPolicy.SOURCE)
     public @interface DeviceVolumeBehavior {}
 
+    /** @hide */
+    @IntDef({
+            DEVICE_VOLUME_BEHAVIOR_UNSET,
+            DEVICE_VOLUME_BEHAVIOR_VARIABLE,
+            DEVICE_VOLUME_BEHAVIOR_FULL,
+            DEVICE_VOLUME_BEHAVIOR_FIXED,
+            DEVICE_VOLUME_BEHAVIOR_ABSOLUTE,
+            DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_MULTI_MODE,
+    })
+    @Retention(RetentionPolicy.SOURCE)
+    public @interface DeviceVolumeBehaviorState {}
+
     /**
      * @hide
      * Throws IAE on an invalid volume behavior value
@@ -4713,7 +4731,7 @@
      * @return the volume behavior for the device
      */
     @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
-    public @DeviceVolumeBehavior int getDeviceVolumeBehavior(int deviceType,
+    public @DeviceVolumeBehaviorState int getDeviceVolumeBehavior(int deviceType,
             @Nullable String deviceAddress) {
         // verify arguments
         AudioDeviceInfo.enforceValidAudioDeviceTypeOut(deviceType);
@@ -4728,8 +4746,8 @@
      * @return the volume behavior for the device
      */
     @RequiresPermission(android.Manifest.permission.MODIFY_AUDIO_ROUTING)
-    public @DeviceVolumeBehavior int getDeviceVolumeBehavior(@NonNull AudioDeviceAttributes device)
-    {
+    public @DeviceVolumeBehaviorState int getDeviceVolumeBehavior(
+            @NonNull AudioDeviceAttributes device) {
         // verify arguments (validity of device type is enforced in server)
         Objects.requireNonNull(device);
         // communicate with service
diff --git a/packages/SystemUI/res/layout/media_view.xml b/packages/SystemUI/res/layout/media_view.xml
index 594bbcf..07bbb8f 100644
--- a/packages/SystemUI/res/layout/media_view.xml
+++ b/packages/SystemUI/res/layout/media_view.xml
@@ -26,6 +26,7 @@
     android:gravity="center_horizontal|fill_vertical"
     android:background="@drawable/qs_media_background">
 
+    <!-- As per Material Design on Biderectionality, this is forced to LTR in code -->
     <FrameLayout
         android:id="@+id/notification_media_progress_time"
         android:layout_width="0dp"
@@ -36,7 +37,7 @@
             android:id="@+id/media_elapsed_time"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_alignParentLeft="true"
+            android:layout_alignParentStart="true"
             android:fontFamily="@*android:string/config_bodyFontFamily"
             android:textColor="@color/media_primary_text"
             android:gravity="start"
@@ -46,13 +47,36 @@
             android:id="@+id/media_total_time"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_alignParentRight="true"
+            android:layout_alignParentEnd="true"
             android:fontFamily="@*android:string/config_bodyFontFamily"
             android:textColor="@color/media_primary_text"
             android:gravity="end"
             android:textSize="14sp" />
     </FrameLayout>
 
+    <!--  Actions must be ordered left-to-right even in RTL layout.  However, they appear in a chain
+    with the album art and the title, and must as a group appear at the end of that chain.  This is
+    accomplished by having the guidebox (an invisible view that is positioned around all 5 actions)
+    in the chain with the album art and the title.  The actions are in a LTR chain bounded by that
+    guidebox, and the ambiguity of how wide the guidebox should be is resolved by using a barrier
+    which forces it's starting edge to be as far to the end as possible while fitting the actions.
+    -->
+    <androidx.constraintlayout.widget.Barrier
+        android:id="@+id/media_action_barrier"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:orientation="vertical"
+        app:barrierDirection="start"
+        />
+
+    <View
+        android:id="@+id/media_action_guidebox"
+        android:layout_width="0dp"
+        android:layout_height="48dp"
+        android:layout_marginTop="16dp"
+        android:visibility="invisible"
+        />
+
     <ImageButton
         android:id="@+id/action0"
         style="@style/MediaPlayer.Button"
@@ -98,16 +122,16 @@
         android:background="@drawable/qs_media_light_source"
         android:orientation="horizontal"
         android:forceHasOverlappingRendering="false"
-        android:paddingLeft="12dp"
+        android:paddingStart="12dp"
         android:paddingTop="6dp"
-        android:paddingRight="12dp"
+        android:paddingEnd="12dp"
         android:paddingBottom="6dp">
 
         <ImageView
             android:id="@+id/media_seamless_image"
             android:layout_width="@dimen/qs_seamless_icon_size"
             android:layout_height="@dimen/qs_seamless_icon_size"
-            android:layout_marginRight="8dp"
+            android:layout_marginEnd="8dp"
             android:tint="@color/media_primary_text"
             android:src="@*android:drawable/ic_media_seamless" />
 
@@ -115,10 +139,11 @@
             android:id="@+id/media_seamless_text"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
-            android:fontFamily="@*android:string/config_bodyFontFamily"
+            android:fontFamily="@*android:string/config_headlineFontFamily"
             android:singleLine="true"
             android:text="@*android:string/ext_media_seamless_action"
             android:textColor="@color/media_primary_text"
+            android:textDirection="locale"
             android:textSize="14sp" />
     </LinearLayout>
 
@@ -140,6 +165,7 @@
         />
 
     <!-- Seek Bar -->
+    <!-- As per Material Design on Biderectionality, this is forced to LTR in code -->
     <SeekBar
         android:id="@+id/media_progress_bar"
         style="@android:style/Widget.ProgressBar.Horizontal"
@@ -161,6 +187,8 @@
         android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:singleLine="true"
+        android:fontFamily="@*android:string/config_headlineFontFamily"
+        android:textDirection="locale"
         android:textSize="14sp" />
 
     <!-- Song name -->
@@ -171,6 +199,7 @@
         android:fontFamily="@*android:string/config_headlineFontFamilyMedium"
         android:singleLine="true"
         android:textColor="@color/media_primary_text"
+        android:textDirection="locale"
         android:textSize="16sp" />
 
     <!-- Artist name -->
@@ -178,16 +207,17 @@
         android:id="@+id/header_artist"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:fontFamily="@*android:string/config_bodyFontFamily"
+        android:fontFamily="@*android:string/config_headlineFontFamily"
         android:singleLine="true"
         android:textColor="@color/media_secondary_text"
+        android:textDirection="locale"
         android:textSize="14sp" />
 
     <com.android.internal.widget.CachingIconView
         android:id="@+id/icon"
         android:tint="@color/media_primary_text"
-        android:layout_width="16dp"
-        android:layout_height="16dp" />
+        android:layout_width="20dp"
+        android:layout_height="20dp" />
 
     <!-- Buttons to remove this view when no longer needed -->
     <include
diff --git a/packages/SystemUI/res/xml/media_collapsed.xml b/packages/SystemUI/res/xml/media_collapsed.xml
index 0e886d6..811e0e3 100644
--- a/packages/SystemUI/res/xml/media_collapsed.xml
+++ b/packages/SystemUI/res/xml/media_collapsed.xml
@@ -85,7 +85,7 @@
         app:layout_constraintTop_toBottomOf="@id/app_name"
         app:layout_constraintBottom_toTopOf="@id/header_artist"
         app:layout_constraintStart_toEndOf="@id/album_art"
-        app:layout_constraintEnd_toStartOf="@id/action0"
+        app:layout_constraintEnd_toStartOf="@id/media_action_barrier"
         app:layout_constraintHorizontal_bias="0"/>
 
     <!-- Artist name -->
@@ -97,7 +97,7 @@
         android:layout_marginBottom="24dp"
         app:layout_constraintTop_toBottomOf="@id/header_title"
         app:layout_constraintStart_toStartOf="@id/header_title"
-        app:layout_constraintEnd_toStartOf="@id/action0"
+        app:layout_constraintEnd_toStartOf="@id/media_action_barrier"
         app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintHorizontal_bias="0"/>
 
@@ -128,15 +128,37 @@
         />
 
     <Constraint
+        android:id="@+id/media_action_barrier"
+        android:layout_width="0dp"
+        android:layout_height="0dp"
+        android:orientation="vertical"
+        app:layout_constraintTop_toTopOf="parent"
+        app:barrierDirection="start"
+        app:constraint_referenced_ids="media_action_guidebox,action0,action1,action2,action3,action4"
+        />
+
+    <Constraint
+        android:id="@+id/media_action_guidebox"
+        android:layout_width="0dp"
+        android:layout_height="48dp"
+        android:layout_marginTop="18dp"
+        android:visibility="invisible"
+        app:layout_constraintTop_toBottomOf="@id/app_name"
+        app:layout_constraintStart_toEndOf="@id/header_title"
+        app:layout_constraintEnd_toEndOf="parent"
+        />
+
+    <Constraint
         android:id="@+id/action0"
         android:layout_width="48dp"
         android:layout_height="48dp"
         android:layout_marginStart="4dp"
-        android:layout_marginTop="16dp"
+        android:layout_marginEnd="4dp"
+        android:layout_marginTop="18dp"
         android:visibility="gone"
         app:layout_constraintHorizontal_chainStyle="packed"
         app:layout_constraintTop_toBottomOf="@id/app_name"
-        app:layout_constraintLeft_toRightOf="@id/header_title"
+        app:layout_constraintLeft_toLeftOf="@id/media_action_guidebox"
         app:layout_constraintRight_toLeftOf="@id/action1"
         >
     </Constraint>
@@ -188,9 +210,10 @@
         android:layout_marginEnd="4dp"
         android:visibility="gone"
         android:layout_marginTop="18dp"
+        app:layout_constraintHorizontal_chainStyle="packed"
         app:layout_constraintTop_toBottomOf="@id/app_name"
         app:layout_constraintLeft_toRightOf="@id/action3"
-        app:layout_constraintRight_toRightOf="parent"
+        app:layout_constraintRight_toRightOf="@id/media_action_guidebox"
         >
     </Constraint>
 </ConstraintSet>
diff --git a/packages/SystemUI/res/xml/media_expanded.xml b/packages/SystemUI/res/xml/media_expanded.xml
index 9b4caa4..8432abc 100644
--- a/packages/SystemUI/res/xml/media_expanded.xml
+++ b/packages/SystemUI/res/xml/media_expanded.xml
@@ -182,6 +182,7 @@
         android:layout_marginStart="4dp"
         android:layout_marginEnd="4dp"
         android:layout_marginBottom="@dimen/qs_media_panel_outer_padding"
+        app:layout_constraintHorizontal_chainStyle="packed"
         app:layout_constraintLeft_toRightOf="@id/action3"
         app:layout_constraintRight_toRightOf="parent"
         app:layout_constraintTop_toTopOf="@id/action0"
diff --git a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
index c2e5f31..50828e8 100644
--- a/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
+++ b/packages/SystemUI/src/com/android/systemui/bubbles/BubbleStackView.java
@@ -1504,6 +1504,7 @@
                     && ((BadgedImageView) v).getKey().equals(bubble.getKey())) {
                 mBubbleContainer.removeViewAt(i);
                 bubble.cleanupViews();
+                updatePointerPosition();
                 logBubbleEvent(bubble, SysUiStatsLog.BUBBLE_UICHANGED__ACTION__DISMISSED);
                 return;
             }
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java b/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java
index 951dc99..3bac196 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeFactory.java
@@ -35,7 +35,6 @@
 import com.android.systemui.statusbar.phone.BiometricUnlockController;
 import com.android.systemui.statusbar.phone.DozeParameters;
 import com.android.systemui.statusbar.policy.BatteryController;
-import com.android.systemui.util.concurrency.DelayableExecutor;
 import com.android.systemui.util.sensors.AsyncSensorManager;
 import com.android.systemui.util.sensors.ProximitySensor;
 import com.android.systemui.util.wakelock.DelayedWakeLock;
@@ -56,9 +55,9 @@
     private final DockManager mDockManager;
     private final IWallpaperManager mWallpaperManager;
     private final ProximitySensor mProximitySensor;
+    private final ProximitySensor.ProximityCheck mProximityCheck;
     private final DelayedWakeLock.Builder mDelayedWakeLockBuilder;
     private final Handler mHandler;
-    private final DelayableExecutor mDelayableExecutor;
     private final BiometricUnlockController mBiometricUnlockController;
     private final BroadcastDispatcher mBroadcastDispatcher;
     private final DozeHost mDozeHost;
@@ -69,9 +68,8 @@
             AsyncSensorManager asyncSensorManager, AlarmManager alarmManager,
             WakefulnessLifecycle wakefulnessLifecycle, KeyguardUpdateMonitor keyguardUpdateMonitor,
             DockManager dockManager, @Nullable IWallpaperManager wallpaperManager,
-            ProximitySensor proximitySensor,
+            ProximitySensor proximitySensor, ProximitySensor.ProximityCheck proximityCheck,
             DelayedWakeLock.Builder delayedWakeLockBuilder, @Main Handler handler,
-            @Main DelayableExecutor delayableExecutor,
             BiometricUnlockController biometricUnlockController,
             BroadcastDispatcher broadcastDispatcher, DozeHost dozeHost) {
         mFalsingManager = falsingManager;
@@ -85,9 +83,9 @@
         mDockManager = dockManager;
         mWallpaperManager = wallpaperManager;
         mProximitySensor = proximitySensor;
+        mProximityCheck = proximityCheck;
         mDelayedWakeLockBuilder = delayedWakeLockBuilder;
         mHandler = handler;
-        mDelayableExecutor = delayableExecutor;
         mBiometricUnlockController = biometricUnlockController;
         mBroadcastDispatcher = broadcastDispatcher;
         mDozeHost = dozeHost;
@@ -112,8 +110,8 @@
                 new DozePauser(mHandler, machine, mAlarmManager, mDozeParameters.getPolicy()),
                 new DozeFalsingManagerAdapter(mFalsingManager),
                 createDozeTriggers(dozeService, mAsyncSensorManager, mDozeHost,
-                        mAlarmManager, config, mDozeParameters, mDelayableExecutor, wakeLock,
-                        machine, mDockManager, mDozeLog),
+                        mAlarmManager, config, mDozeParameters, wakeLock,
+                        machine, mDockManager, mDozeLog, mProximityCheck),
                 createDozeUi(dozeService, mDozeHost, wakeLock, machine, mHandler,
                         mAlarmManager, mDozeParameters, mDozeLog),
                 new DozeScreenState(wrappedService, mHandler, mDozeHost, mDozeParameters,
@@ -140,12 +138,13 @@
 
     private DozeTriggers createDozeTriggers(Context context, AsyncSensorManager sensorManager,
             DozeHost host, AlarmManager alarmManager, AmbientDisplayConfiguration config,
-            DozeParameters params, DelayableExecutor delayableExecutor, WakeLock wakeLock,
-            DozeMachine machine, DockManager dockManager, DozeLog dozeLog) {
+            DozeParameters params, WakeLock wakeLock,
+            DozeMachine machine, DockManager dockManager, DozeLog dozeLog,
+            ProximitySensor.ProximityCheck proximityCheck) {
         boolean allowPulseTriggers = true;
         return new DozeTriggers(context, machine, host, alarmManager, config, params,
-                sensorManager, delayableExecutor, wakeLock, allowPulseTriggers, dockManager,
-                mProximitySensor, dozeLog, mBroadcastDispatcher);
+                sensorManager, wakeLock, allowPulseTriggers, dockManager,
+                mProximitySensor, proximityCheck, dozeLog, mBroadcastDispatcher);
 
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
index 6a55014..82639ba 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeTriggers.java
@@ -42,7 +42,6 @@
 import com.android.systemui.dock.DockManager;
 import com.android.systemui.statusbar.phone.DozeParameters;
 import com.android.systemui.util.Assert;
-import com.android.systemui.util.concurrency.DelayableExecutor;
 import com.android.systemui.util.sensors.AsyncSensorManager;
 import com.android.systemui.util.sensors.ProximitySensor;
 import com.android.systemui.util.wakelock.WakeLock;
@@ -153,8 +152,8 @@
     public DozeTriggers(Context context, DozeMachine machine, DozeHost dozeHost,
             AlarmManager alarmManager, AmbientDisplayConfiguration config,
             DozeParameters dozeParameters, AsyncSensorManager sensorManager,
-            DelayableExecutor delayableExecutor, WakeLock wakeLock, boolean allowPulseTriggers,
-            DockManager dockManager, ProximitySensor proximitySensor,
+            WakeLock wakeLock, boolean allowPulseTriggers, DockManager dockManager,
+            ProximitySensor proximitySensor, ProximitySensor.ProximityCheck proxCheck,
             DozeLog dozeLog, BroadcastDispatcher broadcastDispatcher) {
         mContext = context;
         mMachine = machine;
@@ -168,7 +167,7 @@
                 config, wakeLock, this::onSensor, this::onProximityFar, dozeLog, proximitySensor);
         mUiModeManager = mContext.getSystemService(UiModeManager.class);
         mDockManager = dockManager;
-        mProxCheck = new ProximitySensor.ProximityCheck(proximitySensor, delayableExecutor);
+        mProxCheck = proxCheck;
         mDozeLog = dozeLog;
         mBroadcastDispatcher = broadcastDispatcher;
     }
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt
index db45a5f..e2215d5 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaCarouselController.kt
@@ -15,6 +15,7 @@
 import com.android.systemui.qs.PageIndicator
 import com.android.systemui.statusbar.notification.VisualStabilityManager
 import com.android.systemui.statusbar.policy.ConfigurationController
+import com.android.systemui.util.Utils
 import com.android.systemui.util.animation.UniqueObjectHostView
 import com.android.systemui.util.animation.requiresRemeasuring
 import com.android.systemui.util.concurrency.DelayableExecutor
@@ -150,8 +151,15 @@
         mediaManager.addListener(object : MediaDataManager.Listener {
             override fun onMediaDataLoaded(key: String, oldKey: String?, data: MediaData) {
                 oldKey?.let { mediaData.remove(it) }
-                mediaData.put(key, data)
-                addOrUpdatePlayer(key, oldKey, data)
+                if (!data.active && !Utils.useMediaResumption(context)) {
+                    // This view is inactive, let's remove this! This happens e.g when dismissing /
+                    // timing out a view. We still have the data around because resumption could
+                    // be on, but we should save the resources and release this.
+                    onMediaDataRemoved(key)
+                } else {
+                    mediaData.put(key, data)
+                    addOrUpdatePlayer(key, oldKey, data)
+                }
             }
 
             override fun onMediaDataRemoved(key: String) {
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt
index 3266074..c41e610 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt
@@ -140,6 +140,18 @@
         }
 
     /**
+     * Is the shade currently collapsing from the expanded qs? If we're on the lockscreen and in qs,
+     * we wouldn't want to transition in that case.
+     */
+    var collapsingShadeFromQS: Boolean = false
+        set(value) {
+            if (field != value) {
+                field = value
+                updateDesiredLocation(forceNoAnimation = true)
+            }
+        }
+
+    /**
      * Are location changes currently blocked?
      */
     private val blockLocationChanges: Boolean
@@ -161,6 +173,19 @@
         }
 
     /**
+     * Are we currently fullyAwake
+     */
+    private var fullyAwake: Boolean = false
+        set(value) {
+            if (field != value) {
+                field = value
+                if (value) {
+                    updateDesiredLocation(forceNoAnimation = true)
+                }
+            }
+        }
+
+    /**
      * Is the doze animation currently Running
      */
     private var dozeAnimationRunning: Boolean = false
@@ -206,10 +231,12 @@
 
             override fun onStartedGoingToSleep() {
                 goingToSleep = true
+                fullyAwake = false
             }
 
             override fun onFinishedWakingUp() {
                 goingToSleep = false
+                fullyAwake = true
             }
 
             override fun onStartedWakingUp() {
@@ -531,6 +558,18 @@
                 !statusBarStateController.isDozing) {
             return LOCATION_QS
         }
+        if (location == LOCATION_LOCKSCREEN && desiredLocation == LOCATION_QS &&
+                collapsingShadeFromQS) {
+            // When collapsing on the lockscreen, we want to remain in QS
+            return LOCATION_QS
+        }
+        if (location != LOCATION_LOCKSCREEN && desiredLocation == LOCATION_LOCKSCREEN
+                && !fullyAwake) {
+            // When unlocking from dozing / while waking up, the media shouldn't be transitioning
+            // in an animated way. Let's keep it in the lockscreen until we're fully awake and
+            // reattach it without an animation
+            return LOCATION_LOCKSCREEN
+        }
         return location
     }
 
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt b/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt
index 90961db..fc22c02 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaViewController.kt
@@ -17,9 +17,11 @@
 package com.android.systemui.media
 
 import android.content.Context
+import android.content.res.Configuration
 import android.graphics.PointF
 import androidx.constraintlayout.widget.ConstraintSet
 import com.android.systemui.R
+import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.util.animation.MeasurementOutput
 import com.android.systemui.util.animation.TransitionLayout
 import com.android.systemui.util.animation.TransitionLayoutController
@@ -32,6 +34,7 @@
  */
 class MediaViewController @Inject constructor(
     context: Context,
+    private val configurationController: ConfigurationController,
     private val mediaHostStatesManager: MediaHostStatesManager
 ) {
 
@@ -56,12 +59,14 @@
      * The ending location of the view where it ends when all animations and transitions have
      * finished
      */
+    @MediaLocation
     private var currentEndLocation: Int = -1
 
     /**
      * The ending location of the view where it ends when all animations and transitions have
      * finished
      */
+    @MediaLocation
     private var currentStartLocation: Int = -1
 
     /**
@@ -91,10 +96,31 @@
     var currentHeight: Int = 0
 
     /**
+     * A callback for RTL config changes
+     */
+    private val configurationListener = object : ConfigurationController.ConfigurationListener {
+        override fun onConfigChanged(newConfig: Configuration?) {
+            // Because the TransitionLayout is not always attached (and calculates/caches layout
+            // results regardless of attach state), we have to force the layoutDirection of the view
+            // to the correct value for the user's current locale to ensure correct recalculation
+            // when/after calling refreshState()
+            newConfig?.apply {
+                if (transitionLayout?.rawLayoutDirection != layoutDirection) {
+                    transitionLayout?.layoutDirection = layoutDirection
+                    refreshState()
+                }
+            }
+        }
+    }
+
+    /**
      * A callback for media state changes
      */
     val stateCallback = object : MediaHostStatesManager.Callback {
-        override fun onHostStateChanged(location: Int, mediaHostState: MediaHostState) {
+        override fun onHostStateChanged(
+            @MediaLocation location: Int,
+            mediaHostState: MediaHostState
+        ) {
             if (location == currentEndLocation || location == currentStartLocation) {
                 setCurrentState(currentStartLocation,
                         currentEndLocation,
@@ -125,6 +151,7 @@
             currentHeight = height
             sizeChangedListener.invoke()
         }
+        configurationController.addCallback(configurationListener)
     }
 
     /**
@@ -132,6 +159,7 @@
      */
     fun onDestroy() {
         mediaHostStatesManager.removeController(this)
+        configurationController.removeCallback(configurationListener)
     }
 
     private fun ensureAllMeasurements() {
@@ -346,7 +374,7 @@
             // Let's clear all of our measurements and recreate them!
             viewStates.clear()
             setCurrentState(currentStartLocation, currentEndLocation, currentTransitionProgress,
-                    applyImmediately = false)
+                    applyImmediately = true)
         }
         firstRefresh = false
     }
diff --git a/packages/SystemUI/src/com/android/systemui/media/PlayerViewHolder.kt b/packages/SystemUI/src/com/android/systemui/media/PlayerViewHolder.kt
index 9ede083..600fdc2 100644
--- a/packages/SystemUI/src/com/android/systemui/media/PlayerViewHolder.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/PlayerViewHolder.kt
@@ -48,6 +48,7 @@
 
     // Seek bar
     val seekBar = itemView.requireViewById<SeekBar>(R.id.media_progress_bar)
+    val progressTimes = itemView.requireViewById<ViewGroup>(R.id.notification_media_progress_time)
     val elapsedTimeView = itemView.requireViewById<TextView>(R.id.media_elapsed_time)
     val totalTimeView = itemView.requireViewById<TextView>(R.id.media_total_time)
 
@@ -93,8 +94,16 @@
          * @param parent Parent of inflated view.
          */
         @JvmStatic fun create(inflater: LayoutInflater, parent: ViewGroup): PlayerViewHolder {
-            val v = inflater.inflate(R.layout.media_view, parent, false)
-            return PlayerViewHolder(v)
+            val mediaView = inflater.inflate(R.layout.media_view, parent, false)
+            // Because this media view (a TransitionLayout) is used to measure and layout the views
+            // in various states before being attached to its parent, we can't depend on the default
+            // LAYOUT_DIRECTION_INHERIT to correctly resolve the ltr direction.
+            mediaView.layoutDirection = View.LAYOUT_DIRECTION_LOCALE
+            return PlayerViewHolder(mediaView).apply {
+                // Media playback is in the direction of tape, not time, so it stays LTR
+                seekBar.layoutDirection = View.LAYOUT_DIRECTION_LTR
+                progressTimes.layoutDirection = View.LAYOUT_DIRECTION_LTR
+            }
         }
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/media/SeekBarObserver.kt b/packages/SystemUI/src/com/android/systemui/media/SeekBarObserver.kt
index 1b9bbdd..c2631c9 100644
--- a/packages/SystemUI/src/com/android/systemui/media/SeekBarObserver.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/SeekBarObserver.kt
@@ -36,12 +36,11 @@
     /** Updates seek bar views when the data model changes. */
     @UiThread
     override fun onChanged(data: SeekBarViewModel.Progress) {
-        val previouslyEnabled = holder.seekBar.isEnabled
         if (!data.enabled) {
-            holder.seekBar.setEnabled(false)
-            if (previouslyEnabled) {
+            if (holder.seekBar.maxHeight != seekBarDisabledHeight) {
                 holder.seekBar.maxHeight = seekBarDisabledHeight
             }
+            holder.seekBar.setEnabled(false)
             holder.seekBar.getThumb().setAlpha(0)
             holder.seekBar.setProgress(0)
             holder.elapsedTimeView.setText("")
@@ -52,12 +51,8 @@
         holder.seekBar.getThumb().setAlpha(if (data.seekAvailable) 255 else 0)
         holder.seekBar.setEnabled(data.seekAvailable)
 
-        if (previouslyEnabled != holder.seekBar.isEnabled) {
-            holder.seekBar.maxHeight = if (holder.seekBar.isEnabled) {
-                seekBarDefaultMaxHeight
-            } else {
-                seekBarDisabledHeight
-            }
+        if (holder.seekBar.maxHeight != seekBarDefaultMaxHeight) {
+            holder.seekBar.maxHeight = seekBarDefaultMaxHeight
         }
 
         data.elapsedTime?.let {
diff --git a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
index 821144a..71e7883 100644
--- a/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
+++ b/packages/SystemUI/src/com/android/systemui/settings/BrightnessController.java
@@ -443,14 +443,10 @@
             max = mMaximumBacklight;
         }
         // convertGammaToLinearFloat returns 0-1
-        if (BrightnessSynchronizer.brightnessFloatToInt(mContext, brightnessValue)
-                == BrightnessSynchronizer.brightnessFloatToInt(mContext,
+        if (BrightnessSynchronizer.floatEquals(brightnessValue,
                 convertGammaToLinearFloat(mControl.getValue(), min, max))) {
-            // If we have more resolution on the slider than we do in the actual setting, then
-            // multiple slider positions will map to the same setting value. Thus, if we see a
-            // setting value here that maps to the current slider position, we don't bother to
-            // calculate the new slider position since it may differ and look like a brightness
-            // change to the user even though it isn't one.
+            // If the value in the slider is equal to the value on the current brightness
+            // then the slider does not need to animate, since the brightness will not change.
             return;
         }
         // Returns GAMMA_SPACE_MIN - GAMMA_SPACE_MAX
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
index 03a0d93..ad31220 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/Divider.java
@@ -387,6 +387,7 @@
         }
         // Always set this because we could be entering split when mMinimized is already true
         wct.setFocusable(mSplits.mPrimary.token, !mMinimized);
+        boolean onlyFocusable = true;
 
         // Update home-stack resizability
         final boolean homeResizableChanged = mHomeStackResizable != homeStackResizable;
@@ -395,6 +396,7 @@
             if (isDividerVisible()) {
                 WindowManagerProxy.applyHomeTasksMinimized(
                         mSplitLayout, mSplits.mSecondary.token, wct);
+                onlyFocusable = false;
             }
         }
 
@@ -416,7 +418,15 @@
             }
         }
         updateTouchable();
-        mWindowManagerProxy.applySyncTransaction(wct);
+        if (onlyFocusable) {
+            // If we are only setting focusability, a sync transaction isn't necessary (in fact it
+            // can interrupt other animations), so see if it can be submitted on pending instead.
+            if (!mSplits.mDivider.getWmProxy().queueSyncTransactionIfWaiting(wct)) {
+                WindowOrganizer.applyTransaction(wct);
+            }
+        } else {
+            mWindowManagerProxy.applySyncTransaction(wct);
+        }
     }
 
     void setAdjustedForIme(boolean adjustedForIme) {
diff --git a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerImeController.java b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerImeController.java
index d782a3ca..47c8c0a 100644
--- a/packages/SystemUI/src/com/android/systemui/stackdivider/DividerImeController.java
+++ b/packages/SystemUI/src/com/android/systemui/stackdivider/DividerImeController.java
@@ -29,6 +29,7 @@
 import android.window.TaskOrganizer;
 import android.window.WindowContainerToken;
 import android.window.WindowContainerTransaction;
+import android.window.WindowOrganizer;
 
 import androidx.annotation.Nullable;
 
@@ -173,47 +174,51 @@
     }
 
     private void updateImeAdjustState() {
-        // Reposition the server's secondary split position so that it evaluates
-        // insets properly.
-        WindowContainerTransaction wct = new WindowContainerTransaction();
-        final SplitDisplayLayout splitLayout = getLayout();
-        if (mTargetAdjusted) {
-            splitLayout.updateAdjustedBounds(mShownTop, mHiddenTop, mShownTop);
-            wct.setBounds(mSplits.mSecondary.token, splitLayout.mAdjustedSecondary);
-            // "Freeze" the configuration size so that the app doesn't get a config
-            // or relaunch. This is required because normally nav-bar contributes
-            // to configuration bounds (via nondecorframe).
-            Rect adjustAppBounds = new Rect(mSplits.mSecondary.configuration
-                    .windowConfiguration.getAppBounds());
-            adjustAppBounds.offset(0, splitLayout.mAdjustedSecondary.top
-                    - splitLayout.mSecondary.top);
-            wct.setAppBounds(mSplits.mSecondary.token, adjustAppBounds);
-            wct.setScreenSizeDp(mSplits.mSecondary.token,
-                    mSplits.mSecondary.configuration.screenWidthDp,
-                    mSplits.mSecondary.configuration.screenHeightDp);
+        if (mAdjusted != mTargetAdjusted) {
+            // Reposition the server's secondary split position so that it evaluates
+            // insets properly.
+            WindowContainerTransaction wct = new WindowContainerTransaction();
+            final SplitDisplayLayout splitLayout = getLayout();
+            if (mTargetAdjusted) {
+                splitLayout.updateAdjustedBounds(mShownTop, mHiddenTop, mShownTop);
+                wct.setBounds(mSplits.mSecondary.token, splitLayout.mAdjustedSecondary);
+                // "Freeze" the configuration size so that the app doesn't get a config
+                // or relaunch. This is required because normally nav-bar contributes
+                // to configuration bounds (via nondecorframe).
+                Rect adjustAppBounds = new Rect(mSplits.mSecondary.configuration
+                        .windowConfiguration.getAppBounds());
+                adjustAppBounds.offset(0, splitLayout.mAdjustedSecondary.top
+                        - splitLayout.mSecondary.top);
+                wct.setAppBounds(mSplits.mSecondary.token, adjustAppBounds);
+                wct.setScreenSizeDp(mSplits.mSecondary.token,
+                        mSplits.mSecondary.configuration.screenWidthDp,
+                        mSplits.mSecondary.configuration.screenHeightDp);
 
-            wct.setBounds(mSplits.mPrimary.token, splitLayout.mAdjustedPrimary);
-            adjustAppBounds = new Rect(mSplits.mPrimary.configuration
-                    .windowConfiguration.getAppBounds());
-            adjustAppBounds.offset(0, splitLayout.mAdjustedPrimary.top
-                    - splitLayout.mPrimary.top);
-            wct.setAppBounds(mSplits.mPrimary.token, adjustAppBounds);
-            wct.setScreenSizeDp(mSplits.mPrimary.token,
-                    mSplits.mPrimary.configuration.screenWidthDp,
-                    mSplits.mPrimary.configuration.screenHeightDp);
-        } else {
-            wct.setBounds(mSplits.mSecondary.token, splitLayout.mSecondary);
-            wct.setAppBounds(mSplits.mSecondary.token, null);
-            wct.setScreenSizeDp(mSplits.mSecondary.token,
-                    SCREEN_WIDTH_DP_UNDEFINED, SCREEN_HEIGHT_DP_UNDEFINED);
-            wct.setBounds(mSplits.mPrimary.token, splitLayout.mPrimary);
-            wct.setAppBounds(mSplits.mPrimary.token, null);
-            wct.setScreenSizeDp(mSplits.mPrimary.token,
-                    SCREEN_WIDTH_DP_UNDEFINED, SCREEN_HEIGHT_DP_UNDEFINED);
+                wct.setBounds(mSplits.mPrimary.token, splitLayout.mAdjustedPrimary);
+                adjustAppBounds = new Rect(mSplits.mPrimary.configuration
+                        .windowConfiguration.getAppBounds());
+                adjustAppBounds.offset(0, splitLayout.mAdjustedPrimary.top
+                        - splitLayout.mPrimary.top);
+                wct.setAppBounds(mSplits.mPrimary.token, adjustAppBounds);
+                wct.setScreenSizeDp(mSplits.mPrimary.token,
+                        mSplits.mPrimary.configuration.screenWidthDp,
+                        mSplits.mPrimary.configuration.screenHeightDp);
+            } else {
+                wct.setBounds(mSplits.mSecondary.token, splitLayout.mSecondary);
+                wct.setAppBounds(mSplits.mSecondary.token, null);
+                wct.setScreenSizeDp(mSplits.mSecondary.token,
+                        SCREEN_WIDTH_DP_UNDEFINED, SCREEN_HEIGHT_DP_UNDEFINED);
+                wct.setBounds(mSplits.mPrimary.token, splitLayout.mPrimary);
+                wct.setAppBounds(mSplits.mPrimary.token, null);
+                wct.setScreenSizeDp(mSplits.mPrimary.token,
+                        SCREEN_WIDTH_DP_UNDEFINED, SCREEN_HEIGHT_DP_UNDEFINED);
+            }
+
+            if (!mSplits.mDivider.getWmProxy().queueSyncTransactionIfWaiting(wct)) {
+                WindowOrganizer.applyTransaction(wct);
+            }
         }
 
-        mSplits.mDivider.getWmProxy().applySyncTransaction(wct);
-
         // Update all the adjusted-for-ime states
         if (!mPaused) {
             final DividerView view = getView();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java
index 3377144..423f85f 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotificationEntry.java
@@ -178,6 +178,7 @@
     private int mBucket = BUCKET_ALERTING;
     @Nullable private Long mPendingAnimationDuration;
     private boolean mIsMarkedForUserTriggeredMovement;
+    private boolean mShelfIconVisible;
 
     /**
      * @param sbn the StatusBarNotification from system server
@@ -431,6 +432,7 @@
     //TODO: This will go away when we have a way to bind an entry to a row
     public void setRow(ExpandableNotificationRow row) {
         this.row = row;
+        updateShelfIconVisibility();
     }
 
     public ExpandableNotificationRowController getRowController() {
@@ -951,6 +953,18 @@
         return mIsMarkedForUserTriggeredMovement;
     }
 
+    /** Whether or not the icon for this notification is visible in the shelf. */
+    public void setShelfIconVisible(boolean shelfIconVisible) {
+        mShelfIconVisible = shelfIconVisible;
+        updateShelfIconVisibility();
+    }
+
+    private void updateShelfIconVisibility() {
+        if (row != null) {
+            row.setShelfIconVisible(mShelfIconVisible);
+        }
+    }
+
     /**
      * Mark this entry for movement triggered by a user action (ex: changing the priorirty of a
      * conversation). This can then be used for custom animations.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
index 5c802bd..df1de63 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/dagger/NotificationsModule.java
@@ -24,6 +24,7 @@
 import android.view.accessibility.AccessibilityManager;
 
 import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.UiEventLogger;
 import com.android.systemui.R;
 import com.android.systemui.bubbles.BubbleController;
 import com.android.systemui.dagger.qualifiers.Background;
@@ -116,7 +117,8 @@
             ChannelEditorDialogController channelEditorDialogController,
             CurrentUserContextTracker contextTracker,
             Provider<PriorityOnboardingDialogController.Builder> builderProvider,
-            BubbleController bubbleController) {
+            BubbleController bubbleController,
+            UiEventLogger uiEventLogger) {
         return new NotificationGutsManager(
                 context,
                 visualStabilityManager,
@@ -131,7 +133,8 @@
                 channelEditorDialogController,
                 contextTracker,
                 builderProvider,
-                bubbleController);
+                bubbleController,
+                uiEventLogger);
     }
 
     /** Provides an instance of {@link VisualStabilityManager} */
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt
index 011ad19..13f7a53 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt
@@ -96,13 +96,11 @@
         val shelfIcon = iconBuilder.createIconView(entry)
         shelfIcon.scaleType = ImageView.ScaleType.CENTER_INSIDE
 
-        shelfIcon.visibility = View.INVISIBLE
         // TODO: This doesn't belong here
         shelfIcon.setOnVisibilityChangedListener { newVisibility: Int ->
-            if (entry.row != null) {
-                entry.row.setShelfIconVisible(newVisibility == View.VISIBLE)
-            }
+            entry.setShelfIconVisible(newVisibility == View.VISIBLE)
         }
+        shelfIcon.visibility = View.INVISIBLE
 
         // Construct the aod icon view.
         val aodIcon = iconBuilder.createIconView(entry)
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/AppOpsInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/AppOpsInfo.java
index e445c9d..28c53dc 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/AppOpsInfo.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/AppOpsInfo.java
@@ -31,6 +31,7 @@
 import android.widget.TextView;
 
 import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.UiEventLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.systemui.R;
 
@@ -50,6 +51,7 @@
     private MetricsLogger mMetricsLogger;
     private OnSettingsClickListener mOnSettingsClickListener;
     private NotificationGuts mGutsContainer;
+    private UiEventLogger mUiEventLogger;
 
     private OnClickListener mOnOk = v -> {
         mGutsContainer.closeControls(v, false);
@@ -66,6 +68,7 @@
     public void bindGuts(final PackageManager pm,
             final OnSettingsClickListener onSettingsClick,
             final StatusBarNotification sbn,
+            final UiEventLogger uiEventLogger,
             ArraySet<Integer> activeOps) {
         mPkg = sbn.getPackageName();
         mSbn = sbn;
@@ -73,11 +76,13 @@
         mAppName = mPkg;
         mOnSettingsClickListener = onSettingsClick;
         mAppOps = activeOps;
+        mUiEventLogger = uiEventLogger;
 
         bindHeader();
         bindPrompt();
         bindButtons();
 
+        logUiEvent(NotificationAppOpsEvent.NOTIFICATION_APP_OPS_OPEN);
         mMetricsLogger = new MetricsLogger();
         mMetricsLogger.visibility(MetricsEvent.APP_OPS_GUTS, true);
     }
@@ -188,6 +193,7 @@
 
     @Override
     public boolean handleCloseControls(boolean save, boolean force) {
+        logUiEvent(NotificationAppOpsEvent.NOTIFICATION_APP_OPS_CLOSE);
         if (mMetricsLogger != null) {
             mMetricsLogger.visibility(MetricsEvent.APP_OPS_GUTS, false);
         }
@@ -198,4 +204,11 @@
     public int getActualHeight() {
         return getHeight();
     }
+
+    private void logUiEvent(NotificationAppOpsEvent event) {
+        if (mSbn != null) {
+            mUiEventLogger.logWithInstanceId(event,
+                    mSbn.getUid(), mSbn.getPackageName(), mSbn.getInstanceId());
+        }
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationAppOpsEvent.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationAppOpsEvent.java
new file mode 100644
index 0000000..c856245
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationAppOpsEvent.java
@@ -0,0 +1,41 @@
+/*
+ * 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;
+
+import com.android.internal.logging.UiEvent;
+import com.android.internal.logging.UiEventLogger;
+
+enum NotificationAppOpsEvent implements UiEventLogger.UiEventEnum {
+    @UiEvent(doc = "User opened app ops controls on a notification (for active "
+            + "privacy-sensitive permissions usage)")
+    NOTIFICATION_APP_OPS_OPEN(597),
+
+    @UiEvent(doc = "User closed app ops controls")
+    NOTIFICATION_APP_OPS_CLOSE(598),
+
+    @UiEvent(doc = "User clicked through to settings in app ops controls")
+    NOTIFICATION_APP_OPS_SETTINGS_CLICK(599);
+
+    private final int mId;
+    NotificationAppOpsEvent(int id) {
+        mId = id;
+    }
+    @Override public int getId() {
+        return mId;
+    }
+}
+
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationControlsEvent.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationControlsEvent.java
new file mode 100644
index 0000000..6833326
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationControlsEvent.java
@@ -0,0 +1,40 @@
+/*
+ * 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;
+
+import com.android.internal.logging.UiEvent;
+import com.android.internal.logging.UiEventLogger;
+
+enum NotificationControlsEvent implements UiEventLogger.UiEventEnum {
+    @UiEvent(doc = "The user opened the notification inline controls.")
+    NOTIFICATION_CONTROLS_OPEN(594),
+
+    @UiEvent(doc = "In notification inline controls, the user saved a notification channel "
+            + "importance change.")
+    NOTIFICATION_CONTROLS_SAVE_IMPORTANCE(595),
+
+    @UiEvent(doc = "The user closed the notification inline controls.")
+    NOTIFICATION_CONTROLS_CLOSE(596);
+
+    private final int mId;
+    NotificationControlsEvent(int id) {
+        mId = id;
+    }
+    @Override public int getId() {
+        return mId;
+    }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
index 8337cbe4..24883f5 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationGutsManager.java
@@ -41,6 +41,7 @@
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.UiEventLogger;
 import com.android.internal.logging.nano.MetricsProto;
 import com.android.settingslib.notification.ConversationIconFactory;
 import com.android.systemui.Dependency;
@@ -121,6 +122,7 @@
     private final ShortcutManager mShortcutManager;
     private final CurrentUserContextTracker mContextTracker;
     private final Provider<PriorityOnboardingDialogController.Builder> mBuilderProvider;
+    private final UiEventLogger mUiEventLogger;
 
     /**
      * Injected constructor. See {@link NotificationsModule}.
@@ -135,7 +137,8 @@
             ChannelEditorDialogController channelEditorDialogController,
             CurrentUserContextTracker contextTracker,
             Provider<PriorityOnboardingDialogController.Builder> builderProvider,
-            BubbleController bubbleController) {
+            BubbleController bubbleController,
+            UiEventLogger uiEventLogger) {
         mContext = context;
         mVisualStabilityManager = visualStabilityManager;
         mStatusBarLazy = statusBarLazy;
@@ -150,6 +153,7 @@
         mBuilderProvider = builderProvider;
         mChannelEditorDialogController = channelEditorDialogController;
         mBubbleController = bubbleController;
+        mUiEventLogger = uiEventLogger;
     }
 
     public void setUpWithPresenter(NotificationPresenter presenter,
@@ -315,12 +319,16 @@
 
         AppOpsInfo.OnSettingsClickListener onSettingsClick =
                 (View v, String pkg, int uid, ArraySet<Integer> ops) -> {
-            mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_OPS_GUTS_SETTINGS);
-            guts.resetFalsingCheck();
-            startAppOpsSettingsActivity(pkg, uid, ops, row);
+                    mUiEventLogger.logWithInstanceId(
+                            NotificationAppOpsEvent.NOTIFICATION_APP_OPS_SETTINGS_CLICK,
+                            sbn.getUid(), sbn.getPackageName(), sbn.getInstanceId());
+                    mMetricsLogger.action(MetricsProto.MetricsEvent.ACTION_OPS_GUTS_SETTINGS);
+                    guts.resetFalsingCheck();
+                    startAppOpsSettingsActivity(pkg, uid, ops, row);
         };
         if (!row.getEntry().mActiveAppOps.isEmpty()) {
-            appOpsInfoView.bindGuts(pmUser, onSettingsClick, sbn, row.getEntry().mActiveAppOps);
+            appOpsInfoView.bindGuts(pmUser, onSettingsClick, sbn, mUiEventLogger,
+                    row.getEntry().mActiveAppOps);
         }
     }
 
@@ -370,6 +378,7 @@
                 row.getEntry(),
                 onSettingsClick,
                 onAppSettingsClick,
+                mUiEventLogger,
                 mDeviceProvisionedController.isDeviceProvisioned(),
                 row.getIsNonblockable(),
                 mHighPriorityProvider.isHighPriority(row.getEntry()));
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java
index a131ebe..f0c93b1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationInfo.java
@@ -56,6 +56,7 @@
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.UiEventLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import com.android.systemui.Dependency;
 import com.android.systemui.R;
@@ -122,6 +123,7 @@
     private OnAppSettingsClickListener mAppSettingsClickListener;
     private NotificationGuts mGutsContainer;
     private Drawable mPkgIcon;
+    private UiEventLogger mUiEventLogger;
 
     @VisibleForTesting
     boolean mSkipPost = false;
@@ -182,6 +184,7 @@
             NotificationEntry entry,
             OnSettingsClickListener onSettingsClick,
             OnAppSettingsClickListener onAppSettingsClick,
+            UiEventLogger uiEventLogger,
             boolean isDeviceProvisioned,
             boolean isNonblockable,
             boolean wasShownHighPriority)
@@ -205,6 +208,7 @@
         mAppUid = mSbn.getUid();
         mDelegatePkg = mSbn.getOpPkg();
         mIsDeviceProvisioned = isDeviceProvisioned;
+        mUiEventLogger = uiEventLogger;
 
         int numTotalChannels = mINotificationManager.getNumNotificationChannelsForPackage(
                 pkg, mAppUid, false /* includeDeleted */);
@@ -223,6 +227,7 @@
 
         bindInlineControls();
 
+        logUiEvent(NotificationControlsEvent.NOTIFICATION_CONTROLS_OPEN);
         mMetricsLogger.write(notificationControlsLogMaker());
     }
 
@@ -397,6 +402,7 @@
      */
     private void updateImportance() {
         if (mChosenImportance != null) {
+            logUiEvent(NotificationControlsEvent.NOTIFICATION_CONTROLS_SAVE_IMPORTANCE);
             mMetricsLogger.write(importanceChangeLogMaker());
 
             int newImportance = mChosenImportance;
@@ -483,6 +489,7 @@
 
         bindInlineControls();
 
+        logUiEvent(NotificationControlsEvent.NOTIFICATION_CONTROLS_CLOSE);
         mMetricsLogger.write(notificationControlsLogMaker().setType(MetricsEvent.TYPE_CLOSE));
     }
 
@@ -627,6 +634,13 @@
         }
     }
 
+    private void logUiEvent(NotificationControlsEvent event) {
+        if (mSbn != null) {
+            mUiEventLogger.logWithInstanceId(event,
+                    mSbn.getUid(), mSbn.getPackageName(), mSbn.getInstanceId());
+        }
+    }
+
     /**
      * Returns a LogMaker with all available notification information.
      * Caller should set category, type, and maybe subtype, before passing it to mMetricsLogger.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java
index b4220f1..11e698b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/AmbientState.java
@@ -83,6 +83,8 @@
     private float mDozeAmount = 0.0f;
     private HeadsUpManager mHeadUpManager;
     private Runnable mOnPulseHeightChangedListener;
+    private ExpandableNotificationRow mTrackedHeadsUpRow;
+    private float mAppearFraction;
 
     public AmbientState(
             Context context,
@@ -543,4 +545,27 @@
     public Runnable getOnPulseHeightChangedListener() {
         return mOnPulseHeightChangedListener;
     }
+
+    public void setTrackedHeadsUpRow(ExpandableNotificationRow row) {
+        mTrackedHeadsUpRow = row;
+    }
+
+    /**
+     * Returns the currently tracked heads up row, if there is one and it is currently above the
+     * shelf (still appearing).
+     */
+    public ExpandableNotificationRow getTrackedHeadsUpRow() {
+        if (mTrackedHeadsUpRow == null || !mTrackedHeadsUpRow.isAboveShelf()) {
+            return null;
+        }
+        return mTrackedHeadsUpRow;
+    }
+
+    public void setAppearFraction(float appearFraction) {
+        mAppearFraction = appearFraction;
+    }
+
+    public float getAppearFraction() {
+        return mAppearFraction;
+    }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
index 8ebadfb..b9d31a9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@@ -535,6 +535,7 @@
     private float mLastSentAppear;
     private float mLastSentExpandedHeight;
     private boolean mWillExpand;
+    private int mGapHeight;
 
     private int mWaterfallTopInset;
 
@@ -1060,6 +1061,7 @@
 
         Resources res = context.getResources();
         mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height);
+        mGapHeight = res.getDimensionPixelSize(R.dimen.notification_section_divider_height);
         mStackScrollAlgorithm.initView(context);
         mAmbientState.reload(context);
         mPaddingBetweenElements = Math.max(1,
@@ -1420,14 +1422,12 @@
                 // start
                 translationY = height - appearStartPosition + getExpandTranslationStart();
             }
+            stackHeight = (int) (height - translationY);
             if (isHeadsUpTransition()) {
-                stackHeight =
-                        getFirstVisibleSection().getFirstVisibleChild().getPinnedHeadsUpHeight();
                 translationY = MathUtils.lerp(mHeadsUpInset - mTopPadding, 0, appearFraction);
-            } else {
-                stackHeight = (int) (height - translationY);
             }
         }
+        mAmbientState.setAppearFraction(appearFraction);
         if (stackHeight != mCurrentStackHeight) {
             mCurrentStackHeight = stackHeight;
             updateAlgorithmHeightAndPadding();
@@ -1545,17 +1545,18 @@
      */
     @ShadeViewRefactor(RefactorComponent.COORDINATOR)
     private float getAppearEndPosition() {
-        int appearPosition;
-        int notGoneChildCount = getNotGoneChildCount();
-        if (mEmptyShadeView.getVisibility() == GONE && notGoneChildCount != 0) {
+        int appearPosition = 0;
+        int visibleNotifCount = getVisibleNotificationCount();
+        if (mEmptyShadeView.getVisibility() == GONE && visibleNotifCount > 0) {
             if (isHeadsUpTransition()
                     || (mHeadsUpManager.hasPinnedHeadsUp() && !mAmbientState.isDozing())) {
-                appearPosition = getTopHeadsUpPinnedHeight();
-            } else {
-                appearPosition = 0;
-                if (notGoneChildCount >= 1 && mShelf.getVisibility() != GONE) {
-                    appearPosition += mShelf.getIntrinsicHeight();
+                if (mShelf.getVisibility() != GONE && visibleNotifCount > 1) {
+                    appearPosition += mShelf.getIntrinsicHeight() + mPaddingBetweenElements;
                 }
+                appearPosition += getTopHeadsUpPinnedHeight()
+                        + getPositionInLinearLayout(mAmbientState.getTrackedHeadsUpRow());
+            } else if (mShelf.getVisibility() != GONE) {
+                appearPosition += mShelf.getIntrinsicHeight();
             }
         } else {
             appearPosition = mEmptyShadeView.getHeight();
@@ -1565,9 +1566,7 @@
 
     @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
     private boolean isHeadsUpTransition() {
-        NotificationSection firstVisibleSection = getFirstVisibleSection();
-        return mTrackingHeadsUp && firstVisibleSection != null
-                && firstVisibleSection.getFirstVisibleChild().isAboveShelf();
+        return mAmbientState.getTrackedHeadsUpRow() != null;
     }
 
     /**
@@ -2975,7 +2974,16 @@
     @ShadeViewRefactor(RefactorComponent.COORDINATOR)
     public int getLayoutMinHeight() {
         if (isHeadsUpTransition()) {
-            return getTopHeadsUpPinnedHeight();
+            ExpandableNotificationRow trackedHeadsUpRow = mAmbientState.getTrackedHeadsUpRow();
+            if (trackedHeadsUpRow.isAboveShelf()) {
+                int hunDistance = (int) MathUtils.lerp(
+                        0,
+                        getPositionInLinearLayout(trackedHeadsUpRow),
+                        mAmbientState.getAppearFraction());
+                return getTopHeadsUpPinnedHeight() + hunDistance;
+            } else {
+                return getTopHeadsUpPinnedHeight();
+            }
         }
         return mShelf.getVisibility() == GONE ? 0 : mShelf.getIntrinsicHeight();
     }
@@ -5093,8 +5101,10 @@
     }
 
     @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
-    public int getFooterViewHeight() {
-        return mFooterView == null ? 0 : mFooterView.getHeight() + mPaddingBetweenElements;
+    public int getFooterViewHeightWithPadding() {
+        return mFooterView == null ? 0 : mFooterView.getHeight()
+                + mPaddingBetweenElements
+                + mGapHeight;
     }
 
     @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
@@ -5295,6 +5305,7 @@
 
     @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
     public void setTrackingHeadsUp(ExpandableNotificationRow row) {
+        mAmbientState.setTrackedHeadsUpRow(row);
         mTrackingHeadsUp = row != null;
         mRoundnessManager.setTrackingHeadsUp(row);
     }
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
index a4598e9..541c784 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/StackScrollAlgorithm.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.content.res.Resources;
 import android.util.Log;
+import android.util.MathUtils;
 import android.view.View;
 import android.view.ViewGroup;
 
@@ -441,7 +442,7 @@
         } else if (isEmptyShadeView) {
             childViewState.yTranslation = ambientState.getInnerHeight() - childHeight
                     + ambientState.getStackTranslation() * 0.25f;
-        } else {
+        } else if (child != ambientState.getTrackedHeadsUpRow()) {
             clampPositionToShelf(child, childViewState, ambientState);
         }
 
@@ -539,6 +540,19 @@
     private void updateHeadsUpStates(StackScrollAlgorithmState algorithmState,
             AmbientState ambientState) {
         int childCount = algorithmState.visibleChildren.size();
+
+        // Move the tracked heads up into position during the appear animation, by interpolating
+        // between the HUN inset (where it will appear as a HUN) and the end position in the shade
+        ExpandableNotificationRow trackedHeadsUpRow = ambientState.getTrackedHeadsUpRow();
+        if (trackedHeadsUpRow != null) {
+            ExpandableViewState childState = trackedHeadsUpRow.getViewState();
+            if (childState != null) {
+                float endPosition = childState.yTranslation - ambientState.getStackTranslation();
+                childState.yTranslation = MathUtils.lerp(
+                        mHeadsUpInset, endPosition, ambientState.getAppearFraction());
+            }
+        }
+
         ExpandableNotificationRow topHeadsUpEntry = null;
         for (int i = 0; i < childCount; i++) {
             View child = algorithmState.visibleChildren.get(i);
@@ -561,7 +575,7 @@
                         && !row.showingPulsing()) {
                     // Ensure that the heads up is always visible even when scrolled off
                     clampHunToTop(ambientState, row, childState);
-                    if (i == 0 && row.isAboveShelf()) {
+                    if (isTopEntry && row.isAboveShelf()) {
                         // the first hun can't get off screen.
                         clampHunToMaxTranslation(ambientState, row, childState);
                         childState.hidden = false;
@@ -636,9 +650,13 @@
             return;
         }
 
+        ExpandableNotificationRow trackedHeadsUpRow = ambientState.getTrackedHeadsUpRow();
+        boolean isBeforeTrackedHeadsUp = trackedHeadsUpRow != null
+                && mHostView.indexOfChild(child) < mHostView.indexOfChild(trackedHeadsUpRow);
+
         int shelfStart = ambientState.getInnerHeight()
                 - ambientState.getShelf().getIntrinsicHeight();
-        if (ambientState.isAppearing() && !child.isAboveShelf()) {
+        if (ambientState.isAppearing() && !child.isAboveShelf() && !isBeforeTrackedHeadsUp) {
             // Don't show none heads-up notifications while in appearing phase.
             childViewState.yTranslation = Math.max(childViewState.yTranslation, shelfStart);
         }
@@ -695,7 +713,8 @@
             }
             childViewState.zTranslation = baseZ
                     + childrenOnTop * zDistanceBetweenElements;
-        } else if (i == 0 && (child.isAboveShelf() || child.showingPulsing())) {
+        } else if (child == ambientState.getTrackedHeadsUpRow()
+                || (i == 0 && (child.isAboveShelf() || child.showingPulsing()))) {
             // In case this is a new view that has never been measured before, we don't want to
             // elevate if we are currently expanded more then the notification
             int shelfHeight = ambientState.getShelf() == null ? 0 :
@@ -703,7 +722,7 @@
             float shelfStart = ambientState.getInnerHeight()
                     - shelfHeight + ambientState.getTopPadding()
                     + ambientState.getStackTranslation();
-            float notificationEnd = childViewState.yTranslation + child.getPinnedHeadsUpHeight()
+            float notificationEnd = childViewState.yTranslation + child.getIntrinsicHeight()
                     + mPaddingBetweenElements;
             if (shelfStart > notificationEnd) {
                 childViewState.zTranslation = baseZ;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
index e720d82..f2eec39 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelViewController.java
@@ -443,6 +443,7 @@
      */
     private boolean mDelayShowingKeyguardStatusBar;
 
+    private boolean mAnimatingQS;
     private int mOldLayoutDirection;
 
     private View.AccessibilityDelegate mAccessibilityDelegate = new View.AccessibilityDelegate() {
@@ -1860,6 +1861,7 @@
 
             @Override
             public void onAnimationEnd(Animator animation) {
+                mAnimatingQS = false;
                 notifyExpandingFinished();
                 mNotificationStackScroller.resetCheckSnoozeLeavebehind();
                 mQsExpansionAnimator = null;
@@ -1868,6 +1870,9 @@
                 }
             }
         });
+        // Let's note that we're animating QS. Moving the animator here will cancel it immediately,
+        // so we need a separate flag.
+        mAnimatingQS = true;
         animator.start();
         mQsExpansionAnimator = animator;
         mQsAnimatorExpand = expanding;
@@ -2220,6 +2225,9 @@
         mNotificationStackScroller.onExpansionStarted();
         mIsExpanding = true;
         mQsExpandedWhenExpandingStarted = mQsFullyExpanded;
+        mMediaHierarchyManager.setCollapsingShadeFromQS(mQsExpandedWhenExpandingStarted &&
+                /* We also start expanding when flinging closed Qs. Let's exclude that */
+                !mAnimatingQS);
         if (mQsExpanded) {
             onQsExpansionStarted();
         }
@@ -2236,6 +2244,7 @@
         mHeadsUpManager.onExpandingFinished();
         mConversationNotificationManager.onNotificationPanelExpandStateChanged(isFullyCollapsed());
         mIsExpanding = false;
+        mMediaHierarchyManager.setCollapsingShadeFromQS(false);
         if (isFullyCollapsed()) {
             DejankUtils.postAfterTraversal(new Runnable() {
                 @Override
@@ -2397,8 +2406,8 @@
     }
 
     @Override
-    protected int getClearAllHeight() {
-        return mNotificationStackScroller.getFooterViewHeight();
+    protected int getClearAllHeightWithPadding() {
+        return mNotificationStackScroller.getFooterViewHeightWithPadding();
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelViewController.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelViewController.java
index a902e1b..caddc4a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelViewController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PanelViewController.java
@@ -537,9 +537,9 @@
         // the animation only to the last notification, and then jump to the maximum panel height so
         // clear all just fades in and the decelerating motion is towards the last notification.
         final boolean clearAllExpandHack = expand &&
-                shouldExpandToTopOfClearAll(getMaxPanelHeight() - getClearAllHeight());
+                shouldExpandToTopOfClearAll(getMaxPanelHeight() - getClearAllHeightWithPadding());
         if (clearAllExpandHack) {
-            target = getMaxPanelHeight() - getClearAllHeight();
+            target = getMaxPanelHeight() - getClearAllHeightWithPadding();
         }
         if (target == mExpandedHeight || getOverExpansionAmount() > 0f && expand) {
             notifyExpandingFinished();
@@ -1030,9 +1030,9 @@
     protected abstract boolean isClearAllVisible();
 
     /**
-     * @return the height of the clear all button, in pixels
+     * @return the height of the clear all button, in pixels including padding
      */
-    protected abstract int getClearAllHeight();
+    protected abstract int getClearAllHeightWithPadding();
 
     public void setHeadsUpManager(HeadsUpManagerPhone headsUpManager) {
         mHeadsUpManager = headsUpManager;
diff --git a/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt b/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt
index e5b126d..3c0a23a 100644
--- a/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt
@@ -150,15 +150,10 @@
     }
 
     override fun dispatchDraw(canvas: Canvas?) {
-        val clip = !boundsRect.isEmpty
-        if (clip) {
-            canvas?.save()
-            canvas?.clipRect(boundsRect)
-        }
+        canvas?.save()
+        canvas?.clipRect(boundsRect)
         super.dispatchDraw(canvas)
-        if (clip) {
-            canvas?.restore()
-        }
+        canvas?.restore()
     }
 
     private fun updateBounds() {
diff --git a/packages/SystemUI/src/com/android/systemui/util/animation/UniqueObjectHostView.kt b/packages/SystemUI/src/com/android/systemui/util/animation/UniqueObjectHostView.kt
index 5b6444d..d6e7a8b 100644
--- a/packages/SystemUI/src/com/android/systemui/util/animation/UniqueObjectHostView.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/animation/UniqueObjectHostView.kt
@@ -70,7 +70,10 @@
     }
 
     override fun addView(child: View?, index: Int, params: ViewGroup.LayoutParams?) {
-        if (child?.measuredWidth == 0 || measuredWidth == 0 || child?.requiresRemeasuring == true) {
+        if (child == null) {
+            throw IllegalArgumentException("child must be non-null")
+        }
+        if (child.measuredWidth == 0 || measuredWidth == 0 || child.requiresRemeasuring == true) {
             super.addView(child, index, params)
             return
         }
@@ -78,11 +81,13 @@
         // right size when being attached to this view
         invalidate()
         addViewInLayout(child, index, params, true /* preventRequestLayout */)
+        // RTL properties are normally resolved in onMeasure(), which we are intentionally skipping
+        child.resolveRtlPropertiesIfNeeded()
         val left = paddingLeft
         val top = paddingTop
         val paddingHorizontal = paddingStart + paddingEnd
         val paddingVertical = paddingTop + paddingBottom
-        child!!.layout(left,
+        child.layout(left,
                 top,
                 left + measuredWidth - paddingHorizontal,
                 top + measuredHeight - paddingVertical)
diff --git a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
index 73aaeff..1cdc02f 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/doze/DozeTriggersTest.java
@@ -41,12 +41,10 @@
 import com.android.systemui.broadcast.BroadcastDispatcher;
 import com.android.systemui.dock.DockManager;
 import com.android.systemui.statusbar.phone.DozeParameters;
-import com.android.systemui.util.concurrency.FakeExecutor;
 import com.android.systemui.util.sensors.AsyncSensorManager;
 import com.android.systemui.util.sensors.FakeProximitySensor;
 import com.android.systemui.util.sensors.FakeSensorManager;
 import com.android.systemui.util.sensors.ProximitySensor;
-import com.android.systemui.util.time.FakeSystemClock;
 import com.android.systemui.util.wakelock.WakeLock;
 import com.android.systemui.util.wakelock.WakeLockFake;
 
@@ -72,11 +70,12 @@
     private BroadcastDispatcher mBroadcastDispatcher;
     @Mock
     private DockManager mDockManager;
+    @Mock
+    private ProximitySensor.ProximityCheck mProximityCheck;
     private DozeTriggers mTriggers;
     private FakeSensorManager mSensors;
     private Sensor mTapSensor;
     private FakeProximitySensor mProximitySensor;
-    private FakeExecutor mFakeExecutor = new FakeExecutor(new FakeSystemClock());
 
     @Before
     public void setUp() throws Exception {
@@ -91,8 +90,8 @@
         mProximitySensor = new FakeProximitySensor(getContext().getResources(), asyncSensorManager);
 
         mTriggers = new DozeTriggers(mContext, mMachine, mHost, mAlarmManager, config, parameters,
-                asyncSensorManager, mFakeExecutor, wakeLock, true,
-                mDockManager, mProximitySensor, mock(DozeLog.class), mBroadcastDispatcher);
+                asyncSensorManager, wakeLock, true, mDockManager, mProximitySensor,
+                mProximityCheck, mock(DozeLog.class), mBroadcastDispatcher);
         waitForSensorManager();
     }
 
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/SeekBarObserverTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/SeekBarObserverTest.kt
index 75018df..e9a0a40 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/SeekBarObserverTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/SeekBarObserverTest.kt
@@ -22,6 +22,7 @@
 import android.widget.SeekBar
 import android.widget.TextView
 import androidx.test.filters.SmallTest
+import com.android.systemui.R
 import com.android.systemui.SysuiTestCase
 import com.google.common.truth.Truth.assertThat
 import org.junit.Before
@@ -36,6 +37,9 @@
 @TestableLooper.RunWithLooper
 public class SeekBarObserverTest : SysuiTestCase() {
 
+    private val disabledHeight = 1
+    private val enabledHeight = 2
+
     private lateinit var observer: SeekBarObserver
     @Mock private lateinit var mockHolder: PlayerViewHolder
     private lateinit var seekBarView: SeekBar
@@ -45,12 +49,19 @@
     @Before
     fun setUp() {
         mockHolder = mock(PlayerViewHolder::class.java)
+
+        context.orCreateTestableResources
+            .addOverride(R.dimen.qs_media_enabled_seekbar_height, enabledHeight)
+        context.orCreateTestableResources
+            .addOverride(R.dimen.qs_media_disabled_seekbar_height, disabledHeight)
+
         seekBarView = SeekBar(context)
         elapsedTimeView = TextView(context)
         totalTimeView = TextView(context)
         whenever(mockHolder.seekBar).thenReturn(seekBarView)
         whenever(mockHolder.elapsedTimeView).thenReturn(elapsedTimeView)
         whenever(mockHolder.totalTimeView).thenReturn(totalTimeView)
+
         observer = SeekBarObserver(mockHolder)
     }
 
@@ -60,11 +71,12 @@
         val isEnabled = false
         val data = SeekBarViewModel.Progress(isEnabled, false, null, null)
         observer.onChanged(data)
-        // THEN seek bar shows just a line with no text
+        // THEN seek bar shows just a thin line with no text
         assertThat(seekBarView.isEnabled()).isFalse()
         assertThat(seekBarView.getThumb().getAlpha()).isEqualTo(0)
         assertThat(elapsedTimeView.getText()).isEqualTo("")
         assertThat(totalTimeView.getText()).isEqualTo("")
+        assertThat(seekBarView.maxHeight).isEqualTo(disabledHeight)
     }
 
     @Test
@@ -73,10 +85,11 @@
         val isEnabled = true
         val data = SeekBarViewModel.Progress(isEnabled, true, 3000, 12000)
         observer.onChanged(data)
-        // THEN seek bar is visible
+        // THEN seek bar is visible and thick
         assertThat(seekBarView.getVisibility()).isEqualTo(View.VISIBLE)
         assertThat(elapsedTimeView.getVisibility()).isEqualTo(View.VISIBLE)
         assertThat(totalTimeView.getVisibility()).isEqualTo(View.VISIBLE)
+        assertThat(seekBarView.maxHeight).isEqualTo(enabledHeight)
     }
 
     @Test
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/AppOpsInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/AppOpsInfoTest.java
index ec73a75..43d8b50 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/AppOpsInfoTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/AppOpsInfoTest.java
@@ -49,6 +49,7 @@
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import com.android.internal.logging.testing.UiEventLoggerFake;
 import com.android.systemui.R;
 import com.android.systemui.SysuiTestCase;
 
@@ -69,6 +70,7 @@
     private final PackageManager mMockPackageManager = mock(PackageManager.class);
     private final NotificationGuts mGutsParent = mock(NotificationGuts.class);
     private StatusBarNotification mSbn;
+    private UiEventLoggerFake mUiEventLogger = new UiEventLoggerFake();
 
     @Before
     public void setUp() throws Exception {
@@ -94,7 +96,7 @@
     @Test
     public void testBindNotification_SetsTextApplicationName() {
         when(mMockPackageManager.getApplicationLabel(any())).thenReturn("App Name");
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, new ArraySet<>());
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, new ArraySet<>());
         final TextView textView = mAppOpsInfo.findViewById(R.id.pkgname);
         assertTrue(textView.getText().toString().contains("App Name"));
     }
@@ -104,7 +106,7 @@
         final Drawable iconDrawable = mock(Drawable.class);
         when(mMockPackageManager.getApplicationIcon(any(ApplicationInfo.class)))
                 .thenReturn(iconDrawable);
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, new ArraySet<>());
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, new ArraySet<>());
         final ImageView iconView = mAppOpsInfo.findViewById(R.id.pkgicon);
         assertEquals(iconDrawable, iconView.getDrawable());
     }
@@ -120,7 +122,7 @@
             assertEquals(expectedOps, ops);
             assertEquals(TEST_UID, uid);
             latch.countDown();
-        }, mSbn, expectedOps);
+        }, mSbn, mUiEventLogger, expectedOps);
 
         final View settingsButton = mAppOpsInfo.findViewById(R.id.settings);
         settingsButton.performClick();
@@ -129,6 +131,14 @@
     }
 
     @Test
+    public void testBindNotification_LogsOpen() throws Exception {
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, new ArraySet<>());
+        assertEquals(1, mUiEventLogger.numLogs());
+        assertEquals(NotificationAppOpsEvent.NOTIFICATION_APP_OPS_OPEN.getId(),
+                mUiEventLogger.eventId(0));
+    }
+
+    @Test
     public void testOk() {
         ArraySet<Integer> expectedOps = new ArraySet<>();
         expectedOps.add(OP_CAMERA);
@@ -139,7 +149,7 @@
             assertEquals(expectedOps, ops);
             assertEquals(TEST_UID, uid);
             latch.countDown();
-        }, mSbn, expectedOps);
+        }, mSbn, mUiEventLogger, expectedOps);
 
         final View okButton = mAppOpsInfo.findViewById(R.id.ok);
         okButton.performClick();
@@ -151,7 +161,7 @@
     public void testPrompt_camera() {
         ArraySet<Integer> expectedOps = new ArraySet<>();
         expectedOps.add(OP_CAMERA);
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, expectedOps);
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, expectedOps);
         TextView prompt = mAppOpsInfo.findViewById(R.id.prompt);
         assertEquals("This app is using the camera.", prompt.getText());
     }
@@ -160,7 +170,7 @@
     public void testPrompt_mic() {
         ArraySet<Integer> expectedOps = new ArraySet<>();
         expectedOps.add(OP_RECORD_AUDIO);
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, expectedOps);
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, expectedOps);
         TextView prompt = mAppOpsInfo.findViewById(R.id.prompt);
         assertEquals("This app is using the microphone.", prompt.getText());
     }
@@ -169,7 +179,7 @@
     public void testPrompt_overlay() {
         ArraySet<Integer> expectedOps = new ArraySet<>();
         expectedOps.add(OP_SYSTEM_ALERT_WINDOW);
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, expectedOps);
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, expectedOps);
         TextView prompt = mAppOpsInfo.findViewById(R.id.prompt);
         assertEquals("This app is displaying over other apps on your screen.", prompt.getText());
     }
@@ -179,7 +189,7 @@
         ArraySet<Integer> expectedOps = new ArraySet<>();
         expectedOps.add(OP_CAMERA);
         expectedOps.add(OP_RECORD_AUDIO);
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, expectedOps);
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, expectedOps);
         TextView prompt = mAppOpsInfo.findViewById(R.id.prompt);
         assertEquals("This app is using the microphone and camera.", prompt.getText());
     }
@@ -190,7 +200,7 @@
         expectedOps.add(OP_CAMERA);
         expectedOps.add(OP_RECORD_AUDIO);
         expectedOps.add(OP_SYSTEM_ALERT_WINDOW);
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, expectedOps);
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, expectedOps);
         TextView prompt = mAppOpsInfo.findViewById(R.id.prompt);
         assertEquals("This app is displaying over other apps on your screen and using"
                 + " the microphone and camera.", prompt.getText());
@@ -201,7 +211,7 @@
         ArraySet<Integer> expectedOps = new ArraySet<>();
         expectedOps.add(OP_CAMERA);
         expectedOps.add(OP_SYSTEM_ALERT_WINDOW);
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, expectedOps);
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, expectedOps);
         TextView prompt = mAppOpsInfo.findViewById(R.id.prompt);
         assertEquals("This app is displaying over other apps on your screen and using"
                 + " the camera.", prompt.getText());
@@ -212,7 +222,7 @@
         ArraySet<Integer> expectedOps = new ArraySet<>();
         expectedOps.add(OP_RECORD_AUDIO);
         expectedOps.add(OP_SYSTEM_ALERT_WINDOW);
-        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, expectedOps);
+        mAppOpsInfo.bindGuts(mMockPackageManager, null, mSbn, mUiEventLogger, expectedOps);
         TextView prompt = mAppOpsInfo.findViewById(R.id.prompt);
         assertEquals("This app is displaying over other apps on your screen and using"
                 + " the microphone.", prompt.getText());
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
index 5b5873b..9dee843 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationGutsManagerTest.java
@@ -64,6 +64,8 @@
 import androidx.test.filters.SmallTest;
 
 import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.UiEventLogger;
+import com.android.internal.logging.testing.UiEventLoggerFake;
 import com.android.systemui.SysuiTestCase;
 import com.android.systemui.bubbles.BubbleController;
 import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
@@ -149,7 +151,8 @@
         mGutsManager = new NotificationGutsManager(mContext, mVisualStabilityManager,
                 () -> mStatusBar, mHandler, mHandler, mAccessibilityManager, mHighPriorityProvider,
                 mINotificationManager, mLauncherApps, mShortcutManager,
-                mChannelEditorDialogController, mContextTracker, mProvider, mBubbleController);
+                mChannelEditorDialogController, mContextTracker, mProvider, mBubbleController,
+                new UiEventLoggerFake());
         mGutsManager.setUpWithPresenter(mPresenter, mStackScroller,
                 mCheckSaveListener, mOnSettingsClickListener);
         mGutsManager.setNotificationActivityStarter(mNotificationActivityStarter);
@@ -362,6 +365,7 @@
                 eq(entry),
                 any(NotificationInfo.OnSettingsClickListener.class),
                 any(NotificationInfo.OnAppSettingsClickListener.class),
+                any(UiEventLogger.class),
                 eq(false),
                 eq(false),
                 eq(true) /* wasShownHighPriority */);
@@ -394,6 +398,7 @@
                 eq(entry),
                 any(NotificationInfo.OnSettingsClickListener.class),
                 any(NotificationInfo.OnAppSettingsClickListener.class),
+                any(UiEventLogger.class),
                 eq(true),
                 eq(false),
                 eq(false) /* wasShownHighPriority */);
@@ -424,6 +429,7 @@
                 eq(entry),
                 any(NotificationInfo.OnSettingsClickListener.class),
                 any(NotificationInfo.OnAppSettingsClickListener.class),
+                any(UiEventLogger.class),
                 eq(false),
                 eq(false),
                 eq(false) /* wasShownHighPriority */);
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java
index 6bf6072..ed982ab 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/NotificationInfoTest.java
@@ -62,6 +62,7 @@
 import android.widget.TextView;
 
 import com.android.internal.logging.MetricsLogger;
+import com.android.internal.logging.testing.UiEventLoggerFake;
 import com.android.systemui.Dependency;
 import com.android.systemui.R;
 import com.android.systemui.SysuiTestCase;
@@ -102,6 +103,7 @@
     private Set<NotificationChannel> mDefaultNotificationChannelSet = new HashSet<>();
     private StatusBarNotification mSbn;
     private NotificationEntry mEntry;
+    private UiEventLoggerFake mUiEventLogger = new UiEventLoggerFake();
 
     @Rule
     public MockitoRule mockito = MockitoJUnit.rule();
@@ -187,6 +189,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -211,6 +214,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -231,6 +235,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -260,6 +265,7 @@
                 entry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -281,6 +287,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -307,6 +314,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -328,6 +336,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -348,6 +357,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -372,6 +382,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -392,6 +403,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 true,
                 true);
@@ -416,6 +428,7 @@
                     latch.countDown();
                 },
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -439,6 +452,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -462,6 +476,7 @@
                     assertEquals(mNotificationChannel, c);
                 },
                 null,
+                mUiEventLogger,
                 false,
                 false,
                 true);
@@ -482,6 +497,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -496,6 +512,7 @@
                 mEntry,
                 (View v, NotificationChannel c, int appUid) -> { },
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -519,6 +536,7 @@
                     latch.countDown();
                 },
                 null,
+                mUiEventLogger,
                 true,
                 true,
                 true);
@@ -543,6 +561,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -565,6 +584,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -587,6 +607,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 true,
                 true);
@@ -611,6 +632,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -630,6 +652,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false);
@@ -649,6 +672,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -658,6 +682,28 @@
     }
 
     @Test
+    public void testBindNotification_LogsOpen() throws Exception {
+        mNotificationInfo.bindNotification(
+                mMockPackageManager,
+                mMockINotificationManager,
+                mVisualStabilityManager,
+                mChannelEditorDialogController,
+                TEST_PACKAGE_NAME,
+                mNotificationChannel,
+                mNotificationChannelSet,
+                mEntry,
+                null,
+                null,
+                mUiEventLogger,
+                true,
+                false,
+                true);
+        assertEquals(1, mUiEventLogger.numLogs());
+        assertEquals(NotificationControlsEvent.NOTIFICATION_CONTROLS_OPEN.getId(),
+                mUiEventLogger.eventId(0));
+    }
+
+    @Test
     public void testDoesNotUpdateNotificationChannelAfterImportanceChanged() throws Exception {
         mNotificationChannel.setImportance(IMPORTANCE_LOW);
         mNotificationInfo.bindNotification(
@@ -671,6 +717,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false);
@@ -696,6 +743,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -721,6 +769,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -730,6 +779,13 @@
         verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
                 anyString(), eq(TEST_UID), any());
         assertEquals(originalImportance, mNotificationChannel.getImportance());
+
+        assertEquals(2, mUiEventLogger.numLogs());
+        assertEquals(NotificationControlsEvent.NOTIFICATION_CONTROLS_OPEN.getId(),
+                mUiEventLogger.eventId(0));
+        // The SAVE_IMPORTANCE event is logged whenever importance is saved, even if unchanged.
+        assertEquals(NotificationControlsEvent.NOTIFICATION_CONTROLS_SAVE_IMPORTANCE.getId(),
+                mUiEventLogger.eventId(1));
     }
 
     @Test
@@ -747,6 +803,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -773,6 +830,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -789,6 +847,12 @@
         assertTrue((updated.getValue().getUserLockedFields()
                 & USER_LOCKED_IMPORTANCE) != 0);
         assertEquals(IMPORTANCE_LOW, updated.getValue().getImportance());
+
+        assertEquals(2, mUiEventLogger.numLogs());
+        assertEquals(NotificationControlsEvent.NOTIFICATION_CONTROLS_OPEN.getId(),
+                mUiEventLogger.eventId(0));
+        assertEquals(NotificationControlsEvent.NOTIFICATION_CONTROLS_SAVE_IMPORTANCE.getId(),
+                mUiEventLogger.eventId(1));
     }
 
     @Test
@@ -805,6 +869,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false);
@@ -838,6 +903,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -871,6 +937,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false);
@@ -907,6 +974,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false);
@@ -942,6 +1010,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 true);
@@ -968,6 +1037,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false);
@@ -997,6 +1067,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false);
@@ -1029,6 +1100,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false);
@@ -1040,6 +1112,10 @@
         mTestableLooper.processAllMessages();
         verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
                 eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
+
+        assertEquals(1, mUiEventLogger.numLogs());
+        assertEquals(NotificationControlsEvent.NOTIFICATION_CONTROLS_OPEN.getId(),
+                mUiEventLogger.eventId(0));
     }
 
     @Test
@@ -1056,6 +1132,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false
@@ -1088,6 +1165,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false
@@ -1113,6 +1191,7 @@
                 mEntry,
                 null,
                 null,
+                mUiEventLogger,
                 true,
                 false,
                 false
diff --git a/services/backup/java/com/android/server/backup/UserBackupManagerService.java b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
index dc35c77..f6c4918 100644
--- a/services/backup/java/com/android/server/backup/UserBackupManagerService.java
+++ b/services/backup/java/com/android/server/backup/UserBackupManagerService.java
@@ -318,7 +318,7 @@
 
     private static final String SERIAL_ID_FILE = "serial_id";
 
-    private static final String SKIP_USER_FACING_DATA = "backup_skip_user_facing_data";
+    private static final String SKIP_USER_FACING_PACKAGES = "backup_skip_user_facing_packages";
     private static final String WALLPAPER_PACKAGE = "com.android.wallpaperbackup";
 
     private final @UserIdInt int mUserId;
@@ -3557,7 +3557,7 @@
     }
 
     /**
-     * We want to skip backup/restore of certain packages if 'backup_skip_user_facing_data' is
+     * We want to skip backup/restore of certain packages if 'backup_skip_user_facing_packages' is
      * set to true in secure settings. See b/153940088 for details.
      *
      * TODO(b/154822946): Remove this logic in the next release.
@@ -3581,7 +3581,7 @@
 
     @VisibleForTesting
     public boolean shouldSkipUserFacingData() {
-        return Settings.Secure.getInt(mContext.getContentResolver(), SKIP_USER_FACING_DATA,
+        return Settings.Secure.getInt(mContext.getContentResolver(), SKIP_USER_FACING_PACKAGES,
                 /* def */ 0) != 0;
     }
 
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index bbc24ea..f8ab6f4 100755
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -413,6 +413,13 @@
         AppOpsManager.OP_AUDIO_MEDIA_VOLUME             // STREAM_ASSISTANT
     };
 
+    private static Set<Integer> sDeviceVolumeBehaviorSupportedDeviceOutSet = new HashSet<>(
+            Arrays.asList(
+                    AudioSystem.DEVICE_OUT_HDMI,
+                    AudioSystem.DEVICE_OUT_HDMI_ARC,
+                    AudioSystem.DEVICE_OUT_SPDIF,
+                    AudioSystem.DEVICE_OUT_LINE));
+
     private final boolean mUseFixedVolume;
 
     /**
@@ -525,7 +532,6 @@
 
     // Devices for which the volume is fixed (volume is either max or muted)
     Set<Integer> mFixedVolumeDevices = new HashSet<>(Arrays.asList(
-            AudioSystem.DEVICE_OUT_HDMI,
             AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET,
             AudioSystem.DEVICE_OUT_ANLG_DOCK_HEADSET,
             AudioSystem.DEVICE_OUT_HDMI_ARC,
@@ -929,11 +935,6 @@
                             AudioSystem.DEVICE_ALL_HDMI_SYSTEM_AUDIO_AND_SPEAKER_SET);
                 }
                 mHdmiPlaybackClient = mHdmiManager.getPlaybackClient();
-                if (mHdmiPlaybackClient != null) {
-                    // not a television: HDMI output will be always at max
-                    mFixedVolumeDevices.remove(AudioSystem.DEVICE_OUT_HDMI);
-                    mFullVolumeDevices.add(AudioSystem.DEVICE_OUT_HDMI);
-                }
                 mHdmiAudioSystemClient = mHdmiManager.getAudioSystemClient();
             }
         }
@@ -4049,6 +4050,11 @@
         }
 
         readVolumeGroupsSettings();
+
+        if (DEBUG_VOL) {
+            Log.d(TAG, "Restoring device volume behavior");
+        }
+        restoreDeviceVolumeBehavior();
     }
 
     /** @see AudioManager#setSpeakerphoneOn(boolean) */
@@ -4908,50 +4914,47 @@
         if (pkgName == null) {
             pkgName = "";
         }
-        // translate Java device type to native device type (for the devices masks for full / fixed)
-        final int type;
-        switch (device.getType()) {
-            case AudioDeviceInfo.TYPE_HDMI:
-                type = AudioSystem.DEVICE_OUT_HDMI;
-                break;
-            case AudioDeviceInfo.TYPE_HDMI_ARC:
-                type = AudioSystem.DEVICE_OUT_HDMI_ARC;
-                break;
-            case AudioDeviceInfo.TYPE_LINE_DIGITAL:
-                type = AudioSystem.DEVICE_OUT_SPDIF;
-                break;
-            case AudioDeviceInfo.TYPE_AUX_LINE:
-                type = AudioSystem.DEVICE_OUT_LINE;
-                break;
-            default:
-                // unsupported for now
-                throw new IllegalArgumentException("Unsupported device type " + device.getType());
+
+        int audioSystemDeviceOut = AudioDeviceInfo.convertDeviceTypeToInternalDevice(
+                device.getType());
+        setDeviceVolumeBehaviorInternal(audioSystemDeviceOut, deviceVolumeBehavior, pkgName);
+
+        persistDeviceVolumeBehavior(audioSystemDeviceOut, deviceVolumeBehavior);
+    }
+
+    private void setDeviceVolumeBehaviorInternal(int audioSystemDeviceOut,
+            @AudioManager.DeviceVolumeBehavior int deviceVolumeBehavior, @NonNull String caller) {
+        if (!sDeviceVolumeBehaviorSupportedDeviceOutSet.contains(audioSystemDeviceOut)) {
+            // unsupported for now
+            throw new IllegalArgumentException("Unsupported device type " + audioSystemDeviceOut);
         }
+
         // update device masks based on volume behavior
         switch (deviceVolumeBehavior) {
             case AudioManager.DEVICE_VOLUME_BEHAVIOR_VARIABLE:
-                mFullVolumeDevices.remove(type);
-                mFixedVolumeDevices.remove(type);
+                removeAudioSystemDeviceOutFromFullVolumeDevices(audioSystemDeviceOut);
+                removeAudioSystemDeviceOutFromFixedVolumeDevices(audioSystemDeviceOut);
                 break;
             case AudioManager.DEVICE_VOLUME_BEHAVIOR_FIXED:
-                mFullVolumeDevices.remove(type);
-                mFixedVolumeDevices.add(type);
+                removeAudioSystemDeviceOutFromFullVolumeDevices(audioSystemDeviceOut);
+                addAudioSystemDeviceOutToFixedVolumeDevices(audioSystemDeviceOut);
                 break;
             case AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL:
-                mFullVolumeDevices.add(type);
-                mFixedVolumeDevices.remove(type);
+                addAudioSystemDeviceOutToFullVolumeDevices(audioSystemDeviceOut);
+                removeAudioSystemDeviceOutFromFixedVolumeDevices(audioSystemDeviceOut);
                 break;
             case AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE:
             case AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_MULTI_MODE:
                 throw new IllegalArgumentException("Absolute volume unsupported for now");
         }
+
         // log event and caller
         sDeviceLogger.log(new AudioEventLogger.StringEvent(
-                "Volume behavior " + deviceVolumeBehavior
-                        + " for dev=0x" + Integer.toHexString(type) + " by pkg:" + pkgName));
+                "Volume behavior " + deviceVolumeBehavior + " for dev=0x"
+                      + Integer.toHexString(audioSystemDeviceOut) + " from:" + caller));
         // make sure we have a volume entry for this device, and that volume is updated according
         // to volume behavior
-        checkAddAllFixedVolumeDevices(type, "setDeviceVolumeBehavior:" + pkgName);
+        checkAddAllFixedVolumeDevices(audioSystemDeviceOut, "setDeviceVolumeBehavior:" + caller);
     }
 
     /**
@@ -4959,45 +4962,38 @@
      * @param device the audio output device type
      * @return the volume behavior for the device
      */
-    public @AudioManager.DeviceVolumeBehavior int getDeviceVolumeBehavior(
+    public @AudioManager.DeviceVolumeBehaviorState int getDeviceVolumeBehavior(
             @NonNull AudioDeviceAttributes device) {
         // verify permissions
         enforceModifyAudioRoutingPermission();
+
         // translate Java device type to native device type (for the devices masks for full / fixed)
-        final int type;
-        switch (device.getType()) {
-            case AudioDeviceInfo.TYPE_HEARING_AID:
-                type = AudioSystem.DEVICE_OUT_HEARING_AID;
-                break;
-            case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP:
-                type = AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP;
-                break;
-            case AudioDeviceInfo.TYPE_HDMI:
-                type = AudioSystem.DEVICE_OUT_HDMI;
-                break;
-            case AudioDeviceInfo.TYPE_HDMI_ARC:
-                type = AudioSystem.DEVICE_OUT_HDMI_ARC;
-                break;
-            case AudioDeviceInfo.TYPE_LINE_DIGITAL:
-                type = AudioSystem.DEVICE_OUT_SPDIF;
-                break;
-            case AudioDeviceInfo.TYPE_AUX_LINE:
-                type = AudioSystem.DEVICE_OUT_LINE;
-                break;
-            default:
-                // unsupported for now
-                throw new IllegalArgumentException("Unsupported device type " + device.getType());
+        final int audioSystemDeviceOut = AudioDeviceInfo.convertDeviceTypeToInternalDevice(
+                device.getType());
+        if (!sDeviceVolumeBehaviorSupportedDeviceOutSet.contains(audioSystemDeviceOut)
+                && audioSystemDeviceOut != AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP
+                && audioSystemDeviceOut != AudioSystem.DEVICE_OUT_HEARING_AID) {
+            throw new IllegalArgumentException("Unsupported volume behavior "
+                    + audioSystemDeviceOut);
         }
-        if ((mFullVolumeDevices.contains(type))) {
+
+        int setDeviceVolumeBehavior = retrieveStoredDeviceVolumeBehavior(audioSystemDeviceOut);
+        if (setDeviceVolumeBehavior != AudioManager.DEVICE_VOLUME_BEHAVIOR_UNSET) {
+            return setDeviceVolumeBehavior;
+        }
+
+        // setDeviceVolumeBehavior has not been explicitly called for the device type. Deduce the
+        // current volume behavior.
+        if ((mFullVolumeDevices.contains(audioSystemDeviceOut))) {
             return AudioManager.DEVICE_VOLUME_BEHAVIOR_FULL;
         }
-        if ((mFixedVolumeDevices.contains(type))) {
+        if ((mFixedVolumeDevices.contains(audioSystemDeviceOut))) {
             return AudioManager.DEVICE_VOLUME_BEHAVIOR_FIXED;
         }
-        if ((mAbsVolumeMultiModeCaseDevices.contains(type))) {
+        if ((mAbsVolumeMultiModeCaseDevices.contains(audioSystemDeviceOut))) {
             return AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE_MULTI_MODE;
         }
-        if (type == AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP
+        if (audioSystemDeviceOut == AudioSystem.DEVICE_OUT_BLUETOOTH_A2DP
                 && mDeviceBroker.isAvrcpAbsoluteVolumeSupported()) {
             return AudioManager.DEVICE_VOLUME_BEHAVIOR_ABSOLUTE;
         }
@@ -7120,18 +7116,20 @@
     @GuardedBy("mHdmiClientLock")
     private void updateHdmiCecSinkLocked(boolean hdmiCecSink) {
         mHdmiCecSink = hdmiCecSink;
-        if (mHdmiCecSink) {
-            if (DEBUG_VOL) {
-                Log.d(TAG, "CEC sink: setting HDMI as full vol device");
+        if (!hasDeviceVolumeBehavior(AudioSystem.DEVICE_OUT_HDMI)) {
+            if (mHdmiCecSink) {
+                if (DEBUG_VOL) {
+                    Log.d(TAG, "CEC sink: setting HDMI as full vol device");
+                }
+                addAudioSystemDeviceOutToFullVolumeDevices(AudioSystem.DEVICE_OUT_HDMI);
+            } else {
+                if (DEBUG_VOL) {
+                    Log.d(TAG, "TV, no CEC: setting HDMI as regular vol device");
+                }
+                // Android TV devices without CEC service apply software volume on
+                // HDMI output
+                removeAudioSystemDeviceOutFromFullVolumeDevices(AudioSystem.DEVICE_OUT_HDMI);
             }
-            mFullVolumeDevices.add(AudioSystem.DEVICE_OUT_HDMI);
-        } else {
-            if (DEBUG_VOL) {
-                Log.d(TAG, "TV, no CEC: setting HDMI as regular vol device");
-            }
-            // Android TV devices without CEC service apply software volume on
-            // HDMI output
-            mFullVolumeDevices.remove(AudioSystem.DEVICE_OUT_HDMI);
         }
 
         checkAddAllFixedVolumeDevices(AudioSystem.DEVICE_OUT_HDMI,
@@ -8970,4 +8968,91 @@
         }
         return mFullVolumeDevices.contains(deviceType);
     }
+
+    //====================
+    // Helper functions for {set,get}DeviceVolumeBehavior
+    //====================
+    private static String getSettingsNameForDeviceVolumeBehavior(int deviceType) {
+        return "AudioService_DeviceVolumeBehavior_" + AudioSystem.getOutputDeviceName(deviceType);
+    }
+
+    private void persistDeviceVolumeBehavior(int deviceType,
+            @AudioManager.DeviceVolumeBehavior int deviceVolumeBehavior) {
+        if (DEBUG_VOL) {
+            Log.d(TAG, "Persisting Volume Behavior for DeviceType: " + deviceType);
+        }
+        System.putIntForUser(mContentResolver,
+                getSettingsNameForDeviceVolumeBehavior(deviceType),
+                deviceVolumeBehavior,
+                UserHandle.USER_CURRENT);
+    }
+
+    @AudioManager.DeviceVolumeBehaviorState
+    private int retrieveStoredDeviceVolumeBehavior(int deviceType) {
+        return System.getIntForUser(mContentResolver,
+                getSettingsNameForDeviceVolumeBehavior(deviceType),
+                AudioManager.DEVICE_VOLUME_BEHAVIOR_UNSET,
+                UserHandle.USER_CURRENT);
+    }
+
+    private void restoreDeviceVolumeBehavior() {
+        for (int deviceType : sDeviceVolumeBehaviorSupportedDeviceOutSet) {
+            if (DEBUG_VOL) {
+                Log.d(TAG, "Retrieving Volume Behavior for DeviceType: " + deviceType);
+            }
+            int deviceVolumeBehavior = retrieveStoredDeviceVolumeBehavior(deviceType);
+            if (deviceVolumeBehavior == AudioManager.DEVICE_VOLUME_BEHAVIOR_UNSET) {
+                if (DEBUG_VOL) {
+                    Log.d(TAG, "Skipping Setting Volume Behavior for DeviceType: " + deviceType);
+                }
+                continue;
+            }
+
+            setDeviceVolumeBehaviorInternal(deviceType, deviceVolumeBehavior,
+                    "AudioService.restoreDeviceVolumeBehavior()");
+        }
+    }
+
+    /**
+     * @param audioSystemDeviceOut one of AudioSystem.DEVICE_OUT_*
+     * @return whether {@code audioSystemDeviceOut} has previously been set to a specific volume
+     * behavior
+     */
+    private boolean hasDeviceVolumeBehavior(
+            int audioSystemDeviceOut) {
+        return retrieveStoredDeviceVolumeBehavior(audioSystemDeviceOut)
+                != AudioManager.DEVICE_VOLUME_BEHAVIOR_UNSET;
+    }
+
+    private void addAudioSystemDeviceOutToFixedVolumeDevices(int audioSystemDeviceOut) {
+        if (DEBUG_VOL) {
+            Log.d(TAG, "Adding DeviceType: 0x" + Integer.toHexString(audioSystemDeviceOut)
+                    + " to mFixedVolumeDevices");
+        }
+        mFixedVolumeDevices.add(audioSystemDeviceOut);
+    }
+
+    private void removeAudioSystemDeviceOutFromFixedVolumeDevices(int audioSystemDeviceOut) {
+        if (DEBUG_VOL) {
+            Log.d(TAG, "Removing DeviceType: 0x" + Integer.toHexString(audioSystemDeviceOut)
+                    + " from mFixedVolumeDevices");
+        }
+        mFixedVolumeDevices.remove(audioSystemDeviceOut);
+    }
+
+    private void addAudioSystemDeviceOutToFullVolumeDevices(int audioSystemDeviceOut) {
+        if (DEBUG_VOL) {
+            Log.d(TAG, "Adding DeviceType: 0x" + Integer.toHexString(audioSystemDeviceOut)
+                    + " to mFullVolumeDevices");
+        }
+        mFullVolumeDevices.add(audioSystemDeviceOut);
+    }
+
+    private void removeAudioSystemDeviceOutFromFullVolumeDevices(int audioSystemDeviceOut) {
+        if (DEBUG_VOL) {
+            Log.d(TAG, "Removing DeviceType: 0x" + Integer.toHexString(audioSystemDeviceOut)
+                    + " from mFullVolumeDevices");
+        }
+        mFullVolumeDevices.remove(audioSystemDeviceOut);
+    }
 }
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java
index de13bd8..70f0399 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerInternal.java
@@ -17,6 +17,7 @@
 package com.android.server.inputmethod;
 
 import android.annotation.NonNull;
+import android.annotation.Nullable;
 import android.annotation.UserIdInt;
 import android.os.IBinder;
 import android.view.inputmethod.InlineSuggestionsRequest;
@@ -109,6 +110,16 @@
             int displayId);
 
     /**
+     * Reports that IME control has transferred to the given window token, or if null that
+     * control has been taken away from client windows (and is instead controlled by the policy
+     * or SystemUI).
+     *
+     * @param windowToken the window token that is now in control, or {@code null} if no client
+     *                   window is in control of the IME.
+     */
+    public abstract void reportImeControl(@Nullable IBinder windowToken);
+
+    /**
      * Fake implementation of {@link InputMethodManagerInternal}.  All the methods do nothing.
      */
     private static final InputMethodManagerInternal NOP =
@@ -151,6 +162,10 @@
                         int displayId) {
                     return false;
                 }
+
+                @Override
+                public void reportImeControl(@Nullable IBinder windowToken) {
+                }
             };
 
     /**
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index fea7980..9acb475 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -179,6 +179,7 @@
 import java.util.Date;
 import java.util.List;
 import java.util.Locale;
+import java.util.Objects;
 import java.util.WeakHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -593,6 +594,11 @@
     private boolean mCurClientInKeyguard;
 
     /**
+     * {@code true} if the IME has not been mostly hidden via {@link android.view.InsetsController}
+     */
+    private boolean mCurPerceptible;
+
+    /**
      * Set to true if our ServiceConnection is currently actively bound to
      * a service (whether or not we have gotten its IBinder back yet).
      */
@@ -2936,6 +2942,9 @@
             if (vis != 0 && isKeyguardLocked() && !mCurClientInKeyguard) {
                 vis = 0;
             }
+            if (!mCurPerceptible) {
+                vis = 0;
+            }
             // mImeWindowVis should be updated before calling shouldShowImeSwitcherLocked().
             final boolean needsToShowImeSwitcher = shouldShowImeSwitcherLocked(vis);
             if (mStatusBar != null) {
@@ -3148,6 +3157,28 @@
         }
     }
 
+    @BinderThread
+    @Override
+    public void reportPerceptible(IBinder windowToken, boolean perceptible) {
+        Objects.requireNonNull(windowToken, "windowToken must not be null");
+        int uid = Binder.getCallingUid();
+        synchronized (mMethodMap) {
+            if (!calledFromValidUserLocked()) {
+                return;
+            }
+            final long ident = Binder.clearCallingIdentity();
+            try {
+                if (mCurFocusedWindow == windowToken
+                        && mCurPerceptible != perceptible) {
+                    mCurPerceptible = perceptible;
+                    updateSystemUiLocked(mImeWindowVis, mBackDisposition);
+                }
+            } finally {
+                Binder.restoreCallingIdentity(ident);
+            }
+        }
+    }
+
     @GuardedBy("mMethodMap")
     boolean showCurrentInputLocked(IBinder windowToken, int flags, ResultReceiver resultReceiver,
             @SoftInputShowHideReason int reason) {
@@ -3451,6 +3482,7 @@
         mCurFocusedWindow = windowToken;
         mCurFocusedWindowSoftInputMode = softInputMode;
         mCurFocusedWindowClient = cs;
+        mCurPerceptible = true;
 
         // Should we auto-show the IME even if the caller has not
         // specified what should be done with it?
@@ -5010,6 +5042,16 @@
         return mInputManagerInternal.transferTouchFocus(sourceInputToken, curHostInputToken);
     }
 
+    private void reportImeControl(@Nullable IBinder windowToken) {
+        synchronized (mMethodMap) {
+            if (mCurFocusedWindow != windowToken) {
+                // mCurPerceptible was set by the focused window, but it is no longer in control,
+                // so we reset mCurPerceptible.
+                mCurPerceptible = true;
+            }
+        }
+    }
+
     private static final class LocalServiceImpl extends InputMethodManagerInternal {
         @NonNull
         private final InputMethodManagerService mService;
@@ -5062,6 +5104,11 @@
                 int displayId) {
             return mService.transferTouchFocusToImeWindow(sourceInputToken, displayId);
         }
+
+        @Override
+        public void reportImeControl(@Nullable IBinder windowToken) {
+            mService.reportImeControl(windowToken);
+        }
     }
 
     @BinderThread
@@ -5164,6 +5211,7 @@
             p.println("  mCurMethodId=" + mCurMethodId);
             client = mCurClient;
             p.println("  mCurClient=" + client + " mCurSeq=" + mCurSeq);
+            p.println("  mCurPerceptible=" + mCurPerceptible);
             p.println("  mCurFocusedWindow=" + mCurFocusedWindow
                     + " softInputMode=" +
                     InputMethodDebug.softInputModeToString(mCurFocusedWindowSoftInputMode)
diff --git a/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java
index 33c78e4..2e3d396 100644
--- a/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/MultiClientInputMethodManagerService.java
@@ -221,6 +221,10 @@
                             reportNotSupported();
                             return false;
                         }
+
+                        @Override
+                        public void reportImeControl(@Nullable IBinder windowToken) {
+                        }
                     });
         }
 
@@ -1753,6 +1757,12 @@
 
         @BinderThread
         @Override
+        public void reportPerceptible(IBinder windowClient, boolean perceptible) {
+            reportNotSupported();
+        }
+
+        @BinderThread
+        @Override
         public void onShellCommand(@Nullable FileDescriptor in, @Nullable FileDescriptor out,
                 @Nullable FileDescriptor err, String[] args, @Nullable ShellCallback callback,
                 ResultReceiver resultReceiver) {
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index ed055eb..9b5d94e 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -210,6 +210,7 @@
 import com.android.internal.util.function.pooled.PooledFunction;
 import com.android.internal.util.function.pooled.PooledLambda;
 import com.android.internal.util.function.pooled.PooledPredicate;
+import com.android.server.inputmethod.InputMethodManagerInternal;
 import com.android.server.policy.WindowManagerPolicy;
 import com.android.server.protolog.common.ProtoLog;
 import com.android.server.wm.utils.DisplayRotationUtil;
@@ -3566,6 +3567,14 @@
     private void updateImeControlTarget() {
         mInputMethodControlTarget = computeImeControlTarget();
         mInsetsStateController.onImeControlTargetChanged(mInputMethodControlTarget);
+
+        final WindowState win = mInputMethodControlTarget != null
+                ? mInputMethodControlTarget.getWindow() : null;
+        final IBinder token = win != null ? win.mClient.asBinder() : null;
+        // Note: not allowed to call into IMMS with the WM lock held, hence the post.
+        mWmService.mH.post(() ->
+                InputMethodManagerInternal.get().reportImeControl(token)
+        );
     }
 
     private void updateImeParent() {
diff --git a/services/core/java/com/android/server/wm/DisplayPolicy.java b/services/core/java/com/android/server/wm/DisplayPolicy.java
index 8cfe1cd..72b014c 100644
--- a/services/core/java/com/android/server/wm/DisplayPolicy.java
+++ b/services/core/java/com/android/server/wm/DisplayPolicy.java
@@ -3782,7 +3782,8 @@
                 && (behavior == BEHAVIOR_SHOW_BARS_BY_SWIPE
                         || behavior == BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE)
                 && getInsetsPolicy().isHidden(ITYPE_NAVIGATION_BAR)
-                && win != getNotificationShade();
+                && win != getNotificationShade()
+                && !win.isActivityTypeDream();
     }
 
     /**
diff --git a/services/core/java/com/android/server/wm/InsetsPolicy.java b/services/core/java/com/android/server/wm/InsetsPolicy.java
index c7b9106..254356d 100644
--- a/services/core/java/com/android/server/wm/InsetsPolicy.java
+++ b/services/core/java/com/android/server/wm/InsetsPolicy.java
@@ -482,6 +482,12 @@
                     WindowInsetsAnimation animation,
                     Bounds bounds) {
             }
+
+            @Override
+            public void reportPerceptible(int types, boolean perceptible) {
+                // No-op for now - only client windows report perceptibility for now, with policy
+                // controllers assumed to always be perceptible.
+            }
         }
     }
 }
diff --git a/services/core/java/com/android/server/wm/LockTaskController.java b/services/core/java/com/android/server/wm/LockTaskController.java
index 4a0da75..892ee71 100644
--- a/services/core/java/com/android/server/wm/LockTaskController.java
+++ b/services/core/java/com/android/server/wm/LockTaskController.java
@@ -175,7 +175,7 @@
      * {@link ActivityManager#LOCK_TASK_MODE_NONE}, {@link ActivityManager#LOCK_TASK_MODE_LOCKED},
      * {@link ActivityManager#LOCK_TASK_MODE_PINNED}
      */
-    private int mLockTaskModeState = LOCK_TASK_MODE_NONE;
+    private volatile int mLockTaskModeState = LOCK_TASK_MODE_NONE;
 
     /**
      * This is ActivityStackSupervisor's Handler.
@@ -500,24 +500,29 @@
 
     // This method should only be called on the handler thread
     private void performStopLockTask(int userId) {
+        // Update the internal mLockTaskModeState early to avoid the scenario that SysUI queries
+        // mLockTaskModeState (from setStatusBarState) and gets staled state.
+        // TODO: revisit this approach.
+        // The race condition raised above can be addressed by moving this function out of handler
+        // thread, which makes it guarded by ATMS#mGlobalLock as ATMS#getLockTaskModeState.
+        final int oldLockTaskModeState = mLockTaskModeState;
+        mLockTaskModeState = LOCK_TASK_MODE_NONE;
         // When lock task ends, we enable the status bars.
         try {
-            setStatusBarState(LOCK_TASK_MODE_NONE, userId);
-            setKeyguardState(LOCK_TASK_MODE_NONE, userId);
-            if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) {
+            setStatusBarState(mLockTaskModeState, userId);
+            setKeyguardState(mLockTaskModeState, userId);
+            if (oldLockTaskModeState == LOCK_TASK_MODE_PINNED) {
                 lockKeyguardIfNeeded();
             }
             if (getDevicePolicyManager() != null) {
                 getDevicePolicyManager().notifyLockTaskModeChanged(false, null, userId);
             }
-            if (mLockTaskModeState == LOCK_TASK_MODE_PINNED) {
+            if (oldLockTaskModeState == LOCK_TASK_MODE_PINNED) {
                 getStatusBarService().showPinningEnterExitToast(false /* entering */);
             }
-            mWindowManager.onLockTaskStateChanged(LOCK_TASK_MODE_NONE);
+            mWindowManager.onLockTaskStateChanged(mLockTaskModeState);
         } catch (RemoteException ex) {
             throw new RuntimeException(ex);
-        } finally {
-            mLockTaskModeState = LOCK_TASK_MODE_NONE;
         }
     }
 
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index 3a1619b..1a6d855 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -1897,6 +1897,7 @@
     }
 
     boolean needsZBoost() {
+        if (mNeedsZBoost) return true;
         for (int i = 0; i < mChildren.size(); i++) {
             if (mChildren.get(i).needsZBoost()) {
                 return true;
diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
index c7dac78..465a351 100644
--- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
+++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp
@@ -3109,9 +3109,7 @@
         result = gnssMeasurementIface_V1_1->setCallback_1_1(cbIface, enableFullTracking);
     } else {
         if (enableFullTracking == JNI_TRUE) {
-            // full tracking mode not supported in 1.0 HAL
-            result.assertOk(); // isOk() must be called before result destructor is invoked.
-            return JNI_FALSE;
+            ALOGW("Full tracking mode not supported in 1.0 GNSS HAL.");
         }
         result = gnssMeasurementIface->setCallback(cbIface);
     }
diff --git a/tools/stats_log_api_gen/Android.bp b/tools/stats_log_api_gen/Android.bp
index b1e2487..e3b6db0 100644
--- a/tools/stats_log_api_gen/Android.bp
+++ b/tools/stats_log_api_gen/Android.bp
@@ -21,7 +21,6 @@
     name: "stats-log-api-gen",
     srcs: [
         "Collation.cpp",
-        "atoms_info_writer.cpp",
         "java_writer.cpp",
         "java_writer_q.cpp",
         "main.cpp",
diff --git a/tools/stats_log_api_gen/Collation.cpp b/tools/stats_log_api_gen/Collation.cpp
index 958e94e..a230de4 100644
--- a/tools/stats_log_api_gen/Collation.cpp
+++ b/tools/stats_log_api_gen/Collation.cpp
@@ -52,9 +52,7 @@
       defaultState(that.defaultState),
       triggerStateReset(that.triggerStateReset),
       nested(that.nested),
-      uidField(that.uidField),
-      whitelisted(that.whitelisted),
-      truncateTimestamp(that.truncateTimestamp) {
+      uidField(that.uidField) {
 }
 
 AtomDecl::AtomDecl(int c, const string& n, const string& m) : code(c), name(n), message(m) {
@@ -520,13 +518,6 @@
         shared_ptr<AtomDecl> atomDecl =
                 make_shared<AtomDecl>(atomField->number(), atomField->name(), atom->name());
 
-        if (atomField->options().GetExtension(os::statsd::allow_from_any_uid) == true) {
-            atomDecl->whitelisted = true;
-            if (dbg) {
-                printf("%s is whitelisted\n", atomField->name().c_str());
-            }
-        }
-
         if (atomDecl->code < PULL_ATOM_START_ID &&
             atomField->options().GetExtension(os::statsd::truncate_timestamp)) {
             addAnnotationToAtomDecl(atomDecl.get(), ATOM_ID_FIELD_NUMBER,
diff --git a/tools/stats_log_api_gen/Collation.h b/tools/stats_log_api_gen/Collation.h
index 043f8b1..10b34ec 100644
--- a/tools/stats_log_api_gen/Collation.h
+++ b/tools/stats_log_api_gen/Collation.h
@@ -164,10 +164,6 @@
 
     int uidField = 0;
 
-    bool whitelisted = false;
-
-    bool truncateTimestamp = false;
-
     AtomDecl();
     AtomDecl(const AtomDecl& that);
     AtomDecl(int code, const string& name, const string& message);
diff --git a/tools/stats_log_api_gen/atoms_info_writer.cpp b/tools/stats_log_api_gen/atoms_info_writer.cpp
deleted file mode 100644
index 292cb21..0000000
--- a/tools/stats_log_api_gen/atoms_info_writer.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "atoms_info_writer.h"
-
-#include <map>
-#include <set>
-#include <vector>
-
-#include "utils.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-static void write_atoms_info_header_body(FILE* out) {
-    fprintf(out, "struct AtomsInfo {\n");
-    fprintf(out, "  const static std::set<int> kWhitelistedAtoms;\n");
-    fprintf(out, "};\n");
-}
-
-static void write_atoms_info_cpp_body(FILE* out, const Atoms& atoms) {
-
-    fprintf(out, "const std::set<int> AtomsInfo::kWhitelistedAtoms = {\n");
-    for (AtomDeclSet::const_iterator atomIt = atoms.decls.begin(); atomIt != atoms.decls.end();
-         atomIt++) {
-        if ((*atomIt)->whitelisted) {
-            const string constant = make_constant_name((*atomIt)->name);
-            fprintf(out, "    %d, // %s\n", (*atomIt)->code, constant.c_str());
-        }
-    }
-
-    fprintf(out, "};\n");
-    fprintf(out, "\n");
-
-}
-
-int write_atoms_info_header(FILE* out, const string& namespaceStr) {
-    // Print prelude
-    fprintf(out, "// This file is autogenerated\n");
-    fprintf(out, "\n");
-    fprintf(out, "#pragma once\n");
-    fprintf(out, "\n");
-    fprintf(out, "#include <vector>\n");
-    fprintf(out, "#include <map>\n");
-    fprintf(out, "#include <set>\n");
-    fprintf(out, "\n");
-
-    write_namespace(out, namespaceStr);
-
-    write_atoms_info_header_body(out);
-
-    fprintf(out, "\n");
-    write_closing_namespace(out, namespaceStr);
-
-    return 0;
-}
-
-int write_atoms_info_cpp(FILE* out, const Atoms& atoms, const string& namespaceStr,
-                         const string& importHeader) {
-    // Print prelude
-    fprintf(out, "// This file is autogenerated\n");
-    fprintf(out, "\n");
-    fprintf(out, "#include <%s>\n", importHeader.c_str());
-    fprintf(out, "\n");
-
-    write_namespace(out, namespaceStr);
-
-    write_atoms_info_cpp_body(out, atoms);
-
-    // Print footer
-    fprintf(out, "\n");
-    write_closing_namespace(out, namespaceStr);
-
-    return 0;
-}
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/atoms_info_writer.h b/tools/stats_log_api_gen/atoms_info_writer.h
deleted file mode 100644
index 09a4303..0000000
--- a/tools/stats_log_api_gen/atoms_info_writer.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2019, The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#pragma once
-
-#include <stdio.h>
-#include <string.h>
-
-#include "Collation.h"
-
-namespace android {
-namespace stats_log_api_gen {
-
-using namespace std;
-
-int write_atoms_info_cpp(FILE* out, const Atoms& atoms, const string& namespaceStr,
-                         const string& importHeader);
-
-int write_atoms_info_header(FILE* out, const string& namespaceStr);
-
-}  // namespace stats_log_api_gen
-}  // namespace android
diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp
index 136933b..b888ce9 100644
--- a/tools/stats_log_api_gen/main.cpp
+++ b/tools/stats_log_api_gen/main.cpp
@@ -9,7 +9,6 @@
 #include <vector>
 
 #include "Collation.h"
-#include "atoms_info_writer.h"
 #include "frameworks/base/cmds/statsd/src/atoms.pb.h"
 #include "java_writer.h"
 #include "java_writer_q.h"
@@ -30,12 +29,6 @@
     fprintf(stderr, "OPTIONS\n");
     fprintf(stderr, "  --cpp FILENAME       the header file to output for write helpers\n");
     fprintf(stderr, "  --header FILENAME    the cpp file to output for write helpers\n");
-    fprintf(stderr,
-            "  --atomsInfoCpp FILENAME       the header file to output for "
-            "statsd metadata\n");
-    fprintf(stderr,
-            "  --atomsInfoHeader FILENAME    the cpp file to output for statsd "
-            "metadata\n");
     fprintf(stderr, "  --help               this message\n");
     fprintf(stderr, "  --java FILENAME      the java file to output\n");
     fprintf(stderr, "  --module NAME        optional, module name to generate outputs for\n");
@@ -49,10 +42,6 @@
             "  --importHeader NAME  required for cpp/jni to say which header to "
             "import "
             "for write helpers\n");
-    fprintf(stderr,
-            "  --atomsInfoImportHeader NAME  required for cpp to say which "
-            "header to import "
-            "for statsd metadata\n");
     fprintf(stderr, "  --javaPackage PACKAGE             the package for the java file.\n");
     fprintf(stderr, "                                    required for java with module\n");
     fprintf(stderr, "  --javaClass CLASS    the class name of the java class.\n");
@@ -74,15 +63,12 @@
     string cppFilename;
     string headerFilename;
     string javaFilename;
-    string atomsInfoCppFilename;
-    string atomsInfoHeaderFilename;
     string javaPackage;
     string javaClass;
 
     string moduleName = DEFAULT_MODULE_NAME;
     string cppNamespace = DEFAULT_CPP_NAMESPACE;
     string cppHeaderImport = DEFAULT_CPP_HEADER_IMPORT;
-    string atomsInfoCppHeaderImport = DEFAULT_ATOMS_INFO_CPP_HEADER_IMPORT;
     bool supportQ = false;
     bool supportWorkSource = false;
     bool compileQ = false;
@@ -148,27 +134,6 @@
                 return 1;
             }
             javaClass = argv[index];
-        } else if (0 == strcmp("--atomsInfoHeader", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            atomsInfoHeaderFilename = argv[index];
-        } else if (0 == strcmp("--atomsInfoCpp", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            atomsInfoCppFilename = argv[index];
-        } else if (0 == strcmp("--atomsInfoImportHeader", argv[index])) {
-            index++;
-            if (index >= argc) {
-                print_usage();
-                return 1;
-            }
-            atomsInfoCppHeaderImport = argv[index];
         } else if (0 == strcmp("--supportQ", argv[index])) {
             supportQ = true;
         } else if (0 == strcmp("--worksource", argv[index])) {
@@ -180,8 +145,7 @@
         index++;
     }
 
-    if (cppFilename.size() == 0 && headerFilename.size() == 0 && javaFilename.size() == 0 &&
-        atomsInfoHeaderFilename.size() == 0 && atomsInfoCppFilename.size() == 0) {
+    if (cppFilename.size() == 0 && headerFilename.size() == 0 && javaFilename.size() == 0) {
         print_usage();
         return 1;
     }
@@ -210,29 +174,6 @@
     collate_atom(android::os::statsd::AttributionNode::descriptor(), &attributionDecl,
                  &attributionSignature);
 
-    // Write the atoms info .cpp file
-    if (atomsInfoCppFilename.size() != 0) {
-        FILE* out = fopen(atomsInfoCppFilename.c_str(), "w");
-        if (out == NULL) {
-            fprintf(stderr, "Unable to open file for write: %s\n", atomsInfoCppFilename.c_str());
-            return 1;
-        }
-        errorCount = android::stats_log_api_gen::write_atoms_info_cpp(out, atoms, cppNamespace,
-                                                                      atomsInfoCppHeaderImport);
-        fclose(out);
-    }
-
-    // Write the atoms info .h file
-    if (atomsInfoHeaderFilename.size() != 0) {
-        FILE* out = fopen(atomsInfoHeaderFilename.c_str(), "w");
-        if (out == NULL) {
-            fprintf(stderr, "Unable to open file for write: %s\n", atomsInfoHeaderFilename.c_str());
-            return 1;
-        }
-        errorCount = android::stats_log_api_gen::write_atoms_info_header(out, cppNamespace);
-        fclose(out);
-    }
-
     // Write the .cpp file
     if (cppFilename.size() != 0) {
         FILE* out = fopen(cppFilename.c_str(), "w");
diff --git a/tools/stats_log_api_gen/test.proto b/tools/stats_log_api_gen/test.proto
index d22acc6..aaa488e 100644
--- a/tools/stats_log_api_gen/test.proto
+++ b/tools/stats_log_api_gen/test.proto
@@ -187,24 +187,6 @@
     optional int32 state = 3 [(android.os.statsd.state_field_option).exclusive_state = true];
 }
 
-message WhitelistedAtom {
-  optional int32 field = 1;
-}
-
-message NonWhitelistedAtom {
-  optional int32 field = 1;
-}
-
-message ListedAtoms {
-  oneof event {
-    // Atoms can be whitelisted i.e. they can be triggered by any source
-    WhitelistedAtom whitelisted_atom = 1 [(android.os.statsd.allow_from_any_uid) = true];
-    // Atoms are not whitelisted by default, so they can only be triggered
-    // by whitelisted sources
-    NonWhitelistedAtom non_whitelisted_atom = 2;
-  }
-}
-
 message ModuleOneAtom {
     optional int32 field = 1 [(android.os.statsd.is_uid) = true];
 }
diff --git a/tools/stats_log_api_gen/test_collation.cpp b/tools/stats_log_api_gen/test_collation.cpp
index 1504752..dbae588 100644
--- a/tools/stats_log_api_gen/test_collation.cpp
+++ b/tools/stats_log_api_gen/test_collation.cpp
@@ -225,25 +225,6 @@
     EXPECT_TRUE(errorCount > 0);
 }
 
-TEST(CollationTest, PassOnWhitelistedAtom) {
-    Atoms atoms;
-    int errorCount = collate_atoms(ListedAtoms::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-    EXPECT_EQ(errorCount, 0);
-    EXPECT_EQ(atoms.decls.size(), 2ul);
-}
-
-TEST(CollationTest, RecogniseWhitelistedAtom) {
-    Atoms atoms;
-    collate_atoms(ListedAtoms::descriptor(), DEFAULT_MODULE_NAME, &atoms);
-    for (const auto& atomDecl : atoms.decls) {
-        if (atomDecl->code == 1) {
-            EXPECT_TRUE(atomDecl->whitelisted);
-        } else {
-            EXPECT_FALSE(atomDecl->whitelisted);
-        }
-    }
-}
-
 TEST(CollationTest, PassOnLogFromModuleAtom) {
     Atoms atoms;
     int errorCount = collate_atoms(ModuleAtoms::descriptor(), DEFAULT_MODULE_NAME, &atoms);
diff --git a/tools/stats_log_api_gen/utils.h b/tools/stats_log_api_gen/utils.h
index 7d6d08e..73e0cb8 100644
--- a/tools/stats_log_api_gen/utils.h
+++ b/tools/stats_log_api_gen/utils.h
@@ -32,7 +32,6 @@
 
 const string DEFAULT_CPP_NAMESPACE = "android,util";
 const string DEFAULT_CPP_HEADER_IMPORT = "statslog.h";
-const string DEFAULT_ATOMS_INFO_CPP_HEADER_IMPORT = "atoms_info.h";
 
 const int JAVA_MODULE_REQUIRES_FLOAT = 0x01;
 const int JAVA_MODULE_REQUIRES_ATTRIBUTION = 0x02;
diff --git a/wifi/java/android/net/wifi/WifiManager.java b/wifi/java/android/net/wifi/WifiManager.java
index 1b0497a..fb6af5b 100644
--- a/wifi/java/android/net/wifi/WifiManager.java
+++ b/wifi/java/android/net/wifi/WifiManager.java
@@ -928,19 +928,26 @@
 
     /**
      * Broadcast intent action indicating that the configured networks changed.
-     * This can be as a result of adding/updating/deleting a network. If
-     * {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is set to true the new configuration
-     * can be retreived with the {@link #EXTRA_WIFI_CONFIGURATION} extra. If multiple
-     * Wi-Fi configurations changed, {@link #EXTRA_WIFI_CONFIGURATION} will not be present.
+     * This can be as a result of adding/updating/deleting a network.
+     * <br />
+     * {@link #EXTRA_CHANGE_REASON} contains whether the configuration was added/changed/removed.
+     * {@link #EXTRA_WIFI_CONFIGURATION} is never set starting in Android 11.
+     * {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is set for backwards compatibility reasons, but
+     * its value is always true, even if only a single network changed.
+     * <br />
+     * The {@link android.Manifest.permission#ACCESS_WIFI_STATE ACCESS_WIFI_STATE} permission is
+     * required to receive this broadcast.
+     *
      * @hide
      */
     @SystemApi
     public static final String CONFIGURED_NETWORKS_CHANGED_ACTION =
         "android.net.wifi.CONFIGURED_NETWORKS_CHANGE";
     /**
-     * The lookup key for a (@link android.net.wifi.WifiConfiguration} object representing
+     * The lookup key for a {@link android.net.wifi.WifiConfiguration} object representing
      * the changed Wi-Fi configuration when the {@link #CONFIGURED_NETWORKS_CHANGED_ACTION}
      * broadcast is sent.
+     * Note: this extra is never set starting in Android 11.
      * @hide
      */
     @SystemApi
@@ -948,14 +955,16 @@
     /**
      * Multiple network configurations have changed.
      * @see #CONFIGURED_NETWORKS_CHANGED_ACTION
-     *
+     * Note: this extra is always true starting in Android 11.
      * @hide
      */
     @SystemApi
     public static final String EXTRA_MULTIPLE_NETWORKS_CHANGED = "multipleChanges";
     /**
      * The lookup key for an integer indicating the reason a Wi-Fi network configuration
-     * has changed. Only present if {@link #EXTRA_MULTIPLE_NETWORKS_CHANGED} is {@code false}
+     * has changed. One of {@link #CHANGE_REASON_ADDED}, {@link #CHANGE_REASON_REMOVED},
+     * {@link #CHANGE_REASON_CONFIG_CHANGE}.
+     *
      * @see #CONFIGURED_NETWORKS_CHANGED_ACTION
      * @hide
      */