blob: c8f5e860da5bfe0559662ee57e05cdbc17140342 [file] [log] [blame]
Avichal Rakesh74b5ae72023-12-27 16:56:45 -08001/*
2 * Copyright (C) 2024 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#include "Utils.h"
18#include <android-base/properties.h>
19#include <com_android_internal_camera_flags.h>
20
21
22namespace android {
23
24using namespace com::android::internal::camera::flags;
25
26constexpr const char *LEGACY_VNDK_VERSION_PROP = "ro.vndk.version";
27constexpr const char *BOARD_API_LEVEL_PROP = "ro.board.api_level";
28constexpr int MAX_VENDOR_API_LEVEL = 1000000;
29constexpr int FIRST_VNDK_VERSION = 202404;
30
31int getVNDKVersionFromProp(int defaultVersion) {
32 if (!com_android_internal_camera_flags_use_ro_board_api_level_for_vndk_version()) {
33 return base::GetIntProperty(LEGACY_VNDK_VERSION_PROP, defaultVersion);
34 }
35
36 int vndkVersion = base::GetIntProperty(BOARD_API_LEVEL_PROP, MAX_VENDOR_API_LEVEL);
37
38 if (vndkVersion == MAX_VENDOR_API_LEVEL) {
39 // Couldn't find property
40 return defaultVersion;
41 }
42
43 if (vndkVersion < __ANDROID_API_V__) {
44 // VNDK versions below V return the corresponding SDK version.
45 return vndkVersion;
46 }
47
48 // VNDK for Android V and above are of the format YYYYMM starting with 202404 and is bumped
49 // up once a year. So V would be 202404 and the next one would be 202504.
50 // This is the same assumption as that made in system/core/init/property_service.cpp.
51 vndkVersion = (vndkVersion - FIRST_VNDK_VERSION) / 100;
52 return __ANDROID_API_V__ + vndkVersion;
53}
54
55} // namespace android