From 2c1b9b8e80c6cb017a03211667b51ee5b1234d1c Mon Sep 17 00:00:00 2001 From: Remi NGUYEN VAN Date: Fri, 6 Jan 2023 10:57:12 +0900 Subject: [PATCH] Only allow libconnectivity_native usage on U+ No user of the API is expected before U, so limit its usage to U+. Bug: 262199896 Test: atest Change-Id: I211f459a729c216eb1ba9e3b983042e4afcbd135 --- service/libconnectivity/Android.bp | 1 + service/libconnectivity/src/connectivity_native.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/service/libconnectivity/Android.bp b/service/libconnectivity/Android.bp index 391ceacab9..e063af7ce6 100644 --- a/service/libconnectivity/Android.bp +++ b/service/libconnectivity/Android.bp @@ -27,6 +27,7 @@ cc_library_shared { min_sdk_version: "30", static_libs: [ "connectivity_native_aidl_interface-V1-ndk", + "libmodules-utils-build", ], export_include_dirs: ["include"], cflags: [ diff --git a/service/libconnectivity/src/connectivity_native.cpp b/service/libconnectivity/src/connectivity_native.cpp index 9545ed1ec0..49622ae3a5 100644 --- a/service/libconnectivity/src/connectivity_native.cpp +++ b/service/libconnectivity/src/connectivity_native.cpp @@ -17,6 +17,7 @@ #include "connectivity_native.h" #include +#include #include using aidl::android::net::connectivity::aidl::IConnectivityNative; @@ -44,21 +45,25 @@ static int getErrno(const ::ndk::ScopedAStatus& status) { } int AConnectivityNative_blockPortForBind(in_port_t port) { + if (!android::modules::sdklevel::IsAtLeastU()) return ENOSYS; std::shared_ptr c = getBinder(); return getErrno(c->blockPortForBind(port)); } int AConnectivityNative_unblockPortForBind(in_port_t port) { + if (!android::modules::sdklevel::IsAtLeastU()) return ENOSYS; std::shared_ptr c = getBinder(); return getErrno(c->unblockPortForBind(port)); } int AConnectivityNative_unblockAllPortsForBind() { + if (!android::modules::sdklevel::IsAtLeastU()) return ENOSYS; std::shared_ptr c = getBinder(); return getErrno(c->unblockAllPortsForBind()); } int AConnectivityNative_getPortsBlockedForBind(in_port_t *ports, size_t *count) { + if (!android::modules::sdklevel::IsAtLeastU()) return ENOSYS; std::shared_ptr c = getBinder(); std::vector actualBlockedPorts; int err = getErrno(c->getPortsBlockedForBind(&actualBlockedPorts));