Assets should be optional in apex repacking
We should only provide the --assets_dir option when the assets directory is available in the original apex. Bug: 148452817 Test: unit tests pass Change-Id: I44308b80a43ff3f441223f0ecc248991d1d83f31
This commit is contained in:
@@ -133,7 +133,6 @@ class ApexApkSigner(object):
|
|||||||
arguments_dict = {
|
arguments_dict = {
|
||||||
'manifest': os.path.join(apex_dir, 'apex_manifest.pb'),
|
'manifest': os.path.join(apex_dir, 'apex_manifest.pb'),
|
||||||
'build_info': os.path.join(apex_dir, 'apex_build_info.pb'),
|
'build_info': os.path.join(apex_dir, 'apex_build_info.pb'),
|
||||||
'assets_dir': os.path.join(apex_dir, 'assets'),
|
|
||||||
'android_jar_path': android_jar_path,
|
'android_jar_path': android_jar_path,
|
||||||
'key': payload_key,
|
'key': payload_key,
|
||||||
'pubkey': payload_public_key,
|
'pubkey': payload_public_key,
|
||||||
@@ -156,10 +155,16 @@ class ApexApkSigner(object):
|
|||||||
for key, val in arguments_dict.items():
|
for key, val in arguments_dict.items():
|
||||||
repack_cmd.append('--' + key)
|
repack_cmd.append('--' + key)
|
||||||
repack_cmd.append(val)
|
repack_cmd.append(val)
|
||||||
|
# optional arguments for apex repacking
|
||||||
manifest_json = os.path.join(apex_dir, 'apex_manifest.json')
|
manifest_json = os.path.join(apex_dir, 'apex_manifest.json')
|
||||||
if os.path.exists(manifest_json):
|
if os.path.exists(manifest_json):
|
||||||
repack_cmd.append('--manifest_json')
|
repack_cmd.append('--manifest_json')
|
||||||
repack_cmd.append(manifest_json)
|
repack_cmd.append(manifest_json)
|
||||||
|
assets_dir = os.path.join(apex_dir, 'assets')
|
||||||
|
if os.path.isdir(assets_dir):
|
||||||
|
repack_cmd.append('--assets_dir')
|
||||||
|
repack_cmd.append(assets_dir)
|
||||||
|
|
||||||
repack_cmd.append(payload_dir)
|
repack_cmd.append(payload_dir)
|
||||||
repack_cmd.append(repacked_apex)
|
repack_cmd.append(repacked_apex)
|
||||||
common.RunAndCheckOutput(repack_cmd)
|
common.RunAndCheckOutput(repack_cmd)
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import zipfile
|
||||||
|
|
||||||
import apex_utils
|
import apex_utils
|
||||||
import common
|
import common
|
||||||
@@ -155,3 +156,23 @@ class ApexUtilsTest(test_utils.ReleaseToolsTestCase):
|
|||||||
payload_pubkey = common.ExtractAvbPublicKey('avbtool',
|
payload_pubkey = common.ExtractAvbPublicKey('avbtool',
|
||||||
self.payload_key)
|
self.payload_key)
|
||||||
signer.ProcessApexFile(apk_keys, self.payload_key, payload_pubkey)
|
signer.ProcessApexFile(apk_keys, self.payload_key, payload_pubkey)
|
||||||
|
|
||||||
|
@test_utils.SkipIfExternalToolsUnavailable()
|
||||||
|
def test_ApexApkSigner_noAssetDir(self):
|
||||||
|
apex_path = os.path.join(self.testdata_dir, 'has_apk.apex')
|
||||||
|
no_asset = common.MakeTempFile(suffix='.apex')
|
||||||
|
with zipfile.ZipFile(no_asset, 'w') as output_zip:
|
||||||
|
with zipfile.ZipFile(apex_path, 'r') as input_zip:
|
||||||
|
name_list = input_zip.namelist()
|
||||||
|
for name in name_list:
|
||||||
|
if not name.startswith('assets'):
|
||||||
|
output_zip.writestr(name, input_zip.read(name))
|
||||||
|
|
||||||
|
signer = apex_utils.ApexApkSigner(no_asset, None, None)
|
||||||
|
apk_keys = {'wifi-service-resources.apk': os.path.join(
|
||||||
|
self.testdata_dir, 'testkey')}
|
||||||
|
|
||||||
|
self.payload_key = os.path.join(self.testdata_dir, 'testkey_RSA4096.key')
|
||||||
|
payload_pubkey = common.ExtractAvbPublicKey('avbtool',
|
||||||
|
self.payload_key)
|
||||||
|
signer.ProcessApexFile(apk_keys, self.payload_key, payload_pubkey)
|
||||||
|
Reference in New Issue
Block a user