Some fixes to power manager lib code
- Run clang-format on all recently added files;
- Move all new classes to android::power namespace and remove Power
prefix from all classes and enums;
- Add virtual function specifier to overrides of virtual members;
- Add missing virtual destructors;
- Remove namespaces and aliases from public api of header files;
- Delete constructor and destructor of PowerHalLoader;
- Add helper functions to convert hal results in wrapper
implementations;
- Merge test targets to single libpowermanager_test target;
Bug: 150878220
Test: atest libpowermanager_test
Change-Id: Ie2b5ad69f3b05d5f6b576671bc98e0f83b274152
diff --git a/services/powermanager/tests/PowerHalWrapperAidlTest.cpp b/services/powermanager/tests/PowerHalWrapperAidlTest.cpp
index 73b7466..a765659 100644
--- a/services/powermanager/tests/PowerHalWrapperAidlTest.cpp
+++ b/services/powermanager/tests/PowerHalWrapperAidlTest.cpp
@@ -19,14 +19,12 @@
#include <android/hardware/power/Boost.h>
#include <android/hardware/power/Mode.h>
#include <binder/IServiceManager.h>
-
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-
#include <powermanager/PowerHalWrapper.h>
+#include <utils/Log.h>
#include <thread>
-#include <utils/Log.h>
using android::binder::Status;
using android::hardware::power::Boost;
@@ -34,6 +32,7 @@
using android::hardware::power::Mode;
using namespace android;
+using namespace android::power;
using namespace std::chrono_literals;
using namespace testing;
@@ -57,7 +56,7 @@
void SetUp() override;
protected:
- std::unique_ptr<PowerHalWrapper> mWrapper = nullptr;
+ std::unique_ptr<HalWrapper> mWrapper = nullptr;
sp<StrictMock<MockIPower>> mMockHal = nullptr;
};
@@ -65,7 +64,7 @@
void PowerHalWrapperAidlTest::SetUp() {
mMockHal = new StrictMock<MockIPower>();
- mWrapper = std::make_unique<AidlPowerHalWrapper>(mMockHal);
+ mWrapper = std::make_unique<AidlHalWrapper>(mMockHal);
ASSERT_NE(mWrapper, nullptr);
}
@@ -75,62 +74,61 @@
{
InSequence seq;
EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::DISPLAY_UPDATE_IMMINENT), _))
- .Times(Exactly(1))
- .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
EXPECT_CALL(*mMockHal.get(), setBoost(Eq(Boost::DISPLAY_UPDATE_IMMINENT), Eq(100)))
- .Times(Exactly(1));
+ .Times(Exactly(1));
}
auto result = mWrapper->setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 100);
- ASSERT_EQ(PowerHalResult::SUCCESSFUL, result);
+ ASSERT_EQ(HalResult::SUCCESSFUL, result);
}
TEST_F(PowerHalWrapperAidlTest, TestSetBoostFailed) {
{
InSequence seq;
EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::INTERACTION), _))
- .Times(Exactly(1))
- .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
EXPECT_CALL(*mMockHal.get(), setBoost(Eq(Boost::INTERACTION), Eq(100)))
- .Times(Exactly(1))
- .WillRepeatedly(Return(Status::fromExceptionCode(-1)));
+ .Times(Exactly(1))
+ .WillRepeatedly(Return(Status::fromExceptionCode(-1)));
EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::DISPLAY_UPDATE_IMMINENT), _))
- .Times(Exactly(1))
- .WillRepeatedly(Return(Status::fromExceptionCode(-1)));
+ .Times(Exactly(1))
+ .WillRepeatedly(Return(Status::fromExceptionCode(-1)));
}
auto result = mWrapper->setBoost(Boost::INTERACTION, 100);
- ASSERT_EQ(PowerHalResult::FAILED, result);
+ ASSERT_EQ(HalResult::FAILED, result);
result = mWrapper->setBoost(Boost::DISPLAY_UPDATE_IMMINENT, 1000);
- ASSERT_EQ(PowerHalResult::FAILED, result);
+ ASSERT_EQ(HalResult::FAILED, result);
}
TEST_F(PowerHalWrapperAidlTest, TestSetBoostUnsupported) {
EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::INTERACTION), _))
- .Times(Exactly(1))
- .WillRepeatedly(DoAll(SetArgPointee<1>(false), Return(Status())));
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(false), Return(Status())));
auto result = mWrapper->setBoost(Boost::INTERACTION, 1000);
- ASSERT_EQ(PowerHalResult::UNSUPPORTED, result);
+ ASSERT_EQ(HalResult::UNSUPPORTED, result);
result = mWrapper->setBoost(Boost::CAMERA_SHOT, 10);
- ASSERT_EQ(PowerHalResult::UNSUPPORTED, result);
+ ASSERT_EQ(HalResult::UNSUPPORTED, result);
}
TEST_F(PowerHalWrapperAidlTest, TestSetBoostMultiThreadCheckSupportedOnlyOnce) {
{
InSequence seq;
EXPECT_CALL(*mMockHal.get(), isBoostSupported(Eq(Boost::INTERACTION), _))
- .Times(Exactly(1))
- .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
- EXPECT_CALL(*mMockHal.get(), setBoost(Eq(Boost::INTERACTION), Eq(100)))
- .Times(Exactly(10));
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
+ EXPECT_CALL(*mMockHal.get(), setBoost(Eq(Boost::INTERACTION), Eq(100))).Times(Exactly(10));
}
std::vector<std::thread> threads;
for (int i = 0; i < 10; i++) {
threads.push_back(std::thread([&]() {
auto result = mWrapper->setBoost(Boost::INTERACTION, 100);
- ASSERT_EQ(PowerHalResult::SUCCESSFUL, result);
+ ASSERT_EQ(HalResult::SUCCESSFUL, result);
}));
}
std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });
@@ -140,62 +138,61 @@
{
InSequence seq;
EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::DISPLAY_INACTIVE), _))
- .Times(Exactly(1))
- .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
EXPECT_CALL(*mMockHal.get(), setMode(Eq(Mode::DISPLAY_INACTIVE), Eq(false)))
- .Times(Exactly(1));
+ .Times(Exactly(1));
}
auto result = mWrapper->setMode(Mode::DISPLAY_INACTIVE, false);
- ASSERT_EQ(PowerHalResult::SUCCESSFUL, result);
+ ASSERT_EQ(HalResult::SUCCESSFUL, result);
}
TEST_F(PowerHalWrapperAidlTest, TestSetModeFailed) {
{
InSequence seq;
EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::LAUNCH), _))
- .Times(Exactly(1))
- .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
EXPECT_CALL(*mMockHal.get(), setMode(Eq(Mode::LAUNCH), Eq(true)))
- .Times(Exactly(1))
- .WillRepeatedly(Return(Status::fromExceptionCode(-1)));
+ .Times(Exactly(1))
+ .WillRepeatedly(Return(Status::fromExceptionCode(-1)));
EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::DISPLAY_INACTIVE), _))
- .Times(Exactly(1))
- .WillRepeatedly(Return(Status::fromExceptionCode(-1)));
+ .Times(Exactly(1))
+ .WillRepeatedly(Return(Status::fromExceptionCode(-1)));
}
auto result = mWrapper->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(PowerHalResult::FAILED, result);
+ ASSERT_EQ(HalResult::FAILED, result);
result = mWrapper->setMode(Mode::DISPLAY_INACTIVE, false);
- ASSERT_EQ(PowerHalResult::FAILED, result);
+ ASSERT_EQ(HalResult::FAILED, result);
}
TEST_F(PowerHalWrapperAidlTest, TestSetModeUnsupported) {
EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::LAUNCH), _))
- .Times(Exactly(1))
- .WillRepeatedly(DoAll(SetArgPointee<1>(false), Return(Status())));
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(false), Return(Status())));
auto result = mWrapper->setMode(Mode::LAUNCH, true);
- ASSERT_EQ(PowerHalResult::UNSUPPORTED, result);
+ ASSERT_EQ(HalResult::UNSUPPORTED, result);
result = mWrapper->setMode(Mode::CAMERA_STREAMING_HIGH, true);
- ASSERT_EQ(PowerHalResult::UNSUPPORTED, result);
+ ASSERT_EQ(HalResult::UNSUPPORTED, result);
}
TEST_F(PowerHalWrapperAidlTest, TestSetModeMultiThreadCheckSupportedOnlyOnce) {
{
InSequence seq;
EXPECT_CALL(*mMockHal.get(), isModeSupported(Eq(Mode::LAUNCH), _))
- .Times(Exactly(1))
- .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
- EXPECT_CALL(*mMockHal.get(), setMode(Eq(Mode::LAUNCH), Eq(false)))
- .Times(Exactly(10));
+ .Times(Exactly(1))
+ .WillRepeatedly(DoAll(SetArgPointee<1>(true), Return(Status())));
+ EXPECT_CALL(*mMockHal.get(), setMode(Eq(Mode::LAUNCH), Eq(false))).Times(Exactly(10));
}
std::vector<std::thread> threads;
for (int i = 0; i < 10; i++) {
threads.push_back(std::thread([&]() {
auto result = mWrapper->setMode(Mode::LAUNCH, false);
- ASSERT_EQ(PowerHalResult::SUCCESSFUL, result);
+ ASSERT_EQ(HalResult::SUCCESSFUL, result);
}));
}
std::for_each(threads.begin(), threads.end(), [](std::thread& t) { t.join(); });