From ad1158169c424e6db621bc35552bc835d086fc6e Mon Sep 17 00:00:00 2001 From: Alison Cichowlas Date: Thu, 14 Sep 2017 15:01:29 -0400 Subject: [PATCH] Notification importance/selected sound conflict fixes. - When you've selected "Silent" as your sound, update notification importance messaging to match. - When you explicitly move from a silent type of notifications to a loud type, but have "Silent" selected as the sound, change the sound to the default notification sound also. Change-Id: I462785d593e1d6c7d1e87388aeee1bdcbcf6aa3d Fixes: 63109928 Test: RunSettingsRoboTests, manual --- .../notification/AppNotificationSettings.java | 17 +++++++++++++---- .../notification/ChannelImportanceSettings.java | 14 ++++++++++++++ .../ChannelNotificationSettings.java | 12 ++++++------ .../notification/NotificationSettingsBase.java | 5 +++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index 78a0a74999f..72a4cc1a604 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; @@ -191,7 +192,8 @@ public class AppNotificationSettings extends NotificationSettingsBase { } 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( @@ -341,13 +343,20 @@ public class AppNotificationSettings extends NotificationSettingsBase { 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 Comparator mChannelComparator = 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 66e94fa1db4..dd4850e245a 100644 --- a/src/com/android/settings/notification/ChannelNotificationSettings.java +++ b/src/com/android/settings/notification/ChannelNotificationSettings.java @@ -318,15 +318,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: @@ -369,10 +373,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 36b263e950f..0d24afc60b9 100644 --- a/src/com/android/settings/notification/NotificationSettingsBase.java +++ b/src/com/android/settings/notification/NotificationSettingsBase.java @@ -46,6 +46,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; @@ -506,4 +507,8 @@ abstract public class NotificationSettingsBase extends SettingsPreferenceFragmen } } }; + + boolean hasValidSound(NotificationChannel channel) { + return channel.getSound() != null && !Uri.EMPTY.equals(channel.getSound()); + } }