VTSHalPowerTarget: Add condition check for FMQAidl teardown

While FMQAidl Setup() was skipped, some uninitialized objects would be
used in FMQAidl Teardown() which caused the test failed.
Add some condition check to prevent from using uninitialized objects.

Test: atest VTSHalPowerTarget
Bug: 328330332
Change-Id: I83081cbef66da1d74d87e191f266cb16fb559b85
(cherry picked from commit d3753ec91d)
This commit is contained in:
jimmyshiu 2024-03-19 08:56:42 +00:00 committed by Matt Buckley
parent acb80cfdf2
commit 2c3b63f04f

View file

@ -175,9 +175,13 @@ class FMQAidl : public PowerAidl {
ASSERT_NE(mEventFlag, nullptr); ASSERT_NE(mEventFlag, nullptr);
} }
virtual void TearDown() { virtual void TearDown() {
if (mSession) {
mSession->close(); mSession->close();
if (mChannel->isValid()) {
ASSERT_TRUE(power->closeSessionChannel(getpid(), getuid()).isOk()); ASSERT_TRUE(power->closeSessionChannel(getpid(), getuid()).isOk());
} }
}
}
protected: protected:
std::shared_ptr<IPowerHintSession> mSession; std::shared_ptr<IPowerHintSession> mSession;