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