Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5c574e39 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove old screenshots notification channel cleanup code." into sc-v2-dev

parents a9129a5f 145728f1
Loading
Loading
Loading
Loading
+2 −28
Original line number Diff line number Diff line
@@ -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;
    }

+0 −48
Original line number Diff line number Diff line
@@ -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());
    }

}