Merge "Remove libbinder from libpower" am: 250b4c2b0a

Original change: https://android-review.googlesource.com/c/platform/hardware/libhardware_legacy/+/2370628

Change-Id: Idebc797cc42864a898dd5d99e2b26a506c25d2b5
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jooyung Han 2022-12-28 02:21:12 +00:00 committed by Automerger Merge Worker
commit d74e0baa5e
2 changed files with 19 additions and 17 deletions

View file

@ -29,6 +29,9 @@ cc_library_headers {
cc_defaults { cc_defaults {
name: "libpower_defaults", name: "libpower_defaults",
defaults: ["system_suspend_defaults"], defaults: ["system_suspend_defaults"],
// system_suspend_defaults adds libbinder, but libbpower doesn't need it
// because libpower now uses libbinder_ndk.
exclude_shared_libs: ["libbinder"],
cflags: [ cflags: [
"-Wexit-time-destructors", "-Wexit-time-destructors",
"-fno-c++-static-destructors", "-fno-c++-static-destructors",
@ -56,9 +59,9 @@ cc_test {
name: "libpower_test", name: "libpower_test",
defaults: ["libpower_defaults"], defaults: ["libpower_defaults"],
srcs: ["power_test.cpp"], srcs: ["power_test.cpp"],
static_libs: ["libpower"], static_libs: [
shared_libs: [ "libpower",
"android.system.suspend.control.internal-cpp", "android.system.suspend.control.internal-ndk",
"android.system.suspend-V1-ndk", "android.system.suspend-V1-ndk",
], ],
test_suites: ["device-tests"], test_suites: ["device-tests"],

View file

@ -14,21 +14,21 @@
* limitations under the License. * limitations under the License.
*/ */
#include <android/system/suspend/internal/ISuspendControlServiceInternal.h> #include <aidl/android/system/suspend/internal/ISuspendControlServiceInternal.h>
#include <binder/IServiceManager.h> #include <android/binder_manager.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <hardware_legacy/power.h> #include <hardware_legacy/power.h>
#include <wakelock/wakelock.h> #include <wakelock/wakelock.h>
#include <csignal> #include <csignal>
#include <cstdlib> #include <cstdlib>
#include <memory>
#include <string> #include <string>
#include <thread> #include <thread>
#include <vector> #include <vector>
using android::sp; using aidl::android::system::suspend::internal::ISuspendControlServiceInternal;
using android::system::suspend::internal::ISuspendControlServiceInternal; using aidl::android::system::suspend::internal::WakeLockInfo;
using android::system::suspend::internal::WakeLockInfo;
using namespace std::chrono_literals; using namespace std::chrono_literals;
namespace android { namespace android {
@ -93,17 +93,16 @@ TEST(LibpowerTest, WakeLockStressTest) {
class WakeLockTest : public ::testing::Test { class WakeLockTest : public ::testing::Test {
public: public:
virtual void SetUp() override { virtual void SetUp() override {
sp<IBinder> control = ndk::SpAIBinder binder(AServiceManager_waitForService("suspend_control_internal"));
android::defaultServiceManager()->getService(android::String16("suspend_control_internal")); controlService = ISuspendControlServiceInternal::fromBinder(binder);
ASSERT_NE(control, nullptr) << "failed to get the internal suspend control service"; ASSERT_NE(controlService, nullptr) << "failed to get the internal suspend control service";
controlService = interface_cast<ISuspendControlServiceInternal>(control);
} }
// Returns true iff found. // Returns true iff found.
bool findWakeLockInfoByName(const sp<ISuspendControlServiceInternal>& service, const std::string& name, bool findWakeLockInfoByName(const std::string& name,
WakeLockInfo* info) { WakeLockInfo* info) {
std::vector<WakeLockInfo> wlStats; std::vector<WakeLockInfo> wlStats;
service->getWakeLockStats(&wlStats); controlService->getWakeLockStats(&wlStats);
auto it = std::find_if(wlStats.begin(), wlStats.end(), auto it = std::find_if(wlStats.begin(), wlStats.end(),
[&name](const auto& x) { return x.name == name; }); [&name](const auto& x) { return x.name == name; });
if (it != wlStats.end()) { if (it != wlStats.end()) {
@ -114,7 +113,7 @@ class WakeLockTest : public ::testing::Test {
} }
// All userspace wake locks are registered with system suspend. // All userspace wake locks are registered with system suspend.
sp<ISuspendControlServiceInternal> controlService; std::shared_ptr<ISuspendControlServiceInternal> controlService;
}; };
// Test RAII properties of WakeLock destructor. // Test RAII properties of WakeLock destructor.
@ -127,7 +126,7 @@ TEST_F(WakeLockTest, WakeLockDestructor) {
} }
WakeLockInfo info; WakeLockInfo info;
auto success = findWakeLockInfoByName(controlService, name, &info); auto success = findWakeLockInfoByName(name, &info);
ASSERT_TRUE(success); ASSERT_TRUE(success);
ASSERT_EQ(info.name, name); ASSERT_EQ(info.name, name);
ASSERT_EQ(info.pid, getpid()); ASSERT_EQ(info.pid, getpid());
@ -138,7 +137,7 @@ TEST_F(WakeLockTest, WakeLockDestructor) {
// come on binder thread. Sleep to make sure that stats are reported *after* wake lock release. // come on binder thread. Sleep to make sure that stats are reported *after* wake lock release.
std::this_thread::sleep_for(1ms); std::this_thread::sleep_for(1ms);
WakeLockInfo info; WakeLockInfo info;
auto success = findWakeLockInfoByName(controlService, name, &info); auto success = findWakeLockInfoByName(name, &info);
ASSERT_TRUE(success); ASSERT_TRUE(success);
ASSERT_EQ(info.name, name); ASSERT_EQ(info.name, name);
ASSERT_EQ(info.pid, getpid()); ASSERT_EQ(info.pid, getpid());