Merge "Set correct uid for headless system 0 in DnD PreferencesHelperTest" into sc-dev am: 173286e254

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15081240

Change-Id: I4c0396301d23eba243a3c91177710f6070b91304
This commit is contained in:
TreeHugger Robot
2021-06-24 21:32:22 +00:00
committed by Automerger Merge Worker

View File

@@ -90,7 +90,7 @@ import android.os.Bundle;
import android.os.RemoteCallback;
import android.os.RemoteException;
import android.os.UserHandle;
import android.provider.Settings;
import android.os.UserManager;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
import android.service.notification.ConversationChannelWrapper;
@@ -137,6 +137,7 @@ import java.util.concurrent.ThreadLocalRandom;
@RunWith(AndroidJUnit4.class)
public class PreferencesHelperTest extends UiServiceTestCase {
private static final int UID_N_MR1 = 0;
private static final int UID_HEADLESS = 1000000;
private static final UserHandle USER = UserHandle.of(0);
private static final int UID_O = 1111;
private static final int UID_P = 2222;
@@ -1495,11 +1496,13 @@ public class PreferencesHelperTest extends UiServiceTestCase {
@Test
public void testCreateAndDeleteCanChannelsBypassDnd() throws Exception {
int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1;
// create notification channel that can't bypass dnd
// expected result: areChannelsBypassingDnd = false
// setNotificationPolicy isn't called since areChannelsBypassingDnd was already false
NotificationChannel channel = new NotificationChannel("id1", "name1", IMPORTANCE_LOW);
mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel, true, false);
mHelper.createNotificationChannel(PKG_N_MR1, uid, channel, true, false);
assertFalse(mHelper.areChannelsBypassingDnd());
verify(mMockZenModeHelper, never()).setNotificationPolicy(any());
resetZenModeHelper();
@@ -1508,18 +1511,18 @@ public class PreferencesHelperTest extends UiServiceTestCase {
// expected result: areChannelsBypassingDnd = true
NotificationChannel channel2 = new NotificationChannel("id2", "name2", IMPORTANCE_LOW);
channel2.setBypassDnd(true);
mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel2, true, true);
mHelper.createNotificationChannel(PKG_N_MR1, uid, channel2, true, true);
assertTrue(mHelper.areChannelsBypassingDnd());
verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any());
resetZenModeHelper();
// delete channels
mHelper.deleteNotificationChannel(PKG_N_MR1, UID_N_MR1, channel.getId());
mHelper.deleteNotificationChannel(PKG_N_MR1, uid, channel.getId());
assertTrue(mHelper.areChannelsBypassingDnd()); // channel2 can still bypass DND
verify(mMockZenModeHelper, never()).setNotificationPolicy(any());
resetZenModeHelper();
mHelper.deleteNotificationChannel(PKG_N_MR1, UID_N_MR1, channel2.getId());
mHelper.deleteNotificationChannel(PKG_N_MR1, uid, channel2.getId());
assertFalse(mHelper.areChannelsBypassingDnd());
verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any());
resetZenModeHelper();
@@ -1527,11 +1530,13 @@ public class PreferencesHelperTest extends UiServiceTestCase {
@Test
public void testUpdateCanChannelsBypassDnd() throws Exception {
int uid = UserManager.isHeadlessSystemUserMode() ? UID_HEADLESS : UID_N_MR1;
// create notification channel that can't bypass dnd
// expected result: areChannelsBypassingDnd = false
// setNotificationPolicy isn't called since areChannelsBypassingDnd was already false
NotificationChannel channel = new NotificationChannel("id1", "name1", IMPORTANCE_LOW);
mHelper.createNotificationChannel(PKG_N_MR1, UID_N_MR1, channel, true, false);
mHelper.createNotificationChannel(PKG_N_MR1, uid, channel, true, false);
assertFalse(mHelper.areChannelsBypassingDnd());
verify(mMockZenModeHelper, never()).setNotificationPolicy(any());
resetZenModeHelper();
@@ -1539,7 +1544,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
// update channel so it CAN bypass dnd:
// expected result: areChannelsBypassingDnd = true
channel.setBypassDnd(true);
mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, channel, true);
mHelper.updateNotificationChannel(PKG_N_MR1, uid, channel, true);
assertTrue(mHelper.areChannelsBypassingDnd());
verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any());
resetZenModeHelper();
@@ -1547,7 +1552,7 @@ public class PreferencesHelperTest extends UiServiceTestCase {
// update channel so it can't bypass dnd:
// expected result: areChannelsBypassingDnd = false
channel.setBypassDnd(false);
mHelper.updateNotificationChannel(PKG_N_MR1, UID_N_MR1, channel, true);
mHelper.updateNotificationChannel(PKG_N_MR1, uid, channel, true);
assertFalse(mHelper.areChannelsBypassingDnd());
verify(mMockZenModeHelper, times(1)).setNotificationPolicy(any());
resetZenModeHelper();