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) {