blob: 64c6cbc65b5d9ea6694ec45ec2ce35d05a032c19 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.os;
18
Svet Ganov37e43272016-09-09 16:01:32 -070019import android.Manifest;
Anton Hansson81f76a02018-10-04 18:40:22 +010020import android.annotation.NonNull;
Svet Ganov37e43272016-09-09 16:01:32 -070021import android.annotation.RequiresPermission;
Michael Groover6d20d752018-10-01 16:14:50 -070022import android.annotation.SuppressAutoDoc;
Svet Ganovae0e03a2016-02-25 18:22:10 -080023import android.annotation.SystemApi;
Dianne Hackborn337e01a2018-02-27 17:16:37 -080024import android.annotation.TestApi;
Michael Groover6d20d752018-10-01 16:14:50 -070025import android.app.ActivityThread;
Dianne Hackborna47d0452017-11-21 15:04:57 -080026import android.app.Application;
Artur Satayevafdb23a2019-12-10 17:47:53 +000027import android.compat.annotation.UnsupportedAppUsage;
Svet Ganov37e43272016-09-09 16:01:32 -070028import android.content.Context;
Inseob Kim1b5e2412019-11-08 15:06:37 +090029import android.sysprop.TelephonyProperties;
Jeff Sharkey55687722014-04-09 18:07:19 -070030import android.text.TextUtils;
Jeff Sharkeybdd44912014-04-11 16:30:14 -070031import android.util.Slog;
kanewang(43918)25106a92020-11-02 13:38:27 +080032import android.util.Log;
Dianne Hackborna47d0452017-11-21 15:04:57 -080033import android.view.View;
Jeff Sharkey55687722014-04-09 18:07:19 -070034
Narayan Kamatheff258c2014-09-30 13:20:57 +010035import dalvik.system.VMRuntime;
Doug Zongkerad2171a2011-06-14 11:07:24 -070036
Anton Hansson91b54f12018-09-24 18:24:19 +010037import java.util.ArrayList;
38import java.util.List;
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -080039import java.util.Objects;
Inseob Kim1b5e2412019-11-08 15:06:37 +090040import java.util.stream.Collectors;
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -080041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042/**
43 * Information about the current build, extracted from system properties.
44 */
45public class Build {
Jeff Sharkeybdd44912014-04-11 16:30:14 -070046 private static final String TAG = "Build";
47
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080048 /** Value used for when a build property is unknown. */
Ficus Kirkpatrick71de7852010-01-08 13:10:51 -080049 public static final String UNKNOWN = "unknown";
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050
51 /** Either a changelist number, or a label like "M4-rc20". */
52 public static final String ID = getString("ro.build.id");
53
54 /** A build ID string meant for displaying to the user */
55 public static final String DISPLAY = getString("ro.build.display.id");
56
57 /** The name of the overall product. */
58 public static final String PRODUCT = getString("ro.product.name");
59
60 /** The name of the industrial design. */
61 public static final String DEVICE = getString("ro.product.device");
62
63 /** The name of the underlying board, like "goldfish". */
64 public static final String BOARD = getString("ro.product.board");
65
Narayan Kamath1adf4002014-07-12 11:46:37 +010066 /**
67 * The name of the instruction set (CPU type + ABI convention) of native code.
68 *
69 * @deprecated Use {@link #SUPPORTED_ABIS} instead.
70 */
71 @Deprecated
Narayan Kamatheff258c2014-09-30 13:20:57 +010072 public static final String CPU_ABI;
Dianne Hackbornb1811182009-05-21 15:45:42 -070073
Narayan Kamath1adf4002014-07-12 11:46:37 +010074 /**
75 * The name of the second instruction set (CPU type + ABI convention) of native code.
76 *
77 * @deprecated Use {@link #SUPPORTED_ABIS} instead.
78 */
79 @Deprecated
Narayan Kamatheff258c2014-09-30 13:20:57 +010080 public static final String CPU_ABI2;
Ficus Kirkpatrickfa9cafa2010-01-06 17:37:13 -080081
Dianne Hackbornd62ad4f2009-05-19 19:06:25 -070082 /** The manufacturer of the product/hardware. */
83 public static final String MANUFACTURER = getString("ro.product.manufacturer");
84
Dirk Dougherty491b40d2013-10-29 18:33:29 -070085 /** The consumer-visible brand with which the product/hardware will be associated, if any. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086 public static final String BRAND = getString("ro.product.brand");
87
88 /** The end-user-visible name for the end product. */
89 public static final String MODEL = getString("ro.product.model");
90
Doug Zongker74885ef2010-02-02 17:39:26 -080091 /** The system bootloader version number. */
Dan Egnor42471dd2010-01-07 17:25:22 -080092 public static final String BOOTLOADER = getString("ro.bootloader");
93
Doug Zongkerad2171a2011-06-14 11:07:24 -070094 /**
95 * The radio firmware version number.
96 *
97 * @deprecated The radio firmware version is frequently not
98 * available when this class is initialized, leading to a blank or
99 * "unknown" value for this string. Use
100 * {@link #getRadioVersion} instead.
101 */
102 @Deprecated
Inseob Kim1b5e2412019-11-08 15:06:37 +0900103 public static final String RADIO = joinListOrElse(
104 TelephonyProperties.baseband_version(), UNKNOWN);
Dan Egnor42471dd2010-01-07 17:25:22 -0800105
Doug Zongker74885ef2010-02-02 17:39:26 -0800106 /** The name of the hardware (from the kernel command line or /proc). */
107 public static final String HARDWARE = getString("ro.hardware");
Dan Egnor42471dd2010-01-07 17:25:22 -0800108
Griff Hazend3c454d2016-03-25 07:30:34 -0700109 /**
110 * Whether this build was for an emulator device.
111 * @hide
112 */
Artur Satayevf0b7d0b2019-11-04 11:16:45 +0000113 @UnsupportedAppUsage
Wale Ogunwale691af682019-02-11 03:09:10 -0800114 @TestApi
Griff Hazend3c454d2016-03-25 07:30:34 -0700115 public static final boolean IS_EMULATOR = getString("ro.kernel.qemu").equals("1");
116
Svet Ganov37e43272016-09-09 16:01:32 -0700117 /**
118 * A hardware serial number, if available. Alphanumeric only, case-insensitive.
Michael Groover1279ff92019-05-29 14:19:16 -0700119 * This field is always set to {@link Build#UNKNOWN}.
Svet Ganov37e43272016-09-09 16:01:32 -0700120 *
121 * @deprecated Use {@link #getSerial()} instead.
122 **/
123 @Deprecated
124 // IMPORTANT: This field should be initialized via a function call to
125 // prevent its value being inlined in the app during compilation because
126 // we will later set it to the value based on the app's target SDK.
127 public static final String SERIAL = getString("no.such.thing");
128
129 /**
Kevin Hufnagled6ebb552017-05-16 16:48:10 -0700130 * Gets the hardware serial number, if available.
131 *
132 * <p class="note"><b>Note:</b> Root access may allow you to modify device identifiers, such as
133 * the hardware serial number. If you change these identifiers, you can use
134 * <a href="/training/articles/security-key-attestation.html">key attestation</a> to obtain
135 * proof of the device's original identifiers.
136 *
Michael Groovere0de0182020-06-23 19:45:14 -0700137 * <p>Starting with API level 29, persistent device identifiers are guarded behind additional
138 * restrictions, and apps are recommended to use resettable identifiers (see <a
Michael Groover1aef2062020-09-21 15:27:52 -0700139 * href="/training/articles/user-data-ids">Best practices for unique identifiers</a>). This
140 * method can be invoked if one of the following requirements is met:
Michael Groovere0de0182020-06-23 19:45:14 -0700141 * <ul>
142 * <li>If the calling app has been granted the READ_PRIVILEGED_PHONE_STATE permission; this
143 * is a privileged permission that can only be granted to apps preloaded on the device.
144 * <li>If the calling app is the device or profile owner and has been granted the
145 * {@link Manifest.permission#READ_PHONE_STATE} permission. The profile owner is an app that
146 * owns a managed profile on the device; for more details see <a
147 * href="https://developer.android.com/work/managed-profiles">Work profiles</a>.
148 * Profile owner access is deprecated and will be removed in a future release.
149 * <li>If the calling app has carrier privileges (see {@link
150 * android.telephony.TelephonyManager#hasCarrierPrivileges}) on any active subscription.
151 * <li>If the calling app is the default SMS role holder (see {@link
152 * android.app.role.RoleManager#isRoleHeld(String)}).
153 * </ul>
Michael Groover6d20d752018-10-01 16:14:50 -0700154 *
Michael Grooverb0401fb2019-05-09 19:35:16 -0700155 * <p>If the calling app does not meet one of these requirements then this method will behave
156 * as follows:
157 *
158 * <ul>
159 * <li>If the calling app's target SDK is API level 28 or lower and the app has the
160 * READ_PHONE_STATE permission then {@link Build#UNKNOWN} is returned.</li>
161 * <li>If the calling app's target SDK is API level 28 or lower and the app does not have
162 * the READ_PHONE_STATE permission, or if the calling app is targeting API level 29 or
163 * higher, then a SecurityException is thrown.</li>
164 * </ul>
Michael Groovere0de0182020-06-23 19:45:14 -0700165 *
Kevin Hufnagled6ebb552017-05-16 16:48:10 -0700166 * @return The serial number if specified.
Svet Ganov37e43272016-09-09 16:01:32 -0700167 */
Michael Groover6d20d752018-10-01 16:14:50 -0700168 @SuppressAutoDoc // No support for device / profile owner.
169 @RequiresPermission(Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
Svet Ganov37e43272016-09-09 16:01:32 -0700170 public static String getSerial() {
171 IDeviceIdentifiersPolicyService service = IDeviceIdentifiersPolicyService.Stub
172 .asInterface(ServiceManager.getService(Context.DEVICE_IDENTIFIERS_SERVICE));
173 try {
Michael Groover6d20d752018-10-01 16:14:50 -0700174 Application application = ActivityThread.currentApplication();
175 String callingPackage = application != null ? application.getPackageName() : null;
Philip P. Moltmann33692f72019-10-03 11:56:11 -0700176 return service.getSerialForPackage(callingPackage, null);
Svet Ganov37e43272016-09-09 16:01:32 -0700177 } catch (RemoteException e) {
178 e.rethrowFromSystemServer();
179 }
180 return UNKNOWN;
181 }
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000182
183 /**
Narayan Kamath0f206a12014-04-12 11:41:13 +0100184 * An ordered list of ABIs supported by this device. The most preferred ABI is the first
185 * element in the list.
186 *
187 * See {@link #SUPPORTED_32_BIT_ABIS} and {@link #SUPPORTED_64_BIT_ABIS}.
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000188 */
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100189 public static final String[] SUPPORTED_ABIS = getStringList("ro.product.cpu.abilist", ",");
Ramin Zaghi1378aba2014-02-28 15:03:19 +0000190
Narayan Kamath0f206a12014-04-12 11:41:13 +0100191 /**
192 * An ordered list of <b>32 bit</b> ABIs supported by this device. The most preferred ABI
193 * is the first element in the list.
194 *
195 * See {@link #SUPPORTED_ABIS} and {@link #SUPPORTED_64_BIT_ABIS}.
Narayan Kamath0f206a12014-04-12 11:41:13 +0100196 */
Torne (Richard Coles)da8c0372014-05-14 16:17:26 +0100197 public static final String[] SUPPORTED_32_BIT_ABIS =
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100198 getStringList("ro.product.cpu.abilist32", ",");
Narayan Kamath0f206a12014-04-12 11:41:13 +0100199
200 /**
201 * An ordered list of <b>64 bit</b> ABIs supported by this device. The most preferred ABI
202 * is the first element in the list.
203 *
204 * See {@link #SUPPORTED_ABIS} and {@link #SUPPORTED_32_BIT_ABIS}.
Narayan Kamath0f206a12014-04-12 11:41:13 +0100205 */
Torne (Richard Coles)da8c0372014-05-14 16:17:26 +0100206 public static final String[] SUPPORTED_64_BIT_ABIS =
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100207 getStringList("ro.product.cpu.abilist64", ",");
Narayan Kamath0f206a12014-04-12 11:41:13 +0100208
Jeff Sharkeyc6091162018-06-29 17:15:40 -0600209 /** {@hide} */
210 @TestApi
211 public static boolean is64BitAbi(String abi) {
212 return VMRuntime.is64BitAbi(abi);
213 }
Narayan Kamath0f206a12014-04-12 11:41:13 +0100214
Narayan Kamatheff258c2014-09-30 13:20:57 +0100215 static {
216 /*
217 * Adjusts CPU_ABI and CPU_ABI2 depending on whether or not a given process is 64 bit.
218 * 32 bit processes will always see 32 bit ABIs in these fields for backward
219 * compatibility.
220 */
221 final String[] abiList;
222 if (VMRuntime.getRuntime().is64Bit()) {
223 abiList = SUPPORTED_64_BIT_ABIS;
224 } else {
225 abiList = SUPPORTED_32_BIT_ABIS;
226 }
227
228 CPU_ABI = abiList[0];
229 if (abiList.length > 1) {
230 CPU_ABI2 = abiList[1];
231 } else {
232 CPU_ABI2 = "";
233 }
234 }
235
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800236 /** Various version strings. */
237 public static class VERSION {
238 /**
239 * The internal value used by the underlying source control to
240 * represent this build. E.g., a perforce changelist number
241 * or a git hash.
242 */
243 public static final String INCREMENTAL = getString("ro.build.version.incremental");
244
245 /**
Daniel Colascioned1520aa2018-04-06 08:12:05 -0700246 * The user-visible version string. E.g., "1.0" or "3.4b5" or "bananas".
247 *
248 * This field is an opaque string. Do not assume that its value
249 * has any particular structure or that values of RELEASE from
250 * different releases can be somehow ordered.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800251 */
252 public static final String RELEASE = getString("ro.build.version.release");
253
254 /**
Dianne Hackborndb007452019-10-28 16:34:22 -0700255 * The version string we show to the user; may be {@link #RELEASE} or
256 * {@link #CODENAME} if not a final release build.
257 */
258 @NonNull public static final String RELEASE_OR_CODENAME = getString(
259 "ro.build.version.release_or_codename");
260
261 /**
Dianne Hackbornc3f74492015-08-12 16:10:58 -0700262 * The base OS build the product is based on.
263 */
264 public static final String BASE_OS = SystemProperties.get("ro.build.version.base_os", "");
265
266 /**
Kevin Hufnagled9c7b442019-09-20 00:58:45 +0000267 * The user-visible security patch level. This value represents the date when the device
268 * most recently applied a security patch.
Dianne Hackbornc3f74492015-08-12 16:10:58 -0700269 */
270 public static final String SECURITY_PATCH = SystemProperties.get(
271 "ro.build.version.security_patch", "");
272
273 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700274 * The user-visible SDK version of the framework in its raw String
275 * representation; use {@link #SDK_INT} instead.
Andres Moralescb3fd692015-01-14 10:07:55 -0800276 *
Dianne Hackborn851a5412009-05-08 12:06:44 -0700277 * @deprecated Use {@link #SDK_INT} to easily get this as an integer.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278 */
Dianne Hackborn4a51c202009-08-21 15:14:02 -0700279 @Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800280 public static final String SDK = getString("ro.build.version.sdk");
Dianne Hackborn851a5412009-05-08 12:06:44 -0700281
282 /**
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700283 * The SDK version of the software currently running on this hardware
284 * device. This value never changes while a device is booted, but it may
285 * increase when the hardware manufacturer provides an OTA update.
286 * <p>
287 * Possible values are defined in {@link Build.VERSION_CODES}.
Dianne Hackborn851a5412009-05-08 12:06:44 -0700288 */
289 public static final int SDK_INT = SystemProperties.getInt(
290 "ro.build.version.sdk", 0);
291
292 /**
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700293 * The SDK version of the software that <em>initially</em> shipped on
294 * this hardware device. It <em>never</em> changes during the lifetime
295 * of the device, even when {@link #SDK_INT} increases due to an OTA
296 * update.
297 * <p>
298 * Possible values are defined in {@link Build.VERSION_CODES}.
299 *
300 * @see #SDK_INT
Jeff Sharkey1da8bb12018-03-26 12:50:54 -0600301 * @hide
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700302 */
Jeff Sharkey1da8bb12018-03-26 12:50:54 -0600303 @TestApi
Jeff Sharkey28c660f2017-12-12 13:51:32 -0700304 public static final int FIRST_SDK_INT = SystemProperties
305 .getInt("ro.product.first_api_level", 0);
306
307 /**
Adam Powelle9600302015-05-06 18:13:09 -0700308 * The developer preview revision of a prerelease SDK. This value will always
309 * be <code>0</code> on production platform builds/devices.
310 *
311 * <p>When this value is nonzero, any new API added since the last
312 * officially published {@link #SDK_INT API level} is only guaranteed to be present
313 * on that specific preview revision. For example, an API <code>Activity.fooBar()</code>
314 * might be present in preview revision 1 but renamed or removed entirely in
315 * preview revision 2, which may cause an app attempting to call it to crash
316 * at runtime.</p>
317 *
318 * <p>Experimental apps targeting preview APIs should check this value for
319 * equality (<code>==</code>) with the preview SDK revision they were built for
320 * before using any prerelease platform APIs. Apps that detect a preview SDK revision
321 * other than the specific one they expect should fall back to using APIs from
322 * the previously published API level only to avoid unwanted runtime exceptions.
323 * </p>
324 */
325 public static final int PREVIEW_SDK_INT = SystemProperties.getInt(
326 "ro.build.version.preview_sdk", 0);
327
328 /**
Narayan Kamathb081e072018-12-13 19:09:20 +0000329 * The SDK fingerprint for a given prerelease SDK. This value will always be
330 * {@code REL} on production platform builds/devices.
331 *
332 * <p>When this value is not {@code REL}, it contains a string fingerprint of the API
333 * surface exposed by the preview SDK. Preview platforms with different API surfaces
334 * will have different {@code PREVIEW_SDK_FINGERPRINT}.
335 *
336 * <p>This attribute is intended for use by installers for finer grained targeting of
337 * packages. Applications targeting preview APIs should not use this field and should
338 * instead use {@code PREVIEW_SDK_INT} or use reflection or other runtime checks to
339 * detect the presence of an API or guard themselves against unexpected runtime
340 * behavior.
341 *
342 * @hide
343 */
344 @SystemApi
Narayan Kamath714bf492019-03-08 17:08:07 +0000345 @NonNull public static final String PREVIEW_SDK_FINGERPRINT = SystemProperties.get(
Narayan Kamathb081e072018-12-13 19:09:20 +0000346 "ro.build.version.preview_sdk_fingerprint", "REL");
347
348 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700349 * The current development codename, or the string "REL" if this is
350 * a release build.
351 */
352 public static final String CODENAME = getString("ro.build.version.codename");
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800353
Dianne Hackbornffcda102014-04-24 13:06:27 -0700354 private static final String[] ALL_CODENAMES
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +0100355 = getStringList("ro.build.version.all_codenames", ",");
Dianne Hackbornffcda102014-04-24 13:06:27 -0700356
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800357 /**
Dianne Hackborn3b81bc12011-01-15 11:50:52 -0800358 * @hide
359 */
Andrei Onea24ec3212019-03-15 17:35:05 +0000360 @UnsupportedAppUsage
Artur Satayevf0b7d0b2019-11-04 11:16:45 +0000361 @TestApi
Dianne Hackbornffcda102014-04-24 13:06:27 -0700362 public static final String[] ACTIVE_CODENAMES = "REL".equals(ALL_CODENAMES[0])
363 ? new String[0] : ALL_CODENAMES;
364
365 /**
366 * The SDK version to use when accessing resources.
367 * Use the current SDK version code. For every active development codename
368 * we are operating under, we bump the assumed resource platform version by 1.
369 * @hide
370 */
Dianne Hackborn337e01a2018-02-27 17:16:37 -0800371 @TestApi
Dianne Hackbornffcda102014-04-24 13:06:27 -0700372 public static final int RESOURCES_SDK_INT = SDK_INT + ACTIVE_CODENAMES.length;
Przemyslaw Szczepaniak73b6bc82017-12-05 11:07:30 +0000373
374 /**
375 * The current lowest supported value of app target SDK. Applications targeting
Narayan Kamath91c361d2018-03-26 18:31:33 +0100376 * lower values may not function on devices running this SDK version. Its possible
377 * values are defined in {@link Build.VERSION_CODES}.
378 *
379 * @hide
Przemyslaw Szczepaniak73b6bc82017-12-05 11:07:30 +0000380 */
381 public static final int MIN_SUPPORTED_TARGET_SDK_INT = SystemProperties.getInt(
382 "ro.build.version.min_supported_target_sdk", 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800383 }
384
Dianne Hackborn851a5412009-05-08 12:06:44 -0700385 /**
386 * Enumeration of the currently known SDK version codes. These are the
387 * values that can be found in {@link VERSION#SDK}. Version numbers
388 * increment monotonically with each official platform release.
389 */
390 public static class VERSION_CODES {
391 /**
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700392 * Magic version number for a current development build, which has
393 * not yet turned into an official release.
394 */
Tobias Thierer8bacd9b2017-02-15 20:38:29 +0000395 public static final int CUR_DEVELOPMENT = VMRuntime.SDK_VERSION_CUR_DEVELOPMENT;
Andres Moralescb3fd692015-01-14 10:07:55 -0800396
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700397 /**
Dianne Hackborn851a5412009-05-08 12:06:44 -0700398 * October 2008: The original, first, version of Android. Yay!
399 */
400 public static final int BASE = 1;
Andres Moralescb3fd692015-01-14 10:07:55 -0800401
Dianne Hackborn851a5412009-05-08 12:06:44 -0700402 /**
403 * February 2009: First Android update, officially called 1.1.
404 */
405 public static final int BASE_1_1 = 2;
Andres Moralescb3fd692015-01-14 10:07:55 -0800406
Dianne Hackborn851a5412009-05-08 12:06:44 -0700407 /**
408 * May 2009: Android 1.5.
409 */
410 public static final int CUPCAKE = 3;
Andres Moralescb3fd692015-01-14 10:07:55 -0800411
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700412 /**
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700413 * September 2009: Android 1.6.
Andres Moralescb3fd692015-01-14 10:07:55 -0800414 *
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700415 * <p>Applications targeting this or a later release will get these
416 * new changes in behavior:</p>
417 * <ul>
418 * <li> They must explicitly request the
San Mehat5a3a77d2009-06-01 09:25:28 -0700419 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE} permission to be
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700420 * able to modify the contents of the SD card. (Apps targeting
421 * earlier versions will always request the permission.)
Dianne Hackbornfe77ec82009-08-12 16:53:56 -0700422 * <li> They must explicitly request the
423 * {@link android.Manifest.permission#READ_PHONE_STATE} permission to be
424 * able to be able to retrieve phone state info. (Apps targeting
425 * earlier versions will always request the permission.)
426 * <li> They are assumed to support different screen densities and
427 * sizes. (Apps targeting earlier versions are assumed to only support
428 * medium density normal size screens unless otherwise indicated).
429 * They can still explicitly specify screen support either way with the
430 * supports-screens manifest tag.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700431 * <li> {@link android.widget.TabHost} will use the new dark tab
432 * background design.
Dianne Hackborna96cbb42009-05-13 15:06:13 -0700433 * </ul>
434 */
Dianne Hackbornfe77ec82009-08-12 16:53:56 -0700435 public static final int DONUT = 4;
Andres Moralescb3fd692015-01-14 10:07:55 -0800436
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700437 /**
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700438 * November 2009: Android 2.0
Andres Moralescb3fd692015-01-14 10:07:55 -0800439 *
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700440 * <p>Applications targeting this or a later release will get these
441 * new changes in behavior:</p>
442 * <ul>
443 * <li> The {@link android.app.Service#onStartCommand
444 * Service.onStartCommand} function will return the new
445 * {@link android.app.Service#START_STICKY} behavior instead of the
446 * old compatibility {@link android.app.Service#START_STICKY_COMPATIBILITY}.
Dianne Hackborn8d374262009-09-14 21:21:52 -0700447 * <li> The {@link android.app.Activity} class will now execute back
448 * key presses on the key up instead of key down, to be able to detect
449 * canceled presses from virtual keys.
Mike Cleron76097642009-09-25 17:53:56 -0700450 * <li> The {@link android.widget.TabWidget} class will use a new color scheme
451 * for tabs. In the new scheme, the foreground tab has a medium gray background
452 * the background tabs have a dark gray background.
Dianne Hackbornf6f9f2d2009-08-21 16:26:03 -0700453 * </ul>
454 */
Jeff Hamilton6dc3f4e2009-10-10 12:06:19 -0500455 public static final int ECLAIR = 5;
Andres Moralescb3fd692015-01-14 10:07:55 -0800456
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700457 /**
Dianne Hackborn17787762009-11-12 16:11:36 -0800458 * December 2009: Android 2.0.1
Dianne Hackborn0fa35912009-10-23 12:32:45 -0700459 */
Dianne Hackborn17787762009-11-12 16:11:36 -0800460 public static final int ECLAIR_0_1 = 6;
Andres Moralescb3fd692015-01-14 10:07:55 -0800461
Dianne Hackborn23ef7b42009-11-18 18:20:39 -0800462 /**
463 * January 2010: Android 2.1
464 */
465 public static final int ECLAIR_MR1 = 7;
Andres Moralescb3fd692015-01-14 10:07:55 -0800466
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700467 /**
468 * June 2010: Android 2.2
469 */
Adam Powell216bccf2010-02-01 15:03:17 -0800470 public static final int FROYO = 8;
Andres Moralescb3fd692015-01-14 10:07:55 -0800471
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700472 /**
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800473 * November 2010: Android 2.3
Dianne Hackborn81e92762011-10-09 16:00:21 -0700474 *
475 * <p>Applications targeting this or a later release will get these
476 * new changes in behavior:</p>
477 * <ul>
478 * <li> The application's notification icons will be shown on the new
479 * dark status bar background, so must be visible in this situation.
480 * </ul>
Dianne Hackborn3e03cfa2010-06-13 12:07:00 -0700481 */
Dianne Hackborn4fa1a222010-10-18 13:10:49 -0700482 public static final int GINGERBREAD = 9;
Andres Moralescb3fd692015-01-14 10:07:55 -0800483
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800484 /**
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700485 * February 2011: Android 2.3.3.
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800486 */
487 public static final int GINGERBREAD_MR1 = 10;
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700488
489 /**
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700490 * February 2011: Android 3.0.
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700491 *
492 * <p>Applications targeting this or a later release will get these
493 * new changes in behavior:</p>
494 * <ul>
Dianne Hackborn3e6d50c2010-08-23 18:30:44 -0700495 * <li> The default theme for applications is now dark holographic:
496 * {@link android.R.style#Theme_Holo}.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700497 * <li> On large screen devices that do not have a physical menu
498 * button, the soft (compatibility) menu is disabled.
Dianne Hackborn0aae2d42010-12-07 23:51:29 -0800499 * <li> The activity lifecycle has changed slightly as per
500 * {@link android.app.Activity}.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700501 * <li> An application will crash if it does not call through
502 * to the super implementation of its
503 * {@link android.app.Activity#onPause Activity.onPause()} method.
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800504 * <li> When an application requires a permission to access one of
Dianne Hackborn6c2c5fc2011-01-18 17:02:33 -0800505 * its components (activity, receiver, service, provider), this
506 * permission is no longer enforced when the application wants to
507 * access its own component. This means it can require a permission
508 * on a component that it does not itself hold and still access that
509 * component.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700510 * <li> {@link android.content.Context#getSharedPreferences
511 * Context.getSharedPreferences()} will not automatically reload
512 * the preferences if they have changed on storage, unless
513 * {@link android.content.Context#MODE_MULTI_PROCESS} is used.
514 * <li> {@link android.view.ViewGroup#setMotionEventSplittingEnabled}
515 * will default to true.
516 * <li> {@link android.view.WindowManager.LayoutParams#FLAG_SPLIT_TOUCH}
517 * is enabled by default on windows.
518 * <li> {@link android.widget.PopupWindow#isSplitTouchEnabled()
519 * PopupWindow.isSplitTouchEnabled()} will return true by default.
520 * <li> {@link android.widget.GridView} and {@link android.widget.ListView}
521 * will use {@link android.view.View#setActivated View.setActivated}
522 * for selected items if they do not implement {@link android.widget.Checkable}.
523 * <li> {@link android.widget.Scroller} will be constructed with
524 * "flywheel" behavior enabled by default.
Dianne Hackbornb1ad5972010-08-02 17:30:33 -0700525 * </ul>
526 */
Dianne Hackborn9d97b632011-01-23 14:56:39 -0800527 public static final int HONEYCOMB = 11;
Andres Moralescb3fd692015-01-14 10:07:55 -0800528
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700529 /**
Dianne Hackborna8138732011-05-12 15:45:21 -0700530 * May 2011: Android 3.1.
Dianne Hackbornedf1fc62011-03-17 18:34:48 -0700531 */
532 public static final int HONEYCOMB_MR1 = 12;
Andres Moralescb3fd692015-01-14 10:07:55 -0800533
Dianne Hackborna8138732011-05-12 15:45:21 -0700534 /**
Dianne Hackborn426431a2011-06-09 11:29:08 -0700535 * June 2011: Android 3.2.
Dianne Hackborne6676352011-06-01 16:51:20 -0700536 *
537 * <p>Update to Honeycomb MR1 to support 7 inch tablets, improve
538 * screen compatibility mode, etc.</p>
539 *
540 * <p>As of this version, applications that don't say whether they
541 * support XLARGE screens will be assumed to do so only if they target
542 * {@link #HONEYCOMB} or later; it had been {@link #GINGERBREAD} or
543 * later. Applications that don't support a screen size at least as
544 * large as the current screen will provide the user with a UI to
545 * switch them in to screen size compatibility mode.</p>
Dianne Hackborne289bff2011-06-13 19:33:22 -0700546 *
547 * <p>This version introduces new screen size resource qualifiers
548 * based on the screen size in dp: see
549 * {@link android.content.res.Configuration#screenWidthDp},
550 * {@link android.content.res.Configuration#screenHeightDp}, and
551 * {@link android.content.res.Configuration#smallestScreenWidthDp}.
552 * Supplying these in &lt;supports-screens&gt; as per
553 * {@link android.content.pm.ApplicationInfo#requiresSmallestWidthDp},
554 * {@link android.content.pm.ApplicationInfo#compatibleWidthLimitDp}, and
555 * {@link android.content.pm.ApplicationInfo#largestWidthLimitDp} is
556 * preferred over the older screen size buckets and for older devices
557 * the appropriate buckets will be inferred from them.</p>
558 *
Dianne Hackborn81e92762011-10-09 16:00:21 -0700559 * <p>Applications targeting this or a later release will get these
560 * new changes in behavior:</p>
561 * <ul>
562 * <li><p>New {@link android.content.pm.PackageManager#FEATURE_SCREEN_PORTRAIT}
Dianne Hackborne289bff2011-06-13 19:33:22 -0700563 * and {@link android.content.pm.PackageManager#FEATURE_SCREEN_LANDSCAPE}
Dianne Hackborn81e92762011-10-09 16:00:21 -0700564 * features were introduced in this release. Applications that target
Dianne Hackborne289bff2011-06-13 19:33:22 -0700565 * previous platform versions are assumed to require both portrait and
566 * landscape support in the device; when targeting Honeycomb MR1 or
567 * greater the application is responsible for specifying any specific
568 * orientation it requires.</p>
Dianne Hackborn81e92762011-10-09 16:00:21 -0700569 * <li><p>{@link android.os.AsyncTask} will use the serial executor
570 * by default when calling {@link android.os.AsyncTask#execute}.</p>
571 * <li><p>{@link android.content.pm.ActivityInfo#configChanges
572 * ActivityInfo.configChanges} will have the
573 * {@link android.content.pm.ActivityInfo#CONFIG_SCREEN_SIZE} and
574 * {@link android.content.pm.ActivityInfo#CONFIG_SMALLEST_SCREEN_SIZE}
575 * bits set; these need to be cleared for older applications because
576 * some developers have done absolute comparisons against this value
577 * instead of correctly masking the bits they are interested in.
578 * </ul>
Dianne Hackborna8138732011-05-12 15:45:21 -0700579 */
Dianne Hackborn426431a2011-06-09 11:29:08 -0700580 public static final int HONEYCOMB_MR2 = 13;
Dianne Hackborn3fc982f2011-03-30 16:20:26 -0700581
582 /**
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700583 * October 2011: Android 4.0.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700584 *
585 * <p>Applications targeting this or a later release will get these
586 * new changes in behavior:</p>
587 * <ul>
Dianne Hackborn9d0e37e2011-09-22 12:58:54 -0700588 * <li> For devices without a dedicated menu key, the software compatibility
589 * menu key will not be shown even on phones. By targeting Ice Cream Sandwich
590 * or later, your UI must always have its own menu UI affordance if needed,
591 * on both tablets and phones. The ActionBar will take care of this for you.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700592 * <li> 2d drawing hardware acceleration is now turned on by default.
593 * You can use
594 * {@link android.R.attr#hardwareAccelerated android:hardwareAccelerated}
595 * to turn it off if needed, although this is strongly discouraged since
596 * it will result in poor performance on larger screen devices.
Adam Powell6e90a362011-08-14 16:48:32 -0700597 * <li> The default theme for applications is now the "device default" theme:
598 * {@link android.R.style#Theme_DeviceDefault}. This may be the
599 * holo dark theme or a different dark theme defined by the specific device.
600 * The {@link android.R.style#Theme_Holo} family must not be modified
601 * for a device to be considered compatible. Applications that explicitly
602 * request a theme from the Holo family will be guaranteed that these themes
603 * will not change character within the same platform version. Applications
604 * that wish to blend in with the device should use a theme from the
605 * {@link android.R.style#Theme_DeviceDefault} family.
Dianne Hackborn9d0e37e2011-09-22 12:58:54 -0700606 * <li> Managed cursors can now throw an exception if you directly close
607 * the cursor yourself without stopping the management of it; previously failures
608 * would be silently ignored.
609 * <li> The fadingEdge attribute on views will be ignored (fading edges is no
610 * longer a standard part of the UI). A new requiresFadingEdge attribute allows
611 * applications to still force fading edges on for special cases.
Dianne Hackborn81e92762011-10-09 16:00:21 -0700612 * <li> {@link android.content.Context#bindService Context.bindService()}
613 * will not automatically add in {@link android.content.Context#BIND_WAIVE_PRIORITY}.
614 * <li> App Widgets will have standard padding automatically added around
615 * them, rather than relying on the padding being baked into the widget itself.
616 * <li> An exception will be thrown if you try to change the type of a
617 * window after it has been added to the window manager. Previously this
618 * would result in random incorrect behavior.
619 * <li> {@link android.view.animation.AnimationSet} will parse out
620 * the duration, fillBefore, fillAfter, repeatMode, and startOffset
621 * XML attributes that are defined.
622 * <li> {@link android.app.ActionBar#setHomeButtonEnabled
623 * ActionBar.setHomeButtonEnabled()} is false by default.
Dianne Hackborn2d6833b2011-06-24 16:04:19 -0700624 * </ul>
Dianne Hackborn3fc982f2011-03-30 16:20:26 -0700625 */
Dianne Hackborn0784cfb2011-09-14 13:48:15 -0700626 public static final int ICE_CREAM_SANDWICH = 14;
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700627
628 /**
Dianne Hackborn81e92762011-10-09 16:00:21 -0700629 * December 2011: Android 4.0.3.
Dianne Hackbornf35fe232011-11-01 19:25:20 -0700630 */
631 public static final int ICE_CREAM_SANDWICH_MR1 = 15;
Dianne Hackborn81e92762011-10-09 16:00:21 -0700632
633 /**
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700634 * June 2012: Android 4.1.
Dianne Hackborn65696252012-03-05 18:49:21 -0800635 *
636 * <p>Applications targeting this or a later release will get these
637 * new changes in behavior:</p>
638 * <ul>
Dianne Hackborn636fd522012-06-05 17:38:50 -0700639 * <li> You must explicitly request the {@link android.Manifest.permission#READ_CALL_LOG}
640 * and/or {@link android.Manifest.permission#WRITE_CALL_LOG} permissions;
641 * access to the call log is no longer implicitly provided through
642 * {@link android.Manifest.permission#READ_CONTACTS} and
643 * {@link android.Manifest.permission#WRITE_CONTACTS}.
644 * <li> {@link android.widget.RemoteViews} will throw an exception if
645 * setting an onClick handler for views being generated by a
646 * {@link android.widget.RemoteViewsService} for a collection container;
647 * previously this just resulted in a warning log message.
648 * <li> New {@link android.app.ActionBar} policy for embedded tabs:
649 * embedded tabs are now always stacked in the action bar when in portrait
650 * mode, regardless of the size of the screen.
651 * <li> {@link android.webkit.WebSettings#setAllowFileAccessFromFileURLs(boolean)
652 * WebSettings.setAllowFileAccessFromFileURLs} and
653 * {@link android.webkit.WebSettings#setAllowUniversalAccessFromFileURLs(boolean)
654 * WebSettings.setAllowUniversalAccessFromFileURLs} default to false.
Dianne Hackborn65696252012-03-05 18:49:21 -0800655 * <li> Calls to {@link android.content.pm.PackageManager#setComponentEnabledSetting
656 * PackageManager.setComponentEnabledSetting} will now throw an
657 * IllegalArgumentException if the given component class name does not
658 * exist in the application's manifest.
Dianne Hackborn636fd522012-06-05 17:38:50 -0700659 * <li> {@link android.nfc.NfcAdapter#setNdefPushMessage
660 * NfcAdapter.setNdefPushMessage},
661 * {@link android.nfc.NfcAdapter#setNdefPushMessageCallback
662 * NfcAdapter.setNdefPushMessageCallback} and
663 * {@link android.nfc.NfcAdapter#setOnNdefPushCompleteCallback
664 * NfcAdapter.setOnNdefPushCompleteCallback} will throw
665 * IllegalStateException if called after the Activity has been destroyed.
666 * <li> Accessibility services must require the new
667 * {@link android.Manifest.permission#BIND_ACCESSIBILITY_SERVICE} permission or
668 * they will not be available for use.
669 * <li> {@link android.accessibilityservice.AccessibilityServiceInfo#FLAG_INCLUDE_NOT_IMPORTANT_VIEWS
670 * AccessibilityServiceInfo.FLAG_INCLUDE_NOT_IMPORTANT_VIEWS} must be set
671 * for unimportant views to be included in queries.
Dianne Hackborn65696252012-03-05 18:49:21 -0800672 * </ul>
Dianne Hackborn81e92762011-10-09 16:00:21 -0700673 */
Dianne Hackbornfa61f0b2012-05-09 21:49:38 -0700674 public static final int JELLY_BEAN = 16;
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700675
676 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700677 * November 2012: Android 4.2, Moar jelly beans!
Nick Kralevichf097b162012-07-28 12:43:48 -0700678 *
679 * <p>Applications targeting this or a later release will get these
680 * new changes in behavior:</p>
681 * <ul>
682 * <li>Content Providers: The default value of {@code android:exported} is now
683 * {@code false}. See
Nick Kralevich2caec6c2012-08-08 11:33:17 -0700684 * <a href="{@docRoot}guide/topics/manifest/provider-element.html#exported">
Nick Kralevichf097b162012-07-28 12:43:48 -0700685 * the android:exported section</a> in the provider documentation for more details.</li>
Dianne Hackbornfc494742012-09-27 16:15:42 -0700686 * <li>{@link android.view.View#getLayoutDirection() View.getLayoutDirection()}
687 * can return different values than {@link android.view.View#LAYOUT_DIRECTION_LTR}
688 * based on the locale etc.
689 * <li> {@link android.webkit.WebView#addJavascriptInterface(Object, String)
690 * WebView.addJavascriptInterface} requires explicit annotations on methods
691 * for them to be accessible from Javascript.
Nick Kralevichf097b162012-07-28 12:43:48 -0700692 * </ul>
Dianne Hackborn435cdb42012-07-30 17:36:43 -0700693 */
694 public static final int JELLY_BEAN_MR1 = 17;
Nick Kralevicha985c3b2013-01-09 16:03:14 -0800695
696 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700697 * July 2013: Android 4.3, the revenge of the beans.
Nick Kralevicha985c3b2013-01-09 16:03:14 -0800698 */
Dianne Hackbornd2eeed62013-04-22 13:04:28 -0700699 public static final int JELLY_BEAN_MR2 = 18;
Dianne Hackborn5d2bfa12013-03-05 10:28:34 -0800700
701 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700702 * October 2013: Android 4.4, KitKat, another tasty treat.
Dianne Hackborn221ea892013-08-04 16:50:16 -0700703 *
704 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700705 * new changes in behavior. For more information about this release, see the
706 * <a href="/about/versions/kitkat/">Android KitKat overview</a>.</p>
Dianne Hackborn221ea892013-08-04 16:50:16 -0700707 * <ul>
Mark Dolinerd0646dc2014-08-27 16:04:02 -0700708 * <li> The default result of
709 * {@link android.preference.PreferenceActivity#isValidFragment(String)
Dianne Hackborn6bc37892013-10-03 11:05:14 -0700710 * PreferenceActivity.isValueFragment} becomes false instead of true.</li>
711 * <li> In {@link android.webkit.WebView}, apps targeting earlier versions will have
712 * JS URLs evaluated directly and any result of the evaluation will not replace
713 * the current page content. Apps targetting KITKAT or later that load a JS URL will
714 * have the result of that URL replace the content of the current page</li>
715 * <li> {@link android.app.AlarmManager#set AlarmManager.set} becomes interpreted as
716 * an inexact value, to give the system more flexibility in scheduling alarms.</li>
717 * <li> {@link android.content.Context#getSharedPreferences(String, int)
718 * Context.getSharedPreferences} no longer allows a null name.</li>
719 * <li> {@link android.widget.RelativeLayout} changes to compute wrapped content
720 * margins correctly.</li>
721 * <li> {@link android.app.ActionBar}'s window content overlay is allowed to be
722 * drawn.</li>
Jeff Sharkey3ec2f602013-10-29 12:21:23 -0700723 * <li>The {@link android.Manifest.permission#READ_EXTERNAL_STORAGE}
724 * permission is now always enforced.</li>
725 * <li>Access to package-specific external storage directories belonging
726 * to the calling app no longer requires the
727 * {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} or
728 * {@link android.Manifest.permission#WRITE_EXTERNAL_STORAGE}
729 * permissions.</li>
Dianne Hackborn221ea892013-08-04 16:50:16 -0700730 * </ul>
Dianne Hackborn5d2bfa12013-03-05 10:28:34 -0800731 */
Dianne Hackborn6bc37892013-10-03 11:05:14 -0700732 public static final int KITKAT = 19;
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700733
734 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700735 * June 2014: Android 4.4W. KitKat for watches, snacks on the run.
Justin Koh78b94de2014-05-13 15:48:42 -0700736 *
737 * <p>Applications targeting this or a later release will get these
738 * new changes in behavior:</p>
739 * <ul>
740 * <li>{@link android.app.AlertDialog} might not have a default background if the theme does
741 * not specify one.</li>
742 * </ul>
Jeff Brown1c3f3322014-04-16 13:15:22 -0700743 */
Justin Koh78b94de2014-05-13 15:48:42 -0700744 public static final int KITKAT_WATCH = 20;
Jeff Brown047f3c72014-04-16 14:18:49 -0700745
746 /**
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700747 * Temporary until we completely switch to {@link #LOLLIPOP}.
Dianne Hackbornd3511d42014-10-16 17:48:30 -0700748 * @hide
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700749 */
750 public static final int L = 21;
751
752 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700753 * November 2014: Lollipop. A flat one with beautiful shadows. But still tasty.
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700754 *
755 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700756 * new changes in behavior. For more information about this release, see the
757 * <a href="/about/versions/lollipop/">Android Lollipop overview</a>.</p>
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700758 * <ul>
759 * <li> {@link android.content.Context#bindService Context.bindService} now
Michael Wright5b5def52014-04-11 13:37:50 -0700760 * requires an explicit Intent, and will throw an exception if given an implicit
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700761 * Intent.</li>
Dianne Hackbornd3511d42014-10-16 17:48:30 -0700762 * <li> {@link android.app.Notification.Builder Notification.Builder} will
763 * not have the colors of their various notification elements adjusted to better
764 * match the new material design look.</li>
765 * <li> {@link android.os.Message} will validate that a message is not currently
766 * in use when it is recycled.</li>
767 * <li> Hardware accelerated drawing in windows will be enabled automatically
768 * in most places.</li>
769 * <li> {@link android.widget.Spinner} throws an exception if attaching an
770 * adapter with more than one item type.</li>
771 * <li> If the app is a launcher, the launcher will be available to the user
772 * even when they are using corporate profiles (which requires that the app
773 * use {@link android.content.pm.LauncherApps} to correctly populate its
774 * apps UI).</li>
775 * <li> Calling {@link android.app.Service#stopForeground Service.stopForeground}
776 * with removeNotification false will modify the still posted notification so that
777 * it is no longer forced to be ongoing.</li>
778 * <li> A {@link android.service.dreams.DreamService} must require the
779 * {@link android.Manifest.permission#BIND_DREAM_SERVICE} permission to be usable.</li>
Dianne Hackborn10ad9822014-03-17 11:28:36 -0700780 * </ul>
781 */
Dianne Hackborn955d8d62014-10-07 20:17:19 -0700782 public static final int LOLLIPOP = 21;
Dianne Hackborn3b696882014-10-16 18:14:12 -0700783
784 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700785 * March 2015: Lollipop with an extra sugar coating on the outside!
Andrew Solovaya861ff72018-08-06 13:43:30 -0700786 * For more information about this release, see the
787 * <a href="/about/versions/android-5.1">Android 5.1 APIs</a>.
Dianne Hackborn3b696882014-10-16 18:14:12 -0700788 */
789 public static final int LOLLIPOP_MR1 = 22;
Dianne Hackborn8bd95f12015-01-27 13:18:24 -0800790
791 /**
Dianne Hackborne7a34352015-09-17 14:50:47 -0700792 * M is for Marshmallow!
793 *
794 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700795 * new changes in behavior. For more information about this release, see the
796 * <a href="/about/versions/marshmallow/">Android 6.0 Marshmallow overview</a>.</p>
Dianne Hackborne7a34352015-09-17 14:50:47 -0700797 * <ul>
798 * <li> Runtime permissions. Dangerous permissions are no longer granted at
799 * install time, but must be requested by the application at runtime through
800 * {@link android.app.Activity#requestPermissions}.</li>
801 * <li> Bluetooth and Wi-Fi scanning now requires holding the location permission.</li>
802 * <li> {@link android.app.AlarmManager#setTimeZone AlarmManager.setTimeZone} will fail if
803 * the given timezone is non-Olson.</li>
804 * <li> Activity transitions will only return shared
805 * elements mapped in the returned view hierarchy back to the calling activity.</li>
806 * <li> {@link android.view.View} allows a number of behaviors that may break
807 * existing apps: Canvas throws an exception if restore() is called too many times,
808 * widgets may return a hint size when returning UNSPECIFIED measure specs, and it
809 * will respect the attributes {@link android.R.attr#foreground},
810 * {@link android.R.attr#foregroundGravity}, {@link android.R.attr#foregroundTint}, and
811 * {@link android.R.attr#foregroundTintMode}.</li>
812 * <li> {@link android.view.MotionEvent#getButtonState MotionEvent.getButtonState}
813 * will no longer report {@link android.view.MotionEvent#BUTTON_PRIMARY}
814 * and {@link android.view.MotionEvent#BUTTON_SECONDARY} as synonyms for
815 * {@link android.view.MotionEvent#BUTTON_STYLUS_PRIMARY} and
816 * {@link android.view.MotionEvent#BUTTON_STYLUS_SECONDARY}.</li>
817 * <li> {@link android.widget.ScrollView} now respects the layout param margins
818 * when measuring.</li>
819 * </ul>
Dianne Hackborn8bd95f12015-01-27 13:18:24 -0800820 */
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700821 public static final int M = 23;
Wale Ogunwale79113102015-10-05 16:52:53 -0700822
823 /**
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700824 * N is for Nougat.
825 *
826 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700827 * new changes in behavior. For more information about this release, see
828 * the <a href="/about/versions/nougat/">Android Nougat overview</a>.</p>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700829 * <ul>
830 * <li> {@link android.app.DownloadManager.Request#setAllowedNetworkTypes
831 * DownloadManager.Request.setAllowedNetworkTypes}
832 * will disable "allow over metered" when specifying only
Dianne Hackborn5f1649e2016-08-09 18:00:31 -0700833 * {@link android.app.DownloadManager.Request#NETWORK_WIFI}.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700834 * <li> {@link android.app.DownloadManager} no longer allows access to raw
Dianne Hackborn5f1649e2016-08-09 18:00:31 -0700835 * file paths.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700836 * <li> {@link android.app.Notification.Builder#setShowWhen
837 * Notification.Builder.setShowWhen}
838 * must be called explicitly to have the time shown, and various other changes in
839 * {@link android.app.Notification.Builder Notification.Builder} to how notifications
840 * are shown.</li>
841 * <li>{@link android.content.Context#MODE_WORLD_READABLE} and
842 * {@link android.content.Context#MODE_WORLD_WRITEABLE} are no longer supported.</li>
843 * <li>{@link android.os.FileUriExposedException} will be thrown to applications.</li>
844 * <li>Applications will see global drag and drops as per
845 * {@link android.view.View#DRAG_FLAG_GLOBAL}.</li>
846 * <li>{@link android.webkit.WebView#evaluateJavascript WebView.evaluateJavascript}
847 * will not persist state from an empty WebView.</li>
848 * <li>{@link android.animation.AnimatorSet} will not ignore calls to end() before
849 * start().</li>
850 * <li>{@link android.app.AlarmManager#cancel(android.app.PendingIntent)
851 * AlarmManager.cancel} will throw a NullPointerException if given a null operation.</li>
852 * <li>{@link android.app.FragmentManager} will ensure fragments have been created
853 * before being placed on the back stack.</li>
854 * <li>{@link android.app.FragmentManager} restores fragments in
855 * {@link android.app.Fragment#onCreate Fragment.onCreate} rather than after the
856 * method returns.</li>
857 * <li>{@link android.R.attr#resizeableActivity} defaults to true.</li>
858 * <li>{@link android.graphics.drawable.AnimatedVectorDrawable} throws exceptions when
859 * opening invalid VectorDrawable animations.</li>
860 * <li>{@link android.view.ViewGroup.MarginLayoutParams} will no longer be dropped
861 * when converting between some types of layout params (such as
862 * {@link android.widget.LinearLayout.LayoutParams LinearLayout.LayoutParams} to
863 * {@link android.widget.RelativeLayout.LayoutParams RelativeLayout.LayoutParams}).</li>
864 * <li>Your application processes will not be killed when the device density changes.</li>
Vadim Tryshev06b9b602016-09-23 15:32:33 -0700865 * <li>Drag and drop. After a view receives the
866 * {@link android.view.DragEvent#ACTION_DRAG_ENTERED} event, when the drag shadow moves into
867 * a descendant view that can accept the data, the view receives the
868 * {@link android.view.DragEvent#ACTION_DRAG_EXITED} event and won’t receive
869 * {@link android.view.DragEvent#ACTION_DRAG_LOCATION} and
870 * {@link android.view.DragEvent#ACTION_DROP} events while the drag shadow is within that
871 * descendant view, even if the descendant view returns <code>false</code> from its handler
872 * for these events.</li>
Dianne Hackbornb34cbed2016-08-09 13:18:21 -0700873 * </ul>
Wale Ogunwale79113102015-10-05 16:52:53 -0700874 */
Adam Powell43ec62a2016-05-25 16:36:41 -0700875 public static final int N = 24;
Michael Wright863ae3e2016-06-29 15:47:16 +0100876
877 /**
Andrew Solovaya861ff72018-08-06 13:43:30 -0700878 * N MR1: Nougat++. For more information about this release, see
879 * <a href="/about/versions/nougat/android-7.1">Android 7.1 for
880 * Developers</a>.
Michael Wright863ae3e2016-06-29 15:47:16 +0100881 */
882 public static final int N_MR1 = 25;
Makoto Onuki864f4bd2016-11-02 11:11:32 -0700883
884 /**
885 * O.
Evan Rosky534de292017-06-23 09:45:38 -0700886 *
887 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700888 * new changes in behavior. For more information about this release, see
889 * the <a href="/about/versions/oreo/">Android Oreo overview</a>.</p>
Evan Rosky534de292017-06-23 09:45:38 -0700890 * <ul>
Dianne Hackborna47d0452017-11-21 15:04:57 -0800891 * <li><a href="{@docRoot}about/versions/oreo/background.html">Background execution limits</a>
892 * are applied to the application.</li>
893 * <li>The behavior of AccountManager's
894 * {@link android.accounts.AccountManager#getAccountsByType},
895 * {@link android.accounts.AccountManager#getAccountsByTypeAndFeatures}, and
896 * {@link android.accounts.AccountManager#hasFeatures} has changed as documented there.</li>
897 * <li>{@link android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE_PRE_26}
898 * is now returned as
899 * {@link android.app.ActivityManager.RunningAppProcessInfo#IMPORTANCE_PERCEPTIBLE}.</li>
900 * <li>The {@link android.app.NotificationManager} now requires the use of notification
901 * channels.</li>
902 * <li>Changes to the strict mode that are set in
903 * {@link Application#onCreate Application.onCreate} will no longer be clobbered after
904 * that function returns.</li>
905 * <li>A shared library apk with native code will have that native code included in
906 * the library path of its clients.</li>
907 * <li>{@link android.content.Context#getSharedPreferences Context.getSharedPreferences}
908 * in credential encrypted storage will throw an exception before the user is unlocked.</li>
909 * <li>Attempting to retrieve a {@link Context#FINGERPRINT_SERVICE} on a device that
910 * does not support that feature will now throw a runtime exception.</li>
911 * <li>{@link android.app.Fragment} will stop any active view animations when
912 * the fragment is stopped.</li>
913 * <li>Some compatibility code in Resources that attempts to use the default Theme
914 * the app may be using will be turned off, requiring the app to explicitly request
915 * resources with the right theme.</li>
916 * <li>{@link android.content.ContentResolver#notifyChange ContentResolver.notifyChange} and
917 * {@link android.content.ContentResolver#registerContentObserver
918 * ContentResolver.registerContentObserver}
919 * will throw a SecurityException if the caller does not have permission to access
920 * the provider (or the provider doesn't exit); otherwise the call will be silently
921 * ignored.</li>
922 * <li>{@link android.hardware.camera2.CameraDevice#createCaptureRequest
923 * CameraDevice.createCaptureRequest} will enable
924 * {@link android.hardware.camera2.CaptureRequest#CONTROL_ENABLE_ZSL} by default for
925 * still image capture.</li>
926 * <li>WallpaperManager's {@link android.app.WallpaperManager#getWallpaperFile},
927 * {@link android.app.WallpaperManager#getDrawable},
928 * {@link android.app.WallpaperManager#getFastDrawable},
929 * {@link android.app.WallpaperManager#peekDrawable}, and
930 * {@link android.app.WallpaperManager#peekFastDrawable} will throw an exception
931 * if you can not access the wallpaper.</li>
932 * <li>The behavior of
933 * {@link android.hardware.usb.UsbDeviceConnection#requestWait UsbDeviceConnection.requestWait}
934 * is modified as per the documentation there.</li>
935 * <li>{@link StrictMode.VmPolicy.Builder#detectAll StrictMode.VmPolicy.Builder.detectAll}
936 * will also enable {@link StrictMode.VmPolicy.Builder#detectContentUriWithoutPermission}
937 * and {@link StrictMode.VmPolicy.Builder#detectUntaggedSockets}.</li>
938 * <li>{@link StrictMode.ThreadPolicy.Builder#detectAll StrictMode.ThreadPolicy.Builder.detectAll}
939 * will also enable {@link StrictMode.ThreadPolicy.Builder#detectUnbufferedIo}.</li>
940 * <li>{@link android.provider.DocumentsContract}'s various methods will throw failure
941 * exceptions back to the caller instead of returning null.
942 * <li>{@link View#hasFocusable View.hasFocusable} now includes auto-focusable views.</li>
943 * <li>{@link android.view.SurfaceView} will no longer always change the underlying
944 * Surface object when something about it changes; apps need to look at the current
945 * state of the object to determine which things they are interested in have changed.</li>
946 * <li>{@link android.view.WindowManager.LayoutParams#TYPE_APPLICATION_OVERLAY} must be
947 * used for overlay windows, other system overlay window types are not allowed.</li>
948 * <li>{@link android.view.ViewTreeObserver#addOnDrawListener
949 * ViewTreeObserver.addOnDrawListener} will throw an exception if called from within
950 * onDraw.</li>
951 * <li>{@link android.graphics.Canvas#setBitmap Canvas.setBitmap} will no longer preserve
952 * the current matrix and clip stack of the canvas.</li>
953 * <li>{@link android.widget.ListPopupWindow#setHeight ListPopupWindow.setHeight}
954 * will throw an exception if a negative height is supplied.</li>
955 * <li>{@link android.widget.TextView} will use internationalized input for numbers,
956 * dates, and times.</li>
957 * <li>{@link android.widget.Toast} must be used for showing toast windows; the toast
958 * window type can not be directly used.</li>
959 * <li>{@link android.net.wifi.WifiManager#getConnectionInfo WifiManager.getConnectionInfo}
960 * requires that the caller hold the location permission to return BSSID/SSID</li>
961 * <li>{@link android.net.wifi.p2p.WifiP2pManager#requestPeers WifiP2pManager.requestPeers}
962 * requires the caller hold the location permission.</li>
963 * <li>{@link android.R.attr#maxAspectRatio} defaults to 0, meaning there is no restriction
964 * on the app's maximum aspect ratio (so it can be stretched to fill larger screens).</li>
Evan Rosky534de292017-06-23 09:45:38 -0700965 * <li>{@link android.R.attr#focusable} defaults to a new state ({@code auto}) where it will
966 * inherit the value of {@link android.R.attr#clickable} unless explicitly overridden.</li>
967 * <li>A default theme-appropriate focus-state highlight will be supplied to all Views
968 * which don't provide a focus-state drawable themselves. This can be disabled by setting
969 * {@link android.R.attr#defaultFocusHighlightEnabled} to false.</li>
970 * </ul>
Makoto Onuki864f4bd2016-11-02 11:11:32 -0700971 */
Ian Pedowitz967869d2017-05-04 00:10:04 +0000972 public static final int O = 26;
Jeff Sharkey7beabc22017-07-19 13:57:35 -0600973
974 /**
975 * O MR1.
Dianne Hackborna47d0452017-11-21 15:04:57 -0800976 *
977 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700978 * new changes in behavior. For more information about this release, see
979 * <a href="/about/versions/oreo/android-8.1">Android 8.1 features and
980 * APIs</a>.</p>
Dianne Hackborna47d0452017-11-21 15:04:57 -0800981 * <ul>
982 * <li>Apps exporting and linking to apk shared libraries must explicitly
983 * enumerate all signing certificates in a consistent order.</li>
984 * <li>{@link android.R.attr#screenOrientation} can not be used to request a fixed
985 * orientation if the associated activity is not fullscreen and opaque.</li>
986 * </ul>
Andrew Solovaya861ff72018-08-06 13:43:30 -0700987 *
Jeff Sharkey7beabc22017-07-19 13:57:35 -0600988 */
Michael Wrighteec01ac2017-08-23 13:49:14 -0700989 public static final int O_MR1 = 27;
Makoto Onuki7bd7a622017-08-31 08:35:59 -0700990
991 /**
992 * P.
Dianne Hackborndd027b32018-01-19 17:44:46 -0800993 *
994 * <p>Applications targeting this or a later release will get these
Andrew Solovaya861ff72018-08-06 13:43:30 -0700995 * new changes in behavior. For more information about this release, see the
996 * <a href="/about/versions/pie/">Android 9 Pie overview</a>.</p>
Dianne Hackborndd027b32018-01-19 17:44:46 -0800997 * <ul>
998 * <li>{@link android.app.Service#startForeground Service.startForeground} requires
999 * that apps hold the permission
1000 * {@link android.Manifest.permission#FOREGROUND_SERVICE}.</li>
Chet Haasecb848882018-03-21 14:09:44 -07001001 * <li>{@link android.widget.LinearLayout} will always remeasure weighted children,
1002 * even if there is no excess space.</li>
Dianne Hackborndd027b32018-01-19 17:44:46 -08001003 * </ul>
Andrew Solovaya861ff72018-08-06 13:43:30 -07001004 *
Makoto Onuki7bd7a622017-08-31 08:35:59 -07001005 */
Wale Ogunwale3da5f3b2018-04-11 15:12:31 -07001006 public static final int P = 28;
Jeff Sharkey8929b522018-05-15 13:34:52 -06001007
1008 /**
1009 * Q.
Bradley Allen46248162020-08-10 23:16:42 +00001010 *
1011 * <p>Applications targeting this or a later release will get these new changes in behavior.
1012 * For more information about this release, see the
1013 * <a href="/about/versions/10">Android 10 overview</a>.</p>
1014 * <ul>
1015 * <li><a href="/about/versions/10/behavior-changes-all">Behavior changes: all apps</a></li>
1016 * <li><a href="/about/versions/10/behavior-changes-10">Behavior changes: apps targeting API
1017 * 29+</a></li>
1018 * </ul>
1019 *
Jeff Sharkey8929b522018-05-15 13:34:52 -06001020 */
Ian Pedowitz1912a572019-05-12 19:44:42 +00001021 public static final int Q = 29;
Suprabh Shukla1d081c52019-04-29 17:07:51 -07001022
1023 /**
1024 * R.
Bradley Allencefc89c2020-09-09 17:30:08 +00001025 *
1026 * <p>Applications targeting this or a later release will get these new changes in behavior.
1027 * For more information about this release, see the
1028 * <a href="/about/versions/11">Android 11 overview</a>.</p>
1029 * <ul>
1030 * <li><a href="/about/versions/11/behavior-changes-all">Behavior changes: all apps</a></li>
1031 * <li><a href="/about/versions/11/behavior-changes-11">Behavior changes: Apps targeting
1032 * Android 11</a></li>
1033 * <li><a href="/about/versions/11/non-sdk-11">Updates to non-SDK interface restrictions
1034 * in Android 11</a></li>
1035 * </ul>
1036 *
Suprabh Shukla1d081c52019-04-29 17:07:51 -07001037 */
Svet Ganov38cd2212020-04-15 15:10:14 -07001038 public static final int R = 30;
Dianne Hackborn851a5412009-05-08 12:06:44 -07001039 }
Andres Moralescb3fd692015-01-14 10:07:55 -08001040
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001041 /** The type of build, like "user" or "eng". */
1042 public static final String TYPE = getString("ro.build.type");
1043
1044 /** Comma-separated tags describing the build, like "unsigned,debug". */
1045 public static final String TAGS = getString("ro.build.tags");
1046
1047 /** A string that uniquely identifies this build. Do not attempt to parse this value. */
Jeff Sharkey55687722014-04-09 18:07:19 -07001048 public static final String FINGERPRINT = deriveFingerprint();
1049
1050 /**
1051 * Some devices split the fingerprint components between multiple
1052 * partitions, so we might derive the fingerprint at runtime.
1053 */
1054 private static String deriveFingerprint() {
1055 String finger = SystemProperties.get("ro.build.fingerprint");
1056 if (TextUtils.isEmpty(finger)) {
1057 finger = getString("ro.product.brand") + '/' +
1058 getString("ro.product.name") + '/' +
1059 getString("ro.product.device") + ':' +
1060 getString("ro.build.version.release") + '/' +
1061 getString("ro.build.id") + '/' +
1062 getString("ro.build.version.incremental") + ':' +
1063 getString("ro.build.type") + '/' +
1064 getString("ro.build.tags");
1065 }
1066 return finger;
1067 }
1068
1069 /**
1070 * Ensure that raw fingerprint system property is defined. If it was derived
1071 * dynamically by {@link #deriveFingerprint()} this is where we push the
1072 * derived value into the property service.
1073 *
1074 * @hide
1075 */
1076 public static void ensureFingerprintProperty() {
1077 if (TextUtils.isEmpty(SystemProperties.get("ro.build.fingerprint"))) {
Jeff Sharkeybdd44912014-04-11 16:30:14 -07001078 try {
1079 SystemProperties.set("ro.build.fingerprint", FINGERPRINT);
1080 } catch (IllegalArgumentException e) {
1081 Slog.e(TAG, "Failed to set fingerprint property", e);
1082 }
Jeff Sharkey55687722014-04-09 18:07:19 -07001083 }
1084 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001085
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001086 /**
Michael Schwartz18511182017-05-15 11:40:40 -07001087 * True if Treble is enabled and required for this device.
1088 *
1089 * @hide
1090 */
1091 public static final boolean IS_TREBLE_ENABLED =
1092 SystemProperties.getBoolean("ro.treble.enabled", false);
1093
1094 /**
1095 * Verifies the current flash of the device is consistent with what
Andres Moralesfd282ed2015-02-06 15:07:59 -08001096 * was expected at build time.
Michael Schwartz18511182017-05-15 11:40:40 -07001097 *
1098 * Treble devices will verify the Vendor Interface (VINTF). A device
1099 * launched without Treble:
1100 *
Andres Moralesfd282ed2015-02-06 15:07:59 -08001101 * 1) Checks that device fingerprint is defined and that it matches across
1102 * various partitions.
1103 * 2) Verifies radio and bootloader partitions are those expected in the build.
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001104 *
1105 * @hide
1106 */
Andres Moralesfd282ed2015-02-06 15:07:59 -08001107 public static boolean isBuildConsistent() {
Xiaohui Chen2102dcb2015-10-02 16:45:55 -07001108 // Don't care on eng builds. Incremental build may trigger false negative.
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001109 if (IS_ENG) return true;
Xiaohui Chen2102dcb2015-10-02 16:45:55 -07001110
Michael Schwartz18511182017-05-15 11:40:40 -07001111 if (IS_TREBLE_ENABLED) {
Bowgo Tsaib1de4312017-11-17 17:18:50 +08001112 // If we can run this code, the device should already pass AVB.
1113 // So, we don't need to check AVB here.
1114 int result = VintfObject.verifyWithoutAvb();
Michael Schwartz18511182017-05-15 11:40:40 -07001115
1116 if (result != 0) {
1117 Slog.e(TAG, "Vendor interface is incompatible, error="
1118 + String.valueOf(result));
1119 }
1120
1121 return result == 0;
1122 }
1123
Felix88c1bf02019-10-20 02:04:04 +02001124 final String system = SystemProperties.get("ro.system.build.fingerprint");
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001125 final String vendor = SystemProperties.get("ro.vendor.build.fingerprint");
Andres Moralescb3fd692015-01-14 10:07:55 -08001126 final String bootimage = SystemProperties.get("ro.bootimage.build.fingerprint");
Andres Moralesfd282ed2015-02-06 15:07:59 -08001127 final String requiredBootloader = SystemProperties.get("ro.build.expect.bootloader");
1128 final String currentBootloader = SystemProperties.get("ro.bootloader");
1129 final String requiredRadio = SystemProperties.get("ro.build.expect.baseband");
Inseob Kim1b5e2412019-11-08 15:06:37 +09001130 final String currentRadio = joinListOrElse(
1131 TelephonyProperties.baseband_version(), "");
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001132
1133 if (TextUtils.isEmpty(system)) {
Felix88c1bf02019-10-20 02:04:04 +02001134 Slog.e(TAG, "Required ro.system.build.fingerprint is empty!");
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001135 return false;
1136 }
1137
1138 if (!TextUtils.isEmpty(vendor)) {
1139 if (!Objects.equals(system, vendor)) {
1140 Slog.e(TAG, "Mismatched fingerprints; system reported " + system
1141 + " but vendor reported " + vendor);
1142 return false;
1143 }
1144 }
1145
Andres Moralesc97b92e2015-06-01 17:50:43 +00001146 /* TODO: Figure out issue with checks failing
Andres Moralescb3fd692015-01-14 10:07:55 -08001147 if (!TextUtils.isEmpty(bootimage)) {
Andres Morales7de24ce2015-01-23 12:45:54 -08001148 if (!Objects.equals(system, bootimage)) {
1149 Slog.e(TAG, "Mismatched fingerprints; system reported " + system
Andres Moralescb3fd692015-01-14 10:07:55 -08001150 + " but bootimage reported " + bootimage);
1151 return false;
1152 }
1153 }
1154
Andres Moralesfd282ed2015-02-06 15:07:59 -08001155 if (!TextUtils.isEmpty(requiredBootloader)) {
1156 if (!Objects.equals(currentBootloader, requiredBootloader)) {
1157 Slog.e(TAG, "Mismatched bootloader version: build requires " + requiredBootloader
1158 + " but runtime reports " + currentBootloader);
1159 return false;
1160 }
1161 }
1162
1163 if (!TextUtils.isEmpty(requiredRadio)) {
1164 if (!Objects.equals(currentRadio, requiredRadio)) {
1165 Slog.e(TAG, "Mismatched radio version: build requires " + requiredRadio
1166 + " but runtime reports " + currentRadio);
1167 return false;
1168 }
1169 }
Daniel Rosenberg159c2052015-02-20 13:10:26 -08001170 */
Andres Moralesfd282ed2015-02-06 15:07:59 -08001171
Jeff Sharkey2cffc7d2014-11-14 13:57:53 -08001172 return true;
1173 }
1174
Anton Hansson91b54f12018-09-24 18:24:19 +01001175 /** Build information for a particular device partition. */
1176 public static class Partition {
1177 /** The name identifying the system partition. */
1178 public static final String PARTITION_NAME_SYSTEM = "system";
1179
Anton Hansson2579d1a2019-02-06 12:14:12 +00001180 private final String mName;
1181 private final String mFingerprint;
1182 private final long mTimeMs;
Anton Hansson91b54f12018-09-24 18:24:19 +01001183
1184 private Partition(String name, String fingerprint, long timeMs) {
1185 mName = name;
1186 mFingerprint = fingerprint;
1187 mTimeMs = timeMs;
1188 }
1189
1190 /** The name of this partition, e.g. "system", or "vendor" */
Anton Hansson81f76a02018-10-04 18:40:22 +01001191 @NonNull
Anton Hansson91b54f12018-09-24 18:24:19 +01001192 public String getName() {
1193 return mName;
1194 }
1195
1196 /** The build fingerprint of this partition, see {@link Build#FINGERPRINT}. */
Anton Hansson81f76a02018-10-04 18:40:22 +01001197 @NonNull
Anton Hansson91b54f12018-09-24 18:24:19 +01001198 public String getFingerprint() {
1199 return mFingerprint;
1200 }
1201
1202 /** The time (ms since epoch), at which this partition was built, see {@link Build#TIME}. */
Anton Hansson81f76a02018-10-04 18:40:22 +01001203 public long getBuildTimeMillis() {
Anton Hansson91b54f12018-09-24 18:24:19 +01001204 return mTimeMs;
1205 }
Anton Hansson81f76a02018-10-04 18:40:22 +01001206
1207 @Override
1208 public boolean equals(Object o) {
1209 if (!(o instanceof Partition)) {
1210 return false;
1211 }
1212 Partition op = (Partition) o;
1213 return mName.equals(op.mName)
1214 && mFingerprint.equals(op.mFingerprint)
1215 && mTimeMs == op.mTimeMs;
1216 }
1217
1218 @Override
1219 public int hashCode() {
1220 return Objects.hash(mName, mFingerprint, mTimeMs);
1221 }
Anton Hansson91b54f12018-09-24 18:24:19 +01001222 }
1223
1224 /**
1225 * Get build information about partitions that have a separate fingerprint defined.
1226 *
1227 * The list includes partitions that are suitable candidates for over-the-air updates. This is
1228 * not an exhaustive list of partitions on the device.
1229 */
Anton Hansson81f76a02018-10-04 18:40:22 +01001230 @NonNull
1231 public static List<Partition> getFingerprintedPartitions() {
Anton Hansson91b54f12018-09-24 18:24:19 +01001232 ArrayList<Partition> partitions = new ArrayList();
1233
1234 String[] names = new String[] {
Jeongik Cha9ec059a2019-07-04 21:12:06 +09001235 "bootimage", "odm", "product", "system_ext", Partition.PARTITION_NAME_SYSTEM,
Anton Hansson91b54f12018-09-24 18:24:19 +01001236 "vendor"
1237 };
1238 for (String name : names) {
1239 String fingerprint = SystemProperties.get("ro." + name + ".build.fingerprint");
1240 if (TextUtils.isEmpty(fingerprint)) {
1241 continue;
1242 }
1243 long time = getLong("ro." + name + ".build.date.utc") * 1000;
1244 partitions.add(new Partition(name, fingerprint, time));
1245 }
1246
1247 return partitions;
1248 }
1249
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001250 // The following properties only make sense for internal engineering builds.
Anton Hansson91b54f12018-09-24 18:24:19 +01001251
1252 /** The time at which the build was produced, given in milliseconds since the UNIX epoch. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001253 public static final long TIME = getLong("ro.build.date.utc") * 1000;
1254 public static final String USER = getString("ro.build.user");
1255 public static final String HOST = getString("ro.build.host");
1256
Doug Zongkerad2171a2011-06-14 11:07:24 -07001257 /**
Jeff Brown89101cd92011-10-27 21:24:54 -07001258 * Returns true if we are running a debug build such as "user-debug" or "eng".
1259 * @hide
1260 */
Andrei Onea24ec3212019-03-15 17:35:05 +00001261 @UnsupportedAppUsage
Jeff Brown89101cd92011-10-27 21:24:54 -07001262 public static final boolean IS_DEBUGGABLE =
1263 SystemProperties.getInt("ro.debuggable", 0) == 1;
1264
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001265 /** {@hide} */
Jeff Sharkeycdee83a2017-01-26 15:29:16 -07001266 public static final boolean IS_ENG = "eng".equals(TYPE);
1267 /** {@hide} */
1268 public static final boolean IS_USERDEBUG = "userdebug".equals(TYPE);
1269 /** {@hide} */
1270 public static final boolean IS_USER = "user".equals(TYPE);
Jeff Sharkey5eb3eb52016-12-13 08:44:51 -07001271
Jeff Brown89101cd92011-10-27 21:24:54 -07001272 /**
Xiaohui Chen387c65f2017-01-17 14:29:03 -08001273 * Whether this build is running inside a container.
1274 *
1275 * We should try to avoid checking this flag if possible to minimize
1276 * unnecessarily diverging from non-container Android behavior.
1277 * Checking this flag is acceptable when low-level resources being
1278 * different, e.g. the availability of certain capabilities, access to
1279 * system resources being restricted, and the fact that the host OS might
1280 * handle some features for us.
1281 * For higher-level behavior differences, other checks should be preferred.
1282 * @hide
1283 */
1284 public static final boolean IS_CONTAINER =
1285 SystemProperties.getBoolean("ro.boot.container", false);
1286
1287 /**
Svet Ganov9c165d72015-12-01 19:52:26 -08001288 * Specifies whether the permissions needed by a legacy app should be
1289 * reviewed before any of its components can run. A legacy app is one
1290 * with targetSdkVersion < 23, i.e apps using the old permission model.
1291 * If review is not required, permissions are reviewed before the app
1292 * is installed.
1293 *
1294 * @hide
Svet Ganov77df6f32016-08-17 11:46:34 -07001295 * @removed
Svet Ganov9c165d72015-12-01 19:52:26 -08001296 */
Svet Ganovae0e03a2016-02-25 18:22:10 -08001297 @SystemApi
Philip P. Moltmann6c644e62018-07-18 15:41:24 -07001298 public static final boolean PERMISSIONS_REVIEW_REQUIRED = true;
Svet Ganov9c165d72015-12-01 19:52:26 -08001299
kanewang(43918)25106a92020-11-02 13:38:27 +08001300 /** {@hide} */
1301 public static String getFairphoneModel() {
1302 String backCamera = getString("persist.vendor.camera.back");
1303 String frontCamera = getString("persist.vendor.camera.front");
1304 String pcba = getString("ro.boot.pcbastage");
1305 return backCamera.equals("S5KGM1SP_TXD")
1306 && frontCamera.equals("S5K3P9SP_TXD")
1307 && pcba.contains("8903")
1308 ? "FP3+"
1309 : "FP3";
1310 }
1311
Svet Ganov9c165d72015-12-01 19:52:26 -08001312 /**
Doug Zongkerad2171a2011-06-14 11:07:24 -07001313 * Returns the version string for the radio firmware. May return
1314 * null (if, for instance, the radio is not currently on).
1315 */
1316 public static String getRadioVersion() {
Inseob Kim1b5e2412019-11-08 15:06:37 +09001317 return joinListOrElse(TelephonyProperties.baseband_version(), null);
Doug Zongkerad2171a2011-06-14 11:07:24 -07001318 }
1319
Andrei Onea24ec3212019-03-15 17:35:05 +00001320 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001321 private static String getString(String property) {
1322 return SystemProperties.get(property, UNKNOWN);
1323 }
1324
Torne (Richard Coles)ff701a62014-07-30 12:11:15 +01001325 private static String[] getStringList(String property, String separator) {
1326 String value = SystemProperties.get(property);
1327 if (value.isEmpty()) {
1328 return new String[0];
1329 } else {
1330 return value.split(separator);
1331 }
1332 }
1333
Andrei Onea24ec3212019-03-15 17:35:05 +00001334 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001335 private static long getLong(String property) {
1336 try {
1337 return Long.parseLong(SystemProperties.get(property));
1338 } catch (NumberFormatException e) {
1339 return -1;
1340 }
1341 }
Inseob Kim1b5e2412019-11-08 15:06:37 +09001342
1343 private static <T> String joinListOrElse(List<T> list, String defaultValue) {
1344 String ret = list.stream().map(elem -> elem == null ? "" : elem.toString())
1345 .collect(Collectors.joining(","));
1346 return ret.isEmpty() ? defaultValue : ret;
1347 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001348}