Make isAtLeast*() robust against lowercase codenames from old sdks
Chrome was using the same code and was seeing some crashes in the wild
from older devices.
https://bugs.chromium.org/p/chromium/issues/detail?id=1260525#c2
Change-Id: Iefdc77ced172e125244ae3b677e6f00ebba534e8
diff --git a/core/core/src/main/java/androidx/core/os/BuildCompat.java b/core/core/src/main/java/androidx/core/os/BuildCompat.java
index 835f1c9..8e25696 100644
--- a/core/core/src/main/java/androidx/core/os/BuildCompat.java
+++ b/core/core/src/main/java/androidx/core/os/BuildCompat.java
@@ -24,6 +24,8 @@
import androidx.annotation.RequiresOptIn;
import androidx.annotation.RestrictTo;
+import java.util.Locale;
+
/**
* This class contains additional platform version checking methods for targeting pre-release
* versions of Android.
@@ -54,7 +56,7 @@
// Otherwise lexically compare them. Return true if the build codename is equal to or
// greater than the requested codename.
- return buildCodename.compareTo(codename) >= 0;
+ return buildCodename.toUpperCase(Locale.ROOT).compareTo(codename) >= 0;
}
/**
@@ -163,7 +165,8 @@
*/
@ChecksSdkIntAtLeast(api = 31, codename = "S")
public static boolean isAtLeastS() {
- return VERSION.SDK_INT >= 31 || isAtLeastPreReleaseCodename("S", VERSION.CODENAME);
+ return VERSION.SDK_INT >= 31
+ || (VERSION.SDK_INT >= 30 && isAtLeastPreReleaseCodename("S", VERSION.CODENAME));
}
/**
@@ -179,7 +182,7 @@
@PrereleaseSdkCheck
@ChecksSdkIntAtLeast(codename = "T")
public static boolean isAtLeastT() {
- return isAtLeastPreReleaseCodename("T", VERSION.CODENAME);
+ return VERSION.SDK_INT >= 31 && isAtLeastPreReleaseCodename("T", VERSION.CODENAME);
}
/**