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

Commit 0c4c5411 authored by Jay Aliomer's avatar Jay Aliomer Committed by Automerger Merge Worker
Browse files

Merge "Show system notifications when DnD is enabled" into tm-dev am:...

Merge "Show system notifications when DnD is enabled" into tm-dev am: ab13fd85 am: 47b70b94 am: 2c1fdf2e

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



Change-Id: I7aea42ac3b7660f3dfb2ace145801e402005642d
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents b608e1d4 2c1fdf2e
Loading
Loading
Loading
Loading
+17 −17
Original line number Original line Diff line number Diff line
@@ -157,13 +157,6 @@ public final class NotificationEntry extends ListEntry {
    // this value will reset when the view is completely removed from the shade (ie: filtered out)
    // this value will reset when the view is completely removed from the shade (ie: filtered out)
    private long initializationTime = -1;
    private long initializationTime = -1;


    /**
     * Whether or not this row represents a system notification. Note that if this is
     * {@code null}, that means we were either unable to retrieve the info or have yet to
     * retrieve the info.
     */
    public Boolean mIsSystemNotification;

    /**
    /**
     * Has the user sent a reply through this Notification.
     * Has the user sent a reply through this Notification.
     */
     */
@@ -777,12 +770,28 @@ public final class NotificationEntry extends ListEntry {
        if (mSbn.getNotification().isMediaNotification()) {
        if (mSbn.getNotification().isMediaNotification()) {
            return true;
            return true;
        }
        }
        if (mIsSystemNotification != null && mIsSystemNotification) {
        if (!isBlockable()) {
            return true;
            return true;
        }
        }
        return false;
        return false;
    }
    }


    /**
     * Returns whether this row is considered blockable (i.e. it's not a system notif
     * or is not in an allowList).
     */
    public boolean isBlockable() {
        if (getChannel() == null) {
            return false;
        }
        if (getChannel().isImportanceLockedByCriticalDeviceFunction()
                && !getChannel().isBlockable()) {
            return false;
        }

        return true;
    }

    private boolean shouldSuppressVisualEffect(int effect) {
    private boolean shouldSuppressVisualEffect(int effect) {
        if (isExemptFromDndVisualSuppression()) {
        if (isExemptFromDndVisualSuppression()) {
            return false;
            return false;
@@ -857,15 +866,6 @@ public final class NotificationEntry extends ListEntry {
        return Objects.equals(n.category, category);
        return Objects.equals(n.category, category);
    }
    }


    /**
     * Whether or not this row represents a system notification. Note that if this is
     * {@code null}, that means we were either unable to retrieve the info or have yet to
     * retrieve the info.
     */
    public Boolean isSystemNotification() {
        return mIsSystemNotification;
    }

    /**
    /**
     * Set this notification to be sensitive.
     * Set this notification to be sensitive.
     *
     *
+7 −8
Original line number Original line Diff line number Diff line
@@ -513,16 +513,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
     * or is in an allowList).
     * or is in an allowList).
     */
     */
    public boolean getIsNonblockable() {
    public boolean getIsNonblockable() {
        if (mEntry == null || mEntry.getChannel() == null) {
        if (mEntry == null) {
            Log.w(TAG, "missing entry or channel");
            return true;
            return true;
        }
        }
        if (mEntry.getChannel().isImportanceLockedByCriticalDeviceFunction()
        return !mEntry.isBlockable();
                && !mEntry.getChannel().isBlockable()) {
            return true;
        }

        return false;
    }
    }


    private boolean isConversation() {
    private boolean isConversation() {
@@ -1669,6 +1663,11 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
        }
    }
    }


    @VisibleForTesting
    protected void setEntry(NotificationEntry entry) {
        mEntry = entry;
    }

    private final Runnable mExpireRecentlyAlertedFlag = () -> applyAudiblyAlertedRecently(false);
    private final Runnable mExpireRecentlyAlertedFlag = () -> applyAudiblyAlertedRecently(false);


    private void applyAudiblyAlertedRecently(boolean audiblyAlertedRecently) {
    private void applyAudiblyAlertedRecently(boolean audiblyAlertedRecently) {
+47 −2
Original line number Original line Diff line number Diff line
@@ -29,6 +29,7 @@ import static com.android.systemui.statusbar.NotificationEntryHelper.modifySbn;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mock;


import android.app.ActivityManager;
import android.app.ActivityManager;
@@ -57,6 +58,7 @@ import com.android.systemui.util.time.FakeSystemClock;
import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
import org.mockito.Mockito;


import java.util.ArrayList;
import java.util.ArrayList;


@@ -72,6 +74,7 @@ public class NotificationEntryTest extends SysuiTestCase {
    private int mId;
    private int mId;


    private NotificationEntry mEntry;
    private NotificationEntry mEntry;
    private NotificationChannel mChannel = Mockito.mock(NotificationChannel.class);
    private final FakeSystemClock mClock = new FakeSystemClock();
    private final FakeSystemClock mClock = new FakeSystemClock();


    @Before
    @Before
@@ -85,10 +88,13 @@ public class NotificationEntryTest extends SysuiTestCase {
                .setPkg(TEST_PACKAGE_NAME)
                .setPkg(TEST_PACKAGE_NAME)
                .setOpPkg(TEST_PACKAGE_NAME)
                .setOpPkg(TEST_PACKAGE_NAME)
                .setUid(TEST_UID)
                .setUid(TEST_UID)
                .setChannel(mChannel)
                .setId(mId++)
                .setId(mId++)
                .setNotification(n.build())
                .setNotification(n.build())
                .setUser(new UserHandle(ActivityManager.getCurrentUser()))
                .setUser(new UserHandle(ActivityManager.getCurrentUser()))
                .build();
                .build();

        doReturn(false).when(mChannel).isBlockable();
    }
    }


    @Test
    @Test
@@ -99,6 +105,44 @@ public class NotificationEntryTest extends SysuiTestCase {
        assertFalse(mEntry.shouldSuppressAmbient());
        assertFalse(mEntry.shouldSuppressAmbient());
    }
    }


    @Test
    public void testBlockableEntryWhenCritical() {
        doReturn(true).when(mChannel).isBlockable();

        assertTrue(mEntry.isBlockable());
    }


    @Test
    public void testBlockableEntryWhenCriticalAndChannelNotBlockable() {
        doReturn(true).when(mChannel).isBlockable();
        doReturn(true).when(mChannel).isImportanceLockedByCriticalDeviceFunction();

        assertTrue(mEntry.isBlockable());
    }

    @Test
    public void testNonBlockableEntryWhenCriticalAndChannelNotBlockable() {
        doReturn(false).when(mChannel).isBlockable();
        doReturn(true).when(mChannel).isImportanceLockedByCriticalDeviceFunction();

        assertFalse(mEntry.isBlockable());
    }

    @Test
    public void testBlockableWhenEntryHasNoChannel() {
        StatusBarNotification sbn = new SbnBuilder().build();
        Ranking ranking = new RankingBuilder()
                .setChannel(null)
                .setKey(sbn.getKey())
                .build();

        NotificationEntry entry =
                new NotificationEntry(sbn, ranking, mClock.uptimeMillis());

        assertFalse(entry.isBlockable());
    }

    @Test
    @Test
    public void testIsExemptFromDndVisualSuppression_media() {
    public void testIsExemptFromDndVisualSuppression_media() {
        Notification.Builder n = new Notification.Builder(mContext, "")
        Notification.Builder n = new Notification.Builder(mContext, "")
@@ -117,7 +161,8 @@ public class NotificationEntryTest extends SysuiTestCase {


    @Test
    @Test
    public void testIsExemptFromDndVisualSuppression_system() {
    public void testIsExemptFromDndVisualSuppression_system() {
        mEntry.mIsSystemNotification = true;
        doReturn(true).when(mChannel).isImportanceLockedByCriticalDeviceFunction();
        doReturn(false).when(mChannel).isBlockable();


        assertTrue(mEntry.isExemptFromDndVisualSuppression());
        assertTrue(mEntry.isExemptFromDndVisualSuppression());
        assertFalse(mEntry.shouldSuppressAmbient());
        assertFalse(mEntry.shouldSuppressAmbient());
@@ -128,7 +173,7 @@ public class NotificationEntryTest extends SysuiTestCase {
        NotificationEntry entry = new NotificationEntryBuilder()
        NotificationEntry entry = new NotificationEntryBuilder()
                .setUid(UID_NORMAL)
                .setUid(UID_NORMAL)
                .build();
                .build();
        entry.mIsSystemNotification = true;
        doReturn(true).when(mChannel).isImportanceLockedByCriticalDeviceFunction();
        modifyRanking(entry).setSuppressedVisualEffects(SUPPRESSED_EFFECT_AMBIENT).build();
        modifyRanking(entry).setSuppressedVisualEffects(SUPPRESSED_EFFECT_AMBIENT).build();


        modifySbn(entry)
        modifySbn(entry)
+5 −2
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.systemui.statusbar.notification.collection.coordinator;
package com.android.systemui.statusbar.notification.collection.coordinator;


import static android.app.NotificationManager.IMPORTANCE_DEFAULT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;


@@ -30,6 +31,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.app.Notification;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.NotificationManager;
import android.testing.AndroidTestingRunner;
import android.testing.AndroidTestingRunner;


@@ -277,6 +279,7 @@ public class RankingCoordinatorTest extends SysuiTestCase {


    private RankingBuilder getRankingForUnfilteredNotif() {
    private RankingBuilder getRankingForUnfilteredNotif() {
        return new RankingBuilder(mEntry.getRanking())
        return new RankingBuilder(mEntry.getRanking())
                .setChannel(new NotificationChannel("id", null, IMPORTANCE_DEFAULT))
                .setSuppressedVisualEffects(0)
                .setSuppressedVisualEffects(0)
                .setSuspended(false);
                .setSuspended(false);
    }
    }
@@ -292,7 +295,7 @@ public class RankingCoordinatorTest extends SysuiTestCase {
        mEntry.setRanking(new RankingBuilder(mEntry.getRanking())
        mEntry.setRanking(new RankingBuilder(mEntry.getRanking())
                .setImportance(ambient
                .setImportance(ambient
                        ? NotificationManager.IMPORTANCE_MIN
                        ? NotificationManager.IMPORTANCE_MIN
                        : NotificationManager.IMPORTANCE_DEFAULT)
                        : IMPORTANCE_DEFAULT)
                .build());
                .build());
        assertEquals(ambient, mEntry.getRanking().isAmbient());
        assertEquals(ambient, mEntry.getRanking().isAmbient());
    }
    }
+2 −0
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.when;


import android.app.Notification;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.PendingIntent;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.Intent;
import android.graphics.drawable.Icon;
import android.graphics.drawable.Icon;
@@ -552,6 +553,7 @@ public class NotificationInterruptStateProviderImplTest extends SysuiTestCase {
                .setPkg("a")
                .setPkg("a")
                .setOpPkg("a")
                .setOpPkg("a")
                .setTag("a")
                .setTag("a")
                .setChannel(new NotificationChannel("a", null, importance))
                .setNotification(n)
                .setNotification(n)
                .setImportance(importance)
                .setImportance(importance)
                .build();
                .build();
Loading