Improve forward compatibility for BuildCompat.isAtLeastX() methods
Bug: 37193704
Test: n/a
Change-Id: I5d7b651e79cb460d082df49adab0cd5349ee2c83
(cherry picked from commit 4736f7de68dafa1a79a70475981d25b6e08d8e3d)
diff --git a/api/26.0.0-SNAPSHOT.txt b/api/26.0.0-SNAPSHOT.txt
index 121357c..13339db 100644
--- a/api/26.0.0-SNAPSHOT.txt
+++ b/api/26.0.0-SNAPSHOT.txt
@@ -7386,9 +7386,11 @@
}
public class BuildCompat {
- method public static boolean isAtLeastN();
- method public static boolean isAtLeastNMR1();
+ method public static deprecated boolean isAtLeastN();
+ method public static deprecated boolean isAtLeastNMR1();
method public static boolean isAtLeastO();
+ method public static boolean isAtLeastOMR1();
+ method public static boolean isAtLeastP();
}
public final class CancellationSignal {
diff --git a/compat/java/android/support/v4/os/BuildCompat.java b/compat/java/android/support/v4/os/BuildCompat.java
index 2ab9b7a..4977d18 100644
--- a/compat/java/android/support/v4/os/BuildCompat.java
+++ b/compat/java/android/support/v4/os/BuildCompat.java
@@ -14,52 +14,83 @@
* limitations under the License.
*/
-
package android.support.v4.os;
import android.os.Build.VERSION;
/**
- * BuildCompat contains additional platform version checking methods for
- * testing compatibility with new features.
+ * This class contains additional platform version checking methods for targeting pre-release
+ * versions of Android.
*/
public class BuildCompat {
private BuildCompat() {
}
- /* Boilerplate for isAtLeast${PLATFORM}:
- * public static boolean isAtLeast*() {
- * return !"REL".equals(VERSION.CODENAME)
- * && ("${PLATFORM}".equals(VERSION.CODENAME)
- * || VERSION.CODENAME.startsWith("${PLATFORM}MR"));
- * }
- */
/**
- * Check if the device is running on the Android N release or newer.
+ * Checks if the device is running on the Android N release or newer.
*
* @return {@code true} if N APIs are available for use
+ * @deprecated Android N is a finalized release and this method is no longer necessary. It will
+ * be removed in a future release of the Support Library. Instead, use
+ * {@code Build.SDK_INT >= Build.VERSION_CODES#N}.
*/
+ @Deprecated
public static boolean isAtLeastN() {
return VERSION.SDK_INT >= 24;
}
/**
- * Check if the device is running on the Android N MR1 release or newer.
+ * Checks if the device is running on the Android N MR1 release or newer.
*
* @return {@code true} if N MR1 APIs are available for use
+ * @deprecated Android N MR1 is a finalized release and this method is no longer necessary. It
+ * will be removed in a future release of the Support Library. Instead, use
+ * {@code Build.SDK_INT >= Build.VERSION_CODES#N_MR1}.
*/
+ @Deprecated
public static boolean isAtLeastNMR1() {
return VERSION.SDK_INT >= 25;
}
/**
- * Check if the device is running on the Android O release or newer.
+ * Checks if the device is running on a pre-release version of Android O or newer.
+ * <p>
+ * <strong>Note:</strong> This method will return {@code false} on devices running release
+ * versions of Android. When Android O is finalized for release, this method will be deprecated
+ * and all calls should be replaced with {@code Build.SDK_INT >= Build.VERSION_CODES#O}.
*
- * @return {@code true} if O APIs are available for use
+ * @return {@code true} if O APIs are available for use, {@code false} otherwise
*/
public static boolean isAtLeastO() {
- return !"REL".equals(VERSION.CODENAME)
- && ("O".equals(VERSION.CODENAME) || VERSION.CODENAME.startsWith("OMR")
- || VERSION.CODENAME.startsWith("ODR"));
+ return VERSION.CODENAME.equals("O")
+ || VERSION.CODENAME.startsWith("ODR")
+ || isAtLeastOMR1();
+ }
+
+ /**
+ * Checks if the device is running on a pre-release version of Android O MR1 or newer.
+ * <p>
+ * <strong>Note:</strong> This method will return {@code false} on devices running release
+ * versions of Android. When Android O is finalized for release, this method will be deprecated
+ * and all calls should be replaced with {@code Build.SDK_INT >= Build.VERSION_CODES#O_MR1}.
+ *
+ * @return {@code true} if O APIs are available for use, {@code false} otherwise
+ */
+ public static boolean isAtLeastOMR1() {
+ return VERSION.CODENAME.startsWith("OMR")
+ || isAtLeastP();
+ }
+
+ /**
+ * Checks if the device is running on a pre-release version of Android P or newer.
+ * <p>
+ * <strong>Note:</strong> This method will return {@code false} on devices running release
+ * versions of Android. When Android P is finalized for release, this method will be deprecated
+ * and all calls should be replaced with {@code Build.SDK_INT >= Build.VERSION_CODES#P}.
+ *
+ * @return {@code true} if O APIs are available for use, {@code false} otherwise
+ */
+ public static boolean isAtLeastP() {
+ return VERSION.CODENAME.equals("P");
}
}