Loading src/com/android/settings/notification/modes/ZenMode.java +2 −2 Original line number Diff line number Diff line Loading @@ -103,8 +103,8 @@ class ZenMode { mIsManualDnd = isManualDnd; } static ZenMode manualDndMode(AutomaticZenRule dndPolicyAsRule, boolean isActive) { return new ZenMode(MANUAL_DND_MODE_ID, dndPolicyAsRule, isActive, true); static ZenMode manualDndMode(AutomaticZenRule manualRule, boolean isActive) { return new ZenMode(MANUAL_DND_MODE_ID, manualRule, isActive, true); } @NonNull Loading src/com/android/settings/notification/modes/ZenModesBackend.java +19 −18 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.settings.notification.modes; import static java.util.Objects.requireNonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.AutomaticZenRule; Loading @@ -32,11 +30,11 @@ import android.provider.ContactsContract; import android.provider.Settings; import android.service.notification.Condition; import android.service.notification.ConversationChannelWrapper; import android.service.notification.ZenAdapters; import android.service.notification.ZenModeConfig; import android.util.Log; import androidx.annotation.VisibleForTesting; import com.android.settings.R; import java.time.Duration; Loading Loading @@ -162,22 +160,19 @@ class ZenModesBackend { } private ZenMode getManualDndMode(ZenModeConfig config) { // TODO: b/333530553 - Read ZenDeviceEffects of manual DND. ZenModeConfig.ZenRule manualRule = config.manualRule; // TODO: b/333682392 - Replace with final strings for name & trigger description AutomaticZenRule manualDndRule = new AutomaticZenRule.Builder( mContext.getString(R.string.zen_mode_settings_title), Uri.EMPTY) .setType(AutomaticZenRule.TYPE_OTHER) .setZenPolicy(ZenAdapters.notificationPolicyToZenPolicy( mNotificationManager.getNotificationPolicy())) .setDeviceEffects(null) .setManualInvocationAllowed(true) mContext.getString(R.string.zen_mode_settings_title), manualRule.conditionId) .setType(manualRule.type) .setZenPolicy(manualRule.zenPolicy) .setDeviceEffects(manualRule.zenDeviceEffects) .setManualInvocationAllowed(manualRule.allowManualInvocation) .setConfigurationActivity(null) // No further settings .setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY) .build(); // Regardless of its contents, non-null manualRule means that manual rule is active. return ZenMode.manualDndMode(manualDndRule, config != null && config.manualRule != null); return ZenMode.manualDndMode(manualDndRule, config != null && config.isManualActive()); } private static boolean isRuleActive(String id, ZenModeConfig config) { Loading @@ -191,10 +186,16 @@ class ZenModesBackend { void updateMode(ZenMode mode) { if (mode.isManualDnd()) { try { NotificationManager.Policy dndPolicy = new ZenModeConfig().toNotificationPolicy(requireNonNull(mode.getPolicy())); new ZenModeConfig().toNotificationPolicy(mode.getPolicy()); mNotificationManager.setNotificationPolicy(dndPolicy, /* fromUser= */ true); // TODO: b/333530553 - Update ZenDeviceEffects of the manual DND too. mNotificationManager.setManualZenRuleDeviceEffects( mode.getRule().getDeviceEffects()); } catch (Exception e) { Log.w(TAG, "Error updating manual mode", e); } } else { mNotificationManager.updateAutomaticZenRule(mode.getId(), mode.getRule(), /* fromUser= */ true); Loading src/com/android/settings/notification/zen/ZenModeBackend.java +2 −2 Original line number Diff line number Diff line Loading @@ -400,7 +400,7 @@ public class ZenModeBackend { ZenPolicy setDefaultZenPolicy(ZenPolicy zenPolicy) { int calls; if (mPolicy.allowCalls()) { calls = ZenAdapters.notificationPolicySendersToZenPolicyPeopleType( calls = ZenAdapters.prioritySendersToPeopleType( mPolicy.allowCallsFrom()); } else { calls = ZenPolicy.PEOPLE_TYPE_NONE; Loading @@ -408,7 +408,7 @@ public class ZenModeBackend { int messages; if (mPolicy.allowMessages()) { messages = ZenAdapters.notificationPolicySendersToZenPolicyPeopleType( messages = ZenAdapters.prioritySendersToPeopleType( mPolicy.allowMessagesFrom()); } else { messages = ZenPolicy.PEOPLE_TYPE_NONE; Loading tests/robotests/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ android_robolectric_test { "notification_flags_lib", "platform-test-annotations", "testables", "android.app.flags-aconfig-java", ], libs: [ Loading tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/DndConditionalCardControllerTest.java +6 −24 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import com.android.settings.R; import com.android.settings.homepage.contextualcards.ContextualCard; import com.android.settings.testutils.shadow.ShadowNotificationManager; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -92,35 +91,18 @@ public class DndConditionalCardControllerTest { private ZenModeConfig getCustomConfig() { final ZenModeConfig config = new ZenModeConfig(); // Some sounds allowed config.allowAlarms = true; config.allowMedia = false; config.allowSystem = false; config.allowCalls = true; config.allowRepeatCallers = true; config.allowMessages = false; config.allowReminders = false; config.allowEvents = false; config.areChannelsBypassingDnd = false; config.allowCallsFrom = ZenModeConfig.SOURCE_ANYONE; config.allowMessagesFrom = ZenModeConfig.SOURCE_ANYONE; config.suppressedVisualEffects = 0; config.applyNotificationPolicy(new NotificationManager.Policy( NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS | NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | NotificationManager.Policy.PRIORITY_CATEGORY_CALLS, NotificationManager.Policy.PRIORITY_SENDERS_ANY, 0)); return config; } private ZenModeConfig getMutedAllConfig() { final ZenModeConfig config = new ZenModeConfig(); // No sounds allowed config.allowAlarms = false; config.allowMedia = false; config.allowSystem = false; config.allowCalls = false; config.allowRepeatCallers = false; config.allowMessages = false; config.allowReminders = false; config.allowEvents = false; config.applyNotificationPolicy(new NotificationManager.Policy(0, 0, 0)); config.areChannelsBypassingDnd = false; config.suppressedVisualEffects = 0; return config; } } Loading
src/com/android/settings/notification/modes/ZenMode.java +2 −2 Original line number Diff line number Diff line Loading @@ -103,8 +103,8 @@ class ZenMode { mIsManualDnd = isManualDnd; } static ZenMode manualDndMode(AutomaticZenRule dndPolicyAsRule, boolean isActive) { return new ZenMode(MANUAL_DND_MODE_ID, dndPolicyAsRule, isActive, true); static ZenMode manualDndMode(AutomaticZenRule manualRule, boolean isActive) { return new ZenMode(MANUAL_DND_MODE_ID, manualRule, isActive, true); } @NonNull Loading
src/com/android/settings/notification/modes/ZenModesBackend.java +19 −18 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.settings.notification.modes; import static java.util.Objects.requireNonNull; import android.annotation.Nullable; import android.app.ActivityManager; import android.app.AutomaticZenRule; Loading @@ -32,11 +30,11 @@ import android.provider.ContactsContract; import android.provider.Settings; import android.service.notification.Condition; import android.service.notification.ConversationChannelWrapper; import android.service.notification.ZenAdapters; import android.service.notification.ZenModeConfig; import android.util.Log; import androidx.annotation.VisibleForTesting; import com.android.settings.R; import java.time.Duration; Loading Loading @@ -162,22 +160,19 @@ class ZenModesBackend { } private ZenMode getManualDndMode(ZenModeConfig config) { // TODO: b/333530553 - Read ZenDeviceEffects of manual DND. ZenModeConfig.ZenRule manualRule = config.manualRule; // TODO: b/333682392 - Replace with final strings for name & trigger description AutomaticZenRule manualDndRule = new AutomaticZenRule.Builder( mContext.getString(R.string.zen_mode_settings_title), Uri.EMPTY) .setType(AutomaticZenRule.TYPE_OTHER) .setZenPolicy(ZenAdapters.notificationPolicyToZenPolicy( mNotificationManager.getNotificationPolicy())) .setDeviceEffects(null) .setManualInvocationAllowed(true) mContext.getString(R.string.zen_mode_settings_title), manualRule.conditionId) .setType(manualRule.type) .setZenPolicy(manualRule.zenPolicy) .setDeviceEffects(manualRule.zenDeviceEffects) .setManualInvocationAllowed(manualRule.allowManualInvocation) .setConfigurationActivity(null) // No further settings .setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_PRIORITY) .build(); // Regardless of its contents, non-null manualRule means that manual rule is active. return ZenMode.manualDndMode(manualDndRule, config != null && config.manualRule != null); return ZenMode.manualDndMode(manualDndRule, config != null && config.isManualActive()); } private static boolean isRuleActive(String id, ZenModeConfig config) { Loading @@ -191,10 +186,16 @@ class ZenModesBackend { void updateMode(ZenMode mode) { if (mode.isManualDnd()) { try { NotificationManager.Policy dndPolicy = new ZenModeConfig().toNotificationPolicy(requireNonNull(mode.getPolicy())); new ZenModeConfig().toNotificationPolicy(mode.getPolicy()); mNotificationManager.setNotificationPolicy(dndPolicy, /* fromUser= */ true); // TODO: b/333530553 - Update ZenDeviceEffects of the manual DND too. mNotificationManager.setManualZenRuleDeviceEffects( mode.getRule().getDeviceEffects()); } catch (Exception e) { Log.w(TAG, "Error updating manual mode", e); } } else { mNotificationManager.updateAutomaticZenRule(mode.getId(), mode.getRule(), /* fromUser= */ true); Loading
src/com/android/settings/notification/zen/ZenModeBackend.java +2 −2 Original line number Diff line number Diff line Loading @@ -400,7 +400,7 @@ public class ZenModeBackend { ZenPolicy setDefaultZenPolicy(ZenPolicy zenPolicy) { int calls; if (mPolicy.allowCalls()) { calls = ZenAdapters.notificationPolicySendersToZenPolicyPeopleType( calls = ZenAdapters.prioritySendersToPeopleType( mPolicy.allowCallsFrom()); } else { calls = ZenPolicy.PEOPLE_TYPE_NONE; Loading @@ -408,7 +408,7 @@ public class ZenModeBackend { int messages; if (mPolicy.allowMessages()) { messages = ZenAdapters.notificationPolicySendersToZenPolicyPeopleType( messages = ZenAdapters.prioritySendersToPeopleType( mPolicy.allowMessagesFrom()); } else { messages = ZenPolicy.PEOPLE_TYPE_NONE; Loading
tests/robotests/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -102,6 +102,7 @@ android_robolectric_test { "notification_flags_lib", "platform-test-annotations", "testables", "android.app.flags-aconfig-java", ], libs: [ Loading
tests/robotests/src/com/android/settings/homepage/contextualcards/conditional/DndConditionalCardControllerTest.java +6 −24 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import com.android.settings.R; import com.android.settings.homepage.contextualcards.ContextualCard; import com.android.settings.testutils.shadow.ShadowNotificationManager; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; Loading Loading @@ -92,35 +91,18 @@ public class DndConditionalCardControllerTest { private ZenModeConfig getCustomConfig() { final ZenModeConfig config = new ZenModeConfig(); // Some sounds allowed config.allowAlarms = true; config.allowMedia = false; config.allowSystem = false; config.allowCalls = true; config.allowRepeatCallers = true; config.allowMessages = false; config.allowReminders = false; config.allowEvents = false; config.areChannelsBypassingDnd = false; config.allowCallsFrom = ZenModeConfig.SOURCE_ANYONE; config.allowMessagesFrom = ZenModeConfig.SOURCE_ANYONE; config.suppressedVisualEffects = 0; config.applyNotificationPolicy(new NotificationManager.Policy( NotificationManager.Policy.PRIORITY_CATEGORY_ALARMS | NotificationManager.Policy.PRIORITY_CATEGORY_REPEAT_CALLERS | NotificationManager.Policy.PRIORITY_CATEGORY_CALLS, NotificationManager.Policy.PRIORITY_SENDERS_ANY, 0)); return config; } private ZenModeConfig getMutedAllConfig() { final ZenModeConfig config = new ZenModeConfig(); // No sounds allowed config.allowAlarms = false; config.allowMedia = false; config.allowSystem = false; config.allowCalls = false; config.allowRepeatCallers = false; config.allowMessages = false; config.allowReminders = false; config.allowEvents = false; config.applyNotificationPolicy(new NotificationManager.Policy(0, 0, 0)); config.areChannelsBypassingDnd = false; config.suppressedVisualEffects = 0; return config; } }