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.
This commit is contained in:
Nick Alexander 2016-01-26 10:36:09 -08:00
parent 61ddcc0a51
commit d8104a59cd
2 changed files with 11 additions and 5 deletions

View File

@ -643,7 +643,7 @@ public class Distribution {
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();
@ -718,13 +718,16 @@ public class Distribution {
}
/**
* 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];
@ -739,11 +742,14 @@ public class Distribution {
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;
}