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

Commit 47e9be2d authored by Felipe Leme's avatar Felipe Leme
Browse files

Moved DumpstateUtil.h functions to its own namespace.

Also make it a shared library.

Test: dumpstate_test passes
Test: manual verification

Bug: 26379932

Change-Id: I75dd3ef9fec3ac692a132bdd8c68307c1a1ee602
parent 7440ddb7
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -21,12 +21,11 @@ COMMON_SHARED_LIBRARIES := \
        libbinder \
        libcutils \
        libdumpstateaidl \
        libdumpstateutil \
        liblog \
        libselinux \
        libutils \
        $(COMMON_ZIP_LIBRARIES)
COMMON_STATIC_LIBRARIES := \
        libdumpstateutil

# ====================#
# libdumpstateutil #
@@ -42,9 +41,10 @@ LOCAL_SRC_FILES := \
        DumpstateInternal.cpp \
        DumpstateUtil.cpp
LOCAL_SHARED_LIBRARIES := \
        libbase
        libbase \
        liblog \

include $(BUILD_STATIC_LIBRARY)
include $(BUILD_SHARED_LIBRARY)

# ====================#
# libdumpstateheaders #
+11 −3
Original line number Diff line number Diff line
@@ -34,10 +34,14 @@

#include "DumpstateInternal.h"

// TODO: move to unnamed namespace
namespace android {
namespace os {
namespace dumpstate {

namespace {

static constexpr const char* kSuPath = "/system/xbin/su";

// TODO: move to unnamed namespace
static bool waitpid_with_timeout(pid_t pid, int timeout_seconds, int* status) {
    sigset_t child_mask, old_mask;
    sigemptyset(&child_mask);
@@ -81,10 +85,10 @@ static bool waitpid_with_timeout(pid_t pid, int timeout_seconds, int* status) {
    }
    return true;
}
}  // unnamed namespace

CommandOptions CommandOptions::DEFAULT = CommandOptions::WithTimeout(10).Build();
CommandOptions CommandOptions::AS_ROOT = CommandOptions::WithTimeout(10).AsRoot().Build();
CommandOptions CommandOptions::AS_ROOT_5 = CommandOptions::WithTimeout(5).AsRoot().Build();

CommandOptions::CommandOptionsBuilder::CommandOptionsBuilder(int64_t timeout) : values(timeout) {
}
@@ -374,3 +378,7 @@ int GetPidByName(const std::string& ps_name) {
    closedir(proc_dir);
    return -1;
}

}  // namespace dumpstate
}  // namespace os
}  // namespace android
+10 −7
Original line number Diff line number Diff line
@@ -13,13 +13,15 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef FRAMEWORK_NATIVE_CMD_DUMPSTATE_UTIL_H_
#define FRAMEWORK_NATIVE_CMD_DUMPSTATE_UTIL_H_
#ifndef ANDROID_OS_DUMPSTATE_UTIL_H_
#define ANDROID_OS_DUMPSTATE_UTIL_H_

#include <cstdint>
#include <string>

// TODO: use android::os::dumpstate (must wait until device code is refactored)
namespace android {
namespace os {
namespace dumpstate {

/*
 * Defines the Linux account that should be executing a command.
@@ -120,9 +122,6 @@ class CommandOptions {
    // Common options.
    static CommandOptions DEFAULT;
    static CommandOptions AS_ROOT;

    // TODO: temporary, until device implementations use AS_ROOT
    static CommandOptions AS_ROOT_5;
};

/*
@@ -180,4 +179,8 @@ int DumpFileToFd(int fd, const std::string& title, const std::string& path);
 */
int GetPidByName(const std::string& ps_name);

#endif  // FRAMEWORK_NATIVE_CMD_DUMPSTATE_UTIL_H_
}  // namespace dumpstate
}  // namespace os
}  // namespace android

#endif  // ANDROID_OS_DUMPSTATE_UTIL_H_
+9 −3
Original line number Diff line number Diff line
@@ -57,6 +57,12 @@ using ::android::hardware::dumpstate::V1_0::IDumpstateDevice;
using ::android::hardware::vibrator::V1_0::IVibrator;
using VibratorStatus = ::android::hardware::vibrator::V1_0::Status;

// TODO: remove once moved to namespace
using android::os::dumpstate::CommandOptions;
using android::os::dumpstate::DumpFileToFd;
using android::os::dumpstate::PropertiesHelper;
using android::os::dumpstate::GetPidByName;

/* read before root is shed */
static char cmdline_buf[16384] = "(unknown)";
static const char *dump_traces_path = NULL;
@@ -1029,11 +1035,11 @@ static void dumpstate() {
               CommandOptions::WithTimeout(20).Build());

#ifdef FWDUMP_bcmdhd
    RunCommand("ND OFFLOAD TABLE", {WLUTIL, "nd_hostip"}, CommandOptions::AS_ROOT_5);
    RunCommand("ND OFFLOAD TABLE", {WLUTIL, "nd_hostip"}, CommandOptions::AS_ROOT);

    RunCommand("DUMP WIFI INTERNAL COUNTERS (1)", {WLUTIL, "counters"}, AS_ROOT_20);

    RunCommand("ND OFFLOAD STATUS (1)", {WLUTIL, "nd_status"}, CommandOptions::AS_ROOT_5);
    RunCommand("ND OFFLOAD STATUS (1)", {WLUTIL, "nd_status"}, CommandOptions::AS_ROOT);

#endif
    DumpFile("INTERRUPTS (1)", "/proc/interrupts");
@@ -1046,7 +1052,7 @@ static void dumpstate() {

    RunCommand("DUMP WIFI INTERNAL COUNTERS (2)", {WLUTIL, "counters"}, AS_ROOT_20);

    RunCommand("ND OFFLOAD STATUS (2)", {WLUTIL, "nd_status"}, CommandOptions::AS_ROOT_5);
    RunCommand("ND OFFLOAD STATUS (2)", {WLUTIL, "nd_status"}, CommandOptions::AS_ROOT);
#endif
    DumpFile("INTERRUPTS (2)", "/proc/interrupts");

+20 −8
Original line number Diff line number Diff line
@@ -36,6 +36,19 @@
// TODO: remove once not used
#define MAX_ARGS_ARRAY_SIZE 1000

// TODO: move everything under this namespace
// TODO: and then remove explicitly android::os::dumpstate:: prefixes
namespace android {
namespace os {
namespace dumpstate {

class DumpstateTest;
class ProgressTest;

}  // namespace dumpstate
}  // namespace os
}  // namespace android

// TODO: remove once moved to HAL
#ifdef __cplusplus
extern "C" {
@@ -74,8 +87,8 @@ class DurationReporter {
 *
 */
class Progress {
    friend class ProgressTest;
    friend class DumpstateTest;
    friend class android::os::dumpstate::ProgressTest;
    friend class android::os::dumpstate::DumpstateTest;

  public:
    /*
@@ -152,13 +165,10 @@ class Dumpstate {
    friend class DumpstateTest;

  public:
    static CommandOptions DEFAULT_DUMPSYS;
    static android::os::dumpstate::CommandOptions DEFAULT_DUMPSYS;

    static Dumpstate& GetInstance();

    // TODO: temporary function until device code uses PropertiesHelper::IsUserBuild()
    bool IsUserBuild();

    /* Checkes whether dumpstate is generating a zipped bugreport. */
    bool IsZipping() const;

@@ -172,7 +182,8 @@ class Dumpstate {
     * |options| optional argument defining the command's behavior.
     */
    int RunCommand(const std::string& title, const std::vector<std::string>& fullCommand,
                   const CommandOptions& options = CommandOptions::DEFAULT);
                   const android::os::dumpstate::CommandOptions& options =
                       android::os::dumpstate::CommandOptions::DEFAULT);

    /*
     * Runs `dumpsys` with the given arguments, automatically setting its timeout
@@ -187,7 +198,8 @@ class Dumpstate {
     * timeout from `options`)
     */
    void RunDumpsys(const std::string& title, const std::vector<std::string>& dumpsys_args,
                    const CommandOptions& options = DEFAULT_DUMPSYS, long dumpsys_timeout = 0);
                    const android::os::dumpstate::CommandOptions& options = DEFAULT_DUMPSYS,
                    long dumpsys_timeout = 0);

    /*
     * Prints the contents of a file.
Loading