diff options
| author | 2024-04-04 02:49:55 +0000 | |
|---|---|---|
| committer | 2024-04-04 02:49:55 +0000 | |
| commit | 8e3e49856236e65ac6fe04870d709af29276ad52 (patch) | |
| tree | f53dfce8651497ba30ee19dddafba38c0f56bf03 | |
| parent | c118e9624f0996de9556db55f22a752e145c02ff (diff) | |
| parent | 6b3fcf06b7b6524b17b839d7afa02759c0ff536a (diff) | |
Merge "Do not redact system notifications" into main
2 files changed, 48 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerImpl.java index 860068c137a3..0d53277e51dc 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerImpl.java @@ -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(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerTest.kt index 581ca3b14822..4ace163164f1 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/policy/SensitiveNotificationProtectionControllerTest.kt @@ -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() @@ -384,13 +387,33 @@ class SensitiveNotificationProtectionControllerTest : SysuiTestCase() { } @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 // com.android.systemui.tests so use that instead of hardcoding 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) } |