Add notification volume controller in settings
Separate notification and ring controllers based on the ring/volume stream alias boolean in config.xml. For both ring and volume controller: Not show vibrate icon when vibration is not supported on device. Show silent icon instead. Known issue: Add the notification volume slider only in Settings, and not in VolumePanelDialog. When the alias is set to false and the streams separated, the ring volume slider in VolumePanelDialog keeps its title of "Ring & notification volume" instead of changing to "Ring volume". Bug: b/38477228 Test: make DEBUG_ROBOLECTRIC=1 ROBOTEST_FILTER=NotificationVolumePreferenceControllerTest RunSettingsRoboTests -j40 make DEBUG_ROBOLECTRIC=1 ROBOTEST_FILTER=RingVolumePreferenceControllerTest RunSettingsRoboTests -j40 make DEBUG_ROBOLECTRIC=1 ROBOTEST_FILTER=SoundSettingsTest RunSettingsRoboTests Change-Id: Id17523f49b291a5cf612b90f93c3b2ab6486c62f
This commit is contained in:
26
res/drawable/ic_ring_volume.xml
Normal file
26
res/drawable/ic_ring_volume.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<!--
|
||||
Copyright (C) 2022 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.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:pathData="M11,7V2H13V7ZM17.6,9.85 L16.2,8.4 19.75,4.85 21.15,6.3ZM6.4,9.85 L2.85,6.3 4.25,4.85 7.8,8.4ZM12,12Q14.95,12 17.812,13.188Q20.675,14.375 22.9,16.75Q23.2,17.05 23.2,17.45Q23.2,17.85 22.9,18.15L20.6,20.4Q20.325,20.675 19.963,20.7Q19.6,20.725 19.3,20.5L16.4,18.3Q16.2,18.15 16.1,17.95Q16,17.75 16,17.5V14.65Q15.05,14.35 14.05,14.175Q13.05,14 12,14Q10.95,14 9.95,14.175Q8.95,14.35 8,14.65V17.5Q8,17.75 7.9,17.95Q7.8,18.15 7.6,18.3L4.7,20.5Q4.4,20.725 4.038,20.7Q3.675,20.675 3.4,20.4L1.1,18.15Q0.8,17.85 0.8,17.45Q0.8,17.05 1.1,16.75Q3.3,14.375 6.175,13.188Q9.05,12 12,12ZM6,15.35Q5.275,15.725 4.6,16.212Q3.925,16.7 3.2,17.3L4.2,18.3L6,16.9ZM18,15.4V16.9L19.8,18.3L20.8,17.35Q20.075,16.7 19.4,16.225Q18.725,15.75 18,15.4ZM6,15.35Q6,15.35 6,15.35Q6,15.35 6,15.35ZM18,15.4Q18,15.4 18,15.4Q18,15.4 18,15.4Z"
|
||||
android:fillColor="?android:attr/colorPrimary"/>
|
||||
|
||||
</vector>
|
34
res/drawable/ic_ring_volume_off.xml
Normal file
34
res/drawable/ic_ring_volume_off.xml
Normal file
@@ -0,0 +1,34 @@
|
||||
<!--
|
||||
Copyright (C) 2022 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.
|
||||
-->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?android:attr/colorControlNormal">
|
||||
<path
|
||||
android:pathData="M0.8,4.2l8.1,8.1c-2.2,0.5 -5.2,1.6 -7.8,4.4c-0.4,0.4 -0.4,1 0,1.4l2.3,2.3c0.3,0.3 0.9,0.4 1.3,0.1l2.9,-2.2C7.8,18.1 8,17.8 8,17.5v-2.9c0.9,-0.3 1.7,-0.5 2.7,-0.6l8.5,8.5l1.4,-1.4L2.2,2.8L0.8,4.2z"
|
||||
android:fillColor="?android:attr/colorPrimary"/>
|
||||
<path
|
||||
android:pathData="M11,2h2v5h-2z"
|
||||
android:fillColor="?android:attr/colorPrimary"/>
|
||||
<path
|
||||
android:pathData="M21.2,6.3l-1.4,-1.4l-3.6,3.6l1.4,1.4C17.6,9.8 21,6.3 21.2,6.3z"
|
||||
android:fillColor="?android:attr/colorPrimary"/>
|
||||
<path
|
||||
android:pathData="M22.9,16.7c-2.8,-3 -6.2,-4.1 -8.4,-4.5l7.2,7.2l1.3,-1.3C23.3,17.7 23.3,17.1 22.9,16.7z"
|
||||
android:fillColor="?android:attr/colorPrimary"/>
|
||||
</vector>
|
@@ -8727,9 +8727,12 @@
|
||||
<!-- Sound: Title for the option managing alarm volume. [CHAR LIMIT=30] -->
|
||||
<string name="alarm_volume_option_title">Alarm volume</string>
|
||||
|
||||
<!-- Sound: Title for the option managing ring volume. [CHAR LIMIT=30] -->
|
||||
<!-- Sound: Title for the option managing ring & notification volume. [CHAR LIMIT=30] -->
|
||||
<string name="ring_volume_option_title">Ring & notification volume</string>
|
||||
|
||||
<!-- Sound: Title for the option managing ring volume. [CHAR LIMIT=30] -->
|
||||
<string name="separate_ring_volume_option_title">Ring volume</string>
|
||||
|
||||
<!-- Sound: Title for the option managing notification volume. [CHAR LIMIT=30] -->
|
||||
<string name="notification_volume_option_title">Notification volume</string>
|
||||
|
||||
|
@@ -72,23 +72,23 @@
|
||||
android:order="-160"
|
||||
settings:controller="com.android.settings.notification.RingVolumePreferenceController"/>
|
||||
|
||||
<!-- Notification volume -->
|
||||
<com.android.settings.notification.VolumeSeekBarPreference
|
||||
android:key="notification_volume"
|
||||
android:icon="@drawable/ic_notifications"
|
||||
android:title="@string/notification_volume_option_title"
|
||||
android:order="-150"
|
||||
settings:controller=
|
||||
"com.android.settings.notification.NotificationVolumePreferenceController"/>
|
||||
|
||||
<!-- Alarm volume -->
|
||||
<com.android.settings.notification.VolumeSeekBarPreference
|
||||
android:key="alarm_volume"
|
||||
android:icon="@*android:drawable/ic_audio_alarm"
|
||||
android:title="@string/alarm_volume_option_title"
|
||||
android:order="-150"
|
||||
settings:controller="com.android.settings.notification.AlarmVolumePreferenceController"/>
|
||||
|
||||
<!-- Notification volume -->
|
||||
<com.android.settings.notification.VolumeSeekBarPreference
|
||||
android:key="notification_volume"
|
||||
android:icon="@drawable/ic_notifications"
|
||||
android:title="@string/notification_volume_option_title"
|
||||
android:order="-140"
|
||||
settings:controller="com.android.settings.notification.NotificationVolumePreferenceController"/>
|
||||
|
||||
settings:controller="com.android.settings.notification.AlarmVolumePreferenceController"/>
|
||||
x
|
||||
<!-- TODO(b/174964721): make this a PrimarySwitchPreference -->
|
||||
<!-- Interruptions -->
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
|
@@ -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,25 +176,70 @@ public class RingVolumePreferenceController extends VolumeSeekBarPreferenceContr
|
||||
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 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);
|
||||
}
|
||||
updatePreferenceIcon();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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.
|
||||
*/
|
||||
|
@@ -22,10 +22,14 @@ import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Vibrator;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -46,6 +50,8 @@ public class NotificationVolumePreferenceControllerTest {
|
||||
private AudioManager mAudioManager;
|
||||
@Mock
|
||||
private Vibrator mVibrator;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
|
||||
private Context mContext;
|
||||
private NotificationVolumePreferenceController mController;
|
||||
@@ -57,6 +63,8 @@ public class NotificationVolumePreferenceControllerTest {
|
||||
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
|
||||
when(mContext.getSystemService(Context.AUDIO_SERVICE)).thenReturn(mAudioManager);
|
||||
when(mContext.getSystemService(Context.VIBRATOR_SERVICE)).thenReturn(mVibrator);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
|
||||
mController = new NotificationVolumePreferenceController(mContext);
|
||||
mController.setAudioHelper(mHelper);
|
||||
}
|
||||
@@ -76,15 +84,50 @@ public class NotificationVolumePreferenceControllerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_voiceCapable_shouldReturnFalse() {
|
||||
public void isAvailable_voiceCapable_aliasedWithRing_shouldReturnFalse() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
|
||||
when(mResources.getBoolean(R.bool.config_alias_ring_notif_stream_types)).thenReturn(true);
|
||||
|
||||
NotificationVolumePreferenceController controller =
|
||||
new NotificationVolumePreferenceController(mContext);
|
||||
when(mHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
|
||||
|
||||
assertThat(controller.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* With the introduction of ring-notification volume separation, voice-capable devices could now
|
||||
* display the notification volume slider.
|
||||
*/
|
||||
@Test
|
||||
public void isAvailable_voiceCapable_separatedFromRing_shouldReturnTrue() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
|
||||
when(mResources.getBoolean(R.bool.config_alias_ring_notif_stream_types)).thenReturn(false);
|
||||
|
||||
NotificationVolumePreferenceController controller =
|
||||
new NotificationVolumePreferenceController(mContext);
|
||||
|
||||
when(mHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(true);
|
||||
|
||||
assertThat(controller.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_notShowNotificationVolume_shouldReturnFalse() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(false);
|
||||
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isAvailable_notSingleVolume_notVoiceCapable_shouldReturnTrue() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.settings.R.bool.config_show_notification_volume)).thenReturn(true);
|
||||
when(mHelper.isSingleVolume()).thenReturn(false);
|
||||
when(mTelephonyManager.isVoiceCapable()).thenReturn(false);
|
||||
|
||||
@@ -107,4 +150,24 @@ public class NotificationVolumePreferenceControllerTest {
|
||||
public void isPublicSlice_returnTrue() {
|
||||
assertThat(mController.isPublicSlice()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsRing_DoesNotMatch() {
|
||||
assertThat(mController.hintsMatch(
|
||||
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsAll_Matches() {
|
||||
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintNotification_Matches() {
|
||||
assertThat(mController
|
||||
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -18,15 +18,20 @@ package com.android.settings.notification;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Vibrator;
|
||||
import android.service.notification.NotificationListenerService;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.settings.R;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -51,8 +56,13 @@ public class RingVolumePreferenceControllerTest {
|
||||
private NotificationManager mNotificationManager;
|
||||
@Mock
|
||||
private ComponentName mSuppressor;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
@Mock
|
||||
private VolumeSeekBarPreference mPreference;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
private RingVolumePreferenceController mController;
|
||||
|
||||
@Before
|
||||
@@ -63,8 +73,9 @@ public class RingVolumePreferenceControllerTest {
|
||||
shadowContext.setSystemService(Context.AUDIO_SERVICE, mAudioManager);
|
||||
shadowContext.setSystemService(Context.VIBRATOR_SERVICE, mVibrator);
|
||||
shadowContext.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
when(mNotificationManager.getEffectsSuppressor()).thenReturn(mSuppressor);
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
mController = new RingVolumePreferenceController(mContext);
|
||||
mController.setAudioHelper(mHelper);
|
||||
}
|
||||
@@ -109,4 +120,92 @@ public class RingVolumePreferenceControllerTest {
|
||||
public void isPublicSlice_returnTrue() {
|
||||
assertThat(mController.isPublicSlice()).isTrue();
|
||||
}
|
||||
|
||||
// todo: verify that the title change is displayed, by examining the underlying preference
|
||||
@Test
|
||||
public void ringNotificationStreamsNotAliased_sliderTitleSetToRingOnly() {
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_alias_ring_notif_stream_types))
|
||||
.thenReturn(false);
|
||||
final RingVolumePreferenceController controller =
|
||||
new RingVolumePreferenceController(mContext);
|
||||
|
||||
int expectedTitleId = R.string.separate_ring_volume_option_title;
|
||||
|
||||
assertThat(controller.mTitleId).isEqualTo(expectedTitleId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ringNotificationStreamsAliased_sliderTitleIncludesBothRingNotification() {
|
||||
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_alias_ring_notif_stream_types)).thenReturn(true);
|
||||
final RingVolumePreferenceController control = new RingVolumePreferenceController(mContext);
|
||||
|
||||
int expectedTitleId = R.string.ring_volume_option_title;
|
||||
|
||||
assertThat(control.mTitleId).isEqualTo(expectedTitleId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsRing_aliased_Matches() {
|
||||
assertThat(mController.hintsMatch(
|
||||
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, true)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsRingNotification_aliased_Matches() {
|
||||
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS,
|
||||
true)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintNotification_aliased_Matches() {
|
||||
assertThat(mController
|
||||
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS,
|
||||
true)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsRing_unaliased_Matches() {
|
||||
assertThat(mController.hintsMatch(
|
||||
NotificationListenerService.HINT_HOST_DISABLE_CALL_EFFECTS, false)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintsRingNotification_unaliased_Matches() {
|
||||
assertThat(mController.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_EFFECTS,
|
||||
false)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setHintNotification_unaliased_doesNotMatch() {
|
||||
assertThat(mController
|
||||
.hintsMatch(NotificationListenerService.HINT_HOST_DISABLE_NOTIFICATION_EFFECTS,
|
||||
false)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRingerModeToVibrate_butNoVibratorAvailable_iconIsSilent() {
|
||||
when(mHelper.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
|
||||
|
||||
mController.setPreference(mPreference);
|
||||
mController.setVibrator(null);
|
||||
mController.updateRingerMode();
|
||||
|
||||
assertThat(mController.getMuteIcon()).isEqualTo(mController.mSilentIconId);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setRingerModeToVibrate_VibratorAvailable_iconIsVibrate() {
|
||||
when(mHelper.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE);
|
||||
when(mVibrator.hasVibrator()).thenReturn(true);
|
||||
|
||||
mController.setPreference(mPreference);
|
||||
mController.setVibrator(mVibrator);
|
||||
mController.updateRingerMode();
|
||||
|
||||
assertThat(mController.getMuteIcon()).isEqualTo(mController.mVibrateIconId);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -35,6 +35,7 @@ import com.android.settings.testutils.shadow.ShadowBluetoothAdapter;
|
||||
import com.android.settings.testutils.shadow.ShadowDeviceConfig;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
@@ -44,8 +45,6 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Ignore;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class SoundSettingsTest {
|
||||
|
||||
@@ -86,4 +85,19 @@ public class SoundSettingsTest {
|
||||
|
||||
assertThat(settings.mHandler.hasMessages(SoundSettings.STOP_SAMPLE)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notificationVolume_isBetweenRingAndAlarm() {
|
||||
final Context context = spy(RuntimeEnvironment.application);
|
||||
final SoundSettings settings = new SoundSettings();
|
||||
final int xmlId = settings.getPreferenceScreenResId();
|
||||
final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context, xmlId);
|
||||
|
||||
int ring = keys.indexOf("ring_volume");
|
||||
int notification = keys.indexOf("notification_volume");
|
||||
int alarm = keys.indexOf("alarm_volume");
|
||||
|
||||
assertThat(ring < notification).isTrue();
|
||||
assertThat(notification < alarm).isTrue();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user