From df6cf300753fa96bc8aedbb677b474681a6f48e0 Mon Sep 17 00:00:00 2001 From: Tyler Wear Date: Wed, 8 Mar 2023 11:22:10 -0800 Subject: [PATCH] libconnectivity_native add null check Return null if service is not yet up. Bug: 271243867 Test: atest connectivity_native_test Change-Id: I18c887415e94e44eabcfd1c6bab1d22744f39723 --- .../libconnectivity/src/connectivity_native.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/service/libconnectivity/src/connectivity_native.cpp b/service/libconnectivity/src/connectivity_native.cpp index 9545ed1ec0..a476498ecc 100644 --- a/service/libconnectivity/src/connectivity_native.cpp +++ b/service/libconnectivity/src/connectivity_native.cpp @@ -23,8 +23,8 @@ using aidl::android::net::connectivity::aidl::IConnectivityNative; static std::shared_ptr getBinder() { - static ndk::SpAIBinder sBinder = ndk::SpAIBinder(reinterpret_cast( - AServiceManager_getService("connectivity_native"))); + ndk::SpAIBinder sBinder = ndk::SpAIBinder(reinterpret_cast( + AServiceManager_checkService("connectivity_native"))); return aidl::android::net::connectivity::aidl::IConnectivityNative::fromBinder(sBinder); } @@ -45,21 +45,33 @@ static int getErrno(const ::ndk::ScopedAStatus& status) { int AConnectivityNative_blockPortForBind(in_port_t port) { std::shared_ptr c = getBinder(); + if (!c) { + return EAGAIN; + } return getErrno(c->blockPortForBind(port)); } int AConnectivityNative_unblockPortForBind(in_port_t port) { std::shared_ptr c = getBinder(); + if (!c) { + return EAGAIN; + } return getErrno(c->unblockPortForBind(port)); } int AConnectivityNative_unblockAllPortsForBind() { std::shared_ptr c = getBinder(); + if (!c) { + return EAGAIN; + } return getErrno(c->unblockAllPortsForBind()); } int AConnectivityNative_getPortsBlockedForBind(in_port_t *ports, size_t *count) { std::shared_ptr c = getBinder(); + if (!c) { + return EAGAIN; + } std::vector actualBlockedPorts; int err = getErrno(c->getPortsBlockedForBind(&actualBlockedPorts)); if (err) {