Merge "Fix number of channels in inline notification settings" into oc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1ab1da3f25
@@ -115,25 +115,6 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
|
||||
mPm = pm;
|
||||
mAppSettingsClickListener = onAppSettingsClick;
|
||||
mStartingUserImportance = startingUserImportance;
|
||||
int numTotalChannels = 1;
|
||||
numTotalChannels = iNotificationManager.getNumNotificationChannelsForPackage(
|
||||
pkg, mAppUid, false /* includeDeleted */);
|
||||
if (mNotificationChannels.isEmpty()) {
|
||||
throw new IllegalArgumentException("bindNotification requires at least one channel");
|
||||
} else {
|
||||
if (mNotificationChannels.size() == 1) {
|
||||
mSingleNotificationChannel = mNotificationChannels.get(0);
|
||||
// Special behavior for the Default channel if no other channels have been defined.
|
||||
mIsSingleDefaultChannel =
|
||||
(mSingleNotificationChannel.getId()
|
||||
.equals(NotificationChannel.DEFAULT_CHANNEL_ID) &&
|
||||
numTotalChannels <= 1);
|
||||
} else {
|
||||
mSingleNotificationChannel = null;
|
||||
mIsSingleDefaultChannel = false;
|
||||
}
|
||||
}
|
||||
|
||||
mAppName = mPkg;
|
||||
Drawable pkgicon = null;
|
||||
CharSequence channelNameText = "";
|
||||
@@ -155,6 +136,24 @@ public class NotificationInfo extends LinearLayout implements NotificationGuts.G
|
||||
}
|
||||
((ImageView) findViewById(R.id.pkgicon)).setImageDrawable(pkgicon);
|
||||
|
||||
int numTotalChannels = iNotificationManager.getNumNotificationChannelsForPackage(
|
||||
pkg, mAppUid, false /* includeDeleted */);
|
||||
if (mNotificationChannels.isEmpty()) {
|
||||
throw new IllegalArgumentException("bindNotification requires at least one channel");
|
||||
} else {
|
||||
if (mNotificationChannels.size() == 1) {
|
||||
mSingleNotificationChannel = mNotificationChannels.get(0);
|
||||
// Special behavior for the Default channel if no other channels have been defined.
|
||||
mIsSingleDefaultChannel =
|
||||
(mSingleNotificationChannel.getId()
|
||||
.equals(NotificationChannel.DEFAULT_CHANNEL_ID) &&
|
||||
numTotalChannels <= 1);
|
||||
} else {
|
||||
mSingleNotificationChannel = null;
|
||||
mIsSingleDefaultChannel = false;
|
||||
}
|
||||
}
|
||||
|
||||
String channelsDescText;
|
||||
mNumChannelsView = findViewById(R.id.num_channels_desc);
|
||||
if (mIsSingleDefaultChannel) {
|
||||
|
||||
@@ -74,6 +74,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
@UiThreadTest
|
||||
public class NotificationInfoTest extends SysuiTestCase {
|
||||
private static final String TEST_PACKAGE_NAME = "test_package";
|
||||
private static final int TEST_UID = 1;
|
||||
private static final String TEST_CHANNEL = "test_channel";
|
||||
private static final String TEST_CHANNEL_NAME = "TEST CHANNEL NAME";
|
||||
|
||||
@@ -96,13 +97,13 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
packageInfo.packageName = TEST_PACKAGE_NAME;
|
||||
when(mMockPackageManager.getPackageInfo(anyString(), anyInt())).thenReturn(packageInfo);
|
||||
final ApplicationInfo applicationInfo = new ApplicationInfo();
|
||||
applicationInfo.uid = 1; // non-zero
|
||||
applicationInfo.uid = TEST_UID; // non-zero
|
||||
when(mMockPackageManager.getApplicationInfo(anyString(), anyInt())).thenReturn(
|
||||
applicationInfo);
|
||||
|
||||
// Package has one channel by default.
|
||||
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(1);
|
||||
eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(1);
|
||||
|
||||
// Some test channels.
|
||||
mNotificationChannel = new NotificationChannel(
|
||||
@@ -185,7 +186,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
final NotificationChannelGroup notificationChannelGroup =
|
||||
new NotificationChannelGroup("test_group_id", "Test Group Name");
|
||||
when(mMockINotificationManager.getNotificationChannelGroupForPackage(
|
||||
eq("test_group_id"), eq(TEST_PACKAGE_NAME), anyInt()))
|
||||
eq("test_group_id"), eq(TEST_PACKAGE_NAME), eq(TEST_UID)))
|
||||
.thenReturn(notificationChannelGroup);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
|
||||
@@ -224,7 +225,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testBindNotification_DefaultChannelUsesNameWhenMoreThanOneChannelExists()
|
||||
throws Exception {
|
||||
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
|
||||
eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
|
||||
mNotificationChannel.getImportance(), mSbn, null, null, null,
|
||||
@@ -309,7 +310,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testBindNotification_SettingsTextWithMultipleChannels() throws Exception {
|
||||
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
|
||||
eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
|
||||
mNotificationChannel.getImportance(), mSbn,
|
||||
@@ -352,7 +353,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testBindNotification_NumChannelsTextDisplaysWhenMoreThanOneChannelExists()
|
||||
throws Exception {
|
||||
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
|
||||
eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel),
|
||||
mNotificationChannel.getImportance(), mSbn, null, null,
|
||||
@@ -380,7 +381,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
public void testBindNotification_NumChannelsTextScalesWithNumberOfChannels()
|
||||
throws Exception {
|
||||
when(mMockINotificationManager.getNumNotificationChannelsForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), anyBoolean())).thenReturn(2);
|
||||
eq(TEST_PACKAGE_NAME), eq(TEST_UID), anyBoolean())).thenReturn(2);
|
||||
mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager,
|
||||
TEST_PACKAGE_NAME, Arrays.asList(mNotificationChannel),
|
||||
mNotificationChannel.getImportance(), mSbn, null, null, null,
|
||||
@@ -511,7 +512,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
mNotificationChannel.getImportance(), mSbn, null, null, null,
|
||||
null, null);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
anyString(), anyInt(), any());
|
||||
anyString(), eq(TEST_UID), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -525,7 +526,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
Switch enabledSwitch = (Switch) mNotificationInfo.findViewById(R.id.channel_enabled_switch);
|
||||
enabledSwitch.setChecked(false);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
anyString(), anyInt(), any());
|
||||
anyString(), eq(TEST_UID), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -538,7 +539,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
|
||||
mNotificationInfo.handleCloseControls(true, false);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
anyString(), anyInt(), any());
|
||||
anyString(), eq(TEST_UID), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -552,7 +553,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
|
||||
mNotificationInfo.handleCloseControls(true, false);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
anyString(), anyInt(), any());
|
||||
anyString(), eq(TEST_UID), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -612,7 +613,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
null, Collections.singleton(TEST_PACKAGE_NAME));
|
||||
mNotificationInfo.handleCloseControls(true, false);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
anyString(), anyInt(), any());
|
||||
anyString(), eq(TEST_UID), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -630,7 +631,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
ArgumentCaptor<NotificationChannel> updated =
|
||||
ArgumentCaptor.forClass(NotificationChannel.class);
|
||||
verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
|
||||
anyString(), anyInt(), updated.capture());
|
||||
anyString(), eq(TEST_UID), updated.capture());
|
||||
assertTrue((updated.getValue().getUserLockedFields()
|
||||
& NotificationChannel.USER_LOCKED_IMPORTANCE) != 0);
|
||||
}
|
||||
@@ -647,7 +648,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
enabledSwitch.setChecked(false);
|
||||
mNotificationInfo.handleCloseControls(false, false);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel));
|
||||
eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -664,7 +665,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
enabledSwitch.setChecked(false);
|
||||
mNotificationInfo.handleCloseControls(true, false);
|
||||
verify(mMockINotificationManager, never()).updateNotificationChannelForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel));
|
||||
eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -682,7 +683,7 @@ public class NotificationInfoTest extends SysuiTestCase {
|
||||
enabledSwitch.setChecked(false);
|
||||
mNotificationInfo.handleCloseControls(true, false);
|
||||
verify(mMockINotificationManager, times(1)).updateNotificationChannelForPackage(
|
||||
eq(TEST_PACKAGE_NAME), anyInt(), eq(mNotificationChannel));
|
||||
eq(TEST_PACKAGE_NAME), eq(TEST_UID), eq(mNotificationChannel));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user