Blocked packages can't create channels.

Test: runtest systemui-notification
Change-Id: I3f0560a71adc33d9881021f920ce2824b96ddc14
This commit is contained in:
Julia Reynolds
2016-11-28 10:47:18 -05:00
parent f57de46d0b
commit 32c97ef3c8
2 changed files with 20 additions and 0 deletions

View File

@@ -15,6 +15,8 @@
*/
package com.android.server.notification;
import static android.app.NotificationManager.IMPORTANCE_NONE;
import com.android.internal.R;
import android.app.Notification;
@@ -450,6 +452,9 @@ public class RankingHelper implements RankingConfig {
@Override
public void createNotificationChannel(String pkg, int uid, NotificationChannel channel) {
Record r = getOrCreateRecord(pkg, uid);
if (IMPORTANCE_NONE == r.importance) {
throw new IllegalArgumentException("Package blocked");
}
if (r.channels.containsKey(channel.getId()) || channel.getName().equals(
mContext.getString(R.string.default_notification_channel_label))) {
throw new IllegalArgumentException("Channel already exists");

View File

@@ -15,6 +15,8 @@
*/
package com.android.server.notification;
import static junit.framework.Assert.fail;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -347,6 +349,19 @@ public class RankingHelperTest {
assertEquals(NotificationChannel.USER_LOCKED_VISIBILITY, updated2.getUserLockedFields());
}
@Test
public void testCreateChannel_blocked() throws Exception {
mHelper.setImportance(pkg, uid, NotificationManager.IMPORTANCE_NONE);
try {
mHelper.createNotificationChannel(pkg, uid,
new NotificationChannel(pkg, "", NotificationManager.IMPORTANCE_LOW));
fail("Channel creation should fail");
} catch (IllegalArgumentException e) {
// pass
}
}
@Test
public void testUpdate_userLockedImportance() throws Exception {
// all fields locked by user