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

Commit 6c76550a authored by Alison Cichowlas's avatar Alison Cichowlas Committed by android-build-merger
Browse files

Notification importance/selected sound conflict fixes.

am: ad115816

Change-Id: I7b921e8845bcd549790318cc074838a24fe22182
parents a81e3e3c ad115816
Loading
Loading
Loading
Loading
+13 −4
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;
@@ -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:
                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 Comparator<NotificationChannel> mChannelComparator =
+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
@@ -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) {
+5 −0
Original line number Diff line number Diff line
@@ -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());
    }
}