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

Commit 24fee7bb authored by Yu Shan's avatar Yu Shan
Browse files

Define VhalResult alias.

Define a VhalResult alias to represent Result that contains a VHAL
StatusCode as error type. This alias helps client to easier migrate
from android::base::Result to VhalResult.

Test: Presubmit
Bug: 219612366
Change-Id: I17f15044ee962c7148b0adc3925e0b0a9dfab2a8
parent 726d51a6
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ namespace fake {

class FakeVehicleHardware : public IVehicleHardware {
  public:
    using ValueResultType = android::base::Result<VehiclePropValuePool::RecyclableType, VhalError>;
    using ValueResultType = VhalResult<VehiclePropValuePool::RecyclableType>;

    FakeVehicleHardware();

@@ -90,7 +90,7 @@ class FakeVehicleHardware : public IVehicleHardware {
    ValueResultType getValue(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;

    android::base::Result<void, VhalError> setValue(
    VhalResult<void> setValue(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value);

  private:
@@ -117,17 +117,17 @@ class FakeVehicleHardware : public IVehicleHardware {
    // Override the properties using config files in 'overrideDir'.
    void overrideProperties(const char* overrideDir);

    android::base::Result<void, VhalError> maybeSetSpecialValue(
    VhalResult<void> maybeSetSpecialValue(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value,
            bool* isSpecialValue);
    ValueResultType maybeGetSpecialValue(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value,
            bool* isSpecialValue) const;
    android::base::Result<void, VhalError> setApPowerStateReport(
    VhalResult<void> setApPowerStateReport(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value);
    VehiclePropValuePool::RecyclableType createApPowerStateReq(
            aidl::android::hardware::automotive::vehicle::VehicleApPowerStateReq state);
    android::base::Result<void, VhalError> setUserHalProp(
    VhalResult<void> setUserHalProp(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value);
    ValueResultType getUserHalProp(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& value) const;
+5 −7
Original line number Diff line number Diff line
@@ -68,8 +68,6 @@ using ::android::base::Result;
using ::android::base::StartsWith;
using ::android::base::StringPrintf;

using StatusError = android::base::Error<VhalError>;

const char* VENDOR_OVERRIDE_DIR = "/vendor/etc/automotive/vhaloverride/";
const char* OVERRIDE_PROPERTY = "persist.vendor.vhal_init_value_override";

@@ -193,7 +191,7 @@ VehiclePropValuePool::RecyclableType FakeVehicleHardware::createApPowerStateReq(
    return req;
}

Result<void, VhalError> FakeVehicleHardware::setApPowerStateReport(const VehiclePropValue& value) {
VhalResult<void> FakeVehicleHardware::setApPowerStateReport(const VehiclePropValue& value) {
    auto updatedValue = mValuePool->obtain(value);
    updatedValue->timestamp = elapsedRealtimeNano();

@@ -270,7 +268,7 @@ bool FakeVehicleHardware::isHvacPropAndHvacNotAvailable(int32_t propId) {
    return false;
}

Result<void, VhalError> FakeVehicleHardware::setUserHalProp(const VehiclePropValue& value) {
VhalResult<void> FakeVehicleHardware::setUserHalProp(const VehiclePropValue& value) {
    auto result = mFakeUserHal->onSetProperty(value);
    if (!result.ok()) {
        return StatusError(getErrorCode(result))
@@ -345,7 +343,7 @@ FakeVehicleHardware::ValueResultType FakeVehicleHardware::maybeGetSpecialValue(
    return nullptr;
}

Result<void, VhalError> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValue& value,
VhalResult<void> FakeVehicleHardware::maybeSetSpecialValue(const VehiclePropValue& value,
                                                           bool* isSpecialValue) {
    *isSpecialValue = false;
    VehiclePropValuePool::RecyclableType updatedValue;
@@ -442,7 +440,7 @@ StatusCode FakeVehicleHardware::setValues(std::shared_ptr<const SetValuesCallbac
    return StatusCode::OK;
}

Result<void, VhalError> FakeVehicleHardware::setValue(const VehiclePropValue& value) {
VhalResult<void> FakeVehicleHardware::setValue(const VehiclePropValue& value) {
    bool isSpecialValue = false;
    auto setSpecialValueResult = maybeSetSpecialValue(value, &isSpecialValue);

+3 −3
Original line number Diff line number Diff line
@@ -38,11 +38,11 @@ class FakeObd2Frame final {
            const aidl::android::hardware::automotive::vehicle::VehiclePropConfig& propConfig);
    void initObd2FreezeFrame(
            const aidl::android::hardware::automotive::vehicle::VehiclePropConfig& propConfig);
    android::base::Result<VehiclePropValuePool::RecyclableType, VhalError> getObd2FreezeFrame(
    VhalResult<VehiclePropValuePool::RecyclableType> getObd2FreezeFrame(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue&
                    requestedPropValue) const;
    android::base::Result<VehiclePropValuePool::RecyclableType, VhalError> getObd2DtcInfo() const;
    android::base::Result<void, VhalError> clearObd2FreezeFrames(
    VhalResult<VehiclePropValuePool::RecyclableType> getObd2DtcInfo() const;
    VhalResult<void> clearObd2FreezeFrames(
            const aidl::android::hardware::automotive::vehicle::VehiclePropValue& propValue);
    static bool isDiagnosticProperty(
            const aidl::android::hardware::automotive::vehicle::VehiclePropConfig& propConfig);
+3 −5
Original line number Diff line number Diff line
@@ -46,8 +46,6 @@ using ::aidl::android::hardware::automotive::vehicle::VehiclePropertyType;
using ::aidl::android::hardware::automotive::vehicle::VehiclePropValue;
using ::android::base::Result;

using StatusError = android::base::Error<VhalError>;

std::unique_ptr<Obd2SensorStore> FakeObd2Frame::fillDefaultObd2Frame(size_t numVendorIntegerSensors,
                                                                     size_t numVendorFloatSensors) {
    std::unique_ptr<Obd2SensorStore> sensorStore(new Obd2SensorStore(
@@ -127,7 +125,7 @@ void FakeObd2Frame::initObd2FreezeFrame(const VehiclePropConfig& propConfig) {
    }
}

Result<VehiclePropValuePool::RecyclableType, VhalError> FakeObd2Frame::getObd2FreezeFrame(
VhalResult<VehiclePropValuePool::RecyclableType> FakeObd2Frame::getObd2FreezeFrame(
        const VehiclePropValue& requestedPropValue) const {
    if (requestedPropValue.value.int64Values.size() != 1) {
        return StatusError(StatusCode::INVALID_ARG)
@@ -153,7 +151,7 @@ Result<VehiclePropValuePool::RecyclableType, VhalError> FakeObd2Frame::getObd2Fr
    return readValueResult;
}

Result<VehiclePropValuePool::RecyclableType, VhalError> FakeObd2Frame::getObd2DtcInfo() const {
VhalResult<VehiclePropValuePool::RecyclableType> FakeObd2Frame::getObd2DtcInfo() const {
    std::vector<int64_t> timestamps;
    auto result = mPropStore->readValuesForProperty(OBD2_FREEZE_FRAME);
    if (!result.ok()) {
@@ -170,7 +168,7 @@ Result<VehiclePropValuePool::RecyclableType, VhalError> FakeObd2Frame::getObd2Dt
    return outValue;
}

Result<void, VhalError> FakeObd2Frame::clearObd2FreezeFrames(const VehiclePropValue& propValue) {
VhalResult<void> FakeObd2Frame::clearObd2FreezeFrames(const VehiclePropValue& propValue) {
    if (propValue.value.int64Values.size() == 0) {
        mPropStore->removeValuesForProperty(OBD2_FREEZE_FRAME);
        return {};
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ constexpr char kUserHalDumpOption[] = "--user-hal";
// Class used to emulate a real User HAL behavior through lshal debug requests.
class FakeUserHal final {
  public:
    using ValueResultType = android::base::Result<VehiclePropValuePool::RecyclableType, VhalError>;
    using ValueResultType = VhalResult<VehiclePropValuePool::RecyclableType>;

    explicit FakeUserHal(std::shared_ptr<VehiclePropValuePool> valuePool) : mValuePool(valuePool) {}

Loading