Merge "Remove old screenshots notification channel cleanup code." into sc-v2-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
5c574e39e8
@@ -31,7 +31,6 @@ import java.util.Arrays;
|
|||||||
|
|
||||||
public class NotificationChannels extends SystemUI {
|
public class NotificationChannels extends SystemUI {
|
||||||
public static String ALERTS = "ALR";
|
public static String ALERTS = "ALR";
|
||||||
public static String SCREENSHOTS_LEGACY = "SCN";
|
|
||||||
public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP";
|
public static String SCREENSHOTS_HEADSUP = "SCN_HEADSUP";
|
||||||
public static String GENERAL = "GEN";
|
public static String GENERAL = "GEN";
|
||||||
public static String STORAGE = "DSK";
|
public static String STORAGE = "DSK";
|
||||||
@@ -84,18 +83,11 @@ public class NotificationChannels extends SystemUI {
|
|||||||
general,
|
general,
|
||||||
storage,
|
storage,
|
||||||
createScreenshotChannel(
|
createScreenshotChannel(
|
||||||
context.getString(R.string.notification_channel_screenshot),
|
context.getString(R.string.notification_channel_screenshot)),
|
||||||
nm.getNotificationChannel(SCREENSHOTS_LEGACY)),
|
|
||||||
batteryChannel,
|
batteryChannel,
|
||||||
hint
|
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)) {
|
if (isTv(context)) {
|
||||||
// TV specific notification channel for TV PIP controls.
|
// TV specific notification channel for TV PIP controls.
|
||||||
// Importance should be {@link NotificationManager#IMPORTANCE_MAX} to have the highest
|
// Importance should be {@link NotificationManager#IMPORTANCE_MAX} to have the highest
|
||||||
@@ -113,7 +105,7 @@ public class NotificationChannels extends SystemUI {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting static NotificationChannel createScreenshotChannel(
|
@VisibleForTesting static NotificationChannel createScreenshotChannel(
|
||||||
String name, NotificationChannel legacySS) {
|
String name) {
|
||||||
NotificationChannel screenshotChannel = new NotificationChannel(SCREENSHOTS_HEADSUP,
|
NotificationChannel screenshotChannel = new NotificationChannel(SCREENSHOTS_HEADSUP,
|
||||||
name, NotificationManager.IMPORTANCE_HIGH); // pop on screen
|
name, NotificationManager.IMPORTANCE_HIGH); // pop on screen
|
||||||
|
|
||||||
@@ -121,24 +113,6 @@ public class NotificationChannels extends SystemUI {
|
|||||||
new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build());
|
new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).build());
|
||||||
screenshotChannel.setBlockable(true);
|
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;
|
return screenshotChannel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import static org.mockito.Mockito.verify;
|
|||||||
import android.app.NotificationChannel;
|
import android.app.NotificationChannel;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
|
||||||
import android.test.suitebuilder.annotation.SmallTest;
|
import android.test.suitebuilder.annotation.SmallTest;
|
||||||
import android.util.ArraySet;
|
import android.util.ArraySet;
|
||||||
|
|
||||||
@@ -68,51 +67,4 @@ public class ChannelsTest extends SysuiTestCase {
|
|||||||
list.forEach((chan) -> assertTrue(ALL_CHANNELS.contains(chan.getId())));
|
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user