From acf23a23e74b48e1d648426c95d8266cdfeb874e Mon Sep 17 00:00:00 2001 From: Ruslan Tkhakokhov Date: Fri, 21 Jun 2019 10:31:37 +0000 Subject: [PATCH] Merged-In Revert "libpower: RAII wake lock implementation" This reverts commit 23009bb199ba68ef720431776e9e4b9bb148ed8b. Reason for revert: Breaks the build Change-Id: I347928c4d444f4b1ce9d79f855c171626c0214c0 --- Android.bp | 5 +-- include/hardware_legacy/power.h | 26 ++------------ power.cpp | 25 -------------- power_test.cpp | 60 ++++----------------------------- 4 files changed, 9 insertions(+), 107 deletions(-) diff --git a/Android.bp b/Android.bp index bc453fe..d198b18 100644 --- a/Android.bp +++ b/Android.bp @@ -35,10 +35,7 @@ cc_test { defaults: ["libpower_defaults"], srcs: ["power_test.cpp"], static_libs: ["libpower"], - shared_libs: [ - "android.system.suspend@1.0", - "suspend_control_aidl_interface-cpp", - ], + shared_libs: ["android.system.suspend@1.0"], test_suites: ["device-tests"], require_root: true, } diff --git a/include/hardware_legacy/power.h b/include/hardware_legacy/power.h index a053583..604e0ed 100644 --- a/include/hardware_legacy/power.h +++ b/include/hardware_legacy/power.h @@ -17,10 +17,6 @@ #ifndef _HARDWARE_POWER_H #define _HARDWARE_POWER_H -#if __cplusplus -#include -#include -#endif #include #if __cplusplus @@ -37,27 +33,9 @@ enum { int acquire_wake_lock(int lock, const char* id); int release_wake_lock(const char* id); -#if __cplusplus -} // extern "C" -#endif #if __cplusplus -// RAII way to acquire wake locks. -namespace android { -namespace power { - -class WakeLock { - public: - WakeLock(const std::string& name); - ~WakeLock(); - - private: - class WakeLockImpl; - std::unique_ptr mImpl; -}; - -} // namespace power -} // namespace android +} // extern "C" #endif -#endif // _HARDWARE_POWER_H +#endif // _HARDWARE_POWER_H diff --git a/power.cpp b/power.cpp index 39084d7..74abac9 100644 --- a/power.cpp +++ b/power.cpp @@ -78,28 +78,3 @@ int release_wake_lock(const char* id) { } return -1; } - -namespace android::power { - -WakeLock::WakeLock(const std::string& name) : mImpl(std::make_unique(name)) {} - -WakeLock::~WakeLock() = default; - -class WakeLock::WakeLockImpl { - public: - WakeLockImpl(const std::string& name) : mWakeLock(nullptr) { - static sp suspendService = ISystemSuspend::getService(); - mWakeLock = suspendService->acquireWakeLock(WakeLockType::PARTIAL, name); - } - ~WakeLockImpl() { - auto ret = mWakeLock->release(); - if (!ret.isOk()) { - LOG(ERROR) << "IWakeLock::release() call failed: " << ret.description(); - } - } - - private: - sp mWakeLock; -}; - -} // namespace android::power diff --git a/power_test.cpp b/power_test.cpp index 5ae19d6..1ade263 100644 --- a/power_test.cpp +++ b/power_test.cpp @@ -14,9 +14,6 @@ * limitations under the License. */ -#include -#include -#include #include #include @@ -25,9 +22,8 @@ #include #include -using android::sp; -using android::system::suspend::ISuspendControlService; -using android::system::suspend::WakeLockInfo; +#include + using namespace std::chrono_literals; namespace android { @@ -77,8 +73,10 @@ TEST(LibpowerTest, WakeLockStressTest) { for (int j = 0; j < numLocks; j++) { // We want ids to be unique. std::string id = std::to_string(i) + "/" + std::to_string(j); - ASSERT_EQ(acquire_wake_lock(PARTIAL_WAKE_LOCK, id.c_str()), 0) << "id: " << id; - ASSERT_EQ(release_wake_lock(id.c_str()), 0) << "id: " << id; + ASSERT_EQ(acquire_wake_lock(PARTIAL_WAKE_LOCK, id.c_str()), 0) + << "id: " << id; + ASSERT_EQ(release_wake_lock(id.c_str()), 0) + << "id: " << id;; } }); } @@ -87,50 +85,4 @@ TEST(LibpowerTest, WakeLockStressTest) { } } -// Returns true iff found. -bool findWakeLockInfoByName( - const sp& service, - const std::string& name, - WakeLockInfo* info) { - std::vector wlStats; - service->getWakeLockStats(&wlStats); - auto it = std::find_if(wlStats.begin(), wlStats.end(), - [&name](const auto& x) { return x.name == name; }); - if (it != wlStats.end()) { - *info = *it; - return true; - } - return false; -} - -// Test RAII properties of WakeLock class. -TEST(LibpowerTest, RAIIWakeLock) { - sp control = - android::defaultServiceManager()->getService(android::String16("suspend_control")); - ASSERT_NE(control, nullptr) << "failed to get the suspend control service"; - sp controlService = interface_cast(control); - - auto name = std::to_string(rand()); - { - android::power::WakeLock wl{name}; - - WakeLockInfo info; - auto success = findWakeLockInfoByName(controlService, name, &info); - ASSERT_TRUE(success); - ASSERT_EQ(info.name, name); - ASSERT_EQ(info.pid, getpid()); - ASSERT_TRUE(info.isActive); - } - - // SystemSuspend receives wake lock release requests on hwbinder thread, while stats requests - // come on binder thread. Sleep to make sure that stats are reported *after* wake lock release. - std::this_thread::sleep_for(1ms); - WakeLockInfo info; - auto success = findWakeLockInfoByName(controlService, name, &info); - ASSERT_TRUE(success); - ASSERT_EQ(info.name, name); - ASSERT_EQ(info.pid, getpid()); - ASSERT_FALSE(info.isActive); -} - } // namespace android