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

Commit 8a4e9b73 authored by Shunkai Yao's avatar Shunkai Yao
Browse files

Effect Aidl: make EffectFactoryHelper methods static only

Bug: 327678656
Test: atest --test-mapping hardware/interfaces/audio/aidl/vts:presubmit
Change-Id: I57d924d19f38257e32dba95d4de0ca00532c5ab4
parent 9f9fe929
Loading
Loading
Loading
Loading
+0 −20
Original line number Diff line number Diff line
@@ -36,21 +36,6 @@ using aidl::android::media::audio::common::AudioUuid;

class EffectFactoryHelper {
  public:
    explicit EffectFactoryHelper(const std::string& name) : mServiceName(name) {}

    void ConnectToFactoryService() {
        mEffectFactory = IFactory::fromBinder(binderUtil.connectToService(mServiceName));
        ASSERT_NE(mEffectFactory, nullptr);
    }

    void RestartFactoryService() {
        ASSERT_NE(mEffectFactory, nullptr);
        mEffectFactory = IFactory::fromBinder(binderUtil.restartService());
        ASSERT_NE(mEffectFactory, nullptr);
    }

    std::shared_ptr<IFactory> GetFactory() const { return mEffectFactory; }

    static std::vector<std::pair<std::shared_ptr<IFactory>, Descriptor>> getAllEffectDescriptors(
            std::string serviceName, std::optional<AudioUuid> type = std::nullopt) {
        AudioHalBinderServiceUtil util;
@@ -84,9 +69,4 @@ class EffectFactoryHelper {
        return EffectFactoryHelper::getHalVersion(factory) >=
               aidl::android::hardware::audio::effect::kReopenSupportedVersion;
    }

  private:
    std::shared_ptr<IFactory> mEffectFactory;
    std::string mServiceName;
    AudioHalBinderServiceUtil binderUtil;
};
+11 −10
Original line number Diff line number Diff line
@@ -56,10 +56,7 @@ using android::hardware::audio::common::testing::detail::TestExecutionTracer;
/// Effect factory testing.
class EffectFactoryTest : public testing::TestWithParam<std::string> {
  public:
    void SetUp() override {
        mFactoryHelper = std::make_unique<EffectFactoryHelper>(GetParam());
        connectAndGetFactory();
    }
    void SetUp() override { connectAndGetFactory(); }

    void TearDown() override {
        for (auto& effect : mEffects) {
@@ -68,13 +65,14 @@ class EffectFactoryTest : public testing::TestWithParam<std::string> {
        }
    }

    std::unique_ptr<EffectFactoryHelper> mFactoryHelper;
    std::string kServiceName = GetParam();
    std::shared_ptr<IFactory> mEffectFactory;
    std::vector<std::shared_ptr<IEffect>> mEffects;
    const Descriptor::Identity kNullId = {.uuid = getEffectUuidNull()};
    const Descriptor::Identity kZeroId = {.uuid = getEffectUuidZero()};
    const Descriptor kNullDesc = {.common.id = kNullId};
    const Descriptor kZeroDesc = {.common.id = kZeroId};
    AudioHalBinderServiceUtil mBinderUtil;

    template <typename Functor>
    void ForEachId(const std::vector<Descriptor::Identity> ids, Functor functor) {
@@ -117,8 +115,7 @@ class EffectFactoryTest : public testing::TestWithParam<std::string> {
        }
    }
    void connectAndGetFactory() {
        ASSERT_NO_FATAL_FAILURE(mFactoryHelper->ConnectToFactoryService());
        mEffectFactory = mFactoryHelper->GetFactory();
        mEffectFactory = IFactory::fromBinder(mBinderUtil.connectToService(kServiceName));
        ASSERT_NE(mEffectFactory, nullptr);
    }
};
@@ -128,7 +125,9 @@ TEST_P(EffectFactoryTest, SetupAndTearDown) {
}

TEST_P(EffectFactoryTest, CanBeRestarted) {
    ASSERT_NO_FATAL_FAILURE(mFactoryHelper->RestartFactoryService());
    ASSERT_NE(mEffectFactory, nullptr);
    mEffectFactory = IFactory::fromBinder(mBinderUtil.restartService());
    ASSERT_NE(mEffectFactory, nullptr);
}

/**
@@ -250,7 +249,8 @@ TEST_P(EffectFactoryTest, CreateDestroyWithRestart) {
    EXPECT_NE(descs.size(), 0UL);
    creatAndDestroyDescs(descs);

    mFactoryHelper->RestartFactoryService();
    mEffectFactory = IFactory::fromBinder(mBinderUtil.restartService());
    ASSERT_NE(mEffectFactory, nullptr);

    connectAndGetFactory();
    creatAndDestroyDescs(descs);
@@ -263,7 +263,8 @@ TEST_P(EffectFactoryTest, EffectInvalidAfterRestart) {
    EXPECT_NE(descs.size(), 0UL);
    std::vector<std::shared_ptr<IEffect>> effects = createWithDescs(descs);

    ASSERT_NO_FATAL_FAILURE(mFactoryHelper->RestartFactoryService());
    mEffectFactory = IFactory::fromBinder(mBinderUtil.restartService());
    ASSERT_NE(mEffectFactory, nullptr);

    connectAndGetFactory();
    destroyEffects(effects, EX_ILLEGAL_ARGUMENT);