diff options
author | 2025-02-21 14:04:06 -0800 | |
---|---|---|
committer | 2025-02-28 09:51:41 -0800 | |
commit | cefabb22d58818dbd702f076cbbc477b4593a0cd (patch) | |
tree | 6da1c547498d22450d58b48e806a2f2d48a50787 | |
parent | 909cc533175b236d072737169b2e4a5610315d67 (diff) |
Use the creation time and when to decide whether to redact otps
When deciding whether to redact a notification with an OTP, look to see
if the notification creation time is older than the when, and choose the
earliest timestamp. This ensures that an old OTP won't cause new notification
to be redacted.
Fixes: 389606876
Test: atest NotificationLockscreenUserManagerTest
Flag: android.app.redact_sensitive_content_notifications_on_lockscreen
Change-Id: Ia1f7f16e6c4ef59ca0d2ecbc0048eeb13f60e8f9
2 files changed, 45 insertions, 2 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java index 3eec1cd2d54c..f54c28f4295b 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerTest.java @@ -200,6 +200,7 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { private NotificationEntry mSecondaryUserNotif; private NotificationEntry mWorkProfileNotif; private NotificationEntry mSensitiveContentNotif; + private NotificationEntry mSensitiveNotifWithOldCreationTime; private long mSensitiveNotifPostTime; private final FakeFeatureFlagsClassic mFakeFeatureFlags = new FakeFeatureFlagsClassic(); private final FakeSystemClock mFakeSystemClock = new FakeSystemClock(); @@ -274,6 +275,20 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { .setSensitiveContent(true) .setVisibilityOverride(VISIBILITY_NO_OVERRIDE).build()); mSensitiveNotifPostTime = mSensitiveContentNotif.getSbn().getNotification().getWhen(); + + mSensitiveNotifWithOldCreationTime = new NotificationEntryBuilder() + .setNotification(notifWithPrivateVisibility) + .setUser(new UserHandle(mCurrentUser.id)) + .setPostTime(System.currentTimeMillis()) + // creation time of at least -2 hours, no matter what the current value of + // SystemClock.currentTimeMillis + .setCreationTime(-1 * TimeUnit.HOURS.toMillis(2)) + .build(); + mSensitiveNotifWithOldCreationTime.setRanking( + new RankingBuilder(mCurrentUserNotif.getRanking()) + .setChannel(channel) + .setSensitiveContent(true) + .setVisibilityOverride(VISIBILITY_NO_OVERRIDE).build()); when(mNotifCollection.getEntry(mWorkProfileNotif.getKey())).thenReturn(mWorkProfileNotif); when(mKeyguardInteractorLazy.get()).thenReturn(mKeyguardInteractor); when(mKeyguardInteractor.isKeyguardDismissible()) @@ -653,6 +668,23 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase { @Test @EnableFlags(LockscreenOtpRedaction.FLAG_NAME) + public void testNewSensitiveNotification_notRedactedIfOldCreationTime() { + // Allow private notifications for this user + mSettings.putIntForUser(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, + mCurrentUser.id); + changeSetting(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS); + mLockscreenUserManager.mLocked.set(true); + // Claim the device was last unlocked 1 hour ago. Old enough to redact, but newer than the + // old creation time in the notification (which is -2 hours) + mLockscreenUserManager.mLastLockTime + .set(mSensitiveNotifPostTime - TimeUnit.HOURS.toMillis(1)); + mLockscreenUserManager.mConnectedToWifi.set(false); + assertEquals(REDACTION_TYPE_NONE, + mLockscreenUserManager.getRedactionType(mSensitiveNotifWithOldCreationTime)); + } + + @Test + @EnableFlags(LockscreenOtpRedaction.FLAG_NAME) public void testHasSensitiveContent_redacted() { // Allow private notifications for this user mSettings.putIntForUser(LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java index 32da6fff6bcc..c9b96e9871ed 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationLockscreenUserManagerImpl.java @@ -47,6 +47,7 @@ import android.database.ExecutorContentObserver; import android.net.Uri; import android.os.Looper; import android.os.Process; +import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; import android.provider.Settings; @@ -817,6 +818,7 @@ public class NotificationLockscreenUserManagerImpl implements return false; } + long notificationTime = getEarliestNotificationTime(ent); if (!mRedactOtpOnWifi.get()) { if (mConnectedToWifi.get()) { return false; @@ -824,7 +826,7 @@ public class NotificationLockscreenUserManagerImpl implements long lastWifiConnectTime = mLastWifiConnectionTime.get(); // If the device has connected to wifi since receiving the notification, do not redact - if (ent.getSbn().getPostTime() < lastWifiConnectTime) { + if (notificationTime < lastWifiConnectTime) { return false; } } @@ -837,13 +839,22 @@ public class NotificationLockscreenUserManagerImpl implements // when this notification arrived, do not redact long latestTimeForRedaction = mLastLockTime.get() + mOtpRedactionRequiredLockTimeMs.get(); - if (ent.getSbn().getPostTime() < latestTimeForRedaction) { + if (notificationTime < latestTimeForRedaction) { return false; } return true; } + // Get the earliest time the user might have seen this notification. This is either the + // notification's "when" time, or the notification entry creation time + private long getEarliestNotificationTime(NotificationEntry notif) { + long notifWhenWallClock = notif.getSbn().getNotification().getWhen(); + long creationTimeDelta = SystemClock.elapsedRealtime() - notif.getCreationTime(); + long creationTimeWallClock = System.currentTimeMillis() - creationTimeDelta; + return Math.min(notifWhenWallClock, creationTimeWallClock); + } + private boolean packageHasVisibilityOverride(String key) { if (mCommonNotifCollectionLazy.get() == null) { Log.wtf(TAG, "mEntryManager was null!", new Throwable()); |