API availability should be checked using __builtin_available

This change turns -Wunguarded-availability option which enforces calls
to APIs which are introduced after the min_sdk_version of the
compliation unit to be guarded with __builtin_available check. For
example, let's assume that we have foo() which was introduced with API
level 30.

void foo() __INTRODUCED_IN(30);

Then if foo() is called for a module whose min_sdk_version is less than
30, say 26, it should be called as below:

if (__builtin_available(android 30, *)) {
  foo();
} else {
  // fallback impl
}

For modules whose min_sdk_version is >=30, the guard is not required.

Bug: 150860940
Bug: 134795810
Test: m

Change-Id: I084148b9a051350626a37cb394daa4398b7332d5
This commit is contained in:
Jiyong Park
2020-08-11 09:35:08 +09:00
parent b35a819834
commit 423e37873b

View File

@@ -141,6 +141,13 @@ func init() {
// Warnings from clang-10
// Nested and array designated initialization is nice to have.
"-Wno-c99-designator",
// Calls to the APIs that are newer than the min sdk version of the caller should be
// guarded with __builtin_available.
"-Wunguarded-availability",
// This macro allows the bionic versioning.h to indirectly determine whether the
// option -Wunguarded-availability is on or not.
"-D__ANDROID_UNGUARDED_AVAILABILITY__",
}, " "))
pctx.StaticVariable("ClangExtraCppflags", strings.Join([]string{