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

Commit bfa5dc4c authored by John Spurlock's avatar John Spurlock
Browse files

Zen: Classify notifications using the alarm stream.

Also:
 - include audio attributes in dump
 - workaround for recent AudioAttributes change.

Bug:16455021
Change-Id: Ib9b047a74cff3e0cc354a5aaa96bc92a400b3845
parent 3af1afb0
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -1812,7 +1812,14 @@ public class NotificationManagerService extends SystemService {
    }

    private static AudioAttributes audioAttributesForNotification(Notification n) {
        return new AudioAttributes.Builder().setLegacyStreamType(n.audioStreamType).build();
        if (n.audioAttributes != null
                && !Notification.AUDIO_ATTRIBUTES_DEFAULT.equals(n.audioAttributes)) {
            return n.audioAttributes;
        }
        return new AudioAttributes.Builder()
                .setLegacyStreamType(n.audioStreamType)
                .setUsage(AudioAttributes.usageForLegacyStreamType(n.audioStreamType))
                .build();
    }

    void showNextToastLocked() {
+14 −1
Original line number Diff line number Diff line
@@ -20,7 +20,9 @@ import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.media.AudioAttributes;
import android.service.notification.StatusBarNotification;

import com.android.internal.annotations.VisibleForTesting;

import java.io.PrintWriter;
@@ -105,6 +107,8 @@ public final class NotificationRecord {
        pw.println(prefix + String.format("  defaults=0x%08x flags=0x%08x",
                notification.defaults, notification.flags));
        pw.println(prefix + "  sound=" + notification.sound);
        pw.println(prefix + "  audioStreamType=" + notification.audioStreamType);
        pw.println(prefix + "  audioAttributes=" + notification.audioAttributes);
        pw.println(prefix + String.format("  color=0x%08x", notification.color));
        pw.println(prefix + "  vibrate=" + Arrays.toString(notification.vibrate));
        pw.println(prefix + String.format("  led=0x%08x onMs=%d offMs=%d",
@@ -224,7 +228,16 @@ public final class NotificationRecord {
    }

    public boolean isCategory(String category) {
        return Objects.equals(category, getNotification().category);
        return Objects.equals(getNotification().category, category);
    }

    public boolean isAudioStream(int stream) {
        return getNotification().audioStreamType == stream;
    }

    public boolean isAudioAttributesUsage(int usage) {
        final AudioAttributes attributes = getNotification().audioAttributes;
        return attributes != null && attributes.getUsage() == usage;
    }

    /**
+4 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.IntentFilter;
import android.content.res.Resources;
import android.content.res.XmlResourceParser;
import android.database.ContentObserver;
import android.media.AudioAttributes;
import android.media.AudioManager;
import android.net.Uri;
import android.os.Handler;
@@ -319,7 +320,9 @@ public class ZenModeHelper {

    private boolean isAlarm(NotificationRecord record) {
        return record.isCategory(Notification.CATEGORY_ALARM)
                || record.isCategory(Notification.CATEGORY_EVENT);
                || record.isCategory(Notification.CATEGORY_EVENT)
                || record.isAudioStream(AudioManager.STREAM_ALARM)
                || record.isAudioAttributesUsage(AudioAttributes.USAGE_ALARM);
    }

    private boolean isCall(NotificationRecord record) {