blob: 3307e72b7c30eff9e8b35a6ed34b308cc13fb6af [file] [log] [blame]
Jiyong Park641b6cc2018-01-15 14:48:40 +09001#
2# Copyright (C) 2018 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
17ifdef BOARD_SYSTEMSDK_VERSIONS
Jeongik Cha07a44f42020-04-25 04:31:39 +090018 # Apps and jars in vendor, product or odm partition are forced to build against System SDK.
Jeongik Cha74529792019-07-19 13:40:18 +090019 _cannot_use_platform_apis :=
Jiyong Park641b6cc2018-01-15 14:48:40 +090020 ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE)))
21 # Note: no need to check LOCAL_MODULE_PATH* since LOCAL_[VENDOR|ODM|OEM]_MODULE is already
22 # set correctly before this is included.
Jeongik Cha74529792019-07-19 13:40:18 +090023 _cannot_use_platform_apis := true
24 else ifeq ($(LOCAL_PRODUCT_MODULE),true)
25 ifeq ($(PRODUCT_ENFORCE_PRODUCT_PARTITION_INTERFACE),true)
26 _cannot_use_platform_apis := true
27 endif
Jiyong Park641b6cc2018-01-15 14:48:40 +090028 endif
29 ifneq (,$(filter JAVA_LIBRARIES APPS,$(LOCAL_MODULE_CLASS)))
30 ifndef LOCAL_SDK_VERSION
Jeongik Cha74529792019-07-19 13:40:18 +090031 ifeq ($(_cannot_use_platform_apis),true)
Jeongik Cha07a44f42020-04-25 04:31:39 +090032 ifeq (,$(LOCAL_IS_RUNTIME_RESOURCE_OVERLAY))
Anton Hansson038177b2019-01-29 15:01:06 +000033 # Runtime resource overlays are exempted from building against System SDK.
Jeongik Cha07a44f42020-04-25 04:31:39 +090034 # TODO(b/155027019): remove this, after no product/vendor apps rely on this behavior.
Jiyong Parkc0ece102018-03-26 17:16:33 +090035 LOCAL_SDK_VERSION := system_current
Jiyong Park7a669242024-01-04 23:20:42 +000036 # We have run below again since LOCAL_SDK_VERSION is newly set and the "_current"
37 # may have to be updated
38 include $(BUILD_SYSTEM)/local_current_sdk.mk
Jiyong Parkc0ece102018-03-26 17:16:33 +090039 endif
Jiyong Park641b6cc2018-01-15 14:48:40 +090040 endif
41 endif
42 endif
43endif
44
45# Ensure that the selected System SDK version is one of the supported versions.
46# The range of support versions becomes narrower when BOARD_SYSTEMSDK_VERSIONS
47# is set, which is a subset of PLATFORM_SYSTEMSDK_VERSIONS.
48ifneq (,$(call has-system-sdk-version,$(LOCAL_SDK_VERSION)))
Jeongik Cha74529792019-07-19 13:40:18 +090049 ifneq ($(_cannot_use_platform_apis),true)
Jiyong Park641b6cc2018-01-15 14:48:40 +090050 # apps bundled in system partition can use all system sdk versions provided by the platform
51 _supported_systemsdk_versions := $(PLATFORM_SYSTEMSDK_VERSIONS)
52 else ifdef BOARD_SYSTEMSDK_VERSIONS
53 # When BOARD_SYSTEMSDK_VERSIONS is set, vendors apps are restricted to use those versions
54 # which is equal to or smaller than PLATFORM_SYSTEMSDK_VERSIONS
55 _supported_systemsdk_versions := $(BOARD_SYSTEMSDK_VERSIONS)
56 else
57 # If not, vendor apks are treated equally to system apps
58 _supported_systemsdk_versions := $(PLATFORM_SYSTEMSDK_VERSIONS)
59 endif
Jiyong Park7a669242024-01-04 23:20:42 +000060
61 # b/314011075: apks and jars in the vendor or odm partitions cannot use system SDK 35 and beyond.
62 # This is to discourage the use of Java APIs in the partitions, which hasn't been supported since
63 # the beginning of the project Treble back in Android 10. Ultimately, we'd like to completely
64 # disallow any Java API in the partitions, but it shall be done progressively.
65 ifneq (,$(filter true,$(LOCAL_VENDOR_MODULE) $(LOCAL_ODM_MODULE) $(LOCAL_PROPRIETARY_MODULE)))
66 # 28 is the API level when BOARD_SYSTEMSDK_VERSIONS was introduced. So, it's the oldset API
67 # we allow.
68 _supported_systemsdk_versions := $(call int_range_list, 28, 34)
69 endif
70
71 # Extract version number from LOCAL_SDK_VERSION (ex: system_34 -> 34)
Jiyong Park641b6cc2018-01-15 14:48:40 +090072 _system_sdk_version := $(call get-numeric-sdk-version,$(LOCAL_SDK_VERSION))
Jiyong Park7a669242024-01-04 23:20:42 +000073 # However, the extraction may fail if it doesn't have any number (i.e. current, core_current,
74 # system_current, or similar) Then use the latest platform SDK version number or the actual
75 # codename.
76 ifeq (,$(_system_sdk_version)
77 ifeq (REL,$(PLATFORM_VERSION_CODENAME))
78 _system_sdk_version := $(PLATFORM_SDK_VERSION)
79 else
80 _system_sdk_version := $(PLATFORM_VERSION_CODENAME)
81 endif
82 endif
83
Jiyong Park641b6cc2018-01-15 14:48:40 +090084 ifneq ($(_system_sdk_version),$(filter $(_system_sdk_version),$(_supported_systemsdk_versions)))
Jiyong Park885b0042024-01-04 23:21:26 +000085 ifneq (true,$(BUILD_BROKEN_DONT_CHECK_SYSTEMSDK)
86 $(call pretty-error,Incompatible LOCAL_SDK_VERSION '$(LOCAL_SDK_VERSION)'. \
87 System SDK version '$(_system_sdk_version)' is not supported. Supported versions are: $(_supported_systemsdk_versions))
88 endif
Jiyong Park641b6cc2018-01-15 14:48:40 +090089 endif
90 _system_sdk_version :=
91 _supported_systemsdk_versions :=
92endif