Bug 1163082 - Part 2: Extract Android distribution from packaged assets rather than APK root. r=rnewman
☠☠ backed out by 03297f8c28a0 ☠ ☠
authorNick Alexander <nalexander@mozilla.com>
Tue, 26 Jan 2016 10:36:09 -0800
changeset 319184 baf25be8d4917e6dcc52eede79e61e1837328c86
parent 319183 e228040a044b7ff7363a178da2cb0b8b42724048
child 319185 03297f8c28a08d2b39a252c7b368524d9e69da69
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1163082, 1163080
milestone47.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1163082 - Part 2: Extract Android distribution from packaged assets rather than APK root. r=rnewman This reads from "assets/distribution/**" in the APK and writes to "distribution/**" in the data directory. That output is the same, but the input used to read from "distribution/**", which is not really supported by modern build tooling (Gradle), which doesn't allow to write files directly into the APK root. I manually tested this without issue. I see no way to add meaningful tests to our current Robocop test suite; the long term testing approach is to develop a new test for this functionality and only run it against the "distribution" build type that was added in Bug 1163080. However, that's a larger project than I have time for now.
mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
--- a/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
+++ b/mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java
@@ -638,17 +638,17 @@ public class Distribution {
     }
 
     /**
      * @return true if we copied files out of the APK. Sets distributionDir in that case.
      */
     private boolean copyAndCheckAPKDistribution() {
         try {
             // First, try copying distribution files out of the APK.
-            if (copyFiles()) {
+            if (copyFilesFromPackagedAssets()) {
                 // We always copy to the data dir, and we only copy files from
                 // a 'distribution' subdirectory. Now determine our actual distribution directory.
                 return checkDataDistribution();
             }
         } catch (IOException e) {
             Log.e(LOGTAG, "Error copying distribution files from APK.", e);
         }
         return false;
@@ -713,42 +713,48 @@ public class Distribution {
 
             writeStream(jar, outFile, entry.getTime(), buffer);
         }
 
         return distributionSet;
     }
 
     /**
-     * Copies the /distribution folder out of the APK and into the app's data directory.
+     * Copies the /assets/distribution folder out of the APK and into the app's data directory.
      * Returns true if distribution files were found and copied.
      */
-    private boolean copyFiles() throws IOException {
+    private boolean copyFilesFromPackagedAssets() throws IOException {
         final File applicationPackage = new File(packagePath);
         final ZipFile zip = new ZipFile(applicationPackage);
 
+        final String assetsPrefix = "assets/";
+        final String fullPrefix = assetsPrefix + DISTRIBUTION_PATH;
+
         boolean distributionSet = false;
         try {
             final byte[] buffer = new byte[1024];
 
             final Enumeration<? extends ZipEntry> zipEntries = zip.entries();
             while (zipEntries.hasMoreElements()) {
                 final ZipEntry fileEntry = zipEntries.nextElement();
                 final String name = fileEntry.getName();
 
                 if (fileEntry.isDirectory()) {
                     // We'll let getDataFile deal with creating the directory hierarchy.
                     continue;
                 }
 
-                if (!name.startsWith(DISTRIBUTION_PATH)) {
+                // Read from "assets/distribution/**".
+                if (!name.startsWith(fullPrefix)) {
                     continue;
                 }
 
-                final File outFile = getDataFile(name);
+                // Write to "distribution/**".
+                final String nameWithoutPrefix = name.substring(assetsPrefix.length());
+                final File outFile = getDataFile(nameWithoutPrefix);
                 if (outFile == null) {
                     continue;
                 }
 
                 distributionSet = true;
 
                 final InputStream fileStream = zip.getInputStream(fileEntry);
                 try {