From e960030f75d2b510706c4623d94ad71aba427fb8 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Wed, 6 May 2015 18:13:09 -0700 Subject: [PATCH] Add Build.VERSION.PREVIEW_SDK_INT Add a constant to the SDK that apps may use to detect incremental API changes across prerelease preview builds. APIs newer than the latest official API level are not guaranteed to be stable or even present across preview revisions. Change-Id: I14341e55a3ebc3d872977970b9440c400e71f588 --- api/current.txt | 1 + api/system-current.txt | 1 + core/java/android/os/Build.java | 21 +++++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/api/current.txt b/api/current.txt index 0ef476632ee32..4ee1c517b82f4 100644 --- a/api/current.txt +++ b/api/current.txt @@ -22906,6 +22906,7 @@ package android.os { ctor public Build.VERSION(); field public static final java.lang.String CODENAME; field public static final java.lang.String INCREMENTAL; + field public static final int PREVIEW_SDK_INT; field public static final java.lang.String RELEASE; field public static final deprecated java.lang.String SDK; field public static final int SDK_INT; diff --git a/api/system-current.txt b/api/system-current.txt index 3aa6ca0cd4739..4563edc07f1ab 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -24805,6 +24805,7 @@ package android.os { ctor public Build.VERSION(); field public static final java.lang.String CODENAME; field public static final java.lang.String INCREMENTAL; + field public static final int PREVIEW_SDK_INT; field public static final java.lang.String RELEASE; field public static final deprecated java.lang.String SDK; field public static final int SDK_INT; diff --git a/core/java/android/os/Build.java b/core/java/android/os/Build.java index 36fc4f960d800..50eed3e9df7ee 100644 --- a/core/java/android/os/Build.java +++ b/core/java/android/os/Build.java @@ -172,6 +172,27 @@ public class Build { public static final int SDK_INT = SystemProperties.getInt( "ro.build.version.sdk", 0); + /** + * The developer preview revision of a prerelease SDK. This value will always + * be 0 on production platform builds/devices. + * + *

When this value is nonzero, any new API added since the last + * officially published {@link #SDK_INT API level} is only guaranteed to be present + * on that specific preview revision. For example, an API Activity.fooBar() + * might be present in preview revision 1 but renamed or removed entirely in + * preview revision 2, which may cause an app attempting to call it to crash + * at runtime.

+ * + *

Experimental apps targeting preview APIs should check this value for + * equality (==) with the preview SDK revision they were built for + * before using any prerelease platform APIs. Apps that detect a preview SDK revision + * other than the specific one they expect should fall back to using APIs from + * the previously published API level only to avoid unwanted runtime exceptions. + *

+ */ + public static final int PREVIEW_SDK_INT = SystemProperties.getInt( + "ro.build.version.preview_sdk", 0); + /** * The current development codename, or the string "REL" if this is * a release build.