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