Loading services/core/java/com/android/server/notification/ZenModeHelper.java +11 −1 Original line number Diff line number Diff line Loading @@ -1941,9 +1941,19 @@ public class ZenModeHelper { @Nullable public Policy getNotificationPolicy(UserHandle user) { synchronized (mConfigLock) { if (Flags.modesMultiuser()) { // Return a fallback (default) policy for users without a zen config. // Note that zen updates (setPolicy, setFilter) won't be applied, so this is mostly // about preventing NPEs for careless callers. ZenModeConfig config = getConfigLocked(user); return config != null ? getNotificationPolicy(config) : getNotificationPolicy(mDefaultConfig); } else { return getNotificationPolicy(getConfigLocked(user)); } } } @Nullable private static Policy getNotificationPolicy(@Nullable ZenModeConfig config) { Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -7363,6 +7363,20 @@ public class ZenModeHelperTest extends UiServiceTestCase { verify(callback, never()).onZenModeChanged(); } @Test @EnableFlags(FLAG_MODES_MULTIUSER) public void getNotificationPolicy_fromUserWithoutZenConfig_returnsDefaultPolicy() { // Set a custom policy for the current user to double check we return a default one below. mZenModeHelper.setNotificationPolicy(UserHandle.CURRENT, new Policy(0, 0, 0), ORIGIN_SYSTEM, SYSTEM_UID); Policy ghostPolicy = mZenModeHelper.getNotificationPolicy(UserHandle.of(5552368)); assertThat(ghostPolicy).isNotNull(); assertThat(ZenAdapters.notificationPolicyToZenPolicy(ghostPolicy)) .isEqualTo(mZenModeHelper.getDefaultZenPolicy()); } private static void addZenRule(ZenModeConfig config, String id, String ownerPkg, int zenMode, @Nullable ZenPolicy zenPolicy) { ZenRule rule = new ZenRule(); Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +11 −1 Original line number Diff line number Diff line Loading @@ -1941,9 +1941,19 @@ public class ZenModeHelper { @Nullable public Policy getNotificationPolicy(UserHandle user) { synchronized (mConfigLock) { if (Flags.modesMultiuser()) { // Return a fallback (default) policy for users without a zen config. // Note that zen updates (setPolicy, setFilter) won't be applied, so this is mostly // about preventing NPEs for careless callers. ZenModeConfig config = getConfigLocked(user); return config != null ? getNotificationPolicy(config) : getNotificationPolicy(mDefaultConfig); } else { return getNotificationPolicy(getConfigLocked(user)); } } } @Nullable private static Policy getNotificationPolicy(@Nullable ZenModeConfig config) { Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +14 −0 Original line number Diff line number Diff line Loading @@ -7363,6 +7363,20 @@ public class ZenModeHelperTest extends UiServiceTestCase { verify(callback, never()).onZenModeChanged(); } @Test @EnableFlags(FLAG_MODES_MULTIUSER) public void getNotificationPolicy_fromUserWithoutZenConfig_returnsDefaultPolicy() { // Set a custom policy for the current user to double check we return a default one below. mZenModeHelper.setNotificationPolicy(UserHandle.CURRENT, new Policy(0, 0, 0), ORIGIN_SYSTEM, SYSTEM_UID); Policy ghostPolicy = mZenModeHelper.getNotificationPolicy(UserHandle.of(5552368)); assertThat(ghostPolicy).isNotNull(); assertThat(ZenAdapters.notificationPolicyToZenPolicy(ghostPolicy)) .isEqualTo(mZenModeHelper.getDefaultZenPolicy()); } private static void addZenRule(ZenModeConfig config, String id, String ownerPkg, int zenMode, @Nullable ZenPolicy zenPolicy) { ZenRule rule = new ZenRule(); Loading