diff options
-rw-r--r-- | Android.bp | 6 | ||||
-rw-r--r-- | audio/Android.bp | 1 | ||||
-rw-r--r-- | include/wakelock/wakelock.h | 37 | ||||
-rw-r--r-- | power.cpp | 36 | ||||
-rw-r--r-- | power_test.cpp | 67 |
5 files changed, 6 insertions, 141 deletions
@@ -35,12 +35,8 @@ 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, } cc_library_shared { diff --git a/audio/Android.bp b/audio/Android.bp index b4c0799..a7c51af 100644 --- a/audio/Android.bp +++ b/audio/Android.bp @@ -21,7 +21,6 @@ cc_library_static { ], header_libs: [ - "libaudioclient_headers", "libbase_headers", "libhardware_legacy_headers", ], diff --git a/include/wakelock/wakelock.h b/include/wakelock/wakelock.h deleted file mode 100644 index 75a7c72..0000000 --- a/include/wakelock/wakelock.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include <memory> -#include <string> - -namespace android { -namespace wakelock { - -// RAII-style wake lock implementation -class WakeLock { - public: - WakeLock(const std::string& name); - ~WakeLock(); - - private: - class WakeLockImpl; - std::unique_ptr<WakeLockImpl> mImpl; -}; - -} // namespace wakelock -} // namespace android @@ -17,11 +17,9 @@ #define LOG_TAG "power" #define ATRACE_TAG ATRACE_TAG_POWER -#include <hardware_legacy/power.h> -#include <wakelock/wakelock.h> - #include <android-base/logging.h> #include <android/system/suspend/1.0/ISystemSuspend.h> +#include <hardware_legacy/power.h> #include <utils/Trace.h> #include <mutex> @@ -46,7 +44,6 @@ int acquire_wake_lock(int, const char* id) { ATRACE_CALL(); const auto& suspendService = getSystemSuspendServiceOnce(); if (!suspendService) { - LOG(ERROR) << "ISystemSuspend::getService() failed."; return -1; } @@ -80,34 +77,3 @@ int release_wake_lock(const char* id) { } return -1; } - -namespace android { -namespace wakelock { - -class WakeLock::WakeLockImpl { - public: - WakeLockImpl(const std::string& name); - ~WakeLockImpl(); - - private: - sp<IWakeLock> mWakeLock; -}; - -WakeLock::WakeLock(const std::string& name) : mImpl(std::make_unique<WakeLockImpl>(name)) {} - -WakeLock::~WakeLock() = default; - -WakeLock::WakeLockImpl::WakeLockImpl(const std::string& name) : mWakeLock(nullptr) { - static sp<ISystemSuspend> suspendService = ISystemSuspend::getService(); - mWakeLock = suspendService->acquireWakeLock(WakeLockType::PARTIAL, name); -} - -WakeLock::WakeLockImpl::~WakeLockImpl() { - auto ret = mWakeLock->release(); - if (!ret.isOk()) { - LOG(ERROR) << "IWakeLock::release() call failed: " << ret.description(); - } -} - -} // namespace wakelock -} // namespace android diff --git a/power_test.cpp b/power_test.cpp index d6e414d..601df64 100644 --- a/power_test.cpp +++ b/power_test.cpp @@ -14,11 +14,7 @@ * limitations under the License. */ -#include <android/system/suspend/ISuspendControlService.h> -#include <binder/IServiceManager.h> -#include <gtest/gtest.h> #include <hardware_legacy/power.h> -#include <wakelock/wakelock.h> #include <csignal> #include <cstdlib> @@ -26,9 +22,8 @@ #include <thread> #include <vector> -using android::sp; -using android::system::suspend::ISuspendControlService; -using android::system::suspend::WakeLockInfo; +#include <gtest/gtest.h> + using namespace std::chrono_literals; namespace android { @@ -78,10 +73,8 @@ 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); + ASSERT_EQ(release_wake_lock(id.c_str()), 0); } }); } @@ -90,56 +83,4 @@ TEST(LibpowerTest, WakeLockStressTest) { } } -class WakeLockTest : public ::testing::Test { - public: - virtual void SetUp() override { - sp<IBinder> control = - android::defaultServiceManager()->getService(android::String16("suspend_control")); - ASSERT_NE(control, nullptr) << "failed to get the suspend control service"; - controlService = interface_cast<ISuspendControlService>(control); - } - - // Returns true iff found. - bool findWakeLockInfoByName(const sp<ISuspendControlService>& service, const std::string& name, - WakeLockInfo* info) { - std::vector<WakeLockInfo> 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; - } - - // All userspace wake locks are registered with system suspend. - sp<ISuspendControlService> controlService; -}; - -// Test RAII properties of WakeLock destructor. -TEST_F(WakeLockTest, WakeLockDestructor) { - auto name = std::to_string(rand()); - { - android::wakelock::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 |