blob: 018bb2c9f9b2409c3db4e249d2746f8ab0e419f2 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.os;
18
Svet Ganov37e43272016-09-09 16:01:32 -070019import android.Manifest;
Anton Hansson81f76a02018-10-04 18:40:22 +010020import android.annotation.NonNull;
Svet Ganov37e43272016-09-09 16:01:32 -070021import android.annotation.RequiresPermission;
Michael Groover6d20d752018-10-01 16:14:50 -070022import android.annotation.SuppressAutoDoc;
Svet Ganovae0e03a2016-02-25 18:22:10 -080023import android.annotation.SystemApi;
Dianne Hackborn337e01a2018-02-27 17:16:37 -080024import android.annotation.TestApi;
Michael Groover6d20d752018-10-01 16:14:50 -070025import android.app.ActivityThread;
Dianne Hackborna47d0452017-11-21 15:04:57 -080026import android.app.Application;
Artur Satayevafdb23a2019-12-10 17:47:53 +000027import android.compat.annotation.UnsupportedAppUsage;
Svet Ganov37e43272016-09-09 16:01:32 -070028import android.content.Context;
Inseob Kim1b5e2412019-11-08 15:06:37 +090029import android.sysprop.TelephonyProperties;
Jeff Sharkey55687722014-04-09 18:07:19 -070030import android.text.TextUtils;
Jeff Sharkeybdd44912014-04-11 16:30:14 -070031import android.util.Slog;
Dianne Hackborna47d0452017-11-21 15:04:57 -080032import android.view.View;
Jeff Sharkey55687722014-04-09 18:07:19 -070033
Narayan Kamatheff258c2014-09-30 13:20:57 +010034import dalvik.system.VMRuntime;
Doug Zongkerad2171a2011-06-14 11:07:24 -070035
Anton Hansson91b54f12018-09-24 18:24:19 +010036import java.util.ArrayList;
37import java.util.List;
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -080038import java.util.Objects;
Inseob Kim1b5e2412019-11-08 15:06:37 +090039import java.util.stream.Collectors;
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -080040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080041/**
42 * Information about the current build, extracted from system properties.
43 */
44public class Build {
Jeff Sharkeybdd44912014-04-11 16:30:14 -070045 private static final String TAG = "Build";
46
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080047 /** Value used for when a build property is unknown. */
Ficus Kirkpatrick71de7852010-01-08 13:10:51 -080048 public static final String UNKNOWN = "unknown";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049
50 /** Either a changelist number, or a label like "M4-rc20". */
51 public static final String ID = getString("ro.build.id");
52
53 /** A build ID string meant for displaying to the user */
54 public static final String DISPLAY = getString("ro.build.display.id");
55
56 /** The name of the overall product. */
57 public static final String PRODUCT = getString("ro.product.name");
58
59 /** The name of the industrial design. */
60 public static final String DEVICE = getString("ro.product.device");
61
62 /** The name of the underlying board, like "goldfish". */
63 public static final String BOARD = getString("ro.product.board");
64
Narayan Kamath1adf4002014-07-12 11:46:37 +010065 /**
66 * The name of the instruction set (CPU type + ABI convention) of native code.
67 *
68 * @deprecated Use {@link #SUPPORTED_ABIS} instead.
69 */
70 @Deprecated
Narayan Kamatheff258c2014-09-30 13:20:57 +010071 public static final String CPU_ABI;
Dianne Hackbornb1811182009-05-21 15:45:42 -070072
Narayan Kamath1adf4002014-07-12 11:46:37 +010073 /**
74 * The name of the second instruction set (CPU type + ABI convention) of native code.
75 *
76 * @deprecated Use {@link #SUPPORTED_ABIS} instead.
77 */
78 @Deprecated
Narayan Kamatheff258c2014-09-30 13:20:57 +010079 public static final String CPU_ABI2;
Ficus Kirkpatrickfa9cafa2010-01-06 17:37:13 -080080
Dianne Hackbornd62ad4f2009-05-19 19:06:25 -070081 /** The manufacturer of the product/hardware. */
82 public static final String MANUFACTURER = getString("ro.product.manufacturer");
83
Dirk Dougherty491b40d2013-10-29 18:33:29 -070084 /** The consumer-visible brand with which the product/hardware will be associated, if any. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080085 public static final String BRAND = getString("ro.product.brand");
86
87 /** The end-user-visible name for the end product. */
88 public static final String MODEL = getString("ro.product.model");
89
Doug Zongker74885ef2010-02-02 17:39:26 -080090 /** The system bootloader version number. */
Dan Egnor42471dd2010-01-07 17:25:22 -080091 public static final String BOOTLOADER = getString("ro.bootloader");
92
Doug Zongkerad2171a2011-06-14 11:07:24 -070093 /**
94 * The radio firmware version number.
95 *
96 * @deprecated The radio firmware version is frequently not
97 * available when this class is initialized, leading to a blank or
98 * "unknown" value for this string. Use
99 * {@link #getRadioVersion} instead.
100 */
101 @Deprecated
Inseob Kim1b5e2412019-11-08 15:06:37 +0900102 public static final String RADIO = joinListOrElse(
103 TelephonyProperties.baseband_version(), UNKNOWN);
Dan Egnor42471dd2010-01-07 17:25:22 -0800104
Doug Zongker74885ef2010-02-02 17:39:26 -0800105 /** The name of the hardware (from the kernel command line or /proc). */
106 public static final String HARDWARE = getString("ro.hardware");
Dan Egnor42471dd2010-01-07 17:25:22 -0800107
Griff Hazend3c454d2016-03-25 07:30:34 -0700108 /**
109 * Whether this build was for an emulator device.
110 * @hide
111 */
Artur Satayevf0b7d0b2019-11-04 11:16:45 +0000112 @UnsupportedAppUsage
Wale Ogunwale691af682019-02-11 03:09:10 -0800113 @TestApi
Griff Hazend3c454d2016-03-25 07:30:34 -0700114 public static final boolean IS_EMULATOR = getString("ro.kernel.qemu").equals("1");
115
Svet Ganov37e43272016-09-09 16:01:32 -0700116 /**
117 * A hardware serial number, if available. Alphanumeric only, case-insensitive.
Michael Groover1279ff92019-05-29 14:19:16 -0700118 * This field is always set to {@link Build#UNKNOWN}.
Svet Ganov37e43272016-09-09 16:01:32 -0700119 *
120 * @deprecated Use {@link #getSerial()} instead.
121 **/
122 @Deprecated
123 // IMPORTANT: This field should be initialized via a function call to
124 // prevent its value being inlined in the app during compilation because
125 // we will later set it to the value based on the app's target SDK.
126 public static final String SERIAL = getString("no.such.thing");
127
128 /**
Kevin Hufnagled6ebb552017-05-16 16:48:10 -0700129 * Gets the hardware serial number, if available.
130 *
131 * <p class="note"><b>Note:</b> Root access may allow you to modify device identifiers, such as
132 * the hardware serial number. If you change these identifiers, you can use
133 * <a href="/training/articles/security-key-attestation.html">key attestation</a> to obtain
134 * proof of the device's original identifiers.
135 *
Michael Groovere0de0182020-06-23 19:45:14 -0700136 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional
137 * restrictions, and apps are recommended to use resettable identifiers (see <a
Michael Groover1aef2062020-09-21 15:27:52 -0700138 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This
139 * method can be invoked if one of the following requirements is met:
Michael Groovere0de0182020-06-23 19:45:14 -0700140 * <ul>
141 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this
142 * is a privileged permission that can only be granted to apps preloaded on the device.
143 * <li>If the calling app is the device or profile owner and has been granted the
144 * {@link Manifest.permission#READ_PHONE_STATE} permission. The profile owner is an app that
145 * owns a managed profile on the device; for more details see <a
146 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>.
147 * Profile owner access is deprecated and will be removed in a future release.
148 * <li>If the calling app has carrier privileges (see {@link
149 * android.telephony.TelephonyManager#hasCarrierPrivileges}) on any active subscription.
150 * <li>If the calling app is the default SMS role holder (see {@link
151 * android.app.role.RoleManager#isRoleHeld(String)}).
152 * </ul>
Michael Groover6d20d752018-10-01 16:14:50 -0700153 *
Michael Grooverb0401fb2019-05-09 19:35:16 -0700154 * <p>If the calling app does not meet one of these requirements then this method will behave
155 * as follows:
156 *
157 * <ul>
158 * <li>If the calling app's target SDK is API level 28 or lower and the app has the
159 * READ_PHONE_STATE permission then {@link Build#UNKNOWN} is returned.</li>
160 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have
161 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or
162 * higher, then a SecurityException is thrown.</li>
163 * </ul>
Michael Groovere0de0182020-06-23 19:45:14 -0700164 *
Kevin Hufnagled6ebb552017-05-16 16:48:10 -0700165 * @return The serial number if specified.
Svet Ganov37e43272016-09-09 16:01:32 -0700166 */
Michael Groover6d20d752018-10-01 16:14:50 -0700167 @SuppressAutoDoc // No support for device / profile owner.
168 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Svet Ganov37e43272016-09-09 16:01:32 -0700169 public static String getSerial() {
170 IDeviceIdentifiersPolicyService service = IDeviceIdentifiersPolicyService.Stub
171 .asInterface(ServiceManager.getService(Context.DEVICE_IDENTIFIERS_SERVICE));
172 try {
Michael Groover6d20d752018-10-01 16:14:50 -0700173 Application application = ActivityThread.currentApplication();
174 String callingPackage = application != null ? application.getPackageName() : null;
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700175 return service.getSerialForPackage(callingPackage, null);
Svet Ganov37e43272016-09-09 16:01:32 -0700176 } catch (RemoteException e) {
177 e.rethrowFromSystemServer();
178 }
179 return UNKNOWN;
180 }
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000181
182 /**
Narayan Kamath0f206a12014-04-12 11:41:13 +0100183 * An ordered list of ABIs supported by this device. The most preferred ABI is the first
184 * element in the list.
185 *
186 * See {@link #SUPPORTED_32_BIT_ABIS} and {@link #SUPPORTED_64_BIT_ABIS}.
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000187 */
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100188 public static final String[] SUPPORTED_ABIS = getStringList("ro.product.cpu.abilist", ",");
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000189
Narayan Kamath0f206a12014-04-12 11:41:13 +0100190 /**
191 * An ordered list of <b>32 bit</b> ABIs supported by this device. The most preferred ABI
192 * is the first element in the list.
193 *
194 * See {@link #SUPPORTED_ABIS} and {@link #SUPPORTED_64_BIT_ABIS}.
Narayan Kamath0f206a12014-04-12 11:41:13 +0100195 */
Torne (Richard Coles)da8c0372014-05-14 16:17:26 +0100196 public static final String[] SUPPORTED_32_BIT_ABIS =
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100197 getStringList("ro.product.cpu.abilist32", ",");
Narayan Kamath0f206a12014-04-12 11:41:13 +0100198
199 /**
200 * An ordered list of <b>64 bit</b> ABIs supported by this device. The most preferred ABI
201 * is the first element in the list.
202 *
203 * See {@link #SUPPORTED_ABIS} and {@link #SUPPORTED_32_BIT_ABIS}.
Narayan Kamath0f206a12014-04-12 11:41:13 +0100204 */
Torne (Richard Coles)da8c0372014-05-14 16:17:26 +0100205 public static final String[] SUPPORTED_64_BIT_ABIS =
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100206 getStringList("ro.product.cpu.abilist64", ",");
Narayan Kamath0f206a12014-04-12 11:41:13 +0100207
Jeff Sharkeyc6091162018-06-29 17:15:40 -0600208 /** {@hide} */
209 @TestApi
210 public static boolean is64BitAbi(String abi) {
211 return VMRuntime.is64BitAbi(abi);
212 }
Narayan Kamath0f206a12014-04-12 11:41:13 +0100213
Narayan Kamatheff258c2014-09-30 13:20:57 +0100214 static {
215 /*
216 * Adjusts CPU_ABI and CPU_ABI2 depending on whether or not a given process is 64 bit.
217 * 32 bit processes will always see 32 bit ABIs in these fields for backward
218 * compatibility.
219 */
220 final String[] abiList;
221 if (VMRuntime.getRuntime().is64Bit()) {
222 abiList = SUPPORTED_64_BIT_ABIS;
223 } else {
224 abiList = SUPPORTED_32_BIT_ABIS;
225 }
226
227 CPU_ABI = abiList[0];
228 if (abiList.length > 1) {
229 CPU_ABI2 = abiList[1];
230 } else {
231 CPU_ABI2 = "";
232 }
233 }
234
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800235 /** Various version strings. */
236 public static class VERSION {
237 /**
238 * The internal value used by the underlying source control to
239 * represent this build. E.g., a perforce changelist number
240 * or a git hash.
241 */
242 public static final String INCREMENTAL = getString("ro.build.version.incremental");
243
244 /**
Daniel Colascioned1520aa2018-04-06 08:12:05 -0700245 * The user-visible version string. E.g., "1.0" or "3.4b5" or "bananas".
246 *
247 * This field is an opaque string. Do not assume that its value
248 * has any particular structure or that values of RELEASE from
249 * different releases can be somehow ordered.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800250 */
251 public static final String RELEASE = getString("ro.build.version.release");
252
253 /**
Dianne Hackborndb007452019-10-28 16:34:22 -0700254 * The version string we show to the user; may be {@link #RELEASE} or
255 * {@link #CODENAME} if not a final release build.
256 */
257 @NonNull public static final String RELEASE_OR_CODENAME = getString(
258 "ro.build.version.release_or_codename");
259
260 /**
Dianne Hackbornc3f74492015-08-12 16:10:58 -0700261 * The base OS build the product is based on.
262 */
263 public static final String BASE_OS = SystemProperties.get("ro.build.version.base_os", "");
264
265 /**
Kevin Hufnagled9c7b442019-09-20 00:58:45 +0000266 * The user-visible security patch level. This value represents the date when the device
267 * most recently applied a security patch.
Dianne Hackbornc3f74492015-08-12 16:10:58 -0700268 */
269 public static final String SECURITY_PATCH = SystemProperties.get(
270 "ro.build.version.security_patch", "");
271
272 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700273 * The user-visible SDK version of the framework in its raw String
274 * representation; use {@link #SDK_INT} instead.
Andres Moralescb3fd692015-01-14 10:07:55 -0800275 *
Dianne Hackborn851a5412009-05-08 12:06:44 -0700276 * @deprecated Use {@link #SDK_INT} to easily get this as an integer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700278 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 public static final String SDK = getString("ro.build.version.sdk");
Dianne Hackborn851a5412009-05-08 12:06:44 -0700280
281 /**
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700282 * The SDK version of the software currently running on this hardware
283 * device. This value never changes while a device is booted, but it may
284 * increase when the hardware manufacturer provides an OTA update.
285 * <p>
286 * Possible values are defined in {@link Build.VERSION_CODES}.
Dianne Hackborn851a5412009-05-08 12:06:44 -0700287 */
288 public static final int SDK_INT = SystemProperties.getInt(
289 "ro.build.version.sdk", 0);
290
291 /**
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700292 * The SDK version of the software that <em>initially</em> shipped on
293 * this hardware device. It <em>never</em> changes during the lifetime
294 * of the device, even when {@link #SDK_INT} increases due to an OTA
295 * update.
296 * <p>
297 * Possible values are defined in {@link Build.VERSION_CODES}.
298 *
299 * @see #SDK_INT
Jeff Sharkey1da8bb12018-03-26 12:50:54 -0600300 * @hide
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700301 */
Jeff Sharkey1da8bb12018-03-26 12:50:54 -0600302 @TestApi
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700303 public static final int FIRST_SDK_INT = SystemProperties
304 .getInt("ro.product.first_api_level", 0);
305
306 /**
Adam Powelle9600302015-05-06 18:13:09 -0700307 * The developer preview revision of a prerelease SDK. This value will always
308 * be <code>0</code> on production platform builds/devices.
309 *
310 * <p>When this value is nonzero, any new API added since the last
311 * officially published {@link #SDK_INT API level} is only guaranteed to be present
312 * on that specific preview revision. For example, an API <code>Activity.fooBar()</code>
313 * might be present in preview revision 1 but renamed or removed entirely in
314 * preview revision 2, which may cause an app attempting to call it to crash
315 * at runtime.</p>
316 *
317 * <p>Experimental apps targeting preview APIs should check this value for
318 * equality (<code>==</code>) with the preview SDK revision they were built for
319 * before using any prerelease platform APIs. Apps that detect a preview SDK revision
320 * other than the specific one they expect should fall back to using APIs from
321 * the previously published API level only to avoid unwanted runtime exceptions.
322 * </p>
323 */
324 public static final int PREVIEW_SDK_INT = SystemProperties.getInt(
325 "ro.build.version.preview_sdk", 0);
326
327 /**
Narayan Kamathb081e072018-12-13 19:09:20 +0000328 * The SDK fingerprint for a given prerelease SDK. This value will always be
329 * {@code REL} on production platform builds/devices.
330 *
331 * <p>When this value is not {@code REL}, it contains a string fingerprint of the API
332 * surface exposed by the preview SDK. Preview platforms with different API surfaces
333 * will have different {@code PREVIEW_SDK_FINGERPRINT}.
334 *
335 * <p>This attribute is intended for use by installers for finer grained targeting of
336 * packages. Applications targeting preview APIs should not use this field and should
337 * instead use {@code PREVIEW_SDK_INT} or use reflection or other runtime checks to
338 * detect the presence of an API or guard themselves against unexpected runtime
339 * behavior.
340 *
341 * @hide
342 */
343 @SystemApi
Narayan Kamath714bf492019-03-08 17:08:07 +0000344 @NonNull public static final String PREVIEW_SDK_FINGERPRINT = SystemProperties.get(
Narayan Kamathb081e072018-12-13 19:09:20 +0000345 "ro.build.version.preview_sdk_fingerprint", "REL");
346
347 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700348 * The current development codename, or the string "REL" if this is
349 * a release build.
350 */
351 public static final String CODENAME = getString("ro.build.version.codename");
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800352
Dianne Hackbornffcda102014-04-24 13:06:27 -0700353 private static final String[] ALL_CODENAMES
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100354 = getStringList("ro.build.version.all_codenames", ",");
Dianne Hackbornffcda102014-04-24 13:06:27 -0700355
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800356 /**
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800357 * @hide
358 */
Andrei Onea24ec3212019-03-15 17:35:05 +0000359 @UnsupportedAppUsage
Artur Satayevf0b7d0b2019-11-04 11:16:45 +0000360 @TestApi
Dianne Hackbornffcda102014-04-24 13:06:27 -0700361 public static final String[] ACTIVE_CODENAMES = "REL".equals(ALL_CODENAMES[0])
362 ? new String[0] : ALL_CODENAMES;
363
364 /**
365 * The SDK version to use when accessing resources.
366 * Use the current SDK version code. For every active development codename
367 * we are operating under, we bump the assumed resource platform version by 1.
368 * @hide
369 */
Dianne Hackborn337e01a2018-02-27 17:16:37 -0800370 @TestApi
Dianne Hackbornffcda102014-04-24 13:06:27 -0700371 public static final int RESOURCES_SDK_INT = SDK_INT + ACTIVE_CODENAMES.length;
Przemyslaw Szczepaniak73b6bc82017-12-05 11:07:30 +0000372
373 /**
374 * The current lowest supported value of app target SDK. Applications targeting
Narayan Kamath91c361d2018-03-26 18:31:33 +0100375 * lower values may not function on devices running this SDK version. Its possible
376 * values are defined in {@link Build.VERSION_CODES}.
377 *
378 * @hide
Przemyslaw Szczepaniak73b6bc82017-12-05 11:07:30 +0000379 */
380 public static final int MIN_SUPPORTED_TARGET_SDK_INT = SystemProperties.getInt(
381 "ro.build.version.min_supported_target_sdk", 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800382 }
383
Dianne Hackborn851a5412009-05-08 12:06:44 -0700384 /**
385 * Enumeration of the currently known SDK version codes. These are the
386 * values that can be found in {@link VERSION#SDK}. Version numbers
387 * increment monotonically with each official platform release.
388 */
389 public static class VERSION_CODES {
390 /**
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700391 * Magic version number for a current development build, which has
392 * not yet turned into an official release.
393 */
Tobias Thierer8bacd9b2017-02-15 20:38:29 +0000394 public static final int CUR_DEVELOPMENT = VMRuntime.SDK_VERSION_CUR_DEVELOPMENT;
Andres Moralescb3fd692015-01-14 10:07:55 -0800395
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700396 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700397 * October 2008: The original, first, version of Android. Yay!
398 */
399 public static final int BASE = 1;
Andres Moralescb3fd692015-01-14 10:07:55 -0800400
Dianne Hackborn851a5412009-05-08 12:06:44 -0700401 /**
402 * February 2009: First Android update, officially called 1.1.
403 */
404 public static final int BASE_1_1 = 2;
Andres Moralescb3fd692015-01-14 10:07:55 -0800405
Dianne Hackborn851a5412009-05-08 12:06:44 -0700406 /**
407 * May 2009: Android 1.5.
408 */
409 public static final int CUPCAKE = 3;
Andres Moralescb3fd692015-01-14 10:07:55 -0800410
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700411 /**
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700412 * September 2009: Android 1.6.
Andres Moralescb3fd692015-01-14 10:07:55 -0800413 *
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700414 * <p>Applications targeting this or a later release will get these
415 * new changes in behavior:</p>
416 * <ul>
417 * <li> They must explicitly request the
San Mehat5a3a77d2009-06-01 09:25:28 -0700418 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission to be
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700419 * able to modify the contents of the SD card. (Apps targeting
420 * earlier versions will always request the permission.)
Dianne Hackbornfe77ec82009-08-12 16:53:56 -0700421 * <li> They must explicitly request the
422 * {@link android.Manifest.permission#READ_PHONE_STATE} permission to be
423 * able to be able to retrieve phone state info. (Apps targeting
424 * earlier versions will always request the permission.)
425 * <li> They are assumed to support different screen densities and
426 * sizes. (Apps targeting earlier versions are assumed to only support
427 * medium density normal size screens unless otherwise indicated).
428 * They can still explicitly specify screen support either way with the
429 * supports-screens manifest tag.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700430 * <li> {@link android.widget.TabHost} will use the new dark tab
431 * background design.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700432 * </ul>
433 */
Dianne Hackbornfe77ec82009-08-12 16:53:56 -0700434 public static final int DONUT = 4;
Andres Moralescb3fd692015-01-14 10:07:55 -0800435
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700436 /**
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700437 * November 2009: Android 2.0
Andres Moralescb3fd692015-01-14 10:07:55 -0800438 *
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700439 * <p>Applications targeting this or a later release will get these
440 * new changes in behavior:</p>
441 * <ul>
442 * <li> The {@link android.app.Service#onStartCommand
443 * Service.onStartCommand} function will return the new
444 * {@link android.app.Service#START_STICKY} behavior instead of the
445 * old compatibility {@link android.app.Service#START_STICKY_COMPATIBILITY}.
Dianne Hackborn8d374262009-09-14 21:21:52 -0700446 * <li> The {@link android.app.Activity} class will now execute back
447 * key presses on the key up instead of key down, to be able to detect
448 * canceled presses from virtual keys.
Mike Cleron76097642009-09-25 17:53:56 -0700449 * <li> The {@link android.widget.TabWidget} class will use a new color scheme
450 * for tabs. In the new scheme, the foreground tab has a medium gray background
451 * the background tabs have a dark gray background.
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700452 * </ul>
453 */
Jeff Hamilton6dc3f4e2009-10-10 12:06:19 -0500454 public static final int ECLAIR = 5;
Andres Moralescb3fd692015-01-14 10:07:55 -0800455
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700456 /**
Dianne Hackborn17787762009-11-12 16:11:36 -0800457 * December 2009: Android 2.0.1
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700458 */
Dianne Hackborn17787762009-11-12 16:11:36 -0800459 public static final int ECLAIR_0_1 = 6;
Andres Moralescb3fd692015-01-14 10:07:55 -0800460
Dianne Hackborn23ef7b42009-11-18 18:20:39 -0800461 /**
462 * January 2010: Android 2.1
463 */
464 public static final int ECLAIR_MR1 = 7;
Andres Moralescb3fd692015-01-14 10:07:55 -0800465
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700466 /**
467 * June 2010: Android 2.2
468 */
Adam Powell216bccf2010-02-01 15:03:17 -0800469 public static final int FROYO = 8;
Andres Moralescb3fd692015-01-14 10:07:55 -0800470
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700471 /**
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800472 * November 2010: Android 2.3
Dianne Hackborn81e92762011-10-09 16:00:21 -0700473 *
474 * <p>Applications targeting this or a later release will get these
475 * new changes in behavior:</p>
476 * <ul>
477 * <li> The application's notification icons will be shown on the new
478 * dark status bar background, so must be visible in this situation.
479 * </ul>
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700480 */
Dianne Hackborn4fa1a222010-10-18 13:10:49 -0700481 public static final int GINGERBREAD = 9;
Andres Moralescb3fd692015-01-14 10:07:55 -0800482
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800483 /**
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700484 * February 2011: Android 2.3.3.
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800485 */
486 public static final int GINGERBREAD_MR1 = 10;
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700487
488 /**
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700489 * February 2011: Android 3.0.
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700490 *
491 * <p>Applications targeting this or a later release will get these
492 * new changes in behavior:</p>
493 * <ul>
Dianne Hackborn3e6d50c2010-08-23 18:30:44 -0700494 * <li> The default theme for applications is now dark holographic:
495 * {@link android.R.style#Theme_Holo}.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700496 * <li> On large screen devices that do not have a physical menu
497 * button, the soft (compatibility) menu is disabled.
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800498 * <li> The activity lifecycle has changed slightly as per
499 * {@link android.app.Activity}.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700500 * <li> An application will crash if it does not call through
501 * to the super implementation of its
502 * {@link android.app.Activity#onPause Activity.onPause()} method.
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800503 * <li> When an application requires a permission to access one of
Dianne Hackborn6c2c5fc2011-01-18 17:02:33 -0800504 * its components (activity, receiver, service, provider), this
505 * permission is no longer enforced when the application wants to
506 * access its own component. This means it can require a permission
507 * on a component that it does not itself hold and still access that
508 * component.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700509 * <li> {@link android.content.Context#getSharedPreferences
510 * Context.getSharedPreferences()} will not automatically reload
511 * the preferences if they have changed on storage, unless
512 * {@link android.content.Context#MODE_MULTI_PROCESS} is used.
513 * <li> {@link android.view.ViewGroup#setMotionEventSplittingEnabled}
514 * will default to true.
515 * <li> {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH}
516 * is enabled by default on windows.
517 * <li> {@link android.widget.PopupWindow#isSplitTouchEnabled()
518 * PopupWindow.isSplitTouchEnabled()} will return true by default.
519 * <li> {@link android.widget.GridView} and {@link android.widget.ListView}
520 * will use {@link android.view.View#setActivated View.setActivated}
521 * for selected items if they do not implement {@link android.widget.Checkable}.
522 * <li> {@link android.widget.Scroller} will be constructed with
523 * "flywheel" behavior enabled by default.
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700524 * </ul>
525 */
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800526 public static final int HONEYCOMB = 11;
Andres Moralescb3fd692015-01-14 10:07:55 -0800527
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700528 /**
Dianne Hackborna8138732011-05-12 15:45:21 -0700529 * May 2011: Android 3.1.
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700530 */
531 public static final int HONEYCOMB_MR1 = 12;
Andres Moralescb3fd692015-01-14 10:07:55 -0800532
Dianne Hackborna8138732011-05-12 15:45:21 -0700533 /**
Dianne Hackborn426431a2011-06-09 11:29:08 -0700534 * June 2011: Android 3.2.
Dianne Hackborne6676352011-06-01 16:51:20 -0700535 *
536 * <p>Update to Honeycomb MR1 to support 7 inch tablets, improve
537 * screen compatibility mode, etc.</p>
538 *
539 * <p>As of this version, applications that don't say whether they
540 * support XLARGE screens will be assumed to do so only if they target
541 * {@link #HONEYCOMB} or later; it had been {@link #GINGERBREAD} or
542 * later. Applications that don't support a screen size at least as
543 * large as the current screen will provide the user with a UI to
544 * switch them in to screen size compatibility mode.</p>
Dianne Hackborne289bff2011-06-13 19:33:22 -0700545 *
546 * <p>This version introduces new screen size resource qualifiers
547 * based on the screen size in dp: see
548 * {@link android.content.res.Configuration#screenWidthDp},
549 * {@link android.content.res.Configuration#screenHeightDp}, and
550 * {@link android.content.res.Configuration#smallestScreenWidthDp}.
551 * Supplying these in &lt;supports-screens&gt; as per
552 * {@link android.content.pm.ApplicationInfo#requiresSmallestWidthDp},
553 * {@link android.content.pm.ApplicationInfo#compatibleWidthLimitDp}, and
554 * {@link android.content.pm.ApplicationInfo#largestWidthLimitDp} is
555 * preferred over the older screen size buckets and for older devices
556 * the appropriate buckets will be inferred from them.</p>
557 *
Dianne Hackborn81e92762011-10-09 16:00:21 -0700558 * <p>Applications targeting this or a later release will get these
559 * new changes in behavior:</p>
560 * <ul>
561 * <li><p>New {@link android.content.pm.PackageManager#FEATURE_SCREEN_PORTRAIT}
Dianne Hackborne289bff2011-06-13 19:33:22 -0700562 * and {@link android.content.pm.PackageManager#FEATURE_SCREEN_LANDSCAPE}
Dianne Hackborn81e92762011-10-09 16:00:21 -0700563 * features were introduced in this release. Applications that target
Dianne Hackborne289bff2011-06-13 19:33:22 -0700564 * previous platform versions are assumed to require both portrait and
565 * landscape support in the device; when targeting Honeycomb MR1 or
566 * greater the application is responsible for specifying any specific
567 * orientation it requires.</p>
Dianne Hackborn81e92762011-10-09 16:00:21 -0700568 * <li><p>{@link android.os.AsyncTask} will use the serial executor
569 * by default when calling {@link android.os.AsyncTask#execute}.</p>
570 * <li><p>{@link android.content.pm.ActivityInfo#configChanges
571 * ActivityInfo.configChanges} will have the
572 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE} and
573 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE}
574 * bits set; these need to be cleared for older applications because
575 * some developers have done absolute comparisons against this value
576 * instead of correctly masking the bits they are interested in.
577 * </ul>
Dianne Hackborna8138732011-05-12 15:45:21 -0700578 */
Dianne Hackborn426431a2011-06-09 11:29:08 -0700579 public static final int HONEYCOMB_MR2 = 13;
Dianne Hackborn3fc982f2011-03-30 16:20:26 -0700580
581 /**
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700582 * October 2011: Android 4.0.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700583 *
584 * <p>Applications targeting this or a later release will get these
585 * new changes in behavior:</p>
586 * <ul>
Dianne Hackborn9d0e37e2011-09-22 12:58:54 -0700587 * <li> For devices without a dedicated menu key, the software compatibility
588 * menu key will not be shown even on phones. By targeting Ice Cream Sandwich
589 * or later, your UI must always have its own menu UI affordance if needed,
590 * on both tablets and phones. The ActionBar will take care of this for you.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700591 * <li> 2d drawing hardware acceleration is now turned on by default.
592 * You can use
593 * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated}
594 * to turn it off if needed, although this is strongly discouraged since
595 * it will result in poor performance on larger screen devices.
Adam Powell6e90a362011-08-14 16:48:32 -0700596 * <li> The default theme for applications is now the "device default" theme:
597 * {@link android.R.style#Theme_DeviceDefault}. This may be the
598 * holo dark theme or a different dark theme defined by the specific device.
599 * The {@link android.R.style#Theme_Holo} family must not be modified
600 * for a device to be considered compatible. Applications that explicitly
601 * request a theme from the Holo family will be guaranteed that these themes
602 * will not change character within the same platform version. Applications
603 * that wish to blend in with the device should use a theme from the
604 * {@link android.R.style#Theme_DeviceDefault} family.
Dianne Hackborn9d0e37e2011-09-22 12:58:54 -0700605 * <li> Managed cursors can now throw an exception if you directly close
606 * the cursor yourself without stopping the management of it; previously failures
607 * would be silently ignored.
608 * <li> The fadingEdge attribute on views will be ignored (fading edges is no
609 * longer a standard part of the UI). A new requiresFadingEdge attribute allows
610 * applications to still force fading edges on for special cases.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700611 * <li> {@link android.content.Context#bindService Context.bindService()}
612 * will not automatically add in {@link android.content.Context#BIND_WAIVE_PRIORITY}.
613 * <li> App Widgets will have standard padding automatically added around
614 * them, rather than relying on the padding being baked into the widget itself.
615 * <li> An exception will be thrown if you try to change the type of a
616 * window after it has been added to the window manager. Previously this
617 * would result in random incorrect behavior.
618 * <li> {@link android.view.animation.AnimationSet} will parse out
619 * the duration, fillBefore, fillAfter, repeatMode, and startOffset
620 * XML attributes that are defined.
621 * <li> {@link android.app.ActionBar#setHomeButtonEnabled
622 * ActionBar.setHomeButtonEnabled()} is false by default.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700623 * </ul>
Dianne Hackborn3fc982f2011-03-30 16:20:26 -0700624 */
Dianne Hackborn0784cfb2011-09-14 13:48:15 -0700625 public static final int ICE_CREAM_SANDWICH = 14;
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700626
627 /**
Dianne Hackborn81e92762011-10-09 16:00:21 -0700628 * December 2011: Android 4.0.3.
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700629 */
630 public static final int ICE_CREAM_SANDWICH_MR1 = 15;
Dianne Hackborn81e92762011-10-09 16:00:21 -0700631
632 /**
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700633 * June 2012: Android 4.1.
Dianne Hackborn65696252012-03-05 18:49:21 -0800634 *
635 * <p>Applications targeting this or a later release will get these
636 * new changes in behavior:</p>
637 * <ul>
Dianne Hackborn636fd522012-06-05 17:38:50 -0700638 * <li> You must explicitly request the {@link android.Manifest.permission#READ_CALL_LOG}
639 * and/or {@link android.Manifest.permission#WRITE_CALL_LOG} permissions;
640 * access to the call log is no longer implicitly provided through
641 * {@link android.Manifest.permission#READ_CONTACTS} and
642 * {@link android.Manifest.permission#WRITE_CONTACTS}.
643 * <li> {@link android.widget.RemoteViews} will throw an exception if
644 * setting an onClick handler for views being generated by a
645 * {@link android.widget.RemoteViewsService} for a collection container;
646 * previously this just resulted in a warning log message.
647 * <li> New {@link android.app.ActionBar} policy for embedded tabs:
648 * embedded tabs are now always stacked in the action bar when in portrait
649 * mode, regardless of the size of the screen.
650 * <li> {@link android.webkit.WebSettings#setAllowFileAccessFromFileURLs(boolean)
651 * WebSettings.setAllowFileAccessFromFileURLs} and
652 * {@link android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs(boolean)
653 * WebSettings.setAllowUniversalAccessFromFileURLs} default to false.
Dianne Hackborn65696252012-03-05 18:49:21 -0800654 * <li> Calls to {@link android.content.pm.PackageManager#setComponentEnabledSetting
655 * PackageManager.setComponentEnabledSetting} will now throw an
656 * IllegalArgumentException if the given component class name does not
657 * exist in the application's manifest.
Dianne Hackborn636fd522012-06-05 17:38:50 -0700658 * <li> {@link android.nfc.NfcAdapter#setNdefPushMessage
659 * NfcAdapter.setNdefPushMessage},
660 * {@link android.nfc.NfcAdapter#setNdefPushMessageCallback
661 * NfcAdapter.setNdefPushMessageCallback} and
662 * {@link android.nfc.NfcAdapter#setOnNdefPushCompleteCallback
663 * NfcAdapter.setOnNdefPushCompleteCallback} will throw
664 * IllegalStateException if called after the Activity has been destroyed.
665 * <li> Accessibility services must require the new
666 * {@link android.Manifest.permission#BIND_ACCESSIBILITY_SERVICE} permission or
667 * they will not be available for use.
668 * <li> {@link android.accessibilityservice.AccessibilityServiceInfo#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
669 * AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS} must be set
670 * for unimportant views to be included in queries.
Dianne Hackborn65696252012-03-05 18:49:21 -0800671 * </ul>
Dianne Hackborn81e92762011-10-09 16:00:21 -0700672 */
Dianne Hackbornfa61f0b2012-05-09 21:49:38 -0700673 public static final int JELLY_BEAN = 16;
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700674
675 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700676 * November 2012: Android 4.2, Moar jelly beans!
Nick Kralevichf097b162012-07-28 12:43:48 -0700677 *
678 * <p>Applications targeting this or a later release will get these
679 * new changes in behavior:</p>
680 * <ul>
681 * <li>Content Providers: The default value of {@code android:exported} is now
682 * {@code false}. See
Nick Kralevich2caec6c2012-08-08 11:33:17 -0700683 * <a href="{@docRoot}guide/topics/manifest/provider-element.html#exported">
Nick Kralevichf097b162012-07-28 12:43:48 -0700684 * the android:exported section</a> in the provider documentation for more details.</li>
Dianne Hackbornfc494742012-09-27 16:15:42 -0700685 * <li>{@link android.view.View#getLayoutDirection() View.getLayoutDirection()}
686 * can return different values than {@link android.view.View#LAYOUT_DIRECTION_LTR}
687 * based on the locale etc.
688 * <li> {@link android.webkit.WebView#addJavascriptInterface(Object, String)
689 * WebView.addJavascriptInterface} requires explicit annotations on methods
690 * for them to be accessible from Javascript.
Nick Kralevichf097b162012-07-28 12:43:48 -0700691 * </ul>
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700692 */
693 public static final int JELLY_BEAN_MR1 = 17;
Nick Kralevicha985c3b2013-01-09 16:03:14 -0800694
695 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700696 * July 2013: Android 4.3, the revenge of the beans.
Nick Kralevicha985c3b2013-01-09 16:03:14 -0800697 */
Dianne Hackbornd2eeed62013-04-22 13:04:28 -0700698 public static final int JELLY_BEAN_MR2 = 18;
Dianne Hackborn5d2bfa12013-03-05 10:28:34 -0800699
700 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700701 * October 2013: Android 4.4, KitKat, another tasty treat.
Dianne Hackborn221ea892013-08-04 16:50:16 -0700702 *
703 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700704 * new changes in behavior. For more information about this release, see the
705 * <a href="/about/versions/kitkat/">Android KitKat overview</a>.</p>
Dianne Hackborn221ea892013-08-04 16:50:16 -0700706 * <ul>
Mark Dolinerd0646dc2014-08-27 16:04:02 -0700707 * <li> The default result of
708 * {@link android.preference.PreferenceActivity#isValidFragment(String)
Dianne Hackborn6bc37892013-10-03 11:05:14 -0700709 * PreferenceActivity.isValueFragment} becomes false instead of true.</li>
710 * <li> In {@link android.webkit.WebView}, apps targeting earlier versions will have
711 * JS URLs evaluated directly and any result of the evaluation will not replace
712 * the current page content. Apps targetting KITKAT or later that load a JS URL will
713 * have the result of that URL replace the content of the current page</li>
714 * <li> {@link android.app.AlarmManager#set AlarmManager.set} becomes interpreted as
715 * an inexact value, to give the system more flexibility in scheduling alarms.</li>
716 * <li> {@link android.content.Context#getSharedPreferences(String, int)
717 * Context.getSharedPreferences} no longer allows a null name.</li>
718 * <li> {@link android.widget.RelativeLayout} changes to compute wrapped content
719 * margins correctly.</li>
720 * <li> {@link android.app.ActionBar}'s window content overlay is allowed to be
721 * drawn.</li>
Jeff Sharkey3ec2f602013-10-29 12:21:23 -0700722 * <li>The {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
723 * permission is now always enforced.</li>
724 * <li>Access to package-specific external storage directories belonging
725 * to the calling app no longer requires the
726 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} or
727 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
728 * permissions.</li>
Dianne Hackborn221ea892013-08-04 16:50:16 -0700729 * </ul>
Dianne Hackborn5d2bfa12013-03-05 10:28:34 -0800730 */
Dianne Hackborn6bc37892013-10-03 11:05:14 -0700731 public static final int KITKAT = 19;
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700732
733 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700734 * June 2014: Android 4.4W. KitKat for watches, snacks on the run.
Justin Koh78b94de2014-05-13 15:48:42 -0700735 *
736 * <p>Applications targeting this or a later release will get these
737 * new changes in behavior:</p>
738 * <ul>
739 * <li>{@link android.app.AlertDialog} might not have a default background if the theme does
740 * not specify one.</li>
741 * </ul>
Jeff Brown1c3f3322014-04-16 13:15:22 -0700742 */
Justin Koh78b94de2014-05-13 15:48:42 -0700743 public static final int KITKAT_WATCH = 20;
Jeff Brown047f3c72014-04-16 14:18:49 -0700744
745 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700746 * Temporary until we completely switch to {@link #LOLLIPOP}.
Dianne Hackbornd3511d42014-10-16 17:48:30 -0700747 * @hide
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700748 */
749 public static final int L = 21;
750
751 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700752 * November 2014: Lollipop. A flat one with beautiful shadows. But still tasty.
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700753 *
754 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700755 * new changes in behavior. For more information about this release, see the
756 * <a href="/about/versions/lollipop/">Android Lollipop overview</a>.</p>
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700757 * <ul>
758 * <li> {@link android.content.Context#bindService Context.bindService} now
Michael Wright5b5def52014-04-11 13:37:50 -0700759 * requires an explicit Intent, and will throw an exception if given an implicit
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700760 * Intent.</li>
Dianne Hackbornd3511d42014-10-16 17:48:30 -0700761 * <li> {@link android.app.Notification.Builder Notification.Builder} will
762 * not have the colors of their various notification elements adjusted to better
763 * match the new material design look.</li>
764 * <li> {@link android.os.Message} will validate that a message is not currently
765 * in use when it is recycled.</li>
766 * <li> Hardware accelerated drawing in windows will be enabled automatically
767 * in most places.</li>
768 * <li> {@link android.widget.Spinner} throws an exception if attaching an
769 * adapter with more than one item type.</li>
770 * <li> If the app is a launcher, the launcher will be available to the user
771 * even when they are using corporate profiles (which requires that the app
772 * use {@link android.content.pm.LauncherApps} to correctly populate its
773 * apps UI).</li>
774 * <li> Calling {@link android.app.Service#stopForeground Service.stopForeground}
775 * with removeNotification false will modify the still posted notification so that
776 * it is no longer forced to be ongoing.</li>
777 * <li> A {@link android.service.dreams.DreamService} must require the
778 * {@link android.Manifest.permission#BIND_DREAM_SERVICE} permission to be usable.</li>
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700779 * </ul>
780 */
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700781 public static final int LOLLIPOP = 21;
Dianne Hackborn3b696882014-10-16 18:14:12 -0700782
783 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700784 * March 2015: Lollipop with an extra sugar coating on the outside!
Andrew Solovaya861ff72018-08-06 13:43:30 -0700785 * For more information about this release, see the
786 * <a href="/about/versions/android-5.1">Android 5.1 APIs</a>.
Dianne Hackborn3b696882014-10-16 18:14:12 -0700787 */
788 public static final int LOLLIPOP_MR1 = 22;
Dianne Hackborn8bd95f12015-01-27 13:18:24 -0800789
790 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700791 * M is for Marshmallow!
792 *
793 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700794 * new changes in behavior. For more information about this release, see the
795 * <a href="/about/versions/marshmallow/">Android 6.0 Marshmallow overview</a>.</p>
Dianne Hackborne7a34352015-09-17 14:50:47 -0700796 * <ul>
797 * <li> Runtime permissions. Dangerous permissions are no longer granted at
798 * install time, but must be requested by the application at runtime through
799 * {@link android.app.Activity#requestPermissions}.</li>
800 * <li> Bluetooth and Wi-Fi scanning now requires holding the location permission.</li>
801 * <li> {@link android.app.AlarmManager#setTimeZone AlarmManager.setTimeZone} will fail if
802 * the given timezone is non-Olson.</li>
803 * <li> Activity transitions will only return shared
804 * elements mapped in the returned view hierarchy back to the calling activity.</li>
805 * <li> {@link android.view.View} allows a number of behaviors that may break
806 * existing apps: Canvas throws an exception if restore() is called too many times,
807 * widgets may return a hint size when returning UNSPECIFIED measure specs, and it
808 * will respect the attributes {@link android.R.attr#foreground},
809 * {@link android.R.attr#foregroundGravity}, {@link android.R.attr#foregroundTint}, and
810 * {@link android.R.attr#foregroundTintMode}.</li>
811 * <li> {@link android.view.MotionEvent#getButtonState MotionEvent.getButtonState}
812 * will no longer report {@link android.view.MotionEvent#BUTTON_PRIMARY}
813 * and {@link android.view.MotionEvent#BUTTON_SECONDARY} as synonyms for
814 * {@link android.view.MotionEvent#BUTTON_STYLUS_PRIMARY} and
815 * {@link android.view.MotionEvent#BUTTON_STYLUS_SECONDARY}.</li>
816 * <li> {@link android.widget.ScrollView} now respects the layout param margins
817 * when measuring.</li>
818 * </ul>
Dianne Hackborn8bd95f12015-01-27 13:18:24 -0800819 */
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700820 public static final int M = 23;
Wale Ogunwale79113102015-10-05 16:52:53 -0700821
822 /**
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700823 * N is for Nougat.
824 *
825 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700826 * new changes in behavior. For more information about this release, see
827 * the <a href="/about/versions/nougat/">Android Nougat overview</a>.</p>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700828 * <ul>
829 * <li> {@link android.app.DownloadManager.Request#setAllowedNetworkTypes
830 * DownloadManager.Request.setAllowedNetworkTypes}
831 * will disable "allow over metered" when specifying only
Dianne Hackborn5f1649e2016-08-09 18:00:31 -0700832 * {@link android.app.DownloadManager.Request#NETWORK_WIFI}.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700833 * <li> {@link android.app.DownloadManager} no longer allows access to raw
Dianne Hackborn5f1649e2016-08-09 18:00:31 -0700834 * file paths.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700835 * <li> {@link android.app.Notification.Builder#setShowWhen
836 * Notification.Builder.setShowWhen}
837 * must be called explicitly to have the time shown, and various other changes in
838 * {@link android.app.Notification.Builder Notification.Builder} to how notifications
839 * are shown.</li>
840 * <li>{@link android.content.Context#MODE_WORLD_READABLE} and
841 * {@link android.content.Context#MODE_WORLD_WRITEABLE} are no longer supported.</li>
842 * <li>{@link android.os.FileUriExposedException} will be thrown to applications.</li>
843 * <li>Applications will see global drag and drops as per
844 * {@link android.view.View#DRAG_FLAG_GLOBAL}.</li>
845 * <li>{@link android.webkit.WebView#evaluateJavascript WebView.evaluateJavascript}
846 * will not persist state from an empty WebView.</li>
847 * <li>{@link android.animation.AnimatorSet} will not ignore calls to end() before
848 * start().</li>
849 * <li>{@link android.app.AlarmManager#cancel(android.app.PendingIntent)
850 * AlarmManager.cancel} will throw a NullPointerException if given a null operation.</li>
851 * <li>{@link android.app.FragmentManager} will ensure fragments have been created
852 * before being placed on the back stack.</li>
853 * <li>{@link android.app.FragmentManager} restores fragments in
854 * {@link android.app.Fragment#onCreate Fragment.onCreate} rather than after the
855 * method returns.</li>
856 * <li>{@link android.R.attr#resizeableActivity} defaults to true.</li>
857 * <li>{@link android.graphics.drawable.AnimatedVectorDrawable} throws exceptions when
858 * opening invalid VectorDrawable animations.</li>
859 * <li>{@link android.view.ViewGroup.MarginLayoutParams} will no longer be dropped
860 * when converting between some types of layout params (such as
861 * {@link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams} to
862 * {@link android.widget.RelativeLayout.LayoutParams RelativeLayout.LayoutParams}).</li>
863 * <li>Your application processes will not be killed when the device density changes.</li>
Vadim Tryshev06b9b602016-09-23 15:32:33 -0700864 * <li>Drag and drop. After a view receives the
865 * {@link android.view.DragEvent#ACTION_DRAG_ENTERED} event, when the drag shadow moves into
866 * a descendant view that can accept the data, the view receives the
867 * {@link android.view.DragEvent#ACTION_DRAG_EXITED} event and won’t receive
868 * {@link android.view.DragEvent#ACTION_DRAG_LOCATION} and
869 * {@link android.view.DragEvent#ACTION_DROP} events while the drag shadow is within that
870 * descendant view, even if the descendant view returns <code>false</code> from its handler
871 * for these events.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700872 * </ul>
Wale Ogunwale79113102015-10-05 16:52:53 -0700873 */
Adam Powell43ec62a2016-05-25 16:36:41 -0700874 public static final int N = 24;
Michael Wright863ae3e2016-06-29 15:47:16 +0100875
876 /**
Andrew Solovaya861ff72018-08-06 13:43:30 -0700877 * N MR1: Nougat++. For more information about this release, see
878 * <a href="/about/versions/nougat/android-7.1">Android 7.1 for
879 * Developers</a>.
Michael Wright863ae3e2016-06-29 15:47:16 +0100880 */
881 public static final int N_MR1 = 25;
Makoto Onuki864f4bd2016-11-02 11:11:32 -0700882
883 /**
884 * O.
Evan Rosky534de292017-06-23 09:45:38 -0700885 *
886 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700887 * new changes in behavior. For more information about this release, see
888 * the <a href="/about/versions/oreo/">Android Oreo overview</a>.</p>
Evan Rosky534de292017-06-23 09:45:38 -0700889 * <ul>
Dianne Hackborna47d0452017-11-21 15:04:57 -0800890 * <li><a href="{@docRoot}about/versions/oreo/background.html">Background execution limits</a>
891 * are applied to the application.</li>
892 * <li>The behavior of AccountManager's
893 * {@link android.accounts.AccountManager#getAccountsByType},
894 * {@link android.accounts.AccountManager#getAccountsByTypeAndFeatures}, and
895 * {@link android.accounts.AccountManager#hasFeatures} has changed as documented there.</li>
896 * <li>{@link android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE_PRE_26}
897 * is now returned as
898 * {@link android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.</li>
899 * <li>The {@link android.app.NotificationManager} now requires the use of notification
900 * channels.</li>
901 * <li>Changes to the strict mode that are set in
902 * {@link Application#onCreate Application.onCreate} will no longer be clobbered after
903 * that function returns.</li>
904 * <li>A shared library apk with native code will have that native code included in
905 * the library path of its clients.</li>
906 * <li>{@link android.content.Context#getSharedPreferences Context.getSharedPreferences}
907 * in credential encrypted storage will throw an exception before the user is unlocked.</li>
908 * <li>Attempting to retrieve a {@link Context#FINGERPRINT_SERVICE} on a device that
909 * does not support that feature will now throw a runtime exception.</li>
910 * <li>{@link android.app.Fragment} will stop any active view animations when
911 * the fragment is stopped.</li>
912 * <li>Some compatibility code in Resources that attempts to use the default Theme
913 * the app may be using will be turned off, requiring the app to explicitly request
914 * resources with the right theme.</li>
915 * <li>{@link android.content.ContentResolver#notifyChange ContentResolver.notifyChange} and
916 * {@link android.content.ContentResolver#registerContentObserver
917 * ContentResolver.registerContentObserver}
918 * will throw a SecurityException if the caller does not have permission to access
919 * the provider (or the provider doesn't exit); otherwise the call will be silently
920 * ignored.</li>
921 * <li>{@link android.hardware.camera2.CameraDevice#createCaptureRequest
922 * CameraDevice.createCaptureRequest} will enable
923 * {@link android.hardware.camera2.CaptureRequest#CONTROL_ENABLE_ZSL} by default for
924 * still image capture.</li>
925 * <li>WallpaperManager's {@link android.app.WallpaperManager#getWallpaperFile},
926 * {@link android.app.WallpaperManager#getDrawable},
927 * {@link android.app.WallpaperManager#getFastDrawable},
928 * {@link android.app.WallpaperManager#peekDrawable}, and
929 * {@link android.app.WallpaperManager#peekFastDrawable} will throw an exception
930 * if you can not access the wallpaper.</li>
931 * <li>The behavior of
932 * {@link android.hardware.usb.UsbDeviceConnection#requestWait UsbDeviceConnection.requestWait}
933 * is modified as per the documentation there.</li>
934 * <li>{@link StrictMode.VmPolicy.Builder#detectAll StrictMode.VmPolicy.Builder.detectAll}
935 * will also enable {@link StrictMode.VmPolicy.Builder#detectContentUriWithoutPermission}
936 * and {@link StrictMode.VmPolicy.Builder#detectUntaggedSockets}.</li>
937 * <li>{@link StrictMode.ThreadPolicy.Builder#detectAll StrictMode.ThreadPolicy.Builder.detectAll}
938 * will also enable {@link StrictMode.ThreadPolicy.Builder#detectUnbufferedIo}.</li>
939 * <li>{@link android.provider.DocumentsContract}'s various methods will throw failure
940 * exceptions back to the caller instead of returning null.
941 * <li>{@link View#hasFocusable View.hasFocusable} now includes auto-focusable views.</li>
942 * <li>{@link android.view.SurfaceView} will no longer always change the underlying
943 * Surface object when something about it changes; apps need to look at the current
944 * state of the object to determine which things they are interested in have changed.</li>
945 * <li>{@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} must be
946 * used for overlay windows, other system overlay window types are not allowed.</li>
947 * <li>{@link android.view.ViewTreeObserver#addOnDrawListener
948 * ViewTreeObserver.addOnDrawListener} will throw an exception if called from within
949 * onDraw.</li>
950 * <li>{@link android.graphics.Canvas#setBitmap Canvas.setBitmap} will no longer preserve
951 * the current matrix and clip stack of the canvas.</li>
952 * <li>{@link android.widget.ListPopupWindow#setHeight ListPopupWindow.setHeight}
953 * will throw an exception if a negative height is supplied.</li>
954 * <li>{@link android.widget.TextView} will use internationalized input for numbers,
955 * dates, and times.</li>
956 * <li>{@link android.widget.Toast} must be used for showing toast windows; the toast
957 * window type can not be directly used.</li>
958 * <li>{@link android.net.wifi.WifiManager#getConnectionInfo WifiManager.getConnectionInfo}
959 * requires that the caller hold the location permission to return BSSID/SSID</li>
960 * <li>{@link android.net.wifi.p2p.WifiP2pManager#requestPeers WifiP2pManager.requestPeers}
961 * requires the caller hold the location permission.</li>
962 * <li>{@link android.R.attr#maxAspectRatio} defaults to 0, meaning there is no restriction
963 * on the app's maximum aspect ratio (so it can be stretched to fill larger screens).</li>
Evan Rosky534de292017-06-23 09:45:38 -0700964 * <li>{@link android.R.attr#focusable} defaults to a new state ({@code auto}) where it will
965 * inherit the value of {@link android.R.attr#clickable} unless explicitly overridden.</li>
966 * <li>A default theme-appropriate focus-state highlight will be supplied to all Views
967 * which don't provide a focus-state drawable themselves. This can be disabled by setting
968 * {@link android.R.attr#defaultFocusHighlightEnabled} to false.</li>
969 * </ul>
Makoto Onuki864f4bd2016-11-02 11:11:32 -0700970 */
Ian Pedowitz967869d2017-05-04 00:10:04 +0000971 public static final int O = 26;
Jeff Sharkey7beabc22017-07-19 13:57:35 -0600972
973 /**
974 * O MR1.
Dianne Hackborna47d0452017-11-21 15:04:57 -0800975 *
976 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700977 * new changes in behavior. For more information about this release, see
978 * <a href="/about/versions/oreo/android-8.1">Android 8.1 features and
979 * APIs</a>.</p>
Dianne Hackborna47d0452017-11-21 15:04:57 -0800980 * <ul>
981 * <li>Apps exporting and linking to apk shared libraries must explicitly
982 * enumerate all signing certificates in a consistent order.</li>
983 * <li>{@link android.R.attr#screenOrientation} can not be used to request a fixed
984 * orientation if the associated activity is not fullscreen and opaque.</li>
985 * </ul>
Andrew Solovaya861ff72018-08-06 13:43:30 -0700986 *
Jeff Sharkey7beabc22017-07-19 13:57:35 -0600987 */
Michael Wrighteec01ac2017-08-23 13:49:14 -0700988 public static final int O_MR1 = 27;
Makoto Onuki7bd7a622017-08-31 08:35:59 -0700989
990 /**
991 * P.
Dianne Hackborndd027b32018-01-19 17:44:46 -0800992 *
993 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700994 * new changes in behavior. For more information about this release, see the
995 * <a href="/about/versions/pie/">Android 9 Pie overview</a>.</p>
Dianne Hackborndd027b32018-01-19 17:44:46 -0800996 * <ul>
997 * <li>{@link android.app.Service#startForeground Service.startForeground} requires
998 * that apps hold the permission
999 * {@link android.Manifest.permission#FOREGROUND_SERVICE}.</li>
Chet Haasecb848882018-03-21 14:09:44 -07001000 * <li>{@link android.widget.LinearLayout} will always remeasure weighted children,
1001 * even if there is no excess space.</li>
Dianne Hackborndd027b32018-01-19 17:44:46 -08001002 * </ul>
Andrew Solovaya861ff72018-08-06 13:43:30 -07001003 *
Makoto Onuki7bd7a622017-08-31 08:35:59 -07001004 */
Wale Ogunwale3da5f3b2018-04-11 15:12:31 -07001005 public static final int P = 28;
Jeff Sharkey8929b522018-05-15 13:34:52 -06001006
1007 /**
1008 * Q.
Bradley Allen46248162020-08-10 23:16:42 +00001009 *
1010 * <p>Applications targeting this or a later release will get these new changes in behavior.
1011 * For more information about this release, see the
1012 * <a href="/about/versions/10">Android 10 overview</a>.</p>
1013 * <ul>
1014 * <li><a href="/about/versions/10/behavior-changes-all">Behavior changes: all apps</a></li>
1015 * <li><a href="/about/versions/10/behavior-changes-10">Behavior changes: apps targeting API
1016 * 29+</a></li>
1017 * </ul>
1018 *
Jeff Sharkey8929b522018-05-15 13:34:52 -06001019 */
Ian Pedowitz1912a572019-05-12 19:44:42 +00001020 public static final int Q = 29;
Suprabh Shukla1d081c52019-04-29 17:07:51 -07001021
1022 /**
1023 * R.
Bradley Allencefc89c2020-09-09 17:30:08 +00001024 *
1025 * <p>Applications targeting this or a later release will get these new changes in behavior.
1026 * For more information about this release, see the
1027 * <a href="/about/versions/11">Android 11 overview</a>.</p>
1028 * <ul>
1029 * <li><a href="/about/versions/11/behavior-changes-all">Behavior changes: all apps</a></li>
1030 * <li><a href="/about/versions/11/behavior-changes-11">Behavior changes: Apps targeting
1031 * Android 11</a></li>
1032 * <li><a href="/about/versions/11/non-sdk-11">Updates to non-SDK interface restrictions
1033 * in Android 11</a></li>
1034 * </ul>
1035 *
Suprabh Shukla1d081c52019-04-29 17:07:51 -07001036 */
Svet Ganov38cd2212020-04-15 15:10:14 -07001037 public static final int R = 30;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001038 }
Andres Moralescb3fd692015-01-14 10:07:55 -08001039
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001040 /** The type of build, like "user" or "eng". */
1041 public static final String TYPE = getString("ro.build.type");
1042
1043 /** Comma-separated tags describing the build, like "unsigned,debug". */
1044 public static final String TAGS = getString("ro.build.tags");
1045
1046 /** A string that uniquely identifies this build. Do not attempt to parse this value. */
Jeff Sharkey55687722014-04-09 18:07:19 -07001047 public static final String FINGERPRINT = deriveFingerprint();
1048
1049 /**
1050 * Some devices split the fingerprint components between multiple
1051 * partitions, so we might derive the fingerprint at runtime.
1052 */
1053 private static String deriveFingerprint() {
1054 String finger = SystemProperties.get("ro.build.fingerprint");
1055 if (TextUtils.isEmpty(finger)) {
1056 finger = getString("ro.product.brand") + '/' +
1057 getString("ro.product.name") + '/' +
1058 getString("ro.product.device") + ':' +
1059 getString("ro.build.version.release") + '/' +
1060 getString("ro.build.id") + '/' +
1061 getString("ro.build.version.incremental") + ':' +
1062 getString("ro.build.type") + '/' +
1063 getString("ro.build.tags");
1064 }
1065 return finger;
1066 }
1067
1068 /**
1069 * Ensure that raw fingerprint system property is defined. If it was derived
1070 * dynamically by {@link #deriveFingerprint()} this is where we push the
1071 * derived value into the property service.
1072 *
1073 * @hide
1074 */
1075 public static void ensureFingerprintProperty() {
1076 if (TextUtils.isEmpty(SystemProperties.get("ro.build.fingerprint"))) {
Jeff Sharkeybdd44912014-04-11 16:30:14 -07001077 try {
1078 SystemProperties.set("ro.build.fingerprint", FINGERPRINT);
1079 } catch (IllegalArgumentException e) {
1080 Slog.e(TAG, "Failed to set fingerprint property", e);
1081 }
Jeff Sharkey55687722014-04-09 18:07:19 -07001082 }
1083 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001084
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001085 /**
Michael Schwartz18511182017-05-15 11:40:40 -07001086 * True if Treble is enabled and required for this device.
1087 *
1088 * @hide
1089 */
1090 public static final boolean IS_TREBLE_ENABLED =
1091 SystemProperties.getBoolean("ro.treble.enabled", false);
1092
1093 /**
1094 * Verifies the current flash of the device is consistent with what
Andres Moralesfd282ed2015-02-06 15:07:59 -08001095 * was expected at build time.
Michael Schwartz18511182017-05-15 11:40:40 -07001096 *
1097 * Treble devices will verify the Vendor Interface (VINTF). A device
1098 * launched without Treble:
1099 *
Andres Moralesfd282ed2015-02-06 15:07:59 -08001100 * 1) Checks that device fingerprint is defined and that it matches across
1101 * various partitions.
1102 * 2) Verifies radio and bootloader partitions are those expected in the build.
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001103 *
1104 * @hide
1105 */
Andres Moralesfd282ed2015-02-06 15:07:59 -08001106 public static boolean isBuildConsistent() {
Xiaohui Chen2102dcb2015-10-02 16:45:55 -07001107 // Don't care on eng builds. Incremental build may trigger false negative.
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001108 if (IS_ENG) return true;
Xiaohui Chen2102dcb2015-10-02 16:45:55 -07001109
Michael Schwartz18511182017-05-15 11:40:40 -07001110 if (IS_TREBLE_ENABLED) {
Bowgo Tsaib1de4312017-11-17 17:18:50 +08001111 // If we can run this code, the device should already pass AVB.
1112 // So, we don't need to check AVB here.
1113 int result = VintfObject.verifyWithoutAvb();
Michael Schwartz18511182017-05-15 11:40:40 -07001114
1115 if (result != 0) {
1116 Slog.e(TAG, "Vendor interface is incompatible, error="
1117 + String.valueOf(result));
1118 }
1119
1120 return result == 0;
1121 }
1122
Felix88c1bf02019-10-20 02:04:04 +02001123 final String system = SystemProperties.get("ro.system.build.fingerprint");
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001124 final String vendor = SystemProperties.get("ro.vendor.build.fingerprint");
Andres Moralescb3fd692015-01-14 10:07:55 -08001125 final String bootimage = SystemProperties.get("ro.bootimage.build.fingerprint");
Andres Moralesfd282ed2015-02-06 15:07:59 -08001126 final String requiredBootloader = SystemProperties.get("ro.build.expect.bootloader");
1127 final String currentBootloader = SystemProperties.get("ro.bootloader");
1128 final String requiredRadio = SystemProperties.get("ro.build.expect.baseband");
Inseob Kim1b5e2412019-11-08 15:06:37 +09001129 final String currentRadio = joinListOrElse(
1130 TelephonyProperties.baseband_version(), "");
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001131
1132 if (TextUtils.isEmpty(system)) {
Felix88c1bf02019-10-20 02:04:04 +02001133 Slog.e(TAG, "Required ro.system.build.fingerprint is empty!");
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001134 return false;
1135 }
1136
1137 if (!TextUtils.isEmpty(vendor)) {
1138 if (!Objects.equals(system, vendor)) {
1139 Slog.e(TAG, "Mismatched fingerprints; system reported " + system
1140 + " but vendor reported " + vendor);
1141 return false;
1142 }
1143 }
1144
Andres Moralesc97b92e2015-06-01 17:50:43 +00001145 /* TODO: Figure out issue with checks failing
Andres Moralescb3fd692015-01-14 10:07:55 -08001146 if (!TextUtils.isEmpty(bootimage)) {
Andres Morales7de24ce2015-01-23 12:45:54 -08001147 if (!Objects.equals(system, bootimage)) {
1148 Slog.e(TAG, "Mismatched fingerprints; system reported " + system
Andres Moralescb3fd692015-01-14 10:07:55 -08001149 + " but bootimage reported " + bootimage);
1150 return false;
1151 }
1152 }
1153
Andres Moralesfd282ed2015-02-06 15:07:59 -08001154 if (!TextUtils.isEmpty(requiredBootloader)) {
1155 if (!Objects.equals(currentBootloader, requiredBootloader)) {
1156 Slog.e(TAG, "Mismatched bootloader version: build requires " + requiredBootloader
1157 + " but runtime reports " + currentBootloader);
1158 return false;
1159 }
1160 }
1161
1162 if (!TextUtils.isEmpty(requiredRadio)) {
1163 if (!Objects.equals(currentRadio, requiredRadio)) {
1164 Slog.e(TAG, "Mismatched radio version: build requires " + requiredRadio
1165 + " but runtime reports " + currentRadio);
1166 return false;
1167 }
1168 }
Daniel Rosenberg159c2052015-02-20 13:10:26 -08001169 */
Andres Moralesfd282ed2015-02-06 15:07:59 -08001170
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001171 return true;
1172 }
1173
Anton Hansson91b54f12018-09-24 18:24:19 +01001174 /** Build information for a particular device partition. */
1175 public static class Partition {
1176 /** The name identifying the system partition. */
1177 public static final String PARTITION_NAME_SYSTEM = "system";
1178
Anton Hansson2579d1a2019-02-06 12:14:12 +00001179 private final String mName;
1180 private final String mFingerprint;
1181 private final long mTimeMs;
Anton Hansson91b54f12018-09-24 18:24:19 +01001182
1183 private Partition(String name, String fingerprint, long timeMs) {
1184 mName = name;
1185 mFingerprint = fingerprint;
1186 mTimeMs = timeMs;
1187 }
1188
1189 /** The name of this partition, e.g. "system", or "vendor" */
Anton Hansson81f76a02018-10-04 18:40:22 +01001190 @NonNull
Anton Hansson91b54f12018-09-24 18:24:19 +01001191 public String getName() {
1192 return mName;
1193 }
1194
1195 /** The build fingerprint of this partition, see {@link Build#FINGERPRINT}. */
Anton Hansson81f76a02018-10-04 18:40:22 +01001196 @NonNull
Anton Hansson91b54f12018-09-24 18:24:19 +01001197 public String getFingerprint() {
1198 return mFingerprint;
1199 }
1200
1201 /** The time (ms since epoch), at which this partition was built, see {@link Build#TIME}. */
Anton Hansson81f76a02018-10-04 18:40:22 +01001202 public long getBuildTimeMillis() {
Anton Hansson91b54f12018-09-24 18:24:19 +01001203 return mTimeMs;
1204 }
Anton Hansson81f76a02018-10-04 18:40:22 +01001205
1206 @Override
1207 public boolean equals(Object o) {
1208 if (!(o instanceof Partition)) {
1209 return false;
1210 }
1211 Partition op = (Partition) o;
1212 return mName.equals(op.mName)
1213 && mFingerprint.equals(op.mFingerprint)
1214 && mTimeMs == op.mTimeMs;
1215 }
1216
1217 @Override
1218 public int hashCode() {
1219 return Objects.hash(mName, mFingerprint, mTimeMs);
1220 }
Anton Hansson91b54f12018-09-24 18:24:19 +01001221 }
1222
1223 /**
1224 * Get build information about partitions that have a separate fingerprint defined.
1225 *
1226 * The list includes partitions that are suitable candidates for over-the-air updates. This is
1227 * not an exhaustive list of partitions on the device.
1228 */
Anton Hansson81f76a02018-10-04 18:40:22 +01001229 @NonNull
1230 public static List<Partition> getFingerprintedPartitions() {
Anton Hansson91b54f12018-09-24 18:24:19 +01001231 ArrayList<Partition> partitions = new ArrayList();
1232
1233 String[] names = new String[] {
Jeongik Cha9ec059a2019-07-04 21:12:06 +09001234 "bootimage", "odm", "product", "system_ext", Partition.PARTITION_NAME_SYSTEM,
Anton Hansson91b54f12018-09-24 18:24:19 +01001235 "vendor"
1236 };
1237 for (String name : names) {
1238 String fingerprint = SystemProperties.get("ro." + name + ".build.fingerprint");
1239 if (TextUtils.isEmpty(fingerprint)) {
1240 continue;
1241 }
1242 long time = getLong("ro." + name + ".build.date.utc") * 1000;
1243 partitions.add(new Partition(name, fingerprint, time));
1244 }
1245
1246 return partitions;
1247 }
1248
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001249 // The following properties only make sense for internal engineering builds.
Anton Hansson91b54f12018-09-24 18:24:19 +01001250
1251 /** The time at which the build was produced, given in milliseconds since the UNIX epoch. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001252 public static final long TIME = getLong("ro.build.date.utc") * 1000;
1253 public static final String USER = getString("ro.build.user");
1254 public static final String HOST = getString("ro.build.host");
1255
Doug Zongkerad2171a2011-06-14 11:07:24 -07001256 /**
Jeff Brown89101cd92011-10-27 21:24:54 -07001257 * Returns true if we are running a debug build such as "user-debug" or "eng".
1258 * @hide
1259 */
Andrei Onea24ec3212019-03-15 17:35:05 +00001260 @UnsupportedAppUsage
Jeff Brown89101cd92011-10-27 21:24:54 -07001261 public static final boolean IS_DEBUGGABLE =
1262 SystemProperties.getInt("ro.debuggable", 0) == 1;
1263
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001264 /** {@hide} */
Jeff Sharkeycdee83a2017-01-26 15:29:16 -07001265 public static final boolean IS_ENG = "eng".equals(TYPE);
1266 /** {@hide} */
1267 public static final boolean IS_USERDEBUG = "userdebug".equals(TYPE);
1268 /** {@hide} */
1269 public static final boolean IS_USER = "user".equals(TYPE);
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001270
Jeff Brown89101cd92011-10-27 21:24:54 -07001271 /**
Xiaohui Chen387c65f2017-01-17 14:29:03 -08001272 * Whether this build is running inside a container.
1273 *
1274 * We should try to avoid checking this flag if possible to minimize
1275 * unnecessarily diverging from non-container Android behavior.
1276 * Checking this flag is acceptable when low-level resources being
1277 * different, e.g. the availability of certain capabilities, access to
1278 * system resources being restricted, and the fact that the host OS might
1279 * handle some features for us.
1280 * For higher-level behavior differences, other checks should be preferred.
1281 * @hide
1282 */
1283 public static final boolean IS_CONTAINER =
1284 SystemProperties.getBoolean("ro.boot.container", false);
1285
1286 /**
Svet Ganov9c165d72015-12-01 19:52:26 -08001287 * Specifies whether the permissions needed by a legacy app should be
1288 * reviewed before any of its components can run. A legacy app is one
1289 * with targetSdkVersion < 23, i.e apps using the old permission model.
1290 * If review is not required, permissions are reviewed before the app
1291 * is installed.
1292 *
1293 * @hide
Svet Ganov77df6f32016-08-17 11:46:34 -07001294 * @removed
Svet Ganov9c165d72015-12-01 19:52:26 -08001295 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08001296 @SystemApi
Philip P. Moltmann6c644e62018-07-18 15:41:24 -07001297 public static final boolean PERMISSIONS_REVIEW_REQUIRED = true;
Svet Ganov9c165d72015-12-01 19:52:26 -08001298
1299 /**
Doug Zongkerad2171a2011-06-14 11:07:24 -07001300 * Returns the version string for the radio firmware. May return
1301 * null (if, for instance, the radio is not currently on).
1302 */
1303 public static String getRadioVersion() {
Inseob Kim1b5e2412019-11-08 15:06:37 +09001304 return joinListOrElse(TelephonyProperties.baseband_version(), null);
Doug Zongkerad2171a2011-06-14 11:07:24 -07001305 }
1306
Andrei Onea24ec3212019-03-15 17:35:05 +00001307 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001308 private static String getString(String property) {
1309 return SystemProperties.get(property, UNKNOWN);
1310 }
1311
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +01001312 private static String[] getStringList(String property, String separator) {
1313 String value = SystemProperties.get(property);
1314 if (value.isEmpty()) {
1315 return new String[0];
1316 } else {
1317 return value.split(separator);
1318 }
1319 }
1320
Andrei Onea24ec3212019-03-15 17:35:05 +00001321 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001322 private static long getLong(String property) {
1323 try {
1324 return Long.parseLong(SystemProperties.get(property));
1325 } catch (NumberFormatException e) {
1326 return -1;
1327 }
1328 }
Inseob Kim1b5e2412019-11-08 15:06:37 +09001329
1330 private static <T> String joinListOrElse(List<T> list, String defaultValue) {
1331 String ret = list.stream().map(elem -> elem == null ? "" : elem.toString())
1332 .collect(Collectors.joining(","));
1333 return ret.isEmpty() ? defaultValue : ret;
1334 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335}