Merge "Pre-O apps can see Default Channel name." into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
e7fb3c9f26
@@ -62,6 +62,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
|
|||||||
private int mAppUid;
|
private int mAppUid;
|
||||||
private List<NotificationChannel> mNotificationChannels;
|
private List<NotificationChannel> mNotificationChannels;
|
||||||
private NotificationChannel mSingleNotificationChannel;
|
private NotificationChannel mSingleNotificationChannel;
|
||||||
|
private boolean mIsSingleDefaultChannel;
|
||||||
private StatusBarNotification mSbn;
|
private StatusBarNotification mSbn;
|
||||||
private int mStartingUserImportance;
|
private int mStartingUserImportance;
|
||||||
|
|
||||||
@@ -113,17 +114,23 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
|
|||||||
mSbn = sbn;
|
mSbn = sbn;
|
||||||
mPm = pm;
|
mPm = pm;
|
||||||
mAppSettingsClickListener = onAppSettingsClick;
|
mAppSettingsClickListener = onAppSettingsClick;
|
||||||
boolean isSingleDefaultChannel = false;
|
|
||||||
mStartingUserImportance = startingUserImportance;
|
mStartingUserImportance = startingUserImportance;
|
||||||
|
int numTotalChannels = 1;
|
||||||
|
numTotalChannels = iNotificationManager.getNumNotificationChannelsForPackage(
|
||||||
|
pkg, mAppUid, false /* includeDeleted */);
|
||||||
if (mNotificationChannels.isEmpty()) {
|
if (mNotificationChannels.isEmpty()) {
|
||||||
throw new IllegalArgumentException("bindNotification requires at least one channel");
|
throw new IllegalArgumentException("bindNotification requires at least one channel");
|
||||||
} else {
|
} else {
|
||||||
if (mNotificationChannels.size() == 1) {
|
if (mNotificationChannels.size() == 1) {
|
||||||
mSingleNotificationChannel = mNotificationChannels.get(0);
|
mSingleNotificationChannel = mNotificationChannels.get(0);
|
||||||
isSingleDefaultChannel = mSingleNotificationChannel.getId()
|
// Special behavior for the Default channel if no other channels have been defined.
|
||||||
.equals(NotificationChannel.DEFAULT_CHANNEL_ID);
|
mIsSingleDefaultChannel =
|
||||||
|
(mSingleNotificationChannel.getId()
|
||||||
|
.equals(NotificationChannel.DEFAULT_CHANNEL_ID) &&
|
||||||
|
numTotalChannels <= 1);
|
||||||
} else {
|
} else {
|
||||||
mSingleNotificationChannel = null;
|
mSingleNotificationChannel = null;
|
||||||
|
mIsSingleDefaultChannel = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,19 +155,16 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
|
|||||||
}
|
}
|
||||||
((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon);
|
((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon);
|
||||||
|
|
||||||
int numChannels = 1;
|
|
||||||
numChannels = iNotificationManager.getNumNotificationChannelsForPackage(
|
|
||||||
pkg, mAppUid, false /* includeDeleted */);
|
|
||||||
|
|
||||||
String channelsDescText;
|
String channelsDescText;
|
||||||
mNumChannelsView = findViewById(R.id.num_channels_desc);
|
mNumChannelsView = findViewById(R.id.num_channels_desc);
|
||||||
if (isSingleDefaultChannel) {
|
if (mIsSingleDefaultChannel) {
|
||||||
channelsDescText = mContext.getString(R.string.notification_default_channel_desc);
|
channelsDescText = mContext.getString(R.string.notification_default_channel_desc);
|
||||||
} else {
|
} else {
|
||||||
switch (mNotificationChannels.size()) {
|
switch (mNotificationChannels.size()) {
|
||||||
case 1:
|
case 1:
|
||||||
channelsDescText = String.format(mContext.getResources().getQuantityString(
|
channelsDescText = String.format(mContext.getResources().getQuantityString(
|
||||||
R.plurals.notification_num_channels_desc, numChannels), numChannels);
|
R.plurals.notification_num_channels_desc, numTotalChannels),
|
||||||
|
numTotalChannels);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
channelsDescText = mContext.getString(
|
channelsDescText = mContext.getString(
|
||||||
@@ -185,7 +189,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
|
|||||||
// Multiple channels don't use a channel name for the title.
|
// Multiple channels don't use a channel name for the title.
|
||||||
channelNameText = mContext.getString(R.string.notification_num_channels,
|
channelNameText = mContext.getString(R.string.notification_num_channels,
|
||||||
mNotificationChannels.size());
|
mNotificationChannels.size());
|
||||||
} else if (isSingleDefaultChannel) {
|
} else if (mIsSingleDefaultChannel) {
|
||||||
// If this is the default channel, don't use our channel-specific text.
|
// If this is the default channel, don't use our channel-specific text.
|
||||||
channelNameText = mContext.getString(R.string.notification_header_default_channel);
|
channelNameText = mContext.getString(R.string.notification_header_default_channel);
|
||||||
} else {
|
} else {
|
||||||
@@ -241,7 +245,7 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
|
|||||||
(View view) -> {
|
(View view) -> {
|
||||||
onSettingsClick.onClick(view, mSingleNotificationChannel, appUidF);
|
onSettingsClick.onClick(view, mSingleNotificationChannel, appUidF);
|
||||||
});
|
});
|
||||||
if (numChannels > 1) {
|
if (numTotalChannels > 1) {
|
||||||
settingsButton.setText(R.string.notification_all_categories);
|
settingsButton.setText(R.string.notification_all_categories);
|
||||||
} else {
|
} else {
|
||||||
settingsButton.setText(R.string.notification_more_settings);
|
settingsButton.setText(R.string.notification_more_settings);
|
||||||
@@ -327,14 +331,12 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
|
|||||||
private void updateSecondaryText() {
|
private void updateSecondaryText() {
|
||||||
final boolean disabled = mSingleNotificationChannel != null &&
|
final boolean disabled = mSingleNotificationChannel != null &&
|
||||||
getSelectedImportance() == IMPORTANCE_NONE;
|
getSelectedImportance() == IMPORTANCE_NONE;
|
||||||
final boolean isDefaultChannel = mSingleNotificationChannel != null &&
|
|
||||||
mSingleNotificationChannel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID);
|
|
||||||
if (disabled) {
|
if (disabled) {
|
||||||
mChannelDisabledView.setVisibility(View.VISIBLE);
|
mChannelDisabledView.setVisibility(View.VISIBLE);
|
||||||
mNumChannelsView.setVisibility(View.GONE);
|
mNumChannelsView.setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
mChannelDisabledView.setVisibility(View.GONE);
|
mChannelDisabledView.setVisibility(View.GONE);
|
||||||
mNumChannelsView.setVisibility(isDefaultChannel ? View.INVISIBLE : View.VISIBLE);
|
mNumChannelsView.setVisibility(mIsSingleDefaultChannel ? View.INVISIBLE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -209,6 +209,30 @@ public class NotificationInfoTest extends SysuiTestCase {
|
|||||||
assertEquals(TEST_CHANNEL_NAME, textView.getText());
|
assertEquals(TEST_CHANNEL_NAME, textView.getText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBindNotification_DefaultChannelDoesNotUseChannelName() throws Exception {
|
||||||
|
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||||
|
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
|
||||||
|
mNotificationChannel.getImportance(), mSbn, null, null, null,
|
||||||
|
null, null);
|
||||||
|
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 {
|
||||||
|
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||||
|
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
|
||||||
|
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||||
|
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
|
||||||
|
mNotificationChannel.getImportance(), mSbn, null, null, null,
|
||||||
|
null, null);
|
||||||
|
final TextView textView = (TextView) mNotificationInfo.findViewById(R.id.channel_name);
|
||||||
|
assertEquals(mDefaultNotificationChannel.getName(), textView.getText());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
|
public void testBindNotification_SetsOnClickListenerForSettings() throws Exception {
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
@@ -324,6 +348,21 @@ public class NotificationInfoTest extends SysuiTestCase {
|
|||||||
assertEquals(View.INVISIBLE, numChannelsView.getVisibility());
|
assertEquals(View.INVISIBLE, numChannelsView.getVisibility());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBindNotification_NumChannelsTextDisplaysWhenMoreThanOneChannelExists()
|
||||||
|
throws Exception {
|
||||||
|
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||||
|
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
|
||||||
|
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||||
|
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
|
||||||
|
mNotificationChannel.getImportance(), mSbn, null, null,
|
||||||
|
null, null, null);
|
||||||
|
final TextView numChannelsView =
|
||||||
|
(TextView) mNotificationInfo.findViewById(R.id.num_channels_desc);
|
||||||
|
assertEquals(numChannelsView.getVisibility(), View.VISIBLE);
|
||||||
|
assertEquals(getNumChannelsDescString(2), numChannelsView.getText());
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBindNotification_NumChannelsTextDisplaysWhenNotDefaultChannel()
|
public void testBindNotification_NumChannelsTextDisplaysWhenNotDefaultChannel()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user