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

Commit 94c5dd21 authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge "Exempt some notis from DND visual suppression" into pi-dev

am: a000724a

Change-Id: I47c11979e3a0687262f7e9beed81a3ed5db06905
parents d9b91fca a000724a
Loading
Loading
Loading
Loading
+30 −39
Original line number Diff line number Diff line
@@ -18,25 +18,21 @@ package com.android.systemui.statusbar;

import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_AMBIENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_FULL_SCREEN_INTENT;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_LIGHTS;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_NOTIFICATION_LIST;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_PEEK;
import static android.app.NotificationManager.Policy.SUPPRESSED_EFFECT_STATUS_BAR;

import android.Manifest;
import android.app.AppGlobals;
import android.app.AppOpsManager;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.content.Context;
import android.graphics.drawable.Icon;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.SystemClock;
import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.Ranking;
import android.service.notification.NotificationListenerService.RankingMap;
import android.service.notification.SnoozeCriterion;
@@ -46,10 +42,8 @@ import android.util.ArraySet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RemoteViews;
import android.Manifest;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.messages.nano.SystemMessageProto;
import com.android.internal.statusbar.StatusBarIcon;
import com.android.internal.util.NotificationColorUtil;
import com.android.systemui.Dependency;
@@ -454,47 +448,44 @@ public class NotificationData {
        return Ranking.VISIBILITY_NO_OVERRIDE;
    }

    public boolean shouldSuppressFullScreenIntent(String key) {
        if (mRankingMap != null) {
            getRanking(key, mTmpRanking);
            return (mTmpRanking.getSuppressedVisualEffects()
                    & SUPPRESSED_EFFECT_FULL_SCREEN_INTENT) != 0;
    public boolean shouldSuppressFullScreenIntent(StatusBarNotification sbn) {
        return shouldSuppressVisualEffect(sbn, SUPPRESSED_EFFECT_FULL_SCREEN_INTENT);
    }
        return false;

    public boolean shouldSuppressPeek(StatusBarNotification sbn) {
        return shouldSuppressVisualEffect(sbn, SUPPRESSED_EFFECT_PEEK);
    }

    public boolean shouldSuppressPeek(String key) {
        if (mRankingMap != null) {
            getRanking(key, mTmpRanking);
            return (mTmpRanking.getSuppressedVisualEffects()
                    & SUPPRESSED_EFFECT_PEEK) != 0;
    public boolean shouldSuppressStatusBar(StatusBarNotification sbn) {
        return shouldSuppressVisualEffect(sbn, SUPPRESSED_EFFECT_STATUS_BAR);
    }
        return false;

    public boolean shouldSuppressAmbient(StatusBarNotification sbn) {
        return shouldSuppressVisualEffect(sbn, SUPPRESSED_EFFECT_AMBIENT);
    }

    public boolean shouldSuppressStatusBar(String key) {
        if (mRankingMap != null) {
            getRanking(key, mTmpRanking);
            return (mTmpRanking.getSuppressedVisualEffects()
                    & SUPPRESSED_EFFECT_STATUS_BAR) != 0;
    public boolean shouldSuppressNotificationList(StatusBarNotification sbn) {
        return shouldSuppressVisualEffect(sbn, SUPPRESSED_EFFECT_NOTIFICATION_LIST);
    }

    private boolean shouldSuppressVisualEffect(StatusBarNotification sbn, int effect) {
        if (isExemptFromDndVisualSuppression(sbn)) {
            return false;
        }

    public boolean shouldSuppressAmbient(String key) {
        String key = sbn.getKey();
        if (mRankingMap != null) {
            getRanking(key, mTmpRanking);
            return (mTmpRanking.getSuppressedVisualEffects()
                    & SUPPRESSED_EFFECT_AMBIENT) != 0;
            return (mTmpRanking.getSuppressedVisualEffects() & effect) != 0;
        }
        return false;
    }

    public boolean shouldSuppressNotificationList(String key) {
        if (mRankingMap != null) {
            getRanking(key, mTmpRanking);
            return (mTmpRanking.getSuppressedVisualEffects()
                    & SUPPRESSED_EFFECT_NOTIFICATION_LIST) != 0;
    protected boolean isExemptFromDndVisualSuppression(StatusBarNotification sbn) {
        if ((sbn.getNotification().flags & Notification.FLAG_FOREGROUND_SERVICE) != 0) {
            return true;
        }
        if (sbn.getNotification().isMediaNotification()) {
            return true;
        }
        return false;
    }
@@ -620,11 +611,11 @@ public class NotificationData {
            return true;
        }

        if (mEnvironment.isDozing() && shouldSuppressAmbient(sbn.getKey())) {
        if (mEnvironment.isDozing() && shouldSuppressAmbient(sbn)) {
            return true;
        }

        if (!mEnvironment.isDozing() && shouldSuppressNotificationList(sbn.getKey())) {
        if (!mEnvironment.isDozing() && shouldSuppressNotificationList(sbn)) {
            return true;
        }

+5 −5
Original line number Diff line number Diff line
@@ -299,12 +299,12 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
        updateNotifications();
    }

    private boolean shouldSuppressFullScreenIntent(String key) {
    private boolean shouldSuppressFullScreenIntent(StatusBarNotification sbn) {
        if (mPresenter.isDeviceInVrMode()) {
            return true;
        }

        return mNotificationData.shouldSuppressFullScreenIntent(key);
        return mNotificationData.shouldSuppressFullScreenIntent(sbn);
    }

    private void inflateViews(NotificationData.Entry entry, ViewGroup parent) {
@@ -690,7 +690,7 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
        NotificationData.Entry shadeEntry = createNotificationViews(notification);
        boolean isHeadsUped = shouldPeek(shadeEntry);
        if (!isHeadsUped && notification.getNotification().fullScreenIntent != null) {
            if (shouldSuppressFullScreenIntent(key)) {
            if (shouldSuppressFullScreenIntent(notification)) {
                if (DEBUG) {
                    Log.d(TAG, "No Fullscreen intent: suppressed by DND: " + key);
                }
@@ -846,13 +846,13 @@ public class NotificationEntryManager implements Dumpable, NotificationInflater.
            return false;
        }

        if (!mPresenter.isDozing() && mNotificationData.shouldSuppressPeek(sbn.getKey())) {
        if (!mPresenter.isDozing() && mNotificationData.shouldSuppressPeek(sbn)) {
            if (DEBUG) Log.d(TAG, "No peeking: suppressed by DND: " + sbn.getKey());
            return false;
        }

        // Peeking triggers an ambient display pulse, so disable peek is ambient is active
        if (mPresenter.isDozing() && mNotificationData.shouldSuppressAmbient(sbn.getKey())) {
        if (mPresenter.isDozing() && mNotificationData.shouldSuppressAmbient(sbn)) {
            if (DEBUG) Log.d(TAG, "No peeking: suppressed by DND: " + sbn.getKey());
            return false;
        }
+1 −1
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ public class NotificationIconAreaController implements DarkReceiver {

        // showAmbient == show in shade but not shelf
        if (!showAmbient && mEntryManager.getNotificationData().shouldSuppressStatusBar(
                entry.key)) {
                entry.notification)) {
            return false;
        }

+37 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.app.Notification;
import android.app.NotificationChannel;
import android.content.pm.IPackageManager;
import android.content.pm.PackageManager;
import android.media.session.MediaSession;
import android.os.Bundle;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;
@@ -61,6 +62,7 @@ public class NotificationDataTest extends SysuiTestCase {
    private static final int UID_NORMAL = 123;
    private static final int UID_ALLOW_DURING_SETUP = 456;
    private static final String TEST_HIDDEN_NOTIFICATION_KEY = "testHiddenNotificationKey";
    private static final String TEST_EXEMPT_DND_VISUAL_SUPPRESSION_KEY = "exempt";

    private final StatusBarNotification mMockStatusBarNotification =
            mock(StatusBarNotification.class);
@@ -275,6 +277,7 @@ public class NotificationDataTest extends SysuiTestCase {

    @Test
    public void testShouldFilterHiddenNotifications() {
        initStatusBarNotification(false);
        // setup
        when(mFsc.isSystemAlertWarningNeeded(anyInt(), anyString())).thenReturn(false);
        when(mFsc.isSystemAlertNotification(any())).thenReturn(false);
@@ -289,6 +292,33 @@ public class NotificationDataTest extends SysuiTestCase {
        assertFalse(mNotificationData.shouldFilterOut(mMockStatusBarNotification));
    }

    @Test
    public void testIsExemptFromDndVisualSuppression_foreground() {
        initStatusBarNotification(false);
        when(mMockStatusBarNotification.getKey()).thenReturn(
                TEST_EXEMPT_DND_VISUAL_SUPPRESSION_KEY);
        Notification n = mMockStatusBarNotification.getNotification();
        n.flags = Notification.FLAG_FOREGROUND_SERVICE;

        assertTrue(mNotificationData.isExemptFromDndVisualSuppression(mMockStatusBarNotification));
        assertFalse(mNotificationData.shouldSuppressAmbient(mMockStatusBarNotification));
    }

    @Test
    public void testIsExemptFromDndVisualSuppression_media() {
        initStatusBarNotification(false);
        when(mMockStatusBarNotification.getKey()).thenReturn(
                TEST_EXEMPT_DND_VISUAL_SUPPRESSION_KEY);
        Notification n = mMockStatusBarNotification.getNotification();
        Notification.Builder nb = Notification.Builder.recoverBuilder(mContext, n);
        nb.setStyle(new Notification.MediaStyle().setMediaSession(mock(MediaSession.Token.class)));
        n = nb.build();
        when(mMockStatusBarNotification.getNotification()).thenReturn(n);

        assertTrue(mNotificationData.isExemptFromDndVisualSuppression(mMockStatusBarNotification));
        assertFalse(mNotificationData.shouldSuppressAmbient(mMockStatusBarNotification));
    }

    private void initStatusBarNotification(boolean allowDuringSetup) {
        Bundle bundle = new Bundle();
        bundle.putBoolean(Notification.EXTRA_ALLOW_DURING_SETUP, allowDuringSetup);
@@ -318,6 +348,13 @@ public class NotificationDataTest extends SysuiTestCase {
                        outRanking.getImportance(), outRanking.getImportanceExplanation(),
                        outRanking.getOverrideGroupKey(), outRanking.getChannel(), null, null,
                        outRanking.canShowBadge(), outRanking.getUserSentiment(), true);
            } else if (key.equals(TEST_EXEMPT_DND_VISUAL_SUPPRESSION_KEY)) {
                outRanking.populate(key, outRanking.getRank(),
                        outRanking.matchesInterruptionFilter(),
                        outRanking.getVisibilityOverride(), 255,
                        outRanking.getImportance(), outRanking.getImportanceExplanation(),
                        outRanking.getOverrideGroupKey(), outRanking.getChannel(), null, null,
                        outRanking.canShowBadge(), outRanking.getUserSentiment(), true);
            } else {
                outRanking.populate(key, outRanking.getRank(),
                        outRanking.matchesInterruptionFilter(),