Loading packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java +2 −28 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import java.util.Arrays; public class NotificationChannels extends SystemUI { public static String ALERTS = "ALR"; public static String SCREENSHOTS_LEGACY = "SCN"; public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP"; public static String GENERAL = "GEN"; public static String STORAGE = "DSK"; Loading Loading @@ -84,18 +83,11 @@ public class NotificationChannels extends SystemUI { general, storage, createScreenshotChannel( context.getString(R.string.notification_channel_screenshot), nm.getNotificationChannel(SCREENSHOTS_LEGACY)), context.getString(R.string.notification_channel_screenshot)), batteryChannel, hint )); // Delete older SS channel if present. // Screenshots promoted to heads-up in P, this cleans up the lower priority channel from O. // This line can be deleted in Q. nm.deleteNotificationChannel(SCREENSHOTS_LEGACY); if (isTv(context)) { // TV specific notification channel for TV PIP controls. // Importance should be {@link NotificationManager#IMPORTANCE_MAX} to have the highest Loading @@ -113,7 +105,7 @@ public class NotificationChannels extends SystemUI { * @return */ @VisibleForTesting static NotificationChannel createScreenshotChannel( String name, NotificationChannel legacySS) { String name) { NotificationChannel screenshotChannel = new NotificationChannel(SCREENSHOTS_HEADSUP, name, NotificationManager.IMPORTANCE_HIGH); // pop on screen Loading @@ -121,24 +113,6 @@ public class NotificationChannels extends SystemUI { new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); screenshotChannel.setBlockable(true); if (legacySS != null) { // Respect any user modified fields from the old channel. int userlock = legacySS.getUserLockedFields(); if ((userlock & NotificationChannel.USER_LOCKED_IMPORTANCE) != 0) { screenshotChannel.setImportance(legacySS.getImportance()); } if ((userlock & NotificationChannel.USER_LOCKED_SOUND) != 0) { screenshotChannel.setSound(legacySS.getSound(), legacySS.getAudioAttributes()); } if ((userlock & NotificationChannel.USER_LOCKED_VIBRATION) != 0) { screenshotChannel.setVibrationPattern(legacySS.getVibrationPattern()); } if ((userlock & NotificationChannel.USER_LOCKED_LIGHTS) != 0) { screenshotChannel.setLightColor(legacySS.getLightColor()); } // skip show_badge, irrelevant for system channel } return screenshotChannel; } Loading packages/SystemUI/tests/src/com/android/systemui/util/ChannelsTest.java +0 −48 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.provider.Settings; import android.test.suitebuilder.annotation.SmallTest; import android.util.ArraySet; Loading Loading @@ -68,51 +67,4 @@ public class ChannelsTest extends SysuiTestCase { list.forEach((chan) -> assertTrue(ALL_CHANNELS.contains(chan.getId()))); } @Test public void testChannelSetup_noLegacyScreenshot() { // Assert old channel cleaned up. // TODO: remove that code + this test after P. NotificationChannels.createAll(mContext); ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(mMockNotificationManager).deleteNotificationChannel( NotificationChannels.SCREENSHOTS_LEGACY); } @Test public void testInheritFromLegacy_keepsUserLockedLegacySettings() { NotificationChannel legacyChannel = new NotificationChannel("id", "oldName", NotificationManager.IMPORTANCE_MIN); legacyChannel.setImportance(NotificationManager.IMPORTANCE_NONE);; legacyChannel.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, legacyChannel.getAudioAttributes()); legacyChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE | NotificationChannel.USER_LOCKED_SOUND); NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", legacyChannel); // NONE importance user locked, so don't use HIGH for new channel. assertEquals(NotificationManager.IMPORTANCE_NONE, newChannel.getImportance()); assertEquals(Settings.System.DEFAULT_NOTIFICATION_URI, newChannel.getSound()); } @Test public void testInheritFromLegacy_dropsUnlockedLegacySettings() { NotificationChannel legacyChannel = new NotificationChannel("id", "oldName", NotificationManager.IMPORTANCE_MIN); NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", legacyChannel); assertEquals(null, newChannel.getSound()); assertEquals("newName", newChannel.getName()); // MIN importance not user locked, so HIGH wins out. assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); } @Test public void testInheritFromLegacy_noLegacyExists() { NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", null); assertEquals(null, newChannel.getSound()); assertEquals("newName", newChannel.getName()); assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); } } Loading
packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java +2 −28 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import java.util.Arrays; public class NotificationChannels extends SystemUI { public static String ALERTS = "ALR"; public static String SCREENSHOTS_LEGACY = "SCN"; public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP"; public static String GENERAL = "GEN"; public static String STORAGE = "DSK"; Loading Loading @@ -84,18 +83,11 @@ public class NotificationChannels extends SystemUI { general, storage, createScreenshotChannel( context.getString(R.string.notification_channel_screenshot), nm.getNotificationChannel(SCREENSHOTS_LEGACY)), context.getString(R.string.notification_channel_screenshot)), batteryChannel, hint )); // Delete older SS channel if present. // Screenshots promoted to heads-up in P, this cleans up the lower priority channel from O. // This line can be deleted in Q. nm.deleteNotificationChannel(SCREENSHOTS_LEGACY); if (isTv(context)) { // TV specific notification channel for TV PIP controls. // Importance should be {@link NotificationManager#IMPORTANCE_MAX} to have the highest Loading @@ -113,7 +105,7 @@ public class NotificationChannels extends SystemUI { * @return */ @VisibleForTesting static NotificationChannel createScreenshotChannel( String name, NotificationChannel legacySS) { String name) { NotificationChannel screenshotChannel = new NotificationChannel(SCREENSHOTS_HEADSUP, name, NotificationManager.IMPORTANCE_HIGH); // pop on screen Loading @@ -121,24 +113,6 @@ public class NotificationChannels extends SystemUI { new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); screenshotChannel.setBlockable(true); if (legacySS != null) { // Respect any user modified fields from the old channel. int userlock = legacySS.getUserLockedFields(); if ((userlock & NotificationChannel.USER_LOCKED_IMPORTANCE) != 0) { screenshotChannel.setImportance(legacySS.getImportance()); } if ((userlock & NotificationChannel.USER_LOCKED_SOUND) != 0) { screenshotChannel.setSound(legacySS.getSound(), legacySS.getAudioAttributes()); } if ((userlock & NotificationChannel.USER_LOCKED_VIBRATION) != 0) { screenshotChannel.setVibrationPattern(legacySS.getVibrationPattern()); } if ((userlock & NotificationChannel.USER_LOCKED_LIGHTS) != 0) { screenshotChannel.setLightColor(legacySS.getLightColor()); } // skip show_badge, irrelevant for system channel } return screenshotChannel; } Loading
packages/SystemUI/tests/src/com/android/systemui/util/ChannelsTest.java +0 −48 Original line number Diff line number Diff line Loading @@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.provider.Settings; import android.test.suitebuilder.annotation.SmallTest; import android.util.ArraySet; Loading Loading @@ -68,51 +67,4 @@ public class ChannelsTest extends SysuiTestCase { list.forEach((chan) -> assertTrue(ALL_CHANNELS.contains(chan.getId()))); } @Test public void testChannelSetup_noLegacyScreenshot() { // Assert old channel cleaned up. // TODO: remove that code + this test after P. NotificationChannels.createAll(mContext); ArgumentCaptor<List> captor = ArgumentCaptor.forClass(List.class); verify(mMockNotificationManager).deleteNotificationChannel( NotificationChannels.SCREENSHOTS_LEGACY); } @Test public void testInheritFromLegacy_keepsUserLockedLegacySettings() { NotificationChannel legacyChannel = new NotificationChannel("id", "oldName", NotificationManager.IMPORTANCE_MIN); legacyChannel.setImportance(NotificationManager.IMPORTANCE_NONE);; legacyChannel.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, legacyChannel.getAudioAttributes()); legacyChannel.lockFields(NotificationChannel.USER_LOCKED_IMPORTANCE | NotificationChannel.USER_LOCKED_SOUND); NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", legacyChannel); // NONE importance user locked, so don't use HIGH for new channel. assertEquals(NotificationManager.IMPORTANCE_NONE, newChannel.getImportance()); assertEquals(Settings.System.DEFAULT_NOTIFICATION_URI, newChannel.getSound()); } @Test public void testInheritFromLegacy_dropsUnlockedLegacySettings() { NotificationChannel legacyChannel = new NotificationChannel("id", "oldName", NotificationManager.IMPORTANCE_MIN); NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", legacyChannel); assertEquals(null, newChannel.getSound()); assertEquals("newName", newChannel.getName()); // MIN importance not user locked, so HIGH wins out. assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); } @Test public void testInheritFromLegacy_noLegacyExists() { NotificationChannel newChannel = NotificationChannels.createScreenshotChannel("newName", null); assertEquals(null, newChannel.getSound()); assertEquals("newName", newChannel.getName()); assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); } }