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

Commit 2bc9e4fd authored by Julia Reynolds's avatar Julia Reynolds Committed by android-build-merger
Browse files

Merge "Properly filter alert window notifications" into pi-dev

am: cfa0f19f

Change-Id: I2eda66d48b148156f8e6b2dc0a29bd1256ffbc16
parents 98e63d56 cfa0f19f
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -1219,11 +1219,11 @@ public class Notification implements Parcelable
    public static final String EXTRA_SUBSTITUTE_APP_NAME = "android.substName";

    /**
     * This is set on the notification shown by the activity manager about all apps
     * running in the background.  It indicates that the notification should be shown
     * only if any of the given apps do not already have a {@link #FLAG_FOREGROUND_SERVICE}
     * notification currently visible to the user.  This is a string array of all
     * package names of the apps.
     * This is set on the notifications shown by system_server about apps running foreground
     * services. It indicates that the notification should be shown
     * only if any of the given apps do not already have a properly tagged
     * {@link #FLAG_FOREGROUND_SERVICE} notification currently visible to the user.
     * This is a string array of all package names of the apps.
     * @hide
     */
    public static final String EXTRA_FOREGROUND_APPS = "android.foregroundApps";
+8 −3
Original line number Diff line number Diff line
@@ -641,10 +641,15 @@ public class NotificationData {
            // this is a foreground-service disclosure for a user that does not need to show one
            return true;
        }
        if (mFsc.isSystemAlertNotification(sbn) && !mFsc.isSystemAlertWarningNeeded(
                sbn.getUserId(), sbn.getPackageName())) {
        if (mFsc.isSystemAlertNotification(sbn)) {
            final String[] apps = sbn.getNotification().extras.getStringArray(
                    Notification.EXTRA_FOREGROUND_APPS);
            if (apps != null && apps.length >= 1) {
                if (!mFsc.isSystemAlertWarningNeeded(sbn.getUserId(), apps[0])) {
                    return true;
                }
            }
        }

        return false;
    }
+6 −6
Original line number Diff line number Diff line
@@ -363,16 +363,16 @@ public class PhoneStatusBarPolicy implements Callback, Callbacks,
            zenDescription = mContext.getString(R.string.interruption_level_priority);
        }

        if (DndTile.isVisible(mContext) && !DndTile.isCombinedIcon(mContext)
                && audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
            volumeVisible = true;
            volumeIconId = R.drawable.stat_sys_ringer_silent;
            volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
        } else if (zen != Global.ZEN_MODE_NO_INTERRUPTIONS && zen != Global.ZEN_MODE_ALARMS &&
        if (zen != Global.ZEN_MODE_NO_INTERRUPTIONS && zen != Global.ZEN_MODE_ALARMS &&
                audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_VIBRATE) {
            volumeVisible = true;
            volumeIconId = R.drawable.stat_sys_ringer_vibrate;
            volumeDescription = mContext.getString(R.string.accessibility_ringer_vibrate);
        } else if (zen != Global.ZEN_MODE_NO_INTERRUPTIONS && zen != Global.ZEN_MODE_ALARMS &&
                audioManager.getRingerModeInternal() == AudioManager.RINGER_MODE_SILENT) {
            volumeVisible = true;
            volumeIconId = R.drawable.stat_sys_ringer_silent;
            volumeDescription = mContext.getString(R.string.accessibility_ringer_silent);
        }

        if (zenVisible) {
+25 −0
Original line number Diff line number Diff line
@@ -226,12 +226,21 @@ public class NotificationDataTest extends SysuiTestCase {
    public void testSuppressSystemAlertNotification() {
        when(mFsc.isSystemAlertWarningNeeded(anyInt(), anyString())).thenReturn(false);
        when(mFsc.isSystemAlertNotification(any())).thenReturn(true);
        StatusBarNotification sbn = mRow.getEntry().notification;
        Bundle bundle = new Bundle();
        bundle.putStringArray(Notification.EXTRA_FOREGROUND_APPS, new String[] {"something"});
        sbn.getNotification().extras = bundle;

        assertTrue(mNotificationData.shouldFilterOut(mRow.getEntry().notification));
    }

    @Test
    public void testDoNotSuppressSystemAlertNotification() {
        StatusBarNotification sbn = mRow.getEntry().notification;
        Bundle bundle = new Bundle();
        bundle.putStringArray(Notification.EXTRA_FOREGROUND_APPS, new String[] {"something"});
        sbn.getNotification().extras = bundle;

        when(mFsc.isSystemAlertWarningNeeded(anyInt(), anyString())).thenReturn(true);
        when(mFsc.isSystemAlertNotification(any())).thenReturn(true);

@@ -248,6 +257,22 @@ public class NotificationDataTest extends SysuiTestCase {
        assertFalse(mNotificationData.shouldFilterOut(mRow.getEntry().notification));
    }

    @Test
    public void testDoNotSuppressMalformedSystemAlertNotification() {
        when(mFsc.isSystemAlertWarningNeeded(anyInt(), anyString())).thenReturn(true);

        // missing extra
        assertFalse(mNotificationData.shouldFilterOut(mRow.getEntry().notification));

        StatusBarNotification sbn = mRow.getEntry().notification;
        Bundle bundle = new Bundle();
        bundle.putStringArray(Notification.EXTRA_FOREGROUND_APPS, new String[] {});
        sbn.getNotification().extras = bundle;

        // extra missing values
        assertFalse(mNotificationData.shouldFilterOut(mRow.getEntry().notification));
    }

    @Test
    public void testShouldFilterHiddenNotifications() {
        // setup
+5 −0
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;

import android.net.Uri;
import android.os.Bundle;

import com.android.internal.R;
import com.android.server.policy.IconUtilities;

@@ -109,6 +111,8 @@ class AlertWindowNotification {

        final String message = context.getString(R.string.alert_windows_notification_message,
                appName);
        Bundle extras = new Bundle();
        extras.putStringArray(Notification.EXTRA_FOREGROUND_APPS, new String[] {mPackageName});
        final Notification.Builder builder = new Notification.Builder(context, mNotificationTag)
                .setOngoing(true)
                .setContentTitle(
@@ -118,6 +122,7 @@ class AlertWindowNotification {
                .setColor(context.getColor(R.color.system_notification_accent_color))
                .setStyle(new Notification.BigTextStyle().bigText(message))
                .setLocalOnly(true)
                .addExtras(extras)
                .setContentIntent(getContentIntent(context, mPackageName));

        if (aInfo != null) {