1 /*
2  * Copyright (C) 2021 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 com.android.settingslib.utils;
18 
19 import android.os.Build;
20 import android.os.Build.VERSION;
21 
22 import androidx.annotation.ChecksSdkIntAtLeast;
23 
24 /**
25  * An util class to check whether the current OS version is higher or equal to sdk version of
26  * device.
27  */
28 public final class BuildCompatUtils {
29 
30     /**
31      * Implementation of BuildCompat.isAtLeastS() suitable for use in Settings
32      *
33      * @return Whether the current OS version is higher or equal to S.
34      */
35     @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S)
isAtLeastS()36     public static boolean isAtLeastS() {
37         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S;
38     }
39 
40     /**
41      * Implementation of BuildCompat.isAtLeastS() suitable for use in Settings
42      *
43      * @return Whether the current OS version is higher or equal to Sv2.
44      */
45     @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.S_V2)
isAtLeastSV2()46     public static boolean isAtLeastSV2() {
47         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.S_V2;
48     }
49 
50     /**
51      * Implementation of BuildCompat.isAtLeastT() suitable for use in Settings
52      *
53      * @return Whether the current OS version is higher or equal to T.
54      */
55     @ChecksSdkIntAtLeast(api = Build.VERSION_CODES.TIRAMISU)
isAtLeastT()56     public static boolean isAtLeastT() {
57         return Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;
58     }
59 
BuildCompatUtils()60     private BuildCompatUtils() {}
61 }
62