From 1149017c4562f4c548f47f34b5b3573b13577f5b Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Tue, 28 Dec 2021 20:41:25 +0000 Subject: [PATCH 1/2] Convert notification debug filter to CommandRegistry Bug: 235268992 Test: PlatformScenarioTests Change-Id: I646820a93b9b3129029a39564f3627f6773709aa --- .../provider/DebugModeFilterProvider.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) 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 a0c39c6daab4e..f1d73850503da 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 ` + * or + * `$ adb shell cmd statusbar notif-filter allowed-pkgs ...` * * 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) { + 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 ") + pw.println("Available commands:") + pw.println(" reset") + pw.println(" Restore the default system behavior.") + pw.println(" allowed-pkgs ...") + pw.println(" Hide all notification except from packages listed here.") + pw.println(" Providing no packages is treated as a reset.") + } + } } From 98b4f5d380861481ac3d49cd93512dd7b385482b Mon Sep 17 00:00:00 2001 From: Jeff DeCew Date: Thu, 9 Jun 2022 20:07:53 +0000 Subject: [PATCH 2/2] Remove the old broadcast receiver for setting the notification debug mode filter Bug: 235268992 Test: PlatformScenarioTests Change-Id: I5dfc97bf83394f3bf3e8e68d24fb8ef98c40a5b1 --- .../provider/DebugModeFilterProvider.kt | 42 ++----------------- 1 file changed, 3 insertions(+), 39 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 f1d73850503da..fd5bae1515505 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 @@ -16,10 +16,6 @@ package com.android.systemui.statusbar.notification.collection.provider -import android.content.BroadcastReceiver -import android.content.Context -import android.content.Intent -import android.content.IntentFilter import android.os.Build import android.util.Log import com.android.systemui.Dumpable @@ -41,17 +37,12 @@ import javax.inject.Inject * The only configuration is a list of allowed packages. When this list is empty, the feature is * disabled. When SystemUI starts up, this feature is disabled. * - * To enabled filtering, provide the list of packages in a comma-separated list using the command: + * To enabled filtering, provide the space-separated list of packages using the command: * - * `$ adb shell am broadcast -a com.android.systemui.action.SET_NOTIF_DEBUG_MODE - * --esal allowed_packages ` - * or * `$ adb shell cmd statusbar notif-filter allowed-pkgs ...` * - * To disable filtering, send the action without a list: + * To disable filtering, send the command without any packages, or explicitly reset: * - * `$ 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. @@ -59,7 +50,6 @@ import javax.inject.Inject @SysUISingleton class DebugModeFilterProvider @Inject constructor( private val commandRegistry: CommandRegistry, - private val context: Context, dumpManager: DumpManager ) : Dumpable { private var allowedPackages: List = emptyList() @@ -82,10 +72,7 @@ class DebugModeFilterProvider @Inject constructor( 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) - Log.d(TAG, "Registered: $mReceiver") + Log.d(TAG, "Registered notif-filter command") } } @@ -108,31 +95,8 @@ class DebugModeFilterProvider @Inject constructor( } } - private val mReceiver: BroadcastReceiver = object : BroadcastReceiver() { - override fun onReceive(context: Context, intent: Intent?) { - val action = intent?.action - if (ACTION_SET_NOTIF_DEBUG_MODE == action) { - // TODO(b/235268992) remove - Log.d(TAG, "ACTION_SET_NOTIF_DEBUG_MODE enter") - allowedPackages = intent.extras?.getStringArrayList(EXTRA_ALLOWED_PACKAGES) - ?: emptyList() - Log.d(TAG, "Updated allowedPackages: $allowedPackages") - listeners.forEach(Runnable::run) - // TODO(b/235268992) remove - Log.d(TAG, "ACTION_SET_NOTIF_DEBUG_MODE leave") - } else { - Log.d(TAG, "Malformed intent: $intent") - } - } - } - companion object { private const val TAG = "DebugModeFilterProvider" - private const val ACTION_SET_NOTIF_DEBUG_MODE = - "com.android.systemui.action.SET_NOTIF_DEBUG_MODE" - private const val NOTIF_DEBUG_MODE_PERMISSION = - "com.android.systemui.permission.NOTIF_DEBUG_MODE" - private const val EXTRA_ALLOWED_PACKAGES = "allowed_packages" } inner class NotifFilterCommand : Command {