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

Commit 0abae11b authored by Julia Reynolds's avatar Julia Reynolds
Browse files

Properly consider non-blockable channels

In inline controls

Bug: 109875297
Test: atest SystemUITests
Change-Id: I4308b1312339dae611a84a0d22f6aadc877bc3e2
parent e9922a88
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -438,7 +438,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
     */
    public boolean getIsNonblockable() {
        boolean isNonblockable = Dependency.get(NotificationBlockingHelperManager.class)
                .isNonblockablePackage(mStatusBarNotification.getPackageName());
                .isNonblockable(mStatusBarNotification.getPackageName(),
                        mEntry.channel.getId());

        // If the SystemNotifAsyncTask hasn't finished running or retrieved a value, we'll try once
        // again, but in-place on the main thread this time. This should rarely ever get called.
+15 −2
Original line number Diff line number Diff line
@@ -144,8 +144,15 @@ public class NotificationBlockingHelperManager {
    /**
     * Returns whether the given package name is in the list of non-blockable packages.
     */
    public boolean isNonblockablePackage(String packageName) {
        return mNonBlockablePkgs.contains(packageName);
    public boolean isNonblockable(String packageName, String channelName) {
        return mNonBlockablePkgs.contains(packageName)
                || mNonBlockablePkgs.contains(makeChannelKey(packageName, channelName));
    }

    // Format must stay in sync with frameworks/base/core/res/res/values/config.xml
    // config_nonBlockableNotificationPackages
    private String makeChannelKey(String pkg, String channel) {
        return pkg + ":" + channel;
    }

    @VisibleForTesting
@@ -157,4 +164,10 @@ public class NotificationBlockingHelperManager {
    void setBlockingHelperRowForTest(ExpandableNotificationRow blockingHelperRowForTest) {
        mBlockingHelperRow = blockingHelperRowForTest;
    }

    @VisibleForTesting
    void setNonBlockablePkgs(String[] pkgsAndChannels) {
        mNonBlockablePkgs = new HashSet<>();
        Collections.addAll(mNonBlockablePkgs, pkgsAndChannels);
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
        // of the child row.
        ExpandableNotificationRow childRow = groupRow.getChildrenContainer().getViewAtPosition(0);
        childRow.getEntry().userSentiment = USER_SENTIMENT_NEGATIVE;
        assertFalse(childRow.getIsNonblockable());

        assertTrue(mBlockingHelperManager.perhapsShowBlockingHelper(childRow, mMenuRow));

@@ -220,6 +221,24 @@ public class NotificationBlockingHelperManagerTest extends SysuiTestCase {
        verify(mEntryManager).updateNotifications();
    }

    @Test
    public void testNonBlockable_package() {
        mBlockingHelperManager.setNonBlockablePkgs(new String[] {"banana", "strawberry:pie"});

        assertFalse(mBlockingHelperManager.isNonblockable("orange", "pie"));

        assertTrue(mBlockingHelperManager.isNonblockable("banana", "pie"));
    }

    @Test
    public void testNonBlockable_channel() {
        mBlockingHelperManager.setNonBlockablePkgs(new String[] {"banana", "strawberry:pie"});

        assertFalse(mBlockingHelperManager.isNonblockable("strawberry", "shortcake"));

        assertTrue(mBlockingHelperManager.isNonblockable("strawberry", "pie"));
    }

    private ExpandableNotificationRow createBlockableRowSpy() throws Exception {
        ExpandableNotificationRow row = spy(mHelper.createRow());
        when(row.getIsNonblockable()).thenReturn(false);
+2 −2
Original line number Diff line number Diff line
@@ -280,7 +280,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase {
                any(PackageManager.class),
                any(INotificationManager.class),
                eq(statusBarNotification.getPackageName()),
                isNull(),
                any(NotificationChannel.class),
                anyInt(),
                eq(statusBarNotification),
                any(NotificationInfo.CheckSaveListener.class),
@@ -306,7 +306,7 @@ public class NotificationGutsManagerTest extends SysuiTestCase {
                any(PackageManager.class),
                any(INotificationManager.class),
                eq(statusBarNotification.getPackageName()),
                isNull(),
                any(NotificationChannel.class),
                anyInt(),
                eq(statusBarNotification),
                any(NotificationInfo.CheckSaveListener.class),
+7 −1
Original line number Diff line number Diff line
@@ -16,10 +16,13 @@

package com.android.systemui.statusbar;

import static android.app.NotificationManager.IMPORTANCE_DEFAULT;

import android.annotation.Nullable;
import android.app.ActivityManager;
import android.app.Instrumentation;
import android.app.Notification;
import android.app.NotificationChannel;
import android.content.Context;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
@@ -118,7 +121,7 @@ public class NotificationTestHelper {
                        R.layout.custom_view_dark))
                .build();
        Notification.Builder notificationBuilder =
                new Notification.Builder(mContext)
                new Notification.Builder(mContext, "channelId")
                        .setSmallIcon(R.drawable.ic_person)
                        .setContentTitle("Title")
                        .setContentText("Text")
@@ -166,6 +169,9 @@ public class NotificationTestHelper {
        NotificationData.Entry entry = new NotificationData.Entry(sbn);
        entry.row = row;
        entry.createIcons(mContext, sbn);
        entry.channel = new NotificationChannel(
                notification.getChannelId(), notification.getChannelId(), IMPORTANCE_DEFAULT);
        entry.channel.setBlockableSystem(true);
        NotificationInflaterTest.runThenWaitForInflation(
                () -> row.updateNotification(entry),
                row.getNotificationInflater());