Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit efea2f25 authored by Andreas Miko's avatar Andreas Miko
Browse files

Enable easy and deterministic debug bundle

This enables non-eng people to test the feature with notify or other
apps deterministically by using the following command:

`adb shell setprop persist.debug.notification_bundle_ui_debug_app_name com.google.cinek.notify && adb reboot`

Test: Tested manually. Command and debug bundle.
Bug: b/389839492
Flag: com.android.systemui.notification_bundle_ui
Change-Id: Icb446848d61511dabea985222f252d1d9489afbb
parent 4ebe88f1
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import android.service.notification.NotificationListenerService
import android.service.notification.StatusBarNotification
import com.android.internal.logging.MetricsLogger
import com.android.systemui.statusbar.notification.NotificationActivityStarter
import com.android.systemui.statusbar.notification.collection.coordinator.BundleCoordinator
import com.android.systemui.statusbar.notification.collection.coordinator.BundleCoordinator.Companion.debugBundleAppName
import com.android.systemui.statusbar.notification.collection.coordinator.VisualStabilityCoordinator
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifLifetimeExtender
import com.android.systemui.statusbar.notification.collection.provider.HighPriorityProvider
@@ -270,7 +270,7 @@ class NotificationEntryAdapter(
    }

    override fun isBundled(): Boolean {
        return entry.isBundled || (BundleCoordinator.Companion.debugBundleUi && hasBundleParent())
        return entry.isBundled || (!debugBundleAppName.isNullOrEmpty() && hasBundleParent())
    }

    private fun hasBundleParent(): Boolean {
+2 −4
Original line number Diff line number Diff line
@@ -294,9 +294,7 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {

        mIdToBundleEntry.clear();
        for (BundleSpec spec : mNotifBundler.getBundleSpecs()) {
            if (BundleCoordinator.debugBundleUi) {
                Log.i(TAG, "create BundleEntry with id: " + spec.getKey());
            }
            debugBundleLog(TAG, () -> "create BundleEntry with id: " + spec.getKey());
            mIdToBundleEntry.put(spec.getKey(), new BundleEntry(spec));
        }
    }
@@ -722,7 +720,7 @@ public class ShadeListBuilder implements Dumpable, PipelineDumpable {
    }

    private void debugList(String s) {
        if (!BundleCoordinator.debugBundleUi) {
        if (!BundleCoordinator.debugBundleLogs) {
            return;
        }
        StringBuilder listStr = new StringBuilder();
+25 −4
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import android.app.NotificationChannel.NEWS_ID
import android.app.NotificationChannel.PROMOTIONS_ID
import android.app.NotificationChannel.RECS_ID
import android.app.NotificationChannel.SOCIAL_MEDIA_ID
import android.os.Build
import android.os.SystemProperties
import com.android.systemui.statusbar.notification.collection.BundleEntry
import com.android.systemui.statusbar.notification.collection.BundleSpec
import com.android.systemui.statusbar.notification.collection.GroupEntry
@@ -109,7 +111,7 @@ constructor(
                add(BundleSpec.SOCIAL_MEDIA)
                add(BundleSpec.PROMOTIONS)
                add(BundleSpec.RECOMMENDED)
                if (debugBundleUi) add(BundleSpec.DEBUG)
                if (!debugBundleAppName.isNullOrEmpty()) add(BundleSpec.DEBUG)
            }

            private val bundleIds = this.bundleSpecs.map { it.key }
@@ -119,7 +121,7 @@ constructor(
             * ListEntry should not be bundled
             */
            override fun getBundleIdOrNull(entry: ListEntry): String? {
                if (debugBundleUi && entry?.key?.contains("notify") == true) {
                if (isFromDebugApp(entry)) {
                    return BundleSpec.DEBUG.key
                }
                if (entry is GroupEntry) {
@@ -133,6 +135,10 @@ constructor(
                return getBundleIdForNotifEntry(entry as NotificationEntry)
            }

            private fun isFromDebugApp(entry: ListEntry): Boolean {
                return !debugBundleAppName.isNullOrEmpty() && entry.key.contains(debugBundleAppName)
            }

            private fun getBundleIdForNotifEntry(notifEntry: NotificationEntry): String? {
                return notifEntry.representativeEntry?.channel?.id?.takeIf { it in this.bundleIds }
            }
@@ -178,10 +184,25 @@ constructor(

    companion object {
        @JvmField val TAG: String = "BundleCoordinator"
        @JvmField var debugBundleUi: Boolean = false

        @JvmField var debugBundleLogs: Boolean = false

        /**
         * All notifications that contain this String in the key are bundled into a debug bundle
         * such that bundle code can be easily and deterministically tested.
         *
         * E.g. use this command to bundle all notifications from notify: `adb shell setprop
         * persist.debug.notification_bundle_ui_debug_app_name com.google.cinek.notify && adb
         * reboot`
         */
        val debugBundleAppName: String? =
            if (Build.IS_USERDEBUG)
                SystemProperties.get("persist.debug.notification_bundle_ui_debug_app_name")
            else null

        @JvmStatic
        fun debugBundleLog(tag: String, stringLambda: () -> String) {
            if (debugBundleUi) {
            if (debugBundleLogs) {
                android.util.Log.d(tag, stringLambda())
            }
        }