Notification importance/selected sound conflict fixes.

am: ad1158169c

Change-Id: I7b921e8845bcd549790318cc074838a24fe22182
This commit is contained in:
Alison Cichowlas
2017-09-22 18:23:34 +00:00
committed by android-build-merger
4 changed files with 38 additions and 10 deletions

View File

@@ -21,6 +21,7 @@ import android.app.NotificationChannel;
import android.app.NotificationChannelGroup; import android.app.NotificationChannelGroup;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.Intent; import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Bundle; import android.os.Bundle;
import android.provider.Settings; import android.provider.Settings;
@@ -191,7 +192,8 @@ public class AppNotificationSettings extends NotificationSettingsBase {
} }
int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid); int deletedChannelCount = mBackend.getDeletedChannelCount(mAppRow.pkg, mAppRow.uid);
if (deletedChannelCount > 0) { if (deletedChannelCount > 0 &&
getPreferenceScreen().findPreference(KEY_DELETED) == null) {
mDeletedChannels = new FooterPreference(getPrefContext()); mDeletedChannels = new FooterPreference(getPrefContext());
mDeletedChannels.setSelectable(false); mDeletedChannels.setSelectable(false);
mDeletedChannels.setTitle(getResources().getQuantityString( mDeletedChannels.setTitle(getResources().getQuantityString(
@@ -341,13 +343,20 @@ public class AppNotificationSettings extends NotificationSettingsBase {
case NotificationManager.IMPORTANCE_LOW: case NotificationManager.IMPORTANCE_LOW:
return getContext().getString(R.string.notification_importance_low); return getContext().getString(R.string.notification_importance_low);
case NotificationManager.IMPORTANCE_DEFAULT: case NotificationManager.IMPORTANCE_DEFAULT:
if (hasValidSound(channel)) {
return getContext().getString(R.string.notification_importance_default); 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_HIGH:
case NotificationManager.IMPORTANCE_MAX: case NotificationManager.IMPORTANCE_MAX:
default: default:
if (hasValidSound(channel)) {
return getContext().getString(R.string.notification_importance_high); return getContext().getString(R.string.notification_importance_high);
} else { // Silent
return getContext().getString(R.string.notification_importance_high_silent);
}
} }
} }
private Comparator<NotificationChannel> mChannelComparator = private Comparator<NotificationChannel> mChannelComparator =

View File

@@ -17,6 +17,7 @@
package com.android.settings.notification; package com.android.settings.notification;
import static android.app.NotificationChannel.USER_LOCKED_IMPORTANCE; 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_DEFAULT;
import static android.app.NotificationManager.IMPORTANCE_HIGH; import static android.app.NotificationManager.IMPORTANCE_HIGH;
import static android.app.NotificationManager.IMPORTANCE_LOW; 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 static android.app.NotificationManager.IMPORTANCE_MIN;
import android.content.Context; import android.content.Context;
import android.media.RingtoneManager;
import android.provider.SearchIndexableResource; import android.provider.SearchIndexableResource;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen; import android.support.v7.preference.PreferenceScreen;
@@ -125,6 +127,7 @@ public class ChannelImportanceSettings extends NotificationSettingsBase
@Override @Override
public void onRadioButtonClicked(RadioButtonPreference clicked) { public void onRadioButtonClicked(RadioButtonPreference clicked) {
int oldImportance = mChannel.getImportance();
switch (clicked.getKey()) { switch (clicked.getKey()) {
case KEY_IMPORTANCE_HIGH: case KEY_IMPORTANCE_HIGH:
mChannel.setImportance(IMPORTANCE_HIGH); mChannel.setImportance(IMPORTANCE_HIGH);
@@ -140,6 +143,17 @@ public class ChannelImportanceSettings extends NotificationSettingsBase
break; break;
} }
updateRadioButtons(clicked.getKey()); 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); mChannel.lockFields(USER_LOCKED_IMPORTANCE);
mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, mChannel); mBackend.updateChannel(mAppRow.pkg, mAppRow.uid, mChannel);
} }

View File

@@ -318,15 +318,19 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
break; break;
case NotificationManager.IMPORTANCE_DEFAULT: case NotificationManager.IMPORTANCE_DEFAULT:
title = getContext().getString(R.string.notification_importance_default_title); title = getContext().getString(R.string.notification_importance_default_title);
if (hasValidSound()) { if (hasValidSound(mChannel)) {
summary = getContext().getString(R.string.notification_importance_default); summary = getContext().getString(R.string.notification_importance_default);
} else {
summary = getContext().getString(R.string.notification_importance_low);
} }
break; break;
case NotificationManager.IMPORTANCE_HIGH: case NotificationManager.IMPORTANCE_HIGH:
case NotificationManager.IMPORTANCE_MAX: case NotificationManager.IMPORTANCE_MAX:
title = getContext().getString(R.string.notification_importance_high_title); title = getContext().getString(R.string.notification_importance_high_title);
if (hasValidSound()) { if (hasValidSound(mChannel)) {
summary = getContext().getString(R.string.notification_importance_high); summary = getContext().getString(R.string.notification_importance_high);
} else {
summary = getContext().getString(R.string.notification_importance_high_silent);
} }
break; break;
default: default:
@@ -369,10 +373,6 @@ public class ChannelNotificationSettings extends NotificationSettingsBase {
Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1; Settings.System.NOTIFICATION_LIGHT_PULSE, 0) == 1;
} }
boolean hasValidSound() {
return mChannel.getSound() != null && !Uri.EMPTY.equals(mChannel.getSound());
}
void updateDependents(boolean banned) { void updateDependents(boolean banned) {
PreferenceGroup parent; PreferenceGroup parent;
if (mShowLegacyChannelConfig) { if (mShowLegacyChannelConfig) {

View File

@@ -46,6 +46,7 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; 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());
}
} }