Merge "Add notification volume controller in settings" into tm-qpr-dev am: 7f6c833b89
Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/19940409 Change-Id: Iffd5dcd7eb9ad645807d9529f352582457dc3f0e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
committed by
Automerger Merge Worker
commit
8b2496eb9e
@@ -16,26 +16,96 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.INotificationManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.Vibrator;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class NotificationVolumePreferenceController extends
|
||||
RingVolumePreferenceController {
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Update notification volume icon in Settings in response to user adjusting volume
|
||||
*/
|
||||
public class NotificationVolumePreferenceController extends VolumeSeekBarPreferenceController {
|
||||
|
||||
private static final String TAG = "NotificationVolumePreferenceController";
|
||||
private static final String KEY_NOTIFICATION_VOLUME = "notification_volume";
|
||||
|
||||
private Vibrator mVibrator;
|
||||
private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
|
||||
private ComponentName mSuppressor;
|
||||
private final RingReceiver mReceiver = new RingReceiver();
|
||||
private final H mHandler = new H();
|
||||
private INotificationManager mNoMan;
|
||||
|
||||
|
||||
private int mMuteIcon;
|
||||
private final int mNormalIconId = R.drawable.ic_notifications;
|
||||
private final int mVibrateIconId = R.drawable.ic_volume_ringer_vibrate;
|
||||
private final int mSilentIconId = R.drawable.ic_notifications_off_24dp;
|
||||
|
||||
private final boolean mRingNotificationAliased;
|
||||
|
||||
|
||||
public NotificationVolumePreferenceController(Context context) {
|
||||
super(context, KEY_NOTIFICATION_VOLUME);
|
||||
this(context, KEY_NOTIFICATION_VOLUME);
|
||||
}
|
||||
|
||||
public NotificationVolumePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE);
|
||||
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
||||
mVibrator = null;
|
||||
}
|
||||
|
||||
mRingNotificationAliased = mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_alias_ring_notif_stream_types);
|
||||
updateRingerMode();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mReceiver.register(true);
|
||||
updateEffectsSuppressor();
|
||||
updatePreferenceIconAndSliderState();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mReceiver.register(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
|
||||
// Show separate notification slider if ring/notification are not aliased by AudioManager --
|
||||
// if they are, notification volume is controlled by RingVolumePreferenceController.
|
||||
return mContext.getResources().getBoolean(R.bool.config_show_notification_volume)
|
||||
&& !Utils.isVoiceCapable(mContext) && !mHelper.isSingleVolume()
|
||||
&& (!mRingNotificationAliased || !Utils.isVoiceCapable(mContext))
|
||||
&& !mHelper.isSingleVolume()
|
||||
? AVAILABLE : UNSUPPORTED_ON_DEVICE;
|
||||
}
|
||||
|
||||
@@ -54,6 +124,11 @@ public class NotificationVolumePreferenceController extends
|
||||
return KEY_NOTIFICATION_VOLUME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useDynamicSliceSummary() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAudioStream() {
|
||||
return AudioManager.STREAM_NOTIFICATION;
|
||||
@@ -61,7 +136,141 @@ public class NotificationVolumePreferenceController extends
|
||||
|
||||
@Override
|
||||
public int getMuteIcon() {
|
||||
return R.drawable.ic_notifications_off_24dp;
|
||||
return mMuteIcon;
|
||||
}
|
||||
|
||||
private void updateRingerMode() {
|
||||
final int ringerMode = mHelper.getRingerModeInternal();
|
||||
if (mRingerMode == ringerMode) return;
|
||||
mRingerMode = ringerMode;
|
||||
updatePreferenceIconAndSliderState();
|
||||
}
|
||||
|
||||
private void updateEffectsSuppressor() {
|
||||
final ComponentName suppressor = NotificationManager.from(mContext).getEffectsSuppressor();
|
||||
if (Objects.equals(suppressor, mSuppressor)) return;
|
||||
|
||||
if (mNoMan == null) {
|
||||
mNoMan = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
}
|
||||
|
||||
final int hints;
|
||||
try {
|
||||
hints = mNoMan.getHintsFromListenerNoToken();
|
||||
} catch (android.os.RemoteException exception) {
|
||||
Log.w(TAG, "updateEffectsSuppressor: " + exception.getLocalizedMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (hintsMatch(hints)) {
|
||||
|
||||
mSuppressor = suppressor;
|
||||
if (mPreference != null) {
|
||||
final String text = SuppressorHelper.getSuppressionText(mContext, suppressor);
|
||||
mPreference.setSuppressionText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean hintsMatch(int hints) {
|
||||
boolean allEffectsDisabled =
|
||||
(hints & NotificationListenerService.HINT_HOST_DISABLE_EFFECTS) != 0;
|
||||
boolean notificationEffectsDisabled =
|
||||
(hints & NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS) != 0;
|
||||
|
||||
return allEffectsDisabled || notificationEffectsDisabled;
|
||||
}
|
||||
|
||||
private void updatePreferenceIconAndSliderState() {
|
||||
if (mPreference != null) {
|
||||
if (mVibrator != null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||
mMuteIcon = mVibrateIconId;
|
||||
mPreference.showIcon(mVibrateIconId);
|
||||
mPreference.setEnabled(false);
|
||||
|
||||
} else if (mRingerMode == AudioManager.RINGER_MODE_SILENT
|
||||
|| mVibrator == null && mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||
mMuteIcon = mSilentIconId;
|
||||
mPreference.showIcon(mSilentIconId);
|
||||
mPreference.setEnabled(false);
|
||||
} else { // ringmode normal: could be that we are still silent
|
||||
mPreference.setEnabled(true);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final class H extends Handler {
|
||||
private static final int UPDATE_EFFECTS_SUPPRESSOR = 1;
|
||||
private static final int UPDATE_RINGER_MODE = 2;
|
||||
private static final int NOTIFICATION_VOLUME_CHANGED = 3;
|
||||
|
||||
private H() {
|
||||
super(Looper.getMainLooper());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
switch (msg.what) {
|
||||
case UPDATE_EFFECTS_SUPPRESSOR:
|
||||
updateEffectsSuppressor();
|
||||
break;
|
||||
case UPDATE_RINGER_MODE:
|
||||
updateRingerMode();
|
||||
break;
|
||||
case NOTIFICATION_VOLUME_CHANGED:
|
||||
updatePreferenceIconAndSliderState();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* For notification volume icon to be accurate, we need to listen to volume change as well.
|
||||
* That is because the icon can change from mute/vibrate to normal without ringer mode changing.
|
||||
*/
|
||||
private class RingReceiver extends BroadcastReceiver {
|
||||
private boolean mRegistered;
|
||||
|
||||
public void register(boolean register) {
|
||||
if (mRegistered == register) return;
|
||||
if (register) {
|
||||
final IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED);
|
||||
filter.addAction(AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION);
|
||||
filter.addAction(AudioManager.VOLUME_CHANGED_ACTION);
|
||||
mContext.registerReceiver(this, filter);
|
||||
} else {
|
||||
mContext.unregisterReceiver(this);
|
||||
}
|
||||
mRegistered = register;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
if (NotificationManager.ACTION_EFFECTS_SUPPRESSOR_CHANGED.equals(action)) {
|
||||
mHandler.sendEmptyMessage(H.UPDATE_EFFECTS_SUPPRESSOR);
|
||||
} else if (AudioManager.INTERNAL_RINGER_MODE_CHANGED_ACTION.equals(action)) {
|
||||
mHandler.sendEmptyMessage(H.UPDATE_RINGER_MODE);
|
||||
} else if (AudioManager.VOLUME_CHANGED_ACTION.equals(action)) {
|
||||
int streamType = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_TYPE, -1);
|
||||
if (streamType == AudioManager.STREAM_NOTIFICATION) {
|
||||
int streamValue = intent.getIntExtra(AudioManager.EXTRA_VOLUME_STREAM_VALUE,
|
||||
-1);
|
||||
mHandler.obtainMessage(H.NOTIFICATION_VOLUME_CHANGED, streamValue, 0)
|
||||
.sendToTarget();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.INotificationManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ComponentName;
|
||||
@@ -26,30 +27,56 @@ import android.media.AudioManager;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.Message;
|
||||
import android.os.ServiceManager;
|
||||
import android.os.Vibrator;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.lifecycle.OnLifecycleEvent;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* This slider can represent both ring and notification, if the corresponding streams are aliased,
|
||||
* and only ring if the streams are not aliased.
|
||||
*/
|
||||
public class RingVolumePreferenceController extends VolumeSeekBarPreferenceController {
|
||||
|
||||
private static final String TAG = "RingVolumeController";
|
||||
private static final String TAG = "RingVolumePreferenceController";
|
||||
private static final String KEY_RING_VOLUME = "ring_volume";
|
||||
|
||||
private Vibrator mVibrator;
|
||||
private int mRingerMode = -1;
|
||||
private int mRingerMode = AudioManager.RINGER_MODE_NORMAL;
|
||||
private ComponentName mSuppressor;
|
||||
private final RingReceiver mReceiver = new RingReceiver();
|
||||
private final H mHandler = new H();
|
||||
|
||||
private int mMuteIcon;
|
||||
|
||||
/*
|
||||
* Whether ring and notification streams are aliased together by AudioManager.
|
||||
* If they are, we'll present one volume control for both.
|
||||
* If not, we'll present separate volume controls.
|
||||
*/
|
||||
private final boolean mRingAliasNotif;
|
||||
|
||||
private final int mNormalIconId;
|
||||
@VisibleForTesting
|
||||
final int mVibrateIconId;
|
||||
@VisibleForTesting
|
||||
final int mSilentIconId;
|
||||
|
||||
@VisibleForTesting
|
||||
final int mTitleId;
|
||||
|
||||
private INotificationManager mNoMan;
|
||||
|
||||
public RingVolumePreferenceController(Context context) {
|
||||
this(context, KEY_RING_VOLUME);
|
||||
}
|
||||
@@ -60,9 +87,31 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
if (mVibrator != null && !mVibrator.hasVibrator()) {
|
||||
mVibrator = null;
|
||||
}
|
||||
|
||||
mRingAliasNotif = isRingAliasNotification();
|
||||
if (mRingAliasNotif) {
|
||||
mTitleId = R.string.ring_volume_option_title;
|
||||
|
||||
mNormalIconId = R.drawable.ic_notifications;
|
||||
mSilentIconId = R.drawable.ic_notifications_off_24dp;
|
||||
} else {
|
||||
mTitleId = R.string.separate_ring_volume_option_title;
|
||||
|
||||
mNormalIconId = R.drawable.ic_ring_volume;
|
||||
mSilentIconId = R.drawable.ic_ring_volume_off;
|
||||
}
|
||||
// todo: set a distinct vibrate icon for ring vs notification
|
||||
mVibrateIconId = R.drawable.ic_volume_ringer_vibrate;
|
||||
|
||||
updateRingerMode();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isRingAliasNotification() {
|
||||
return mContext.getResources().getBoolean(
|
||||
com.android.internal.R.bool.config_alias_ring_notif_stream_types);
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
|
||||
@Override
|
||||
public void onResume() {
|
||||
@@ -70,6 +119,7 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
mReceiver.register(true);
|
||||
updateEffectsSuppressor();
|
||||
updatePreferenceIcon();
|
||||
setPreferenceTitle();
|
||||
}
|
||||
|
||||
@OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)
|
||||
@@ -115,7 +165,8 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
return mMuteIcon;
|
||||
}
|
||||
|
||||
private void updateRingerMode() {
|
||||
@VisibleForTesting
|
||||
void updateRingerMode() {
|
||||
final int ringerMode = mHelper.getRingerModeInternal();
|
||||
if (mRingerMode == ringerMode) return;
|
||||
mRingerMode = ringerMode;
|
||||
@@ -125,28 +176,73 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
private void updateEffectsSuppressor() {
|
||||
final ComponentName suppressor = NotificationManager.from(mContext).getEffectsSuppressor();
|
||||
if (Objects.equals(suppressor, mSuppressor)) return;
|
||||
mSuppressor = suppressor;
|
||||
if (mPreference != null) {
|
||||
final String text = SuppressorHelper.getSuppressionText(mContext, suppressor);
|
||||
mPreference.setSuppressionText(text);
|
||||
|
||||
if (mNoMan == null) {
|
||||
mNoMan = INotificationManager.Stub.asInterface(
|
||||
ServiceManager.getService(Context.NOTIFICATION_SERVICE));
|
||||
}
|
||||
updatePreferenceIcon();
|
||||
|
||||
final int hints;
|
||||
try {
|
||||
hints = mNoMan.getHintsFromListenerNoToken();
|
||||
} catch (android.os.RemoteException ex) {
|
||||
Log.w(TAG, "updateEffectsSuppressor: " + ex.getMessage());
|
||||
return;
|
||||
}
|
||||
|
||||
if (hintsMatch(hints, mRingAliasNotif)) {
|
||||
mSuppressor = suppressor;
|
||||
if (mPreference != null) {
|
||||
final String text = SuppressorHelper.getSuppressionText(mContext, suppressor);
|
||||
mPreference.setSuppressionText(text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean hintsMatch(int hints, boolean ringNotificationAliased) {
|
||||
return (hints & NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS) != 0
|
||||
|| (hints & NotificationListenerService.HINT_HOST_DISABLE_EFFECTS) != 0
|
||||
|| ((hints & NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS)
|
||||
!= 0 && ringNotificationAliased);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setPreference(VolumeSeekBarPreference volumeSeekBarPreference) {
|
||||
mPreference = volumeSeekBarPreference;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void setVibrator(Vibrator vibrator) {
|
||||
mVibrator = vibrator;
|
||||
}
|
||||
|
||||
private void updatePreferenceIcon() {
|
||||
if (mPreference != null) {
|
||||
if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE) {
|
||||
mMuteIcon = R.drawable.ic_volume_ringer_vibrate;
|
||||
mPreference.showIcon(R.drawable.ic_volume_ringer_vibrate);
|
||||
} else if (mRingerMode == AudioManager.RINGER_MODE_SILENT) {
|
||||
mMuteIcon = R.drawable.ic_notifications_off_24dp;
|
||||
mPreference.showIcon(R.drawable.ic_notifications_off_24dp);
|
||||
if (mRingerMode == AudioManager.RINGER_MODE_NORMAL) {
|
||||
mPreference.showIcon(mNormalIconId);
|
||||
} else {
|
||||
mPreference.showIcon(R.drawable.ic_notifications);
|
||||
if (mRingerMode == AudioManager.RINGER_MODE_VIBRATE && mVibrator != null) {
|
||||
mMuteIcon = mVibrateIconId;
|
||||
} else {
|
||||
mMuteIcon = mSilentIconId;
|
||||
}
|
||||
mPreference.showIcon(mMuteIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This slider can represent both ring and notification, or only ring.
|
||||
* Note: This cannot be used in the constructor, as the reference to preference object would
|
||||
* still be null.
|
||||
*/
|
||||
private void setPreferenceTitle() {
|
||||
if (mPreference != null) {
|
||||
mPreference.setTitle(mTitleId);
|
||||
}
|
||||
}
|
||||
|
||||
private final class H extends Handler {
|
||||
private static final int UPDATE_EFFECTS_SUPPRESSOR = 1;
|
||||
private static final int UPDATE_RINGER_MODE = 2;
|
||||
|
@@ -54,7 +54,7 @@ public class PanelSlicesAdapter
|
||||
* Maximum number of slices allowed on the panel view.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static final int MAX_NUM_OF_SLICES = 6;
|
||||
static final int MAX_NUM_OF_SLICES = 7;
|
||||
|
||||
private final List<LiveData<Slice>> mSliceLiveData;
|
||||
private final int mMetricsCategory;
|
||||
|
@@ -217,6 +217,16 @@ public class CustomSliceRegistry {
|
||||
.appendPath("ring_volume")
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Full {@link Uri} for the Notification volume Slice.
|
||||
*/
|
||||
public static final Uri VOLUME_NOTIFICATION_URI = new Uri.Builder()
|
||||
.scheme(ContentResolver.SCHEME_CONTENT)
|
||||
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
|
||||
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
|
||||
.appendPath("notification_volume")
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Full {@link Uri} for the all volume Slices.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user