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

Commit 9d6f51c7 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic 'dumpstate-hidlize'

* changes:
  Moved DumpstateUtil.h functions to its own namespace.
  dumpstate: remove references to legacy dumpstate
parents 7a74a7cc 47e9be2d
Loading
Loading
Loading
Loading
+4 −17
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 #
@@ -107,8 +107,6 @@ LOCAL_SHARED_LIBRARIES := $(COMMON_SHARED_LIBRARIES) \

LOCAL_STATIC_LIBRARIES := $(COMMON_STATIC_LIBRARIES)

LOCAL_HAL_STATIC_LIBRARIES := libdumpstate

LOCAL_CFLAGS += $(COMMON_LOCAL_CFLAGS)

LOCAL_INIT_RC := dumpstate.rc
@@ -181,14 +179,3 @@ LOCAL_GENERATED_SOURCES += $(GEN)
LOCAL_PICKUP_FILES := $(dumpstate_tests_intermediates)

include $(BUILD_NATIVE_TEST)

# =======================#
# libdumpstate.default #
# =======================#
include $(CLEAR_VARS)

LOCAL_SRC_FILES := libdumpstate_default.cpp
LOCAL_MODULE := libdumpstate.default

LOCAL_STATIC_LIBRARIES := libdumpstateheaders
include $(BUILD_STATIC_LIBRARY)
+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_
+24 −12
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;
@@ -107,6 +113,9 @@ static int DumpFile(const std::string& title, const std::string& path) {
// Relative directory (inside the zip) for all files copied as-is into the bugreport.
static const std::string ZIP_ROOT_DIR = "FS";

// Must be hardcoded because dumpstate HAL implementation need SELinux access to it
static const std::string kDumpstateBoardPath = "/bugreports/dumpstate_board.txt";

static constexpr char PROPERTY_EXTRA_OPTIONS[] = "dumpstate.options";
static constexpr char PROPERTY_LAST_ID[] = "dumpstate.last_id";
static constexpr char PROPERTY_VERSION[] = "dumpstate.version";
@@ -1026,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");
@@ -1043,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");

@@ -1080,7 +1089,7 @@ static void dumpstate() {

    ds.DumpstateBoard();

    /* Migrate the ril_dumpstate to a dumpstate_board()? */
    /* Migrate the ril_dumpstate to a device specific dumpstate? */
    int rilDumpstateTimeout = android::base::GetIntProperty("ril.dumpstate.timeout", 0);
    if (rilDumpstateTimeout > 0) {
        // su does not exist on user builds, so try running without it.
@@ -1149,21 +1158,18 @@ void Dumpstate::DumpstateBoard() {
    printf("== Board\n");
    printf("========================================================\n");

    ::android::sp<IDumpstateDevice> dumpstate_device(
        IDumpstateDevice::getService("DumpstateDevice"));
    ::android::sp<IDumpstateDevice> dumpstate_device(IDumpstateDevice::getService("dumpstate"));
    if (dumpstate_device == nullptr) {
        // TODO: temporary workaround until devices on master implement it
        MYLOGE("no IDumpstateDevice implementation; using legacy dumpstate_board()\n");
        dumpstate_board();
        MYLOGE("No IDumpstateDevice implementation\n");
        return;
    }

    if (!IsZipping()) {
        MYLOGE("Not dumping board info because it's not a zipped bugreport\n");
        MYLOGD("Not dumping board info because it's not a zipped bugreport\n");
        return;
    }

    std::string path = ds.GetPath("-dumpstate-board.txt");
    std::string path = kDumpstateBoardPath;
    MYLOGI("Calling IDumpstateDevice implementation using path %s\n", path.c_str());

    int fd =
@@ -1182,7 +1188,13 @@ void Dumpstate::DumpstateBoard() {
    handle->data[0] = fd;

    // TODO: need a timeout mechanism so dumpstate does not hang on device implementation call.
    dumpstate_device->dumpstateBoard(handle);
    android::hardware::Return<void> status = dumpstate_device->dumpstateBoard(handle);
    if (!status.isOk()) {
        MYLOGE("dumpstateBoard failed: %s\n", status.description().c_str());
        native_handle_close(handle);
        native_handle_delete(handle);
        return;
    }

    AddZipEntry("dumpstate-board.txt", path);
    printf("*** See dumpstate-board.txt entry ***\n");
+20 −11
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.
@@ -399,9 +411,6 @@ void dump_route_tables();
/* Play a sound via Stagefright */
void play_sound(const char *path);

/* Implemented by libdumpstate_board to dump board-specific info */
void dumpstate_board();

/* Checks if a given path is a directory. */
bool is_dir(const char* pathname);

Loading