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