OSDN Git Service

Zen: Classify notifications using the alarm stream.
authorJohn Spurlock <jspurlock@google.com>
Tue, 29 Jul 2014 03:30:45 +0000 (23:30 -0400)
committerJohn Spurlock <jspurlock@google.com>
Tue, 29 Jul 2014 03:34:31 +0000 (23:34 -0400)
Also:
 - include audio attributes in dump
 - workaround for recent AudioAttributes change.

Bug:16455021
Change-Id: Ib9b047a74cff3e0cc354a5aaa96bc92a400b3845

services/core/java/com/android/server/notification/NotificationManagerService.java
services/core/java/com/android/server/notification/NotificationRecord.java
services/core/java/com/android/server/notification/ZenModeHelper.java

index f117f99..bedd369 100644 (file)
@@ -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() {
index 57f3e2d..fefa6f6 100644 (file)
@@ -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;
     }
 
     /**
index c61ce03..6b55213 100644 (file)
@@ -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) {