Merge "Migrate to the new apksig API"

am: da343de3ba

Change-Id: I4022a94ff5f7d4064e35204e42e69943cd3f2d57
This commit is contained in:
Victor Hsieh 2017-10-31 19:25:05 +00:00 committed by android-build-merger
commit 9d3b6c2ec4
1 changed files with 6 additions and 3 deletions
tools/signapk/src/com/android/signapk

View File

@ -1082,14 +1082,15 @@ class SignApk {
ByteBuffer[] outputChunks = new ByteBuffer[] {v1SignedApk}; ByteBuffer[] outputChunks = new ByteBuffer[] {v1SignedApk};
ZipSections zipSections = findMainZipSections(v1SignedApk); ZipSections zipSections = findMainZipSections(v1SignedApk);
ApkSignerEngine.OutputApkSigningBlockRequest addV2SignatureRequest = ApkSignerEngine.OutputApkSigningBlockRequest2 addV2SignatureRequest =
apkSigner.outputZipSections( apkSigner.outputZipSections2(
DataSources.asDataSource(zipSections.beforeCentralDir), DataSources.asDataSource(zipSections.beforeCentralDir),
DataSources.asDataSource(zipSections.centralDir), DataSources.asDataSource(zipSections.centralDir),
DataSources.asDataSource(zipSections.eocd)); DataSources.asDataSource(zipSections.eocd));
if (addV2SignatureRequest != null) { if (addV2SignatureRequest != null) {
// Need to insert the returned APK Signing Block before ZIP Central // Need to insert the returned APK Signing Block before ZIP Central
// Directory. // Directory.
int padding = addV2SignatureRequest.getPaddingSizeBeforeApkSigningBlock();
byte[] apkSigningBlock = addV2SignatureRequest.getApkSigningBlock(); byte[] apkSigningBlock = addV2SignatureRequest.getApkSigningBlock();
// Because the APK Signing Block is inserted before the Central Directory, // Because the APK Signing Block is inserted before the Central Directory,
// we need to adjust accordingly the offset of Central Directory inside the // we need to adjust accordingly the offset of Central Directory inside the
@ -1100,10 +1101,12 @@ class SignApk {
modifiedEocd.order(ByteOrder.LITTLE_ENDIAN); modifiedEocd.order(ByteOrder.LITTLE_ENDIAN);
ApkUtils.setZipEocdCentralDirectoryOffset( ApkUtils.setZipEocdCentralDirectoryOffset(
modifiedEocd, modifiedEocd,
zipSections.beforeCentralDir.remaining() + apkSigningBlock.length); zipSections.beforeCentralDir.remaining() + padding +
apkSigningBlock.length);
outputChunks = outputChunks =
new ByteBuffer[] { new ByteBuffer[] {
zipSections.beforeCentralDir, zipSections.beforeCentralDir,
ByteBuffer.allocate(padding),
ByteBuffer.wrap(apkSigningBlock), ByteBuffer.wrap(apkSigningBlock),
zipSections.centralDir, zipSections.centralDir,
modifiedEocd}; modifiedEocd};