diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/DebugModeFilterProvider.kt | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/DebugModeFilterProvider.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/DebugModeFilterProvider.kt index a0c39c6daab4..f1d73850503d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/DebugModeFilterProvider.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/provider/DebugModeFilterProvider.kt @@ -25,6 +25,8 @@ import android.util.Log import com.android.systemui.Dumpable import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dump.DumpManager +import com.android.systemui.statusbar.commandline.Command +import com.android.systemui.statusbar.commandline.CommandRegistry import com.android.systemui.statusbar.notification.collection.NotificationEntry import com.android.systemui.util.Assert import com.android.systemui.util.ListenerSet @@ -43,15 +45,20 @@ import javax.inject.Inject * * `$ adb shell am broadcast -a com.android.systemui.action.SET_NOTIF_DEBUG_MODE * --esal allowed_packages <comma-separated-packages>` + * or + * `$ adb shell cmd statusbar notif-filter allowed-pkgs <package> ...` * * To disable filtering, send the action without a list: * * `$ adb shell am broadcast -a com.android.systemui.action.SET_NOTIF_DEBUG_MODE` + * or + * `$ adb shell cmd statusbar notif-filter reset` * * NOTE: this feature only works on debug builds, and when the broadcaster is root. */ @SysUISingleton class DebugModeFilterProvider @Inject constructor( + private val commandRegistry: CommandRegistry, private val context: Context, dumpManager: DumpManager ) : Dumpable { @@ -74,6 +81,7 @@ class DebugModeFilterProvider @Inject constructor( val needsInitialization = listeners.isEmpty() listeners.addIfAbsent(listener) if (needsInitialization) { + commandRegistry.registerCommand("notif-filter") { NotifFilterCommand() } val filter = IntentFilter().apply { addAction(ACTION_SET_NOTIF_DEBUG_MODE) } val permission = NOTIF_DEBUG_MODE_PERMISSION context.registerReceiver(mReceiver, filter, permission, null, Context.RECEIVER_EXPORTED) @@ -126,4 +134,46 @@ class DebugModeFilterProvider @Inject constructor( "com.android.systemui.permission.NOTIF_DEBUG_MODE" private const val EXTRA_ALLOWED_PACKAGES = "allowed_packages" } + + inner class NotifFilterCommand : Command { + override fun execute(pw: PrintWriter, args: List<String>) { + when (args.firstOrNull()) { + "reset" -> { + if (args.size > 1) { + return invalidCommand(pw, "Unexpected arguments for 'reset' command") + } + allowedPackages = emptyList() + } + "allowed-pkgs" -> { + allowedPackages = args.drop(1) + } + null -> return invalidCommand(pw, "Missing command") + else -> return invalidCommand(pw, "Unknown command: ${args.firstOrNull()}") + } + Log.d(TAG, "Updated allowedPackages: $allowedPackages") + if (allowedPackages.isEmpty()) { + pw.print("Resetting allowedPackages ... ") + } else { + pw.print("Updating allowedPackages: $allowedPackages ... ") + } + listeners.forEach(Runnable::run) + pw.println("DONE") + } + + private fun invalidCommand(pw: PrintWriter, reason: String) { + pw.println("Error: $reason") + pw.println() + help(pw) + } + + override fun help(pw: PrintWriter) { + pw.println("Usage: adb shell cmd statusbar notif-filter <command>") + pw.println("Available commands:") + pw.println(" reset") + pw.println(" Restore the default system behavior.") + pw.println(" allowed-pkgs <package> ...") + pw.println(" Hide all notification except from packages listed here.") + pw.println(" Providing no packages is treated as a reset.") + } + } } |