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

Commit cefabb22 authored by Nate Myren's avatar Nate Myren
Browse files

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
parent 909cc533
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
@@ -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())
@@ -651,6 +666,23 @@ public class NotificationLockscreenUserManagerTest extends SysuiTestCase {
                mLockscreenUserManager.getRedactionType(mSensitiveContentNotif));
    }

    @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() {
+13 −2
Original line number Diff line number Diff line
@@ -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());