OSDN Git Service

Add Build.isAtLeastO
authorClara Bayarri <clarabayarri@google.com>
Mon, 8 Aug 2016 13:52:57 +0000 (14:52 +0100)
committerClara Bayarri <clarabayarri@google.com>
Mon, 8 Aug 2016 13:58:50 +0000 (14:58 +0100)
This makes it easier for features to check the build is O or later
without dealing with codenames and then the switch to an api number.

Change-Id: Ica04e0fdf1e68d72f289f5428aaff6c5aff816c9

core/java/android/os/Build.java

index c5e09bd..10ee739 100644 (file)
@@ -840,4 +840,16 @@ public class Build {
             return -1;
         }
     }
+
+    /**
+     * Check if the device is running on the Android O release or newer.
+     *
+     * @return {@code true} if O APIs are available for use
+     *
+     * @hide
+     */
+    public static boolean isAtLeastO() {
+        return !"REL".equals(VERSION.CODENAME)
+                && "O".compareTo(VERSION.CODENAME) <= 0;
+    }
 }