summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2018-06-18 19:43:00 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-06-18 19:43:00 +0000
commit6e288f4232385afc417ba5923c50938a33a2dc0f (patch)
tree8b5518ba1b4c634574d931a942aef69fa65d8dfb
parentfc7188d8222c45a5d86b518d9af1ef3168a5ac94 (diff)
parent7b5ef08b81ccc9f5669d143069bc7d20ac0dd832 (diff)
downloadpackages_apps_Settings-6e288f4232385afc417ba5923c50938a33a2dc0f.tar.gz
packages_apps_Settings-6e288f4232385afc417ba5923c50938a33a2dc0f.tar.bz2
packages_apps_Settings-6e288f4232385afc417ba5923c50938a33a2dc0f.zip
Merge "Add notification sent count to app info"
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java5
-rw-r--r--src/com/android/settings/notification/NotificationBackend.java23
-rw-r--r--tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java16
-rw-r--r--tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java34
5 files changed, 48 insertions, 32 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f0394c9e5e..d0c076ecdf 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -8270,7 +8270,7 @@
<!-- App notification summary with notifications enabled [CHAR LIMIT=40] -->
<string name="notifications_enabled">On</string>
<!-- App notification summary with notifications enabled [CHAR LIMIT=40] -->
- <string name="notifications_enabled_with_info">On / <xliff:g id="notifications_categories_off" example="3 categories turned off">%1$s</xliff:g> </string>
+ <string name="notifications_enabled_with_info"><xliff:g id="notifications_sent" example="~6 per week">%1$s</xliff:g> / <xliff:g id="notifications_categories_off" example="3 categories turned off">%2$s</xliff:g> </string>
<!-- Label for showing apps with blocked notifications in list [CHAR LIMIT=30] -->
<string name="notifications_disabled">Off</string>
<!-- Label for showing apps with some blocked notifications in list [CHAR LIMIT=30] -->
diff --git a/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java b/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
index d4e7e602b6..e4aaa54652 100644
--- a/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
@@ -84,14 +84,15 @@ public class AppNotificationPreferenceController extends AppInfoPreferenceContro
if (appRow.banned) {
return context.getText(R.string.notifications_disabled);
} else if (appRow.channelCount == 0) {
- return context.getText(R.string.notifications_enabled);
+ return NotificationBackend.getSentSummary(context, appRow.sentByApp, false);
} else if (appRow.channelCount == appRow.blockedChannelCount) {
return context.getText(R.string.notifications_disabled);
} else {
if (appRow.blockedChannelCount == 0) {
- return context.getText(R.string.notifications_enabled);
+ return NotificationBackend.getSentSummary(context, appRow.sentByApp, false);
}
return context.getString(R.string.notifications_enabled_with_info,
+ NotificationBackend.getSentSummary(context, appRow.sentByApp, false),
context.getResources().getQuantityString(R.plurals.notifications_categories_off,
appRow.blockedChannelCount, appRow.blockedChannelCount));
}
diff --git a/src/com/android/settings/notification/NotificationBackend.java b/src/com/android/settings/notification/NotificationBackend.java
index 314a99e6b9..a2474fc2df 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -73,7 +73,7 @@ public class NotificationBackend {
row.userId = UserHandle.getUserId(row.uid);
row.blockedChannelCount = getBlockedChannelCount(row.pkg, row.uid);
row.channelCount = getChannelCount(row.pkg, row.uid);
- row.sentByChannel = getAggregatedUsageEvents(context, row.userId, row.pkg);
+ recordAggregatedUsageEvents(context, row);
return row;
}
@@ -271,22 +271,22 @@ public class NotificationBackend {
}
}
- protected Map<String, NotificationsSentState> getAggregatedUsageEvents(
- Context context, int userId, String pkg) {
+ protected void recordAggregatedUsageEvents(Context context, AppRow appRow) {
long now = System.currentTimeMillis();
long startTime = now - (DateUtils.DAY_IN_MILLIS * DAYS_TO_CHECK);
UsageEvents events = null;
try {
events = sUsageStatsManager.queryEventsForPackageForUser(
- startTime, now, userId, pkg, context.getPackageName());
+ startTime, now, appRow.userId, appRow.pkg, context.getPackageName());
} catch (RemoteException e) {
e.printStackTrace();
}
- return getAggregatedUsageEvents(events);
+ recordAggregatedUsageEvents(events, appRow);
}
- protected Map<String, NotificationsSentState> getAggregatedUsageEvents(UsageEvents events) {
- Map<String, NotificationsSentState> sentByChannel = new HashMap<>();
+ protected void recordAggregatedUsageEvents(UsageEvents events, AppRow appRow) {
+ appRow.sentByChannel = new HashMap<>();
+ appRow.sentByApp = new NotificationsSentState();
if (events != null) {
UsageEvents.Event event = new UsageEvents.Event();
while (events.hasNextEvent()) {
@@ -295,22 +295,24 @@ public class NotificationBackend {
if (event.getEventType() == UsageEvents.Event.NOTIFICATION_INTERRUPTION) {
String channelId = event.mNotificationChannelId;
if (channelId != null) {
- NotificationsSentState stats = sentByChannel.get(channelId);
+ NotificationsSentState stats = appRow.sentByChannel.get(channelId);
if (stats == null) {
stats = new NotificationsSentState();
- sentByChannel.put(channelId, stats);
+ appRow.sentByChannel.put(channelId, stats);
}
if (event.getTimeStamp() > stats.lastSent) {
stats.lastSent = event.getTimeStamp();
+ appRow.sentByApp.lastSent = event.getTimeStamp();
}
stats.sentCount++;
+ appRow.sentByApp.sentCount++;
calculateAvgSentCounts(stats);
}
}
}
+ calculateAvgSentCounts(appRow.sentByApp);
}
- return sentByChannel;
}
public static CharSequence getSentSummary(Context context, NotificationsSentState state,
@@ -372,5 +374,6 @@ public class NotificationBackend {
public int blockedChannelCount;
public int channelCount;
public Map<String, NotificationsSentState> sentByChannel;
+ public NotificationsSentState sentByApp;
}
}
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
index 8b1190ed41..a70c3c4097 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
@@ -139,10 +139,12 @@ public class AppNotificationPreferenceControllerTest {
appRow.banned = false;
appRow.blockedChannelCount = 30;
appRow.channelCount = 60;
+ appRow.sentByApp = new NotificationBackend.NotificationsSentState();
+ appRow.sentByApp.avgSentWeekly = 4;
assertThat(mController.getNotificationSummary(
appRow, mContext).toString().contains("30")).isTrue();
- assertThat(mController.getNotificationSummary(
- appRow, mContext).toString().contains("On")).isTrue();
+ assertThat(mController.getNotificationSummary(appRow, mContext).toString().contains(
+ NotificationBackend.getSentSummary(mContext, appRow.sentByApp, false))).isTrue();
}
@Test
@@ -151,7 +153,10 @@ public class AppNotificationPreferenceControllerTest {
appRow.banned = false;
appRow.blockedChannelCount = 0;
appRow.channelCount = 10;
- assertThat(mController.getNotificationSummary(appRow, mContext).toString()).isEqualTo("On");
+ appRow.sentByApp = new NotificationBackend.NotificationsSentState();
+ appRow.sentByApp.avgSentDaily = 4;
+ assertThat(mController.getNotificationSummary(appRow, mContext).toString()).isEqualTo(
+ NotificationBackend.getSentSummary(mContext, appRow.sentByApp, false));
}
@Test
@@ -160,6 +165,9 @@ public class AppNotificationPreferenceControllerTest {
appRow.banned = false;
appRow.blockedChannelCount = 0;
appRow.channelCount = 0;
- assertThat(mController.getNotificationSummary(appRow, mContext).toString()).isEqualTo("On");
+ appRow.sentByApp = new NotificationBackend.NotificationsSentState();
+ appRow.sentByApp.avgSentDaily = 7;
+ assertThat(mController.getNotificationSummary(appRow, mContext).toString()).isEqualTo(
+ NotificationBackend.getSentSummary(mContext, appRow.sentByApp, false));
}
}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
index c725962bd2..0f5f44dbe6 100644
--- a/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
+++ b/tests/robotests/src/com/android/settings/notification/NotificationBackendTest.java
@@ -142,29 +142,33 @@ public class NotificationBackendTest {
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);
+ UsageEvents.Event good1 = new UsageEvents.Event();
+ good1.mEventType = UsageEvents.Event.NOTIFICATION_INTERRUPTION;
+ good1.mPackage = "pkg";
+ good1.mNotificationChannelId = "channel1";
+ good1.mTimeStamp = 6;
+ events.add(good1);
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);
+ AppRow appRow = new AppRow();
+ appRow.pkg = "pkg";
+ backend.recordAggregatedUsageEvents(getUsageEvents(events), appRow);
+
+ assertThat(appRow.sentByChannel.get("channel1").sentCount).isEqualTo(2);
+ assertThat(appRow.sentByChannel.get("channel1").lastSent).isEqualTo(6);
+ assertThat(appRow.sentByChannel.get("channel1").avgSentWeekly).isEqualTo(2);
+ assertThat(appRow.sentByChannel.get("channel2").sentCount).isEqualTo(1);
+ assertThat(appRow.sentByChannel.get("channel2").lastSent).isEqualTo(3);
+ assertThat(appRow.sentByChannel.get("channel2").avgSentWeekly).isEqualTo(1);
+ assertThat(appRow.sentByApp.sentCount).isEqualTo(3);
+ assertThat(appRow.sentByApp.lastSent).isEqualTo(6);
+ assertThat(appRow.sentByApp.avgSentWeekly).isEqualTo(3);
}
private UsageEvents getUsageEvents(List<UsageEvents.Event> events) {