Define BOARD_API_LEVEL and BOARD_API_LEVEL_FROZEN

BOARD_API_LEVEL and BOARD_API_LEVEL_FROZEN are set by the release
flags.
BOARD_API_LEVEL sets ro.board.api_level that shows the API level of
the vendor API surface.
BOARD_API_LEVEL_FROZEN sets ro.board.api_frozen that shows if the
ro.board.api_level is finalized.

Bug: 295269182
Test: getprop ro.board.api_level
Change-Id: Ie57c57b6c9f1fc0c98968195843059a48da8e512
This commit is contained in:
Justin Yun 2023-11-10 16:31:04 +09:00
parent 481b02106c
commit 23d52435f3
4 changed files with 34 additions and 53 deletions

View file

@ -988,6 +988,21 @@ ifneq (,$(_unsupported_systemsdk_versions))
Supported versions are $(PLATFORM_SYSTEMSDK_VERSIONS)) Supported versions are $(PLATFORM_SYSTEMSDK_VERSIONS))
endif endif
###########################################
# BOARD_API_LEVEL for vendor API surface
ifdef RELEASE_BOARD_API_LEVEL
ifdef BOARD_API_LEVEL
$(error BOARD_API_LEVEL must not set manully. The build system automatically sets this value.)
endif
BOARD_API_LEVEL := $(RELEASE_BOARD_API_LEVEL)
.KATI_READONLY := BOARD_API_LEVEL
ifdef RELEASE_BOARD_API_LEVEL_FROZEN
BOARD_API_LEVEL_FROZEN := true
.KATI_READONLY := BOARD_API_LEVEL_FROZEN
endif
endif
########################################### ###########################################
# Handle BUILD_BROKEN_USES_BUILD_* # Handle BUILD_BROKEN_USES_BUILD_*

View file

@ -293,16 +293,22 @@ endif
# Vendors with GRF must define BOARD_SHIPPING_API_LEVEL for the vendor API level. # Vendors with GRF must define BOARD_SHIPPING_API_LEVEL for the vendor API level.
# This must not be defined for the non-GRF devices. # This must not be defined for the non-GRF devices.
# The values of the GRF properties will be verified by post_process_props.py
ifdef BOARD_SHIPPING_API_LEVEL ifdef BOARD_SHIPPING_API_LEVEL
ADDITIONAL_VENDOR_PROPERTIES += \ ADDITIONAL_VENDOR_PROPERTIES += \
ro.board.first_api_level=$(BOARD_SHIPPING_API_LEVEL) ro.board.first_api_level=$(BOARD_SHIPPING_API_LEVEL)
endif
# To manually set the vendor API level of the vendor modules, BOARD_API_LEVEL can be used. # Build system set BOARD_API_LEVEL to show the api level of the vendor API surface.
# The values of the GRF properties will be verified by post_process_props.py # This must not be altered outside of build system.
ifdef BOARD_API_LEVEL ifdef BOARD_API_LEVEL
ADDITIONAL_VENDOR_PROPERTIES += \ ADDITIONAL_VENDOR_PROPERTIES += \
ro.board.api_level=$(BOARD_API_LEVEL) ro.board.api_level=$(BOARD_API_LEVEL)
endif endif
# BOARD_API_LEVEL_FROZEN is true when the vendor API surface is frozen.
ifdef BOARD_API_LEVEL_FROZEN
ADDITIONAL_VENDOR_PROPERTIES += \
ro.board.api_frozen=$(BOARD_API_LEVEL_FROZEN)
endif endif
# Set build prop. This prop is read by ota_from_target_files when generating OTA, # Set build prop. This prop is read by ota_from_target_files when generating OTA,

View file

@ -39,54 +39,26 @@ def mangle_build_prop(prop_list):
val = val + ",adb" val = val + ",adb"
prop_list.put("persist.sys.usb.config", val) prop_list.put("persist.sys.usb.config", val)
def validate_grf_props(prop_list, sdk_version): def validate_grf_props(prop_list):
"""Validate GRF properties if exist. """Validate GRF properties if exist.
If ro.board.first_api_level is defined, check if its value is valid for the If ro.board.first_api_level is defined, check if its value is valid.
sdk version. This is only for the release version.
Also, validate the value of ro.board.api_level if defined.
Returns: Returns:
True if the GRF properties are valid. True if the GRF properties are valid.
""" """
grf_api_level = prop_list.get_value("ro.board.first_api_level") grf_api_level = prop_list.get_value("ro.board.first_api_level")
board_api_level = prop_list.get_value("ro.board.api_level") board_api_level = prop_list.get_value("ro.board.api_level")
platform_version_codename = prop_list.get_value("ro.build.version.codename")
if not grf_api_level: if grf_api_level and board_api_level:
if board_api_level: grf_api_level = int(grf_api_level)
sys.stderr.write("error: non-GRF device must not define "
"ro.board.api_level\n")
return False
# non-GRF device skips the GRF validation test
return True
grf_api_level = int(grf_api_level)
if board_api_level:
board_api_level = int(board_api_level) board_api_level = int(board_api_level)
if board_api_level < grf_api_level: if board_api_level < grf_api_level:
sys.stderr.write("error: ro.board.api_level(%d) must be greater than " sys.stderr.write("error: ro.board.api_level(%d) must not be less than "
"ro.board.first_api_level(%d)\n" "ro.board.first_api_level(%d)\n"
% (board_api_level, grf_api_level)) % (board_api_level, grf_api_level))
return False return False
# skip sdk version validation for dev-stage non-REL devices
if platform_version_codename != "REL":
return True
if grf_api_level > sdk_version:
sys.stderr.write("error: ro.board.first_api_level(%d) must be less than "
"or equal to ro.build.version.sdk(%d)\n"
% (grf_api_level, sdk_version))
return False
if board_api_level:
if board_api_level > sdk_version:
sys.stderr.write("error: ro.board.api_level(%d) must be less than or "
"equal to ro.build.version.sdk(%d)\n"
% (board_api_level, sdk_version))
return False
return True return True
def validate(prop_list): def validate(prop_list):
@ -271,7 +243,7 @@ def main(argv):
mangle_build_prop(props) mangle_build_prop(props)
if not override_optional_props(props, args.allow_dup): if not override_optional_props(props, args.allow_dup):
sys.exit(1) sys.exit(1)
if not validate_grf_props(props, args.sdk_version): if not validate_grf_props(props):
sys.exit(1) sys.exit(1)
if not validate(props): if not validate(props):
sys.exit(1) sys.exit(1)

View file

@ -255,29 +255,17 @@ class PropListTestcase(unittest.TestCase):
stderr_redirect = io.StringIO() stderr_redirect = io.StringIO()
with contextlib.redirect_stderr(stderr_redirect): with contextlib.redirect_stderr(stderr_redirect):
props = PropList("hello") props = PropList("hello")
props.put("ro.board.first_api_level","25") props.put("ro.board.first_api_level","202504")
props.put("ro.build.version.codename", "REL") props.put("ro.build.version.codename", "REL")
# ro.board.first_api_level must be less than or equal to the sdk version
self.assertFalse(validate_grf_props(props, 20))
self.assertTrue(validate_grf_props(props, 26))
self.assertTrue(validate_grf_props(props, 35))
# manually set ro.board.api_level to an invalid value # manually set ro.board.api_level to an invalid value
props.put("ro.board.api_level","20") props.put("ro.board.api_level","202404")
self.assertFalse(validate_grf_props(props, 26)) self.assertFalse(validate_grf_props(props))
props.get_all_props()[-1].make_as_comment() props.get_all_props()[-1].make_as_comment()
# manually set ro.board.api_level to a valid value # manually set ro.board.api_level to a valid value
props.put("ro.board.api_level","26") props.put("ro.board.api_level","202504")
self.assertTrue(validate_grf_props(props, 26)) self.assertTrue(validate_grf_props(props))
# ro.board.api_level must be less than or equal to the sdk version
self.assertFalse(validate_grf_props(props, 25))
# allow setting future api_level before release
props.get_all_props()[-2].make_as_comment()
props.put("ro.build.version.codename", "NonRel")
self.assertTrue(validate_grf_props(props, 24))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main(verbosity=2) unittest.main(verbosity=2)