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

Commit f50de686 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Proto dump from SystemUI." into tm-qpr-dev

parents 69c39233 afa802a8
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -322,4 +322,7 @@ oneway interface IStatusBar

    /** Unregisters a nearby media devices provider. */
    void unregisterNearbyMediaDevicesProvider(in INearbyMediaDevicesProvider provider);

    /** Dump protos from SystemUI. The proto definition is defined there */
    void dumpProto(in String[] args, in ParcelFileDescriptor pfd);
}
+0 −1
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ public interface Dumpable {

    /**
     * Called when it's time to dump the internal state
     * @param fd A file descriptor.
     * @param pw Where to write your dump to.
     * @param args Arguments.
     */
+7 −0
Original line number Diff line number Diff line
package com.android.systemui

import com.android.systemui.dump.nano.SystemUIProtoDump

interface ProtoDumpable : Dumpable {
    fun dumpProto(systemUIProtoDump: SystemUIProtoDump, args: Array<String>)
}
+1 −1
Original line number Diff line number Diff line
@@ -121,6 +121,6 @@ public class SystemUIService extends Service {
                    DumpHandler.PRIORITY_ARG_CRITICAL};
        }

        mDumpHandler.dump(pw, massagedArgs);
        mDumpHandler.dump(fd, pw, massagedArgs);
    }
}
+46 −8
Original line number Diff line number Diff line
@@ -24,8 +24,13 @@ import com.android.systemui.R
import com.android.systemui.dump.DumpHandler.Companion.PRIORITY_ARG_CRITICAL
import com.android.systemui.dump.DumpHandler.Companion.PRIORITY_ARG_HIGH
import com.android.systemui.dump.DumpHandler.Companion.PRIORITY_ARG_NORMAL
import com.android.systemui.dump.nano.SystemUIProtoDump
import com.android.systemui.plugins.log.LogBuffer
import com.android.systemui.shared.system.UncaughtExceptionPreHandlerManager
import com.google.protobuf.nano.MessageNano
import java.io.BufferedOutputStream
import java.io.FileDescriptor
import java.io.FileOutputStream
import java.io.PrintWriter
import javax.inject.Inject
import javax.inject.Provider
@@ -100,7 +105,7 @@ class DumpHandler @Inject constructor(
    /**
     * Dump the diagnostics! Behavior can be controlled via [args].
     */
    fun dump(pw: PrintWriter, args: Array<String>) {
    fun dump(fd: FileDescriptor, pw: PrintWriter, args: Array<String>) {
        Trace.beginSection("DumpManager#dump()")
        val start = SystemClock.uptimeMillis()

@@ -111,10 +116,12 @@ class DumpHandler @Inject constructor(
            return
        }

        when (parsedArgs.dumpPriority) {
            PRIORITY_ARG_CRITICAL -> dumpCritical(pw, parsedArgs)
            PRIORITY_ARG_NORMAL -> dumpNormal(pw, parsedArgs)
            else -> dumpParameterized(pw, parsedArgs)
        when {
            parsedArgs.dumpPriority == PRIORITY_ARG_CRITICAL -> dumpCritical(pw, parsedArgs)
            parsedArgs.dumpPriority == PRIORITY_ARG_NORMAL && !parsedArgs.proto -> {
                dumpNormal(pw, parsedArgs)
            }
            else -> dumpParameterized(fd, pw, parsedArgs)
        }

        pw.println()
@@ -122,7 +129,7 @@ class DumpHandler @Inject constructor(
        Trace.endSection()
    }

    private fun dumpParameterized(pw: PrintWriter, args: ParsedArgs) {
    private fun dumpParameterized(fd: FileDescriptor, pw: PrintWriter, args: ParsedArgs) {
        when (args.command) {
            "bugreport-critical" -> dumpCritical(pw, args)
            "bugreport-normal" -> dumpNormal(pw, args)
@@ -130,7 +137,13 @@ class DumpHandler @Inject constructor(
            "buffers" -> dumpBuffers(pw, args)
            "config" -> dumpConfig(pw)
            "help" -> dumpHelp(pw)
            else -> dumpTargets(args.nonFlagArgs, pw, args)
            else -> {
                if (args.proto) {
                    dumpProtoTargets(args.nonFlagArgs, fd, args)
                } else {
                    dumpTargets(args.nonFlagArgs, pw, args)
                }
            }
        }
    }

@@ -160,6 +173,26 @@ class DumpHandler @Inject constructor(
        }
    }

    private fun dumpProtoTargets(
            targets: List<String>,
            fd: FileDescriptor,
            args: ParsedArgs
    ) {
        val systemUIProto = SystemUIProtoDump()
        if (targets.isNotEmpty()) {
            for (target in targets) {
                dumpManager.dumpProtoTarget(target, systemUIProto, args.rawArgs)
            }
        } else {
            dumpManager.dumpProtoDumpables(systemUIProto, args.rawArgs)
        }
        val buffer = BufferedOutputStream(FileOutputStream(fd))
        buffer.use {
            it.write(MessageNano.toByteArray(systemUIProto))
            it.flush()
        }
    }

    private fun dumpTargets(
        targets: List<String>,
        pw: PrintWriter,
@@ -267,6 +300,7 @@ class DumpHandler @Inject constructor(
                            }
                        }
                    }
                    PROTO -> pArgs.proto = true
                    "-t", "--tail" -> {
                        pArgs.tailLength = readArgument(iterator, arg) {
                            it.toInt()
@@ -278,6 +312,9 @@ class DumpHandler @Inject constructor(
                    "-h", "--help" -> {
                        pArgs.command = "help"
                    }
                    // This flag is passed as part of the proto dump in Bug reports, we can ignore
                    // it because this is our default behavior.
                    "-a" -> {}
                    else -> {
                        throw ArgParseException("Unknown flag: $arg")
                    }
@@ -314,7 +351,7 @@ class DumpHandler @Inject constructor(
        const val PRIORITY_ARG_CRITICAL = "CRITICAL"
        const val PRIORITY_ARG_HIGH = "HIGH"
        const val PRIORITY_ARG_NORMAL = "NORMAL"
        const val PROTO = "--sysui_proto"
        const val PROTO = "--proto"
    }
}

@@ -338,6 +375,7 @@ private class ParsedArgs(
    var tailLength: Int = 0
    var command: String? = null
    var listOnly = false
    var proto = false
}

class ArgParseException(message: String) : Exception(message)
Loading