Launch correct tone picker for audio attributes
Test: robotests Fixes: 129353516 Change-Id: Iacbf5008f186e59377e534da747544d33a20f81f
This commit is contained in:
@@ -63,8 +63,7 @@
|
|||||||
android:dialogTitle="@string/notification_channel_sound_title"
|
android:dialogTitle="@string/notification_channel_sound_title"
|
||||||
android:order="11"
|
android:order="11"
|
||||||
android:showSilent="true"
|
android:showSilent="true"
|
||||||
android:showDefault="true"
|
android:showDefault="true"/>
|
||||||
android:ringtoneType="notification" />
|
|
||||||
|
|
||||||
<!-- Vibration -->
|
<!-- Vibration -->
|
||||||
<com.android.settingslib.RestrictedSwitchPreference
|
<com.android.settingslib.RestrictedSwitchPreference
|
||||||
|
@@ -16,10 +16,14 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
|
import static android.media.AudioAttributes.USAGE_ALARM;
|
||||||
|
import static android.media.AudioAttributes.USAGE_NOTIFICATION_RINGTONE;
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
|
|
||||||
@@ -91,6 +95,16 @@ public class SoundPreferenceController extends NotificationPreferenceController
|
|||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||||
if (KEY_SOUND.equals(preference.getKey()) && mFragment != null) {
|
if (KEY_SOUND.equals(preference.getKey()) && mFragment != null) {
|
||||||
NotificationSoundPreference pref = (NotificationSoundPreference) preference;
|
NotificationSoundPreference pref = (NotificationSoundPreference) preference;
|
||||||
|
if (mChannel != null && mChannel.getAudioAttributes() != null) {
|
||||||
|
if (USAGE_ALARM == mChannel.getAudioAttributes().getUsage()) {
|
||||||
|
pref.setRingtoneType(RingtoneManager.TYPE_ALARM);
|
||||||
|
} else if (USAGE_NOTIFICATION_RINGTONE
|
||||||
|
== mChannel.getAudioAttributes().getUsage()) {
|
||||||
|
pref.setRingtoneType(RingtoneManager.TYPE_RINGTONE);
|
||||||
|
} else {
|
||||||
|
pref.setRingtoneType(RingtoneManager.TYPE_NOTIFICATION);
|
||||||
|
}
|
||||||
|
}
|
||||||
pref.onPrepareRingtonePickerIntent(pref.getIntent());
|
pref.onPrepareRingtonePickerIntent(pref.getIntent());
|
||||||
mFragment.startActivityForResult(preference.getIntent(), CODE);
|
mFragment.startActivityForResult(preference.getIntent(), CODE);
|
||||||
return true;
|
return true;
|
||||||
|
@@ -39,6 +39,8 @@ import android.app.NotificationChannel;
|
|||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.media.AudioAttributes;
|
||||||
|
import android.media.RingtoneManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
@@ -54,6 +56,7 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Answers;
|
import org.mockito.Answers;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.Robolectric;
|
import org.robolectric.Robolectric;
|
||||||
@@ -230,6 +233,69 @@ public class SoundPreferenceControllerTest {
|
|||||||
verify(mFragment, times(1)).startActivityForResult(any(), anyInt());
|
verify(mFragment, times(1)).startActivityForResult(any(), anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnPreferenceTreeClick_alarmSound() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
|
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
||||||
|
AudioAttributes.USAGE_ALARM).build());
|
||||||
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
|
NotificationSoundPreference pref =
|
||||||
|
spy(new NotificationSoundPreference(mContext, attributeSet));
|
||||||
|
pref.setKey(mController.getPreferenceKey());
|
||||||
|
mController.handlePreferenceTreeClick(pref);
|
||||||
|
|
||||||
|
ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture());
|
||||||
|
assertEquals(RingtoneManager.TYPE_ALARM,
|
||||||
|
intentArgumentCaptor.getValue().getIntExtra(
|
||||||
|
RingtoneManager.EXTRA_RINGTONE_TYPE, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnPreferenceTreeClick_ringtoneSound() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
|
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
||||||
|
AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build());
|
||||||
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
|
NotificationSoundPreference pref =
|
||||||
|
spy(new NotificationSoundPreference(mContext, attributeSet));
|
||||||
|
pref.setKey(mController.getPreferenceKey());
|
||||||
|
mController.handlePreferenceTreeClick(pref);
|
||||||
|
|
||||||
|
ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture());
|
||||||
|
assertEquals(RingtoneManager.TYPE_RINGTONE,
|
||||||
|
intentArgumentCaptor.getValue().getIntExtra(
|
||||||
|
RingtoneManager.EXTRA_RINGTONE_TYPE, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testOnPreferenceTreeClick_otherSound() {
|
||||||
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
|
NotificationChannel channel = new NotificationChannel("", "", IMPORTANCE_HIGH);
|
||||||
|
channel.setSound(null, new AudioAttributes.Builder().setUsage(
|
||||||
|
AudioAttributes.USAGE_UNKNOWN).build());
|
||||||
|
mController.onResume(appRow, channel, null, null);
|
||||||
|
|
||||||
|
AttributeSet attributeSet = Robolectric.buildAttributeSet().build();
|
||||||
|
NotificationSoundPreference pref =
|
||||||
|
spy(new NotificationSoundPreference(mContext, attributeSet));
|
||||||
|
pref.setKey(mController.getPreferenceKey());
|
||||||
|
mController.handlePreferenceTreeClick(pref);
|
||||||
|
|
||||||
|
ArgumentCaptor<Intent> intentArgumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||||
|
verify(pref, times(1)).onPrepareRingtonePickerIntent(intentArgumentCaptor.capture());
|
||||||
|
assertEquals(RingtoneManager.TYPE_NOTIFICATION,
|
||||||
|
intentArgumentCaptor.getValue().getIntExtra(
|
||||||
|
RingtoneManager.EXTRA_RINGTONE_TYPE, 0));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnActivityResult() {
|
public void testOnActivityResult() {
|
||||||
NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
|
NotificationSoundPreference pref = mock(NotificationSoundPreference.class);
|
||||||
|
Reference in New Issue
Block a user