Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: mobile/android/base/distribution/Distribution.java

Issue 4540363985387520: Embed Adblock Plus (Closed)
Patch Set: Install as application scope extension Created Jan. 23, 2015, 11:20 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mobile/android/base/distribution/Distribution.java
===================================================================
--- a/mobile/android/base/distribution/Distribution.java
+++ b/mobile/android/base/distribution/Distribution.java
@@ -340,6 +340,19 @@
protected boolean doInit() {
ThreadUtils.assertNotOnUiThread();
+ // Firefox for Android normally ignores application scope extensions,
+ // and thus doesn't put the extensions directory in place. In Adblock
+ // Browser however, we need this mechanism.
+ //
+ // This logic doesn't really belong here. However, here the change is
+ // minimally invasive, and we're more likely to notice when the logic
+ // changes for the distributions directory.
+ try {
+ copyExtensionsFiles();
+ } catch (IOException e) {
+ Log.e(LOGTAG, "Error copying extensions files from APK.", e);
+ }
+
// Bail if we've already tried to initialize the distribution, and
// there wasn't one.
final SharedPreferences settings;
@@ -650,6 +663,48 @@
return distributionSet;
}
+ /**
+ * Copies the /extensions folder out of the APK and into the app's data directory.
+ * Adapted from copyFiles().
+ */
+ private void copyExtensionsFiles() throws IOException {
+ final File applicationPackage = new File(packagePath);
+ final ZipFile zip = new ZipFile(applicationPackage);
+
+ 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("extensions/")) {
+ continue;
+ }
+
+ final File outFile = getDataFile(name);
+ if (outFile == null) {
+ continue;
+ }
+
+ final InputStream fileStream = zip.getInputStream(fileEntry);
+ try {
+ writeStream(fileStream, outFile, fileEntry.getTime(), buffer);
+ } finally {
+ fileStream.close();
+ }
+ }
+ } finally {
+ zip.close();
+ }
+ }
+
private void writeStream(InputStream fileStream, File outFile, final long modifiedTime, byte[] buffer)
throws FileNotFoundException, IOException {
final OutputStream outStream = new FileOutputStream(outFile);
« no previous file with comments | « mobile/android/app/mobile.js ('k') | mobile/android/build.mk » ('j') | mobile/android/build.mk » ('J')

Powered by Google App Engine
This is Rietveld