Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 136fa83d authored by Justin Yun's avatar Justin Yun Committed by Gerrit Code Review
Browse files

Merge "Define BOARD_API_LEVEL and BOARD_API_LEVEL_FROZEN" into main

parents 534b47bc 23d52435
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -988,6 +988,21 @@ ifneq (,$(_unsupported_systemsdk_versions))
          Supported versions are $(PLATFORM_SYSTEMSDK_VERSIONS))
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_*

+8 −2
Original line number Diff line number Diff line
@@ -293,16 +293,22 @@ endif

# Vendors with GRF must define BOARD_SHIPPING_API_LEVEL for the vendor API level.
# 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
ADDITIONAL_VENDOR_PROPERTIES += \
    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.
# The values of the GRF properties will be verified by post_process_props.py
# Build system set BOARD_API_LEVEL to show the api level of the vendor API surface.
# This must not be altered outside of build system.
ifdef BOARD_API_LEVEL
ADDITIONAL_VENDOR_PROPERTIES += \
    ro.board.api_level=$(BOARD_API_LEVEL)
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

# Set build prop. This prop is read by ota_from_target_files when generating OTA,
+6 −34
Original line number Diff line number Diff line
@@ -39,54 +39,26 @@ def mangle_build_prop(prop_list):
        val = val + ",adb"
      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.

  If ro.board.first_api_level is defined, check if its value is valid for the
  sdk version. This is only for the release version.
  Also, validate the value of ro.board.api_level if defined.
  If ro.board.first_api_level is defined, check if its value is valid.

  Returns:
    True if the GRF properties are valid.
  """
  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:
      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

  if grf_api_level and board_api_level:
    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 "
      sys.stderr.write("error: ro.board.api_level(%d) must not be less 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"
                     % (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

def validate(prop_list):
@@ -271,7 +243,7 @@ def main(argv):
  mangle_build_prop(props)
  if not override_optional_props(props, args.allow_dup):
    sys.exit(1)
  if not validate_grf_props(props, args.sdk_version):
  if not validate_grf_props(props):
    sys.exit(1)
  if not validate(props):
    sys.exit(1)
+5 −17
Original line number Diff line number Diff line
@@ -255,29 +255,17 @@ class PropListTestcase(unittest.TestCase):
    stderr_redirect = io.StringIO()
    with contextlib.redirect_stderr(stderr_redirect):
      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")

      # 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
      props.put("ro.board.api_level","20")
      self.assertFalse(validate_grf_props(props, 26))
      props.put("ro.board.api_level","202404")
      self.assertFalse(validate_grf_props(props))

      props.get_all_props()[-1].make_as_comment()
      # manually set ro.board.api_level to a valid value
      props.put("ro.board.api_level","26")
      self.assertTrue(validate_grf_props(props, 26))
      # 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))
      props.put("ro.board.api_level","202504")
      self.assertTrue(validate_grf_props(props))

if __name__ == '__main__':
    unittest.main(verbosity=2)