Merge "Add shell command to toggle DND"

This commit is contained in:
TreeHugger Robot
2019-06-05 22:48:57 +00:00
committed by Android (Google) Code Review

View File

@@ -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();