Loading packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +3 −2 Original line number Diff line number Diff line Loading @@ -185,7 +185,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { // The public notification will show similar info but with the actual screenshot omitted mPublicNotificationBuilder = new Notification.Builder(context, NotificationChannels.SCREENSHOTS) new Notification.Builder(context, NotificationChannels.SCREENSHOTS_HEADSUP) .setContentTitle(r.getString(R.string.screenshot_saving_title)) .setContentText(r.getString(R.string.screenshot_saving_text)) .setSmallIcon(R.drawable.stat_notify_image) Loading @@ -196,7 +196,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { com.android.internal.R.color.system_notification_accent_color)); SystemUI.overrideNotificationAppName(context, mPublicNotificationBuilder); mNotificationBuilder = new Notification.Builder(context, NotificationChannels.SCREENSHOTS) mNotificationBuilder = new Notification.Builder(context, NotificationChannels.SCREENSHOTS_HEADSUP) .setTicker(r.getString(R.string.screenshot_saving_ticker) + (mTickerAddSpace ? " " : "")) .setContentTitle(r.getString(R.string.screenshot_saving_title)) Loading packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java +45 −5 Original line number Diff line number Diff line Loading @@ -31,7 +31,8 @@ import java.util.Arrays; public class NotificationChannels extends SystemUI { public static String ALERTS = "ALR"; public static String SCREENSHOTS = "SCN"; public static String SCREENSHOTS_LEGACY = "SCN"; public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP"; public static String GENERAL = "GEN"; public static String STORAGE = "DSK"; public static String TVPIP = "TPP"; Loading @@ -55,10 +56,6 @@ public class NotificationChannels extends SystemUI { ALERTS, context.getString(R.string.notification_channel_alerts), NotificationManager.IMPORTANCE_HIGH), new NotificationChannel( SCREENSHOTS, context.getString(R.string.notification_channel_screenshot), NotificationManager.IMPORTANCE_LOW), new NotificationChannel( GENERAL, context.getString(R.string.notification_channel_general), Loading @@ -69,9 +66,18 @@ public class NotificationChannels extends SystemUI { isTv(context) ? NotificationManager.IMPORTANCE_DEFAULT : NotificationManager.IMPORTANCE_LOW), createScreenshotChannel( context.getString(R.string.notification_channel_screenshot), nm.getNotificationChannel(SCREENSHOTS_LEGACY)), batteryChannel )); // 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 @@ -83,6 +89,40 @@ public class NotificationChannels extends SystemUI { } } /** * Set up screenshot channel, respecting any previously committed user settings on legacy * channel. * @return */ @VisibleForTesting static NotificationChannel createScreenshotChannel( String name, NotificationChannel legacySS) { NotificationChannel screenshotChannel = new NotificationChannel(SCREENSHOTS_HEADSUP, name, NotificationManager.IMPORTANCE_HIGH); // pop on screen screenshotChannel.setSound(Uri.parse(""), // silent new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); 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; } @Override public void start() { createAll(mContext); Loading packages/SystemUI/tests/src/com/android/systemui/util/ChannelsTest.java +52 −1 Original line number Diff line number Diff line Loading @@ -26,11 +26,14 @@ import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.net.Uri; import android.provider.Settings; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import android.util.ArraySet; import com.android.systemui.SysuiTestCase; import com.android.systemui.util.NotificationChannels; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -54,7 +57,7 @@ public class ChannelsTest extends SysuiTestCase { public void testChannelSetup() { Set<String> ALL_CHANNELS = new ArraySet<>(Arrays.asList( NotificationChannels.ALERTS, NotificationChannels.SCREENSHOTS, NotificationChannels.SCREENSHOTS_HEADSUP, NotificationChannels.STORAGE, NotificationChannels.GENERAL, NotificationChannels.BATTERY Loading @@ -66,4 +69,52 @@ public class ChannelsTest extends SysuiTestCase { assertEquals(ALL_CHANNELS.size(), list.size()); 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(Uri.EMPTY, 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(Uri.EMPTY, newChannel.getSound()); assertEquals("newName", newChannel.getName()); assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); } } Loading
packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +3 −2 Original line number Diff line number Diff line Loading @@ -185,7 +185,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { // The public notification will show similar info but with the actual screenshot omitted mPublicNotificationBuilder = new Notification.Builder(context, NotificationChannels.SCREENSHOTS) new Notification.Builder(context, NotificationChannels.SCREENSHOTS_HEADSUP) .setContentTitle(r.getString(R.string.screenshot_saving_title)) .setContentText(r.getString(R.string.screenshot_saving_text)) .setSmallIcon(R.drawable.stat_notify_image) Loading @@ -196,7 +196,8 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { com.android.internal.R.color.system_notification_accent_color)); SystemUI.overrideNotificationAppName(context, mPublicNotificationBuilder); mNotificationBuilder = new Notification.Builder(context, NotificationChannels.SCREENSHOTS) mNotificationBuilder = new Notification.Builder(context, NotificationChannels.SCREENSHOTS_HEADSUP) .setTicker(r.getString(R.string.screenshot_saving_ticker) + (mTickerAddSpace ? " " : "")) .setContentTitle(r.getString(R.string.screenshot_saving_title)) Loading
packages/SystemUI/src/com/android/systemui/util/NotificationChannels.java +45 −5 Original line number Diff line number Diff line Loading @@ -31,7 +31,8 @@ import java.util.Arrays; public class NotificationChannels extends SystemUI { public static String ALERTS = "ALR"; public static String SCREENSHOTS = "SCN"; public static String SCREENSHOTS_LEGACY = "SCN"; public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP"; public static String GENERAL = "GEN"; public static String STORAGE = "DSK"; public static String TVPIP = "TPP"; Loading @@ -55,10 +56,6 @@ public class NotificationChannels extends SystemUI { ALERTS, context.getString(R.string.notification_channel_alerts), NotificationManager.IMPORTANCE_HIGH), new NotificationChannel( SCREENSHOTS, context.getString(R.string.notification_channel_screenshot), NotificationManager.IMPORTANCE_LOW), new NotificationChannel( GENERAL, context.getString(R.string.notification_channel_general), Loading @@ -69,9 +66,18 @@ public class NotificationChannels extends SystemUI { isTv(context) ? NotificationManager.IMPORTANCE_DEFAULT : NotificationManager.IMPORTANCE_LOW), createScreenshotChannel( context.getString(R.string.notification_channel_screenshot), nm.getNotificationChannel(SCREENSHOTS_LEGACY)), batteryChannel )); // 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 @@ -83,6 +89,40 @@ public class NotificationChannels extends SystemUI { } } /** * Set up screenshot channel, respecting any previously committed user settings on legacy * channel. * @return */ @VisibleForTesting static NotificationChannel createScreenshotChannel( String name, NotificationChannel legacySS) { NotificationChannel screenshotChannel = new NotificationChannel(SCREENSHOTS_HEADSUP, name, NotificationManager.IMPORTANCE_HIGH); // pop on screen screenshotChannel.setSound(Uri.parse(""), // silent new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build()); 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; } @Override public void start() { createAll(mContext); Loading
packages/SystemUI/tests/src/com/android/systemui/util/ChannelsTest.java +52 −1 Original line number Diff line number Diff line Loading @@ -26,11 +26,14 @@ import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationManager; import android.content.Context; import android.net.Uri; import android.provider.Settings; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.SmallTest; import android.util.ArraySet; import com.android.systemui.SysuiTestCase; import com.android.systemui.util.NotificationChannels; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading @@ -54,7 +57,7 @@ public class ChannelsTest extends SysuiTestCase { public void testChannelSetup() { Set<String> ALL_CHANNELS = new ArraySet<>(Arrays.asList( NotificationChannels.ALERTS, NotificationChannels.SCREENSHOTS, NotificationChannels.SCREENSHOTS_HEADSUP, NotificationChannels.STORAGE, NotificationChannels.GENERAL, NotificationChannels.BATTERY Loading @@ -66,4 +69,52 @@ public class ChannelsTest extends SysuiTestCase { assertEquals(ALL_CHANNELS.size(), list.size()); 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(Uri.EMPTY, 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(Uri.EMPTY, newChannel.getSound()); assertEquals("newName", newChannel.getName()); assertEquals(NotificationManager.IMPORTANCE_HIGH, newChannel.getImportance()); } }