From 154dabcae68d59610ce33000ac64da0808dc0b37 Mon Sep 17 00:00:00 2001 From: Abhijoy Saha Date: Wed, 23 Jun 2021 21:23:18 +0000 Subject: [PATCH] Set correct uid for headless system 0 in DnD PreferencesHelperTest This fixes Dnd PreferenceHelper CTS tests for AAOS. Fixes: 191803082 Test: atest com.android.server.notification.PreferencesHelperTest Change-Id: I91339e8971fa1cea6abc696e084de1764b3b953a --- .../notification/PreferencesHelperTest.java | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java index 3a51ff2fb5fa0..10ca54fe72134 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/PreferencesHelperTest.java @@ -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();