1 /* 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 17 package android.os; 18 19 import android.Manifest; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.RequiresPermission; 23 import android.annotation.SuppressAutoDoc; 24 import android.annotation.SystemApi; 25 import android.annotation.TestApi; 26 import android.app.ActivityThread; 27 import android.app.Application; 28 import android.compat.annotation.UnsupportedAppUsage; 29 import android.content.Context; 30 import android.sysprop.DeviceProperties; 31 import android.sysprop.SocProperties; 32 import android.sysprop.TelephonyProperties; 33 import android.text.TextUtils; 34 import android.util.Slog; 35 import android.view.View; 36 37 import dalvik.system.VMRuntime; 38 39 import java.util.ArrayList; 40 import java.util.List; 41 import java.util.Objects; 42 import java.util.stream.Collectors; 43 44 /** 45 * Information about the current build, extracted from system properties. 46 */ 47 public class Build { 48 private static final String TAG = "Build"; 49 50 /** Value used for when a build property is unknown. */ 51 public static final String UNKNOWN = "unknown"; 52 53 /** Either a changelist number, or a label like "M4-rc20". */ 54 public static final String ID = getString("ro.build.id"); 55 56 /** A build ID string meant for displaying to the user */ 57 public static final String DISPLAY = getString("ro.build.display.id"); 58 59 /** The name of the overall product. */ 60 public static final String PRODUCT = getString("ro.product.name"); 61 62 /** The name of the industrial design. */ 63 public static final String DEVICE = getString("ro.product.device"); 64 65 /** The name of the underlying board, like "goldfish". */ 66 public static final String BOARD = getString("ro.product.board"); 67 68 /** 69 * The name of the instruction set (CPU type + ABI convention) of native code. 70 * 71 * @deprecated Use {@link #SUPPORTED_ABIS} instead. 72 */ 73 @Deprecated 74 public static final String CPU_ABI; 75 76 /** 77 * The name of the second instruction set (CPU type + ABI convention) of native code. 78 * 79 * @deprecated Use {@link #SUPPORTED_ABIS} instead. 80 */ 81 @Deprecated 82 public static final String CPU_ABI2; 83 84 /** The manufacturer of the product/hardware. */ 85 public static final String MANUFACTURER = getString("ro.product.manufacturer"); 86 87 /** The consumer-visible brand with which the product/hardware will be associated, if any. */ 88 public static final String BRAND = getString("ro.product.brand"); 89 90 /** The end-user-visible name for the end product. */ 91 public static final String MODEL = getString("ro.product.model"); 92 93 /** The manufacturer of the device's primary system-on-chip. */ 94 @NonNull 95 public static final String SOC_MANUFACTURER = SocProperties.soc_manufacturer().orElse(UNKNOWN); 96 97 /** The model name of the device's primary system-on-chip. */ 98 @NonNull 99 public static final String SOC_MODEL = SocProperties.soc_model().orElse(UNKNOWN); 100 101 /** The system bootloader version number. */ 102 public static final String BOOTLOADER = getString("ro.bootloader"); 103 104 /** 105 * The radio firmware version number. 106 * 107 * @deprecated The radio firmware version is frequently not 108 * available when this class is initialized, leading to a blank or 109 * "unknown" value for this string. Use 110 * {@link #getRadioVersion} instead. 111 */ 112 @Deprecated 113 public static final String RADIO = joinListOrElse( 114 TelephonyProperties.baseband_version(), UNKNOWN); 115 116 /** The name of the hardware (from the kernel command line or /proc). */ 117 public static final String HARDWARE = getString("ro.hardware"); 118 119 /** 120 * The SKU of the hardware (from the kernel command line). 121 * 122 * <p>The SKU is reported by the bootloader to configure system software features. 123 * If no value is supplied by the bootloader, this is reported as {@link #UNKNOWN}. 124 125 */ 126 @NonNull 127 public static final String SKU = getString("ro.boot.hardware.sku"); 128 129 /** 130 * The SKU of the device as set by the original design manufacturer (ODM). 131 * 132 * <p>This is a runtime-initialized property set during startup to configure device 133 * services. If no value is set, this is reported as {@link #UNKNOWN}. 134 * 135 * <p>The ODM SKU may have multiple variants for the same system SKU in case a manufacturer 136 * produces variants of the same design. For example, the same build may be released with 137 * variations in physical keyboard and/or display hardware, each with a different ODM SKU. 138 */ 139 @NonNull 140 public static final String ODM_SKU = getString("ro.boot.product.hardware.sku"); 141 142 /** 143 * Whether this build was for an emulator device. 144 * @hide 145 */ 146 @UnsupportedAppUsage 147 @TestApi 148 public static final boolean IS_EMULATOR = getString("ro.boot.qemu").equals("1"); 149 150 /** 151 * A hardware serial number, if available. Alphanumeric only, case-insensitive. 152 * This field is always set to {@link Build#UNKNOWN}. 153 * 154 * @deprecated Use {@link #getSerial()} instead. 155 **/ 156 @Deprecated 157 // IMPORTANT: This field should be initialized via a function call to 158 // prevent its value being inlined in the app during compilation because 159 // we will later set it to the value based on the app's target SDK. 160 public static final String SERIAL = getString("no.such.thing"); 161 162 /** 163 * Gets the hardware serial number, if available. 164 * 165 * <p class="note"><b>Note:</b> Root access may allow you to modify device identifiers, such as 166 * the hardware serial number. If you change these identifiers, you can use 167 * <a href="/training/articles/security-key-attestation.html">key attestation</a> to obtain 168 * proof of the device's original identifiers. 169 * 170 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional 171 * restrictions, and apps are recommended to use resettable identifiers (see <a 172 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This 173 * method can be invoked if one of the following requirements is met: 174 * <ul> 175 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this 176 * is a privileged permission that can only be granted to apps preloaded on the device. 177 * <li>If the calling app has carrier privileges (see {@link 178 * android.telephony.TelephonyManager#hasCarrierPrivileges}) on any active subscription. 179 * <li>If the calling app is the default SMS role holder (see {@link 180 * android.app.role.RoleManager#isRoleHeld(String)}). 181 * <li>If the calling app is the device owner of a fully-managed device, a profile 182 * owner of an organization-owned device, or their delegates (see {@link 183 * android.app.admin.DevicePolicyManager#getEnrollmentSpecificId()}). 184 * </ul> 185 * 186 * <p>If the calling app does not meet one of these requirements then this method will behave 187 * as follows: 188 * 189 * <ul> 190 * <li>If the calling app's target SDK is API level 28 or lower and the app has the 191 * READ_PHONE_STATE permission then {@link Build#UNKNOWN} is returned.</li> 192 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have 193 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or 194 * higher, then a SecurityException is thrown.</li> 195 * </ul> 196 * 197 * @return The serial number if specified. 198 */ 199 @SuppressAutoDoc // No support for device / profile owner. 200 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE) getSerial()201 public static String getSerial() { 202 IDeviceIdentifiersPolicyService service = IDeviceIdentifiersPolicyService.Stub 203 .asInterface(ServiceManager.getService(Context.DEVICE_IDENTIFIERS_SERVICE)); 204 try { 205 Application application = ActivityThread.currentApplication(); 206 String callingPackage = application != null ? application.getPackageName() : null; 207 return service.getSerialForPackage(callingPackage, null); 208 } catch (RemoteException e) { 209 e.rethrowFromSystemServer(); 210 } 211 return UNKNOWN; 212 } 213 214 /** 215 * An ordered list of ABIs supported by this device. The most preferred ABI is the first 216 * element in the list. 217 * 218 * See {@link #SUPPORTED_32_BIT_ABIS} and {@link #SUPPORTED_64_BIT_ABIS}. 219 */ 220 public static final String[] SUPPORTED_ABIS = getStringList("ro.product.cpu.abilist", ","); 221 222 /** 223 * An ordered list of <b>32 bit</b> ABIs supported by this device. The most preferred ABI 224 * is the first element in the list. 225 * 226 * See {@link #SUPPORTED_ABIS} and {@link #SUPPORTED_64_BIT_ABIS}. 227 */ 228 public static final String[] SUPPORTED_32_BIT_ABIS = 229 getStringList("ro.product.cpu.abilist32", ","); 230 231 /** 232 * An ordered list of <b>64 bit</b> ABIs supported by this device. The most preferred ABI 233 * is the first element in the list. 234 * 235 * See {@link #SUPPORTED_ABIS} and {@link #SUPPORTED_32_BIT_ABIS}. 236 */ 237 public static final String[] SUPPORTED_64_BIT_ABIS = 238 getStringList("ro.product.cpu.abilist64", ","); 239 240 /** {@hide} */ 241 @TestApi is64BitAbi(String abi)242 public static boolean is64BitAbi(String abi) { 243 return VMRuntime.is64BitAbi(abi); 244 } 245 246 static { 247 /* 248 * Adjusts CPU_ABI and CPU_ABI2 depending on whether or not a given process is 64 bit. 249 * 32 bit processes will always see 32 bit ABIs in these fields for backward 250 * compatibility. 251 */ 252 final String[] abiList; 253 if (VMRuntime.getRuntime().is64Bit()) { 254 abiList = SUPPORTED_64_BIT_ABIS; 255 } else { 256 abiList = SUPPORTED_32_BIT_ABIS; 257 } 258 259 CPU_ABI = abiList[0]; 260 if (abiList.length > 1) { 261 CPU_ABI2 = abiList[1]; 262 } else { 263 CPU_ABI2 = ""; 264 } 265 } 266 267 /** Various version strings. */ 268 public static class VERSION { 269 /** 270 * The internal value used by the underlying source control to 271 * represent this build. E.g., a perforce changelist number 272 * or a git hash. 273 */ 274 public static final String INCREMENTAL = getString("ro.build.version.incremental"); 275 276 /** 277 * The user-visible version string. E.g., "1.0" or "3.4b5" or "bananas". 278 * 279 * This field is an opaque string. Do not assume that its value 280 * has any particular structure or that values of RELEASE from 281 * different releases can be somehow ordered. 282 */ 283 public static final String RELEASE = getString("ro.build.version.release"); 284 285 /** 286 * The version string we show to the user; may be {@link #RELEASE} or 287 * {@link #CODENAME} if not a final release build. 288 */ 289 @NonNull public static final String RELEASE_OR_CODENAME = getString( 290 "ro.build.version.release_or_codename"); 291 292 /** 293 * The base OS build the product is based on. 294 */ 295 public static final String BASE_OS = SystemProperties.get("ro.build.version.base_os", ""); 296 297 /** 298 * The user-visible security patch level. This value represents the date when the device 299 * most recently applied a security patch. 300 */ 301 public static final String SECURITY_PATCH = SystemProperties.get( 302 "ro.build.version.security_patch", ""); 303 304 /** 305 * The media performance class of the device or 0 if none. 306 * <p> 307 * If this value is not <code>0</code>, the device conforms to the media performance class 308 * definition of the SDK version of this value. This value never changes while a device is 309 * booted, but it may increase when the hardware manufacturer provides an OTA update. 310 * <p> 311 * Possible non-zero values are defined in {@link Build.VERSION_CODES} starting with 312 * {@link Build.VERSION_CODES#R}. 313 */ 314 public static final int MEDIA_PERFORMANCE_CLASS = 315 DeviceProperties.media_performance_class().orElse(0); 316 317 /** 318 * The user-visible SDK version of the framework in its raw String 319 * representation; use {@link #SDK_INT} instead. 320 * 321 * @deprecated Use {@link #SDK_INT} to easily get this as an integer. 322 */ 323 @Deprecated 324 public static final String SDK = getString("ro.build.version.sdk"); 325 326 /** 327 * The SDK version of the software currently running on this hardware 328 * device. This value never changes while a device is booted, but it may 329 * increase when the hardware manufacturer provides an OTA update. 330 * <p> 331 * Possible values are defined in {@link Build.VERSION_CODES}. 332 */ 333 public static final int SDK_INT = SystemProperties.getInt( 334 "ro.build.version.sdk", 0); 335 336 /** 337 * The SDK version of the software that <em>initially</em> shipped on 338 * this hardware device. It <em>never</em> changes during the lifetime 339 * of the device, even when {@link #SDK_INT} increases due to an OTA 340 * update. 341 * <p> 342 * Possible values are defined in {@link Build.VERSION_CODES}. 343 * 344 * @see #SDK_INT 345 * @hide 346 */ 347 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) 348 @TestApi 349 public static final int DEVICE_INITIAL_SDK_INT = SystemProperties 350 .getInt("ro.product.first_api_level", 0); 351 352 /** 353 * The developer preview revision of a prerelease SDK. This value will always 354 * be <code>0</code> on production platform builds/devices. 355 * 356 * <p>When this value is nonzero, any new API added since the last 357 * officially published {@link #SDK_INT API level} is only guaranteed to be present 358 * on that specific preview revision. For example, an API <code>Activity.fooBar()</code> 359 * might be present in preview revision 1 but renamed or removed entirely in 360 * preview revision 2, which may cause an app attempting to call it to crash 361 * at runtime.</p> 362 * 363 * <p>Experimental apps targeting preview APIs should check this value for 364 * equality (<code>==</code>) with the preview SDK revision they were built for 365 * before using any prerelease platform APIs. Apps that detect a preview SDK revision 366 * other than the specific one they expect should fall back to using APIs from 367 * the previously published API level only to avoid unwanted runtime exceptions. 368 * </p> 369 */ 370 public static final int PREVIEW_SDK_INT = SystemProperties.getInt( 371 "ro.build.version.preview_sdk", 0); 372 373 /** 374 * The SDK fingerprint for a given prerelease SDK. This value will always be 375 * {@code REL} on production platform builds/devices. 376 * 377 * <p>When this value is not {@code REL}, it contains a string fingerprint of the API 378 * surface exposed by the preview SDK. Preview platforms with different API surfaces 379 * will have different {@code PREVIEW_SDK_FINGERPRINT}. 380 * 381 * <p>This attribute is intended for use by installers for finer grained targeting of 382 * packages. Applications targeting preview APIs should not use this field and should 383 * instead use {@code PREVIEW_SDK_INT} or use reflection or other runtime checks to 384 * detect the presence of an API or guard themselves against unexpected runtime 385 * behavior. 386 * 387 * @hide 388 */ 389 @SystemApi 390 @NonNull public static final String PREVIEW_SDK_FINGERPRINT = SystemProperties.get( 391 "ro.build.version.preview_sdk_fingerprint", "REL"); 392 393 /** 394 * The current development codename, or the string "REL" if this is 395 * a release build. 396 */ 397 public static final String CODENAME = getString("ro.build.version.codename"); 398 399 private static final String[] ALL_CODENAMES 400 = getStringList("ro.build.version.all_codenames", ","); 401 402 /** 403 * @hide 404 */ 405 @UnsupportedAppUsage 406 @TestApi 407 public static final String[] ACTIVE_CODENAMES = "REL".equals(ALL_CODENAMES[0]) 408 ? new String[0] : ALL_CODENAMES; 409 410 /** 411 * The SDK version to use when accessing resources. 412 * Use the current SDK version code. For every active development codename 413 * we are operating under, we bump the assumed resource platform version by 1. 414 * @hide 415 */ 416 @TestApi 417 public static final int RESOURCES_SDK_INT = SDK_INT + ACTIVE_CODENAMES.length; 418 419 /** 420 * The current lowest supported value of app target SDK. Applications targeting 421 * lower values may not function on devices running this SDK version. Its possible 422 * values are defined in {@link Build.VERSION_CODES}. 423 * 424 * @hide 425 */ 426 public static final int MIN_SUPPORTED_TARGET_SDK_INT = SystemProperties.getInt( 427 "ro.build.version.min_supported_target_sdk", 0); 428 } 429 430 /** 431 * Enumeration of the currently known SDK version codes. These are the 432 * values that can be found in {@link VERSION#SDK}. Version numbers 433 * increment monotonically with each official platform release. 434 */ 435 public static class VERSION_CODES { 436 /** 437 * Magic version number for a current development build, which has 438 * not yet turned into an official release. 439 */ 440 // This must match VMRuntime.SDK_VERSION_CUR_DEVELOPMENT. 441 public static final int CUR_DEVELOPMENT = 10000; 442 443 /** 444 * The original, first, version of Android. Yay! 445 * 446 * <p>Released publicly as Android 1.0 in September 2008. 447 */ 448 public static final int BASE = 1; 449 450 /** 451 * First Android update. 452 * 453 * <p>Released publicly as Android 1.1 in February 2009. 454 */ 455 public static final int BASE_1_1 = 2; 456 457 /** 458 * C. 459 * 460 * <p>Released publicly as Android 1.5 in April 2009. 461 */ 462 public static final int CUPCAKE = 3; 463 464 /** 465 * D. 466 * 467 * <p>Released publicly as Android 1.6 in September 2009. 468 * <p>Applications targeting this or a later release will get these 469 * new changes in behavior:</p> 470 * <ul> 471 * <li> They must explicitly request the 472 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission to be 473 * able to modify the contents of the SD card. (Apps targeting 474 * earlier versions will always request the permission.) 475 * <li> They must explicitly request the 476 * {@link android.Manifest.permission#READ_PHONE_STATE} permission to be 477 * able to be able to retrieve phone state info. (Apps targeting 478 * earlier versions will always request the permission.) 479 * <li> They are assumed to support different screen densities and 480 * sizes. (Apps targeting earlier versions are assumed to only support 481 * medium density normal size screens unless otherwise indicated). 482 * They can still explicitly specify screen support either way with the 483 * supports-screens manifest tag. 484 * <li> {@link android.widget.TabHost} will use the new dark tab 485 * background design. 486 * </ul> 487 */ 488 public static final int DONUT = 4; 489 490 /** 491 * E. 492 * 493 * <p>Released publicly as Android 2.0 in October 2009. 494 * <p>Applications targeting this or a later release will get these 495 * new changes in behavior:</p> 496 * <ul> 497 * <li> The {@link android.app.Service#onStartCommand 498 * Service.onStartCommand} function will return the new 499 * {@link android.app.Service#START_STICKY} behavior instead of the 500 * old compatibility {@link android.app.Service#START_STICKY_COMPATIBILITY}. 501 * <li> The {@link android.app.Activity} class will now execute back 502 * key presses on the key up instead of key down, to be able to detect 503 * canceled presses from virtual keys. 504 * <li> The {@link android.widget.TabWidget} class will use a new color scheme 505 * for tabs. In the new scheme, the foreground tab has a medium gray background 506 * the background tabs have a dark gray background. 507 * </ul> 508 */ 509 public static final int ECLAIR = 5; 510 511 /** 512 * E incremental update. 513 * 514 * <p>Released publicly as Android 2.0.1 in December 2009. 515 */ 516 public static final int ECLAIR_0_1 = 6; 517 518 /** 519 * E MR1. 520 * 521 * <p>Released publicly as Android 2.1 in January 2010. 522 */ 523 public static final int ECLAIR_MR1 = 7; 524 525 /** 526 * F. 527 * 528 * <p>Released publicly as Android 2.2 in May 2010. 529 */ 530 public static final int FROYO = 8; 531 532 /** 533 * G. 534 * 535 * <p>Released publicly as Android 2.3 in December 2010. 536 * <p>Applications targeting this or a later release will get these 537 * new changes in behavior:</p> 538 * <ul> 539 * <li> The application's notification icons will be shown on the new 540 * dark status bar background, so must be visible in this situation. 541 * </ul> 542 */ 543 public static final int GINGERBREAD = 9; 544 545 /** 546 * G MR1. 547 * 548 * <p>Released publicly as Android 2.3.3 in February 2011. 549 */ 550 public static final int GINGERBREAD_MR1 = 10; 551 552 /** 553 * H. 554 * 555 * <p>Released publicly as Android 3.0 in February 2011. 556 * <p>Applications targeting this or a later release will get these 557 * new changes in behavior:</p> 558 * <ul> 559 * <li> The default theme for applications is now dark holographic: 560 * {@link android.R.style#Theme_Holo}. 561 * <li> On large screen devices that do not have a physical menu 562 * button, the soft (compatibility) menu is disabled. 563 * <li> The activity lifecycle has changed slightly as per 564 * {@link android.app.Activity}. 565 * <li> An application will crash if it does not call through 566 * to the super implementation of its 567 * {@link android.app.Activity#onPause Activity.onPause()} method. 568 * <li> When an application requires a permission to access one of 569 * its components (activity, receiver, service, provider), this 570 * permission is no longer enforced when the application wants to 571 * access its own component. This means it can require a permission 572 * on a component that it does not itself hold and still access that 573 * component. 574 * <li> {@link android.content.Context#getSharedPreferences 575 * Context.getSharedPreferences()} will not automatically reload 576 * the preferences if they have changed on storage, unless 577 * {@link android.content.Context#MODE_MULTI_PROCESS} is used. 578 * <li> {@link android.view.ViewGroup#setMotionEventSplittingEnabled} 579 * will default to true. 580 * <li> {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} 581 * is enabled by default on windows. 582 * <li> {@link android.widget.PopupWindow#isSplitTouchEnabled() 583 * PopupWindow.isSplitTouchEnabled()} will return true by default. 584 * <li> {@link android.widget.GridView} and {@link android.widget.ListView} 585 * will use {@link android.view.View#setActivated View.setActivated} 586 * for selected items if they do not implement {@link android.widget.Checkable}. 587 * <li> {@link android.widget.Scroller} will be constructed with 588 * "flywheel" behavior enabled by default. 589 * </ul> 590 */ 591 public static final int HONEYCOMB = 11; 592 593 /** 594 * H MR1. 595 * 596 * <p>Released publicly as Android 3.1 in May 2011. 597 */ 598 public static final int HONEYCOMB_MR1 = 12; 599 600 /** 601 * H MR2. 602 * 603 * <p>Released publicly as Android 3.2 in July 2011. 604 * <p>Update to Honeycomb MR1 to support 7 inch tablets, improve 605 * screen compatibility mode, etc.</p> 606 * 607 * <p>As of this version, applications that don't say whether they 608 * support XLARGE screens will be assumed to do so only if they target 609 * {@link #HONEYCOMB} or later; it had been {@link #GINGERBREAD} or 610 * later. Applications that don't support a screen size at least as 611 * large as the current screen will provide the user with a UI to 612 * switch them in to screen size compatibility mode.</p> 613 * 614 * <p>This version introduces new screen size resource qualifiers 615 * based on the screen size in dp: see 616 * {@link android.content.res.Configuration#screenWidthDp}, 617 * {@link android.content.res.Configuration#screenHeightDp}, and 618 * {@link android.content.res.Configuration#smallestScreenWidthDp}. 619 * Supplying these in <supports-screens> as per 620 * {@link android.content.pm.ApplicationInfo#requiresSmallestWidthDp}, 621 * {@link android.content.pm.ApplicationInfo#compatibleWidthLimitDp}, and 622 * {@link android.content.pm.ApplicationInfo#largestWidthLimitDp} is 623 * preferred over the older screen size buckets and for older devices 624 * the appropriate buckets will be inferred from them.</p> 625 * 626 * <p>Applications targeting this or a later release will get these 627 * new changes in behavior:</p> 628 * <ul> 629 * <li><p>New {@link android.content.pm.PackageManager#FEATURE_SCREEN_PORTRAIT} 630 * and {@link android.content.pm.PackageManager#FEATURE_SCREEN_LANDSCAPE} 631 * features were introduced in this release. Applications that target 632 * previous platform versions are assumed to require both portrait and 633 * landscape support in the device; when targeting Honeycomb MR1 or 634 * greater the application is responsible for specifying any specific 635 * orientation it requires.</p> 636 * <li><p>{@link android.os.AsyncTask} will use the serial executor 637 * by default when calling {@link android.os.AsyncTask#execute}.</p> 638 * <li><p>{@link android.content.pm.ActivityInfo#configChanges 639 * ActivityInfo.configChanges} will have the 640 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE} and 641 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE} 642 * bits set; these need to be cleared for older applications because 643 * some developers have done absolute comparisons against this value 644 * instead of correctly masking the bits they are interested in. 645 * </ul> 646 */ 647 public static final int HONEYCOMB_MR2 = 13; 648 649 /** 650 * I. 651 * 652 * <p>Released publicly as Android 4.0 in October 2011. 653 * <p>Applications targeting this or a later release will get these 654 * new changes in behavior:</p> 655 * <ul> 656 * <li> For devices without a dedicated menu key, the software compatibility 657 * menu key will not be shown even on phones. By targeting Ice Cream Sandwich 658 * or later, your UI must always have its own menu UI affordance if needed, 659 * on both tablets and phones. The ActionBar will take care of this for you. 660 * <li> 2d drawing hardware acceleration is now turned on by default. 661 * You can use 662 * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated} 663 * to turn it off if needed, although this is strongly discouraged since 664 * it will result in poor performance on larger screen devices. 665 * <li> The default theme for applications is now the "device default" theme: 666 * {@link android.R.style#Theme_DeviceDefault}. This may be the 667 * holo dark theme or a different dark theme defined by the specific device. 668 * The {@link android.R.style#Theme_Holo} family must not be modified 669 * for a device to be considered compatible. Applications that explicitly 670 * request a theme from the Holo family will be guaranteed that these themes 671 * will not change character within the same platform version. Applications 672 * that wish to blend in with the device should use a theme from the 673 * {@link android.R.style#Theme_DeviceDefault} family. 674 * <li> Managed cursors can now throw an exception if you directly close 675 * the cursor yourself without stopping the management of it; previously failures 676 * would be silently ignored. 677 * <li> The fadingEdge attribute on views will be ignored (fading edges is no 678 * longer a standard part of the UI). A new requiresFadingEdge attribute allows 679 * applications to still force fading edges on for special cases. 680 * <li> {@link android.content.Context#bindService Context.bindService()} 681 * will not automatically add in {@link android.content.Context#BIND_WAIVE_PRIORITY}. 682 * <li> App Widgets will have standard padding automatically added around 683 * them, rather than relying on the padding being baked into the widget itself. 684 * <li> An exception will be thrown if you try to change the type of a 685 * window after it has been added to the window manager. Previously this 686 * would result in random incorrect behavior. 687 * <li> {@link android.view.animation.AnimationSet} will parse out 688 * the duration, fillBefore, fillAfter, repeatMode, and startOffset 689 * XML attributes that are defined. 690 * <li> {@link android.app.ActionBar#setHomeButtonEnabled 691 * ActionBar.setHomeButtonEnabled()} is false by default. 692 * </ul> 693 */ 694 public static final int ICE_CREAM_SANDWICH = 14; 695 696 /** 697 * I MR1. 698 * 699 * <p>Released publicly as Android 4.03 in December 2011. 700 */ 701 public static final int ICE_CREAM_SANDWICH_MR1 = 15; 702 703 /** 704 * J. 705 * 706 * <p>Released publicly as Android 4.1 in July 2012. 707 * <p>Applications targeting this or a later release will get these 708 * new changes in behavior:</p> 709 * <ul> 710 * <li> You must explicitly request the {@link android.Manifest.permission#READ_CALL_LOG} 711 * and/or {@link android.Manifest.permission#WRITE_CALL_LOG} permissions; 712 * access to the call log is no longer implicitly provided through 713 * {@link android.Manifest.permission#READ_CONTACTS} and 714 * {@link android.Manifest.permission#WRITE_CONTACTS}. 715 * <li> {@link android.widget.RemoteViews} will throw an exception if 716 * setting an onClick handler for views being generated by a 717 * {@link android.widget.RemoteViewsService} for a collection container; 718 * previously this just resulted in a warning log message. 719 * <li> New {@link android.app.ActionBar} policy for embedded tabs: 720 * embedded tabs are now always stacked in the action bar when in portrait 721 * mode, regardless of the size of the screen. 722 * <li> {@link android.webkit.WebSettings#setAllowFileAccessFromFileURLs(boolean) 723 * WebSettings.setAllowFileAccessFromFileURLs} and 724 * {@link android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs(boolean) 725 * WebSettings.setAllowUniversalAccessFromFileURLs} default to false. 726 * <li> Calls to {@link android.content.pm.PackageManager#setComponentEnabledSetting 727 * PackageManager.setComponentEnabledSetting} will now throw an 728 * IllegalArgumentException if the given component class name does not 729 * exist in the application's manifest. 730 * <li> {@link android.nfc.NfcAdapter#setNdefPushMessage 731 * NfcAdapter.setNdefPushMessage}, 732 * {@link android.nfc.NfcAdapter#setNdefPushMessageCallback 733 * NfcAdapter.setNdefPushMessageCallback} and 734 * {@link android.nfc.NfcAdapter#setOnNdefPushCompleteCallback 735 * NfcAdapter.setOnNdefPushCompleteCallback} will throw 736 * IllegalStateException if called after the Activity has been destroyed. 737 * <li> Accessibility services must require the new 738 * {@link android.Manifest.permission#BIND_ACCESSIBILITY_SERVICE} permission or 739 * they will not be available for use. 740 * <li> {@link android.accessibilityservice.AccessibilityServiceInfo#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS 741 * AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS} must be set 742 * for unimportant views to be included in queries. 743 * </ul> 744 */ 745 public static final int JELLY_BEAN = 16; 746 747 /** 748 * J MR1. 749 * 750 * <p>Released publicly as Android 4.2 in November 2012. 751 * <p>Applications targeting this or a later release will get these 752 * new changes in behavior:</p> 753 * <ul> 754 * <li>Content Providers: The default value of {@code android:exported} is now 755 * {@code false}. See 756 * <a href="{@docRoot}guide/topics/manifest/provider-element.html#exported"> 757 * the android:exported section</a> in the provider documentation for more details.</li> 758 * <li>{@link android.view.View#getLayoutDirection() View.getLayoutDirection()} 759 * can return different values than {@link android.view.View#LAYOUT_DIRECTION_LTR} 760 * based on the locale etc. 761 * <li> {@link android.webkit.WebView#addJavascriptInterface(Object, String) 762 * WebView.addJavascriptInterface} requires explicit annotations on methods 763 * for them to be accessible from Javascript. 764 * </ul> 765 */ 766 public static final int JELLY_BEAN_MR1 = 17; 767 768 /** 769 * J MR2. 770 * 771 * <p>Released publicly as Android 4.3 in July 2013. 772 */ 773 public static final int JELLY_BEAN_MR2 = 18; 774 775 /** 776 * K. 777 * 778 * <p>Released publicly as Android 4.4 in October 2013. 779 * <p>Applications targeting this or a later release will get these 780 * new changes in behavior. For more information about this release, see the 781 * <a href="/about/versions/kitkat/">Android KitKat overview</a>.</p> 782 * <ul> 783 * <li> The default result of 784 * {@link android.preference.PreferenceActivity#isValidFragment(String) 785 * PreferenceActivity.isValueFragment} becomes false instead of true.</li> 786 * <li> In {@link android.webkit.WebView}, apps targeting earlier versions will have 787 * JS URLs evaluated directly and any result of the evaluation will not replace 788 * the current page content. Apps targetting KITKAT or later that load a JS URL will 789 * have the result of that URL replace the content of the current page</li> 790 * <li> {@link android.app.AlarmManager#set AlarmManager.set} becomes interpreted as 791 * an inexact value, to give the system more flexibility in scheduling alarms.</li> 792 * <li> {@link android.content.Context#getSharedPreferences(String, int) 793 * Context.getSharedPreferences} no longer allows a null name.</li> 794 * <li> {@link android.widget.RelativeLayout} changes to compute wrapped content 795 * margins correctly.</li> 796 * <li> {@link android.app.ActionBar}'s window content overlay is allowed to be 797 * drawn.</li> 798 * <li>The {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} 799 * permission is now always enforced.</li> 800 * <li>Access to package-specific external storage directories belonging 801 * to the calling app no longer requires the 802 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} or 803 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 804 * permissions.</li> 805 * </ul> 806 */ 807 public static final int KITKAT = 19; 808 809 /** 810 * K for watches. 811 * 812 * <p>Released publicly as Android 4.4W in June 2014. 813 * <p>Applications targeting this or a later release will get these 814 * new changes in behavior:</p> 815 * <ul> 816 * <li>{@link android.app.AlertDialog} might not have a default background if the theme does 817 * not specify one.</li> 818 * </ul> 819 */ 820 public static final int KITKAT_WATCH = 20; 821 822 /** 823 * Temporary until we completely switch to {@link #LOLLIPOP}. 824 * @hide 825 */ 826 public static final int L = 21; 827 828 /** 829 * L. 830 * 831 * <p>Released publicly as Android 5.0 in November 2014. 832 * <p>Applications targeting this or a later release will get these 833 * new changes in behavior. For more information about this release, see the 834 * <a href="/about/versions/lollipop/">Android Lollipop overview</a>.</p> 835 * <ul> 836 * <li> {@link android.content.Context#bindService Context.bindService} now 837 * requires an explicit Intent, and will throw an exception if given an implicit 838 * Intent.</li> 839 * <li> {@link android.app.Notification.Builder Notification.Builder} will 840 * not have the colors of their various notification elements adjusted to better 841 * match the new material design look.</li> 842 * <li> {@link android.os.Message} will validate that a message is not currently 843 * in use when it is recycled.</li> 844 * <li> Hardware accelerated drawing in windows will be enabled automatically 845 * in most places.</li> 846 * <li> {@link android.widget.Spinner} throws an exception if attaching an 847 * adapter with more than one item type.</li> 848 * <li> If the app is a launcher, the launcher will be available to the user 849 * even when they are using corporate profiles (which requires that the app 850 * use {@link android.content.pm.LauncherApps} to correctly populate its 851 * apps UI).</li> 852 * <li> Calling {@link android.app.Service#stopForeground Service.stopForeground} 853 * with removeNotification false will modify the still posted notification so that 854 * it is no longer forced to be ongoing.</li> 855 * <li> A {@link android.service.dreams.DreamService} must require the 856 * {@link android.Manifest.permission#BIND_DREAM_SERVICE} permission to be usable.</li> 857 * </ul> 858 */ 859 public static final int LOLLIPOP = 21; 860 861 /** 862 * L MR1. 863 * 864 * <p>Released publicly as Android 5.1 in March 2015. 865 * <p>For more information about this release, see the 866 * <a href="/about/versions/android-5.1">Android 5.1 APIs</a>. 867 */ 868 public static final int LOLLIPOP_MR1 = 22; 869 870 /** 871 * M. 872 * 873 * <p>Released publicly as Android 6.0 in October 2015. 874 * <p>Applications targeting this or a later release will get these 875 * new changes in behavior. For more information about this release, see the 876 * <a href="/about/versions/marshmallow/">Android 6.0 Marshmallow overview</a>.</p> 877 * <ul> 878 * <li> Runtime permissions. Dangerous permissions are no longer granted at 879 * install time, but must be requested by the application at runtime through 880 * {@link android.app.Activity#requestPermissions}.</li> 881 * <li> Bluetooth and Wi-Fi scanning now requires holding the location permission.</li> 882 * <li> {@link android.app.AlarmManager#setTimeZone AlarmManager.setTimeZone} will fail if 883 * the given timezone is non-Olson.</li> 884 * <li> Activity transitions will only return shared 885 * elements mapped in the returned view hierarchy back to the calling activity.</li> 886 * <li> {@link android.view.View} allows a number of behaviors that may break 887 * existing apps: Canvas throws an exception if restore() is called too many times, 888 * widgets may return a hint size when returning UNSPECIFIED measure specs, and it 889 * will respect the attributes {@link android.R.attr#foreground}, 890 * {@link android.R.attr#foregroundGravity}, {@link android.R.attr#foregroundTint}, and 891 * {@link android.R.attr#foregroundTintMode}.</li> 892 * <li> {@link android.view.MotionEvent#getButtonState MotionEvent.getButtonState} 893 * will no longer report {@link android.view.MotionEvent#BUTTON_PRIMARY} 894 * and {@link android.view.MotionEvent#BUTTON_SECONDARY} as synonyms for 895 * {@link android.view.MotionEvent#BUTTON_STYLUS_PRIMARY} and 896 * {@link android.view.MotionEvent#BUTTON_STYLUS_SECONDARY}.</li> 897 * <li> {@link android.widget.ScrollView} now respects the layout param margins 898 * when measuring.</li> 899 * </ul> 900 */ 901 public static final int M = 23; 902 903 /** 904 * N. 905 * 906 * <p>Released publicly as Android 7.0 in August 2016. 907 * <p>Applications targeting this or a later release will get these 908 * new changes in behavior. For more information about this release, see 909 * the <a href="/about/versions/nougat/">Android Nougat overview</a>.</p> 910 * <ul> 911 * <li> {@link android.app.DownloadManager.Request#setAllowedNetworkTypes 912 * DownloadManager.Request.setAllowedNetworkTypes} 913 * will disable "allow over metered" when specifying only 914 * {@link android.app.DownloadManager.Request#NETWORK_WIFI}.</li> 915 * <li> {@link android.app.DownloadManager} no longer allows access to raw 916 * file paths.</li> 917 * <li> {@link android.app.Notification.Builder#setShowWhen 918 * Notification.Builder.setShowWhen} 919 * must be called explicitly to have the time shown, and various other changes in 920 * {@link android.app.Notification.Builder Notification.Builder} to how notifications 921 * are shown.</li> 922 * <li>{@link android.content.Context#MODE_WORLD_READABLE} and 923 * {@link android.content.Context#MODE_WORLD_WRITEABLE} are no longer supported.</li> 924 * <li>{@link android.os.FileUriExposedException} will be thrown to applications.</li> 925 * <li>Applications will see global drag and drops as per 926 * {@link android.view.View#DRAG_FLAG_GLOBAL}.</li> 927 * <li>{@link android.webkit.WebView#evaluateJavascript WebView.evaluateJavascript} 928 * will not persist state from an empty WebView.</li> 929 * <li>{@link android.animation.AnimatorSet} will not ignore calls to end() before 930 * start().</li> 931 * <li>{@link android.app.AlarmManager#cancel(android.app.PendingIntent) 932 * AlarmManager.cancel} will throw a NullPointerException if given a null operation.</li> 933 * <li>{@link android.app.FragmentManager} will ensure fragments have been created 934 * before being placed on the back stack.</li> 935 * <li>{@link android.app.FragmentManager} restores fragments in 936 * {@link android.app.Fragment#onCreate Fragment.onCreate} rather than after the 937 * method returns.</li> 938 * <li>{@link android.R.attr#resizeableActivity} defaults to true.</li> 939 * <li>{@link android.graphics.drawable.AnimatedVectorDrawable} throws exceptions when 940 * opening invalid VectorDrawable animations.</li> 941 * <li>{@link android.view.ViewGroup.MarginLayoutParams} will no longer be dropped 942 * when converting between some types of layout params (such as 943 * {@link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams} to 944 * {@link android.widget.RelativeLayout.LayoutParams RelativeLayout.LayoutParams}).</li> 945 * <li>Your application processes will not be killed when the device density changes.</li> 946 * <li>Drag and drop. After a view receives the 947 * {@link android.view.DragEvent#ACTION_DRAG_ENTERED} event, when the drag shadow moves into 948 * a descendant view that can accept the data, the view receives the 949 * {@link android.view.DragEvent#ACTION_DRAG_EXITED} event and won’t receive 950 * {@link android.view.DragEvent#ACTION_DRAG_LOCATION} and 951 * {@link android.view.DragEvent#ACTION_DROP} events while the drag shadow is within that 952 * descendant view, even if the descendant view returns <code>false</code> from its handler 953 * for these events.</li> 954 * </ul> 955 */ 956 public static final int N = 24; 957 958 /** 959 * N MR1. 960 * 961 * <p>Released publicly as Android 7.1 in October 2016. 962 * <p>For more information about this release, see 963 * <a href="/about/versions/nougat/android-7.1">Android 7.1 for 964 * Developers</a>. 965 */ 966 public static final int N_MR1 = 25; 967 968 /** 969 * O. 970 * 971 * <p>Released publicly as Android 8.0 in August 2017. 972 * <p>Applications targeting this or a later release will get these 973 * new changes in behavior. For more information about this release, see 974 * the <a href="/about/versions/oreo/">Android Oreo overview</a>.</p> 975 * <ul> 976 * <li><a href="{@docRoot}about/versions/oreo/background.html">Background execution limits</a> 977 * are applied to the application.</li> 978 * <li>The behavior of AccountManager's 979 * {@link android.accounts.AccountManager#getAccountsByType}, 980 * {@link android.accounts.AccountManager#getAccountsByTypeAndFeatures}, and 981 * {@link android.accounts.AccountManager#hasFeatures} has changed as documented there.</li> 982 * <li>{@link android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE_PRE_26} 983 * is now returned as 984 * {@link android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.</li> 985 * <li>The {@link android.app.NotificationManager} now requires the use of notification 986 * channels.</li> 987 * <li>Changes to the strict mode that are set in 988 * {@link Application#onCreate Application.onCreate} will no longer be clobbered after 989 * that function returns.</li> 990 * <li>A shared library apk with native code will have that native code included in 991 * the library path of its clients.</li> 992 * <li>{@link android.content.Context#getSharedPreferences Context.getSharedPreferences} 993 * in credential encrypted storage will throw an exception before the user is unlocked.</li> 994 * <li>Attempting to retrieve a {@link Context#FINGERPRINT_SERVICE} on a device that 995 * does not support that feature will now throw a runtime exception.</li> 996 * <li>{@link android.app.Fragment} will stop any active view animations when 997 * the fragment is stopped.</li> 998 * <li>Some compatibility code in Resources that attempts to use the default Theme 999 * the app may be using will be turned off, requiring the app to explicitly request 1000 * resources with the right theme.</li> 1001 * <li>{@link android.content.ContentResolver#notifyChange ContentResolver.notifyChange} and 1002 * {@link android.content.ContentResolver#registerContentObserver 1003 * ContentResolver.registerContentObserver} 1004 * will throw a SecurityException if the caller does not have permission to access 1005 * the provider (or the provider doesn't exit); otherwise the call will be silently 1006 * ignored.</li> 1007 * <li>{@link android.hardware.camera2.CameraDevice#createCaptureRequest 1008 * CameraDevice.createCaptureRequest} will enable 1009 * {@link android.hardware.camera2.CaptureRequest#CONTROL_ENABLE_ZSL} by default for 1010 * still image capture.</li> 1011 * <li>WallpaperManager's {@link android.app.WallpaperManager#getWallpaperFile}, 1012 * {@link android.app.WallpaperManager#getDrawable}, 1013 * {@link android.app.WallpaperManager#getFastDrawable}, 1014 * {@link android.app.WallpaperManager#peekDrawable}, and 1015 * {@link android.app.WallpaperManager#peekFastDrawable} will throw an exception 1016 * if you can not access the wallpaper.</li> 1017 * <li>The behavior of 1018 * {@link android.hardware.usb.UsbDeviceConnection#requestWait UsbDeviceConnection.requestWait} 1019 * is modified as per the documentation there.</li> 1020 * <li>{@link StrictMode.VmPolicy.Builder#detectAll StrictMode.VmPolicy.Builder.detectAll} 1021 * will also enable {@link StrictMode.VmPolicy.Builder#detectContentUriWithoutPermission} 1022 * and {@link StrictMode.VmPolicy.Builder#detectUntaggedSockets}.</li> 1023 * <li>{@link StrictMode.ThreadPolicy.Builder#detectAll StrictMode.ThreadPolicy.Builder.detectAll} 1024 * will also enable {@link StrictMode.ThreadPolicy.Builder#detectUnbufferedIo}.</li> 1025 * <li>{@link android.provider.DocumentsContract}'s various methods will throw failure 1026 * exceptions back to the caller instead of returning null. 1027 * <li>{@link View#hasFocusable View.hasFocusable} now includes auto-focusable views.</li> 1028 * <li>{@link android.view.SurfaceView} will no longer always change the underlying 1029 * Surface object when something about it changes; apps need to look at the current 1030 * state of the object to determine which things they are interested in have changed.</li> 1031 * <li>{@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} must be 1032 * used for overlay windows, other system overlay window types are not allowed.</li> 1033 * <li>{@link android.view.ViewTreeObserver#addOnDrawListener 1034 * ViewTreeObserver.addOnDrawListener} will throw an exception if called from within 1035 * onDraw.</li> 1036 * <li>{@link android.graphics.Canvas#setBitmap Canvas.setBitmap} will no longer preserve 1037 * the current matrix and clip stack of the canvas.</li> 1038 * <li>{@link android.widget.ListPopupWindow#setHeight ListPopupWindow.setHeight} 1039 * will throw an exception if a negative height is supplied.</li> 1040 * <li>{@link android.widget.TextView} will use internationalized input for numbers, 1041 * dates, and times.</li> 1042 * <li>{@link android.widget.Toast} must be used for showing toast windows; the toast 1043 * window type can not be directly used.</li> 1044 * <li>{@link android.net.wifi.WifiManager#getConnectionInfo WifiManager.getConnectionInfo} 1045 * requires that the caller hold the location permission to return BSSID/SSID</li> 1046 * <li>{@link android.net.wifi.p2p.WifiP2pManager#requestPeers WifiP2pManager.requestPeers} 1047 * requires the caller hold the location permission.</li> 1048 * <li>{@link android.R.attr#maxAspectRatio} defaults to 0, meaning there is no restriction 1049 * on the app's maximum aspect ratio (so it can be stretched to fill larger screens).</li> 1050 * <li>{@link android.R.attr#focusable} defaults to a new state ({@code auto}) where it will 1051 * inherit the value of {@link android.R.attr#clickable} unless explicitly overridden.</li> 1052 * <li>A default theme-appropriate focus-state highlight will be supplied to all Views 1053 * which don't provide a focus-state drawable themselves. This can be disabled by setting 1054 * {@link android.R.attr#defaultFocusHighlightEnabled} to false.</li> 1055 * </ul> 1056 */ 1057 public static final int O = 26; 1058 1059 /** 1060 * O MR1. 1061 * 1062 * <p>Released publicly as Android 8.1 in December 2017. 1063 * <p>Applications targeting this or a later release will get these 1064 * new changes in behavior. For more information about this release, see 1065 * <a href="/about/versions/oreo/android-8.1">Android 8.1 features and 1066 * APIs</a>.</p> 1067 * <ul> 1068 * <li>Apps exporting and linking to apk shared libraries must explicitly 1069 * enumerate all signing certificates in a consistent order.</li> 1070 * <li>{@link android.R.attr#screenOrientation} can not be used to request a fixed 1071 * orientation if the associated activity is not fullscreen and opaque.</li> 1072 * </ul> 1073 * 1074 */ 1075 public static final int O_MR1 = 27; 1076 1077 /** 1078 * P. 1079 * 1080 * <p>Released publicly as Android 9 in August 2018. 1081 * <p>Applications targeting this or a later release will get these 1082 * new changes in behavior. For more information about this release, see the 1083 * <a href="/about/versions/pie/">Android 9 Pie overview</a>.</p> 1084 * <ul> 1085 * <li>{@link android.app.Service#startForeground Service.startForeground} requires 1086 * that apps hold the permission 1087 * {@link android.Manifest.permission#FOREGROUND_SERVICE}.</li> 1088 * <li>{@link android.widget.LinearLayout} will always remeasure weighted children, 1089 * even if there is no excess space.</li> 1090 * </ul> 1091 * 1092 */ 1093 public static final int P = 28; 1094 1095 /** 1096 * Q. 1097 * 1098 * <p>Released publicly as Android 10 in September 2019. 1099 * <p>Applications targeting this or a later release will get these new changes in behavior. 1100 * For more information about this release, see the 1101 * <a href="/about/versions/10">Android 10 overview</a>.</p> 1102 * <ul> 1103 * <li><a href="/about/versions/10/behavior-changes-all">Behavior changes: all apps</a></li> 1104 * <li><a href="/about/versions/10/behavior-changes-10">Behavior changes: apps targeting API 1105 * 29+</a></li> 1106 * </ul> 1107 * 1108 */ 1109 public static final int Q = 29; 1110 1111 /** 1112 * R. 1113 * 1114 * <p>Released publicly as Android 11 in September 2020. 1115 * <p>Applications targeting this or a later release will get these new changes in behavior. 1116 * For more information about this release, see the 1117 * <a href="/about/versions/11">Android 11 overview</a>.</p> 1118 * <ul> 1119 * <li><a href="/about/versions/11/behavior-changes-all">Behavior changes: all apps</a></li> 1120 * <li><a href="/about/versions/11/behavior-changes-11">Behavior changes: Apps targeting 1121 * Android 11</a></li> 1122 * <li><a href="/about/versions/11/non-sdk-11">Updates to non-SDK interface restrictions 1123 * in Android 11</a></li> 1124 * </ul> 1125 * 1126 */ 1127 public static final int R = 30; 1128 1129 /** 1130 * S. 1131 */ 1132 public static final int S = 31; 1133 } 1134 1135 /** The type of build, like "user" or "eng". */ 1136 public static final String TYPE = getString("ro.build.type"); 1137 1138 /** Comma-separated tags describing the build, like "unsigned,debug". */ 1139 public static final String TAGS = getString("ro.build.tags"); 1140 1141 /** A string that uniquely identifies this build. Do not attempt to parse this value. */ 1142 public static final String FINGERPRINT = deriveFingerprint(); 1143 1144 /** 1145 * Some devices split the fingerprint components between multiple 1146 * partitions, so we might derive the fingerprint at runtime. 1147 */ deriveFingerprint()1148 private static String deriveFingerprint() { 1149 String finger = SystemProperties.get("ro.build.fingerprint"); 1150 if (TextUtils.isEmpty(finger)) { 1151 finger = getString("ro.product.brand") + '/' + 1152 getString("ro.product.name") + '/' + 1153 getString("ro.product.device") + ':' + 1154 getString("ro.build.version.release") + '/' + 1155 getString("ro.build.id") + '/' + 1156 getString("ro.build.version.incremental") + ':' + 1157 getString("ro.build.type") + '/' + 1158 getString("ro.build.tags"); 1159 } 1160 return finger; 1161 } 1162 1163 /** 1164 * Ensure that raw fingerprint system property is defined. If it was derived 1165 * dynamically by {@link #deriveFingerprint()} this is where we push the 1166 * derived value into the property service. 1167 * 1168 * @hide 1169 */ ensureFingerprintProperty()1170 public static void ensureFingerprintProperty() { 1171 if (TextUtils.isEmpty(SystemProperties.get("ro.build.fingerprint"))) { 1172 try { 1173 SystemProperties.set("ro.build.fingerprint", FINGERPRINT); 1174 } catch (IllegalArgumentException e) { 1175 Slog.e(TAG, "Failed to set fingerprint property", e); 1176 } 1177 } 1178 } 1179 1180 /** 1181 * A multiplier for various timeouts on the system. 1182 * 1183 * The intent is that products targeting software emulators that are orders of magnitude slower 1184 * than real hardware may set this to a large number. On real devices and hardware-accelerated 1185 * virtualized devices this should not be set. 1186 * 1187 * @hide 1188 */ 1189 public static final int HW_TIMEOUT_MULTIPLIER = 1190 SystemProperties.getInt("ro.hw_timeout_multiplier", 1); 1191 1192 /** 1193 * True if Treble is enabled and required for this device. 1194 * 1195 * @hide 1196 */ 1197 public static final boolean IS_TREBLE_ENABLED = 1198 SystemProperties.getBoolean("ro.treble.enabled", false); 1199 1200 /** 1201 * Verifies the current flash of the device is consistent with what 1202 * was expected at build time. 1203 * 1204 * Treble devices will verify the Vendor Interface (VINTF). A device 1205 * launched without Treble: 1206 * 1207 * 1) Checks that device fingerprint is defined and that it matches across 1208 * various partitions. 1209 * 2) Verifies radio and bootloader partitions are those expected in the build. 1210 * 1211 * @hide 1212 */ isBuildConsistent()1213 public static boolean isBuildConsistent() { 1214 // Don't care on eng builds. Incremental build may trigger false negative. 1215 if (IS_ENG) return true; 1216 1217 if (IS_TREBLE_ENABLED) { 1218 // If we can run this code, the device should already pass AVB. 1219 // So, we don't need to check AVB here. 1220 int result = VintfObject.verifyWithoutAvb(); 1221 1222 if (result != 0) { 1223 Slog.e(TAG, "Vendor interface is incompatible, error=" 1224 + String.valueOf(result)); 1225 } 1226 1227 return result == 0; 1228 } 1229 1230 final String system = SystemProperties.get("ro.system.build.fingerprint"); 1231 final String vendor = SystemProperties.get("ro.vendor.build.fingerprint"); 1232 final String bootimage = SystemProperties.get("ro.bootimage.build.fingerprint"); 1233 final String requiredBootloader = SystemProperties.get("ro.build.expect.bootloader"); 1234 final String currentBootloader = SystemProperties.get("ro.bootloader"); 1235 final String requiredRadio = SystemProperties.get("ro.build.expect.baseband"); 1236 final String currentRadio = joinListOrElse( 1237 TelephonyProperties.baseband_version(), ""); 1238 1239 if (TextUtils.isEmpty(system)) { 1240 Slog.e(TAG, "Required ro.system.build.fingerprint is empty!"); 1241 return false; 1242 } 1243 1244 if (!TextUtils.isEmpty(vendor)) { 1245 if (!Objects.equals(system, vendor)) { 1246 Slog.e(TAG, "Mismatched fingerprints; system reported " + system 1247 + " but vendor reported " + vendor); 1248 return false; 1249 } 1250 } 1251 1252 /* TODO: Figure out issue with checks failing 1253 if (!TextUtils.isEmpty(bootimage)) { 1254 if (!Objects.equals(system, bootimage)) { 1255 Slog.e(TAG, "Mismatched fingerprints; system reported " + system 1256 + " but bootimage reported " + bootimage); 1257 return false; 1258 } 1259 } 1260 1261 if (!TextUtils.isEmpty(requiredBootloader)) { 1262 if (!Objects.equals(currentBootloader, requiredBootloader)) { 1263 Slog.e(TAG, "Mismatched bootloader version: build requires " + requiredBootloader 1264 + " but runtime reports " + currentBootloader); 1265 return false; 1266 } 1267 } 1268 1269 if (!TextUtils.isEmpty(requiredRadio)) { 1270 if (!Objects.equals(currentRadio, requiredRadio)) { 1271 Slog.e(TAG, "Mismatched radio version: build requires " + requiredRadio 1272 + " but runtime reports " + currentRadio); 1273 return false; 1274 } 1275 } 1276 */ 1277 1278 return true; 1279 } 1280 1281 /** Build information for a particular device partition. */ 1282 public static class Partition { 1283 /** The name identifying the system partition. */ 1284 public static final String PARTITION_NAME_SYSTEM = "system"; 1285 1286 private final String mName; 1287 private final String mFingerprint; 1288 private final long mTimeMs; 1289 Partition(String name, String fingerprint, long timeMs)1290 private Partition(String name, String fingerprint, long timeMs) { 1291 mName = name; 1292 mFingerprint = fingerprint; 1293 mTimeMs = timeMs; 1294 } 1295 1296 /** The name of this partition, e.g. "system", or "vendor" */ 1297 @NonNull getName()1298 public String getName() { 1299 return mName; 1300 } 1301 1302 /** The build fingerprint of this partition, see {@link Build#FINGERPRINT}. */ 1303 @NonNull getFingerprint()1304 public String getFingerprint() { 1305 return mFingerprint; 1306 } 1307 1308 /** The time (ms since epoch), at which this partition was built, see {@link Build#TIME}. */ getBuildTimeMillis()1309 public long getBuildTimeMillis() { 1310 return mTimeMs; 1311 } 1312 1313 @Override equals(@ullable Object o)1314 public boolean equals(@Nullable Object o) { 1315 if (!(o instanceof Partition)) { 1316 return false; 1317 } 1318 Partition op = (Partition) o; 1319 return mName.equals(op.mName) 1320 && mFingerprint.equals(op.mFingerprint) 1321 && mTimeMs == op.mTimeMs; 1322 } 1323 1324 @Override hashCode()1325 public int hashCode() { 1326 return Objects.hash(mName, mFingerprint, mTimeMs); 1327 } 1328 } 1329 1330 /** 1331 * Get build information about partitions that have a separate fingerprint defined. 1332 * 1333 * The list includes partitions that are suitable candidates for over-the-air updates. This is 1334 * not an exhaustive list of partitions on the device. 1335 */ 1336 @NonNull getFingerprintedPartitions()1337 public static List<Partition> getFingerprintedPartitions() { 1338 ArrayList<Partition> partitions = new ArrayList(); 1339 1340 String[] names = new String[] { 1341 "bootimage", "odm", "product", "system_ext", Partition.PARTITION_NAME_SYSTEM, 1342 "vendor" 1343 }; 1344 for (String name : names) { 1345 String fingerprint = SystemProperties.get("ro." + name + ".build.fingerprint"); 1346 if (TextUtils.isEmpty(fingerprint)) { 1347 continue; 1348 } 1349 long time = getLong("ro." + name + ".build.date.utc") * 1000; 1350 partitions.add(new Partition(name, fingerprint, time)); 1351 } 1352 1353 return partitions; 1354 } 1355 1356 // The following properties only make sense for internal engineering builds. 1357 1358 /** The time at which the build was produced, given in milliseconds since the UNIX epoch. */ 1359 public static final long TIME = getLong("ro.build.date.utc") * 1000; 1360 public static final String USER = getString("ro.build.user"); 1361 public static final String HOST = getString("ro.build.host"); 1362 1363 /** 1364 * Returns true if the device is running a debuggable build such as "userdebug" or "eng". 1365 * 1366 * Debuggable builds allow users to gain root access via local shell, attach debuggers to any 1367 * application regardless of whether they have the "debuggable" attribute set, or downgrade 1368 * selinux into "permissive" mode in particular. 1369 * @hide 1370 */ 1371 @UnsupportedAppUsage 1372 public static final boolean IS_DEBUGGABLE = 1373 SystemProperties.getInt("ro.debuggable", 0) == 1; 1374 1375 /** 1376 * Returns true if the device is running a debuggable build such as "userdebug" or "eng". 1377 * 1378 * Debuggable builds allow users to gain root access via local shell, attach debuggers to any 1379 * application regardless of whether they have the "debuggable" attribute set, or downgrade 1380 * selinux into "permissive" mode in particular. 1381 * @hide 1382 */ 1383 @TestApi 1384 @SystemApi(client = SystemApi.Client.MODULE_LIBRARIES) isDebuggable()1385 public static boolean isDebuggable() { 1386 return IS_DEBUGGABLE; 1387 } 1388 1389 /** {@hide} */ 1390 public static final boolean IS_ENG = "eng".equals(TYPE); 1391 /** {@hide} */ 1392 public static final boolean IS_USERDEBUG = "userdebug".equals(TYPE); 1393 /** {@hide} */ 1394 public static final boolean IS_USER = "user".equals(TYPE); 1395 1396 /** 1397 * Whether this build is running inside a container. 1398 * 1399 * We should try to avoid checking this flag if possible to minimize 1400 * unnecessarily diverging from non-container Android behavior. 1401 * Checking this flag is acceptable when low-level resources being 1402 * different, e.g. the availability of certain capabilities, access to 1403 * system resources being restricted, and the fact that the host OS might 1404 * handle some features for us. 1405 * For higher-level behavior differences, other checks should be preferred. 1406 * @hide 1407 */ 1408 public static final boolean IS_CONTAINER = 1409 SystemProperties.getBoolean("ro.boot.container", false); 1410 1411 /** 1412 * Specifies whether the permissions needed by a legacy app should be 1413 * reviewed before any of its components can run. A legacy app is one 1414 * with targetSdkVersion < 23, i.e apps using the old permission model. 1415 * If review is not required, permissions are reviewed before the app 1416 * is installed. 1417 * 1418 * @hide 1419 * @removed 1420 */ 1421 @SystemApi 1422 public static final boolean PERMISSIONS_REVIEW_REQUIRED = true; 1423 1424 /** 1425 * Returns the version string for the radio firmware. May return 1426 * null (if, for instance, the radio is not currently on). 1427 */ getRadioVersion()1428 public static String getRadioVersion() { 1429 return joinListOrElse(TelephonyProperties.baseband_version(), null); 1430 } 1431 1432 @UnsupportedAppUsage getString(String property)1433 private static String getString(String property) { 1434 return SystemProperties.get(property, UNKNOWN); 1435 } 1436 getStringList(String property, String separator)1437 private static String[] getStringList(String property, String separator) { 1438 String value = SystemProperties.get(property); 1439 if (value.isEmpty()) { 1440 return new String[0]; 1441 } else { 1442 return value.split(separator); 1443 } 1444 } 1445 1446 @UnsupportedAppUsage getLong(String property)1447 private static long getLong(String property) { 1448 try { 1449 return Long.parseLong(SystemProperties.get(property)); 1450 } catch (NumberFormatException e) { 1451 return -1; 1452 } 1453 } 1454 joinListOrElse(List<T> list, String defaultValue)1455 private static <T> String joinListOrElse(List<T> list, String defaultValue) { 1456 String ret = list.stream().map(elem -> elem == null ? "" : elem.toString()) 1457 .collect(Collectors.joining(",")); 1458 return ret.isEmpty() ? defaultValue : ret; 1459 } 1460 } 1461