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

Commit 6b3fcf06 authored by Richard MacGregor's avatar Richard MacGregor
Browse files

Do not redact system notifications

Prevent redaction of important system notifications

Bug: 326119615
Test: atest SensitiveNotificationProtectionControllerTest
Flag: ACONFIG com.android.systemui.screenshare_notification_hiding_bug_fix TRUNK_STAGING
Change-Id: I84a2abaccac9cbca3060caf86615864e1dee7d54
parent 60c608bf
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.permission.flags.Flags.sensitiveNotificationAppProtection;
import static android.provider.Settings.Global.DISABLE_SCREEN_SHARE_PROTECTIONS_FOR_APPS_AND_NOTIFICATIONS;

import static com.android.server.notification.Flags.screenshareNotificationHiding;
import static com.android.systemui.Flags.screenshareNotificationHidingBugFix;

import android.annotation.MainThread;
import android.app.IActivityManager;
@@ -31,6 +32,7 @@ import android.media.projection.MediaProjectionManager;
import android.os.Handler;
import android.os.RemoteException;
import android.os.Trace;
import android.os.UserHandle;
import android.service.notification.StatusBarNotification;
import android.util.ArraySet;
import android.util.Log;
@@ -316,6 +318,10 @@ public class SensitiveNotificationProtectionControllerImpl
            return false;
        }

        if (screenshareNotificationHidingBugFix() && UserHandle.isCore(sbn.getUid())) {
            return false; // do not hide/redact notifications from system uid
        }

        // Only protect/redact notifications if the developer has not explicitly set notification
        // visibility as public and users has not adjusted default channel visibility to private
        boolean notificationRequestsRedaction = entry.isNotificationVisibilityPrivate();
+42 −8
Original line number Diff line number Diff line
@@ -28,8 +28,10 @@ import android.app.NotificationManager.VISIBILITY_NO_OVERRIDE
import android.content.pm.PackageManager
import android.media.projection.MediaProjectionInfo
import android.media.projection.MediaProjectionManager
import android.os.Process
import android.os.UserHandle
import android.permission.flags.Flags.FLAG_SENSITIVE_NOTIFICATION_APP_PROTECTION
import android.platform.test.annotations.DisableFlags
import android.platform.test.annotations.EnableFlags
import android.platform.test.annotations.RequiresFlagsDisabled
import android.platform.test.annotations.RequiresFlagsEnabled
@@ -41,7 +43,8 @@ import androidx.test.filters.SmallTest
import com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession
import com.android.dx.mockito.inline.extended.ExtendedMockito.verify
import com.android.internal.util.FrameworkStatsLog
import com.android.server.notification.Flags
import com.android.server.notification.Flags.FLAG_SCREENSHARE_NOTIFICATION_HIDING
import com.android.systemui.Flags.FLAG_SCREENSHARE_NOTIFICATION_HIDING_BUG_FIX
import com.android.systemui.SysuiTestCase
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.statusbar.RankingBuilder
@@ -77,7 +80,7 @@ import org.mockito.quality.Strictness
@SmallTest
@RunWith(AndroidTestingRunner::class)
@RunWithLooper
@EnableFlags(Flags.FLAG_SCREENSHARE_NOTIFICATION_HIDING)
@EnableFlags(FLAG_SCREENSHARE_NOTIFICATION_HIDING)
class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
    @get:Rule val checkFlagsRule = DeviceFlagsValueProvider.createCheckFlagsRule()

@@ -383,6 +386,26 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
        assertTrue(controller.shouldProtectNotification(notificationEntry))
    }

    @Test
    @DisableFlags(FLAG_SCREENSHARE_NOTIFICATION_HIDING_BUG_FIX)
    fun shouldProtectNotification_projectionActive_isFromCoreApp_fixDisabled_true() {
        mediaProjectionCallback.onStart(mediaProjectionInfo)

        val notificationEntry = setupCoreAppNotificationEntry(TEST_PROJECTION_PACKAGE_NAME)

        assertTrue(controller.shouldProtectNotification(notificationEntry))
    }

    @Test
    @EnableFlags(FLAG_SCREENSHARE_NOTIFICATION_HIDING_BUG_FIX)
    fun shouldProtectNotification_projectionActive_isFromCoreApp_false() {
        mediaProjectionCallback.onStart(mediaProjectionInfo)

        val notificationEntry = setupCoreAppNotificationEntry(TEST_PROJECTION_PACKAGE_NAME)

        assertFalse(controller.shouldProtectNotification(notificationEntry))
    }

    @Test
    fun shouldProtectNotification_projectionActive_sysuiExempt_false() {
        // SystemUi context package name is exempt, but in test scenarios its
@@ -390,7 +413,7 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
        setShareFullScreenViaSystemUi()
        mediaProjectionCallback.onStart(mediaProjectionInfo)

        val notificationEntry = setupNotificationEntry(TEST_PACKAGE_NAME, false)
        val notificationEntry = setupNotificationEntry(TEST_PACKAGE_NAME)

        assertFalse(controller.shouldProtectNotification(notificationEntry))
    }
@@ -407,7 +430,7 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
            .thenReturn(PackageManager.PERMISSION_GRANTED)
        mediaProjectionCallback.onStart(mediaProjectionInfo)

        val notificationEntry = setupNotificationEntry(TEST_PACKAGE_NAME, false)
        val notificationEntry = setupNotificationEntry(TEST_PACKAGE_NAME)

        assertTrue(controller.shouldProtectNotification(notificationEntry))
    }
@@ -424,7 +447,7 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
            .thenReturn(PackageManager.PERMISSION_GRANTED)
        mediaProjectionCallback.onStart(mediaProjectionInfo)

        val notificationEntry = setupNotificationEntry(TEST_PACKAGE_NAME, false)
        val notificationEntry = setupNotificationEntry(TEST_PACKAGE_NAME)

        assertFalse(controller.shouldProtectNotification(notificationEntry))
    }
@@ -434,7 +457,7 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
        setShareFullScreenViaBugReportHandler()
        mediaProjectionCallback.onStart(mediaProjectionInfo)

        val notificationEntry = setupNotificationEntry(TEST_PACKAGE_NAME, false)
        val notificationEntry = setupNotificationEntry(TEST_PACKAGE_NAME)

        assertFalse(controller.shouldProtectNotification(notificationEntry))
    }
@@ -657,6 +680,7 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
    private fun setupNotificationEntry(
        packageName: String,
        isFgs: Boolean = false,
        isCoreApp: Boolean = false,
        overrideVisibility: Boolean = false,
        overrideChannelVisibility: Boolean = false,
    ): NotificationEntry {
@@ -668,8 +692,14 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
            // Developer has marked notification as public
            notification.visibility = VISIBILITY_PUBLIC
        }
        val notificationEntry =
            NotificationEntryBuilder().setNotification(notification).setPkg(packageName).build()
        val notificationEntryBuilder =
            NotificationEntryBuilder().setNotification(notification).setPkg(packageName)
        if (isCoreApp) {
            notificationEntryBuilder.setUid(Process.FIRST_APPLICATION_UID - 10)
        } else {
            notificationEntryBuilder.setUid(Process.FIRST_APPLICATION_UID + 10)
        }
        val notificationEntry = notificationEntryBuilder.build()
        val channel = NotificationChannel("1", "1", IMPORTANCE_HIGH)
        if (overrideChannelVisibility) {
            // User doesn't allow private notifications at the channel level
@@ -688,6 +718,10 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() {
        return setupNotificationEntry(packageName, isFgs = true)
    }

    private fun setupCoreAppNotificationEntry(packageName: String): NotificationEntry {
        return setupNotificationEntry(packageName, isCoreApp = true)
    }

    private fun setupPublicNotificationEntry(packageName: String): NotificationEntry {
        return setupNotificationEntry(packageName, overrideVisibility = true)
    }