Make uid related tests compatible with Android Q
To be compatible with VPN isolation feature, DnsResolver has
different behavior fchown'ing when query socket.
sdk version >= (R+), fchown to apps' uid, otherwise fchown to AID_DNS
Make relevant tests compatible with it.
Test: atest
Bug: 161509097
Change-Id: I1c0bb4b9f35eaae32977a51c2d0a968092095cd0
diff --git a/util.h b/util.h
index d13a032..38f09b8 100644
--- a/util.h
+++ b/util.h
@@ -21,9 +21,29 @@
#include <netinet/in.h>
+#include <android-base/properties.h>
+
socklen_t sockaddrSize(const sockaddr* sa);
socklen_t sockaddrSize(const sockaddr_storage& ss);
// TODO: getExperimentFlagString
// TODO: Migrate it to DnsResolverExperiments.cpp
int getExperimentFlagInt(const std::string& flagName, int defaultValue);
+
+// When sdk X release branch is created, aosp's sdk version would still be X-1,
+// internal would be X. Also there might be some different setting between real devices and
+// CF. Below is the example for the sdk related properties in later R development stage. (internal
+// should be cosidered as S and aosp should be considered as R.)
+// R version is 30, rvc-dev aosp(CF) aosp(non-CF) internal
+// ro.build.version.sdk: [30] [29] [29] [30]
+// Note that, ro.product.first_api_level is device specific - so the value might be various.
+// ro.product.first_api_level: [26-30] [31] [28] [26-30]
+// ro.build.version.preview_sdk: [0] [1] [1] [1]
+inline uint64_t getApiLevel() {
+ uint64_t buildVersionSdk = android::base::GetUintProperty<uint64_t>("ro.build.version.sdk", 0);
+ uint64_t buildVersionPreviewSdk =
+ android::base::GetUintProperty<uint64_t>("ro.build.version.preview_sdk", 0);
+ uint64_t firstApiLevel =
+ android::base::GetUintProperty<uint64_t>("ro.product.first_api_level", 0);
+ return std::max(buildVersionSdk + !!buildVersionPreviewSdk, firstApiLevel);
+}