Merge "Remove old screenshots notification channel cleanup code." into sc-v2-dev am: 5c574e39e8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16008220

Change-Id: I725f106b17d26b370c2fccdf6ae08c8178334778
This commit is contained in:
TreeHugger Robot
2021-10-08 16:57:30 +00:00
committed by Automerger Merge Worker
2 changed files with 2 additions and 76 deletions

View File

@@ -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";
@@ -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
@@ -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
@@ -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;
}

View File

@@ -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;
@@ -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());
}
}