David 'Digit' Turner | 23d2439 | 2010-12-06 12:05:11 +0100 | [diff] [blame] | 1 | /* |
| 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 Hughes | 4aa2e6a | 2014-05-07 12:37:44 -0700 | [diff] [blame] | 28 | |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 29 | #pragma once |
| 30 | |
| 31 | /** |
Dan Albert | d8f4691 | 2020-08-07 13:54:49 -0700 | [diff] [blame] | 32 | * @defgroup apilevels API Levels |
| 33 | * |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 34 | * Defines functions for working with Android API levels. |
Dan Albert | d8f4691 | 2020-08-07 13:54:49 -0700 | [diff] [blame] | 35 | * @{ |
| 36 | */ |
| 37 | |
| 38 | /** |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 39 | * @file android/api-level.h |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 40 | * @brief Functions for dealing with multiple API levels. |
Elliott Hughes | 80e9f65 | 2019-10-14 12:19:29 -0700 | [diff] [blame] | 41 | * |
Elliott Hughes | 273080f | 2025-03-07 05:25:39 -0800 | [diff] [blame] | 42 | * See also |
| 43 | * https://developer.android.com/ndk/guides/using-newer-apis |
| 44 | * for more tutorial information on dealing with multiple API levels. |
| 45 | * |
| 46 | * See also |
| 47 | * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md |
| 48 | * for when to use which `#define` when writing portable code. |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 49 | */ |
David 'Digit' Turner | 23d2439 | 2010-12-06 12:05:11 +0100 | [diff] [blame] | 50 | |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 51 | #include <sys/cdefs.h> |
| 52 | |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 53 | __BEGIN_DECLS |
| 54 | |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 55 | /** |
Elliott Hughes | 80e9f65 | 2019-10-14 12:19:29 -0700 | [diff] [blame] | 56 | * Magic version number for an Android OS build which has not yet turned |
| 57 | * into an official release, for comparison against `__ANDROID_API__`. See |
Elliott Hughes | 9c06d16 | 2023-10-04 23:36:14 +0000 | [diff] [blame] | 58 | * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md. |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 59 | */ |
Dan Albert | 495ec92 | 2016-09-21 01:08:44 -0700 | [diff] [blame] | 60 | #define __ANDROID_API_FUTURE__ 10000 |
Dan Albert | 495ec92 | 2016-09-21 01:08:44 -0700 | [diff] [blame] | 61 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame] | 62 | /* This #ifndef should never be true except when doxygen is generating docs. */ |
Josh Gao | 99739d4 | 2016-04-13 17:16:47 -0700 | [diff] [blame] | 63 | #ifndef __ANDROID_API__ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 64 | /** |
Dan Albert | d8f4691 | 2020-08-07 13:54:49 -0700 | [diff] [blame] | 65 | * `__ANDROID_API__` is the [API |
| 66 | * level](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) |
| 67 | * this code is being built for. The resulting binaries are only guaranteed to |
| 68 | * be compatible with devices which have an API level greater than or equal to |
| 69 | * `__ANDROID_API__`. |
| 70 | * |
| 71 | * For NDK and APEX builds, this macro will always be defined. It is set |
| 72 | * automatically by Clang using the version suffix that is a part of the target |
| 73 | * name. For example, `__ANDROID_API__` will be 24 when Clang is given the |
| 74 | * argument `-target aarch64-linux-android24`. |
| 75 | * |
| 76 | * For non-APEX OS code, this defaults to __ANDROID_API_FUTURE__. |
| 77 | * |
| 78 | * The value of `__ANDROID_API__` can be compared to the named constants in |
| 79 | * `<android/api-level.h>`. |
| 80 | * |
| 81 | * The interpretation of `__ANDROID_API__` is similar to the AndroidManifest.xml |
| 82 | * `minSdkVersion`. In most cases `__ANDROID_API__` will be identical to |
| 83 | * `minSdkVersion`, but as it is a build time constant it is possible for |
| 84 | * library code to use a different value than the app it will be included in. |
| 85 | * When libraries and applications build for different API levels, the |
| 86 | * `minSdkVersion` of the application must be at least as high as the highest |
| 87 | * API level used by any of its libraries which are loaded unconditionally. |
| 88 | * |
| 89 | * Note that in some cases the resulting binaries may load successfully on |
| 90 | * devices with an older API level. That behavior should not be relied upon, |
| 91 | * even if you are careful to avoid using new APIs, as the toolchain may make |
| 92 | * use of new features by default. For example, additional FORTIFY features may |
| 93 | * implicitly make use of new APIs, SysV hashes may be omitted in favor of GNU |
| 94 | * hashes to improve library load times, or relocation packing may be enabled to |
| 95 | * reduce binary size. |
| 96 | * |
| 97 | * See android_get_device_api_level(), |
| 98 | * android_get_application_target_sdk_version() and |
Elliott Hughes | 9c06d16 | 2023-10-04 23:36:14 +0000 | [diff] [blame] | 99 | * https://android.googlesource.com/platform/bionic/+/main/docs/defines.md. |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 100 | */ |
Dan Albert | 495ec92 | 2016-09-21 01:08:44 -0700 | [diff] [blame] | 101 | #define __ANDROID_API__ __ANDROID_API_FUTURE__ |
Josh Gao | 99739d4 | 2016-04-13 17:16:47 -0700 | [diff] [blame] | 102 | #endif |
David 'Digit' Turner | 23d2439 | 2010-12-06 12:05:11 +0100 | [diff] [blame] | 103 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 104 | /** Deprecated name for API level 9. Prefer numeric API levels in new code. */ |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 105 | #define __ANDROID_API_G__ 9 |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 106 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 107 | /** Deprecated name for API level 14. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 108 | #define __ANDROID_API_I__ 14 |
| 109 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 110 | /** Deprecated name for API level 16. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 111 | #define __ANDROID_API_J__ 16 |
| 112 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 113 | /** Deprecated name for API level 17. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 114 | #define __ANDROID_API_J_MR1__ 17 |
| 115 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 116 | /** Deprecated name for API level 18. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 117 | #define __ANDROID_API_J_MR2__ 18 |
| 118 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 119 | /** Deprecated name for API level 19. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 120 | #define __ANDROID_API_K__ 19 |
| 121 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 122 | /** Deprecated name for API level 21. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 123 | #define __ANDROID_API_L__ 21 |
| 124 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 125 | /** Deprecated name for API level 22. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 126 | #define __ANDROID_API_L_MR1__ 22 |
| 127 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 128 | /** Deprecated name for API level 23. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 129 | #define __ANDROID_API_M__ 23 |
| 130 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 131 | /** Deprecated name for API level 24. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 132 | #define __ANDROID_API_N__ 24 |
| 133 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 134 | /** Deprecated name for API level 25. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 135 | #define __ANDROID_API_N_MR1__ 25 |
| 136 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 137 | /** Deprecated name for API level 26. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 138 | #define __ANDROID_API_O__ 26 |
| 139 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 140 | /** Deprecated name for API level 27. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 141 | #define __ANDROID_API_O_MR1__ 27 |
| 142 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 143 | /** Deprecated name for API level 28. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 144 | #define __ANDROID_API_P__ 28 |
| 145 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 146 | /** Deprecated name for API level 29. Prefer numeric API levels in new code. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 147 | #define __ANDROID_API_Q__ 29 |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 148 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 149 | /** Deprecated name for API level 30. Prefer numeric API levels in new code. */ |
Elliott Hughes | 4206711 | 2019-04-18 14:27:24 -0700 | [diff] [blame] | 150 | #define __ANDROID_API_R__ 30 |
| 151 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 152 | /** Deprecated name for API level 31. Prefer numeric API levels in new code. */ |
Dan Albert | 14dcbf8 | 2020-03-26 16:18:13 -0700 | [diff] [blame] | 153 | #define __ANDROID_API_S__ 31 |
| 154 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 155 | /** Deprecated name for API level 33. Prefer numeric API levels in new code. */ |
Dan Albert | e791552 | 2021-09-08 14:57:46 -0700 | [diff] [blame] | 156 | #define __ANDROID_API_T__ 33 |
| 157 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 158 | /** Deprecated name for API level 34. Prefer numeric API levels in new code. */ |
Michael Wright | 8cd2ebf | 2022-06-25 00:55:56 +0000 | [diff] [blame] | 159 | #define __ANDROID_API_U__ 34 |
| 160 | |
Elliott Hughes | e9a34c5 | 2025-02-18 10:53:18 -0800 | [diff] [blame] | 161 | /** Deprecated name for API level 35. Prefer numeric API levels in new code. */ |
Dan Albert | b3e895c | 2023-03-23 18:35:16 +0000 | [diff] [blame] | 162 | #define __ANDROID_API_V__ 35 |
| 163 | |
Elliott Hughes | 43978a0 | 2021-01-07 17:15:41 -0800 | [diff] [blame] | 164 | /* This file is included in <features.h>, and might be used from .S files. */ |
| 165 | #if !defined(__ASSEMBLY__) |
| 166 | |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 167 | /** |
Dan Albert | d8f4691 | 2020-08-07 13:54:49 -0700 | [diff] [blame] | 168 | * Returns the `targetSdkVersion` of the caller, or `__ANDROID_API_FUTURE__` if |
| 169 | * there is no known target SDK version (for code not running in the context of |
| 170 | * an app). |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 171 | * |
| 172 | * The returned values correspond to the named constants in `<android/api-level.h>`, |
| 173 | * and is equivalent to the AndroidManifest.xml `targetSdkVersion`. |
| 174 | * |
| 175 | * See also android_get_device_api_level(). |
| 176 | * |
| 177 | * Available since API level 24. |
| 178 | */ |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame] | 179 | #if __BIONIC_AVAILABILITY_GUARD(24) |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 180 | int android_get_application_target_sdk_version() __INTRODUCED_IN(24); |
Dan Albert | 02ce401 | 2024-10-25 19:13:49 +0000 | [diff] [blame] | 181 | #endif /* __BIONIC_AVAILABILITY_GUARD(24) */ |
| 182 | |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 183 | |
Elliott Hughes | 95c6cd7 | 2019-12-20 13:26:14 -0800 | [diff] [blame] | 184 | #if __ANDROID_API__ < 29 |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 185 | |
Elliott Hughes | 43978a0 | 2021-01-07 17:15:41 -0800 | [diff] [blame] | 186 | /* android_get_device_api_level is a static inline before API level 29. */ |
Dan Albert | 2237fcf | 2024-05-14 17:53:58 +0000 | [diff] [blame] | 187 | #define __BIONIC_GET_DEVICE_API_LEVEL_INLINE static __inline |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 188 | #include <bits/get_device_api_level_inlines.h> |
| 189 | #undef __BIONIC_GET_DEVICE_API_LEVEL_INLINE |
| 190 | |
| 191 | #else |
| 192 | |
| 193 | /** |
| 194 | * Returns the API level of the device we're actually running on, or -1 on failure. |
| 195 | * The returned values correspond to the named constants in `<android/api-level.h>`, |
| 196 | * and is equivalent to the Java `Build.VERSION.SDK_INT` API. |
| 197 | * |
| 198 | * See also android_get_application_target_sdk_version(). |
Elliott Hughes | 273080f | 2025-03-07 05:25:39 -0800 | [diff] [blame] | 199 | * |
| 200 | * Available since API level 29. |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 201 | */ |
| 202 | int android_get_device_api_level() __INTRODUCED_IN(29); |
| 203 | |
| 204 | #endif |
| 205 | |
Elliott Hughes | 43978a0 | 2021-01-07 17:15:41 -0800 | [diff] [blame] | 206 | #endif /* defined(__ASSEMBLY__) */ |
| 207 | |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 208 | __END_DECLS |
Dan Albert | d8f4691 | 2020-08-07 13:54:49 -0700 | [diff] [blame] | 209 | |
| 210 | /** @} */ |