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