blob: 113897c9727d2f7468c0c8a7c9a39a7bcf5925ea [file] [log] [blame]
David 'Digit' Turner23d24392010-12-06 12:05:11 +01001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in
12 * the documentation and/or other materials provided with the
13 * distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
Elliott Hughes4aa2e6a2014-05-07 12:37:44 -070028
Elliott Hughesce934e32018-09-06 13:26:08 -070029#pragma once
30
31/**
Dan Albertd8f46912020-08-07 13:54:49 -070032 * @defgroup apilevels API Levels
33 *
34 * Defines functions and constants for working with Android API levels.
35 * @{
36 */
37
38/**
Elliott Hughesce934e32018-09-06 13:26:08 -070039 * @file android/api-level.h
40 * @brief Functions and constants for dealing with multiple API levels.
Elliott Hughes80e9f652019-10-14 12:19:29 -070041 *
42 * See
Elliott Hughes9c06d162023-10-04 23:36:14 +000043 * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md.
Elliott Hughesce934e32018-09-06 13:26:08 -070044 */
David 'Digit' Turner23d24392010-12-06 12:05:11 +010045
Elliott Hughes203e13d2016-07-22 14:56:18 -070046#include <sys/cdefs.h>
47
Elliott Hughesc0f46562018-11-09 15:38:52 -080048__BEGIN_DECLS
49
Elliott Hughesce934e32018-09-06 13:26:08 -070050/**
Elliott Hughes80e9f652019-10-14 12:19:29 -070051 * Magic version number for an Android OS build which has not yet turned
52 * into an official release, for comparison against `__ANDROID_API__`. See
Elliott Hughes9c06d162023-10-04 23:36:14 +000053 * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md.
Elliott Hughesce934e32018-09-06 13:26:08 -070054 */
Dan Albert495ec922016-09-21 01:08:44 -070055#define __ANDROID_API_FUTURE__ 10000
Dan Albert495ec922016-09-21 01:08:44 -070056
Elliott Hughes9823c922019-10-07 20:51:00 +000057/* This #ifndef should never be true except when doxygen is generating docs. */
Josh Gao99739d42016-04-13 17:16:47 -070058#ifndef __ANDROID_API__
Elliott Hughesce934e32018-09-06 13:26:08 -070059/**
Dan Albertd8f46912020-08-07 13:54:49 -070060 * `__ANDROID_API__` is the [API
61 * level](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)
62 * this code is being built for. The resulting binaries are only guaranteed to
63 * be compatible with devices which have an API level greater than or equal to
64 * `__ANDROID_API__`.
65 *
66 * For NDK and APEX builds, this macro will always be defined. It is set
67 * automatically by Clang using the version suffix that is a part of the target
68 * name. For example, `__ANDROID_API__` will be 24 when Clang is given the
69 * argument `-target aarch64-linux-android24`.
70 *
71 * For non-APEX OS code, this defaults to __ANDROID_API_FUTURE__.
72 *
73 * The value of `__ANDROID_API__` can be compared to the named constants in
74 * `<android/api-level.h>`.
75 *
76 * The interpretation of `__ANDROID_API__` is similar to the AndroidManifest.xml
77 * `minSdkVersion`. In most cases `__ANDROID_API__` will be identical to
78 * `minSdkVersion`, but as it is a build time constant it is possible for
79 * library code to use a different value than the app it will be included in.
80 * When libraries and applications build for different API levels, the
81 * `minSdkVersion` of the application must be at least as high as the highest
82 * API level used by any of its libraries which are loaded unconditionally.
83 *
84 * Note that in some cases the resulting binaries may load successfully on
85 * devices with an older API level. That behavior should not be relied upon,
86 * even if you are careful to avoid using new APIs, as the toolchain may make
87 * use of new features by default. For example, additional FORTIFY features may
88 * implicitly make use of new APIs, SysV hashes may be omitted in favor of GNU
89 * hashes to improve library load times, or relocation packing may be enabled to
90 * reduce binary size.
91 *
92 * See android_get_device_api_level(),
93 * android_get_application_target_sdk_version() and
Elliott Hughes9c06d162023-10-04 23:36:14 +000094 * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md.
Elliott Hughesce934e32018-09-06 13:26:08 -070095 */
Dan Albert495ec922016-09-21 01:08:44 -070096#define __ANDROID_API__ __ANDROID_API_FUTURE__
Josh Gao99739d42016-04-13 17:16:47 -070097#endif
David 'Digit' Turner23d24392010-12-06 12:05:11 +010098
Elliott Hughes9823c922019-10-07 20:51:00 +000099/** Names the Gingerbread API level (9), for comparison against `__ANDROID_API__`. */
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800100#define __ANDROID_API_G__ 9
Elliott Hughes5bc78c82016-11-16 11:35:43 -0800101
Elliott Hughes9823c922019-10-07 20:51:00 +0000102/** Names the Ice-Cream Sandwich API level (14), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700103#define __ANDROID_API_I__ 14
104
Elliott Hughes9823c922019-10-07 20:51:00 +0000105/** Names the Jellybean API level (16), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700106#define __ANDROID_API_J__ 16
107
Elliott Hughes9823c922019-10-07 20:51:00 +0000108/** Names the Jellybean MR1 API level (17), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700109#define __ANDROID_API_J_MR1__ 17
110
Elliott Hughes9823c922019-10-07 20:51:00 +0000111/** Names the Jellybean MR2 API level (18), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700112#define __ANDROID_API_J_MR2__ 18
113
Elliott Hughes9823c922019-10-07 20:51:00 +0000114/** Names the KitKat API level (19), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700115#define __ANDROID_API_K__ 19
116
Elliott Hughes9823c922019-10-07 20:51:00 +0000117/** Names the Lollipop API level (21), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700118#define __ANDROID_API_L__ 21
119
Elliott Hughes9823c922019-10-07 20:51:00 +0000120/** Names the Lollipop MR1 API level (22), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700121#define __ANDROID_API_L_MR1__ 22
122
Elliott Hughes9823c922019-10-07 20:51:00 +0000123/** Names the Marshmallow API level (23), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700124#define __ANDROID_API_M__ 23
125
Elliott Hughes9823c922019-10-07 20:51:00 +0000126/** Names the Nougat API level (24), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700127#define __ANDROID_API_N__ 24
128
Elliott Hughes9823c922019-10-07 20:51:00 +0000129/** Names the Nougat MR1 API level (25), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700130#define __ANDROID_API_N_MR1__ 25
131
Elliott Hughes9823c922019-10-07 20:51:00 +0000132/** Names the Oreo API level (26), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700133#define __ANDROID_API_O__ 26
134
Elliott Hughes9823c922019-10-07 20:51:00 +0000135/** Names the Oreo MR1 API level (27), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700136#define __ANDROID_API_O_MR1__ 27
137
Elliott Hughes9823c922019-10-07 20:51:00 +0000138/** Names the Pie API level (28), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700139#define __ANDROID_API_P__ 28
140
Elliott Hughes9823c922019-10-07 20:51:00 +0000141/**
Elliott Hughes7b396ae2022-07-15 17:04:50 -0700142 * Names the Android 10 (aka "Q" or "Quince Tart") API level (29), for
143 * comparison against `__ANDROID_API__`.
Elliott Hughes9823c922019-10-07 20:51:00 +0000144 */
Elliott Hughesce934e32018-09-06 13:26:08 -0700145#define __ANDROID_API_Q__ 29
Elliott Hughesc0f46562018-11-09 15:38:52 -0800146
Elliott Hughes7b396ae2022-07-15 17:04:50 -0700147/**
148 * Names the Android 11 (aka "R" or "Red Velvet Cake") API level (30), for
149 * comparison against `__ANDROID_API__`.
150 */
Elliott Hughes42067112019-04-18 14:27:24 -0700151#define __ANDROID_API_R__ 30
152
Elliott Hughes7b396ae2022-07-15 17:04:50 -0700153/**
154 * Names the Android 12 (aka "S" or "Snowcone") API level (31), for
155 * comparison against `__ANDROID_API__`.
156 */
Dan Albert14dcbf82020-03-26 16:18:13 -0700157#define __ANDROID_API_S__ 31
158
Elliott Hughes7b396ae2022-07-15 17:04:50 -0700159/**
160 * Names the Android 13 (aka "T" or "Tiramisu") API level (33), for
161 * comparison against `__ANDROID_API__`.
162 */
Dan Alberte7915522021-09-08 14:57:46 -0700163#define __ANDROID_API_T__ 33
164
Elliott Hughes572053a2023-03-23 21:30:15 +0000165/**
166 * Names the Android 14 (aka "U" or "UpsideDownCake") API level (34),
167 * for comparison against `__ANDROID_API__`.
168 */
Michael Wright8cd2ebf2022-06-25 00:55:56 +0000169#define __ANDROID_API_U__ 34
170
Dan Albertb3e895c2023-03-23 18:35:16 +0000171/** Names the "V" API level (35), for comparison against `__ANDROID_API__`. */
172#define __ANDROID_API_V__ 35
173
Elliott Hughes43978a02021-01-07 17:15:41 -0800174/* This file is included in <features.h>, and might be used from .S files. */
175#if !defined(__ASSEMBLY__)
176
Elliott Hughesc0f46562018-11-09 15:38:52 -0800177/**
Dan Albertd8f46912020-08-07 13:54:49 -0700178 * Returns the `targetSdkVersion` of the caller, or `__ANDROID_API_FUTURE__` if
179 * there is no known target SDK version (for code not running in the context of
180 * an app).
Elliott Hughesc0f46562018-11-09 15:38:52 -0800181 *
182 * The returned values correspond to the named constants in `<android/api-level.h>`,
183 * and is equivalent to the AndroidManifest.xml `targetSdkVersion`.
184 *
185 * See also android_get_device_api_level().
186 *
187 * Available since API level 24.
188 */
189int android_get_application_target_sdk_version() __INTRODUCED_IN(24);
190
Elliott Hughes95c6cd72019-12-20 13:26:14 -0800191#if __ANDROID_API__ < 29
Elliott Hughesc0f46562018-11-09 15:38:52 -0800192
Elliott Hughes43978a02021-01-07 17:15:41 -0800193/* android_get_device_api_level is a static inline before API level 29. */
Nick Desaulniers58f06e12024-04-17 10:23:50 -0700194#define __BIONIC_GET_DEVICE_API_LEVEL_INLINE static inline
Elliott Hughesc0f46562018-11-09 15:38:52 -0800195#include <bits/get_device_api_level_inlines.h>
196#undef __BIONIC_GET_DEVICE_API_LEVEL_INLINE
197
198#else
199
200/**
201 * Returns the API level of the device we're actually running on, or -1 on failure.
202 * The returned values correspond to the named constants in `<android/api-level.h>`,
203 * and is equivalent to the Java `Build.VERSION.SDK_INT` API.
204 *
205 * See also android_get_application_target_sdk_version().
206 */
207int android_get_device_api_level() __INTRODUCED_IN(29);
208
209#endif
210
Elliott Hughes43978a02021-01-07 17:15:41 -0800211#endif /* defined(__ASSEMBLY__) */
212
Elliott Hughesc0f46562018-11-09 15:38:52 -0800213__END_DECLS
Dan Albertd8f46912020-08-07 13:54:49 -0700214
215/** @} */