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