Merged-In Revert "libpower: RAII wake lock implementation"
This reverts commit 23009bb199
.
Reason for revert: Breaks the build
Change-Id: I347928c4d444f4b1ce9d79f855c171626c0214c0
This commit is contained in:
parent
23009bb199
commit
acf23a23e7
4 changed files with 9 additions and 107 deletions
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -17,10 +17,6 @@
|
|||
#ifndef _HARDWARE_POWER_H
|
||||
#define _HARDWARE_POWER_H
|
||||
|
||||
#if __cplusplus
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#endif
|
||||
#include <stdint.h>
|
||||
|
||||
#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<WakeLockImpl> mImpl;
|
||||
};
|
||||
|
||||
} // namespace power
|
||||
} // namespace android
|
||||
#endif
|
||||
|
||||
#endif // _HARDWARE_POWER_H
|
||||
|
|
25
power.cpp
25
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<WakeLockImpl>(name)) {}
|
||||
|
||||
WakeLock::~WakeLock() = default;
|
||||
|
||||
class WakeLock::WakeLockImpl {
|
||||
public:
|
||||
WakeLockImpl(const std::string& name) : mWakeLock(nullptr) {
|
||||
static sp<ISystemSuspend> 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<IWakeLock> mWakeLock;
|
||||
};
|
||||
|
||||
} // namespace android::power
|
||||
|
|
|
@ -14,9 +14,6 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <android/system/suspend/ISuspendControlService.h>
|
||||
#include <binder/IServiceManager.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include <hardware_legacy/power.h>
|
||||
|
||||
#include <csignal>
|
||||
|
@ -25,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 {
|
||||
|
@ -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<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;
|
||||
}
|
||||
|
||||
// Test RAII properties of WakeLock class.
|
||||
TEST(LibpowerTest, RAIIWakeLock) {
|
||||
sp<IBinder> control =
|
||||
android::defaultServiceManager()->getService(android::String16("suspend_control"));
|
||||
ASSERT_NE(control, nullptr) << "failed to get the suspend control service";
|
||||
sp<ISuspendControlService> controlService = interface_cast<ISuspendControlService>(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
|
||||
|
|
Loading…
Reference in a new issue