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