Convert notification debug filter to CommandRegistry am: 1149017c45 am: ceaf91a429

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18800598

Change-Id: Idc6af66327a68a04090096fee0cc882d98261de2
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jeff DeCew
2022-06-10 19:50:30 +00:00
committed by Automerger Merge Worker

View File

@@ -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.")
}
}
}