From d50662502f056f9ca7f8b9182d7c9d599c8d710e Mon Sep 17 00:00:00 2001 From: Victor Hsieh Date: Fri, 27 Oct 2017 10:39:02 -0700 Subject: [PATCH] Migrate to the new apksig API Following the new API contract, this effectively add extra padding before central dir to make it 4KB aligned. Test: build succeeded Bug: 30972906 Change-Id: I7cac9d2c4371b473c88df867b3b2ae906443db10 --- tools/signapk/src/com/android/signapk/SignApk.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tools/signapk/src/com/android/signapk/SignApk.java b/tools/signapk/src/com/android/signapk/SignApk.java index 3b00599e67..fdf6283a03 100644 --- a/tools/signapk/src/com/android/signapk/SignApk.java +++ b/tools/signapk/src/com/android/signapk/SignApk.java @@ -1082,14 +1082,15 @@ class SignApk { ByteBuffer[] outputChunks = new ByteBuffer[] {v1SignedApk}; ZipSections zipSections = findMainZipSections(v1SignedApk); - ApkSignerEngine.OutputApkSigningBlockRequest addV2SignatureRequest = - apkSigner.outputZipSections( + ApkSignerEngine.OutputApkSigningBlockRequest2 addV2SignatureRequest = + apkSigner.outputZipSections2( DataSources.asDataSource(zipSections.beforeCentralDir), DataSources.asDataSource(zipSections.centralDir), DataSources.asDataSource(zipSections.eocd)); if (addV2SignatureRequest != null) { // Need to insert the returned APK Signing Block before ZIP Central // Directory. + int padding = addV2SignatureRequest.getPaddingSizeBeforeApkSigningBlock(); byte[] apkSigningBlock = addV2SignatureRequest.getApkSigningBlock(); // Because the APK Signing Block is inserted before the Central Directory, // we need to adjust accordingly the offset of Central Directory inside the @@ -1100,10 +1101,12 @@ class SignApk { modifiedEocd.order(ByteOrder.LITTLE_ENDIAN); ApkUtils.setZipEocdCentralDirectoryOffset( modifiedEocd, - zipSections.beforeCentralDir.remaining() + apkSigningBlock.length); + zipSections.beforeCentralDir.remaining() + padding + + apkSigningBlock.length); outputChunks = new ByteBuffer[] { zipSections.beforeCentralDir, + ByteBuffer.allocate(padding), ByteBuffer.wrap(apkSigningBlock), zipSections.centralDir, modifiedEocd};