Skip to content
Snippets Groups Projects
Commit 9cdc7993 authored by Lyn's avatar Lyn
Browse files

NotificationRecordLogger: age_in_minutes

Bug: 300499874
Test: NotificationRecordLoggerTest
Test: m statsd_testdrive && $ANDROID_HOST_OUT/bin/statsd_testdrive -terse 90 244
Change-Id: I2d49412a577a32d22b5440e792c4085cb7b74cea
parent 5c50e0f6
No related branches found
No related tags found
No related merge requests found
......@@ -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();
}
}
......@@ -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
......
......@@ -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);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment