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