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 |
14 | 15 |
15 from util import build_utils | 16 from util import build_utils |
16 | 17 |
17 def RenameInflateAndAddPageAlignment( | 18 def RenameInflateAndAddPageAlignment( |
18 rezip_apk_jar_path, in_zip_file, out_zip_file): | 19 rezip_apk_jar_path, in_zip_file, out_zip_file): |
19 rezip_apk_cmd = [ | 20 rezip_apk_cmd = [ |
20 'java', | 21 'java', |
21 '-classpath', | 22 '-classpath', |
22 rezip_apk_jar_path, | 23 rezip_apk_jar_path, |
23 'RezipApk', | 24 'RezipApk', |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 apk_to_sign = apk_to_sign_tmp.name | 137 apk_to_sign = apk_to_sign_tmp.name |
137 RenameInflateAndAddPageAlignment( | 138 RenameInflateAndAddPageAlignment( |
138 options.rezip_apk_jar_path, options.unsigned_apk_path, apk_to_sign) | 139 options.rezip_apk_jar_path, options.unsigned_apk_path, apk_to_sign) |
139 else: | 140 else: |
140 apk_to_sign = options.unsigned_apk_path | 141 apk_to_sign = options.unsigned_apk_path |
141 | 142 |
142 signed_apk_path = signed_apk_path_tmp.name | 143 signed_apk_path = signed_apk_path_tmp.name |
143 JarSigner(options.key_path, options.key_name, options.key_passwd, | 144 JarSigner(options.key_path, options.key_name, options.key_passwd, |
144 apk_to_sign, signed_apk_path) | 145 apk_to_sign, signed_apk_path) |
145 | 146 |
| 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 |
146 if options.load_library_from_zip: | 156 if options.load_library_from_zip: |
147 # Reorder the contents of the APK. This re-establishes the canonical | 157 # Reorder the contents of the APK. This re-establishes the canonical |
148 # order which means the library will be back at its page aligned location. | 158 # order which means the library will be back at its page aligned location. |
149 # This step also aligns uncompressed items to 4 bytes. | 159 # This step also aligns uncompressed items to 4 bytes. |
150 ReorderAndAlignApk( | 160 ReorderAndAlignApk( |
151 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) | 161 options.rezip_apk_jar_path, signed_apk_path, options.final_apk_path) |
152 else: | 162 else: |
153 # Align uncompressed items to 4 bytes | 163 # Align uncompressed items to 4 bytes |
154 AlignApk(options.zipalign_path, | 164 AlignApk(options.zipalign_path, |
155 options.page_align_shared_libraries, | 165 options.page_align_shared_libraries, |
156 signed_apk_path, | 166 signed_apk_path, |
157 options.final_apk_path) | 167 options.final_apk_path) |
158 | 168 |
159 | 169 |
160 if __name__ == '__main__': | 170 if __name__ == '__main__': |
161 sys.exit(main(sys.argv[1:])) | 171 sys.exit(main(sys.argv[1:])) |
OLD | NEW |