1 /* 2 * Copyright (C) 2020 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 #pragma once 18 19 #include <android-base/properties.h> 20 #include <android/api-level.h> 21 22 namespace android { 23 namespace modules { 24 namespace sdklevel { 25 26 // Checks if the codename is a matching or higher version than the device's 27 // codename. IsAtLeastPreReleaseCodename(const std::string & codename)28static bool IsAtLeastPreReleaseCodename(const std::string &codename) { 29 const std::string &deviceCodename = 30 android::base::GetProperty("ro.build.version.codename", ""); 31 return "REL" != deviceCodename && deviceCodename.compare(codename) >= 0; 32 } 33 34 // Checks if the device is running on release version of Android R or newer. IsAtLeastR()35static inline bool IsAtLeastR() { return android_get_device_api_level() >= 30; } 36 37 // Checks if the device is running on a pre-release version of Android S or a 38 // release version of Android S or newer. IsAtLeastS()39static inline bool IsAtLeastS() { return android_get_device_api_level() >= 31; } 40 41 // Checks if the device is running on a pre-release version of Android T or a 42 // release version of Android T or newer. IsAtLeastT()43static inline bool IsAtLeastT() { return IsAtLeastPreReleaseCodename("T"); } 44 45 } // namespace utils 46 } // namespace modules 47 } // namespace android 48