Loading core/java/android/app/NotificationChannel.java +2 −2 Original line number Diff line number Diff line Loading @@ -644,7 +644,7 @@ public final class NotificationChannel implements Parcelable { @Nullable private Uri restoreSoundUri(Context context, @Nullable Uri uri) { if (uri == null) { if (uri == null || Uri.EMPTY.equals(uri)) { return null; } ContentResolver contentResolver = context.getContentResolver(); Loading Loading @@ -680,7 +680,7 @@ public final class NotificationChannel implements Parcelable { private Uri getSoundForBackup(Context context) { Uri sound = getSound(); if (sound == null) { if (sound == null || Uri.EMPTY.equals(sound)) { return null; } Uri canonicalSound = context.getContentResolver().canonicalize(sound); Loading packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java +1 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ public class NotificationChannels extends SystemUI { NotificationChannel screenshotChannel = new NotificationChannel(SCREENSHOTS_HEADSUP, name, NotificationManager.IMPORTANCE_HIGH); // pop on screen screenshotChannel.setSound(Uri.parse(""), // silent screenshotChannel.setSound(null, // silent new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); screenshotChannel.setBlockableSystem(true); Loading packages/SystemUI/tests/src/com/android/systemui/util/ChannelsTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -103,7 +103,7 @@ public class ChannelsTest extends SysuiTestCase { NotificationManager.IMPORTANCE_MIN); NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", legacyChannel); assertEquals(Uri.EMPTY, newChannel.getSound()); assertEquals(null, newChannel.getSound()); assertEquals("newName", newChannel.getName()); // MIN importance not user locked, so HIGH wins out. assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); Loading @@ -113,7 +113,7 @@ public class ChannelsTest extends SysuiTestCase { public void testInheritFromLegacy_noLegacyExists() { NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", null); assertEquals(Uri.EMPTY, newChannel.getSound()); assertEquals(null, newChannel.getSound()); assertEquals("newName", newChannel.getName()); assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); } Loading services/tests/uiservicestests/src/com/android/server/notification/NotificationChannelTest.java +25 −0 Original line number Diff line number Diff line Loading @@ -19,20 +19,26 @@ package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import android.app.NotificationChannel; import android.net.Uri; import android.os.Parcel; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import android.util.Xml; import com.android.internal.util.FastXmlSerializer; import com.android.server.UiServiceTestCase; import org.junit.Test; import org.junit.runner.RunWith; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlSerializer; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @SmallTest Loading Loading @@ -68,4 +74,23 @@ public class NotificationChannelTest extends UiServiceTestCase { serializer.setOutput(new BufferedOutputStream(baos), "utf-8"); channel.writeXml(serializer); } @Test public void testBackupEmptySound() throws Exception { NotificationChannel channel = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT); channel.setSound(Uri.EMPTY, null); XmlSerializer serializer = new FastXmlSerializer(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); serializer.setOutput(new BufferedOutputStream(baos), "utf-8"); channel.writeXmlForBackup(serializer, getContext()); XmlPullParser parser = Xml.newPullParser(); parser.setInput(new BufferedInputStream( new ByteArrayInputStream(baos.toByteArray())), null); NotificationChannel restored = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT); restored.populateFromXmlForRestore(parser, getContext()); assertNull(restored.getSound()); } } Loading
core/java/android/app/NotificationChannel.java +2 −2 Original line number Diff line number Diff line Loading @@ -644,7 +644,7 @@ public final class NotificationChannel implements Parcelable { @Nullable private Uri restoreSoundUri(Context context, @Nullable Uri uri) { if (uri == null) { if (uri == null || Uri.EMPTY.equals(uri)) { return null; } ContentResolver contentResolver = context.getContentResolver(); Loading Loading @@ -680,7 +680,7 @@ public final class NotificationChannel implements Parcelable { private Uri getSoundForBackup(Context context) { Uri sound = getSound(); if (sound == null) { if (sound == null || Uri.EMPTY.equals(sound)) { return null; } Uri canonicalSound = context.getContentResolver().canonicalize(sound); Loading
packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java +1 −1 Original line number Diff line number Diff line Loading @@ -113,7 +113,7 @@ public class NotificationChannels extends SystemUI { NotificationChannel screenshotChannel = new NotificationChannel(SCREENSHOTS_HEADSUP, name, NotificationManager.IMPORTANCE_HIGH); // pop on screen screenshotChannel.setSound(Uri.parse(""), // silent screenshotChannel.setSound(null, // silent new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); screenshotChannel.setBlockableSystem(true); Loading
packages/SystemUI/tests/src/com/android/systemui/util/ChannelsTest.java +2 −2 Original line number Diff line number Diff line Loading @@ -103,7 +103,7 @@ public class ChannelsTest extends SysuiTestCase { NotificationManager.IMPORTANCE_MIN); NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", legacyChannel); assertEquals(Uri.EMPTY, newChannel.getSound()); assertEquals(null, newChannel.getSound()); assertEquals("newName", newChannel.getName()); // MIN importance not user locked, so HIGH wins out. assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); Loading @@ -113,7 +113,7 @@ public class ChannelsTest extends SysuiTestCase { public void testInheritFromLegacy_noLegacyExists() { NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", null); assertEquals(Uri.EMPTY, newChannel.getSound()); assertEquals(null, newChannel.getSound()); assertEquals("newName", newChannel.getName()); assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); } Loading
services/tests/uiservicestests/src/com/android/server/notification/NotificationChannelTest.java +25 −0 Original line number Diff line number Diff line Loading @@ -19,20 +19,26 @@ package com.android.server.notification; import static android.app.NotificationManager.IMPORTANCE_DEFAULT; import static junit.framework.Assert.assertEquals; import static junit.framework.Assert.assertNull; import android.app.NotificationChannel; import android.net.Uri; import android.os.Parcel; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import android.util.Xml; import com.android.internal.util.FastXmlSerializer; import com.android.server.UiServiceTestCase; import org.junit.Test; import org.junit.runner.RunWith; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlSerializer; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @SmallTest Loading Loading @@ -68,4 +74,23 @@ public class NotificationChannelTest extends UiServiceTestCase { serializer.setOutput(new BufferedOutputStream(baos), "utf-8"); channel.writeXml(serializer); } @Test public void testBackupEmptySound() throws Exception { NotificationChannel channel = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT); channel.setSound(Uri.EMPTY, null); XmlSerializer serializer = new FastXmlSerializer(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); serializer.setOutput(new BufferedOutputStream(baos), "utf-8"); channel.writeXmlForBackup(serializer, getContext()); XmlPullParser parser = Xml.newPullParser(); parser.setInput(new BufferedInputStream( new ByteArrayInputStream(baos.toByteArray())), null); NotificationChannel restored = new NotificationChannel("a", "ab", IMPORTANCE_DEFAULT); restored.populateFromXmlForRestore(parser, getContext()); assertNull(restored.getSound()); } }