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

Commit dbf3dc8a authored by Ethan Chen's avatar Ethan Chen
Browse files

fs_config: Allow targets to override OEM AID restrictions

* Some legacy devices set OEM AIDs that fall outside the Android O OEM
  AID ranges. Since legacy devices cannot necessarily change AIDs for
  their binaries easily, allow bypassing the AID restrictions if needed.

Change-Id: I13a7bc2036272b43f9424708aaacd894c8b1a65e
parent fbe26900
Loading
Loading
Loading
Loading
+10 −4
Original line number Diff line number Diff line
@@ -72,6 +72,12 @@ else
my_fs_config_h := $(LOCAL_PATH)/default/$(ANDROID_FS_CONFIG_H)
endif

ifneq ($(TARGET_FS_CONFIG_GEN),)
ifeq ($(TARGET_ALLOW_LEGACY_AIDS),true)
allow_legacy_aids := --allow-legacy-aids
endif
endif

##################################
include $(CLEAR_VARS)
LOCAL_SRC_FILES := fs_config_generate.c
@@ -88,7 +94,7 @@ oem := $(local-generated-sources-dir)/generated_oem_aid.h
$(oem): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
$(oem): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
$(oem): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
$(oem): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/fs_config_generator.py oemaid --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
$(oem): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/fs_config_generator.py oemaid --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(allow_legacy_aids) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
$(oem): $(TARGET_FS_CONFIG_GEN) $(LOCAL_PATH)/fs_config_generator.py
	$(transform-generated-source)

@@ -97,7 +103,7 @@ gen := $(local-generated-sources-dir)/$(ANDROID_FS_CONFIG_H)
$(gen): PRIVATE_LOCAL_PATH := $(LOCAL_PATH)
$(gen): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
$(gen): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
$(gen): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/fs_config_generator.py fsconfig --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
$(gen): PRIVATE_CUSTOM_TOOL = $(PRIVATE_LOCAL_PATH)/fs_config_generator.py fsconfig --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(allow_legacy_aids) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
$(gen): $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config) $(LOCAL_PATH)/fs_config_generator.py
	$(transform-generated-source)

@@ -278,7 +284,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
$(LOCAL_BUILT_MODULE): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/fs_config_generator.py $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config)
	@mkdir -p $(dir $@)
	$(hide) $< passwd --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
	$(hide) $< passwd --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(allow_legacy_aids) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@

##################################
# Generate the system/etc/group text file for the target
@@ -296,7 +302,7 @@ $(LOCAL_BUILT_MODULE): PRIVATE_TARGET_FS_CONFIG_GEN := $(TARGET_FS_CONFIG_GEN)
$(LOCAL_BUILT_MODULE): PRIVATE_ANDROID_FS_HDR := $(system_android_filesystem_config)
$(LOCAL_BUILT_MODULE): $(LOCAL_PATH)/fs_config_generator.py $(TARGET_FS_CONFIG_GEN) $(system_android_filesystem_config)
	@mkdir -p $(dir $@)
	$(hide) $< group --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@
	$(hide) $< group --aid-header=$(PRIVATE_ANDROID_FS_HDR) $(allow_legacy_aids) $(PRIVATE_TARGET_FS_CONFIG_GEN) > $@

system_android_filesystem_config :=
endif
+35 −5
Original line number Diff line number Diff line
@@ -524,7 +524,7 @@ class FSConfigFileParser(object):
    _SECTIONS = [('_handle_aid', ('value',)),
                 ('_handle_path', ('mode', 'user', 'group', 'caps'))]

    def __init__(self, config_files, oem_ranges):
    def __init__(self, config_files, oem_ranges, warn_only=False):
        """
        Args:
            config_files ([str]): The list of config.fs files to parse.
@@ -532,6 +532,7 @@ class FSConfigFileParser(object):
            oem_ranges ([(),()]): range tuples indicating reserved OEM ranges.
        """

        self._warn_only = warn_only
        self._files = []
        self._dirs = []
        self._aids = []
@@ -648,6 +649,9 @@ class FSConfigFileParser(object):
        if not Utils.in_any_range(int(aid.value, 0), self._oem_ranges):
            emsg = '"value" not in valid range %s, got: %s'
            emsg = emsg % (str(self._oem_ranges), value)
            if self._warn_only:
                sys.stderr.write(error_message(emsg))
            else:
                sys.exit(error_message(emsg))

        # use the normalized int value in the dict and detect
@@ -945,11 +949,19 @@ class FSConfigGen(BaseGenerator):
            help='An android_filesystem_config.h file'
            ' to parse AIDs and OEM Ranges from')

        opt_group.add_argument(
            '--allow-legacy-aids',
            action="store_true",
            required=False,
            default=False,
            help='Allow legacy AIDs that fall outside allowed OEM ranges')

    def __call__(self, args):

        self._base_parser = AIDHeaderParser(args['aid_header'])
        self._oem_parser = FSConfigFileParser(args['fsconfig'],
                                              self._base_parser.oem_ranges)
                                              self._base_parser.oem_ranges,
                                              args['allow_legacy_aids'])
        base_aids = self._base_parser.aids
        oem_aids = self._oem_parser.aids

@@ -1173,11 +1185,20 @@ class OEMAidGen(BaseGenerator):
            help='An android_filesystem_config.h file'
            'to parse AIDs and OEM Ranges from')

        opt_group.add_argument(
            '--allow-legacy-aids',
            action="store_true",
            required=False,
            default=False,
            help='Allow legacy AIDs that fall outside allowed OEM ranges')

    def __call__(self, args):

        hdr_parser = AIDHeaderParser(args['aid_header'])

        parser = FSConfigFileParser(args['fsconfig'], hdr_parser.oem_ranges)
        parser = FSConfigFileParser(args['fsconfig'],
                                    hdr_parser.oem_ranges,
                                    args['allow_legacy_aids'])

        print OEMAidGen._GENERATED

@@ -1228,11 +1249,20 @@ class PasswdGen(BaseGenerator):
            help='An android_filesystem_config.h file'
            'to parse AIDs and OEM Ranges from')

        opt_group.add_argument(
            '--allow-legacy-aids',
            action="store_true",
            required=False,
            default=False,
            help='Allow legacy AIDs that fall outside allowed OEM ranges')

    def __call__(self, args):

        hdr_parser = AIDHeaderParser(args['aid_header'])

        parser = FSConfigFileParser(args['fsconfig'], hdr_parser.oem_ranges)
        parser = FSConfigFileParser(args['fsconfig'],
                                    hdr_parser.oem_ranges,
                                    args['allow_legacy_aids'])

        aids = parser.aids