From d405431bc97087184d1ecb77e4fa495a6ca4709a Mon Sep 17 00:00:00 2001 From: Chris Wren Date: Fri, 24 Jun 2016 17:07:40 -0400 Subject: [PATCH] use an observer for the default sound matches other settings use, and also improves testability of buzzbeepblink Change-Id: I9445448c4c4f24f4f49f7cb1fdcd2f5362944606 --- .../NotificationManagerService.java | 18 +++++++++++++++--- .../util/FakeSettingsProviderTest.java | 1 - .../server/notification/BuzzBeepBlinkTest.java | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 73850de8681e4..59de263946a6b 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -305,6 +305,7 @@ public class NotificationManagerService extends SystemService { private RankingHandler mRankingHandler; private long mLastOverRateLogTime; private float mMaxPackageEnqueueRate = DEFAULT_MAX_NOTIFICATION_ENQUEUE_RATE; + private String mSystemNotificationSound; private static class Archive { final int mBufferSize; @@ -817,6 +818,8 @@ public class NotificationManagerService extends SystemService { private final class SettingsObserver extends ContentObserver { private final Uri NOTIFICATION_LIGHT_PULSE_URI = Settings.System.getUriFor(Settings.System.NOTIFICATION_LIGHT_PULSE); + private final Uri NOTIFICATION_SOUND_URI + = Settings.System.getUriFor(Settings.System.NOTIFICATION_SOUND); private final Uri NOTIFICATION_RATE_LIMIT_URI = Settings.Global.getUriFor(Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE); @@ -828,6 +831,8 @@ public class NotificationManagerService extends SystemService { ContentResolver resolver = getContext().getContentResolver(); resolver.registerContentObserver(NOTIFICATION_LIGHT_PULSE_URI, false, this, UserHandle.USER_ALL); + resolver.registerContentObserver(NOTIFICATION_SOUND_URI, + false, this, UserHandle.USER_ALL); resolver.registerContentObserver(NOTIFICATION_RATE_LIMIT_URI, false, this, UserHandle.USER_ALL); update(null); @@ -851,6 +856,10 @@ public class NotificationManagerService extends SystemService { mMaxPackageEnqueueRate = Settings.Global.getFloat(resolver, Settings.Global.MAX_NOTIFICATION_ENQUEUE_RATE, mMaxPackageEnqueueRate); } + if (uri == null || NOTIFICATION_SOUND_URI.equals(uri)) { + mSystemNotificationSound = Settings.System.getString(resolver, + Settings.System.NOTIFICATION_SOUND); + } } } @@ -903,6 +912,11 @@ public class NotificationManagerService extends SystemService { mHandler = handler; } + @VisibleForTesting + void setSystemNotificationSound(String systemNotificationSound) { + mSystemNotificationSound = systemNotificationSound; + } + @Override public void onStart() { Resources resources = getContext().getResources(); @@ -2869,9 +2883,7 @@ public class NotificationManagerService extends SystemService { soundUri = Settings.System.DEFAULT_NOTIFICATION_URI; // check to see if the default notification sound is silent - ContentResolver resolver = getContext().getContentResolver(); - hasValidSound = Settings.System.getString(resolver, - Settings.System.NOTIFICATION_SOUND) != null; + hasValidSound = mSystemNotificationSound != null; } else if (notification.sound != null) { soundUri = notification.sound; hasValidSound = (soundUri != null); diff --git a/services/tests/servicestests/src/com/android/internal/util/FakeSettingsProviderTest.java b/services/tests/servicestests/src/com/android/internal/util/FakeSettingsProviderTest.java index c7032376f6002..05de0a53e0550 100644 --- a/services/tests/servicestests/src/com/android/internal/util/FakeSettingsProviderTest.java +++ b/services/tests/servicestests/src/com/android/internal/util/FakeSettingsProviderTest.java @@ -33,7 +33,6 @@ import java.util.concurrent.TimeUnit; /** * Unit tests for FakeSettingsProvider. */ -@Suppress public class FakeSettingsProviderTest extends AndroidTestCase { private MockContentResolver mCr; diff --git a/services/tests/servicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java b/services/tests/servicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java index 83a59fd85d294..d51f2d8152ac6 100644 --- a/services/tests/servicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java +++ b/services/tests/servicestests/src/com/android/server/notification/BuzzBeepBlinkTest.java @@ -76,6 +76,7 @@ public class BuzzBeepBlinkTest extends AndroidTestCase { mService.setVibrator(mVibrator); mService.setSystemReady(true); mService.setHandler(mHandler); + mService.setSystemNotificationSound("beep!"); } //