1 // Copyright (C) 2024 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #include "api_level.h" 16 17 #include <log/log.h> 18 19 #if !defined(__ANDROID_VENDOR__) 20 #include <android-base/properties.h> 21 #endif 22 AVendorSupport_getVendorApiLevelOf(int sdkApiLevel)23int AVendorSupport_getVendorApiLevelOf(int sdkApiLevel) { 24 if (sdkApiLevel < __ANDROID_API_V__) { 25 return sdkApiLevel; 26 } 27 // In Android V, vendor API level started with version 202404. 28 // The calculation assumes that the SDK api level bumps once a year. 29 if (sdkApiLevel < __ANDROID_API_FUTURE__) { 30 return 202404 + ((sdkApiLevel - __ANDROID_API_V__) * 100); 31 } 32 ALOGE("The SDK version must be less than 10000: %d", sdkApiLevel); 33 return __INVALID_API_LEVEL; 34 } 35 AVendorSupport_getSdkApiLevelOf(int vendorApiLevel)36int AVendorSupport_getSdkApiLevelOf(int vendorApiLevel) { 37 if (vendorApiLevel < __ANDROID_API_V__) { 38 return vendorApiLevel; 39 } 40 if (vendorApiLevel >= 202404 && vendorApiLevel < __ANDROID_VENDOR_API_MAX__) { 41 return (vendorApiLevel - 202404) / 100 + __ANDROID_API_V__; 42 } 43 ALOGE("Unexpected vendor api level: %d", vendorApiLevel); 44 return __INVALID_API_LEVEL; 45 } 46 47 #if !defined(__ANDROID_VENDOR__) AVendorSupport_getVendorApiLevel()48int AVendorSupport_getVendorApiLevel() { 49 int vendorApiLevel = android::base::GetIntProperty("ro.vndk.version", 0); 50 if (vendorApiLevel) { 51 return vendorApiLevel; 52 } 53 return android::base::GetIntProperty("ro.board.api_level", 0); 54 } 55 #endif // __ANDROID_VENDOR__ 56