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

Commit ceb79bc3 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

Prevent NotificationManagerService from using bad stream type

When deriving AudioAttributes from a Notification instance,
 and having to use the legacy stream type field, make sure
 it has a valid value, or use the default notification
 attributes.

Bug 17408227

Change-Id: Icd1a122b33b8eceb1f6a177699885b0fb8a99b7c
parent 68c936f7
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.content.res.Resources;
import android.database.ContentObserver;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.media.AudioSystem;
import android.media.IRingtonePlayer;
import android.net.Uri;
import android.os.Binder;
@@ -1945,14 +1946,19 @@ public class NotificationManagerService extends SystemService {
    }

    private static AudioAttributes audioAttributesForNotification(Notification n) {
        if (n.audioAttributes != null
                && !Notification.AUDIO_ATTRIBUTES_DEFAULT.equals(n.audioAttributes)) {
        if (n.audioAttributes != null) {
            return n.audioAttributes;
        }
        } else if (n.audioStreamType >= 0 && n.audioStreamType < AudioSystem.getNumStreamTypes()) {
            // the stream type is valid, use it
            return new AudioAttributes.Builder()
                .setLegacyStreamType(n.audioStreamType)
                .setUsage(AudioAttributes.usageForLegacyStreamType(n.audioStreamType))
                    .setInternalLegacyStreamType(n.audioStreamType)
                    .build();
        } else if (n.audioStreamType == AudioSystem.STREAM_DEFAULT) {
            return Notification.AUDIO_ATTRIBUTES_DEFAULT;
        } else {
            Log.w(TAG, String.format("Invalid stream type: %d", n.audioStreamType));
            return Notification.AUDIO_ATTRIBUTES_DEFAULT;
        }
    }

    void showNextToastLocked() {