diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml
index f3ce40fb18165..a1bf3a24d12ef 100644
--- a/packages/SystemUI/res/values/strings.xml
+++ b/packages/SystemUI/res/values/strings.xml
@@ -1455,6 +1455,9 @@
Hints that the user's only option is to block all of the app's notifications. -->
This app doesn\'t have notification categories
+
+ Notifications from this app can\'t be turned off
+
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java
index 427708b02fbf1..1ffb3b5387a34 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java
@@ -154,9 +154,32 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
}
}
+ boolean nonBlockable = false;
+ try {
+ final PackageInfo pkgInfo = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
+ if (Utils.isSystemPackage(getResources(), pm, pkgInfo)) {
+ final int numChannels = mNotificationChannels.size();
+ for (int i = 0; i < numChannels; i++) {
+ final NotificationChannel notificationChannel = mNotificationChannels.get(i);
+ // If any of the system channels is not blockable, the bundle is nonblockable
+ if (!notificationChannel.isBlockableSystem()) {
+ nonBlockable = true;
+ break;
+ }
+ }
+ }
+ } catch (PackageManager.NameNotFoundException e) {
+ // unlikely.
+ }
+ if (nonBlockablePkgs != null) {
+ nonBlockable |= nonBlockablePkgs.contains(pkg);
+ }
+
String channelsDescText;
mNumChannelsView = findViewById(R.id.num_channels_desc);
- if (mIsSingleDefaultChannel) {
+ if (nonBlockable) {
+ channelsDescText = mContext.getString(R.string.notification_unblockable_desc);
+ } else if (mIsSingleDefaultChannel) {
channelsDescText = mContext.getString(R.string.notification_default_channel_desc);
} else {
switch (mNotificationChannels.size()) {
@@ -188,8 +211,9 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
// Multiple channels don't use a channel name for the title.
channelNameText = mContext.getString(R.string.notification_num_channels,
mNotificationChannels.size());
- } else if (mIsSingleDefaultChannel) {
- // If this is the default channel, don't use our channel-specific text.
+ } else if (mIsSingleDefaultChannel || nonBlockable) {
+ // If this is the default channel or the app is unblockable,
+ // don't use our channel-specific text.
channelNameText = mContext.getString(R.string.notification_header_default_channel);
} else {
channelNameText = mSingleNotificationChannel.getName();
@@ -218,19 +242,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
groupDividerView.setVisibility(View.GONE);
}
- boolean nonBlockable = false;
- try {
- final PackageInfo pkgInfo = pm.getPackageInfo(pkg, PackageManager.GET_SIGNATURES);
- nonBlockable = Utils.isSystemPackage(getResources(), pm, pkgInfo)
- && (mSingleNotificationChannel == null
- || !mSingleNotificationChannel.isBlockableSystem());
- } catch (PackageManager.NameNotFoundException e) {
- // unlikely.
- }
- if (nonBlockablePkgs != null) {
- nonBlockable |= nonBlockablePkgs.contains(pkg);
- }
-
bindButtons(nonBlockable);
// Top-level importance group
@@ -246,12 +257,11 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
(View view) -> {
onSettingsClick.onClick(view, mSingleNotificationChannel, appUidF);
});
- if (numTotalChannels > 1) {
- settingsButton.setText(R.string.notification_all_categories);
- } else {
+ if (numTotalChannels <= 1 || nonBlockable) {
settingsButton.setText(R.string.notification_more_settings);
+ } else {
+ settingsButton.setText(R.string.notification_all_categories);
}
-
} else {
settingsButton.setVisibility(View.GONE);
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java
index 638084763ea88..b6827eaa13bbc 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java
@@ -231,6 +231,17 @@ public class NotificationInfoTest extends SysuiTestCase {
textView.getText());
}
+ @Test
+ public void testBindNotification_UnblockablePackageDoesNotUseChannelName() throws Exception {
+ mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
+ TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
+ mNotificationChannel.getImportance(), mSbn, null, null, null,
+ null, Collections.singleton(TEST_PACKAGE_NAME));
+ final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name);
+ assertEquals(mContext.getString(R.string.notification_header_default_channel),
+ textView.getText());
+ }
+
@Test
public void testBindNotification_DefaultChannelUsesNameWhenMoreThanOneChannelExists()
throws Exception {
@@ -331,6 +342,21 @@ public class NotificationInfoTest extends SysuiTestCase {
assertEquals(getStringById(R.string.notification_all_categories), settingsButton.getText());
}
+ @Test
+ public void testBindNotification_SettingsTextWithMultipleChannelsForUnblockableApp()
+ throws Exception {
+ when(mMockINotificationManager.getNumNotificationChannelsForPackage(
+ eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2);
+ mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
+ TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
+ mNotificationChannel.getImportance(), mSbn,
+ (View v, NotificationChannel c, int appUid) -> {
+ }, null, null, null, Collections.singleton(TEST_PACKAGE_NAME));
+ final TextView settingsButton =
+ (TextView) mNotificationInfo.findViewById(R.id.more_settings);
+ assertEquals(getStringById(R.string.notification_more_settings), settingsButton.getText());
+ }
+
@Test
public void testBindNotification_SetsOnClickListenerForDone() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
@@ -501,6 +527,19 @@ public class NotificationInfoTest extends SysuiTestCase {
assertEquals(numChannelsView.getVisibility(), View.GONE);
}
+ @Test
+ public void testbindNotification_UnblockableTextVisibleWhenAppUnblockable() throws Exception {
+ mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
+ TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
+ mNotificationChannel.getImportance(), mSbn, null, null, null,
+ null, Collections.singleton(TEST_PACKAGE_NAME));
+ final TextView numChannelsView =
+ (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
+ assertEquals(View.VISIBLE, numChannelsView.getVisibility());
+ assertEquals(mContext.getString(R.string.notification_unblockable_desc),
+ numChannelsView.getText());
+ }
+
@Test
@UiThreadTest
public void testBindNotification_ChannelDisabledTextShowsForDefaultChannel()