Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bff0e971 authored by Alison Cichowlas's avatar Alison Cichowlas
Browse files

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
parent 744ff5c6
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -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<NotificationChannelGroup> mChannelGroupComparator =
            new Comparator<NotificationChannelGroup>() {

+14 −0
Original line number Diff line number Diff line
@@ -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);
    }
+6 −6
Original line number Diff line number Diff line
@@ -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) {
+15 −3
Original line number Diff line number Diff line
@@ -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:
                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:
                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());
    }
}