blob: 50cb61a6b0f82d360e8b1dbc363063569fc5f8a0 [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/**
32 * @file android/api-level.h
33 * @brief Functions and constants for dealing with multiple API levels.
Elliott Hughes80e9f652019-10-14 12:19:29 -070034 *
35 * See
36 * https://android.googlesource.com/platform/bionic/+/master/docs/defines.md.
Elliott Hughesce934e32018-09-06 13:26:08 -070037 */
David 'Digit' Turner23d24392010-12-06 12:05:11 +010038
Elliott Hughes203e13d2016-07-22 14:56:18 -070039#include <sys/cdefs.h>
40
Elliott Hughesc0f46562018-11-09 15:38:52 -080041__BEGIN_DECLS
42
Elliott Hughesce934e32018-09-06 13:26:08 -070043/**
Elliott Hughes80e9f652019-10-14 12:19:29 -070044 * Magic version number for an Android OS build which has not yet turned
45 * into an official release, for comparison against `__ANDROID_API__`. See
46 * https://android.googlesource.com/platform/bionic/+/master/docs/defines.md.
Elliott Hughesce934e32018-09-06 13:26:08 -070047 */
Dan Albert495ec922016-09-21 01:08:44 -070048#define __ANDROID_API_FUTURE__ 10000
Dan Albert495ec922016-09-21 01:08:44 -070049
Elliott Hughes9823c922019-10-07 20:51:00 +000050/* This #ifndef should never be true except when doxygen is generating docs. */
Josh Gao99739d42016-04-13 17:16:47 -070051#ifndef __ANDROID_API__
Elliott Hughesce934e32018-09-06 13:26:08 -070052/**
53 * `__ANDROID_API__` is the API level being targeted. For the OS,
54 * this is `__ANDROID_API_FUTURE__`. For the NDK, this is set by the
Elliott Hughes80e9f652019-10-14 12:19:29 -070055 * compiler system based on the API level you claimed to target. See
56 * https://android.googlesource.com/platform/bionic/+/master/docs/defines.md.
Elliott Hughesce934e32018-09-06 13:26:08 -070057 */
Dan Albert495ec922016-09-21 01:08:44 -070058#define __ANDROID_API__ __ANDROID_API_FUTURE__
Josh Gao99739d42016-04-13 17:16:47 -070059#endif
David 'Digit' Turner23d24392010-12-06 12:05:11 +010060
Elliott Hughes9823c922019-10-07 20:51:00 +000061/** Names the Gingerbread API level (9), for comparison against `__ANDROID_API__`. */
Elliott Hughes5bc78c82016-11-16 11:35:43 -080062#define __ANDROID_API_G__ 9
Elliott Hughes5bc78c82016-11-16 11:35:43 -080063
Elliott Hughes9823c922019-10-07 20:51:00 +000064/** Names the Ice-Cream Sandwich API level (14), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070065#define __ANDROID_API_I__ 14
66
Elliott Hughes9823c922019-10-07 20:51:00 +000067/** Names the Jellybean API level (16), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070068#define __ANDROID_API_J__ 16
69
Elliott Hughes9823c922019-10-07 20:51:00 +000070/** Names the Jellybean MR1 API level (17), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070071#define __ANDROID_API_J_MR1__ 17
72
Elliott Hughes9823c922019-10-07 20:51:00 +000073/** Names the Jellybean MR2 API level (18), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070074#define __ANDROID_API_J_MR2__ 18
75
Elliott Hughes9823c922019-10-07 20:51:00 +000076/** Names the KitKat API level (19), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070077#define __ANDROID_API_K__ 19
78
Elliott Hughes9823c922019-10-07 20:51:00 +000079/** Names the Lollipop API level (21), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070080#define __ANDROID_API_L__ 21
81
Elliott Hughes9823c922019-10-07 20:51:00 +000082/** Names the Lollipop MR1 API level (22), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070083#define __ANDROID_API_L_MR1__ 22
84
Elliott Hughes9823c922019-10-07 20:51:00 +000085/** Names the Marshmallow API level (23), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070086#define __ANDROID_API_M__ 23
87
Elliott Hughes9823c922019-10-07 20:51:00 +000088/** Names the Nougat API level (24), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070089#define __ANDROID_API_N__ 24
90
Elliott Hughes9823c922019-10-07 20:51:00 +000091/** Names the Nougat MR1 API level (25), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070092#define __ANDROID_API_N_MR1__ 25
93
Elliott Hughes9823c922019-10-07 20:51:00 +000094/** Names the Oreo API level (26), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070095#define __ANDROID_API_O__ 26
96
Elliott Hughes9823c922019-10-07 20:51:00 +000097/** Names the Oreo MR1 API level (27), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -070098#define __ANDROID_API_O_MR1__ 27
99
Elliott Hughes9823c922019-10-07 20:51:00 +0000100/** Names the Pie API level (28), for comparison against `__ANDROID_API__`. */
Elliott Hughesce934e32018-09-06 13:26:08 -0700101#define __ANDROID_API_P__ 28
102
Elliott Hughes9823c922019-10-07 20:51:00 +0000103/**
104 * Names the "Q" API level (29), for comparison against `__ANDROID_API__`.
105 * This release was called Android 10 publicly, not to be (but sure to be)
106 * confused with API level 10.
107 */
Elliott Hughesce934e32018-09-06 13:26:08 -0700108#define __ANDROID_API_Q__ 29
Elliott Hughesc0f46562018-11-09 15:38:52 -0800109
Elliott Hughes9823c922019-10-07 20:51:00 +0000110/** Names the "R" API level (30), for comparison against `__ANDROID_API__`. */
Elliott Hughes42067112019-04-18 14:27:24 -0700111#define __ANDROID_API_R__ 30
112
Dan Albert14dcbf82020-03-26 16:18:13 -0700113/** Names the "S" API level (31), for comparison against `__ANDROID_API__`. */
114#define __ANDROID_API_S__ 31
115
Elliott Hughesc0f46562018-11-09 15:38:52 -0800116/**
117 * Returns the `targetSdkVersion` of the caller, or `__ANDROID_API_FUTURE__`
118 * if there is no known target SDK version (for code not running in the
119 * context of an app).
120 *
121 * The returned values correspond to the named constants in `<android/api-level.h>`,
122 * and is equivalent to the AndroidManifest.xml `targetSdkVersion`.
123 *
124 * See also android_get_device_api_level().
125 *
126 * Available since API level 24.
127 */
128int android_get_application_target_sdk_version() __INTRODUCED_IN(24);
129
Elliott Hughes95c6cd72019-12-20 13:26:14 -0800130#if __ANDROID_API__ < 29
Elliott Hughesc0f46562018-11-09 15:38:52 -0800131
Elliott Hughes0f57d562018-11-15 15:07:13 -0800132// android_get_device_api_level is a static inline before API level 29.
Elliott Hughesc0f46562018-11-09 15:38:52 -0800133#define __BIONIC_GET_DEVICE_API_LEVEL_INLINE static __inline
134#include <bits/get_device_api_level_inlines.h>
135#undef __BIONIC_GET_DEVICE_API_LEVEL_INLINE
136
137#else
138
139/**
140 * Returns the API level of the device we're actually running on, or -1 on failure.
141 * The returned values correspond to the named constants in `<android/api-level.h>`,
142 * and is equivalent to the Java `Build.VERSION.SDK_INT` API.
143 *
144 * See also android_get_application_target_sdk_version().
145 */
146int android_get_device_api_level() __INTRODUCED_IN(29);
147
148#endif
149
150__END_DECLS