diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index 29eb4a3098e..95c9560d165 100644 --- a/src/com/android/settings/notification/AppNotificationSettings.java +++ b/src/com/android/settings/notification/AppNotificationSettings.java @@ -21,6 +21,7 @@ import android.app.NotificationChannel; import android.app.NotificationChannelGroup; import android.app.NotificationManager; import android.content.Intent; +import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; import android.provider.Settings; @@ -168,7 +169,8 @@ public class AppNotificationSettings extends NotificationSettingsBase { } else { populateGroupList(); int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid); - if (deletedChannelCount > 0) { + if (deletedChannelCount > 0 && + getPreferenceScreen().findPreference(KEY_DELETED) == null) { mDeletedChannels = new FooterPreference(getPrefContext()); mDeletedChannels.setSelectable(false); mDeletedChannels.setTitle(getResources().getQuantityString( @@ -322,6 +324,7 @@ public class AppNotificationSettings extends NotificationSettingsBase { } } + private Comparator mChannelGroupComparator = new Comparator() { diff --git a/src/com/android/settings/notification/ChannelImportanceSettings.java b/src/com/android/settings/notification/ChannelImportanceSettings.java index 26dd57f1481..9e9ffd6aa55 100644 --- a/src/com/android/settings/notification/ChannelImportanceSettings.java +++ b/src/com/android/settings/notification/ChannelImportanceSettings.java @@ -17,6 +17,7 @@ package com.android.settings.notification; import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; +import static android.app.NotificationChannel.USER_LOCKED_SOUND; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_LOW; @@ -24,6 +25,7 @@ import static android.app.NotificationManager.IMPORTANCE_MAX; import static android.app.NotificationManager.IMPORTANCE_MIN; import android.content.Context; +import android.media.RingtoneManager; import android.provider.SearchIndexableResource; import android.support.v7.preference.Preference; import android.support.v7.preference.PreferenceScreen; @@ -125,6 +127,7 @@ public class ChannelImportanceSettings extends NotificationSettingsBase @Override public void onRadioButtonClicked(RadioButtonPreference clicked) { + int oldImportance = mChannel.getImportance(); switch (clicked.getKey()) { case KEY_IMPORTANCE_HIGH: mChannel.setImportance(IMPORTANCE_HIGH); @@ -140,6 +143,17 @@ public class ChannelImportanceSettings extends NotificationSettingsBase break; } updateRadioButtons(clicked.getKey()); + + // If you are moving from an importance level without sound to one with sound, + // but the sound you had selected was "Silence", + // then set sound for this channel to your default sound, + // because you probably intended to cause this channel to actually start making sound. + if (oldImportance < IMPORTANCE_DEFAULT && !hasValidSound(mChannel) && + mChannel.getImportance() >= IMPORTANCE_DEFAULT) { + mChannel.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION), + mChannel.getAudioAttributes()); + mChannel.lockFields(USER_LOCKED_SOUND); + } mChannel.lockFields(USER_LOCKED_IMPORTANCE); mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, mChannel); } diff --git a/src/com/android/settings/notification/ChannelNotificationSettings.java b/src/com/android/settings/notification/ChannelNotificationSettings.java index 5db256d3859..9484f7e6bf5 100644 --- a/src/com/android/settings/notification/ChannelNotificationSettings.java +++ b/src/com/android/settings/notification/ChannelNotificationSettings.java @@ -304,15 +304,19 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { break; case NotificationManager.IMPORTANCE_DEFAULT: title = getContext().getString(R.string.notification_importance_default_title); - if (hasValidSound()) { + if (hasValidSound(mChannel)) { summary = getContext().getString(R.string.notification_importance_default); + } else { + summary = getContext().getString(R.string.notification_importance_low); } break; case NotificationManager.IMPORTANCE_HIGH: case NotificationManager.IMPORTANCE_MAX: title = getContext().getString(R.string.notification_importance_high_title); - if (hasValidSound()) { + if (hasValidSound(mChannel)) { summary = getContext().getString(R.string.notification_importance_high); + } else { + summary = getContext().getString(R.string.notification_importance_high_silent); } break; default: @@ -355,10 +359,6 @@ public class ChannelNotificationSettings extends NotificationSettingsBase { Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1; } - boolean hasValidSound() { - return mChannel.getSound() != null && !Uri.EMPTY.equals(mChannel.getSound()); - } - void updateDependents(boolean banned) { PreferenceGroup parent; if (mShowLegacyChannelConfig) { diff --git a/src/com/android/settings/notification/NotificationSettingsBase.java b/src/com/android/settings/notification/NotificationSettingsBase.java index 92169cdbefd..3f366e1be3e 100644 --- a/src/com/android/settings/notification/NotificationSettingsBase.java +++ b/src/com/android/settings/notification/NotificationSettingsBase.java @@ -49,6 +49,7 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ResolveInfo; import android.content.pm.UserInfo; +import android.net.Uri; import android.os.Bundle; import android.os.UserHandle; import android.os.UserManager; @@ -479,13 +480,20 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen case NotificationManager.IMPORTANCE_LOW: return getContext().getString(R.string.notification_importance_low); case NotificationManager.IMPORTANCE_DEFAULT: - return getContext().getString(R.string.notification_importance_default); + if (hasValidSound(channel)) { + return getContext().getString(R.string.notification_importance_default); + } else { // Silent + return getContext().getString(R.string.notification_importance_low); + } case NotificationManager.IMPORTANCE_HIGH: case NotificationManager.IMPORTANCE_MAX: default: - return getContext().getString(R.string.notification_importance_high); + if (hasValidSound(channel)) { + return getContext().getString(R.string.notification_importance_high); + } else { // Silent + return getContext().getString(R.string.notification_importance_high_silent); + } } - } private void setRestrictedIfNotificationFeaturesDisabled(CharSequence entry, @@ -595,4 +603,8 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen } return left.getId().compareTo(right.getId()); }; + + boolean hasValidSound(NotificationChannel channel) { + return channel.getSound() != null && !Uri.EMPTY.equals(channel.getSound()); + } }