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

Commit 2902817c authored by Jared Duke's avatar Jared Duke
Browse files

Use the standard class name for dumpable keys

Class names are guaranteed to be both non-null and unique, whereas
canonical names may be null for certain types. This avoids issues
where the validity of such names might depend on bytecode optimizations.

Bug: 309672095
Test: m + presubmit
Flag: EXEMPT bugfix
Change-Id: Ie80bdc0a056d5bfc27e1b9d88c43fc5a561d2648
parent 7ba00f0c
Loading
Loading
Loading
Loading
+4 −7
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ open class DumpManager @Inject constructor() {

    /** See [registerCriticalDumpable]. */
    fun registerCriticalDumpable(module: Dumpable) {
        registerCriticalDumpable(module::class.java.canonicalName, module)
        registerCriticalDumpable(module::class.java.name, module)
    }

    /**
@@ -62,7 +62,7 @@ open class DumpManager @Inject constructor() {

    /** See [registerNormalDumpable]. */
    fun registerNormalDumpable(module: Dumpable) {
        registerNormalDumpable(module::class.java.canonicalName, module)
        registerNormalDumpable(module::class.java.name, module)
    }

    /**
@@ -104,13 +104,10 @@ open class DumpManager @Inject constructor() {
        dumpables[name] = DumpableEntry(module, name, priority)
    }

    /**
     * Same as the above override, but automatically uses the canonical class name as the dumpable
     * name.
     */
    /** Same as the above override, but automatically uses the class name as the dumpable name. */
    @Synchronized
    fun registerDumpable(module: Dumpable) {
        registerDumpable(module::class.java.canonicalName, module)
        registerDumpable(module::class.java.name, module)
    }

    /** Unregisters a previously-registered dumpable. */
+16 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.table.TableLogBuffer
import com.google.common.truth.Truth.assertThat
import java.io.PrintWriter
import org.junit.Assert.assertThrows
import org.junit.Before
import org.junit.Test
@@ -130,6 +131,21 @@ class DumpManagerTest : SysuiTestCase() {
        // No exception thrown
    }

    @Test
    fun registerDumpable_supportsAnonymousDumpables() {
        val anonDumpable =
            object : Dumpable {
                override fun dump(pw: PrintWriter, args: Array<out String>) {
                    pw.println("AnonDumpable")
                }
            }

        // THEN registration with implicit names should succeed
        dumpManager.registerCriticalDumpable(anonDumpable)

        // No exception thrown
    }

    @Test
    fun getDumpables_returnsSafeCollection() {
        // GIVEN a variety of registered dumpables