summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreeHugger Robot <treehugger-gerrit@google.com>2023-02-14 06:45:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-02-14 06:45:20 +0000
commitba3a178abe8762771c78debf1ccf342312aae1c3 (patch)
treeb3aba730e4be5375920db950fca3f408c0992d64
parent7606f5baa481222cbc229e1960c01b93e4034186 (diff)
parent4ad07dc499d36781c8bcbb6117d7da7acadc1774 (diff)
downloadsetupcompat-ba3a178abe8762771c78debf1ccf342312aae1c3.tar.gz
Merge "Fix isAtLeastU for post-U codenames"
-rw-r--r--main/java/com/google/android/setupcompat/util/BuildCompatUtils.java18
1 files changed, 13 insertions, 5 deletions
diff --git a/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java b/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java
index d1b0ccb..cccc413 100644
--- a/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java
+++ b/main/java/com/google/android/setupcompat/util/BuildCompatUtils.java
@@ -74,7 +74,7 @@ public final class BuildCompatUtils {
* <li>For current Android release: while new API is not finalized yet (CODENAME =
* "UpsideDownCake", SDK_INT = 33)
* <li>For current Android release: when new API is finalized (CODENAME = "REL", SDK_INT = 34)
- * <li>For next Android release (CODENAME = "V", SDK_INT = 35+)
+ * <li>For next Android release (CODENAME = "VanillaIceCream", SDK_INT = 35+)
* </ul>
*
* <p>Note that Build.VERSION_CODES.T cannot be used here until final SDK is available in all
@@ -84,10 +84,18 @@ public final class BuildCompatUtils {
*/
public static boolean isAtLeastU() {
return (Build.VERSION.CODENAME.equals("REL") && Build.VERSION.SDK_INT >= 34)
- || (Build.VERSION.CODENAME.length() == 1
- && Build.VERSION.CODENAME.charAt(0) >= 'U'
- && Build.VERSION.CODENAME.charAt(0) <= 'Z')
- || (Build.VERSION.CODENAME.equals("UpsideDownCake") && Build.VERSION.SDK_INT >= 33);
+ || isAtLeastPreReleaseCodename("UpsideDownCake");
+ }
+
+ private static boolean isAtLeastPreReleaseCodename(String codename) {
+ // Special case "REL", which means the build is not a pre-release build.
+ if (Build.VERSION.CODENAME.equals("REL")) {
+ return false;
+ }
+
+ // Otherwise lexically compare them. Return true if the build codename is equal to or
+ // greater than the requested codename.
+ return Build.VERSION.CODENAME.compareTo(codename) >= 0;
}
private BuildCompatUtils() {}