Merge "Fix an issue that the icon rewritten logic not working in non-primary user" into rvc-dev
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index 8ba52ef..573a84f 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -4945,9 +4945,12 @@
 
 /**
  * Used for pull network statistics via mobile|wifi networks, and sliced by interesting dimensions.
- * Note that data is expected to be sliced into more dimensions in future. In other words,
- * the caller must not assume the data is unique when filtering with a set of matching conditions.
- * Thus, as the dimension grows, the caller will not be affected.
+ * Note that the data is expected to be sliced into more dimensions in future. In other words,
+ * the caller must not assume any row of data is one full report when filtering with a set of
+ * matching conditions, because future data may represent with multiple rows what is currently
+ * represented by one.
+ * To avoid being broken by future slicing, callers must take care to aggregate rows even if they
+ * query all the existing columns.
  *
  * Pulled from:
  *   StatsPullAtomService (using NetworkStatsService to get NetworkStats)
@@ -4972,21 +4975,26 @@
     optional int32 rat_type = 6;
 
     // Mcc/Mnc read from sim if the record is for a specific subscription, null indicates the
-    // record is combined regardless of subscription.
+    // record is combined across subscriptions.
     optional string sim_mcc = 7;
     optional string sim_mnc = 8;
 
+    // Allows mobile virtual network operators (MVNOs) to be identified with individual IDs.
+    // See TelephonyManager#getSimCarrierId.
+    optional int32 carrier_id = 9;
+
     // Enumeration of opportunistic states with an additional ALL state indicates the record is
     // combined regardless of the boolean value in its field.
     enum DataSubscriptionState {
+        UNKNOWN = 0; // For server side backward compatibility.
         ALL = 1;
         OPPORTUNISTIC = 2;
         NOT_OPPORTUNISTIC = 3;
     }
     // Mark whether the subscription is an opportunistic data subscription, and ALL indicates the
-    // record is combined regardless of opportunistic data subscription.
+    // record is combined across opportunistic data subscriptions.
     // See {@link SubscriptionManager#setOpportunistic}.
-    optional DataSubscriptionState opportunistic_data_sub = 9;
+    optional DataSubscriptionState opportunistic_data_sub = 10;
 }
 
 /**
diff --git a/media/java/android/media/AudioManagerInternal.java b/media/java/android/media/AudioManagerInternal.java
index b44d7bb..357c333 100644
--- a/media/java/android/media/AudioManagerInternal.java
+++ b/media/java/android/media/AudioManagerInternal.java
@@ -29,13 +29,13 @@
 public abstract class AudioManagerInternal {
 
     public abstract void adjustSuggestedStreamVolumeForUid(int streamType, int direction,
-            int flags, String callingPackage, int uid, int pid);
+            int flags, String callingPackage, int uid);
 
     public abstract void adjustStreamVolumeForUid(int streamType, int direction, int flags,
-            String callingPackage, int uid, int pid);
+            String callingPackage, int uid);
 
     public abstract void setStreamVolumeForUid(int streamType, int direction, int flags,
-            String callingPackage, int uid, int pid);
+            String callingPackage, int uid);
 
     public abstract void setRingerModeDelegate(RingerModeDelegate delegate);
 
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java
index 66c07bd..1dc828b 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/PartialConversationInfo.java
@@ -192,9 +192,9 @@
     private void bindName() {
         TextView name = findViewById(R.id.name);
         Bundle extras = mSbn.getNotification().extras;
-        String nameString = extras.getString(Notification.EXTRA_CONVERSATION_TITLE);
+        CharSequence nameString = extras.getCharSequence(Notification.EXTRA_CONVERSATION_TITLE, "");
         if (TextUtils.isEmpty(nameString)) {
-            nameString = extras.getString(Notification.EXTRA_TITLE);
+            nameString = extras.getCharSequence(Notification.EXTRA_TITLE, "");
         }
         name.setText(nameString);
     }
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java
index f21b1a6..545b59a 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/notification/row/PartialConversationInfoTest.java
@@ -47,6 +47,7 @@
 import android.test.suitebuilder.annotation.SmallTest;
 import android.testing.AndroidTestingRunner;
 import android.testing.TestableLooper;
+import android.text.SpannableString;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.widget.ImageView;
@@ -151,8 +152,11 @@
                 NotificationChannel.DEFAULT_CHANNEL_ID, TEST_CHANNEL_NAME,
                 IMPORTANCE_LOW);
         mDefaultNotificationChannelSet.add(mDefaultNotificationChannel);
+        Notification n = new Notification.Builder(mContext, mNotificationChannel.getId())
+                .setContentTitle(new SpannableString("title"))
+                .build();
         mSbn = new StatusBarNotification(TEST_PACKAGE_NAME, TEST_PACKAGE_NAME, 0, null, TEST_UID, 0,
-                new Notification(), UserHandle.CURRENT, null, 0);
+                n, UserHandle.CURRENT, null, 0);
         mEntry = new NotificationEntryBuilder().setSbn(mSbn).build();
     }
 
@@ -176,6 +180,23 @@
     }
 
     @Test
+    public void testBindNotification_SetsName() {
+        mInfo.bindNotification(
+                mMockPackageManager,
+                mMockINotificationManager,
+                mChannelEditorDialogController,
+                TEST_PACKAGE_NAME,
+                mNotificationChannel,
+                mNotificationChannelSet,
+                mEntry,
+                null,
+                true,
+                false);
+        final TextView textView = mInfo.findViewById(R.id.name);
+        assertTrue(textView.getText().toString().contains("title"));
+    }
+
+    @Test
     public void testBindNotification_groupSetsPackageIcon() {
         mEntry.getSbn().getNotification().extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, true);
         final Drawable iconDrawable = mock(Drawable.class);
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java
index 2423f43d..98d662a 100755
--- a/services/core/java/com/android/server/audio/AudioService.java
+++ b/services/core/java/com/android/server/audio/AudioService.java
@@ -955,8 +955,6 @@
 
         mMicMuteFromSystemCached = mAudioSystem.isMicrophoneMuted();
         setMicMuteFromSwitchInput();
-
-        initMinStreamVolumeWithoutModifyAudioSettings();
     }
 
     RoleObserver mRoleObserver;
@@ -1310,7 +1308,7 @@
                 mStreamStates[streamType].setIndex(
                         mStreamStates[mStreamVolumeAlias[streamType]]
                                 .getIndex(AudioSystem.DEVICE_OUT_DEFAULT),
-                        device, caller, true /*hasModifyAudioSettings*/);
+                        device, caller);
             }
             mStreamStates[streamType].checkFixedVolumeDevices();
         }
@@ -1875,16 +1873,13 @@
                     direction, 0 /*ignored*/,
                     extVolCtlr, 0 /*delay*/);
         } else {
-            final boolean hasModifyAudioSettings =
-                    mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
-                            == PackageManager.PERMISSION_GRANTED;
             adjustSuggestedStreamVolume(direction, suggestedStreamType, flags, callingPackage,
-                    caller, Binder.getCallingUid(), hasModifyAudioSettings);
+                    caller, Binder.getCallingUid());
         }
     }
 
     private void adjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
-            String callingPackage, String caller, int uid, boolean hasModifyAudioSettings) {
+            String callingPackage, String caller, int uid) {
         if (DEBUG_VOL) Log.d(TAG, "adjustSuggestedStreamVolume() stream=" + suggestedStreamType
                 + ", flags=" + flags + ", caller=" + caller
                 + ", volControlStream=" + mVolumeControlStream
@@ -1938,12 +1933,10 @@
             if (DEBUG_VOL) Log.d(TAG, "Volume controller suppressed adjustment");
         }
 
-        adjustStreamVolume(streamType, direction, flags, callingPackage, caller, uid,
-                hasModifyAudioSettings);
+        adjustStreamVolume(streamType, direction, flags, callingPackage, caller, uid);
     }
 
-    /** @see AudioManager#adjustStreamVolume(int, int, int)
-     * Part of service interface, check permissions here */
+    /** @see AudioManager#adjustStreamVolume(int, int, int) */
     public void adjustStreamVolume(int streamType, int direction, int flags,
             String callingPackage) {
         if ((streamType == AudioManager.STREAM_ACCESSIBILITY) && !canChangeAccessibilityVolume()) {
@@ -1951,17 +1944,14 @@
                     + "CHANGE_ACCESSIBILITY_VOLUME / callingPackage=" + callingPackage);
             return;
         }
-        final boolean hasModifyAudioSettings =
-                mContext.checkCallingPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
-                        == PackageManager.PERMISSION_GRANTED;
         sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_ADJUST_STREAM_VOL, streamType,
                 direction/*val1*/, flags/*val2*/, callingPackage));
         adjustStreamVolume(streamType, direction, flags, callingPackage, callingPackage,
-                Binder.getCallingUid(), hasModifyAudioSettings);
+                Binder.getCallingUid());
     }
 
     protected void adjustStreamVolume(int streamType, int direction, int flags,
-            String callingPackage, String caller, int uid, boolean hasModifyAudioSettings) {
+            String callingPackage, String caller, int uid) {
         if (mUseFixedVolume) {
             return;
         }
@@ -2115,8 +2105,7 @@
                 Log.e(TAG, "adjustStreamVolume() safe volume index = " + oldIndex);
                 mVolumeController.postDisplaySafeVolumeWarning(flags);
             } else if (!isFullVolumeDevice(device)
-                    && (streamState.adjustIndex(direction * step, device, caller,
-                            hasModifyAudioSettings)
+                    && (streamState.adjustIndex(direction * step, device, caller)
                             || streamState.mIsMuted)) {
                 // Post message to set system volume (it in turn will post a
                 // message to persist).
@@ -2338,9 +2327,9 @@
     }
 
     private void onSetStreamVolume(int streamType, int index, int flags, int device,
-            String caller, boolean hasModifyAudioSettings) {
+            String caller) {
         final int stream = mStreamVolumeAlias[streamType];
-        setStreamVolumeInt(stream, index, device, false, caller, hasModifyAudioSettings);
+        setStreamVolumeInt(stream, index, device, false, caller);
         // setting volume on ui sounds stream type also controls silent mode
         if (((flags & AudioManager.FLAG_ALLOW_RINGER_MODES) != 0) ||
                 (stream == getUiSoundsStreamType())) {
@@ -2388,7 +2377,7 @@
                 continue;
             }
             setStreamVolume(groupedStream, index, flags, callingPackage, callingPackage,
-                            Binder.getCallingUid(), true /*hasModifyAudioSettings*/);
+                            Binder.getCallingUid());
         }
     }
 
@@ -2430,8 +2419,7 @@
         return AudioSystem.getMinVolumeIndexForAttributes(attr);
     }
 
-    /** @see AudioManager#setStreamVolume(int, int, int)
-     * Part of service interface, check permissions here */
+    /** @see AudioManager#setStreamVolume(int, int, int) */
     public void setStreamVolume(int streamType, int index, int flags, String callingPackage) {
         if ((streamType == AudioManager.STREAM_ACCESSIBILITY) && !canChangeAccessibilityVolume()) {
             Log.w(TAG, "Trying to call setStreamVolume() for a11y without"
@@ -2454,13 +2442,10 @@
                     + " MODIFY_AUDIO_ROUTING  callingPackage=" + callingPackage);
             return;
         }
-        final boolean hasModifyAudioSettings =
-                mContext.checkCallingOrSelfPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS)
-                        == PackageManager.PERMISSION_GRANTED;
         sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_SET_STREAM_VOL, streamType,
                 index/*val1*/, flags/*val2*/, callingPackage));
         setStreamVolume(streamType, index, flags, callingPackage, callingPackage,
-                Binder.getCallingUid(), hasModifyAudioSettings);
+                Binder.getCallingUid());
     }
 
     private boolean canChangeAccessibilityVolume() {
@@ -2584,7 +2569,7 @@
     }
 
     private void setStreamVolume(int streamType, int index, int flags, String callingPackage,
-            String caller, int uid, boolean hasModifyAudioSettings) {
+            String caller, int uid) {
         if (DEBUG_VOL) {
             Log.d(TAG, "setStreamVolume(stream=" + streamType+", index=" + index
                     + ", calling=" + callingPackage + ")");
@@ -2675,7 +2660,7 @@
                 mPendingVolumeCommand = new StreamVolumeCommand(
                                                     streamType, index, flags, device);
             } else {
-                onSetStreamVolume(streamType, index, flags, device, caller, hasModifyAudioSettings);
+                onSetStreamVolume(streamType, index, flags, device, caller);
                 index = mStreamStates[streamType].getIndex(device);
             }
         }
@@ -2887,22 +2872,19 @@
      * @param index Desired volume index of the stream
      * @param device the device whose volume must be changed
      * @param force If true, set the volume even if the desired volume is same
-     * @param caller
-     * @param hasModifyAudioSettings true if the caller is granted MODIFY_AUDIO_SETTINGS or
-     *                              MODIFY_AUDIO_ROUTING permission
      * as the current volume.
      */
     private void setStreamVolumeInt(int streamType,
                                     int index,
                                     int device,
                                     boolean force,
-                                    String caller, boolean hasModifyAudioSettings) {
+                                    String caller) {
         if (isFullVolumeDevice(device)) {
             return;
         }
         VolumeStreamState streamState = mStreamStates[streamType];
 
-        if (streamState.setIndex(index, device, caller, hasModifyAudioSettings) || force) {
+        if (streamState.setIndex(index, device, caller) || force) {
             // Post message to set system volume (it in turn will post a message
             // to persist).
             sendMsg(mAudioHandler,
@@ -3435,7 +3417,7 @@
                             int device = vss.mIndexMap.keyAt(i);
                             int value = vss.mIndexMap.valueAt(i);
                             if (value == 0) {
-                                vss.setIndex(10, device, TAG, true /*hasModifyAudioSettings*/);
+                                vss.setIndex(10, device, TAG);
                             }
                         }
                         // Persist volume for stream ring when it is changed here
@@ -3780,8 +3762,7 @@
             int streamType = getActiveStreamType(AudioManager.USE_DEFAULT_STREAM_TYPE);
             int device = getDeviceForStream(streamType);
             int index = mStreamStates[mStreamVolumeAlias[streamType]].getIndex(device);
-            setStreamVolumeInt(mStreamVolumeAlias[streamType], index, device, true, caller,
-                    true /*hasModifyAudioSettings*/);
+            setStreamVolumeInt(mStreamVolumeAlias[streamType], index, device, true, caller);
 
             updateStreamVolumeAlias(true /*updateVolumes*/, caller);
 
@@ -4690,44 +4671,6 @@
         return false;
     }
 
-    /**
-     * Minimum attenuation that can be set for alarms over speaker by an application that
-     * doesn't have the MODIFY_AUDIO_SETTINGS permission.
-     */
-    protected static final float MIN_ALARM_ATTENUATION_NON_PRIVILEGED_DB = -36.0f;
-
-    /**
-     * Configures the VolumeStreamState instances for minimum stream index that can be accessed
-     * without MODIFY_AUDIO_SETTINGS permission.
-     * Can only be done successfully once audio policy has finished reading its configuration files
-     * for the volume curves. If not, getStreamVolumeDB will return NaN, and the min value will
-     * remain at the stream min index value.
-     */
-    protected void initMinStreamVolumeWithoutModifyAudioSettings() {
-        int idx;
-        int deviceForAlarm = AudioSystem.DEVICE_OUT_SPEAKER_SAFE;
-        if (AudioSystem.getStreamVolumeDB(AudioSystem.STREAM_ALARM,
-                MIN_STREAM_VOLUME[AudioSystem.STREAM_ALARM], deviceForAlarm) == Float.NaN) {
-            deviceForAlarm = AudioSystem.DEVICE_OUT_SPEAKER;
-        }
-        for (idx = MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM];
-                idx >= MIN_STREAM_VOLUME[AudioSystem.STREAM_ALARM]; idx--) {
-            if (AudioSystem.getStreamVolumeDB(AudioSystem.STREAM_ALARM, idx, deviceForAlarm)
-                    < MIN_ALARM_ATTENUATION_NON_PRIVILEGED_DB) {
-                break;
-            }
-        }
-        final int safeIndex = idx <= MIN_STREAM_VOLUME[AudioSystem.STREAM_ALARM]
-                ? MIN_STREAM_VOLUME[AudioSystem.STREAM_ALARM]
-                : Math.min(idx + 1, MAX_STREAM_VOLUME[AudioSystem.STREAM_ALARM]);
-        // update the VolumeStreamState for STREAM_ALARM and its aliases
-        for (int stream : mStreamVolumeAlias) {
-            if (mStreamVolumeAlias[stream] == AudioSystem.STREAM_ALARM) {
-                mStreamStates[stream].updateNoPermMinIndex(safeIndex);
-            }
-        }
-    }
-
     /** only public for mocking/spying, do not call outside of AudioService */
     @VisibleForTesting
     public int getDeviceForStream(int stream) {
@@ -5392,8 +5335,6 @@
     private class VolumeStreamState {
         private final int mStreamType;
         private int mIndexMin;
-        // min index when user doesn't have permission to change audio settings
-        private int mIndexMinNoPerm;
         private int mIndexMax;
 
         private boolean mIsMuted;
@@ -5435,7 +5376,6 @@
 
             mStreamType = streamType;
             mIndexMin = MIN_STREAM_VOLUME[streamType] * 10;
-            mIndexMinNoPerm = mIndexMin; // may be overwritten later in updateNoPermMinIndex()
             mIndexMax = MAX_STREAM_VOLUME[streamType] * 10;
             AudioSystem.initStreamVolume(streamType, mIndexMin / 10, mIndexMax / 10);
 
@@ -5446,18 +5386,6 @@
             mStreamDevicesChanged.putExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, mStreamType);
         }
 
-        /**
-         * Update the minimum index that can be used without MODIFY_AUDIO_SETTINGS permission
-         * @param index minimum index expressed in "UI units", i.e. no 10x factor
-         */
-        public void updateNoPermMinIndex(int index) {
-            mIndexMinNoPerm = index * 10;
-            if (mIndexMinNoPerm < mIndexMin) {
-                Log.e(TAG, "Invalid mIndexMinNoPerm for stream " + mStreamType);
-                mIndexMinNoPerm = mIndexMin;
-            }
-        }
-
         public int observeDevicesForStream_syncVSS(boolean checkOthers) {
             if (!mSystemServer.isPrivileged()) {
                 return AudioSystem.DEVICE_NONE;
@@ -5539,8 +5467,7 @@
                         continue;
                     }
 
-                    mIndexMap.put(device, getValidIndex(10 * index,
-                            true /*hasModifyAudioSettings*/));
+                    mIndexMap.put(device, getValidIndex(10 * index));
                 }
             }
         }
@@ -5628,20 +5555,17 @@
             }
         }
 
-        public boolean adjustIndex(int deltaIndex, int device, String caller,
-                boolean hasModifyAudioSettings) {
-            return setIndex(getIndex(device) + deltaIndex, device, caller,
-                    hasModifyAudioSettings);
+        public boolean adjustIndex(int deltaIndex, int device, String caller) {
+            return setIndex(getIndex(device) + deltaIndex, device, caller);
         }
 
-        public boolean setIndex(int index, int device, String caller,
-                boolean hasModifyAudioSettings) {
+        public boolean setIndex(int index, int device, String caller) {
             boolean changed;
             int oldIndex;
             synchronized (mSettingsLock) {
                 synchronized (VolumeStreamState.class) {
                     oldIndex = getIndex(device);
-                    index = getValidIndex(index, hasModifyAudioSettings);
+                    index = getValidIndex(index);
                     if ((mStreamType == AudioSystem.STREAM_SYSTEM_ENFORCED) && mCameraSoundForced) {
                         index = mIndexMax;
                     }
@@ -5661,12 +5585,10 @@
                                 mStreamVolumeAlias[streamType] == mStreamType &&
                                 (changed || !aliasStreamState.hasIndexForDevice(device))) {
                             final int scaledIndex = rescaleIndex(index, mStreamType, streamType);
-                            aliasStreamState.setIndex(scaledIndex, device, caller,
-                                    hasModifyAudioSettings);
+                            aliasStreamState.setIndex(scaledIndex, device, caller);
                             if (isCurrentDevice) {
                                 aliasStreamState.setIndex(scaledIndex,
-                                        getDeviceForStream(streamType), caller,
-                                        hasModifyAudioSettings);
+                                        getDeviceForStream(streamType), caller);
                             }
                         }
                     }
@@ -5756,7 +5678,7 @@
                 index = srcMap.valueAt(i);
                 index = rescaleIndex(index, srcStreamType, mStreamType);
 
-                setIndex(index, device, caller, true /*hasModifyAudioSettings*/);
+                setIndex(index, device, caller);
             }
         }
 
@@ -5823,10 +5745,9 @@
             }
         }
 
-        private int getValidIndex(int index, boolean hasModifyAudioSettings) {
-            final int indexMin = hasModifyAudioSettings ? mIndexMin : mIndexMinNoPerm;
-            if (index < indexMin) {
-                return indexMin;
+        private int getValidIndex(int index) {
+            if (index < mIndexMin) {
+                return mIndexMin;
             } else if (mUseFixedVolume || index > mIndexMax) {
                 return mIndexMax;
             }
@@ -5838,13 +5759,7 @@
             pw.print("   Muted: ");
             pw.println(mIsMuted);
             pw.print("   Min: ");
-            pw.print((mIndexMin + 5) / 10);
-            if (mIndexMin != mIndexMinNoPerm) {
-                pw.print(" w/o perm:");
-                pw.println((mIndexMinNoPerm + 5) / 10);
-            } else {
-                pw.println();
-            }
+            pw.println((mIndexMin + 5) / 10);
             pw.print("   Max: ");
             pw.println((mIndexMax + 5) / 10);
             pw.print("   streamVolume:"); pw.println(getStreamVolume(mStreamType));
@@ -5965,9 +5880,7 @@
         final VolumeStreamState streamState = mStreamStates[update.mStreamType];
         if (update.hasVolumeIndex()) {
             final int index = update.getVolumeIndex();
-            streamState.setIndex(index, update.mDevice, update.mCaller,
-                    // trusted as index is always validated before message is posted
-                    true /*hasModifyAudioSettings*/);
+            streamState.setIndex(index, update.mDevice, update.mCaller);
             sVolumeLogger.log(new AudioEventLogger.StringEvent(update.mCaller + " dev:0x"
                     + Integer.toHexString(update.mDevice) + " volIdx:" + index));
         } else {
@@ -6910,8 +6823,7 @@
         for (int device : devices) {
             int index = streamState.getIndex(device);
             if (index > safeMediaVolumeIndex(device)) {
-                streamState.setIndex(safeMediaVolumeIndex(device), device, caller,
-                            true /*hasModifyAudioSettings*/);
+                streamState.setIndex(safeMediaVolumeIndex(device), device, caller);
                 sendMsg(mAudioHandler,
                         MSG_SET_DEVICE_VOLUME,
                         SENDMSG_QUEUE,
@@ -6945,7 +6857,7 @@
                                   mPendingVolumeCommand.mIndex,
                                   mPendingVolumeCommand.mFlags,
                                   mPendingVolumeCommand.mDevice,
-                                  callingPackage, true /*hasModifyAudioSettings*/);
+                                  callingPackage);
                 mPendingVolumeCommand = null;
             }
         }
@@ -7553,39 +7465,29 @@
 
         @Override
         public void adjustSuggestedStreamVolumeForUid(int streamType, int direction, int flags,
-                String callingPackage, int uid, int pid) {
-            final boolean hasModifyAudioSettings =
-                    mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
-                    == PackageManager.PERMISSION_GRANTED;
+                String callingPackage, int uid) {
             // direction and stream type swap here because the public
             // adjustSuggested has a different order than the other methods.
             adjustSuggestedStreamVolume(direction, streamType, flags, callingPackage,
-                    callingPackage, uid, hasModifyAudioSettings);
+                    callingPackage, uid);
         }
 
         @Override
         public void adjustStreamVolumeForUid(int streamType, int direction, int flags,
-                String callingPackage, int uid, int pid) {
+                String callingPackage, int uid) {
             if (direction != AudioManager.ADJUST_SAME) {
                 sVolumeLogger.log(new VolumeEvent(VolumeEvent.VOL_ADJUST_VOL_UID, streamType,
                         direction/*val1*/, flags/*val2*/, new StringBuilder(callingPackage)
                         .append(" uid:").append(uid).toString()));
             }
-            final boolean hasModifyAudioSettings =
-                    mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
-                            == PackageManager.PERMISSION_GRANTED;
             adjustStreamVolume(streamType, direction, flags, callingPackage,
-                    callingPackage, uid, hasModifyAudioSettings);
+                    callingPackage, uid);
         }
 
         @Override
         public void setStreamVolumeForUid(int streamType, int direction, int flags,
-                String callingPackage, int uid, int pid) {
-            final boolean hasModifyAudioSettings =
-                    mContext.checkPermission(Manifest.permission.MODIFY_AUDIO_SETTINGS, pid, uid)
-                            == PackageManager.PERMISSION_GRANTED;
-            setStreamVolume(streamType, direction, flags, callingPackage, callingPackage, uid,
-                    hasModifyAudioSettings);
+                String callingPackage, int uid) {
+            setStreamVolume(streamType, direction, flags, callingPackage, callingPackage, uid);
         }
 
         @Override
diff --git a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
index d7bd794..c65800a 100644
--- a/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
+++ b/services/core/java/com/android/server/media/MediaRouter2ServiceImpl.java
@@ -808,14 +808,11 @@
                 userRecord.mHandler, manager));
 
         for (RouterRecord routerRecord : userRecord.mRouterRecords) {
-            // TODO: Do not use notifyPreferredFeaturesChangedToManagers since it updates all
-            // managers. Instead, Notify only to the manager that is currently being registered.
-
             // TODO: UserRecord <-> routerRecord, why do they reference each other?
             // How about removing mUserRecord from routerRecord?
             routerRecord.mUserRecord.mHandler.sendMessage(
-                    obtainMessage(UserHandler::notifyPreferredFeaturesChangedToManagers,
-                        routerRecord.mUserRecord.mHandler, routerRecord));
+                    obtainMessage(UserHandler::notifyPreferredFeaturesChangedToManager,
+                        routerRecord.mUserRecord.mHandler, routerRecord, manager));
         }
     }
 
@@ -1928,6 +1925,17 @@
             }
         }
 
+        private void notifyPreferredFeaturesChangedToManager(@NonNull RouterRecord routerRecord,
+                @NonNull IMediaRouter2Manager manager) {
+            try {
+                manager.notifyPreferredFeaturesChanged(routerRecord.mPackageName,
+                        routerRecord.mDiscoveryPreference.getPreferredFeatures());
+            } catch (RemoteException ex) {
+                Slog.w(TAG, "Failed to notify preferred features changed."
+                        + " Manager probably died.", ex);
+            }
+        }
+
         private void notifyPreferredFeaturesChangedToManagers(@NonNull RouterRecord routerRecord) {
             MediaRouter2ServiceImpl service = mServiceRef.get();
             if (service == null) {
diff --git a/services/core/java/com/android/server/media/MediaSessionRecord.java b/services/core/java/com/android/server/media/MediaSessionRecord.java
index 02b7582..67f9782 100644
--- a/services/core/java/com/android/server/media/MediaSessionRecord.java
+++ b/services/core/java/com/android/server/media/MediaSessionRecord.java
@@ -328,7 +328,7 @@
                 public void run() {
                     try {
                         mAudioManagerInternal.setStreamVolumeForUid(stream, volumeValue, flags,
-                                opPackageName, uid, pid);
+                                opPackageName, uid);
                     } catch (IllegalArgumentException | SecurityException e) {
                         Log.e(TAG, "Cannot set volume: stream=" + stream + ", value=" + volumeValue
                                 + ", flags=" + flags, e);
@@ -501,15 +501,12 @@
         // Must use opPackageName for adjusting volumes with UID.
         final String opPackageName;
         final int uid;
-        final int pid;
         if (asSystemService) {
             opPackageName = mContext.getOpPackageName();
             uid = Process.SYSTEM_UID;
-            pid = Process.myPid();
         } else {
             opPackageName = callingOpPackageName;
             uid = callingUid;
-            pid = callingPid;
         }
         mHandler.post(new Runnable() {
             @Override
@@ -518,15 +515,15 @@
                     if (useSuggested) {
                         if (AudioSystem.isStreamActive(stream, 0)) {
                             mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(stream,
-                                    direction, flags, opPackageName, uid, pid);
+                                    direction, flags, opPackageName, uid);
                         } else {
                             mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(
                                     AudioManager.USE_DEFAULT_STREAM_TYPE, direction,
-                                    flags | previousFlagPlaySound, opPackageName, uid, pid);
+                                    flags | previousFlagPlaySound, opPackageName, uid);
                         }
                     } else {
                         mAudioManagerInternal.adjustStreamVolumeForUid(stream, direction, flags,
-                                opPackageName, uid, pid);
+                                opPackageName, uid);
                     }
                 } catch (IllegalArgumentException | SecurityException e) {
                     Log.e(TAG, "Cannot adjust volume: direction=" + direction + ", stream="
diff --git a/services/core/java/com/android/server/media/MediaSessionService.java b/services/core/java/com/android/server/media/MediaSessionService.java
index e16582f..84ec440 100644
--- a/services/core/java/com/android/server/media/MediaSessionService.java
+++ b/services/core/java/com/android/server/media/MediaSessionService.java
@@ -2107,19 +2107,16 @@
                     public void run() {
                         final String callingOpPackageName;
                         final int callingUid;
-                        final int callingPid;
                         if (asSystemService) {
                             callingOpPackageName = mContext.getOpPackageName();
                             callingUid = Process.myUid();
-                            callingPid = Process.myPid();
                         } else {
                             callingOpPackageName = opPackageName;
                             callingUid = uid;
-                            callingPid = pid;
                         }
                         try {
                             mAudioManagerInternal.adjustSuggestedStreamVolumeForUid(suggestedStream,
-                                    direction, flags, callingOpPackageName, callingUid, callingPid);
+                                    direction, flags, callingOpPackageName, callingUid);
                         } catch (SecurityException | IllegalArgumentException e) {
                             Log.e(TAG, "Cannot adjust volume: direction=" + direction
                                     + ", suggestedStream=" + suggestedStream + ", flags=" + flags
diff --git a/services/core/java/com/android/server/policy/LegacyGlobalActions.java b/services/core/java/com/android/server/policy/LegacyGlobalActions.java
index 39f7ac0..9c3a394 100644
--- a/services/core/java/com/android/server/policy/LegacyGlobalActions.java
+++ b/services/core/java/com/android/server/policy/LegacyGlobalActions.java
@@ -339,7 +339,7 @@
         });
         dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
         // Don't acquire soft keyboard focus, to avoid destroying state when capturing bugreports
-        mDialog.getWindow().setFlags(FLAG_ALT_FOCUSABLE_IM, FLAG_ALT_FOCUSABLE_IM);
+        dialog.getWindow().setFlags(FLAG_ALT_FOCUSABLE_IM, FLAG_ALT_FOCUSABLE_IM);
 
         dialog.setOnDismissListener(this);
 
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
index c570cf1..b30d408 100644
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -1257,19 +1257,25 @@
         mYOffset = dy;
         mWallpaperScale = scale;
 
-        try {
-            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
-            mService.openSurfaceTransaction();
-            setWallpaperPositionAndScale(dx, dy, scale, false);
-        } catch (RuntimeException e) {
-            Slog.w(TAG, "Error positioning surface of " + mWin
-                    + " pos=(" + dx + "," + dy + ")", e);
-        } finally {
-            mService.closeSurfaceTransaction("setWallpaperOffset");
-            if (SHOW_LIGHT_TRANSACTIONS) Slog.i(TAG,
-                    "<<< CLOSE TRANSACTION setWallpaperOffset");
-            return true;
+        if (mSurfaceController != null) {
+            try {
+                if (SHOW_LIGHT_TRANSACTIONS) {
+                    Slog.i(TAG, ">>> OPEN TRANSACTION setWallpaperOffset");
+                }
+                mService.openSurfaceTransaction();
+                setWallpaperPositionAndScale(dx, dy, scale, false);
+            } catch (RuntimeException e) {
+                Slog.w(TAG, "Error positioning surface of " + mWin
+                        + " pos=(" + dx + "," + dy + ")", e);
+            } finally {
+                mService.closeSurfaceTransaction("setWallpaperOffset");
+                if (SHOW_LIGHT_TRANSACTIONS) {
+                    Slog.i(TAG, "<<< CLOSE TRANSACTION setWallpaperOffset");
+                }
+            }
         }
+
+        return true;
     }
 
     private void setWallpaperPositionAndScale(int dx, int dy, float scale,