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

Commit f69a1856 authored by Jooyung Han's avatar Jooyung Han Committed by Gerrit Code Review
Browse files

Merge "apex_utils: do not use `deapexer list`" into main

parents fceb0a33 03d62d56
Loading
Loading
Loading
Loading
+13 −15
Original line number Diff line number Diff line
@@ -79,15 +79,10 @@ class ApexApkSigner(object):
    Returns:
      The repacked apex file containing the signed apk files.
    """
    if not os.path.exists(self.debugfs_path):
      raise ApexSigningError(
          "Couldn't find location of debugfs_static: " +
          "Path {} does not exist. ".format(self.debugfs_path) +
          "Make sure bin/debugfs_static can be found in -p <path>")
    list_cmd = ['deapexer', '--debugfs_path', self.debugfs_path,
                'list', self.apex_path]
    entries_names = common.RunAndCheckOutput(list_cmd).split()
    apk_entries = [name for name in entries_names if name.endswith('.apk')]
    payload_dir = self.ExtractApexPayload(self.apex_path)
    apk_entries = []
    for base_dir, _, files in os.walk(payload_dir):
      apk_entries.extend(os.path.join(base_dir, file) for file in files if file.endswith('.apk'))

    # No need to sign and repack, return the original apex path.
    if not apk_entries and self.sign_tool is None:
@@ -105,16 +100,16 @@ class ApexApkSigner(object):
        logger.warning('Apk path does not contain the intended directory name:'
                       ' %s', entry)

    payload_dir, has_signed_content = self.ExtractApexPayloadAndSignContents(
        apk_entries, apk_keys, payload_key, signing_args)
    has_signed_content = self.SignContentsInPayload(
        payload_dir, apk_entries, apk_keys, payload_key, signing_args)
    if not has_signed_content:
      logger.info('No contents has been signed in %s', self.apex_path)
      return self.apex_path

    return self.RepackApexPayload(payload_dir, payload_key, signing_args)

  def ExtractApexPayloadAndSignContents(self, apk_entries, apk_keys, payload_key, signing_args):
    """Extracts the payload image and signs the containing apk files."""
  def ExtractApexPayload(self, apex_path):
    """Extracts the contents of an APEX and returns the directory of the contents"""
    if not os.path.exists(self.debugfs_path):
      raise ApexSigningError(
          "Couldn't find location of debugfs_static: " +
@@ -129,9 +124,12 @@ class ApexApkSigner(object):
    extract_cmd = ['deapexer', '--debugfs_path', self.debugfs_path,
                   '--fsckerofs_path', self.fsckerofs_path,
                   'extract',
                   self.apex_path, payload_dir]
                   apex_path, payload_dir]
    common.RunAndCheckOutput(extract_cmd)
    return payload_dir

  def SignContentsInPayload(self, payload_dir, apk_entries, apk_keys, payload_key, signing_args):
    """Signs the contents in payload."""
    has_signed_content = False
    for entry in apk_entries:
      apk_path = os.path.join(payload_dir, entry)
@@ -163,7 +161,7 @@ class ApexApkSigner(object):
      common.RunAndCheckOutput(cmd)
      has_signed_content = True

    return payload_dir, has_signed_content
    return has_signed_content

  def RepackApexPayload(self, payload_dir, payload_key, signing_args=None):
    """Rebuilds the apex file with the updated payload directory."""