summaryrefslogtreecommitdiff
path: root/libc/include/android/api-level.h
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-11-09 15:38:52 -0800
committerElliott Hughes <enh@google.com>2018-11-15 11:07:30 -0800
commitc0f46564528c7bec8d490e62633e962f2007b8f4 (patch)
tree4dabb94963f869576828c5d169e74956f527031a /libc/include/android/api-level.h
parent83590680649dc04ce8a98cd85b6356e1d6066564 (diff)
Make android_get_application_target_sdk_version available to the NDK.
Also move this and android_get_device_api_level into <android/api-level.h> so that they're always available. This involves cleaning up <sys/cdefs.h> slightly. Bug: N/A Test: builds Change-Id: I25435c55f3549cd0d827a7581bee75ea8228028b
Diffstat (limited to 'libc/include/android/api-level.h')
-rw-r--r--libc/include/android/api-level.h38
1 files changed, 38 insertions, 0 deletions
diff --git a/libc/include/android/api-level.h b/libc/include/android/api-level.h
index 3a8f92663..d1d1aeadf 100644
--- a/libc/include/android/api-level.h
+++ b/libc/include/android/api-level.h
@@ -35,6 +35,8 @@
#include <sys/cdefs.h>
+__BEGIN_DECLS
+
#ifndef __ANDROID_API_FUTURE__
/**
* Magic version number for an Android OS build which has
@@ -97,3 +99,39 @@
/** Names the "Q" API level (29), for comparisons against __ANDROID_API__. */
#define __ANDROID_API_Q__ 29
+
+/**
+ * Returns the `targetSdkVersion` of the caller, or `__ANDROID_API_FUTURE__`
+ * if there is no known target SDK version (for code not running in the
+ * context of an app).
+ *
+ * The returned values correspond to the named constants in `<android/api-level.h>`,
+ * and is equivalent to the AndroidManifest.xml `targetSdkVersion`.
+ *
+ * See also android_get_device_api_level().
+ *
+ * Available since API level 24.
+ */
+int android_get_application_target_sdk_version() __INTRODUCED_IN(24);
+
+#if __ANDROID_API__ < __ANDROID_API_Q__
+
+// android_get_application_target_sdk_version is a static inline before API level 29.
+#define __BIONIC_GET_DEVICE_API_LEVEL_INLINE static __inline
+#include <bits/get_device_api_level_inlines.h>
+#undef __BIONIC_GET_DEVICE_API_LEVEL_INLINE
+
+#else
+
+/**
+ * Returns the API level of the device we're actually running on, or -1 on failure.
+ * The returned values correspond to the named constants in `<android/api-level.h>`,
+ * and is equivalent to the Java `Build.VERSION.SDK_INT` API.
+ *
+ * See also android_get_application_target_sdk_version().
+ */
+int android_get_device_api_level() __INTRODUCED_IN(29);
+
+#endif
+
+__END_DECLS