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