From 08d381b830aa9d2b09fe84cceeee5c8439c04a58 Mon Sep 17 00:00:00 2001 From: Julia Reynolds <juliacr@google.com> Date: Wed, 5 Jun 2019 15:46:27 -0400 Subject: [PATCH] Add shell command to toggle DND adb shell cmd notification set_dnd [type] Where type is one of: none (total silence mode) on (total silence mode) priority (priority only mode) alarms (alarms only mode) all (turn dnd off) off (turn dnd off) Test: manual Fixes: 132901740 Change-Id: I9b634570a0bd6dd0a3277268e39a8ca67e177e89 --- .../notification/NotificationShellCmd.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/notification/NotificationShellCmd.java b/services/core/java/com/android/server/notification/NotificationShellCmd.java index dd0f420b6df5..1ac856a870af 100644 --- a/services/core/java/com/android/server/notification/NotificationShellCmd.java +++ b/services/core/java/com/android/server/notification/NotificationShellCmd.java @@ -16,6 +16,12 @@ package com.android.server.notification; +import static android.app.NotificationManager.INTERRUPTION_FILTER_ALARMS; +import static android.app.NotificationManager.INTERRUPTION_FILTER_ALL; +import static android.app.NotificationManager.INTERRUPTION_FILTER_NONE; +import static android.app.NotificationManager.INTERRUPTION_FILTER_PRIORITY; +import static android.app.NotificationManager.INTERRUPTION_FILTER_UNKNOWN; + import android.app.ActivityManager; import android.app.INotificationManager; import android.app.Notification; @@ -47,13 +53,13 @@ import java.util.Collections; * Implementation of `cmd notification` in NotificationManagerService. */ public class NotificationShellCmd extends ShellCommand { - private static final String USAGE = - "usage: cmd notification SUBCMD [args]\n\n" + private static final String USAGE = "usage: cmd notification SUBCMD [args]\n\n" + "SUBCMDs:\n" + " allow_listener COMPONENT [user_id (current user if not specified)]\n" + " disallow_listener COMPONENT [user_id (current user if not specified)]\n" + " allow_assistant COMPONENT [user_id (current user if not specified)]\n" + " remove_assistant COMPONENT [user_id (current user if not specified)]\n" + + " set_dnd [on|none (same as on)|priority|alarms|all|off (same as all)]" + " allow_dnd PACKAGE [user_id (current user if not specified)]\n" + " disallow_dnd PACKAGE [user_id (current user if not specified)]\n" + " suspend_package PACKAGE\n" @@ -111,6 +117,28 @@ public class NotificationShellCmd extends ShellCommand { final PrintWriter pw = getOutPrintWriter(); try { switch (cmd.replace('-', '_')) { + case "set_dnd": { + String mode = getNextArgRequired(); + int interruptionFilter = INTERRUPTION_FILTER_UNKNOWN; + switch(mode) { + case "none": + case "on": + interruptionFilter = INTERRUPTION_FILTER_NONE; + break; + case "priority": + interruptionFilter = INTERRUPTION_FILTER_PRIORITY; + break; + case "alarms": + interruptionFilter = INTERRUPTION_FILTER_ALARMS; + break; + case "all": + case "off": + interruptionFilter = INTERRUPTION_FILTER_ALL; + } + mBinderService.setInterruptionFilter( + mDirectService.getContext().getPackageName(), interruptionFilter); + } + break; case "allow_dnd": { String packageName = getNextArgRequired(); int userId = ActivityManager.getCurrentUser(); -- GitLab