From ab8a7d2a03af7a6d4972a0cf40faf7aafc177fcf Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Tue, 11 Aug 2020 09:32:55 +0900 Subject: [PATCH] Cgroup APIs are guarded The following API was added for the API level 30 and beyond. Currently, its existence is tested using the null check which is done regardless of the min sdk version of the compilation unit. (which in turn required us to mark the API symbol weak regardless of the min sdk version.) * AGroupController_getFlags Now, we have a better way of testing the API availability; __builtin_available. The null check is replaced with the call to the compiler-provided macro which determines if the code is running in a version of OS where the API is known to exist. Bug: 150860940 Bug: 134795810 Test: m Change-Id: I5d17fc877c553c402a62485b61af574a54658a76 --- libprocessgroup/cgroup_map.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libprocessgroup/cgroup_map.cpp b/libprocessgroup/cgroup_map.cpp index b82b0ab63..5ca096787 100644 --- a/libprocessgroup/cgroup_map.cpp +++ b/libprocessgroup/cgroup_map.cpp @@ -71,7 +71,7 @@ bool CgroupController::IsUsable() { if (!HasValue()) return false; if (state_ == UNKNOWN) { - if (ACgroupController_getFlags != nullptr) { + if (__builtin_available(android 30, *)) { uint32_t flags = ACgroupController_getFlags(controller_); state_ = (flags & CGROUPRC_CONTROLLER_FLAG_MOUNTED) != 0 ? USABLE : MISSING; } else { @@ -172,7 +172,7 @@ void CgroupMap::Print() const { auto controller_count = ACgroupFile_getControllerCount(); for (uint32_t i = 0; i < controller_count; ++i) { const ACgroupController* controller = ACgroupFile_getController(i); - if (ACgroupController_getFlags != nullptr) { + if (__builtin_available(android 30, *)) { LOG(INFO) << "\t" << ACgroupController_getName(controller) << " ver " << ACgroupController_getVersion(controller) << " path " << ACgroupController_getPath(controller) << " flags "