Loading src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java +14 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.Context; 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; Loading Loading @@ -77,7 +78,18 @@ public class AppNotificationPreferenceController extends AppInfoPreferenceContro public static CharSequence getNotificationSummary(NotificationBackend.AppRow appRow, Context context) { // TODO: implement summary when it is known what it should say 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)); } } } src/com/android/settings/notification/NotificationBackend.java +22 −12 Original line number Diff line number Diff line Loading @@ -60,6 +60,8 @@ public class NotificationBackend { 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; } Loading Loading @@ -178,18 +180,6 @@ public class NotificationBackend { } } 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); Loading Loading @@ -224,6 +214,15 @@ public class NotificationBackend { } } 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); Loading @@ -233,6 +232,15 @@ public class NotificationBackend { } } 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(); Loading @@ -259,5 +267,7 @@ public class NotificationBackend { public String lockedChannelId; public boolean showBadge; public int userId; public int blockedChannelCount; public int channelCount; } } tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java +45 −0 Original line number Diff line number Diff line Loading @@ -105,4 +105,49 @@ public class AppNotificationPreferenceControllerTest { 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"); } } Loading
src/com/android/settings/applications/appinfo/AppNotificationPreferenceController.java +14 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.content.Context; 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; Loading Loading @@ -77,7 +78,18 @@ public class AppNotificationPreferenceController extends AppInfoPreferenceContro public static CharSequence getNotificationSummary(NotificationBackend.AppRow appRow, Context context) { // TODO: implement summary when it is known what it should say 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)); } } }
src/com/android/settings/notification/NotificationBackend.java +22 −12 Original line number Diff line number Diff line Loading @@ -60,6 +60,8 @@ public class NotificationBackend { 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; } Loading Loading @@ -178,18 +180,6 @@ public class NotificationBackend { } } 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); Loading Loading @@ -224,6 +214,15 @@ public class NotificationBackend { } } 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); Loading @@ -233,6 +232,15 @@ public class NotificationBackend { } } 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(); Loading @@ -259,5 +267,7 @@ public class NotificationBackend { public String lockedChannelId; public boolean showBadge; public int userId; public int blockedChannelCount; public int channelCount; } }
tests/robotests/src/com/android/settings/applications/appinfo/AppNotificationPreferenceControllerTest.java +45 −0 Original line number Diff line number Diff line Loading @@ -105,4 +105,49 @@ public class AppNotificationPreferenceControllerTest { 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"); } }