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

Commit e1d7073f authored by Yu Shan's avatar Yu Shan Committed by Automerger Merge Worker
Browse files

Merge "Inject getS2rS2dConfig through constructor." into main am: f74d9911 am: 3daaa5c4

parents f4ff6b67 3daaa5c4
Loading
Loading
Loading
Loading
+8 −12
Original line number Original line Diff line number Diff line
@@ -49,11 +49,6 @@ namespace fake {


class FakeVehicleHardware : public IVehicleHardware {
class FakeVehicleHardware : public IVehicleHardware {
  public:
  public:
    // Supports Suspend_to_ram.
    static constexpr int32_t SUPPORT_S2R = 0x1;
    // Supports Suspend_to_disk.
    static constexpr int32_t SUPPORT_S2D = 0x4;

    using ValueResultType = VhalResult<VehiclePropValuePool::RecyclableType>;
    using ValueResultType = VhalResult<VehiclePropValuePool::RecyclableType>;


    FakeVehicleHardware();
    FakeVehicleHardware();
@@ -61,6 +56,13 @@ class FakeVehicleHardware : public IVehicleHardware {
    FakeVehicleHardware(std::string defaultConfigDir, std::string overrideConfigDir,
    FakeVehicleHardware(std::string defaultConfigDir, std::string overrideConfigDir,
                        bool forceOverride);
                        bool forceOverride);


    // s2rS2dConfig is the config for whether S2R or S2D is supported, must be a bit flag combining
    // values from VehicleApPowerStateConfigFlag.
    // The default implementation is reading this from system property:
    // "ro.vendor.fake_vhal.ap_power_state_req.config".
    FakeVehicleHardware(std::string defaultConfigDir, std::string overrideConfigDir,
                        bool forceOverride, int32_t s2rS2dConfig);

    ~FakeVehicleHardware();
    ~FakeVehicleHardware();


    // Get all the property configs.
    // Get all the property configs.
@@ -122,12 +124,6 @@ class FakeVehicleHardware : public IVehicleHardware {


    bool UseOverrideConfigDir();
    bool UseOverrideConfigDir();


    // Gets the config whether S2R or S2D is supported, must returns a bit flag made up of
    // SUPPORT_S2R and SUPPORT_S2D, for example, 0x0 means no support, 0x5 means support both.
    // The default implementation is reading this from system property:
    // "ro.vendor.fake_vhal.ap_power_state_req.config".
    int32_t getS2rS2dConfig();

  private:
  private:
    // Expose private methods to unit test.
    // Expose private methods to unit test.
    friend class FakeVehicleHardwareTestHelper;
    friend class FakeVehicleHardwareTestHelper;
@@ -204,7 +200,7 @@ class FakeVehicleHardware : public IVehicleHardware {
    // provides power controlling related properties.
    // provides power controlling related properties.
    std::string mPowerControllerServiceAddress = "";
    std::string mPowerControllerServiceAddress = "";


    void init();
    void init(int32_t s2rS2dConfig);
    // Stores the initial value to property store.
    // Stores the initial value to property store.
    void storePropInitialValue(const ConfigDeclaration& config);
    void storePropInitialValue(const ConfigDeclaration& config);
    // The callback that would be called when a vehicle property value change happens.
    // The callback that would be called when a vehicle property value change happens.
+10 −7
Original line number Original line Diff line number Diff line
@@ -348,6 +348,13 @@ FakeVehicleHardware::FakeVehicleHardware()


FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir,
FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir,
                                         std::string overrideConfigDir, bool forceOverride)
                                         std::string overrideConfigDir, bool forceOverride)
    : FakeVehicleHardware(defaultConfigDir, overrideConfigDir, forceOverride,
                          /*s2rS2dConfig=*/
                          GetIntProperty(POWER_STATE_REQ_CONFIG_PROPERTY, /*default_value=*/0)) {}

FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir,
                                         std::string overrideConfigDir, bool forceOverride,
                                         int32_t s2rS2dConfig)
    : mValuePool(std::make_unique<VehiclePropValuePool>()),
    : mValuePool(std::make_unique<VehiclePropValuePool>()),
      mServerSidePropStore(new VehiclePropertyStore(mValuePool)),
      mServerSidePropStore(new VehiclePropertyStore(mValuePool)),
      mDefaultConfigDir(defaultConfigDir),
      mDefaultConfigDir(defaultConfigDir),
@@ -360,7 +367,7 @@ FakeVehicleHardware::FakeVehicleHardware(std::string defaultConfigDir,
      mPendingGetValueRequests(this),
      mPendingGetValueRequests(this),
      mPendingSetValueRequests(this),
      mPendingSetValueRequests(this),
      mForceOverride(forceOverride) {
      mForceOverride(forceOverride) {
    init();
    init(s2rS2dConfig);
}
}


FakeVehicleHardware::~FakeVehicleHardware() {
FakeVehicleHardware::~FakeVehicleHardware() {
@@ -388,7 +395,7 @@ std::unordered_map<int32_t, ConfigDeclaration> FakeVehicleHardware::loadConfigDe
    return configsByPropId;
    return configsByPropId;
}
}


void FakeVehicleHardware::init() {
void FakeVehicleHardware::init(int32_t s2rS2dConfig) {
    maybeGetGrpcServiceInfo(&mPowerControllerServiceAddress);
    maybeGetGrpcServiceInfo(&mPowerControllerServiceAddress);


    for (auto& [_, configDeclaration] : loadConfigDeclarations()) {
    for (auto& [_, configDeclaration] : loadConfigDeclarations()) {
@@ -396,7 +403,7 @@ void FakeVehicleHardware::init() {
        VehiclePropertyStore::TokenFunction tokenFunction = nullptr;
        VehiclePropertyStore::TokenFunction tokenFunction = nullptr;


        if (cfg.prop == toInt(VehicleProperty::AP_POWER_STATE_REQ)) {
        if (cfg.prop == toInt(VehicleProperty::AP_POWER_STATE_REQ)) {
            cfg.configArray[0] = getS2rS2dConfig();
            cfg.configArray[0] = s2rS2dConfig;
        } else if (cfg.prop == OBD2_FREEZE_FRAME) {
        } else if (cfg.prop == OBD2_FREEZE_FRAME) {
            tokenFunction = [](const VehiclePropValue& propValue) { return propValue.timestamp; };
            tokenFunction = [](const VehiclePropValue& propValue) { return propValue.timestamp; };
        }
        }
@@ -425,10 +432,6 @@ void FakeVehicleHardware::init() {
    });
    });
}
}


int32_t FakeVehicleHardware::getS2rS2dConfig() {
    return GetIntProperty(POWER_STATE_REQ_CONFIG_PROPERTY, /*default_value=*/0);
}

std::vector<VehiclePropConfig> FakeVehicleHardware::getAllPropertyConfigs() const {
std::vector<VehiclePropConfig> FakeVehicleHardware::getAllPropertyConfigs() const {
    std::vector<VehiclePropConfig> allConfigs = mServerSidePropStore->getAllConfigs();
    std::vector<VehiclePropConfig> allConfigs = mServerSidePropStore->getAllConfigs();
    if (mAddExtraTestVendorConfigs) {
    if (mAddExtraTestVendorConfigs) {
+21 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <FakeUserHal.h>
#include <FakeUserHal.h>
#include <PropertyUtils.h>
#include <PropertyUtils.h>


#include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateConfigFlag.h>
#include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateShutdownParam.h>
#include <aidl/android/hardware/automotive/vehicle/VehicleApPowerStateShutdownParam.h>
#include <android/hardware/automotive/vehicle/TestVendorProperty.h>
#include <android/hardware/automotive/vehicle/TestVendorProperty.h>


@@ -73,6 +74,7 @@ using ::aidl::android::hardware::automotive::vehicle::SetValueRequest;
using ::aidl::android::hardware::automotive::vehicle::SetValueResult;
using ::aidl::android::hardware::automotive::vehicle::SetValueResult;
using ::aidl::android::hardware::automotive::vehicle::StatusCode;
using ::aidl::android::hardware::automotive::vehicle::StatusCode;
using ::aidl::android::hardware::automotive::vehicle::SubscribeOptions;
using ::aidl::android::hardware::automotive::vehicle::SubscribeOptions;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateConfigFlag;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReport;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReport;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReq;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReq;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateShutdownParam;
using ::aidl::android::hardware::automotive::vehicle::VehicleApPowerStateShutdownParam;
@@ -3863,6 +3865,25 @@ TEST_F(FakeVehicleHardwareTest, testSetHvacTemperatureValueSuggestion) {
    }
    }
}
}


TEST_F(FakeVehicleHardwareTest, testOverrideApPowerStateReqConfig) {
    auto hardware = std::make_unique<FakeVehicleHardware>(
            android::base::GetExecutableDirectory(),
            /*overrideConfigDir=*/"",
            /*forceOverride=*/false,
            toInt(VehicleApPowerStateConfigFlag::ENABLE_DEEP_SLEEP_FLAG) |
                    toInt(VehicleApPowerStateConfigFlag::ENABLE_HIBERNATION_FLAG));

    std::vector<VehiclePropConfig> configs = hardware->getAllPropertyConfigs();

    for (const auto& config : configs) {
        if (config.prop != toInt(VehicleProperty::AP_POWER_STATE_REQ)) {
            continue;
        }
        ASSERT_EQ(config.configArray[0], 0x5);
        break;
    }
}

}  // namespace fake
}  // namespace fake
}  // namespace vehicle
}  // namespace vehicle
}  // namespace automotive
}  // namespace automotive