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

Commit c8fc5bce authored by Terry Guan's avatar Terry Guan Committed by Automerger Merge Worker
Browse files

Merge "Added debug statement and refresh in default vehicle hal" into udc-dev...

Merge "Added debug statement and refresh in default vehicle hal" into udc-dev am: 9368d6dc am: 85488e6c

Original change: https://googleplex-android-review.googlesource.com/c/platform/hardware/interfaces/+/22531494



Change-Id: I3e991e07098d155d7563d4d995a155063f559800
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 6fc238c1 85488e6c
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -159,6 +159,7 @@ class FakeVehicleHardware : public IVehicleHardware {
    const std::string mDefaultConfigDir;
    const std::string mDefaultConfigDir;
    const std::string mOverrideConfigDir;
    const std::string mOverrideConfigDir;
    const bool mForceOverride;
    const bool mForceOverride;
    bool mAddExtraTestVendorConfigs;


    // Only used during initialization.
    // Only used during initialization.
    JsonConfigLoader mLoader;
    JsonConfigLoader mLoader;
@@ -248,6 +249,8 @@ class FakeVehicleHardware : public IVehicleHardware {
    std::string genFakeDataCommand(const std::vector<std::string>& options);
    std::string genFakeDataCommand(const std::vector<std::string>& options);
    void sendHvacPropertiesCurrentValues(int32_t areaId);
    void sendHvacPropertiesCurrentValues(int32_t areaId);
    void sendAdasPropertiesState(int32_t propertyId, int32_t state);
    void sendAdasPropertiesState(int32_t propertyId, int32_t state);
    void generateVendorConfigs(
            std::vector<aidl::android::hardware::automotive::vehicle::VehiclePropConfig>&) const;


    static aidl::android::hardware::automotive::vehicle::VehiclePropValue createHwInputKeyProp(
    static aidl::android::hardware::automotive::vehicle::VehiclePropValue createHwInputKeyProp(
            aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction action,
            aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction action,
+37 −1
Original line number Original line Diff line number Diff line
@@ -64,6 +64,7 @@ using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReq;
using ::aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction;
using ::aidl::android::hardware::automotive::vehicle::VehicleHwKeyInputAction;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropConfig;
using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
using ::aidl::android::hardware::automotive::vehicle::VehicleProperty;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyAccess;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyGroup;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyStatus;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyStatus;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType;
@@ -79,6 +80,11 @@ using ::android::base::ScopedLockAssertion;
using ::android::base::StartsWith;
using ::android::base::StartsWith;
using ::android::base::StringPrintf;
using ::android::base::StringPrintf;


// In order to test large number of vehicle property configs, we might generate additional fake
// property config start from this ID. Note these fake properties are for getAllPropertyConfigs
// testing only.
constexpr int32_t STARTING_VENDOR_CODE_PROPERTIES_FOR_TEST = 0x5000;
constexpr int32_t NUMBER_OF_TEST_VENDOR_CODES = 0x3000;
// The directory for default property configuration file.
// The directory for default property configuration file.
// For config file format, see impl/default_config/config/README.md.
// For config file format, see impl/default_config/config/README.md.
constexpr char DEFAULT_CONFIG_DIR[] = "/vendor/etc/automotive/vhalconfig/";
constexpr char DEFAULT_CONFIG_DIR[] = "/vendor/etc/automotive/vhalconfig/";
@@ -291,7 +297,11 @@ void FakeVehicleHardware::init() {
}
}


std::vector<VehiclePropConfig> FakeVehicleHardware::getAllPropertyConfigs() const {
std::vector<VehiclePropConfig> FakeVehicleHardware::getAllPropertyConfigs() const {
    return mServerSidePropStore->getAllConfigs();
    std::vector<VehiclePropConfig> allConfigs = mServerSidePropStore->getAllConfigs();
    if (mAddExtraTestVendorConfigs) {
        generateVendorConfigs(/* outAllConfigs= */ allConfigs);
    }
    return allConfigs;
}
}


VehiclePropValuePool::RecyclableType FakeVehicleHardware::createApPowerStateReq(
VehiclePropValuePool::RecyclableType FakeVehicleHardware::createApPowerStateReq(
@@ -953,6 +963,12 @@ DumpResult FakeVehicleHardware::dump(const std::vector<std::string>& options) {
        result.buffer = mFakeUserHal->dump();
        result.buffer = mFakeUserHal->dump();
    } else if (EqualsIgnoreCase(option, "--genfakedata")) {
    } else if (EqualsIgnoreCase(option, "--genfakedata")) {
        result.buffer = genFakeDataCommand(options);
        result.buffer = genFakeDataCommand(options);
    } else if (EqualsIgnoreCase(option, "--genTestVendorConfigs")) {
        mAddExtraTestVendorConfigs = true;
        result.refreshPropertyConfigs = true;
    } else if (EqualsIgnoreCase(option, "--restoreVendorConfigs")) {
        mAddExtraTestVendorConfigs = false;
        result.refreshPropertyConfigs = true;
    } else {
    } else {
        result.buffer = StringPrintf("Invalid option: %s\n", option.c_str());
        result.buffer = StringPrintf("Invalid option: %s\n", option.c_str());
    }
    }
@@ -1003,6 +1019,13 @@ provided, it would iterate indefinitely.
  [pressure(float)] [size(float)]
  [pressure(float)] [size(float)]
  Generate a motion input event. --pointer option can be specified multiple times.
  Generate a motion input event. --pointer option can be specified multiple times.


--genTestVendorConfigs: Generates fake VehiclePropConfig ranging from 0x5000 to 0x8000 all with
  vendor property group, global vehicle area, and int32 vehicle property type. This is mainly used
  for testing

--restoreVendorConfigs: Restores to to the default state if genTestVendorConfigs was used.
  Otherwise this will do nothing.

)";
)";
}
}


@@ -1012,6 +1035,19 @@ std::string FakeVehicleHardware::parseErrMsg(std::string fieldName, std::string
                        value.c_str(), genFakeDataHelp().c_str());
                        value.c_str(), genFakeDataHelp().c_str());
}
}


void FakeVehicleHardware::generateVendorConfigs(
        std::vector<VehiclePropConfig>& outAllConfigs) const {
    for (int i = STARTING_VENDOR_CODE_PROPERTIES_FOR_TEST;
         i < STARTING_VENDOR_CODE_PROPERTIES_FOR_TEST + NUMBER_OF_TEST_VENDOR_CODES; i++) {
        VehiclePropConfig config;
        config.prop = i | toInt(propertyutils_impl::VehiclePropertyGroup::VENDOR) |
                      toInt(propertyutils_impl::VehicleArea::GLOBAL) |
                      toInt(propertyutils_impl::VehiclePropertyType::INT32);
        config.access = VehiclePropertyAccess::READ_WRITE;
        outAllConfigs.push_back(config);
    }
}

std::string FakeVehicleHardware::genFakeDataCommand(const std::vector<std::string>& options) {
std::string FakeVehicleHardware::genFakeDataCommand(const std::vector<std::string>& options) {
    if (options.size() < 2) {
    if (options.size() < 2) {
        return "No subcommand specified for genfakedata\n" + genFakeDataHelp();
        return "No subcommand specified for genfakedata\n" + genFakeDataHelp();
+2 −0
Original line number Original line Diff line number Diff line
@@ -35,6 +35,8 @@ struct DumpResult {
    bool callerShouldDumpState;
    bool callerShouldDumpState;
    // The dumped information for the caller to print.
    // The dumped information for the caller to print.
    std::string buffer;
    std::string buffer;
    // To pass if DefaultVehicleHal should refresh the property configs
    bool refreshPropertyConfigs = false;
};
};


// A structure to represent a set value error event reported from vehicle.
// A structure to represent a set value error event reported from vehicle.
+3 −1
Original line number Original line Diff line number Diff line
@@ -164,6 +164,7 @@ class DefaultVehicleHal final : public aidl::android::hardware::automotive::vehi
    static constexpr int64_t TIMEOUT_IN_NANO = 30'000'000'000;
    static constexpr int64_t TIMEOUT_IN_NANO = 30'000'000'000;
    // heart beat event interval: 3s
    // heart beat event interval: 3s
    static constexpr int64_t HEART_BEAT_INTERVAL_IN_NANO = 3'000'000'000;
    static constexpr int64_t HEART_BEAT_INTERVAL_IN_NANO = 3'000'000'000;
    bool mShouldRefreshPropertyConfigs;
    std::unique_ptr<IVehicleHardware> mVehicleHardware;
    std::unique_ptr<IVehicleHardware> mVehicleHardware;


    // mConfigsByPropId and mConfigFile are only modified during initialization, so no need to
    // mConfigsByPropId and mConfigFile are only modified during initialization, so no need to
@@ -212,7 +213,6 @@ class DefaultVehicleHal final : public aidl::android::hardware::automotive::vehi
    android::base::Result<std::vector<int64_t>> checkDuplicateRequests(
    android::base::Result<std::vector<int64_t>> checkDuplicateRequests(
            const std::vector<aidl::android::hardware::automotive::vehicle::SetValueRequest>&
            const std::vector<aidl::android::hardware::automotive::vehicle::SetValueRequest>&
                    requests);
                    requests);

    VhalResult<void> checkSubscribeOptions(
    VhalResult<void> checkSubscribeOptions(
            const std::vector<aidl::android::hardware::automotive::vehicle::SubscribeOptions>&
            const std::vector<aidl::android::hardware::automotive::vehicle::SubscribeOptions>&
                    options);
                    options);
@@ -236,6 +236,8 @@ class DefaultVehicleHal final : public aidl::android::hardware::automotive::vehi


    bool checkDumpPermission();
    bool checkDumpPermission();


    bool getAllPropConfigsFromHardware();

    // The looping handler function to process all onBinderDied or onBinderUnlinked events in
    // The looping handler function to process all onBinderDied or onBinderUnlinked events in
    // mBinderEvents.
    // mBinderEvents.
    void onBinderDiedUnlinkedHandler();
    void onBinderDiedUnlinkedHandler();
+25 −14
Original line number Original line Diff line number Diff line
@@ -128,23 +128,10 @@ size_t DefaultVehicleHal::SubscriptionClients::countClients() {
DefaultVehicleHal::DefaultVehicleHal(std::unique_ptr<IVehicleHardware> vehicleHardware)
DefaultVehicleHal::DefaultVehicleHal(std::unique_ptr<IVehicleHardware> vehicleHardware)
    : mVehicleHardware(std::move(vehicleHardware)),
    : mVehicleHardware(std::move(vehicleHardware)),
      mPendingRequestPool(std::make_shared<PendingRequestPool>(TIMEOUT_IN_NANO)) {
      mPendingRequestPool(std::make_shared<PendingRequestPool>(TIMEOUT_IN_NANO)) {
    auto configs = mVehicleHardware->getAllPropertyConfigs();
    if (!getAllPropConfigsFromHardware()) {
    for (auto& config : configs) {
        mConfigsByPropId[config.prop] = config;
    }
    VehiclePropConfigs vehiclePropConfigs;
    vehiclePropConfigs.payloads = std::move(configs);
    auto result = LargeParcelableBase::parcelableToStableLargeParcelable(vehiclePropConfigs);
    if (!result.ok()) {
        ALOGE("failed to convert configs to shared memory file, error: %s, code: %d",
              result.error().message().c_str(), static_cast<int>(result.error().code()));
        return;
        return;
    }
    }


    if (result.value() != nullptr) {
        mConfigFile = std::move(result.value());
    }

    mSubscriptionClients = std::make_shared<SubscriptionClients>(mPendingRequestPool);
    mSubscriptionClients = std::make_shared<SubscriptionClients>(mPendingRequestPool);


    auto subscribeIdByClient = std::make_shared<SubscribeIdByClient>();
    auto subscribeIdByClient = std::make_shared<SubscribeIdByClient>();
@@ -304,6 +291,27 @@ void DefaultVehicleHal::setTimeout(int64_t timeoutInNano) {
    mPendingRequestPool = std::make_unique<PendingRequestPool>(timeoutInNano);
    mPendingRequestPool = std::make_unique<PendingRequestPool>(timeoutInNano);
}
}


bool DefaultVehicleHal::getAllPropConfigsFromHardware() {
    auto configs = mVehicleHardware->getAllPropertyConfigs();
    for (auto& config : configs) {
        mConfigsByPropId[config.prop] = config;
    }
    VehiclePropConfigs vehiclePropConfigs;
    vehiclePropConfigs.payloads = std::move(configs);
    auto result = LargeParcelableBase::parcelableToStableLargeParcelable(vehiclePropConfigs);
    if (!result.ok()) {
        ALOGE("failed to convert configs to shared memory file, error: %s, code: %d",
              result.error().message().c_str(), static_cast<int>(result.error().code()));
        mConfigFile = nullptr;
        return false;
    }

    if (result.value() != nullptr) {
        mConfigFile = std::move(result.value());
    }
    return true;
}

ScopedAStatus DefaultVehicleHal::getAllPropConfigs(VehiclePropConfigs* output) {
ScopedAStatus DefaultVehicleHal::getAllPropConfigs(VehiclePropConfigs* output) {
    if (mConfigFile != nullptr) {
    if (mConfigFile != nullptr) {
        output->payloads.clear();
        output->payloads.clear();
@@ -798,6 +806,9 @@ binder_status_t DefaultVehicleHal::dump(int fd, const char** args, uint32_t numA
        options.clear();
        options.clear();
    }
    }
    DumpResult result = mVehicleHardware->dump(options);
    DumpResult result = mVehicleHardware->dump(options);
    if (result.refreshPropertyConfigs) {
        getAllPropConfigsFromHardware();
    }
    dprintf(fd, "%s", (result.buffer + "\n").c_str());
    dprintf(fd, "%s", (result.buffer + "\n").c_str());
    if (!result.callerShouldDumpState) {
    if (!result.callerShouldDumpState) {
        return STATUS_OK;
        return STATUS_OK;