From a68aa856247fa0019cde92782b792b23c567d9a9 Mon Sep 17 00:00:00 2001 From: Justin Yun Date: Wed, 3 Jan 2024 16:50:25 +0900 Subject: [PATCH] Provide a new LLNDK for the vendor api level handling The library provides mapping functions between SDK versions and vendor api levels. Bug: 315056516 Test: atest libvendorsupport-tests Change-Id: I4a4eae0456ebf756badcc80f09a2946f741843c5 --- libvendorsupport/Android.bp | 35 +++++++++++++ libvendorsupport/OWNERS | 2 + libvendorsupport/TEST_MAPPING | 7 +++ .../include/vendorsupport/api_level.h | 51 +++++++++++++++++++ libvendorsupport/libvendorsupport.map.txt | 7 +++ libvendorsupport/tests/Android.bp | 33 ++++++++++++ libvendorsupport/tests/version_props_test.cpp | 37 ++++++++++++++ libvendorsupport/version_props.c | 41 +++++++++++++++ 8 files changed, 213 insertions(+) create mode 100644 libvendorsupport/Android.bp create mode 100644 libvendorsupport/OWNERS create mode 100644 libvendorsupport/TEST_MAPPING create mode 100644 libvendorsupport/include/vendorsupport/api_level.h create mode 100644 libvendorsupport/libvendorsupport.map.txt create mode 100644 libvendorsupport/tests/Android.bp create mode 100644 libvendorsupport/tests/version_props_test.cpp create mode 100644 libvendorsupport/version_props.c diff --git a/libvendorsupport/Android.bp b/libvendorsupport/Android.bp new file mode 100644 index 000000000..16a4c4c8a --- /dev/null +++ b/libvendorsupport/Android.bp @@ -0,0 +1,35 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +cc_library { + name: "libvendorsupport", + native_bridge_supported: true, + llndk: { + symbol_file: "libvendorsupport.map.txt", + }, + srcs: ["version_props.c"], + cflags: [ + "-Wall", + "-Werror", + ], + local_include_dirs: ["include/vendorsupport"], + export_include_dirs: ["include"], + shared_libs: [ + "liblog", + ], +} diff --git a/libvendorsupport/OWNERS b/libvendorsupport/OWNERS new file mode 100644 index 000000000..2ab18eba7 --- /dev/null +++ b/libvendorsupport/OWNERS @@ -0,0 +1,2 @@ +jiyong@google.com +justinyun@google.com diff --git a/libvendorsupport/TEST_MAPPING b/libvendorsupport/TEST_MAPPING new file mode 100644 index 000000000..5bd09ba4e --- /dev/null +++ b/libvendorsupport/TEST_MAPPING @@ -0,0 +1,7 @@ +{ + "postsubmit": [ + { + "name": "libvendorsupport-tests" + } + ] +} diff --git a/libvendorsupport/include/vendorsupport/api_level.h b/libvendorsupport/include/vendorsupport/api_level.h new file mode 100644 index 000000000..ba1a6b887 --- /dev/null +++ b/libvendorsupport/include/vendorsupport/api_level.h @@ -0,0 +1,51 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once + +#include + +#define __ANDROID_VENDOR_API_MAX__ 1000000 +#define __INVALID_API_LEVEL -1 + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Find corresponding vendor API level from an SDK API version. + * + * @details + * SDK API versions and vendor API levels are not compatible and not + * convertible. However, this function can be used to compare the two versions + * to know which one is newer than the other. + * + * @param sdk_api_level The SDK version int. This must be less than 10000. + * @return The corresponding vendor API level of the SDK version. -1 if the SDK + * version is invalid or 10000. + */ +int vendor_api_level_of(int sdk_api_level); + +/** + * @brief Find corresponding SDK API version from a vendor API level. + * + * @param vendor_api_level The vendor API level int. + * @return The corresponding SDK API version of the vendor API level. -1 if the + * vendor API level is invalid. + */ +int sdk_api_level_of(int vendor_api_level); + +#ifdef __cplusplus +} +#endif diff --git a/libvendorsupport/libvendorsupport.map.txt b/libvendorsupport/libvendorsupport.map.txt new file mode 100644 index 000000000..9a23b940f --- /dev/null +++ b/libvendorsupport/libvendorsupport.map.txt @@ -0,0 +1,7 @@ +LIBVENDORSUPPORT { + global: + vendor_api_level_of; # llndk systemapi + sdk_api_level_of; # llndk systemapi + local: + *; +}; diff --git a/libvendorsupport/tests/Android.bp b/libvendorsupport/tests/Android.bp new file mode 100644 index 000000000..42e3371c9 --- /dev/null +++ b/libvendorsupport/tests/Android.bp @@ -0,0 +1,33 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package { + default_applicable_licenses: ["Android-Apache-2.0"], +} + +cc_test { + name: "libvendorsupport-tests", + srcs: [ + "version_props_test.cpp", + ], + cflags: [ + "-Wall", + "-Werror", + ], + shared_libs: [ + "libvendorsupport", + ], + test_suites: ["general-tests"], +} + diff --git a/libvendorsupport/tests/version_props_test.cpp b/libvendorsupport/tests/version_props_test.cpp new file mode 100644 index 000000000..538a2e26b --- /dev/null +++ b/libvendorsupport/tests/version_props_test.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include + +#include + +using namespace std; + +namespace { + +TEST(vendorsupport, get_corresponding_vendor_api_level) { + ASSERT_EQ(__ANDROID_API_U__, vendor_api_level_of(__ANDROID_API_U__)); + ASSERT_EQ(202404, vendor_api_level_of(__ANDROID_API_V__)); + ASSERT_EQ(__INVALID_API_LEVEL, vendor_api_level_of(__ANDROID_API_FUTURE__)); +} + +TEST(vendorsupport, get_corresponding_sdk_api_level) { + ASSERT_EQ(__ANDROID_API_U__, sdk_api_level_of(__ANDROID_API_U__)); + ASSERT_EQ(__ANDROID_API_V__, sdk_api_level_of(202404)); + ASSERT_EQ(__INVALID_API_LEVEL, sdk_api_level_of(__ANDROID_VENDOR_API_MAX__)); + ASSERT_EQ(__INVALID_API_LEVEL, sdk_api_level_of(35)); +} + +} // namespace \ No newline at end of file diff --git a/libvendorsupport/version_props.c b/libvendorsupport/version_props.c new file mode 100644 index 000000000..4d0e45ecf --- /dev/null +++ b/libvendorsupport/version_props.c @@ -0,0 +1,41 @@ +// Copyright (C) 2024 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "api_level.h" + +#include + +int vendor_api_level_of(int sdk_api_level) { + if (sdk_api_level < __ANDROID_API_V__) { + return sdk_api_level; + } + // In Android V, vendor API level started with version 202404. + // The calculation assumes that the SDK api level bumps once a year. + if (sdk_api_level < __ANDROID_API_FUTURE__) { + return 202404 + ((sdk_api_level - __ANDROID_API_V__) * 100); + } + ALOGE("The SDK version must be less than 10000: %d", sdk_api_level); + return __INVALID_API_LEVEL; +} + +int sdk_api_level_of(int vendor_api_level) { + if (vendor_api_level < __ANDROID_API_V__) { + return vendor_api_level; + } + if (vendor_api_level >= 202404 && vendor_api_level < __ANDROID_VENDOR_API_MAX__) { + return (vendor_api_level - 202404) / 100 + __ANDROID_API_V__; + } + ALOGE("Unexpected vendor api level: %d", vendor_api_level); + return __INVALID_API_LEVEL; +}