1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.support.v4.os; 18 19 import android.os.Build.VERSION; 20 21 /** 22 * This class contains additional platform version checking methods for targeting pre-release 23 * versions of Android. 24 */ 25 public class BuildCompat { BuildCompat()26 private BuildCompat() { 27 } 28 29 /** 30 * Checks if the device is running on the Android N release or newer. 31 * 32 * @return {@code true} if N APIs are available for use 33 * @deprecated Android N is a finalized release and this method is no longer necessary. It will 34 * be removed in a future release of the Support Library. Instead, use 35 * {@code Build.SDK_INT >= Build.VERSION_CODES#N}. 36 */ 37 @Deprecated isAtLeastN()38 public static boolean isAtLeastN() { 39 return VERSION.SDK_INT >= 24; 40 } 41 42 /** 43 * Checks if the device is running on the Android N MR1 release or newer. 44 * 45 * @return {@code true} if N MR1 APIs are available for use 46 * @deprecated Android N MR1 is a finalized release and this method is no longer necessary. It 47 * will be removed in a future release of the Support Library. Instead, use 48 * {@code Build.SDK_INT >= Build.VERSION_CODES#N_MR1}. 49 */ 50 @Deprecated isAtLeastNMR1()51 public static boolean isAtLeastNMR1() { 52 return VERSION.SDK_INT >= 25; 53 } 54 55 /** 56 * Checks if the device is running on a pre-release version of Android O or newer. 57 * <p> 58 * @return {@code true} if O APIs are available for use, {@code false} otherwise 59 * @deprecated Android O is a finalized release and this method is no longer necessary. It will 60 * be removed in a future release of the Support Library. Instead use 61 * {@code Build.SDK_INT >= Build.VERSION_CODES#O}. 62 */ isAtLeastO()63 public static boolean isAtLeastO() { 64 return VERSION.SDK_INT >= 26; 65 } 66 67 /** 68 * Checks if the device is running on a pre-release version of Android O MR1 or newer. 69 * <p> 70 * <strong>Note:</strong> This method will return {@code false} on devices running release 71 * versions of Android. When Android O MR1 is finalized for release, this method will be 72 * deprecated and all calls should be replaced with 73 * {@code Build.SDK_INT >= Build.VERSION_CODES#O_MR1}. 74 * 75 * @return {@code true} if O MR1 APIs are available for use, {@code false} otherwise 76 */ isAtLeastOMR1()77 public static boolean isAtLeastOMR1() { 78 return VERSION.CODENAME.startsWith("OMR") 79 || isAtLeastP(); 80 } 81 82 /** 83 * Checks if the device is running on a pre-release version of Android P or newer. 84 * <p> 85 * <strong>Note:</strong> This method will return {@code false} on devices running release 86 * versions of Android. When Android P is finalized for release, this method will be deprecated 87 * and all calls should be replaced with {@code Build.SDK_INT >= Build.VERSION_CODES#P}. 88 * 89 * @return {@code true} if P APIs are available for use, {@code false} otherwise 90 */ isAtLeastP()91 public static boolean isAtLeastP() { 92 return VERSION.CODENAME.equals("P"); 93 } 94 } 95