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