Add notification sent count to channel settings

Bug: 79607096
Test: robotests
Change-Id: I3c1d8fd1cbd9f5b8e997f1bfd50926121a5040fb
This commit is contained in:
Julia Reynolds
2018-06-12 10:17:26 -04:00
parent a5711f1bc6
commit 8ebfb12cac
4 changed files with 156 additions and 0 deletions

View File

@@ -16,17 +16,31 @@
package com.android.settings.notification;
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.when;
import android.app.usage.UsageEvents;
import android.os.Parcel;
import com.android.settings.notification.NotificationBackend.AppRow;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@RunWith(SettingsRobolectricTestRunner.class)
public class NotificationBackendTest {
@@ -118,4 +132,47 @@ public class NotificationBackendTest {
assertTrue(appRow.lockedImportance);
assertEquals("SpecificChannel", appRow.lockedChannelId);
}
@Test
public void testGetAggregatedUsageEvents_multipleEventsAgg() {
List<UsageEvents.Event> events = new ArrayList<>();
UsageEvents.Event good = new UsageEvents.Event();
good.mEventType = UsageEvents.Event.NOTIFICATION_INTERRUPTION;
good.mPackage = "pkg";
good.mNotificationChannelId = "channel1";
good.mTimeStamp = 2;
events.add(good);
UsageEvents.Event good1 = new UsageEvents.Event();
good1.mEventType = UsageEvents.Event.NOTIFICATION_INTERRUPTION;
good1.mPackage = "pkg";
good1.mNotificationChannelId = "channel1";
good1.mTimeStamp = 6;
events.add(good1);
UsageEvents.Event good2 = new UsageEvents.Event();
good2.mEventType = UsageEvents.Event.NOTIFICATION_INTERRUPTION;
good2.mPackage = "pkg";
good2.mNotificationChannelId = "channel2";
good2.mTimeStamp = 3;
events.add(good2);
NotificationBackend backend = new NotificationBackend();
Map<String, NotificationBackend.NotificationsSentState> stats =
backend.getAggregatedUsageEvents(getUsageEvents(events));
assertThat(stats.get("channel1").sentCount).isEqualTo(2);
assertThat(stats.get("channel1").lastSent).isEqualTo(6);
assertThat(stats.get("channel1").avgSentWeekly).isEqualTo(2);
assertThat(stats.get("channel2").sentCount).isEqualTo(1);
assertThat(stats.get("channel2").lastSent).isEqualTo(3);
assertThat(stats.get("channel2").avgSentWeekly).isEqualTo(1);
}
private UsageEvents getUsageEvents(List<UsageEvents.Event> events) {
UsageEvents usageEvents = new UsageEvents(events, new String[] {"pkg"});
Parcel parcel = Parcel.obtain();
parcel.setDataPosition(0);
usageEvents.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
return UsageEvents.CREATOR.createFromParcel(parcel);
}
}