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

Commit 1b6c1f0c authored by Sham Rathod's avatar Sham Rathod
Browse files

Volume: Add AIDL placeholder implementation and vts test

Bug: 258124419
Test: atest VtsHalVolumeTargetTest

Change-Id: Ie3eaa820f94be0287ba72b7647d3d7ab8b5c70b8
parent 686c214a
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -30,6 +30,9 @@
    {
      "name": "VtsHalVisualizerTargetTest"
    },
    {
      "name": "VtsHalVolumeTargetTest"
    },
    {
      "name": "VtsHalAECTargetTest"
    },
+3 −0
Original line number Diff line number Diff line
@@ -37,6 +37,9 @@ union Volume {
  android.hardware.audio.effect.VendorExtension vendor;
  int levelDb;
  boolean mute;
  // TODO(b/263416041) Move to Capability
  const int MIN_LEVEL_DB = -9600;
  const int MAX_LEVEL_DB = 0;
  @VintfStability
  union Id {
    int vendorExtensionTag;
+12 −0
Original line number Diff line number Diff line
@@ -57,6 +57,18 @@ union Volume {
        int maxLevel;
    }

    // TODO(b/263416041) Move to Capability
    /**
     * Minimal level in dB.
     */
    const int MIN_LEVEL_DB = -9600;

    /**
     * Maximum level in dB.
     */
    const int MAX_LEVEL_DB = 0;

    /**
    /**
     * Current level in dB.
     */
+55 −5
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@ extern "C" binder_exception_t queryEffect(const AudioUuid* in_impl_uuid, Descrip
namespace aidl::android::hardware::audio::effect {

const std::string VolumeSw::kEffectName = "VolumeSw";
const Volume::Capability VolumeSw::kCapability;
const Volume::Capability VolumeSw::kCapability = {.maxLevel = Volume::MAX_LEVEL_DB};
const Descriptor VolumeSw::kDescriptor = {
        .common = {.id = {.type = kVolumeTypeUUID,
                          .uuid = kVolumeSwImplUUID,
@@ -82,16 +82,66 @@ ndk::ScopedAStatus VolumeSw::setParameterSpecific(const Parameter::Specific& spe
    RETURN_IF(Parameter::Specific::volume != specific.getTag(), EX_ILLEGAL_ARGUMENT,
              "EffectNotSupported");

    mSpecificParam = specific.get<Parameter::Specific::volume>();
    LOG(DEBUG) << __func__ << " success with: " << specific.toString();
    auto& volParam = specific.get<Parameter::Specific::volume>();
    auto tag = volParam.getTag();

    switch (tag) {
        case Volume::levelDb: {
            RETURN_IF(mContext->setVolLevel(volParam.get<Volume::levelDb>()) != RetCode::SUCCESS,
                      EX_ILLEGAL_ARGUMENT, "LevelNotSupported");
            return ndk::ScopedAStatus::ok();
        }
        case Volume::mute: {
            RETURN_IF(mContext->setVolMute(volParam.get<Volume::mute>()) != RetCode::SUCCESS,
                      EX_ILLEGAL_ARGUMENT, "MuteNotSupported");
            return ndk::ScopedAStatus::ok();
        }
        default: {
            LOG(ERROR) << __func__ << " unsupported tag: " << toString(tag);
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "VolumeTagNotSupported");
        }
    }
}

ndk::ScopedAStatus VolumeSw::getParameterSpecific(const Parameter::Id& id,
                                                  Parameter::Specific* specific) {
    auto tag = id.getTag();
    RETURN_IF(Parameter::Id::volumeTag != tag, EX_ILLEGAL_ARGUMENT, "wrongIdTag");
    specific->set<Parameter::Specific::volume>(mSpecificParam);
    auto volId = id.get<Parameter::Id::volumeTag>();
    auto volIdTag = volId.getTag();
    switch (volIdTag) {
        case Volume::Id::commonTag:
            return getParameterVolume(volId.get<Volume::Id::commonTag>(), specific);
        default:
            LOG(ERROR) << __func__ << " unsupported tag: " << toString(tag);
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "VolumeTagNotSupported");
    }
}

ndk::ScopedAStatus VolumeSw::getParameterVolume(const Volume::Tag& tag,
                                                Parameter::Specific* specific) {
    RETURN_IF(!mContext, EX_NULL_POINTER, "nullContext");

    Volume volParam;
    switch (tag) {
        case Volume::levelDb: {
            volParam.set<Volume::levelDb>(mContext->getVolLevel());
            break;
        }
        case Volume::mute: {
            volParam.set<Volume::mute>(mContext->getVolMute());
            break;
        }
        default: {
            LOG(ERROR) << __func__ << " unsupported tag: " << toString(tag);
            return ndk::ScopedAStatus::fromExceptionCodeWithMessage(EX_ILLEGAL_ARGUMENT,
                                                                    "VolumeTagNotSupported");
        }
    }

    specific->set<Parameter::Specific::volume>(volParam);
    return ndk::ScopedAStatus::ok();
}

+26 −3
Original line number Diff line number Diff line
@@ -32,7 +32,30 @@ class VolumeSwContext final : public EffectContext {
        : EffectContext(statusDepth, common) {
        LOG(DEBUG) << __func__;
    }
    // TODO: add specific context here

    RetCode setVolLevel(int level) {
        if (level < Volume::MIN_LEVEL_DB || level > Volume::MAX_LEVEL_DB) {
            LOG(ERROR) << __func__ << " invalid level " << level;
            return RetCode::ERROR_ILLEGAL_PARAMETER;
        }
        // TODO : Add implementation to apply new level
        mLevel = level;
        return RetCode::SUCCESS;
    }

    int getVolLevel() const { return mLevel; }

    RetCode setVolMute(bool mute) {
        // TODO : Add implementation to modify mute
        mMute = mute;
        return RetCode::SUCCESS;
    }

    bool getVolMute() const { return mMute; }

  private:
    int mLevel = 0;
    bool mMute = false;
};

class VolumeSw final : public EffectImpl {
@@ -60,7 +83,7 @@ class VolumeSw final : public EffectImpl {

  private:
    std::shared_ptr<VolumeSwContext> mContext;
    /* parameters */
    Volume mSpecificParam;

    ndk::ScopedAStatus getParameterVolume(const Volume::Tag& tag, Parameter::Specific* specific);
};
}  // namespace aidl::android::hardware::audio::effect
Loading