blob: f21956bfe607b9b46f7777a28f4a0c44e2e56c64 [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;
Andrei Onea24ec3212019-03-15 17:35:05 +000025import android.annotation.UnsupportedAppUsage;
Michael Groover6d20d752018-10-01 16:14:50 -070026import android.app.ActivityThread;
Dianne Hackborna47d0452017-11-21 15:04:57 -080027import android.app.Application;
Svet Ganov37e43272016-09-09 16:01:32 -070028import android.content.Context;
Jeff Sharkey55687722014-04-09 18:07:19 -070029import android.text.TextUtils;
Jeff Sharkeybdd44912014-04-11 16:30:14 -070030import android.util.Slog;
Dianne Hackborna47d0452017-11-21 15:04:57 -080031import android.view.View;
Jeff Sharkey55687722014-04-09 18:07:19 -070032
Doug Zongkerad2171a2011-06-14 11:07:24 -070033import com.android.internal.telephony.TelephonyProperties;
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -080034
Narayan Kamatheff258c2014-09-30 13:20:57 +010035import dalvik.system.VMRuntime;
Doug Zongkerad2171a2011-06-14 11:07:24 -070036
Anton Hansson91b54f12018-09-24 18:24:19 +010037import java.util.ArrayList;
38import java.util.List;
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -080039import java.util.Objects;
40
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
102 public static final String RADIO = getString(TelephonyProperties.PROPERTY_BASEBAND_VERSION);
Dan Egnor42471dd2010-01-07 17:25:22 -0800103
Doug Zongker74885ef2010-02-02 17:39:26 -0800104 /** The name of the hardware (from the kernel command line or /proc). */
105 public static final String HARDWARE = getString("ro.hardware");
Dan Egnor42471dd2010-01-07 17:25:22 -0800106
Griff Hazend3c454d2016-03-25 07:30:34 -0700107 /**
108 * Whether this build was for an emulator device.
109 * @hide
110 */
Artur Satayev5a525852019-10-31 15:15:50 +0000111 @UnsupportedAppUsage
Wale Ogunwale691af682019-02-11 03:09:10 -0800112 @TestApi
Griff Hazend3c454d2016-03-25 07:30:34 -0700113 public static final boolean IS_EMULATOR = getString("ro.kernel.qemu").equals("1");
114
Svet Ganov37e43272016-09-09 16:01:32 -0700115 /**
116 * A hardware serial number, if available. Alphanumeric only, case-insensitive.
Michael Groover1279ff92019-05-29 14:19:16 -0700117 * This field is always set to {@link Build#UNKNOWN}.
Svet Ganov37e43272016-09-09 16:01:32 -0700118 *
119 * @deprecated Use {@link #getSerial()} instead.
120 **/
121 @Deprecated
122 // IMPORTANT: This field should be initialized via a function call to
123 // prevent its value being inlined in the app during compilation because
124 // we will later set it to the value based on the app's target SDK.
125 public static final String SERIAL = getString("no.such.thing");
126
127 /**
Kevin Hufnagled6ebb552017-05-16 16:48:10 -0700128 * Gets the hardware serial number, if available.
129 *
130 * <p class="note"><b>Note:</b> Root access may allow you to modify device identifiers, such as
131 * the hardware serial number. If you change these identifiers, you can use
132 * <a href="/training/articles/security-key-attestation.html">key attestation</a> to obtain
133 * proof of the device's original identifiers.
134 *
Michael Grooverb0401fb2019-05-09 19:35:16 -0700135 * <p>Requires Permission: READ_PRIVILEGED_PHONE_STATE, for the calling app to be the device or
136 * profile owner and have the READ_PHONE_STATE permission, or that the calling app has carrier
137 * privileges (see {@link android.telephony.TelephonyManager#hasCarrierPrivileges}). The profile
138 * owner is an app that owns a managed profile on the device; for more details see <a
139 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>. Profile owner
140 * access is deprecated and will be removed in a future release.
Michael Groover6d20d752018-10-01 16:14:50 -0700141 *
Michael Grooverb0401fb2019-05-09 19:35:16 -0700142 * <p>If the calling app does not meet one of these requirements then this method will behave
143 * as follows:
144 *
145 * <ul>
146 * <li>If the calling app's target SDK is API level 28 or lower and the app has the
147 * READ_PHONE_STATE permission then {@link Build#UNKNOWN} is returned.</li>
148 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have
149 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or
150 * higher, then a SecurityException is thrown.</li>
151 * </ul>
152 * *
Kevin Hufnagled6ebb552017-05-16 16:48:10 -0700153 * @return The serial number if specified.
Svet Ganov37e43272016-09-09 16:01:32 -0700154 */
Michael Groover6d20d752018-10-01 16:14:50 -0700155 @SuppressAutoDoc // No support for device / profile owner.
156 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Svet Ganov37e43272016-09-09 16:01:32 -0700157 public static String getSerial() {
158 IDeviceIdentifiersPolicyService service = IDeviceIdentifiersPolicyService.Stub
159 .asInterface(ServiceManager.getService(Context.DEVICE_IDENTIFIERS_SERVICE));
160 try {
Michael Groover6d20d752018-10-01 16:14:50 -0700161 Application application = ActivityThread.currentApplication();
162 String callingPackage = application != null ? application.getPackageName() : null;
163 return service.getSerialForPackage(callingPackage);
Svet Ganov37e43272016-09-09 16:01:32 -0700164 } catch (RemoteException e) {
165 e.rethrowFromSystemServer();
166 }
167 return UNKNOWN;
168 }
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000169
170 /**
Narayan Kamath0f206a12014-04-12 11:41:13 +0100171 * An ordered list of ABIs supported by this device. The most preferred ABI is the first
172 * element in the list.
173 *
174 * See {@link #SUPPORTED_32_BIT_ABIS} and {@link #SUPPORTED_64_BIT_ABIS}.
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000175 */
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100176 public static final String[] SUPPORTED_ABIS = getStringList("ro.product.cpu.abilist", ",");
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000177
Narayan Kamath0f206a12014-04-12 11:41:13 +0100178 /**
179 * An ordered list of <b>32 bit</b> ABIs supported by this device. The most preferred ABI
180 * is the first element in the list.
181 *
182 * See {@link #SUPPORTED_ABIS} and {@link #SUPPORTED_64_BIT_ABIS}.
Narayan Kamath0f206a12014-04-12 11:41:13 +0100183 */
Torne (Richard Coles)da8c0372014-05-14 16:17:26 +0100184 public static final String[] SUPPORTED_32_BIT_ABIS =
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100185 getStringList("ro.product.cpu.abilist32", ",");
Narayan Kamath0f206a12014-04-12 11:41:13 +0100186
187 /**
188 * An ordered list of <b>64 bit</b> ABIs supported by this device. The most preferred ABI
189 * is the first element in the list.
190 *
191 * See {@link #SUPPORTED_ABIS} and {@link #SUPPORTED_32_BIT_ABIS}.
Narayan Kamath0f206a12014-04-12 11:41:13 +0100192 */
Torne (Richard Coles)da8c0372014-05-14 16:17:26 +0100193 public static final String[] SUPPORTED_64_BIT_ABIS =
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100194 getStringList("ro.product.cpu.abilist64", ",");
Narayan Kamath0f206a12014-04-12 11:41:13 +0100195
Jeff Sharkeyc6091162018-06-29 17:15:40 -0600196 /** {@hide} */
197 @TestApi
198 public static boolean is64BitAbi(String abi) {
199 return VMRuntime.is64BitAbi(abi);
200 }
Narayan Kamath0f206a12014-04-12 11:41:13 +0100201
Narayan Kamatheff258c2014-09-30 13:20:57 +0100202 static {
203 /*
204 * Adjusts CPU_ABI and CPU_ABI2 depending on whether or not a given process is 64 bit.
205 * 32 bit processes will always see 32 bit ABIs in these fields for backward
206 * compatibility.
207 */
208 final String[] abiList;
209 if (VMRuntime.getRuntime().is64Bit()) {
210 abiList = SUPPORTED_64_BIT_ABIS;
211 } else {
212 abiList = SUPPORTED_32_BIT_ABIS;
213 }
214
215 CPU_ABI = abiList[0];
216 if (abiList.length > 1) {
217 CPU_ABI2 = abiList[1];
218 } else {
219 CPU_ABI2 = "";
220 }
221 }
222
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800223 /** Various version strings. */
224 public static class VERSION {
225 /**
226 * The internal value used by the underlying source control to
227 * represent this build. E.g., a perforce changelist number
228 * or a git hash.
229 */
230 public static final String INCREMENTAL = getString("ro.build.version.incremental");
231
232 /**
Daniel Colascioned1520aa2018-04-06 08:12:05 -0700233 * The user-visible version string. E.g., "1.0" or "3.4b5" or "bananas".
234 *
235 * This field is an opaque string. Do not assume that its value
236 * has any particular structure or that values of RELEASE from
237 * different releases can be somehow ordered.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800238 */
239 public static final String RELEASE = getString("ro.build.version.release");
240
241 /**
Dianne Hackbornc3f74492015-08-12 16:10:58 -0700242 * The base OS build the product is based on.
243 */
244 public static final String BASE_OS = SystemProperties.get("ro.build.version.base_os", "");
245
246 /**
247 * The user-visible security patch level.
248 */
249 public static final String SECURITY_PATCH = SystemProperties.get(
250 "ro.build.version.security_patch", "");
251
252 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700253 * The user-visible SDK version of the framework in its raw String
254 * representation; use {@link #SDK_INT} instead.
Andres Moralescb3fd692015-01-14 10:07:55 -0800255 *
Dianne Hackborn851a5412009-05-08 12:06:44 -0700256 * @deprecated Use {@link #SDK_INT} to easily get this as an integer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700258 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800259 public static final String SDK = getString("ro.build.version.sdk");
Dianne Hackborn851a5412009-05-08 12:06:44 -0700260
261 /**
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700262 * The SDK version of the software currently running on this hardware
263 * device. This value never changes while a device is booted, but it may
264 * increase when the hardware manufacturer provides an OTA update.
265 * <p>
266 * Possible values are defined in {@link Build.VERSION_CODES}.
Dianne Hackborn851a5412009-05-08 12:06:44 -0700267 */
268 public static final int SDK_INT = SystemProperties.getInt(
269 "ro.build.version.sdk", 0);
270
271 /**
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700272 * The SDK version of the software that <em>initially</em> shipped on
273 * this hardware device. It <em>never</em> changes during the lifetime
274 * of the device, even when {@link #SDK_INT} increases due to an OTA
275 * update.
276 * <p>
277 * Possible values are defined in {@link Build.VERSION_CODES}.
278 *
279 * @see #SDK_INT
Jeff Sharkey1da8bb12018-03-26 12:50:54 -0600280 * @hide
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700281 */
Jeff Sharkey1da8bb12018-03-26 12:50:54 -0600282 @TestApi
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700283 public static final int FIRST_SDK_INT = SystemProperties
284 .getInt("ro.product.first_api_level", 0);
285
286 /**
Adam Powelle9600302015-05-06 18:13:09 -0700287 * The developer preview revision of a prerelease SDK. This value will always
288 * be <code>0</code> on production platform builds/devices.
289 *
290 * <p>When this value is nonzero, any new API added since the last
291 * officially published {@link #SDK_INT API level} is only guaranteed to be present
292 * on that specific preview revision. For example, an API <code>Activity.fooBar()</code>
293 * might be present in preview revision 1 but renamed or removed entirely in
294 * preview revision 2, which may cause an app attempting to call it to crash
295 * at runtime.</p>
296 *
297 * <p>Experimental apps targeting preview APIs should check this value for
298 * equality (<code>==</code>) with the preview SDK revision they were built for
299 * before using any prerelease platform APIs. Apps that detect a preview SDK revision
300 * other than the specific one they expect should fall back to using APIs from
301 * the previously published API level only to avoid unwanted runtime exceptions.
302 * </p>
303 */
304 public static final int PREVIEW_SDK_INT = SystemProperties.getInt(
305 "ro.build.version.preview_sdk", 0);
306
307 /**
Narayan Kamathb081e072018-12-13 19:09:20 +0000308 * The SDK fingerprint for a given prerelease SDK. This value will always be
309 * {@code REL} on production platform builds/devices.
310 *
311 * <p>When this value is not {@code REL}, it contains a string fingerprint of the API
312 * surface exposed by the preview SDK. Preview platforms with different API surfaces
313 * will have different {@code PREVIEW_SDK_FINGERPRINT}.
314 *
315 * <p>This attribute is intended for use by installers for finer grained targeting of
316 * packages. Applications targeting preview APIs should not use this field and should
317 * instead use {@code PREVIEW_SDK_INT} or use reflection or other runtime checks to
318 * detect the presence of an API or guard themselves against unexpected runtime
319 * behavior.
320 *
321 * @hide
322 */
323 @SystemApi
Narayan Kamath714bf492019-03-08 17:08:07 +0000324 @NonNull public static final String PREVIEW_SDK_FINGERPRINT = SystemProperties.get(
Narayan Kamathb081e072018-12-13 19:09:20 +0000325 "ro.build.version.preview_sdk_fingerprint", "REL");
326
327 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700328 * The current development codename, or the string "REL" if this is
329 * a release build.
330 */
331 public static final String CODENAME = getString("ro.build.version.codename");
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800332
Dianne Hackbornffcda102014-04-24 13:06:27 -0700333 private static final String[] ALL_CODENAMES
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100334 = getStringList("ro.build.version.all_codenames", ",");
Dianne Hackbornffcda102014-04-24 13:06:27 -0700335
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800336 /**
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800337 * @hide
338 */
Dan Willemsencac5c612019-04-18 13:38:57 -0700339 @TestApi
Andrei Onea24ec3212019-03-15 17:35:05 +0000340 @UnsupportedAppUsage
Dianne Hackbornffcda102014-04-24 13:06:27 -0700341 public static final String[] ACTIVE_CODENAMES = "REL".equals(ALL_CODENAMES[0])
342 ? new String[0] : ALL_CODENAMES;
343
344 /**
345 * The SDK version to use when accessing resources.
346 * Use the current SDK version code. For every active development codename
347 * we are operating under, we bump the assumed resource platform version by 1.
348 * @hide
349 */
Dianne Hackborn337e01a2018-02-27 17:16:37 -0800350 @TestApi
Dianne Hackbornffcda102014-04-24 13:06:27 -0700351 public static final int RESOURCES_SDK_INT = SDK_INT + ACTIVE_CODENAMES.length;
Przemyslaw Szczepaniak73b6bc82017-12-05 11:07:30 +0000352
353 /**
354 * The current lowest supported value of app target SDK. Applications targeting
Narayan Kamath91c361d2018-03-26 18:31:33 +0100355 * lower values may not function on devices running this SDK version. Its possible
356 * values are defined in {@link Build.VERSION_CODES}.
357 *
358 * @hide
Przemyslaw Szczepaniak73b6bc82017-12-05 11:07:30 +0000359 */
360 public static final int MIN_SUPPORTED_TARGET_SDK_INT = SystemProperties.getInt(
361 "ro.build.version.min_supported_target_sdk", 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800362 }
363
Dianne Hackborn851a5412009-05-08 12:06:44 -0700364 /**
365 * Enumeration of the currently known SDK version codes. These are the
366 * values that can be found in {@link VERSION#SDK}. Version numbers
367 * increment monotonically with each official platform release.
368 */
369 public static class VERSION_CODES {
370 /**
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700371 * Magic version number for a current development build, which has
372 * not yet turned into an official release.
373 */
Tobias Thierer8bacd9b2017-02-15 20:38:29 +0000374 public static final int CUR_DEVELOPMENT = VMRuntime.SDK_VERSION_CUR_DEVELOPMENT;
Andres Moralescb3fd692015-01-14 10:07:55 -0800375
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700376 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700377 * October 2008: The original, first, version of Android. Yay!
378 */
379 public static final int BASE = 1;
Andres Moralescb3fd692015-01-14 10:07:55 -0800380
Dianne Hackborn851a5412009-05-08 12:06:44 -0700381 /**
382 * February 2009: First Android update, officially called 1.1.
383 */
384 public static final int BASE_1_1 = 2;
Andres Moralescb3fd692015-01-14 10:07:55 -0800385
Dianne Hackborn851a5412009-05-08 12:06:44 -0700386 /**
387 * May 2009: Android 1.5.
388 */
389 public static final int CUPCAKE = 3;
Andres Moralescb3fd692015-01-14 10:07:55 -0800390
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700391 /**
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700392 * September 2009: Android 1.6.
Andres Moralescb3fd692015-01-14 10:07:55 -0800393 *
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700394 * <p>Applications targeting this or a later release will get these
395 * new changes in behavior:</p>
396 * <ul>
397 * <li> They must explicitly request the
San Mehat5a3a77d2009-06-01 09:25:28 -0700398 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission to be
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700399 * able to modify the contents of the SD card. (Apps targeting
400 * earlier versions will always request the permission.)
Dianne Hackbornfe77ec82009-08-12 16:53:56 -0700401 * <li> They must explicitly request the
402 * {@link android.Manifest.permission#READ_PHONE_STATE} permission to be
403 * able to be able to retrieve phone state info. (Apps targeting
404 * earlier versions will always request the permission.)
405 * <li> They are assumed to support different screen densities and
406 * sizes. (Apps targeting earlier versions are assumed to only support
407 * medium density normal size screens unless otherwise indicated).
408 * They can still explicitly specify screen support either way with the
409 * supports-screens manifest tag.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700410 * <li> {@link android.widget.TabHost} will use the new dark tab
411 * background design.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700412 * </ul>
413 */
Dianne Hackbornfe77ec82009-08-12 16:53:56 -0700414 public static final int DONUT = 4;
Andres Moralescb3fd692015-01-14 10:07:55 -0800415
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700416 /**
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700417 * November 2009: Android 2.0
Andres Moralescb3fd692015-01-14 10:07:55 -0800418 *
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700419 * <p>Applications targeting this or a later release will get these
420 * new changes in behavior:</p>
421 * <ul>
422 * <li> The {@link android.app.Service#onStartCommand
423 * Service.onStartCommand} function will return the new
424 * {@link android.app.Service#START_STICKY} behavior instead of the
425 * old compatibility {@link android.app.Service#START_STICKY_COMPATIBILITY}.
Dianne Hackborn8d374262009-09-14 21:21:52 -0700426 * <li> The {@link android.app.Activity} class will now execute back
427 * key presses on the key up instead of key down, to be able to detect
428 * canceled presses from virtual keys.
Mike Cleron76097642009-09-25 17:53:56 -0700429 * <li> The {@link android.widget.TabWidget} class will use a new color scheme
430 * for tabs. In the new scheme, the foreground tab has a medium gray background
431 * the background tabs have a dark gray background.
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700432 * </ul>
433 */
Jeff Hamilton6dc3f4e2009-10-10 12:06:19 -0500434 public static final int ECLAIR = 5;
Andres Moralescb3fd692015-01-14 10:07:55 -0800435
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700436 /**
Dianne Hackborn17787762009-11-12 16:11:36 -0800437 * December 2009: Android 2.0.1
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700438 */
Dianne Hackborn17787762009-11-12 16:11:36 -0800439 public static final int ECLAIR_0_1 = 6;
Andres Moralescb3fd692015-01-14 10:07:55 -0800440
Dianne Hackborn23ef7b42009-11-18 18:20:39 -0800441 /**
442 * January 2010: Android 2.1
443 */
444 public static final int ECLAIR_MR1 = 7;
Andres Moralescb3fd692015-01-14 10:07:55 -0800445
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700446 /**
447 * June 2010: Android 2.2
448 */
Adam Powell216bccf2010-02-01 15:03:17 -0800449 public static final int FROYO = 8;
Andres Moralescb3fd692015-01-14 10:07:55 -0800450
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700451 /**
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800452 * November 2010: Android 2.3
Dianne Hackborn81e92762011-10-09 16:00:21 -0700453 *
454 * <p>Applications targeting this or a later release will get these
455 * new changes in behavior:</p>
456 * <ul>
457 * <li> The application's notification icons will be shown on the new
458 * dark status bar background, so must be visible in this situation.
459 * </ul>
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700460 */
Dianne Hackborn4fa1a222010-10-18 13:10:49 -0700461 public static final int GINGERBREAD = 9;
Andres Moralescb3fd692015-01-14 10:07:55 -0800462
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800463 /**
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700464 * February 2011: Android 2.3.3.
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800465 */
466 public static final int GINGERBREAD_MR1 = 10;
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700467
468 /**
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700469 * February 2011: Android 3.0.
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700470 *
471 * <p>Applications targeting this or a later release will get these
472 * new changes in behavior:</p>
473 * <ul>
Dianne Hackborn3e6d50c2010-08-23 18:30:44 -0700474 * <li> The default theme for applications is now dark holographic:
475 * {@link android.R.style#Theme_Holo}.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700476 * <li> On large screen devices that do not have a physical menu
477 * button, the soft (compatibility) menu is disabled.
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800478 * <li> The activity lifecycle has changed slightly as per
479 * {@link android.app.Activity}.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700480 * <li> An application will crash if it does not call through
481 * to the super implementation of its
482 * {@link android.app.Activity#onPause Activity.onPause()} method.
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800483 * <li> When an application requires a permission to access one of
Dianne Hackborn6c2c5fc2011-01-18 17:02:33 -0800484 * its components (activity, receiver, service, provider), this
485 * permission is no longer enforced when the application wants to
486 * access its own component. This means it can require a permission
487 * on a component that it does not itself hold and still access that
488 * component.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700489 * <li> {@link android.content.Context#getSharedPreferences
490 * Context.getSharedPreferences()} will not automatically reload
491 * the preferences if they have changed on storage, unless
492 * {@link android.content.Context#MODE_MULTI_PROCESS} is used.
493 * <li> {@link android.view.ViewGroup#setMotionEventSplittingEnabled}
494 * will default to true.
495 * <li> {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH}
496 * is enabled by default on windows.
497 * <li> {@link android.widget.PopupWindow#isSplitTouchEnabled()
498 * PopupWindow.isSplitTouchEnabled()} will return true by default.
499 * <li> {@link android.widget.GridView} and {@link android.widget.ListView}
500 * will use {@link android.view.View#setActivated View.setActivated}
501 * for selected items if they do not implement {@link android.widget.Checkable}.
502 * <li> {@link android.widget.Scroller} will be constructed with
503 * "flywheel" behavior enabled by default.
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700504 * </ul>
505 */
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800506 public static final int HONEYCOMB = 11;
Andres Moralescb3fd692015-01-14 10:07:55 -0800507
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700508 /**
Dianne Hackborna8138732011-05-12 15:45:21 -0700509 * May 2011: Android 3.1.
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700510 */
511 public static final int HONEYCOMB_MR1 = 12;
Andres Moralescb3fd692015-01-14 10:07:55 -0800512
Dianne Hackborna8138732011-05-12 15:45:21 -0700513 /**
Dianne Hackborn426431a2011-06-09 11:29:08 -0700514 * June 2011: Android 3.2.
Dianne Hackborne6676352011-06-01 16:51:20 -0700515 *
516 * <p>Update to Honeycomb MR1 to support 7 inch tablets, improve
517 * screen compatibility mode, etc.</p>
518 *
519 * <p>As of this version, applications that don't say whether they
520 * support XLARGE screens will be assumed to do so only if they target
521 * {@link #HONEYCOMB} or later; it had been {@link #GINGERBREAD} or
522 * later. Applications that don't support a screen size at least as
523 * large as the current screen will provide the user with a UI to
524 * switch them in to screen size compatibility mode.</p>
Dianne Hackborne289bff2011-06-13 19:33:22 -0700525 *
526 * <p>This version introduces new screen size resource qualifiers
527 * based on the screen size in dp: see
528 * {@link android.content.res.Configuration#screenWidthDp},
529 * {@link android.content.res.Configuration#screenHeightDp}, and
530 * {@link android.content.res.Configuration#smallestScreenWidthDp}.
531 * Supplying these in &lt;supports-screens&gt; as per
532 * {@link android.content.pm.ApplicationInfo#requiresSmallestWidthDp},
533 * {@link android.content.pm.ApplicationInfo#compatibleWidthLimitDp}, and
534 * {@link android.content.pm.ApplicationInfo#largestWidthLimitDp} is
535 * preferred over the older screen size buckets and for older devices
536 * the appropriate buckets will be inferred from them.</p>
537 *
Dianne Hackborn81e92762011-10-09 16:00:21 -0700538 * <p>Applications targeting this or a later release will get these
539 * new changes in behavior:</p>
540 * <ul>
541 * <li><p>New {@link android.content.pm.PackageManager#FEATURE_SCREEN_PORTRAIT}
Dianne Hackborne289bff2011-06-13 19:33:22 -0700542 * and {@link android.content.pm.PackageManager#FEATURE_SCREEN_LANDSCAPE}
Dianne Hackborn81e92762011-10-09 16:00:21 -0700543 * features were introduced in this release. Applications that target
Dianne Hackborne289bff2011-06-13 19:33:22 -0700544 * previous platform versions are assumed to require both portrait and
545 * landscape support in the device; when targeting Honeycomb MR1 or
546 * greater the application is responsible for specifying any specific
547 * orientation it requires.</p>
Dianne Hackborn81e92762011-10-09 16:00:21 -0700548 * <li><p>{@link android.os.AsyncTask} will use the serial executor
549 * by default when calling {@link android.os.AsyncTask#execute}.</p>
550 * <li><p>{@link android.content.pm.ActivityInfo#configChanges
551 * ActivityInfo.configChanges} will have the
552 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE} and
553 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE}
554 * bits set; these need to be cleared for older applications because
555 * some developers have done absolute comparisons against this value
556 * instead of correctly masking the bits they are interested in.
557 * </ul>
Dianne Hackborna8138732011-05-12 15:45:21 -0700558 */
Dianne Hackborn426431a2011-06-09 11:29:08 -0700559 public static final int HONEYCOMB_MR2 = 13;
Dianne Hackborn3fc982f2011-03-30 16:20:26 -0700560
561 /**
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700562 * October 2011: Android 4.0.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700563 *
564 * <p>Applications targeting this or a later release will get these
565 * new changes in behavior:</p>
566 * <ul>
Dianne Hackborn9d0e37e2011-09-22 12:58:54 -0700567 * <li> For devices without a dedicated menu key, the software compatibility
568 * menu key will not be shown even on phones. By targeting Ice Cream Sandwich
569 * or later, your UI must always have its own menu UI affordance if needed,
570 * on both tablets and phones. The ActionBar will take care of this for you.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700571 * <li> 2d drawing hardware acceleration is now turned on by default.
572 * You can use
573 * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated}
574 * to turn it off if needed, although this is strongly discouraged since
575 * it will result in poor performance on larger screen devices.
Adam Powell6e90a362011-08-14 16:48:32 -0700576 * <li> The default theme for applications is now the "device default" theme:
577 * {@link android.R.style#Theme_DeviceDefault}. This may be the
578 * holo dark theme or a different dark theme defined by the specific device.
579 * The {@link android.R.style#Theme_Holo} family must not be modified
580 * for a device to be considered compatible. Applications that explicitly
581 * request a theme from the Holo family will be guaranteed that these themes
582 * will not change character within the same platform version. Applications
583 * that wish to blend in with the device should use a theme from the
584 * {@link android.R.style#Theme_DeviceDefault} family.
Dianne Hackborn9d0e37e2011-09-22 12:58:54 -0700585 * <li> Managed cursors can now throw an exception if you directly close
586 * the cursor yourself without stopping the management of it; previously failures
587 * would be silently ignored.
588 * <li> The fadingEdge attribute on views will be ignored (fading edges is no
589 * longer a standard part of the UI). A new requiresFadingEdge attribute allows
590 * applications to still force fading edges on for special cases.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700591 * <li> {@link android.content.Context#bindService Context.bindService()}
592 * will not automatically add in {@link android.content.Context#BIND_WAIVE_PRIORITY}.
593 * <li> App Widgets will have standard padding automatically added around
594 * them, rather than relying on the padding being baked into the widget itself.
595 * <li> An exception will be thrown if you try to change the type of a
596 * window after it has been added to the window manager. Previously this
597 * would result in random incorrect behavior.
598 * <li> {@link android.view.animation.AnimationSet} will parse out
599 * the duration, fillBefore, fillAfter, repeatMode, and startOffset
600 * XML attributes that are defined.
601 * <li> {@link android.app.ActionBar#setHomeButtonEnabled
602 * ActionBar.setHomeButtonEnabled()} is false by default.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700603 * </ul>
Dianne Hackborn3fc982f2011-03-30 16:20:26 -0700604 */
Dianne Hackborn0784cfb2011-09-14 13:48:15 -0700605 public static final int ICE_CREAM_SANDWICH = 14;
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700606
607 /**
Dianne Hackborn81e92762011-10-09 16:00:21 -0700608 * December 2011: Android 4.0.3.
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700609 */
610 public static final int ICE_CREAM_SANDWICH_MR1 = 15;
Dianne Hackborn81e92762011-10-09 16:00:21 -0700611
612 /**
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700613 * June 2012: Android 4.1.
Dianne Hackborn65696252012-03-05 18:49:21 -0800614 *
615 * <p>Applications targeting this or a later release will get these
616 * new changes in behavior:</p>
617 * <ul>
Dianne Hackborn636fd522012-06-05 17:38:50 -0700618 * <li> You must explicitly request the {@link android.Manifest.permission#READ_CALL_LOG}
619 * and/or {@link android.Manifest.permission#WRITE_CALL_LOG} permissions;
620 * access to the call log is no longer implicitly provided through
621 * {@link android.Manifest.permission#READ_CONTACTS} and
622 * {@link android.Manifest.permission#WRITE_CONTACTS}.
623 * <li> {@link android.widget.RemoteViews} will throw an exception if
624 * setting an onClick handler for views being generated by a
625 * {@link android.widget.RemoteViewsService} for a collection container;
626 * previously this just resulted in a warning log message.
627 * <li> New {@link android.app.ActionBar} policy for embedded tabs:
628 * embedded tabs are now always stacked in the action bar when in portrait
629 * mode, regardless of the size of the screen.
630 * <li> {@link android.webkit.WebSettings#setAllowFileAccessFromFileURLs(boolean)
631 * WebSettings.setAllowFileAccessFromFileURLs} and
632 * {@link android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs(boolean)
633 * WebSettings.setAllowUniversalAccessFromFileURLs} default to false.
Dianne Hackborn65696252012-03-05 18:49:21 -0800634 * <li> Calls to {@link android.content.pm.PackageManager#setComponentEnabledSetting
635 * PackageManager.setComponentEnabledSetting} will now throw an
636 * IllegalArgumentException if the given component class name does not
637 * exist in the application's manifest.
Dianne Hackborn636fd522012-06-05 17:38:50 -0700638 * <li> {@link android.nfc.NfcAdapter#setNdefPushMessage
639 * NfcAdapter.setNdefPushMessage},
640 * {@link android.nfc.NfcAdapter#setNdefPushMessageCallback
641 * NfcAdapter.setNdefPushMessageCallback} and
642 * {@link android.nfc.NfcAdapter#setOnNdefPushCompleteCallback
643 * NfcAdapter.setOnNdefPushCompleteCallback} will throw
644 * IllegalStateException if called after the Activity has been destroyed.
645 * <li> Accessibility services must require the new
646 * {@link android.Manifest.permission#BIND_ACCESSIBILITY_SERVICE} permission or
647 * they will not be available for use.
648 * <li> {@link android.accessibilityservice.AccessibilityServiceInfo#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
649 * AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS} must be set
650 * for unimportant views to be included in queries.
Dianne Hackborn65696252012-03-05 18:49:21 -0800651 * </ul>
Dianne Hackborn81e92762011-10-09 16:00:21 -0700652 */
Dianne Hackbornfa61f0b2012-05-09 21:49:38 -0700653 public static final int JELLY_BEAN = 16;
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700654
655 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700656 * November 2012: Android 4.2, Moar jelly beans!
Nick Kralevichf097b162012-07-28 12:43:48 -0700657 *
658 * <p>Applications targeting this or a later release will get these
659 * new changes in behavior:</p>
660 * <ul>
661 * <li>Content Providers: The default value of {@code android:exported} is now
662 * {@code false}. See
Nick Kralevich2caec6c2012-08-08 11:33:17 -0700663 * <a href="{@docRoot}guide/topics/manifest/provider-element.html#exported">
Nick Kralevichf097b162012-07-28 12:43:48 -0700664 * the android:exported section</a> in the provider documentation for more details.</li>
Dianne Hackbornfc494742012-09-27 16:15:42 -0700665 * <li>{@link android.view.View#getLayoutDirection() View.getLayoutDirection()}
666 * can return different values than {@link android.view.View#LAYOUT_DIRECTION_LTR}
667 * based on the locale etc.
668 * <li> {@link android.webkit.WebView#addJavascriptInterface(Object, String)
669 * WebView.addJavascriptInterface} requires explicit annotations on methods
670 * for them to be accessible from Javascript.
Nick Kralevichf097b162012-07-28 12:43:48 -0700671 * </ul>
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700672 */
673 public static final int JELLY_BEAN_MR1 = 17;
Nick Kralevicha985c3b2013-01-09 16:03:14 -0800674
675 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700676 * July 2013: Android 4.3, the revenge of the beans.
Nick Kralevicha985c3b2013-01-09 16:03:14 -0800677 */
Dianne Hackbornd2eeed62013-04-22 13:04:28 -0700678 public static final int JELLY_BEAN_MR2 = 18;
Dianne Hackborn5d2bfa12013-03-05 10:28:34 -0800679
680 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700681 * October 2013: Android 4.4, KitKat, another tasty treat.
Dianne Hackborn221ea892013-08-04 16:50:16 -0700682 *
683 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700684 * new changes in behavior. For more information about this release, see the
685 * <a href="/about/versions/kitkat/">Android KitKat overview</a>.</p>
Dianne Hackborn221ea892013-08-04 16:50:16 -0700686 * <ul>
Mark Dolinerd0646dc2014-08-27 16:04:02 -0700687 * <li> The default result of
688 * {@link android.preference.PreferenceActivity#isValidFragment(String)
Dianne Hackborn6bc37892013-10-03 11:05:14 -0700689 * PreferenceActivity.isValueFragment} becomes false instead of true.</li>
690 * <li> In {@link android.webkit.WebView}, apps targeting earlier versions will have
691 * JS URLs evaluated directly and any result of the evaluation will not replace
692 * the current page content. Apps targetting KITKAT or later that load a JS URL will
693 * have the result of that URL replace the content of the current page</li>
694 * <li> {@link android.app.AlarmManager#set AlarmManager.set} becomes interpreted as
695 * an inexact value, to give the system more flexibility in scheduling alarms.</li>
696 * <li> {@link android.content.Context#getSharedPreferences(String, int)
697 * Context.getSharedPreferences} no longer allows a null name.</li>
698 * <li> {@link android.widget.RelativeLayout} changes to compute wrapped content
699 * margins correctly.</li>
700 * <li> {@link android.app.ActionBar}'s window content overlay is allowed to be
701 * drawn.</li>
Jeff Sharkey3ec2f602013-10-29 12:21:23 -0700702 * <li>The {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
703 * permission is now always enforced.</li>
704 * <li>Access to package-specific external storage directories belonging
705 * to the calling app no longer requires the
706 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} or
707 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
708 * permissions.</li>
Dianne Hackborn221ea892013-08-04 16:50:16 -0700709 * </ul>
Dianne Hackborn5d2bfa12013-03-05 10:28:34 -0800710 */
Dianne Hackborn6bc37892013-10-03 11:05:14 -0700711 public static final int KITKAT = 19;
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700712
713 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700714 * June 2014: Android 4.4W. KitKat for watches, snacks on the run.
Justin Koh78b94de2014-05-13 15:48:42 -0700715 *
716 * <p>Applications targeting this or a later release will get these
717 * new changes in behavior:</p>
718 * <ul>
719 * <li>{@link android.app.AlertDialog} might not have a default background if the theme does
720 * not specify one.</li>
721 * </ul>
Jeff Brown1c3f3322014-04-16 13:15:22 -0700722 */
Justin Koh78b94de2014-05-13 15:48:42 -0700723 public static final int KITKAT_WATCH = 20;
Jeff Brown047f3c72014-04-16 14:18:49 -0700724
725 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700726 * Temporary until we completely switch to {@link #LOLLIPOP}.
Dianne Hackbornd3511d42014-10-16 17:48:30 -0700727 * @hide
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700728 */
729 public static final int L = 21;
730
731 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700732 * November 2014: Lollipop. A flat one with beautiful shadows. But still tasty.
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700733 *
734 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700735 * new changes in behavior. For more information about this release, see the
736 * <a href="/about/versions/lollipop/">Android Lollipop overview</a>.</p>
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700737 * <ul>
738 * <li> {@link android.content.Context#bindService Context.bindService} now
Michael Wright5b5def52014-04-11 13:37:50 -0700739 * requires an explicit Intent, and will throw an exception if given an implicit
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700740 * Intent.</li>
Dianne Hackbornd3511d42014-10-16 17:48:30 -0700741 * <li> {@link android.app.Notification.Builder Notification.Builder} will
742 * not have the colors of their various notification elements adjusted to better
743 * match the new material design look.</li>
744 * <li> {@link android.os.Message} will validate that a message is not currently
745 * in use when it is recycled.</li>
746 * <li> Hardware accelerated drawing in windows will be enabled automatically
747 * in most places.</li>
748 * <li> {@link android.widget.Spinner} throws an exception if attaching an
749 * adapter with more than one item type.</li>
750 * <li> If the app is a launcher, the launcher will be available to the user
751 * even when they are using corporate profiles (which requires that the app
752 * use {@link android.content.pm.LauncherApps} to correctly populate its
753 * apps UI).</li>
754 * <li> Calling {@link android.app.Service#stopForeground Service.stopForeground}
755 * with removeNotification false will modify the still posted notification so that
756 * it is no longer forced to be ongoing.</li>
757 * <li> A {@link android.service.dreams.DreamService} must require the
758 * {@link android.Manifest.permission#BIND_DREAM_SERVICE} permission to be usable.</li>
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700759 * </ul>
760 */
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700761 public static final int LOLLIPOP = 21;
Dianne Hackborn3b696882014-10-16 18:14:12 -0700762
763 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700764 * March 2015: Lollipop with an extra sugar coating on the outside!
Andrew Solovaya861ff72018-08-06 13:43:30 -0700765 * For more information about this release, see the
766 * <a href="/about/versions/android-5.1">Android 5.1 APIs</a>.
Dianne Hackborn3b696882014-10-16 18:14:12 -0700767 */
768 public static final int LOLLIPOP_MR1 = 22;
Dianne Hackborn8bd95f12015-01-27 13:18:24 -0800769
770 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700771 * M is for Marshmallow!
772 *
773 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700774 * new changes in behavior. For more information about this release, see the
775 * <a href="/about/versions/marshmallow/">Android 6.0 Marshmallow overview</a>.</p>
Dianne Hackborne7a34352015-09-17 14:50:47 -0700776 * <ul>
777 * <li> Runtime permissions. Dangerous permissions are no longer granted at
778 * install time, but must be requested by the application at runtime through
779 * {@link android.app.Activity#requestPermissions}.</li>
780 * <li> Bluetooth and Wi-Fi scanning now requires holding the location permission.</li>
781 * <li> {@link android.app.AlarmManager#setTimeZone AlarmManager.setTimeZone} will fail if
782 * the given timezone is non-Olson.</li>
783 * <li> Activity transitions will only return shared
784 * elements mapped in the returned view hierarchy back to the calling activity.</li>
785 * <li> {@link android.view.View} allows a number of behaviors that may break
786 * existing apps: Canvas throws an exception if restore() is called too many times,
787 * widgets may return a hint size when returning UNSPECIFIED measure specs, and it
788 * will respect the attributes {@link android.R.attr#foreground},
789 * {@link android.R.attr#foregroundGravity}, {@link android.R.attr#foregroundTint}, and
790 * {@link android.R.attr#foregroundTintMode}.</li>
791 * <li> {@link android.view.MotionEvent#getButtonState MotionEvent.getButtonState}
792 * will no longer report {@link android.view.MotionEvent#BUTTON_PRIMARY}
793 * and {@link android.view.MotionEvent#BUTTON_SECONDARY} as synonyms for
794 * {@link android.view.MotionEvent#BUTTON_STYLUS_PRIMARY} and
795 * {@link android.view.MotionEvent#BUTTON_STYLUS_SECONDARY}.</li>
796 * <li> {@link android.widget.ScrollView} now respects the layout param margins
797 * when measuring.</li>
798 * </ul>
Dianne Hackborn8bd95f12015-01-27 13:18:24 -0800799 */
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700800 public static final int M = 23;
Wale Ogunwale79113102015-10-05 16:52:53 -0700801
802 /**
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700803 * N is for Nougat.
804 *
805 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700806 * new changes in behavior. For more information about this release, see
807 * the <a href="/about/versions/nougat/">Android Nougat overview</a>.</p>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700808 * <ul>
809 * <li> {@link android.app.DownloadManager.Request#setAllowedNetworkTypes
810 * DownloadManager.Request.setAllowedNetworkTypes}
811 * will disable "allow over metered" when specifying only
Dianne Hackborn5f1649e2016-08-09 18:00:31 -0700812 * {@link android.app.DownloadManager.Request#NETWORK_WIFI}.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700813 * <li> {@link android.app.DownloadManager} no longer allows access to raw
Dianne Hackborn5f1649e2016-08-09 18:00:31 -0700814 * file paths.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700815 * <li> {@link android.app.Notification.Builder#setShowWhen
816 * Notification.Builder.setShowWhen}
817 * must be called explicitly to have the time shown, and various other changes in
818 * {@link android.app.Notification.Builder Notification.Builder} to how notifications
819 * are shown.</li>
820 * <li>{@link android.content.Context#MODE_WORLD_READABLE} and
821 * {@link android.content.Context#MODE_WORLD_WRITEABLE} are no longer supported.</li>
822 * <li>{@link android.os.FileUriExposedException} will be thrown to applications.</li>
823 * <li>Applications will see global drag and drops as per
824 * {@link android.view.View#DRAG_FLAG_GLOBAL}.</li>
825 * <li>{@link android.webkit.WebView#evaluateJavascript WebView.evaluateJavascript}
826 * will not persist state from an empty WebView.</li>
827 * <li>{@link android.animation.AnimatorSet} will not ignore calls to end() before
828 * start().</li>
829 * <li>{@link android.app.AlarmManager#cancel(android.app.PendingIntent)
830 * AlarmManager.cancel} will throw a NullPointerException if given a null operation.</li>
831 * <li>{@link android.app.FragmentManager} will ensure fragments have been created
832 * before being placed on the back stack.</li>
833 * <li>{@link android.app.FragmentManager} restores fragments in
834 * {@link android.app.Fragment#onCreate Fragment.onCreate} rather than after the
835 * method returns.</li>
836 * <li>{@link android.R.attr#resizeableActivity} defaults to true.</li>
837 * <li>{@link android.graphics.drawable.AnimatedVectorDrawable} throws exceptions when
838 * opening invalid VectorDrawable animations.</li>
839 * <li>{@link android.view.ViewGroup.MarginLayoutParams} will no longer be dropped
840 * when converting between some types of layout params (such as
841 * {@link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams} to
842 * {@link android.widget.RelativeLayout.LayoutParams RelativeLayout.LayoutParams}).</li>
843 * <li>Your application processes will not be killed when the device density changes.</li>
Vadim Tryshev06b9b602016-09-23 15:32:33 -0700844 * <li>Drag and drop. After a view receives the
845 * {@link android.view.DragEvent#ACTION_DRAG_ENTERED} event, when the drag shadow moves into
846 * a descendant view that can accept the data, the view receives the
847 * {@link android.view.DragEvent#ACTION_DRAG_EXITED} event and won’t receive
848 * {@link android.view.DragEvent#ACTION_DRAG_LOCATION} and
849 * {@link android.view.DragEvent#ACTION_DROP} events while the drag shadow is within that
850 * descendant view, even if the descendant view returns <code>false</code> from its handler
851 * for these events.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700852 * </ul>
Wale Ogunwale79113102015-10-05 16:52:53 -0700853 */
Adam Powell43ec62a2016-05-25 16:36:41 -0700854 public static final int N = 24;
Michael Wright863ae3e2016-06-29 15:47:16 +0100855
856 /**
Andrew Solovaya861ff72018-08-06 13:43:30 -0700857 * N MR1: Nougat++. For more information about this release, see
858 * <a href="/about/versions/nougat/android-7.1">Android 7.1 for
859 * Developers</a>.
Michael Wright863ae3e2016-06-29 15:47:16 +0100860 */
861 public static final int N_MR1 = 25;
Makoto Onuki864f4bd2016-11-02 11:11:32 -0700862
863 /**
864 * O.
Evan Rosky534de292017-06-23 09:45:38 -0700865 *
866 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700867 * new changes in behavior. For more information about this release, see
868 * the <a href="/about/versions/oreo/">Android Oreo overview</a>.</p>
Evan Rosky534de292017-06-23 09:45:38 -0700869 * <ul>
Dianne Hackborna47d0452017-11-21 15:04:57 -0800870 * <li><a href="{@docRoot}about/versions/oreo/background.html">Background execution limits</a>
871 * are applied to the application.</li>
872 * <li>The behavior of AccountManager's
873 * {@link android.accounts.AccountManager#getAccountsByType},
874 * {@link android.accounts.AccountManager#getAccountsByTypeAndFeatures}, and
875 * {@link android.accounts.AccountManager#hasFeatures} has changed as documented there.</li>
876 * <li>{@link android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE_PRE_26}
877 * is now returned as
878 * {@link android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.</li>
879 * <li>The {@link android.app.NotificationManager} now requires the use of notification
880 * channels.</li>
881 * <li>Changes to the strict mode that are set in
882 * {@link Application#onCreate Application.onCreate} will no longer be clobbered after
883 * that function returns.</li>
884 * <li>A shared library apk with native code will have that native code included in
885 * the library path of its clients.</li>
886 * <li>{@link android.content.Context#getSharedPreferences Context.getSharedPreferences}
887 * in credential encrypted storage will throw an exception before the user is unlocked.</li>
888 * <li>Attempting to retrieve a {@link Context#FINGERPRINT_SERVICE} on a device that
889 * does not support that feature will now throw a runtime exception.</li>
890 * <li>{@link android.app.Fragment} will stop any active view animations when
891 * the fragment is stopped.</li>
892 * <li>Some compatibility code in Resources that attempts to use the default Theme
893 * the app may be using will be turned off, requiring the app to explicitly request
894 * resources with the right theme.</li>
895 * <li>{@link android.content.ContentResolver#notifyChange ContentResolver.notifyChange} and
896 * {@link android.content.ContentResolver#registerContentObserver
897 * ContentResolver.registerContentObserver}
898 * will throw a SecurityException if the caller does not have permission to access
899 * the provider (or the provider doesn't exit); otherwise the call will be silently
900 * ignored.</li>
901 * <li>{@link android.hardware.camera2.CameraDevice#createCaptureRequest
902 * CameraDevice.createCaptureRequest} will enable
903 * {@link android.hardware.camera2.CaptureRequest#CONTROL_ENABLE_ZSL} by default for
904 * still image capture.</li>
905 * <li>WallpaperManager's {@link android.app.WallpaperManager#getWallpaperFile},
906 * {@link android.app.WallpaperManager#getDrawable},
907 * {@link android.app.WallpaperManager#getFastDrawable},
908 * {@link android.app.WallpaperManager#peekDrawable}, and
909 * {@link android.app.WallpaperManager#peekFastDrawable} will throw an exception
910 * if you can not access the wallpaper.</li>
911 * <li>The behavior of
912 * {@link android.hardware.usb.UsbDeviceConnection#requestWait UsbDeviceConnection.requestWait}
913 * is modified as per the documentation there.</li>
914 * <li>{@link StrictMode.VmPolicy.Builder#detectAll StrictMode.VmPolicy.Builder.detectAll}
915 * will also enable {@link StrictMode.VmPolicy.Builder#detectContentUriWithoutPermission}
916 * and {@link StrictMode.VmPolicy.Builder#detectUntaggedSockets}.</li>
917 * <li>{@link StrictMode.ThreadPolicy.Builder#detectAll StrictMode.ThreadPolicy.Builder.detectAll}
918 * will also enable {@link StrictMode.ThreadPolicy.Builder#detectUnbufferedIo}.</li>
919 * <li>{@link android.provider.DocumentsContract}'s various methods will throw failure
920 * exceptions back to the caller instead of returning null.
921 * <li>{@link View#hasFocusable View.hasFocusable} now includes auto-focusable views.</li>
922 * <li>{@link android.view.SurfaceView} will no longer always change the underlying
923 * Surface object when something about it changes; apps need to look at the current
924 * state of the object to determine which things they are interested in have changed.</li>
925 * <li>{@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} must be
926 * used for overlay windows, other system overlay window types are not allowed.</li>
927 * <li>{@link android.view.ViewTreeObserver#addOnDrawListener
928 * ViewTreeObserver.addOnDrawListener} will throw an exception if called from within
929 * onDraw.</li>
930 * <li>{@link android.graphics.Canvas#setBitmap Canvas.setBitmap} will no longer preserve
931 * the current matrix and clip stack of the canvas.</li>
932 * <li>{@link android.widget.ListPopupWindow#setHeight ListPopupWindow.setHeight}
933 * will throw an exception if a negative height is supplied.</li>
934 * <li>{@link android.widget.TextView} will use internationalized input for numbers,
935 * dates, and times.</li>
936 * <li>{@link android.widget.Toast} must be used for showing toast windows; the toast
937 * window type can not be directly used.</li>
938 * <li>{@link android.net.wifi.WifiManager#getConnectionInfo WifiManager.getConnectionInfo}
939 * requires that the caller hold the location permission to return BSSID/SSID</li>
940 * <li>{@link android.net.wifi.p2p.WifiP2pManager#requestPeers WifiP2pManager.requestPeers}
941 * requires the caller hold the location permission.</li>
942 * <li>{@link android.R.attr#maxAspectRatio} defaults to 0, meaning there is no restriction
943 * on the app's maximum aspect ratio (so it can be stretched to fill larger screens).</li>
Evan Rosky534de292017-06-23 09:45:38 -0700944 * <li>{@link android.R.attr#focusable} defaults to a new state ({@code auto}) where it will
945 * inherit the value of {@link android.R.attr#clickable} unless explicitly overridden.</li>
946 * <li>A default theme-appropriate focus-state highlight will be supplied to all Views
947 * which don't provide a focus-state drawable themselves. This can be disabled by setting
948 * {@link android.R.attr#defaultFocusHighlightEnabled} to false.</li>
949 * </ul>
Makoto Onuki864f4bd2016-11-02 11:11:32 -0700950 */
Ian Pedowitz967869d2017-05-04 00:10:04 +0000951 public static final int O = 26;
Jeff Sharkey7beabc22017-07-19 13:57:35 -0600952
953 /**
954 * O MR1.
Dianne Hackborna47d0452017-11-21 15:04:57 -0800955 *
956 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700957 * new changes in behavior. For more information about this release, see
958 * <a href="/about/versions/oreo/android-8.1">Android 8.1 features and
959 * APIs</a>.</p>
Dianne Hackborna47d0452017-11-21 15:04:57 -0800960 * <ul>
961 * <li>Apps exporting and linking to apk shared libraries must explicitly
962 * enumerate all signing certificates in a consistent order.</li>
963 * <li>{@link android.R.attr#screenOrientation} can not be used to request a fixed
964 * orientation if the associated activity is not fullscreen and opaque.</li>
965 * </ul>
Andrew Solovaya861ff72018-08-06 13:43:30 -0700966 *
Jeff Sharkey7beabc22017-07-19 13:57:35 -0600967 */
Michael Wrighteec01ac2017-08-23 13:49:14 -0700968 public static final int O_MR1 = 27;
Makoto Onuki7bd7a622017-08-31 08:35:59 -0700969
970 /**
971 * P.
Dianne Hackborndd027b32018-01-19 17:44:46 -0800972 *
973 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700974 * new changes in behavior. For more information about this release, see the
975 * <a href="/about/versions/pie/">Android 9 Pie overview</a>.</p>
Dianne Hackborndd027b32018-01-19 17:44:46 -0800976 * <ul>
977 * <li>{@link android.app.Service#startForeground Service.startForeground} requires
978 * that apps hold the permission
979 * {@link android.Manifest.permission#FOREGROUND_SERVICE}.</li>
Chet Haasecb848882018-03-21 14:09:44 -0700980 * <li>{@link android.widget.LinearLayout} will always remeasure weighted children,
981 * even if there is no excess space.</li>
Dianne Hackborndd027b32018-01-19 17:44:46 -0800982 * </ul>
Andrew Solovaya861ff72018-08-06 13:43:30 -0700983 *
Makoto Onuki7bd7a622017-08-31 08:35:59 -0700984 */
Wale Ogunwale3da5f3b2018-04-11 15:12:31 -0700985 public static final int P = 28;
Jeff Sharkey8929b522018-05-15 13:34:52 -0600986
987 /**
988 * Q.
989 * <p>
990 * <em>Why? Why, to give you a taste of your future, a preview of things
991 * to come. Con permiso, Capitan. The hall is rented, the orchestra
992 * engaged. It's now time to see if you can dance.</em>
993 */
Ian Pedowitz1912a572019-05-12 19:44:42 +0000994 public static final int Q = 29;
Dianne Hackborn851a5412009-05-08 12:06:44 -0700995 }
Andres Moralescb3fd692015-01-14 10:07:55 -0800996
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800997 /** The type of build, like "user" or "eng". */
998 public static final String TYPE = getString("ro.build.type");
999
1000 /** Comma-separated tags describing the build, like "unsigned,debug". */
1001 public static final String TAGS = getString("ro.build.tags");
1002
1003 /** A string that uniquely identifies this build. Do not attempt to parse this value. */
Jeff Sharkey55687722014-04-09 18:07:19 -07001004 public static final String FINGERPRINT = deriveFingerprint();
1005
1006 /**
1007 * Some devices split the fingerprint components between multiple
1008 * partitions, so we might derive the fingerprint at runtime.
1009 */
1010 private static String deriveFingerprint() {
1011 String finger = SystemProperties.get("ro.build.fingerprint");
1012 if (TextUtils.isEmpty(finger)) {
1013 finger = getString("ro.product.brand") + '/' +
1014 getString("ro.product.name") + '/' +
1015 getString("ro.product.device") + ':' +
1016 getString("ro.build.version.release") + '/' +
1017 getString("ro.build.id") + '/' +
1018 getString("ro.build.version.incremental") + ':' +
1019 getString("ro.build.type") + '/' +
1020 getString("ro.build.tags");
1021 }
1022 return finger;
1023 }
1024
1025 /**
1026 * Ensure that raw fingerprint system property is defined. If it was derived
1027 * dynamically by {@link #deriveFingerprint()} this is where we push the
1028 * derived value into the property service.
1029 *
1030 * @hide
1031 */
1032 public static void ensureFingerprintProperty() {
1033 if (TextUtils.isEmpty(SystemProperties.get("ro.build.fingerprint"))) {
Jeff Sharkeybdd44912014-04-11 16:30:14 -07001034 try {
1035 SystemProperties.set("ro.build.fingerprint", FINGERPRINT);
1036 } catch (IllegalArgumentException e) {
1037 Slog.e(TAG, "Failed to set fingerprint property", e);
1038 }
Jeff Sharkey55687722014-04-09 18:07:19 -07001039 }
1040 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001042 /**
Michael Schwartz18511182017-05-15 11:40:40 -07001043 * True if Treble is enabled and required for this device.
1044 *
1045 * @hide
1046 */
1047 public static final boolean IS_TREBLE_ENABLED =
1048 SystemProperties.getBoolean("ro.treble.enabled", false);
1049
1050 /**
1051 * Verifies the current flash of the device is consistent with what
Andres Moralesfd282ed2015-02-06 15:07:59 -08001052 * was expected at build time.
Michael Schwartz18511182017-05-15 11:40:40 -07001053 *
1054 * Treble devices will verify the Vendor Interface (VINTF). A device
1055 * launched without Treble:
1056 *
Andres Moralesfd282ed2015-02-06 15:07:59 -08001057 * 1) Checks that device fingerprint is defined and that it matches across
1058 * various partitions.
1059 * 2) Verifies radio and bootloader partitions are those expected in the build.
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001060 *
1061 * @hide
1062 */
Andres Moralesfd282ed2015-02-06 15:07:59 -08001063 public static boolean isBuildConsistent() {
Xiaohui Chen2102dcb2015-10-02 16:45:55 -07001064 // Don't care on eng builds. Incremental build may trigger false negative.
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001065 if (IS_ENG) return true;
Xiaohui Chen2102dcb2015-10-02 16:45:55 -07001066
Michael Schwartz18511182017-05-15 11:40:40 -07001067 if (IS_TREBLE_ENABLED) {
Bowgo Tsaib1de4312017-11-17 17:18:50 +08001068 // If we can run this code, the device should already pass AVB.
1069 // So, we don't need to check AVB here.
1070 int result = VintfObject.verifyWithoutAvb();
Michael Schwartz18511182017-05-15 11:40:40 -07001071
1072 if (result != 0) {
1073 Slog.e(TAG, "Vendor interface is incompatible, error="
1074 + String.valueOf(result));
1075 }
1076
1077 return result == 0;
1078 }
1079
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001080 final String system = SystemProperties.get("ro.build.fingerprint");
1081 final String vendor = SystemProperties.get("ro.vendor.build.fingerprint");
Andres Moralescb3fd692015-01-14 10:07:55 -08001082 final String bootimage = SystemProperties.get("ro.bootimage.build.fingerprint");
Andres Moralesfd282ed2015-02-06 15:07:59 -08001083 final String requiredBootloader = SystemProperties.get("ro.build.expect.bootloader");
1084 final String currentBootloader = SystemProperties.get("ro.bootloader");
1085 final String requiredRadio = SystemProperties.get("ro.build.expect.baseband");
1086 final String currentRadio = SystemProperties.get("gsm.version.baseband");
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001087
1088 if (TextUtils.isEmpty(system)) {
1089 Slog.e(TAG, "Required ro.build.fingerprint is empty!");
1090 return false;
1091 }
1092
1093 if (!TextUtils.isEmpty(vendor)) {
1094 if (!Objects.equals(system, vendor)) {
1095 Slog.e(TAG, "Mismatched fingerprints; system reported " + system
1096 + " but vendor reported " + vendor);
1097 return false;
1098 }
1099 }
1100
Andres Moralesc97b92e2015-06-01 17:50:43 +00001101 /* TODO: Figure out issue with checks failing
Andres Moralescb3fd692015-01-14 10:07:55 -08001102 if (!TextUtils.isEmpty(bootimage)) {
Andres Morales7de24ce2015-01-23 12:45:54 -08001103 if (!Objects.equals(system, bootimage)) {
1104 Slog.e(TAG, "Mismatched fingerprints; system reported " + system
Andres Moralescb3fd692015-01-14 10:07:55 -08001105 + " but bootimage reported " + bootimage);
1106 return false;
1107 }
1108 }
1109
Andres Moralesfd282ed2015-02-06 15:07:59 -08001110 if (!TextUtils.isEmpty(requiredBootloader)) {
1111 if (!Objects.equals(currentBootloader, requiredBootloader)) {
1112 Slog.e(TAG, "Mismatched bootloader version: build requires " + requiredBootloader
1113 + " but runtime reports " + currentBootloader);
1114 return false;
1115 }
1116 }
1117
1118 if (!TextUtils.isEmpty(requiredRadio)) {
1119 if (!Objects.equals(currentRadio, requiredRadio)) {
1120 Slog.e(TAG, "Mismatched radio version: build requires " + requiredRadio
1121 + " but runtime reports " + currentRadio);
1122 return false;
1123 }
1124 }
Daniel Rosenberg159c2052015-02-20 13:10:26 -08001125 */
Andres Moralesfd282ed2015-02-06 15:07:59 -08001126
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001127 return true;
1128 }
1129
Anton Hansson91b54f12018-09-24 18:24:19 +01001130 /** Build information for a particular device partition. */
1131 public static class Partition {
1132 /** The name identifying the system partition. */
1133 public static final String PARTITION_NAME_SYSTEM = "system";
1134
Anton Hansson2579d1a2019-02-06 12:14:12 +00001135 private final String mName;
1136 private final String mFingerprint;
1137 private final long mTimeMs;
Anton Hansson91b54f12018-09-24 18:24:19 +01001138
1139 private Partition(String name, String fingerprint, long timeMs) {
1140 mName = name;
1141 mFingerprint = fingerprint;
1142 mTimeMs = timeMs;
1143 }
1144
1145 /** The name of this partition, e.g. "system", or "vendor" */
Anton Hansson81f76a02018-10-04 18:40:22 +01001146 @NonNull
Anton Hansson91b54f12018-09-24 18:24:19 +01001147 public String getName() {
1148 return mName;
1149 }
1150
1151 /** The build fingerprint of this partition, see {@link Build#FINGERPRINT}. */
Anton Hansson81f76a02018-10-04 18:40:22 +01001152 @NonNull
Anton Hansson91b54f12018-09-24 18:24:19 +01001153 public String getFingerprint() {
1154 return mFingerprint;
1155 }
1156
1157 /** The time (ms since epoch), at which this partition was built, see {@link Build#TIME}. */
Anton Hansson81f76a02018-10-04 18:40:22 +01001158 public long getBuildTimeMillis() {
Anton Hansson91b54f12018-09-24 18:24:19 +01001159 return mTimeMs;
1160 }
Anton Hansson81f76a02018-10-04 18:40:22 +01001161
1162 @Override
1163 public boolean equals(Object o) {
1164 if (!(o instanceof Partition)) {
1165 return false;
1166 }
1167 Partition op = (Partition) o;
1168 return mName.equals(op.mName)
1169 && mFingerprint.equals(op.mFingerprint)
1170 && mTimeMs == op.mTimeMs;
1171 }
1172
1173 @Override
1174 public int hashCode() {
1175 return Objects.hash(mName, mFingerprint, mTimeMs);
1176 }
Anton Hansson91b54f12018-09-24 18:24:19 +01001177 }
1178
1179 /**
1180 * Get build information about partitions that have a separate fingerprint defined.
1181 *
1182 * The list includes partitions that are suitable candidates for over-the-air updates. This is
1183 * not an exhaustive list of partitions on the device.
1184 */
Anton Hansson81f76a02018-10-04 18:40:22 +01001185 @NonNull
1186 public static List<Partition> getFingerprintedPartitions() {
Anton Hansson91b54f12018-09-24 18:24:19 +01001187 ArrayList<Partition> partitions = new ArrayList();
1188
1189 String[] names = new String[] {
Jeongik Chaf6629832019-07-04 21:12:06 +09001190 "bootimage", "odm", "product", "system_ext", Partition.PARTITION_NAME_SYSTEM,
Anton Hansson91b54f12018-09-24 18:24:19 +01001191 "vendor"
1192 };
1193 for (String name : names) {
1194 String fingerprint = SystemProperties.get("ro." + name + ".build.fingerprint");
1195 if (TextUtils.isEmpty(fingerprint)) {
1196 continue;
1197 }
1198 long time = getLong("ro." + name + ".build.date.utc") * 1000;
1199 partitions.add(new Partition(name, fingerprint, time));
1200 }
1201
1202 return partitions;
1203 }
1204
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001205 // The following properties only make sense for internal engineering builds.
Anton Hansson91b54f12018-09-24 18:24:19 +01001206
1207 /** 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 -08001208 public static final long TIME = getLong("ro.build.date.utc") * 1000;
1209 public static final String USER = getString("ro.build.user");
1210 public static final String HOST = getString("ro.build.host");
1211
Doug Zongkerad2171a2011-06-14 11:07:24 -07001212 /**
Jeff Brown89101cd92011-10-27 21:24:54 -07001213 * Returns true if we are running a debug build such as "user-debug" or "eng".
1214 * @hide
1215 */
Andrei Onea24ec3212019-03-15 17:35:05 +00001216 @UnsupportedAppUsage
Jeff Brown89101cd92011-10-27 21:24:54 -07001217 public static final boolean IS_DEBUGGABLE =
1218 SystemProperties.getInt("ro.debuggable", 0) == 1;
1219
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001220 /** {@hide} */
Jeff Sharkeycdee83a2017-01-26 15:29:16 -07001221 public static final boolean IS_ENG = "eng".equals(TYPE);
1222 /** {@hide} */
1223 public static final boolean IS_USERDEBUG = "userdebug".equals(TYPE);
1224 /** {@hide} */
1225 public static final boolean IS_USER = "user".equals(TYPE);
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001226
Jeff Brown89101cd92011-10-27 21:24:54 -07001227 /**
Xiaohui Chen387c65f2017-01-17 14:29:03 -08001228 * Whether this build is running inside a container.
1229 *
1230 * We should try to avoid checking this flag if possible to minimize
1231 * unnecessarily diverging from non-container Android behavior.
1232 * Checking this flag is acceptable when low-level resources being
1233 * different, e.g. the availability of certain capabilities, access to
1234 * system resources being restricted, and the fact that the host OS might
1235 * handle some features for us.
1236 * For higher-level behavior differences, other checks should be preferred.
1237 * @hide
1238 */
1239 public static final boolean IS_CONTAINER =
1240 SystemProperties.getBoolean("ro.boot.container", false);
1241
1242 /**
Svet Ganov9c165d72015-12-01 19:52:26 -08001243 * Specifies whether the permissions needed by a legacy app should be
1244 * reviewed before any of its components can run. A legacy app is one
1245 * with targetSdkVersion < 23, i.e apps using the old permission model.
1246 * If review is not required, permissions are reviewed before the app
1247 * is installed.
1248 *
1249 * @hide
Svet Ganov77df6f32016-08-17 11:46:34 -07001250 * @removed
Svet Ganov9c165d72015-12-01 19:52:26 -08001251 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08001252 @SystemApi
Philip P. Moltmann6c644e62018-07-18 15:41:24 -07001253 public static final boolean PERMISSIONS_REVIEW_REQUIRED = true;
Svet Ganov9c165d72015-12-01 19:52:26 -08001254
1255 /**
Doug Zongkerad2171a2011-06-14 11:07:24 -07001256 * Returns the version string for the radio firmware. May return
1257 * null (if, for instance, the radio is not currently on).
1258 */
1259 public static String getRadioVersion() {
Seongho Kim73273e02018-11-16 13:44:48 +09001260 String propVal = SystemProperties.get(TelephonyProperties.PROPERTY_BASEBAND_VERSION);
1261 return TextUtils.isEmpty(propVal) ? null : propVal;
Doug Zongkerad2171a2011-06-14 11:07:24 -07001262 }
1263
Andrei Onea24ec3212019-03-15 17:35:05 +00001264 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001265 private static String getString(String property) {
1266 return SystemProperties.get(property, UNKNOWN);
1267 }
1268
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +01001269 private static String[] getStringList(String property, String separator) {
1270 String value = SystemProperties.get(property);
1271 if (value.isEmpty()) {
1272 return new String[0];
1273 } else {
1274 return value.split(separator);
1275 }
1276 }
1277
Andrei Onea24ec3212019-03-15 17:35:05 +00001278 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001279 private static long getLong(String property) {
1280 try {
1281 return Long.parseLong(SystemProperties.get(property));
1282 } catch (NumberFormatException e) {
1283 return -1;
1284 }
1285 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001286}