From 6f2450636a9d660f0d0f41701724611a5f4d2fe0 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Thu, 29 Mar 2018 15:54:16 -0400 Subject: [PATCH] Fix 'show badge' for pre O apps Test: make -j RunSettingsRoboTests Change-Id: I20f6b38986afde0ca781329ffc24326601650a1f Fixes: 69437269 --- .../notification/BadgePreferenceController.java | 9 +++++-- .../BadgePreferenceControllerTest.java | 29 ++++++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/notification/BadgePreferenceController.java b/src/com/android/settings/notification/BadgePreferenceController.java index 6b72c50bb7..8f0376c062 100644 --- a/src/com/android/settings/notification/BadgePreferenceController.java +++ b/src/com/android/settings/notification/BadgePreferenceController.java @@ -18,6 +18,7 @@ package com.android.settings.notification; import static android.provider.Settings.Secure.NOTIFICATION_BADGING; +import android.app.NotificationChannel; import android.content.Context; import android.provider.Settings; import android.support.v7.preference.Preference; @@ -55,8 +56,12 @@ public class BadgePreferenceController extends NotificationPreferenceController NOTIFICATION_BADGING, SYSTEM_WIDE_ON) == SYSTEM_WIDE_OFF) { return false; } - if (mChannel != null && !mAppRow.showBadge) { - return false; + if (mChannel != null) { + if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) { + return true; + } else { + return mAppRow.showBadge; + } } return true; } diff --git a/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java index c216875a0d..ad012505ed 100644 --- a/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/BadgePreferenceControllerTest.java @@ -134,6 +134,19 @@ public class BadgePreferenceControllerTest { } @Test + public void testIsAvailable_defaultChannel() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.showBadge = true; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); + when(channel.getId()).thenReturn(DEFAULT_CHANNEL_ID); + mController.onResume(appRow, channel, null, null); + Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1); + + assertTrue(mController.isAvailable()); + } + + @Test public void testIsAvailable_channel() { NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); appRow.showBadge = true; @@ -146,11 +159,23 @@ public class BadgePreferenceControllerTest { } @Test + public void testIsAvailable_channelAppOff() { + NotificationBackend.AppRow appRow = new NotificationBackend.AppRow(); + appRow.showBadge = false; + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getImportance()).thenReturn(IMPORTANCE_HIGH); + mController.onResume(appRow, channel, null, null); + Settings.Secure.putInt(mContext.getContentResolver(), NOTIFICATION_BADGING, 1); + + assertFalse(mController.isAvailable()); + } + + @Test public void testUpdateState_disabledByAdmin() { NotificationChannel channel = mock(NotificationChannel.class); when(channel.getId()).thenReturn("something"); - mController.onResume( - new NotificationBackend.AppRow(), channel, null, mock(RestrictedLockUtils.EnforcedAdmin.class)); + mController.onResume(new NotificationBackend.AppRow(), channel, null, + mock(RestrictedLockUtils.EnforcedAdmin.class)); Preference pref = new RestrictedSwitchPreference(mContext); mController.updateState(pref); -- 2.11.0