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

Commit d4d75ae1 authored by Lyn Han's avatar Lyn Han Committed by Android (Google) Code Review
Browse files

Merge "NotificationRecordLogger: age_in_minutes" into main

parents 2ae61c92 9cdc7993
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.internal.logging.UiEvent;
import com.android.internal.logging.UiEventLogger;
import com.android.internal.util.FrameworkStatsLog;

import java.time.Duration;
import java.util.ArrayList;
import java.util.Objects;

@@ -497,6 +498,7 @@ interface NotificationRecordLogger {
        final boolean is_non_dismissible;
        final int fsi_state;
        final boolean is_locked;
        final int age_in_minutes;
        @DurationMillisLong long post_duration_millis; // Not final; calculated at the end.

        NotificationReported(NotificationRecordPair p,
@@ -541,6 +543,9 @@ interface NotificationRecordLogger {
                    hasFullScreenIntent, hasFsiRequestedButDeniedFlag, eventType);

            this.is_locked = p.r.isLocked();

            this.age_in_minutes = NotificationRecordLogger.getAgeInMinutes(
                    p.r.getSbn().getPostTime(), p.r.getSbn().getNotification().when);
        }
    }

@@ -601,4 +606,13 @@ interface NotificationRecordLogger {
        }
        return FrameworkStatsLog.NOTIFICATION_REPORTED__FSI_STATE__NO_FSI;
    }

    /**
     * @param postTimeMs time (in {@link System#currentTimeMillis} time) the notification was posted
     * @param whenMs A timestamp related to this notification, in milliseconds since the epoch.
     * @return difference in duration as an integer in minutes
     */
    static int getAgeInMinutes(long postTimeMs, long whenMs) {
        return (int) Duration.ofMillis(postTimeMs - whenMs).toMinutes();
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -77,7 +77,8 @@ class NotificationRecordLoggerImpl implements NotificationRecordLogger {
                notificationReported.is_non_dismissible,
                notificationReported.post_duration_millis,
                notificationReported.fsi_state,
                notificationReported.is_locked);
                notificationReported.is_locked,
                notificationReported.age_in_minutes);
    }

    @Override
+11 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static com.android.server.notification.NotificationRecordLogger.Notificat
import static com.android.server.notification.NotificationRecordLogger.NotificationCancelledEvent.NOTIFICATION_CANCEL_USER_OTHER;
import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_POSTED;
import static com.android.server.notification.NotificationRecordLogger.NotificationReportedEvent.NOTIFICATION_UPDATED;
import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -48,6 +49,8 @@ import com.android.internal.util.FrameworkStatsLog;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.time.Duration;


@SmallTest
@RunWith(AndroidJUnit4.class)
@@ -230,4 +233,12 @@ public class NotificationRecordLoggerTest extends UiServiceTestCase {
                NotificationRecordLogger.NotificationCancelledEvent.fromCancelReason(
                        REASON_CANCEL, DISMISSAL_OTHER));
    }

    @Test
    public void testGetAgeInMinutes() {
        long postTimeMs = Duration.ofMinutes(5).toMillis();
        long whenMs = Duration.ofMinutes(2).toMillis();
        int age = NotificationRecordLogger.getAgeInMinutes(postTimeMs, whenMs);
        assertThat(age).isEqualTo(3);
    }
}