Merge "Add app info notification summary" into pi-dev
diff --git a/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java b/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
index 87fa9ca..4c1f009 100644
--- a/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java
@@ -22,6 +22,7 @@
import android.os.Bundle;
import android.support.v7.preference.Preference;
+import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.notification.AppNotificationSettings;
import com.android.settings.notification.NotificationBackend;
@@ -77,7 +78,18 @@
public static CharSequence getNotificationSummary(NotificationBackend.AppRow appRow,
Context context) {
- // TODO: implement summary when it is known what it should say
- return "";
+ if (appRow == null) {
+ return "";
+ }
+ if (appRow.banned || appRow.channelCount == appRow.blockedChannelCount) {
+ return context.getString(R.string.notifications_disabled);
+ } else {
+ if (appRow.blockedChannelCount == 0) {
+ return context.getString(R.string.notifications_enabled);
+ }
+ return context.getString(R.string.notifications_enabled_with_info,
+ 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 34b6ce5..62c8388 100644
--- a/src/com/android/settings/notification/NotificationBackend.java
+++ b/src/com/android/settings/notification/NotificationBackend.java
@@ -60,6 +60,8 @@
row.banned = getNotificationsBanned(row.pkg, row.uid);
row.showBadge = canShowBadge(row.pkg, row.uid);
row.userId = UserHandle.getUserId(row.uid);
+ row.blockedChannelCount = getBlockedChannelCount(row.pkg, row.uid);
+ row.channelCount = getChannelCount(row.pkg, row.uid);
return row;
}
@@ -178,18 +180,6 @@
}
}
- public NotificationChannelGroup getGroupWithChannels(String pkg, int uid, String groupId) {
- if (groupId == null) {
- return null;
- }
- try {
- return sINM.getPopulatedNotificationChannelGroupForPackage(pkg, uid, groupId, true);
- } catch (Exception e) {
- Log.w(TAG, "Error calling NoMan", e);
- return null;
- }
- }
-
public ParceledListSlice<NotificationChannelGroup> getGroups(String pkg, int uid) {
try {
return sINM.getNotificationChannelGroupsForPackage(pkg, uid, false);
@@ -224,6 +214,15 @@
}
}
+ public int getBlockedChannelCount(String pkg, int uid) {
+ try {
+ return sINM.getBlockedChannelCount(pkg, uid);
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ return 0;
+ }
+ }
+
public boolean onlyHasDefaultChannel(String pkg, int uid) {
try {
return sINM.onlyHasDefaultChannel(pkg, uid);
@@ -233,6 +232,15 @@
}
}
+ public int getChannelCount(String pkg, int uid) {
+ try {
+ return sINM.getNumNotificationChannelsForPackage(pkg, uid, false);
+ } catch (Exception e) {
+ Log.w(TAG, "Error calling NoMan", e);
+ return 0;
+ }
+ }
+
public List<NotifyingApp> getRecentApps() {
try {
return sINM.getRecentNotifyingAppsForUser(UserHandle.myUserId()).getList();
@@ -259,5 +267,7 @@
public String lockedChannelId;
public boolean showBadge;
public int userId;
+ public int blockedChannelCount;
+ public int channelCount;
}
}
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 5d24180..a453f78 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java
@@ -105,4 +105,49 @@
assertThat(controller.getArguments().containsKey(EXTRA_FRAGMENT_ARG_KEY)).isTrue();
assertThat(controller.getArguments().getString(EXTRA_FRAGMENT_ARG_KEY)).isEqualTo("test");
}
+
+ @Test
+ public void getNotificationSummary_noCrashOnNull() {
+ mController.getNotificationSummary(null, mContext);
+ }
+
+ @Test
+ public void getNotificationSummary_appBlocked() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = true;
+ appRow.blockedChannelCount = 30;
+ assertThat(mController.getNotificationSummary(appRow, mContext).toString())
+ .isEqualTo("Off");
+ }
+
+ @Test
+ public void getNotificationSummary_appNotBlockedAllChannelsBlocked() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = false;
+ appRow.blockedChannelCount = 30;
+ appRow.channelCount = 30;
+ assertThat(mController.getNotificationSummary(appRow, mContext).toString())
+ .isEqualTo("Off");
+ }
+
+ @Test
+ public void getNotificationSummary_appNotBlocked() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = false;
+ appRow.blockedChannelCount = 30;
+ appRow.channelCount = 60;
+ assertThat(mController.getNotificationSummary(
+ appRow, mContext).toString().contains("30")).isTrue();
+ assertThat(mController.getNotificationSummary(
+ appRow, mContext).toString().contains("On")).isTrue();
+ }
+
+ @Test
+ public void getNotificationSummary_channelsNotBlocked() {
+ NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
+ appRow.banned = false;
+ appRow.blockedChannelCount = 0;
+ appRow.channelCount = 10;
+ assertThat(mController.getNotificationSummary(appRow, mContext).toString()).isEqualTo("On");
+ }
}