Add condition to ignore invalid packages in NotificationChannelSlice
If all displayable notification channels of package are turned off, stop showing notification channel slice of package. Bug: 124480122 Test: robotests Change-Id: I3ce9ebc4cca18dac3b4b6f15c28c697b72df81e3
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.homepage.contextualcards.slices;
|
||||
|
||||
import static android.app.NotificationManager.IMPORTANCE_LOW;
|
||||
import static android.app.NotificationManager.IMPORTANCE_NONE;
|
||||
import static android.app.slice.Slice.HINT_LIST_ITEM;
|
||||
import static android.app.slice.SliceItem.FORMAT_SLICE;
|
||||
@@ -116,7 +117,8 @@ public class NotificationChannelSliceTest {
|
||||
public void getSlice_hasSuggestedApp_shouldHaveNotificationChannelTitle() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -130,7 +132,8 @@ public class NotificationChannelSliceTest {
|
||||
public void getSlice_hasSuggestedApp_shouldSortByNotificationSentCount() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -157,7 +160,8 @@ public class NotificationChannelSliceTest {
|
||||
public void getSlice_noRecentlyInstalledApp_shouldHaveNoSuggestedAppTitle() {
|
||||
addMockPackageToPackageManager(false /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -169,7 +173,8 @@ public class NotificationChannelSliceTest {
|
||||
public void getSlice_noMultiChannelApp_shouldHaveNoSuggestedAppTitle() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(1 /* channelCount */, NOTIFICATION_COUNT, false /* banned */);
|
||||
mockNotificationBackend(1 /* channelCount */, NOTIFICATION_COUNT, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -178,10 +183,12 @@ public class NotificationChannelSliceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
|
||||
public void getSlice_insufficientNotificationSentCount_shouldHaveNoSuggestedAppTitle() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT, 1 /* notificationCount */, false /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT, 1 /* notificationCount */, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -192,7 +199,8 @@ public class NotificationChannelSliceTest {
|
||||
@Test
|
||||
public void getSlice_isSystemApp_shouldHaveNoSuggestedAppTitle() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */, ApplicationInfo.FLAG_SYSTEM);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -204,7 +212,8 @@ public class NotificationChannelSliceTest {
|
||||
public void getSlice_isNotificationBanned_shouldHaveNoSuggestedAppTitle() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, true /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, true /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -218,7 +227,7 @@ public class NotificationChannelSliceTest {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(NotificationChannelSlice.DEFAULT_EXPANDED_ROW_COUNT * 2,
|
||||
NOTIFICATION_COUNT, false /* banned */);
|
||||
NOTIFICATION_COUNT, false /* banned */, false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -234,7 +243,8 @@ public class NotificationChannelSliceTest {
|
||||
public void getSlice_channelCountIsLessThanDefaultRows_subTitleShouldNotHaveTapToManagerAll() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT - 1, NOTIFICATION_COUNT, false /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT - 1, NOTIFICATION_COUNT, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -249,7 +259,8 @@ public class NotificationChannelSliceTest {
|
||||
public void getSlice_channelCountIsEqualToDefaultRows_subTitleShouldNotHaveTapToManagerAll() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -263,7 +274,8 @@ public class NotificationChannelSliceTest {
|
||||
public void getSlice_channelCountIsMoreThanDefaultRows_subTitleShouldHaveTapToManagerAll() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT + 1, NOTIFICATION_COUNT, false /* banned */);
|
||||
mockNotificationBackend(CHANNEL_COUNT + 1, NOTIFICATION_COUNT, false /* banned */,
|
||||
false /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
@@ -273,6 +285,20 @@ public class NotificationChannelSliceTest {
|
||||
CHANNEL_COUNT + 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
|
||||
public void getSlice_isAllDisplayableChannelBlocked_shouldHaveNoSuggestedAppTitle() {
|
||||
addMockPackageToPackageManager(true /* isRecentlyInstalled */,
|
||||
ApplicationInfo.FLAG_INSTALLED);
|
||||
mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false /* banned */,
|
||||
true /* isChannelBlocked */);
|
||||
|
||||
final Slice slice = mNotificationChannelSlice.getSlice();
|
||||
|
||||
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
|
||||
assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.no_suggested_app));
|
||||
}
|
||||
|
||||
private void addMockPackageToPackageManager(boolean isRecentlyInstalled, int flags) {
|
||||
final ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
applicationInfo.name = APP_LABEL;
|
||||
@@ -294,8 +320,10 @@ public class NotificationChannelSliceTest {
|
||||
return System.currentTimeMillis();
|
||||
}
|
||||
|
||||
private void mockNotificationBackend(int channelCount, int notificationCount, boolean banned) {
|
||||
final List<NotificationChannel> channels = buildNotificationChannel(channelCount);
|
||||
private void mockNotificationBackend(int channelCount, int notificationCount, boolean banned,
|
||||
boolean isChannelBlocked) {
|
||||
final List<NotificationChannel> channels = buildNotificationChannel(channelCount,
|
||||
isChannelBlocked);
|
||||
final AppRow appRow = buildAppRow(channelCount, notificationCount, banned);
|
||||
|
||||
doReturn(buildNotificationChannelGroups(channels)).when(mNotificationBackend).getGroups(
|
||||
@@ -308,6 +336,8 @@ public class NotificationChannelSliceTest {
|
||||
|
||||
private AppRow buildAppRow(int channelCount, int sentCount, boolean banned) {
|
||||
final AppRow appRow = new AppRow();
|
||||
appRow.pkg = PACKAGE_NAME;
|
||||
appRow.uid = UID;
|
||||
appRow.banned = banned;
|
||||
appRow.channelCount = channelCount;
|
||||
appRow.sentByApp = new NotificationsSentState();
|
||||
@@ -317,11 +347,12 @@ public class NotificationChannelSliceTest {
|
||||
return appRow;
|
||||
}
|
||||
|
||||
private List<NotificationChannel> buildNotificationChannel(int channelCount) {
|
||||
private List<NotificationChannel> buildNotificationChannel(int channelCount,
|
||||
boolean isChannelBlock) {
|
||||
final List<NotificationChannel> channels = new ArrayList<>();
|
||||
for (int i = 0; i < channelCount; i++) {
|
||||
channels.add(new NotificationChannel(CHANNEL_NAME_PREFIX + i, CHANNEL_NAME_PREFIX + i,
|
||||
IMPORTANCE_NONE));
|
||||
isChannelBlock ? IMPORTANCE_NONE : IMPORTANCE_LOW));
|
||||
}
|
||||
|
||||
return channels;
|
||||
@@ -369,4 +400,4 @@ public class NotificationChannelSliceTest {
|
||||
// Index 0: title; Index 1: summary.
|
||||
return rowSliceItems.get(1).getText();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user