Merge "Fix 'show badge' for pre O apps" into pi-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d31c655a12
@@ -18,6 +18,7 @@ package com.android.settings.notification;
|
|||||||
|
|
||||||
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
|
import static android.provider.Settings.Secure.NOTIFICATION_BADGING;
|
||||||
|
|
||||||
|
import android.app.NotificationChannel;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
@@ -55,8 +56,12 @@ public class BadgePreferenceController extends NotificationPreferenceController
|
|||||||
NOTIFICATION_BADGING, SYSTEM_WIDE_ON) == SYSTEM_WIDE_OFF) {
|
NOTIFICATION_BADGING, SYSTEM_WIDE_ON) == SYSTEM_WIDE_OFF) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (mChannel != null && !mAppRow.showBadge) {
|
if (mChannel != null) {
|
||||||
return false;
|
if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return mAppRow.showBadge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -133,6 +133,19 @@ public class BadgePreferenceControllerTest {
|
|||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testIsAvailable_channel() {
|
public void testIsAvailable_channel() {
|
||||||
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
NotificationBackend.AppRow appRow = new NotificationBackend.AppRow();
|
||||||
@@ -145,12 +158,24 @@ public class BadgePreferenceControllerTest {
|
|||||||
assertTrue(mController.isAvailable());
|
assertTrue(mController.isAvailable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
@Test
|
||||||
public void testUpdateState_disabledByAdmin() {
|
public void testUpdateState_disabledByAdmin() {
|
||||||
NotificationChannel channel = mock(NotificationChannel.class);
|
NotificationChannel channel = mock(NotificationChannel.class);
|
||||||
when(channel.getId()).thenReturn("something");
|
when(channel.getId()).thenReturn("something");
|
||||||
mController.onResume(
|
mController.onResume(new NotificationBackend.AppRow(), channel, null,
|
||||||
new NotificationBackend.AppRow(), channel, null, mock(RestrictedLockUtils.EnforcedAdmin.class));
|
mock(RestrictedLockUtils.EnforcedAdmin.class));
|
||||||
|
|
||||||
Preference pref = new RestrictedSwitchPreference(mContext);
|
Preference pref = new RestrictedSwitchPreference(mContext);
|
||||||
mController.updateState(pref);
|
mController.updateState(pref);
|
||||||
|
Reference in New Issue
Block a user