Merge "Merge UP1A.230905.019" into aosp-main-future
diff --git a/res/values/strings.xml b/res/values/strings.xml
index ddbd5f2..fa79cbb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -7151,6 +7151,18 @@
     <!-- Sound: Title for the option managing notification volume. [CHAR LIMIT=30] -->
     <string name="notification_volume_option_title">Notification volume</string>
 
+    <!-- Sound: Content description of ring volume title in silent mode. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=8994620163934249882] -->
+    <string name="ringer_content_description_silent_mode">Ringer silent</string>
+
+    <!-- Sound: Content description of ring volume title in vibrate mode. [CHAR LIMIT=NONE BACKUP_MESSAGE_ID=6261841170896561364] -->
+    <string name="ringer_content_description_vibrate_mode">Ringer vibrate</string>
+
+    <!-- Sound: Content description of notification volume title in vibrate mode. [CHAR LIMIT=NONE] -->
+    <string name="notification_volume_content_description_vibrate_mode">Notification volume muted, notifications will vibrate</string>
+
+    <!-- Sound: Content description of volume title in silent mode [CHAR LIMIT=NONE] -->
+    <string name="volume_content_description_silent_mode"> <xliff:g id="volume type" example="notification volume">%1$s</xliff:g> muted</string>
+
     <!-- Sound: Summary for when notification volume is disabled. [CHAR LIMIT=100] -->
     <string name="notification_volume_disabled_summary">Unavailable because ring is muted</string>
 
diff --git a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
index 0767e65..6bee62c 100644
--- a/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
+++ b/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceController.java
@@ -81,6 +81,8 @@
         final RestrictedSwitchPreference preference =
                 (RestrictedSwitchPreference) pref;
         final CharSequence label = mPkgInfo.applicationInfo.loadLabel(mPm);
+        final boolean isAllowedCn = mCn.flattenToShortString().length()
+                <= NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH;
         final boolean isEnabled = isServiceEnabled(mCn);
         preference.setChecked(isEnabled);
         preference.setOnPreferenceChangeListener((p, newValue) -> {
@@ -105,7 +107,8 @@
                 return false;
             }
         });
-        preference.updateState(mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isEnabled);
+        preference.updateState(
+                mCn.getPackageName(), mPkgInfo.applicationInfo.uid, isAllowedCn, isEnabled);
     }
 
     public void disable(final ComponentName cn) {
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
index be090e3..fb3319c 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintSettings.java
@@ -623,9 +623,9 @@
                 return; // Activity went away
             }
 
-            final Preference addPreference = findPreference(KEY_FINGERPRINT_ADD);
+            mAddFingerprintPreference = findPreference(KEY_FINGERPRINT_ADD);
 
-            if (addPreference == null) {
+            if (mAddFingerprintPreference == null) {
                 return; // b/275519315 Skip if updateAddPreference() invoke before addPreference()
             }
 
diff --git a/src/com/android/settings/notification/MediaVolumePreferenceController.java b/src/com/android/settings/notification/MediaVolumePreferenceController.java
index e40a2b4..79df55a 100644
--- a/src/com/android/settings/notification/MediaVolumePreferenceController.java
+++ b/src/com/android/settings/notification/MediaVolumePreferenceController.java
@@ -52,6 +52,7 @@
 
     public MediaVolumePreferenceController(Context context) {
         super(context, KEY_MEDIA_VOLUME);
+        mVolumePreferenceListener = this::updateContentDescription;
     }
 
     @Override
@@ -109,6 +110,18 @@
         return false;
     }
 
+    private void updateContentDescription() {
+        if (mPreference != null) {
+            if (mPreference.isMuted()) {
+                mPreference.updateContentDescription(
+                        mContext.getString(R.string.volume_content_description_silent_mode,
+                        mPreference.getTitle()));
+            } else {
+                mPreference.updateContentDescription(mPreference.getTitle());
+            }
+        }
+    }
+
     @Override
     public SliceAction getSliceEndItem(Context context) {
         if (!isSupportEndItem()) {
diff --git a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
index dfe6df2..a6b565a 100644
--- a/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
+++ b/src/com/android/settings/notification/NotificationAccessConfirmationActivity.java
@@ -67,7 +67,9 @@
         mUserId = getIntent().getIntExtra(EXTRA_USER_ID, UserHandle.USER_NULL);
         CharSequence mAppLabel;
 
-        if (mComponentName == null || mComponentName.getPackageName() == null) {
+        if (mComponentName == null || mComponentName.getPackageName() == null
+                || mComponentName.flattenToString().length()
+                > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
             finish();
             return;
         }
diff --git a/src/com/android/settings/notification/NotificationAccessSettings.java b/src/com/android/settings/notification/NotificationAccessSettings.java
index 369c4f6..e2ef0dd 100644
--- a/src/com/android/settings/notification/NotificationAccessSettings.java
+++ b/src/com/android/settings/notification/NotificationAccessSettings.java
@@ -66,7 +66,6 @@
     private static final String TAG = "NotifAccessSettings";
     static final String ALLOWED_KEY = "allowed";
     static final String NOT_ALLOWED_KEY = "not_allowed";
-    private static final int MAX_CN_LENGTH = 500;
 
     private static final ManagedServiceSettings.Config CONFIG =
             new ManagedServiceSettings.Config.Builder()
@@ -150,7 +149,8 @@
         for (ServiceInfo service : services) {
             final ComponentName cn = new ComponentName(service.packageName, service.name);
             boolean isAllowed = mNm.isNotificationListenerAccessGranted(cn);
-            if (!isAllowed && cn.flattenToString().length() > MAX_CN_LENGTH) {
+            if (!isAllowed && cn.flattenToString().length()
+                    > NotificationManager.MAX_SERVICE_COMPONENT_NAME_LENGTH) {
                 continue;
             }
 
diff --git a/src/com/android/settings/notification/NotificationVolumePreferenceController.java b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
index cf8a33f..fe7b70b 100644
--- a/src/com/android/settings/notification/NotificationVolumePreferenceController.java
+++ b/src/com/android/settings/notification/NotificationVolumePreferenceController.java
@@ -26,6 +26,7 @@
 import android.os.Looper;
 import android.os.Message;
 import android.service.notification.NotificationListenerService;
+import android.view.View;
 
 import androidx.lifecycle.OnLifecycleEvent;
 import androidx.preference.PreferenceScreen;
@@ -75,6 +76,7 @@
 
         updateEffectsSuppressor();
         selectPreferenceIconState();
+        updateContentDescription();
         updateEnabledState();
     }
 
@@ -120,23 +122,37 @@
     }
 
     @Override
-    protected void selectPreferenceIconState() {
+    protected int getEffectiveRingerMode() {
+        if (mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
+            return AudioManager.RINGER_MODE_SILENT;
+        } else if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
+            if (mHelper.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
+                // Ring is in normal, but notification is in silent.
+                return AudioManager.RINGER_MODE_SILENT;
+            }
+        }
+        return mRingerMode;
+    }
+
+    @Override
+    protected void updateContentDescription() {
         if (mPreference != null) {
-            if (mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
-                mMuteIcon = mVibrateIconId;
-                mPreference.showIcon(mVibrateIconId);
-            } else if (mRingerMode == AudioManager.RINGER_MODE_SILENT
-                    || mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
-                mMuteIcon = mSilentIconId;
-                mPreference.showIcon(mSilentIconId);
-            } else { // ringmode normal: could be that we are still silent
-                if (mHelper.getStreamVolume(AudioManager.STREAM_NOTIFICATION) == 0) {
-                    // ring is in normal, but notification is in silent
-                    mMuteIcon = mSilentIconId;
-                    mPreference.showIcon(mSilentIconId);
-                } else {
-                    mPreference.showIcon(mNormalIconId);
-                }
+            int ringerMode = getEffectiveRingerMode();
+            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
+                mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
+                mPreference.updateContentDescription(
+                        mContext.getString(
+                                R.string.notification_volume_content_description_vibrate_mode));
+            } else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
+                mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_POLITE);
+                mPreference.updateContentDescription(
+                        mContext.getString(R.string.volume_content_description_silent_mode,
+                                mPreference.getTitle()));
+            } else {
+                // Set a11y mode to none in order not to trigger talkback while changing
+                // notification volume in normal mode.
+                mPreference.setAccessibilityLiveRegion(View.ACCESSIBILITY_LIVE_REGION_NONE);
+                mPreference.updateContentDescription(mPreference.getTitle());
             }
         }
     }
@@ -169,6 +185,7 @@
                     break;
                 case NOTIFICATION_VOLUME_CHANGED:
                     selectPreferenceIconState();
+                    updateContentDescription();
                     updateEnabledState();
                     break;
             }
diff --git a/src/com/android/settings/notification/RingerModeAffectedVolumePreferenceController.java b/src/com/android/settings/notification/RingerModeAffectedVolumePreferenceController.java
index 3687770..ab65f8f 100644
--- a/src/com/android/settings/notification/RingerModeAffectedVolumePreferenceController.java
+++ b/src/com/android/settings/notification/RingerModeAffectedVolumePreferenceController.java
@@ -26,6 +26,7 @@
 import android.util.Log;
 
 import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
 
 import java.util.Objects;
 
@@ -54,6 +55,7 @@
         if (mVibrator != null && !mVibrator.hasVibrator()) {
             mVibrator = null;
         }
+        mVolumePreferenceListener = this::updateContentDescription;
     }
 
     protected void updateEffectsSuppressor() {
@@ -123,6 +125,7 @@
         }
         mRingerMode = ringerMode;
         selectPreferenceIconState();
+        updateContentDescription();
         return true;
     }
 
@@ -131,10 +134,11 @@
      */
     protected void selectPreferenceIconState() {
         if (mPreference != null) {
-            if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
+            int ringerMode = getEffectiveRingerMode();
+            if (ringerMode == AudioManager.RINGER_MODE_NORMAL) {
                 mPreference.showIcon(mNormalIconId);
             } else {
-                if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE && mVibrator != null) {
+                if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
                     mMuteIcon = mVibrateIconId;
                 } else {
                     mMuteIcon = mSilentIconId;
@@ -144,6 +148,28 @@
         }
     }
 
+    protected int getEffectiveRingerMode() {
+        if (mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
+            return AudioManager.RINGER_MODE_SILENT;
+        }
+        return mRingerMode;
+    }
+
+    protected void updateContentDescription() {
+        if (mPreference != null) {
+            int ringerMode = getEffectiveRingerMode();
+            if (ringerMode == AudioManager.RINGER_MODE_VIBRATE) {
+                mPreference.updateContentDescription(
+                        mContext.getString(R.string.ringer_content_description_vibrate_mode));
+            } else if (ringerMode == AudioManager.RINGER_MODE_SILENT) {
+                mPreference.updateContentDescription(
+                        mContext.getString(R.string.ringer_content_description_silent_mode));
+            } else {
+                mPreference.updateContentDescription(mPreference.getTitle());
+            }
+        }
+    }
+
     protected abstract boolean hintsMatch(int hints);
 
 }
diff --git a/src/com/android/settings/notification/SeparateRingVolumePreferenceController.java b/src/com/android/settings/notification/SeparateRingVolumePreferenceController.java
index b8a9908..91926e3 100644
--- a/src/com/android/settings/notification/SeparateRingVolumePreferenceController.java
+++ b/src/com/android/settings/notification/SeparateRingVolumePreferenceController.java
@@ -65,6 +65,7 @@
         mReceiver.register(true);
         updateEffectsSuppressor();
         selectPreferenceIconState();
+        updateContentDescription();
 
         if (mPreference != null) {
             mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
diff --git a/src/com/android/settings/notification/VolumeSeekBarPreference.java b/src/com/android/settings/notification/VolumeSeekBarPreference.java
index 14955c4..0000eba 100644
--- a/src/com/android/settings/notification/VolumeSeekBarPreference.java
+++ b/src/com/android/settings/notification/VolumeSeekBarPreference.java
@@ -47,10 +47,13 @@
 
     protected SeekBar mSeekBar;
     private int mStream;
-    private SeekBarVolumizer mVolumizer;
+    @VisibleForTesting
+    SeekBarVolumizer mVolumizer;
     private Callback mCallback;
+    private Listener mListener;
     private ImageView mIconView;
     private TextView mSuppressionTextView;
+    private TextView mTitle;
     private String mSuppressionText;
     private boolean mMuted;
     private boolean mZenMuted;
@@ -98,6 +101,10 @@
         mCallback = callback;
     }
 
+    public void setListener(Listener listener) {
+        mListener = listener;
+    }
+
     public void onActivityResume() {
         if (mStopped) {
             init();
@@ -118,6 +125,7 @@
         mSeekBar = (SeekBar) view.findViewById(com.android.internal.R.id.seekbar);
         mIconView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
         mSuppressionTextView = (TextView) view.findViewById(R.id.suppression_text);
+        mTitle = (TextView) view.findViewById(com.android.internal.R.id.title);
         init();
     }
 
@@ -142,6 +150,9 @@
                 mMuted = muted;
                 mZenMuted = zenMuted;
                 updateIconView();
+                if (mListener != null) {
+                    mListener.onUpdateMuteState();
+                }
             }
             @Override
             public void onStartTrackingTouch(SeekBarVolumizer sbv) {
@@ -165,6 +176,9 @@
         mVolumizer.setSeekBar(mSeekBar);
         updateIconView();
         updateSuppressionText();
+        if (mListener != null) {
+            mListener.onUpdateMuteState();
+        }
         if (!isEnabled()) {
             mSeekBar.setEnabled(false);
             mVolumizer.stop();
@@ -175,7 +189,7 @@
         if (mIconView == null) return;
         if (mIconResId != 0) {
             mIconView.setImageResource(mIconResId);
-        } else if (mMuteIconResId != 0 && mMuted && !mZenMuted) {
+        } else if (mMuteIconResId != 0 && isMuted()) {
             mIconView.setImageResource(mMuteIconResId);
         } else {
             mIconView.setImageDrawable(getIcon());
@@ -208,6 +222,10 @@
         updateSuppressionText();
     }
 
+    protected boolean isMuted() {
+        return mMuted && !mZenMuted;
+    }
+
     protected void updateSuppressionText() {
         if (mSuppressionTextView != null && mSeekBar != null) {
             mSuppressionTextView.setText(mSuppressionText);
@@ -216,6 +234,19 @@
         }
     }
 
+    /**
+     * Update content description of title to improve talkback announcements.
+     */
+    protected void updateContentDescription(CharSequence contentDescription) {
+        if (mTitle == null) return;
+        mTitle.setContentDescription(contentDescription);
+    }
+
+    protected void setAccessibilityLiveRegion(int mode) {
+        if (mTitle == null) return;
+        mTitle.setAccessibilityLiveRegion(mode);
+    }
+
     public interface Callback {
         void onSampleStarting(SeekBarVolumizer sbv);
         void onStreamValueChanged(int stream, int progress);
@@ -225,4 +256,15 @@
          */
         void onStartTrackingTouch(SeekBarVolumizer sbv);
     }
+
+    /**
+     * Listener to view updates in volumeSeekbarPreference.
+     */
+    public interface Listener {
+
+        /**
+         * Listener to mute state updates.
+         */
+        void onUpdateMuteState();
+    }
 }
diff --git a/src/com/android/settings/notification/VolumeSeekBarPreferenceController.java b/src/com/android/settings/notification/VolumeSeekBarPreferenceController.java
index 0414565..285e8dd 100644
--- a/src/com/android/settings/notification/VolumeSeekBarPreferenceController.java
+++ b/src/com/android/settings/notification/VolumeSeekBarPreferenceController.java
@@ -36,6 +36,7 @@
     protected VolumeSeekBarPreference mPreference;
     protected VolumeSeekBarPreference.Callback mVolumePreferenceCallback;
     protected AudioHelper mHelper;
+    protected VolumeSeekBarPreference.Listener mVolumePreferenceListener;
 
     public VolumeSeekBarPreferenceController(Context context, String key) {
         super(context, key);
@@ -62,6 +63,7 @@
     protected void setupVolPreference(PreferenceScreen screen) {
         mPreference = screen.findPreference(getPreferenceKey());
         mPreference.setCallback(mVolumePreferenceCallback);
+        mPreference.setListener(mVolumePreferenceListener);
         mPreference.setStream(getAudioStream());
         mPreference.setMuteIcon(getMuteIcon());
     }
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAccessConfirmationActivityTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAccessConfirmationActivityTest.java
new file mode 100644
index 0000000..86631ff
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAccessConfirmationActivityTest.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2023 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.settings.notification;
+
+import static com.android.internal.notification.NotificationAccessConfirmationActivityContract.EXTRA_COMPONENT_NAME;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.robolectric.Shadows.shadowOf;
+
+import android.annotation.Nullable;
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Intent;
+import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageInfo;
+import android.widget.TextView;
+
+import com.android.settings.R;
+
+import com.google.common.base.Strings;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class NotificationAccessConfirmationActivityTest {
+
+    @Test
+    public void start_showsDialog() {
+        ComponentName cn = new ComponentName("com.example", "com.example.SomeService");
+        installPackage(cn.getPackageName(), "X");
+
+        NotificationAccessConfirmationActivity activity = startActivityWithIntent(cn);
+
+        assertThat(activity.isFinishing()).isFalse();
+        assertThat(getDialogText(activity)).isEqualTo(
+                activity.getString(R.string.notification_listener_security_warning_summary, "X"));
+    }
+
+    @Test
+    public void start_withMissingPackage_finishes() {
+        ComponentName cn = new ComponentName("com.example", "com.example.SomeService");
+
+        NotificationAccessConfirmationActivity activity = startActivityWithIntent(cn);
+
+        assertThat(getDialogText(activity)).isNull();
+        assertThat(activity.isFinishing()).isTrue();
+    }
+
+    @Test
+    public void start_componentNameTooLong_finishes() {
+        ComponentName longCn = new ComponentName("com.example", Strings.repeat("Blah", 150));
+        installPackage(longCn.getPackageName(), "<Unused>");
+
+        NotificationAccessConfirmationActivity activity = startActivityWithIntent(longCn);
+
+        assertThat(getDialogText(activity)).isNull();
+        assertThat(activity.isFinishing()).isTrue();
+    }
+
+    private static NotificationAccessConfirmationActivity startActivityWithIntent(
+            ComponentName cn) {
+        return Robolectric.buildActivity(
+                        NotificationAccessConfirmationActivity.class,
+                        new Intent().putExtra(EXTRA_COMPONENT_NAME, cn))
+                .setup()
+                .get();
+    }
+
+    private static void installPackage(String packageName, String appName) {
+        PackageInfo pi = new PackageInfo();
+        pi.packageName = packageName;
+        pi.applicationInfo = new ApplicationInfo();
+        pi.applicationInfo.packageName = packageName;
+        pi.applicationInfo.name = appName;
+        shadowOf(RuntimeEnvironment.application.getPackageManager()).installPackage(pi);
+    }
+
+    @Nullable
+    private static String getDialogText(Activity activity) {
+        TextView tv = activity.getWindow().findViewById(android.R.id.message);
+        CharSequence text = (tv != null ? tv.getText() : null);
+        return text != null ? text.toString() : null;
+    }
+
+}
diff --git a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
index 2d54c38..f7e32a2 100644
--- a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceControllerTest.java
@@ -49,6 +49,8 @@
     @Mock
     private VolumeSeekBarPreference.Callback mCallback;
     @Mock
+    private VolumeSeekBarPreference.Listener mListener;
+    @Mock
     private AudioHelper mHelper;
 
     private VolumeSeekBarPreferenceControllerTestable mController;
@@ -59,7 +61,7 @@
         when(mScreen.findPreference(nullable(String.class))).thenReturn(mPreference);
         when(mPreference.getKey()).thenReturn("key");
         mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, true,
-                mPreference.getKey());
+                mPreference.getKey(), mListener);
         mController.setAudioHelper(mHelper);
     }
 
@@ -70,18 +72,20 @@
         verify(mPreference).setCallback(mCallback);
         verify(mPreference).setStream(VolumeSeekBarPreferenceControllerTestable.AUDIO_STREAM);
         verify(mPreference).setMuteIcon(VolumeSeekBarPreferenceControllerTestable.MUTE_ICON);
+        verify(mPreference).setListener(mListener);
     }
 
     @Test
     public void displayPreference_notAvailable_shouldNotUpdatePreference() {
         mController = new VolumeSeekBarPreferenceControllerTestable(mContext, mCallback, false,
-                mPreference.getKey());
+                mPreference.getKey(), mListener);
 
         mController.displayPreference(mScreen);
 
         verify(mPreference, never()).setCallback(any(VolumeSeekBarPreference.Callback.class));
         verify(mPreference, never()).setStream(anyInt());
         verify(mPreference, never()).setMuteIcon(anyInt());
+        verify(mPreference, never()).setListener(mListener);
     }
 
     @Test
@@ -157,10 +161,12 @@
         private boolean mAvailable;
 
         VolumeSeekBarPreferenceControllerTestable(Context context,
-            VolumeSeekBarPreference.Callback callback, boolean available, String key) {
+                VolumeSeekBarPreference.Callback callback, boolean available, String key,
+                VolumeSeekBarPreference.Listener listener) {
             super(context, key);
             setCallback(callback);
             mAvailable = available;
+            mVolumePreferenceListener = listener;
         }
 
         @Override
diff --git a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
index d74f76a..59f0bcb 100644
--- a/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/notification/VolumeSeekBarPreferenceTest.java
@@ -18,11 +18,14 @@
 
 import static org.mockito.ArgumentMatchers.anyInt;
 import static org.mockito.Mockito.doCallRealMethod;
+import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import android.content.Context;
 import android.media.AudioManager;
+import android.preference.SeekBarVolumizer;
+import android.widget.SeekBar;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -34,18 +37,28 @@
 @RunWith(RobolectricTestRunner.class)
 public class VolumeSeekBarPreferenceTest {
 
+    private static final CharSequence CONTENT_DESCRIPTION = "TEST";
     @Mock
     private AudioManager mAudioManager;
     @Mock
     private VolumeSeekBarPreference mPreference;
     @Mock
     private Context mContext;
+    @Mock
+    private SeekBar mSeekBar;
+    @Mock
+    private SeekBarVolumizer mVolumizer;
+    private VolumeSeekBarPreference.Listener mListener;
 
     @Before
     public void setUp() {
         MockitoAnnotations.initMocks(this);
         when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
+        doCallRealMethod().when(mPreference).updateContentDescription(CONTENT_DESCRIPTION);
+        mPreference.mSeekBar = mSeekBar;
         mPreference.mAudioManager = mAudioManager;
+        mPreference.mVolumizer = mVolumizer;
+        mListener = () -> mPreference.updateContentDescription(CONTENT_DESCRIPTION);
     }
 
     @Test
@@ -65,4 +78,24 @@
         verify(mPreference).setMin(min);
         verify(mPreference).setProgress(progress);
     }
+
+    @Test
+    public void init_listenerIsCalled() {
+        doCallRealMethod().when(mPreference).setListener(mListener);
+        doCallRealMethod().when(mPreference).init();
+
+        mPreference.setListener(mListener);
+        mPreference.init();
+
+        verify(mPreference).updateContentDescription(CONTENT_DESCRIPTION);
+    }
+
+    @Test
+    public void init_listenerNotSet_noException() {
+        doCallRealMethod().when(mPreference).init();
+
+        mPreference.init();
+
+        verify(mPreference, never()).updateContentDescription(CONTENT_DESCRIPTION);
+    }
 }
diff --git a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
index 249b713..4601a1c 100644
--- a/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
+++ b/tests/unit/src/com/android/settings/applications/specialaccess/notificationaccess/ApprovalPreferenceControllerTest.java
@@ -84,6 +84,36 @@
     }
 
     @Test
+    public void updateState_enabled() {
+        when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
+                AppOpsManager.MODE_ALLOWED);
+        when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
+        RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
+                mContext);
+        pref.setAppOps(mAppOpsManager);
+
+        mController.updateState(pref);
+
+        assertThat(pref.isEnabled()).isTrue();
+    }
+
+    @Test
+    public void updateState_invalidCn_disabled() {
+        ComponentName longCn = new ComponentName("com.example.package",
+                com.google.common.base.Strings.repeat("Blah", 150));
+        mController.setCn(longCn);
+        when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
+                AppOpsManager.MODE_ALLOWED);
+        RestrictedSwitchPreference pref = new RestrictedSwitchPreference(
+                mContext);
+        pref.setAppOps(mAppOpsManager);
+
+        mController.updateState(pref);
+
+        assertThat(pref.isEnabled()).isFalse();
+    }
+
+    @Test
     public void updateState_checked() {
         when(mAppOpsManager.noteOpNoThrow(anyInt(), anyInt(), anyString())).thenReturn(
                 AppOpsManager.MODE_ALLOWED);