Build.java revision bdd4491b322bebd96b99da508ec7b0b7d59d97ae
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 17package android.os; 18 19import android.text.TextUtils; 20import android.util.Slog; 21 22import com.android.internal.telephony.TelephonyProperties; 23 24/** 25 * Information about the current build, extracted from system properties. 26 */ 27public class Build { 28 private static final String TAG = "Build"; 29 30 /** Value used for when a build property is unknown. */ 31 public static final String UNKNOWN = "unknown"; 32 33 /** Either a changelist number, or a label like "M4-rc20". */ 34 public static final String ID = getString("ro.build.id"); 35 36 /** A build ID string meant for displaying to the user */ 37 public static final String DISPLAY = getString("ro.build.display.id"); 38 39 /** The name of the overall product. */ 40 public static final String PRODUCT = getString("ro.product.name"); 41 42 /** The name of the industrial design. */ 43 public static final String DEVICE = getString("ro.product.device"); 44 45 /** The name of the underlying board, like "goldfish". */ 46 public static final String BOARD = getString("ro.product.board"); 47 48 /** The name of the instruction set (CPU type + ABI convention) of native code. */ 49 public static final String CPU_ABI = getString("ro.product.cpu.abi"); 50 51 /** The name of the second instruction set (CPU type + ABI convention) of native code. */ 52 public static final String CPU_ABI2 = getString("ro.product.cpu.abi2"); 53 54 /** The manufacturer of the product/hardware. */ 55 public static final String MANUFACTURER = getString("ro.product.manufacturer"); 56 57 /** The consumer-visible brand with which the product/hardware will be associated, if any. */ 58 public static final String BRAND = getString("ro.product.brand"); 59 60 /** The end-user-visible name for the end product. */ 61 public static final String MODEL = getString("ro.product.model"); 62 63 /** The system bootloader version number. */ 64 public static final String BOOTLOADER = getString("ro.bootloader"); 65 66 /** 67 * The radio firmware version number. 68 * 69 * @deprecated The radio firmware version is frequently not 70 * available when this class is initialized, leading to a blank or 71 * "unknown" value for this string. Use 72 * {@link #getRadioVersion} instead. 73 */ 74 @Deprecated 75 public static final String RADIO = getString(TelephonyProperties.PROPERTY_BASEBAND_VERSION); 76 77 /** The name of the hardware (from the kernel command line or /proc). */ 78 public static final String HARDWARE = getString("ro.hardware"); 79 80 /** A hardware serial number, if available. Alphanumeric only, case-insensitive. */ 81 public static final String SERIAL = getString("ro.serialno"); 82 83 /** 84 * A list of ABIs (in priority) order supported by this device. 85 * 86 * @hide 87 */ 88 public static final String[] SUPPORTED_ABIS = getString("ro.product.cpu.abilist").split(","); 89 90 /** Various version strings. */ 91 public static class VERSION { 92 /** 93 * The internal value used by the underlying source control to 94 * represent this build. E.g., a perforce changelist number 95 * or a git hash. 96 */ 97 public static final String INCREMENTAL = getString("ro.build.version.incremental"); 98 99 /** 100 * The user-visible version string. E.g., "1.0" or "3.4b5". 101 */ 102 public static final String RELEASE = getString("ro.build.version.release"); 103 104 /** 105 * The user-visible SDK version of the framework in its raw String 106 * representation; use {@link #SDK_INT} instead. 107 * 108 * @deprecated Use {@link #SDK_INT} to easily get this as an integer. 109 */ 110 @Deprecated 111 public static final String SDK = getString("ro.build.version.sdk"); 112 113 /** 114 * The user-visible SDK version of the framework; its possible 115 * values are defined in {@link Build.VERSION_CODES}. 116 */ 117 public static final int SDK_INT = SystemProperties.getInt( 118 "ro.build.version.sdk", 0); 119 120 /** 121 * The current development codename, or the string "REL" if this is 122 * a release build. 123 */ 124 public static final String CODENAME = getString("ro.build.version.codename"); 125 126 private static final String[] ALL_CODENAMES 127 = getString("ro.build.version.all_codenames").split(","); 128 129 /** 130 * @hide 131 */ 132 public static final String[] ACTIVE_CODENAMES = "REL".equals(ALL_CODENAMES[0]) 133 ? new String[0] : ALL_CODENAMES; 134 135 /** 136 * The SDK version to use when accessing resources. 137 * Use the current SDK version code. For every active development codename 138 * we are operating under, we bump the assumed resource platform version by 1. 139 * @hide 140 */ 141 public static final int RESOURCES_SDK_INT = SDK_INT + ACTIVE_CODENAMES.length; 142 } 143 144 /** 145 * Enumeration of the currently known SDK version codes. These are the 146 * values that can be found in {@link VERSION#SDK}. Version numbers 147 * increment monotonically with each official platform release. 148 */ 149 public static class VERSION_CODES { 150 /** 151 * Magic version number for a current development build, which has 152 * not yet turned into an official release. 153 */ 154 public static final int CUR_DEVELOPMENT = 10000; 155 156 /** 157 * October 2008: The original, first, version of Android. Yay! 158 */ 159 public static final int BASE = 1; 160 161 /** 162 * February 2009: First Android update, officially called 1.1. 163 */ 164 public static final int BASE_1_1 = 2; 165 166 /** 167 * May 2009: Android 1.5. 168 */ 169 public static final int CUPCAKE = 3; 170 171 /** 172 * September 2009: Android 1.6. 173 * 174 * <p>Applications targeting this or a later release will get these 175 * new changes in behavior:</p> 176 * <ul> 177 * <li> They must explicitly request the 178 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission to be 179 * able to modify the contents of the SD card. (Apps targeting 180 * earlier versions will always request the permission.) 181 * <li> They must explicitly request the 182 * {@link android.Manifest.permission#READ_PHONE_STATE} permission to be 183 * able to be able to retrieve phone state info. (Apps targeting 184 * earlier versions will always request the permission.) 185 * <li> They are assumed to support different screen densities and 186 * sizes. (Apps targeting earlier versions are assumed to only support 187 * medium density normal size screens unless otherwise indicated). 188 * They can still explicitly specify screen support either way with the 189 * supports-screens manifest tag. 190 * <li> {@link android.widget.TabHost} will use the new dark tab 191 * background design. 192 * </ul> 193 */ 194 public static final int DONUT = 4; 195 196 /** 197 * November 2009: Android 2.0 198 * 199 * <p>Applications targeting this or a later release will get these 200 * new changes in behavior:</p> 201 * <ul> 202 * <li> The {@link android.app.Service#onStartCommand 203 * Service.onStartCommand} function will return the new 204 * {@link android.app.Service#START_STICKY} behavior instead of the 205 * old compatibility {@link android.app.Service#START_STICKY_COMPATIBILITY}. 206 * <li> The {@link android.app.Activity} class will now execute back 207 * key presses on the key up instead of key down, to be able to detect 208 * canceled presses from virtual keys. 209 * <li> The {@link android.widget.TabWidget} class will use a new color scheme 210 * for tabs. In the new scheme, the foreground tab has a medium gray background 211 * the background tabs have a dark gray background. 212 * </ul> 213 */ 214 public static final int ECLAIR = 5; 215 216 /** 217 * December 2009: Android 2.0.1 218 */ 219 public static final int ECLAIR_0_1 = 6; 220 221 /** 222 * January 2010: Android 2.1 223 */ 224 public static final int ECLAIR_MR1 = 7; 225 226 /** 227 * June 2010: Android 2.2 228 */ 229 public static final int FROYO = 8; 230 231 /** 232 * November 2010: Android 2.3 233 * 234 * <p>Applications targeting this or a later release will get these 235 * new changes in behavior:</p> 236 * <ul> 237 * <li> The application's notification icons will be shown on the new 238 * dark status bar background, so must be visible in this situation. 239 * </ul> 240 */ 241 public static final int GINGERBREAD = 9; 242 243 /** 244 * February 2011: Android 2.3.3. 245 */ 246 public static final int GINGERBREAD_MR1 = 10; 247 248 /** 249 * February 2011: Android 3.0. 250 * 251 * <p>Applications targeting this or a later release will get these 252 * new changes in behavior:</p> 253 * <ul> 254 * <li> The default theme for applications is now dark holographic: 255 * {@link android.R.style#Theme_Holo}. 256 * <li> On large screen devices that do not have a physical menu 257 * button, the soft (compatibility) menu is disabled. 258 * <li> The activity lifecycle has changed slightly as per 259 * {@link android.app.Activity}. 260 * <li> An application will crash if it does not call through 261 * to the super implementation of its 262 * {@link android.app.Activity#onPause Activity.onPause()} method. 263 * <li> When an application requires a permission to access one of 264 * its components (activity, receiver, service, provider), this 265 * permission is no longer enforced when the application wants to 266 * access its own component. This means it can require a permission 267 * on a component that it does not itself hold and still access that 268 * component. 269 * <li> {@link android.content.Context#getSharedPreferences 270 * Context.getSharedPreferences()} will not automatically reload 271 * the preferences if they have changed on storage, unless 272 * {@link android.content.Context#MODE_MULTI_PROCESS} is used. 273 * <li> {@link android.view.ViewGroup#setMotionEventSplittingEnabled} 274 * will default to true. 275 * <li> {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH} 276 * is enabled by default on windows. 277 * <li> {@link android.widget.PopupWindow#isSplitTouchEnabled() 278 * PopupWindow.isSplitTouchEnabled()} will return true by default. 279 * <li> {@link android.widget.GridView} and {@link android.widget.ListView} 280 * will use {@link android.view.View#setActivated View.setActivated} 281 * for selected items if they do not implement {@link android.widget.Checkable}. 282 * <li> {@link android.widget.Scroller} will be constructed with 283 * "flywheel" behavior enabled by default. 284 * </ul> 285 */ 286 public static final int HONEYCOMB = 11; 287 288 /** 289 * May 2011: Android 3.1. 290 */ 291 public static final int HONEYCOMB_MR1 = 12; 292 293 /** 294 * June 2011: Android 3.2. 295 * 296 * <p>Update to Honeycomb MR1 to support 7 inch tablets, improve 297 * screen compatibility mode, etc.</p> 298 * 299 * <p>As of this version, applications that don't say whether they 300 * support XLARGE screens will be assumed to do so only if they target 301 * {@link #HONEYCOMB} or later; it had been {@link #GINGERBREAD} or 302 * later. Applications that don't support a screen size at least as 303 * large as the current screen will provide the user with a UI to 304 * switch them in to screen size compatibility mode.</p> 305 * 306 * <p>This version introduces new screen size resource qualifiers 307 * based on the screen size in dp: see 308 * {@link android.content.res.Configuration#screenWidthDp}, 309 * {@link android.content.res.Configuration#screenHeightDp}, and 310 * {@link android.content.res.Configuration#smallestScreenWidthDp}. 311 * Supplying these in <supports-screens> as per 312 * {@link android.content.pm.ApplicationInfo#requiresSmallestWidthDp}, 313 * {@link android.content.pm.ApplicationInfo#compatibleWidthLimitDp}, and 314 * {@link android.content.pm.ApplicationInfo#largestWidthLimitDp} is 315 * preferred over the older screen size buckets and for older devices 316 * the appropriate buckets will be inferred from them.</p> 317 * 318 * <p>Applications targeting this or a later release will get these 319 * new changes in behavior:</p> 320 * <ul> 321 * <li><p>New {@link android.content.pm.PackageManager#FEATURE_SCREEN_PORTRAIT} 322 * and {@link android.content.pm.PackageManager#FEATURE_SCREEN_LANDSCAPE} 323 * features were introduced in this release. Applications that target 324 * previous platform versions are assumed to require both portrait and 325 * landscape support in the device; when targeting Honeycomb MR1 or 326 * greater the application is responsible for specifying any specific 327 * orientation it requires.</p> 328 * <li><p>{@link android.os.AsyncTask} will use the serial executor 329 * by default when calling {@link android.os.AsyncTask#execute}.</p> 330 * <li><p>{@link android.content.pm.ActivityInfo#configChanges 331 * ActivityInfo.configChanges} will have the 332 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE} and 333 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE} 334 * bits set; these need to be cleared for older applications because 335 * some developers have done absolute comparisons against this value 336 * instead of correctly masking the bits they are interested in. 337 * </ul> 338 */ 339 public static final int HONEYCOMB_MR2 = 13; 340 341 /** 342 * October 2011: Android 4.0. 343 * 344 * <p>Applications targeting this or a later release will get these 345 * new changes in behavior:</p> 346 * <ul> 347 * <li> For devices without a dedicated menu key, the software compatibility 348 * menu key will not be shown even on phones. By targeting Ice Cream Sandwich 349 * or later, your UI must always have its own menu UI affordance if needed, 350 * on both tablets and phones. The ActionBar will take care of this for you. 351 * <li> 2d drawing hardware acceleration is now turned on by default. 352 * You can use 353 * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated} 354 * to turn it off if needed, although this is strongly discouraged since 355 * it will result in poor performance on larger screen devices. 356 * <li> The default theme for applications is now the "device default" theme: 357 * {@link android.R.style#Theme_DeviceDefault}. This may be the 358 * holo dark theme or a different dark theme defined by the specific device. 359 * The {@link android.R.style#Theme_Holo} family must not be modified 360 * for a device to be considered compatible. Applications that explicitly 361 * request a theme from the Holo family will be guaranteed that these themes 362 * will not change character within the same platform version. Applications 363 * that wish to blend in with the device should use a theme from the 364 * {@link android.R.style#Theme_DeviceDefault} family. 365 * <li> Managed cursors can now throw an exception if you directly close 366 * the cursor yourself without stopping the management of it; previously failures 367 * would be silently ignored. 368 * <li> The fadingEdge attribute on views will be ignored (fading edges is no 369 * longer a standard part of the UI). A new requiresFadingEdge attribute allows 370 * applications to still force fading edges on for special cases. 371 * <li> {@link android.content.Context#bindService Context.bindService()} 372 * will not automatically add in {@link android.content.Context#BIND_WAIVE_PRIORITY}. 373 * <li> App Widgets will have standard padding automatically added around 374 * them, rather than relying on the padding being baked into the widget itself. 375 * <li> An exception will be thrown if you try to change the type of a 376 * window after it has been added to the window manager. Previously this 377 * would result in random incorrect behavior. 378 * <li> {@link android.view.animation.AnimationSet} will parse out 379 * the duration, fillBefore, fillAfter, repeatMode, and startOffset 380 * XML attributes that are defined. 381 * <li> {@link android.app.ActionBar#setHomeButtonEnabled 382 * ActionBar.setHomeButtonEnabled()} is false by default. 383 * </ul> 384 */ 385 public static final int ICE_CREAM_SANDWICH = 14; 386 387 /** 388 * December 2011: Android 4.0.3. 389 */ 390 public static final int ICE_CREAM_SANDWICH_MR1 = 15; 391 392 /** 393 * June 2012: Android 4.1. 394 * 395 * <p>Applications targeting this or a later release will get these 396 * new changes in behavior:</p> 397 * <ul> 398 * <li> You must explicitly request the {@link android.Manifest.permission#READ_CALL_LOG} 399 * and/or {@link android.Manifest.permission#WRITE_CALL_LOG} permissions; 400 * access to the call log is no longer implicitly provided through 401 * {@link android.Manifest.permission#READ_CONTACTS} and 402 * {@link android.Manifest.permission#WRITE_CONTACTS}. 403 * <li> {@link android.widget.RemoteViews} will throw an exception if 404 * setting an onClick handler for views being generated by a 405 * {@link android.widget.RemoteViewsService} for a collection container; 406 * previously this just resulted in a warning log message. 407 * <li> New {@link android.app.ActionBar} policy for embedded tabs: 408 * embedded tabs are now always stacked in the action bar when in portrait 409 * mode, regardless of the size of the screen. 410 * <li> {@link android.webkit.WebSettings#setAllowFileAccessFromFileURLs(boolean) 411 * WebSettings.setAllowFileAccessFromFileURLs} and 412 * {@link android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs(boolean) 413 * WebSettings.setAllowUniversalAccessFromFileURLs} default to false. 414 * <li> Calls to {@link android.content.pm.PackageManager#setComponentEnabledSetting 415 * PackageManager.setComponentEnabledSetting} will now throw an 416 * IllegalArgumentException if the given component class name does not 417 * exist in the application's manifest. 418 * <li> {@link android.nfc.NfcAdapter#setNdefPushMessage 419 * NfcAdapter.setNdefPushMessage}, 420 * {@link android.nfc.NfcAdapter#setNdefPushMessageCallback 421 * NfcAdapter.setNdefPushMessageCallback} and 422 * {@link android.nfc.NfcAdapter#setOnNdefPushCompleteCallback 423 * NfcAdapter.setOnNdefPushCompleteCallback} will throw 424 * IllegalStateException if called after the Activity has been destroyed. 425 * <li> Accessibility services must require the new 426 * {@link android.Manifest.permission#BIND_ACCESSIBILITY_SERVICE} permission or 427 * they will not be available for use. 428 * <li> {@link android.accessibilityservice.AccessibilityServiceInfo#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS 429 * AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS} must be set 430 * for unimportant views to be included in queries. 431 * </ul> 432 */ 433 public static final int JELLY_BEAN = 16; 434 435 /** 436 * Android 4.2: Moar jelly beans! 437 * 438 * <p>Applications targeting this or a later release will get these 439 * new changes in behavior:</p> 440 * <ul> 441 * <li>Content Providers: The default value of {@code android:exported} is now 442 * {@code false}. See 443 * <a href="{@docRoot}guide/topics/manifest/provider-element.html#exported"> 444 * the android:exported section</a> in the provider documentation for more details.</li> 445 * <li>{@link android.view.View#getLayoutDirection() View.getLayoutDirection()} 446 * can return different values than {@link android.view.View#LAYOUT_DIRECTION_LTR} 447 * based on the locale etc. 448 * <li> {@link android.webkit.WebView#addJavascriptInterface(Object, String) 449 * WebView.addJavascriptInterface} requires explicit annotations on methods 450 * for them to be accessible from Javascript. 451 * </ul> 452 */ 453 public static final int JELLY_BEAN_MR1 = 17; 454 455 /** 456 * Android 4.3: Jelly Bean MR2, the revenge of the beans. 457 */ 458 public static final int JELLY_BEAN_MR2 = 18; 459 460 /** 461 * Android 4.4: KitKat, another tasty treat. 462 * 463 * <p>Applications targeting this or a later release will get these 464 * new changes in behavior:</p> 465 * <ul> 466 * <li> The default result of {android.preference.PreferenceActivity#isValidFragment 467 * PreferenceActivity.isValueFragment} becomes false instead of true.</li> 468 * <li> In {@link android.webkit.WebView}, apps targeting earlier versions will have 469 * JS URLs evaluated directly and any result of the evaluation will not replace 470 * the current page content. Apps targetting KITKAT or later that load a JS URL will 471 * have the result of that URL replace the content of the current page</li> 472 * <li> {@link android.app.AlarmManager#set AlarmManager.set} becomes interpreted as 473 * an inexact value, to give the system more flexibility in scheduling alarms.</li> 474 * <li> {@link android.content.Context#getSharedPreferences(String, int) 475 * Context.getSharedPreferences} no longer allows a null name.</li> 476 * <li> {@link android.widget.RelativeLayout} changes to compute wrapped content 477 * margins correctly.</li> 478 * <li> {@link android.app.ActionBar}'s window content overlay is allowed to be 479 * drawn.</li> 480 * <li>The {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} 481 * permission is now always enforced.</li> 482 * <li>Access to package-specific external storage directories belonging 483 * to the calling app no longer requires the 484 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} or 485 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} 486 * permissions.</li> 487 * </ul> 488 */ 489 public static final int KITKAT = 19; 490 491 /** 492 * Android 4.5: KitKat for watches, snacks on the run. 493 */ 494 public static final int KITKAT_WATCH = CUR_DEVELOPMENT; // STOPSHIP: update API level 495 496 /** 497 * L! 498 * 499 * <p>Applications targeting this or a later release will get these 500 * new changes in behavior:</p> 501 * <ul> 502 * <li> {@link android.content.Context#bindService Context.bindService} now 503 * requires an explicit Intent, and will throw an exception if given an implicit 504 * Intent.</li> 505 * </ul> 506 */ 507 public static final int L = CUR_DEVELOPMENT; 508 } 509 510 /** The type of build, like "user" or "eng". */ 511 public static final String TYPE = getString("ro.build.type"); 512 513 /** Comma-separated tags describing the build, like "unsigned,debug". */ 514 public static final String TAGS = getString("ro.build.tags"); 515 516 /** A string that uniquely identifies this build. Do not attempt to parse this value. */ 517 public static final String FINGERPRINT = deriveFingerprint(); 518 519 /** 520 * Some devices split the fingerprint components between multiple 521 * partitions, so we might derive the fingerprint at runtime. 522 */ 523 private static String deriveFingerprint() { 524 String finger = SystemProperties.get("ro.build.fingerprint"); 525 if (TextUtils.isEmpty(finger)) { 526 finger = getString("ro.product.brand") + '/' + 527 getString("ro.product.name") + '/' + 528 getString("ro.product.device") + ':' + 529 getString("ro.build.version.release") + '/' + 530 getString("ro.build.id") + '/' + 531 getString("ro.build.version.incremental") + ':' + 532 getString("ro.build.type") + '/' + 533 getString("ro.build.tags"); 534 } 535 return finger; 536 } 537 538 /** 539 * Ensure that raw fingerprint system property is defined. If it was derived 540 * dynamically by {@link #deriveFingerprint()} this is where we push the 541 * derived value into the property service. 542 * 543 * @hide 544 */ 545 public static void ensureFingerprintProperty() { 546 if (TextUtils.isEmpty(SystemProperties.get("ro.build.fingerprint"))) { 547 try { 548 SystemProperties.set("ro.build.fingerprint", FINGERPRINT); 549 } catch (IllegalArgumentException e) { 550 Slog.e(TAG, "Failed to set fingerprint property", e); 551 } 552 } 553 } 554 555 // The following properties only make sense for internal engineering builds. 556 public static final long TIME = getLong("ro.build.date.utc") * 1000; 557 public static final String USER = getString("ro.build.user"); 558 public static final String HOST = getString("ro.build.host"); 559 560 /** 561 * Returns true if we are running a debug build such as "user-debug" or "eng". 562 * @hide 563 */ 564 public static final boolean IS_DEBUGGABLE = 565 SystemProperties.getInt("ro.debuggable", 0) == 1; 566 567 /** 568 * Returns the version string for the radio firmware. May return 569 * null (if, for instance, the radio is not currently on). 570 */ 571 public static String getRadioVersion() { 572 return SystemProperties.get(TelephonyProperties.PROPERTY_BASEBAND_VERSION, null); 573 } 574 575 private static String getString(String property) { 576 return SystemProperties.get(property, UNKNOWN); 577 } 578 579 private static long getLong(String property) { 580 try { 581 return Long.parseLong(SystemProperties.get(property)); 582 } catch (NumberFormatException e) { 583 return -1; 584 } 585 } 586} 587