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

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

Merge "Added VehicleHal.dump()"

parents 3c95f637 2acb9a7e
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -65,6 +65,12 @@ class IVehicleClient {
    // updateStatus is true if and only if the value is
    // generated by car (ECU/fake generator/injected)
    virtual void onPropertyValue(const VehiclePropValue& value, bool updateStatus) = 0;

    // Dump method forwarded from HIDL's debug()
    // If implemented, it must return whether the caller should dump its state.
    virtual bool dump(const hidl_handle& /* handle */, const hidl_vec<hidl_string>& /* options */) {
        return true;
    }
};

/**
@@ -97,6 +103,13 @@ class IVehicleServer {
    // updateStatus is true if and only if the value is
    // generated by car (ECU/fake generator/injected)
    virtual void onPropertyValueFromCar(const VehiclePropValue& value, bool updateStatus) = 0;

    // Dump method forwarded from HIDL's debug()
    // If implemented, it must return whether the caller should dump its state.
    virtual bool onDump(const hidl_handle& /* handle */,
                        const hidl_vec<hidl_string>& /* options */) {
        return true;
    }
};

/**
@@ -134,6 +147,10 @@ class IPassThroughConnector : public VehicleClientType, public VehicleServerType
        return this->onPropertyValue(value, updateStatus);
    }

    bool dump(const hidl_handle& handle, const hidl_vec<hidl_string>& options) override {
        return this->onDump(handle, options);
    }

    // To be implemented:
    // virtual std::vector<VehiclePropConfig> onGetAllPropertyConfig() = 0;
    // virtual void onPropertyValue(const VehiclePropValue& value) = 0;
+20 −0
Original line number Diff line number Diff line
@@ -70,6 +70,26 @@ public:
     */
    virtual void onCreate() {}

    /**
     * Dump method forwarded from HIDL's debug().
     *
     * By default it doesn't dump anything and let caller dump its properties, but it could be
     * override to change the behavior. For example:
     *
     * - To augment caller's dump, it should dump its state and return true.
     * - To not dump anything at all, it should just return false.
     * - To provide custom dump (like dumping just specific state or executing a custom command),
     *   it should check if options is not empty, handle the options accordingly, then return false.
     *
     * @param handle handle used to dump the contents.
     * @param options options passed to dump.
     *
     * @return whether the caller should dump its state.
     */
    virtual bool dump(const hidl_handle& /* handle */, const hidl_vec<hidl_string>& /* options */) {
        return true;
    }

    void init(
        VehiclePropValuePool* valueObjectPool,
        const HalEventFunction& onHalEvent,
+11 −3
Original line number Diff line number Diff line
@@ -186,11 +186,19 @@ Return<void> VehicleHalManager::debugDump(IVehicle::debugDump_cb _hidl_cb) {
}

Return<void> VehicleHalManager::debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options) {
    if (fd.getNativeHandle() != nullptr && fd->numFds > 0) {
        cmdDump(fd->data[0], options);
    } else {
    if (fd.getNativeHandle() == nullptr || fd->numFds == 0) {
        ALOGE("Invalid parameters passed to debug()");
        return Void();
    }

    bool shouldContinue = mHal->dump(fd, options);
    if (!shouldContinue) {
        ALOGI("Dumped HAL only");
        return Void();
    }

    // Do our dump
    cmdDump(fd->data[0], options);
    return Void();
}

+39 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

#define LOG_TAG "automotive.vehicle@2.0-connector"

#include <fstream>

#include <android-base/logging.h>
#include <utils/SystemClock.h>

@@ -370,6 +372,43 @@ StatusCode EmulatedVehicleServer::onSetInitialUserInfo(const VehiclePropValue& v
    return StatusCode::OK;
}

bool EmulatedVehicleServer::onDump(const hidl_handle& handle,
                                   const hidl_vec<hidl_string>& options) {
    int fd = handle->data[0];

    if (options.size() > 0) {
        if (options[0] == "--help") {
            dprintf(fd, "Emulator-specific usage:\n");
            dprintf(fd, "--user-hal: dumps state used for user management \n");
            dprintf(fd, "\n");
            // Include caller's help options
            return true;
        } else if (options[0] == "--user-hal") {
            dumpUserHal(fd, "");
            return false;

        } else {
            // Let caller handle the options...
            return true;
        }
    }

    dprintf(fd, "Emulator-specific state:\n");
    dumpUserHal(fd, "  ");
    dprintf(fd, "\n");

    return true;
}

void EmulatedVehicleServer::dumpUserHal(int fd, std::string indent) {
    if (mInitialUserResponseFromCmd != nullptr) {
        dprintf(fd, "%sInitial User Info: %s\n", indent.c_str(),
                toString(*mInitialUserResponseFromCmd).c_str());
    } else {
        dprintf(fd, "%sNo Initial User Info\n", indent.c_str());
    }
}

EmulatedPassthroughConnectorPtr makeEmulatedPassthroughConnector() {
    return std::make_unique<EmulatedPassthroughConnector>();
}
+3 −0
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ class EmulatedVehicleServer : public IVehicleServer {

    StatusCode onSetProperty(const VehiclePropValue& value, bool updateStatus) override;

    bool onDump(const hidl_handle& fd, const hidl_vec<hidl_string>& options) override;

    // Set the Property Value Pool used in this server
    void setValuePool(VehiclePropValuePool* valuePool);

@@ -81,6 +83,7 @@ class EmulatedVehicleServer : public IVehicleServer {
    // TODO(b/146207078): it might be clearer to move members below to an EmulatedUserHal class
    std::unique_ptr<VehiclePropValue> mInitialUserResponseFromCmd;
    StatusCode onSetInitialUserInfo(const VehiclePropValue& value, bool updateStatus);
    void dumpUserHal(int fd, std::string indent);
};

// Helper functions
Loading