fix the modtime of files in the apk when signing
SignApk fixes the timestamp of the signature files it adds. Use that
same timestamp for all the files, so that the modtime doesn't vary
from build to build. (Incremental OTAs currently spend significant
time rewriting every .apk to do nothing but patch in timestamp
changes.)
diff --git a/tools/signapk/SignApk.java b/tools/signapk/SignApk.java
index fb55028..caf7935 100644
--- a/tools/signapk/SignApk.java
+++ b/tools/signapk/SignApk.java
@@ -304,9 +304,14 @@
pkcs7.encodeSignedData(out);
}
- /** Copy all the files in a manifest from input to output. */
+ /**
+ * Copy all the files in a manifest from input to output. We set
+ * the modification times in the output to a fixed time, so as to
+ * reduce variation in the output file and make incremental OTAs
+ * more efficient.
+ */
private static void copyFiles(Manifest manifest,
- JarFile in, JarOutputStream out) throws IOException {
+ JarFile in, JarOutputStream out, long timestamp) throws IOException {
byte[] buffer = new byte[4096];
int num;
@@ -315,15 +320,16 @@
Collections.sort(names);
for (String name : names) {
JarEntry inEntry = in.getJarEntry(name);
+ JarEntry outEntry = null;
if (inEntry.getMethod() == JarEntry.STORED) {
// Preserve the STORED method of the input entry.
- out.putNextEntry(new JarEntry(inEntry));
+ outEntry = new JarEntry(inEntry);
} else {
// Create a new entry so that the compressed len is recomputed.
- JarEntry je = new JarEntry(name);
- je.setTime(inEntry.getTime());
- out.putNextEntry(je);
+ outEntry = new JarEntry(name);
}
+ outEntry.setTime(timestamp);
+ out.putNextEntry(outEntry);
InputStream data = in.getInputStream(inEntry);
while ((num = data.read(buffer)) > 0) {
@@ -380,7 +386,7 @@
writeSignatureBlock(signature, publicKey, outputJar);
// Everything else
- copyFiles(manifest, inputJar, outputJar);
+ copyFiles(manifest, inputJar, outputJar, timestamp);
} catch (Exception e) {
e.printStackTrace();
System.exit(1);