Merge "Effect Aidl: make EffectFactoryHelper methods static only" into main

This commit is contained in:
Treehugger Robot 2024-03-05 03:59:06 +00:00 committed by Gerrit Code Review
commit 337c6afb98
2 changed files with 11 additions and 30 deletions

View file

@ -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;
};

View file

@ -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);