Allow setting future api level before REL

At the dev stage, devices may set ro.board.(first_)api_level to the
future API level

Bug: 276927022
Test: test_post_process_props.py
Change-Id: I85c29af74ed8daa780278f64b023480bb6659781
This commit is contained in:
Justin Yun 2023-04-06 16:28:12 +09:00
parent 557a4d56c9
commit 870ea2e188
2 changed files with 24 additions and 7 deletions

View file

@ -43,7 +43,7 @@ def validate_grf_props(prop_list, sdk_version):
"""Validate GRF properties if exist.
If ro.board.first_api_level is defined, check if its value is valid for the
sdk version.
sdk version. This is only for the release version.
Also, validate the value of ro.board.api_level if defined.
Returns:
@ -51,6 +51,7 @@ def validate_grf_props(prop_list, sdk_version):
"""
grf_api_level = prop_list.get_value("ro.board.first_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 board_api_level:
@ -61,6 +62,18 @@ def validate_grf_props(prop_list, sdk_version):
return True
grf_api_level = int(grf_api_level)
if board_api_level:
board_api_level = int(board_api_level)
if board_api_level < grf_api_level:
sys.stderr.write("error: ro.board.api_level(%d) must be greater than "
"ro.board.first_api_level(%d)\n"
% (board_api_level, grf_api_level))
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"
@ -68,12 +81,10 @@ def validate_grf_props(prop_list, sdk_version):
return False
if board_api_level:
board_api_level = int(board_api_level)
if board_api_level < grf_api_level or board_api_level > sdk_version:
sys.stderr.write("error: ro.board.api_level(%d) must be neither less "
"than ro.board.first_api_level(%d) nor greater than "
"ro.build.version.sdk(%d)\n"
% (board_api_level, grf_api_level, sdk_version))
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

View file

@ -256,6 +256,7 @@ class PropListTestcase(unittest.TestCase):
with contextlib.redirect_stderr(stderr_redirect):
props = PropList("hello")
props.put("ro.board.first_api_level","25")
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))
@ -273,5 +274,10 @@ class PropListTestcase(unittest.TestCase):
# 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__':
unittest.main(verbosity=2)