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 | /** |
| 32 | * @file android/api-level.h |
| 33 | * @brief Functions and constants for dealing with multiple API levels. |
| 34 | */ |
David 'Digit' Turner | 23d2439 | 2010-12-06 12:05:11 +0100 | [diff] [blame] | 35 | |
Elliott Hughes | 203e13d | 2016-07-22 14:56:18 -0700 | [diff] [blame] | 36 | #include <sys/cdefs.h> |
| 37 | |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 38 | __BEGIN_DECLS |
| 39 | |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 40 | /** |
| 41 | * Magic version number for an Android OS build which has |
| 42 | * not yet turned into an official release, |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 43 | * for comparison against `__ANDROID_API__`. |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 44 | */ |
Dan Albert | 495ec92 | 2016-09-21 01:08:44 -0700 | [diff] [blame] | 45 | #define __ANDROID_API_FUTURE__ 10000 |
Dan Albert | 495ec92 | 2016-09-21 01:08:44 -0700 | [diff] [blame] | 46 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 47 | /* This #ifndef should never be true except when doxygen is generating docs. */ |
Josh Gao | 99739d4 | 2016-04-13 17:16:47 -0700 | [diff] [blame] | 48 | #ifndef __ANDROID_API__ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 49 | /** |
| 50 | * `__ANDROID_API__` is the API level being targeted. For the OS, |
| 51 | * this is `__ANDROID_API_FUTURE__`. For the NDK, this is set by the |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 52 | * compiler system based on the API level you claimed to target. |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 53 | */ |
Dan Albert | 495ec92 | 2016-09-21 01:08:44 -0700 | [diff] [blame] | 54 | #define __ANDROID_API__ __ANDROID_API_FUTURE__ |
Josh Gao | 99739d4 | 2016-04-13 17:16:47 -0700 | [diff] [blame] | 55 | #endif |
David 'Digit' Turner | 23d2439 | 2010-12-06 12:05:11 +0100 | [diff] [blame] | 56 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 57 | #if __ANDROID_API__ != __ANDROID_API_FUTURE__ |
| 58 | /** |
| 59 | * `__ANDROID_NDK__` is defined for code that's built by the NDK |
| 60 | * rather than as part of the OS. "Built by the NDK" is an ambiguous idea, |
| 61 | * so you might prefer to check `__ANDROID__`, `__BIONIC__`, `__linux__`, |
| 62 | * or `__NDK_MAJOR__` instead, depending on exactly what you're trying to say. |
| 63 | * |
| 64 | * `__ANDROID_NDK__` is intended to capture "this code is being built for |
| 65 | * Android, but targeting a specific API level". This is true for all code built |
| 66 | * by the NDK proper, but also for OS code that sets `sdk_version` in its build |
| 67 | * file. This distinction might matter to you if, for example, your code could |
| 68 | * be built as part of an app *or* as part of the OS. |
| 69 | */ |
| 70 | #define __ANDROID_NDK__ 1 |
| 71 | #endif |
| 72 | |
| 73 | /** Names the Gingerbread API level (9), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 74 | #define __ANDROID_API_G__ 9 |
Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 75 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 76 | /** Names the Ice-Cream Sandwich API level (14), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 77 | #define __ANDROID_API_I__ 14 |
| 78 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 79 | /** Names the Jellybean API level (16), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 80 | #define __ANDROID_API_J__ 16 |
| 81 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 82 | /** Names the Jellybean MR1 API level (17), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 83 | #define __ANDROID_API_J_MR1__ 17 |
| 84 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 85 | /** Names the Jellybean MR2 API level (18), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 86 | #define __ANDROID_API_J_MR2__ 18 |
| 87 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 88 | /** Names the KitKat API level (19), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 89 | #define __ANDROID_API_K__ 19 |
| 90 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 91 | /** Names the Lollipop API level (21), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 92 | #define __ANDROID_API_L__ 21 |
| 93 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 94 | /** Names the Lollipop MR1 API level (22), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 95 | #define __ANDROID_API_L_MR1__ 22 |
| 96 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 97 | /** Names the Marshmallow API level (23), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 98 | #define __ANDROID_API_M__ 23 |
| 99 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 100 | /** Names the Nougat API level (24), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 101 | #define __ANDROID_API_N__ 24 |
| 102 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 103 | /** Names the Nougat MR1 API level (25), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 104 | #define __ANDROID_API_N_MR1__ 25 |
| 105 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 106 | /** Names the Oreo API level (26), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 107 | #define __ANDROID_API_O__ 26 |
| 108 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 109 | /** Names the Oreo MR1 API level (27), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 110 | #define __ANDROID_API_O_MR1__ 27 |
| 111 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 112 | /** Names the Pie API level (28), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 113 | #define __ANDROID_API_P__ 28 |
| 114 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 115 | /** |
| 116 | * Names the "Q" API level (29), for comparison against `__ANDROID_API__`. |
| 117 | * This release was called Android 10 publicly, not to be (but sure to be) |
| 118 | * confused with API level 10. |
| 119 | */ |
Elliott Hughes | ce934e3 | 2018-09-06 13:26:08 -0700 | [diff] [blame] | 120 | #define __ANDROID_API_Q__ 29 |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 121 | |
Elliott Hughes | 9823c92 | 2019-10-07 20:51:00 +0000 | [diff] [blame^] | 122 | /** Names the "R" API level (30), for comparison against `__ANDROID_API__`. */ |
Elliott Hughes | 4206711 | 2019-04-18 14:27:24 -0700 | [diff] [blame] | 123 | #define __ANDROID_API_R__ 30 |
| 124 | |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 125 | /** |
| 126 | * Returns the `targetSdkVersion` of the caller, or `__ANDROID_API_FUTURE__` |
| 127 | * if there is no known target SDK version (for code not running in the |
| 128 | * context of an app). |
| 129 | * |
| 130 | * The returned values correspond to the named constants in `<android/api-level.h>`, |
| 131 | * and is equivalent to the AndroidManifest.xml `targetSdkVersion`. |
| 132 | * |
| 133 | * See also android_get_device_api_level(). |
| 134 | * |
| 135 | * Available since API level 24. |
| 136 | */ |
| 137 | int android_get_application_target_sdk_version() __INTRODUCED_IN(24); |
| 138 | |
| 139 | #if __ANDROID_API__ < __ANDROID_API_Q__ |
| 140 | |
Elliott Hughes | 0f57d56 | 2018-11-15 15:07:13 -0800 | [diff] [blame] | 141 | // android_get_device_api_level is a static inline before API level 29. |
Elliott Hughes | c0f4656 | 2018-11-09 15:38:52 -0800 | [diff] [blame] | 142 | #define __BIONIC_GET_DEVICE_API_LEVEL_INLINE static __inline |
| 143 | #include <bits/get_device_api_level_inlines.h> |
| 144 | #undef __BIONIC_GET_DEVICE_API_LEVEL_INLINE |
| 145 | |
| 146 | #else |
| 147 | |
| 148 | /** |
| 149 | * Returns the API level of the device we're actually running on, or -1 on failure. |
| 150 | * The returned values correspond to the named constants in `<android/api-level.h>`, |
| 151 | * and is equivalent to the Java `Build.VERSION.SDK_INT` API. |
| 152 | * |
| 153 | * See also android_get_application_target_sdk_version(). |
| 154 | */ |
| 155 | int android_get_device_api_level() __INTRODUCED_IN(29); |
| 156 | |
| 157 | #endif |
| 158 | |
| 159 | __END_DECLS |