Merge "Muting ring volume slider disables notification" into tm-qpr-dev am: 40a293fbdf am: d65e087b0d

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/21164988

Change-Id: I560670cee8bd07312766d494c4a66ef770e121cb
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Behnam Heydarshahi
2023-02-16 15:47:36 +00:00
committed by Automerger Merge Worker
7 changed files with 121 additions and 24 deletions

View File

@@ -51,7 +51,6 @@ public class NotificationVolumePreferenceController extends
private final RingReceiver mReceiver = new RingReceiver();
private final H mHandler = new H();
public NotificationVolumePreferenceController(Context context) {
this(context, KEY_NOTIFICATION_VOLUME);
}
@@ -63,7 +62,9 @@ public class NotificationVolumePreferenceController extends
mVibrateIconId = R.drawable.ic_volume_ringer_vibrate;
mSilentIconId = R.drawable.ic_notifications_off_24dp;
updateRingerMode();
if (updateRingerMode()) {
updateEnabledState();
}
}
/**
@@ -77,12 +78,10 @@ public class NotificationVolumePreferenceController extends
if (mPreference == null) {
setupVolPreference(screen);
}
mSeparateNotification = isSeparateNotificationConfigEnabled();
if (mPreference != null) {
mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
}
updateEffectsSuppressor();
selectPreferenceIconState();
updateEnabledState();
}
/**
@@ -95,15 +94,19 @@ public class NotificationVolumePreferenceController extends
boolean newVal = isSeparateNotificationConfigEnabled();
if (newVal != mSeparateNotification) {
mSeparateNotification = newVal;
// manually hiding the preference because being unavailable does not do the job
// Update UI if config change happens when Sound Settings page is on the foreground
if (mPreference != null) {
mPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
int status = getAvailabilityStatus();
mPreference.setVisible(status == AVAILABLE
|| status == DISABLED_DEPENDENT_SETTING);
if (status == DISABLED_DEPENDENT_SETTING) {
mPreference.setEnabled(false);
}
}
}
}
}
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
@Override
public void onResume() {
@@ -126,10 +129,11 @@ public class NotificationVolumePreferenceController extends
@Override
public int getAvailabilityStatus() {
boolean separateNotification = isSeparateNotificationConfigEnabled();
return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
&& !mHelper.isSingleVolume() && separateNotification
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
? (mRingerMode == AudioManager.RINGER_MODE_NORMAL
? AVAILABLE : DISABLED_DEPENDENT_SETTING)
: UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -158,7 +162,6 @@ public class NotificationVolumePreferenceController extends
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;
@@ -175,6 +178,12 @@ public class NotificationVolumePreferenceController extends
}
}
private void updateEnabledState() {
if (mPreference != null) {
mPreference.setEnabled(mRingerMode == AudioManager.RINGER_MODE_NORMAL);
}
}
private final class H extends Handler {
private static final int UPDATE_EFFECTS_SUPPRESSOR = 1;
private static final int UPDATE_RINGER_MODE = 2;
@@ -191,10 +200,13 @@ public class NotificationVolumePreferenceController extends
updateEffectsSuppressor();
break;
case UPDATE_RINGER_MODE:
updateRingerMode();
if (updateRingerMode()) {
updateEnabledState();
}
break;
case NOTIFICATION_VOLUME_CHANGED:
selectPreferenceIconState();
updateEnabledState();
break;
}
}
@@ -239,5 +251,4 @@ public class NotificationVolumePreferenceController extends
}
}
}
}

View File

@@ -140,11 +140,18 @@ public abstract class RingerModeAffectedVolumePreferenceController extends
return valueUpdated;
}
protected void updateRingerMode() {
/**
* Updates UI Icon in response to ringer mode changes.
* @return whether the ringer mode has changed.
*/
protected boolean updateRingerMode() {
final int ringerMode = mHelper.getRingerModeInternal();
if (mRingerMode == ringerMode) return;
if (mRingerMode == ringerMode) {
return false;
}
mRingerMode = ringerMode;
selectPreferenceIconState();
return true;
}
/**

View File

@@ -93,8 +93,9 @@ public class VolumeSliceHelper {
if (AudioManager.VOLUME_CHANGED_ACTION.equals(action)) {
handleVolumeChanged(context, intent);
} else if (AudioManager.STREAM_MUTE_CHANGED_ACTION.equals(action)
|| AudioManager.STREAM_DEVICES_CHANGED_ACTION.equals(action)) {
} else if (AudioManager.STREAM_MUTE_CHANGED_ACTION.equals(action)) {
handleMuteChanged(context, intent);
} else if (AudioManager.STREAM_DEVICES_CHANGED_ACTION.equals(action)) {
handleStreamChanged(context, intent);
} else {
notifyAllStreamsChanged(context);
@@ -109,8 +110,29 @@ public class VolumeSliceHelper {
}
}
/**
* When mute is changed, notifyChange on relevant Volume Slice ContentResolvers to mark them
* as needing update.
*
* In addition to the matching stream, we always notifyChange for the Notification stream
* when Ring events are issued. This is to make sure that Notification always gets updated
* for RingerMode changes, even if Notification's volume is zero and therefore it would not
* get its own AudioManager.VOLUME_CHANGED_ACTION.
*/
private static void handleMuteChanged(Context context, Intent intent) {
final int inputType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
handleStreamChanged(context, inputType);
if (inputType == AudioManager.STREAM_RING) {
handleStreamChanged(context, AudioManager.STREAM_NOTIFICATION);
}
}
private static void handleStreamChanged(Context context, Intent intent) {
final int inputType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
handleStreamChanged(context, inputType);
}
private static void handleStreamChanged(Context context, int inputType) {
synchronized (sRegisteredUri) {
for (Map.Entry<Uri, Integer> entry : sRegisteredUri.entrySet()) {
if (entry.getValue() == inputType) {