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 androidx.core.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 */ 63 @Deprecated isAtLeastO()64 public static boolean isAtLeastO() { 65 return VERSION.SDK_INT >= 26; 66 } 67 68 /** 69 * Checks if the device is running on a pre-release version of Android O MR1 or newer. 70 * <p> 71 * @return {@code true} if O MR1 APIs are available for use, {@code false} otherwise 72 * @deprecated Android O MR1 is a finalized release and this method is no longer necessary. It 73 * will be removed in a future release of the Support Library. Instead, use 74 * {@code Build.SDK_INT >= Build.VERSION_CODES.O_MR1}. 75 */ 76 @Deprecated isAtLeastOMR1()77 public static boolean isAtLeastOMR1() { 78 return VERSION.SDK_INT >= 27; 79 } 80 81 /** 82 * Checks if the device is running on a pre-release version of Android P or newer. 83 * <p> 84 * @return {@code true} if P APIs are available for use, {@code false} otherwise 85 */ isAtLeastP()86 public static boolean isAtLeastP() { 87 return VERSION.SDK_INT >= 28; 88 } 89 90 /** 91 * Checks if the device is running on a pre-release version of Android Q or newer. 92 * <p> 93 * <strong>Note:</strong> This method will return {@code false} on devices running release 94 * versions of Android. When Android Q is finalized for release, this method will be deprecated 95 * and all calls should be replaced with {@code Build.SDK_INT >= Build.VERSION_CODES.Q}. 96 * 97 * @return {@code true} if Q APIs are available for use, {@code false} otherwise 98 */ isAtLeastQ()99 public static boolean isAtLeastQ() { 100 return VERSION.CODENAME.length() == 1 101 && VERSION.CODENAME.charAt(0) >= 'Q' 102 && VERSION.CODENAME.charAt(0) <= 'Z'; 103 } 104 } 105