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