| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 """Signs and zipaligns APK. | 6 """Signs and zipaligns APK. |
| 7 | 7 |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import optparse | 10 import optparse |
| 11 import shutil | 11 import shutil |
| 12 import sys | 12 import sys |
| 13 import tempfile | 13 import tempfile |
| 14 import zipfile | |
| 15 | 14 |
| 16 from util import build_utils | 15 from util import build_utils |
| 17 | 16 |
| 18 def RenameInflateAndAddPageAlignment( | 17 def RenameInflateAndAddPageAlignment( |
| 19 rezip_apk_jar_path, in_zip_file, out_zip_file): | 18 rezip_apk_jar_path, in_zip_file, out_zip_file): |
| 20 rezip_apk_cmd = [ | 19 rezip_apk_cmd = [ |
| 21 'java', | 20 'java', |
| 22 '-classpath', | 21 '-classpath', |
| 23 rezip_apk_jar_path, | 22 rezip_apk_jar_path, |
| 24 'RezipApk', | 23 'RezipApk', |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 apk_to_sign = apk_to_sign_tmp.name | 136 apk_to_sign = apk_to_sign_tmp.name |
| 138 RenameInflateAndAddPageAlignment( | 137 RenameInflateAndAddPageAlignment( |
| 139 options.rezip_apk_jar_path, options.unsigned_apk_path, apk_to_sign) | 138 options.rezip_apk_jar_path, options.unsigned_apk_path, apk_to_sign) |
| 140 else: | 139 else: |
| 141 apk_to_sign = options.unsigned_apk_path | 140 apk_to_sign = options.unsigned_apk_path |
| 142 | 141 |
| 143 signed_apk_path = signed_apk_path_tmp.name | 142 signed_apk_path = signed_apk_path_tmp.name |
| 144 JarSigner(options.key_path, options.key_name, options.key_passwd, | 143 JarSigner(options.key_path, options.key_name, options.key_passwd, |
| 145 apk_to_sign, signed_apk_path) | 144 apk_to_sign, signed_apk_path) |
| 146 | 145 |
| 147 # Make the signing files hermetic. | |
| 148 with tempfile.NamedTemporaryFile(suffix='.zip') as hermetic_signed_apk: | |
| 149 with zipfile.ZipFile(signed_apk_path, 'r') as zi: | |
| 150 with zipfile.ZipFile(hermetic_signed_apk, 'w') as zo: | |
| 151 for info in zi.infolist(): | |
| 152 info.date_time = build_utils.HERMETIC_TIMESTAMP | |
| 153 zo.writestr(info, zi.read(info.filename)) | |
| 154 shutil.copy(hermetic_signed_apk.name, signed_apk_path) | |
| 155 | |
| 156 if options.load_library_from_zip: | 146 if options.load_library_from_zip: |
| 157 # Reorder the contents of the APK. This re-establishes the canonical | 147 # Reorder the contents of the APK. This re-establishes the canonical |
| 158 # order which means the library will be back at its page aligned location. | 148 # order which means the library will be back at its page aligned location. |
| 159 # This step also aligns uncompressed items to 4 bytes. | 149 # This step also aligns uncompressed items to 4 bytes. |
| 160 ReorderAndAlignApk( | 150 ReorderAndAlignApk( |
| 161 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) | 151 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) |
| 162 else: | 152 else: |
| 163 # Align uncompressed items to 4 bytes | 153 # Align uncompressed items to 4 bytes |
| 164 AlignApk(options.zipalign_path, | 154 AlignApk(options.zipalign_path, |
| 165 options.page_align_shared_libraries, | 155 options.page_align_shared_libraries, |
| 166 signed_apk_path, | 156 signed_apk_path, |
| 167 options.final_apk_path) | 157 options.final_apk_path) |
| 168 | 158 |
| 169 | 159 |
| 170 if __name__ == '__main__': | 160 if __name__ == '__main__': |
| 171 sys.exit(main(sys.argv[1:])) | 161 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |