diff options
author | 2024-12-02 16:54:40 +0900 | |
---|---|---|
committer | 2024-12-03 10:45:10 +0900 | |
commit | 03d62d56db2b4ad4a9e6ad3906699a11c4ecd559 (patch) | |
tree | af09a14e3cdab76ae6feeb939b05cd52cdf7f711 | |
parent | 3475af96e614f040876d763bbca37b21a7fbf504 (diff) |
apex_utils: do not use `deapexer list`
`deapexer list` doens't support erofs apex, but `deapexer extract` does.
Hence, we can use `deapexer extract` when signing the contents of an
apex.
Bug: 381185805
Test: releasetools_test
Change-Id: I226cbaaae0462598e6d9450428aa3b669284a521
-rw-r--r-- | tools/releasetools/apex_utils.py | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/tools/releasetools/apex_utils.py b/tools/releasetools/apex_utils.py index 54df955e9f..08f2b83388 100644 --- a/tools/releasetools/apex_utils.py +++ b/tools/releasetools/apex_utils.py @@ -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.""" |