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

Side by Side Diff: mobile/android/base/java/org/mozilla/gecko/distribution/Distribution.java

Issue 29491669: Issue 5426 - ABP isn't packaged in the apk (Closed)
Patch Set: Created July 18, 2017, 10:11 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mobile/android/installer/package-manifest.in » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- 1 /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
2 * This Source Code Form is subject to the terms of the Mozilla Public 2 * This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
4 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 5
6 package org.mozilla.gecko.distribution; 6 package org.mozilla.gecko.distribution;
7 7
8 import java.io.BufferedInputStream; 8 import java.io.BufferedInputStream;
9 import java.io.File; 9 import java.io.File;
10 import java.io.FileNotFoundException; 10 import java.io.FileNotFoundException;
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 ThreadUtils.assertNotOnUiThread(); 442 ThreadUtils.assertNotOnUiThread();
443 443
444 // Firefox for Android normally ignores application scope extensions, 444 // Firefox for Android normally ignores application scope extensions,
445 // and thus doesn't put the extensions directory in place. In Adblock 445 // and thus doesn't put the extensions directory in place. In Adblock
446 // Browser however, we need this mechanism. 446 // Browser however, we need this mechanism.
447 // 447 //
448 // This logic doesn't really belong here. However, here the change is 448 // This logic doesn't really belong here. However, here the change is
449 // minimally invasive, and we're more likely to notice when the logic 449 // minimally invasive, and we're more likely to notice when the logic
450 // changes for the distributions directory. 450 // changes for the distributions directory.
451 try { 451 try {
452 copyExtensionsFiles(); 452 copyExtensionsFromPackagedAssets();
453 } catch (IOException e) { 453 } catch (IOException e) {
454 Log.e(LOGTAG, "Error copying extensions files from APK.", e); 454 Log.e(LOGTAG, "Error copying extensions files from APK.", e);
455 } 455 }
456 456
457 // Bail if we've already tried to initialize the distribution, and 457 // Bail if we've already tried to initialize the distribution, and
458 // there wasn't one. 458 // there wasn't one.
459 final SharedPreferences settings = getSharedPreferences(); 459 final SharedPreferences settings = getSharedPreferences();
460 460
461 final String keyName = getKeyName(); 461 final String keyName = getKeyName();
462 this.state = settings.getInt(keyName, STATE_UNKNOWN); 462 this.state = settings.getInt(keyName, STATE_UNKNOWN);
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 } 764 }
765 } 765 }
766 } finally { 766 } finally {
767 zip.close(); 767 zip.close();
768 } 768 }
769 769
770 return distributionSet; 770 return distributionSet;
771 } 771 }
772 772
773 /** 773 /**
774 * Copies the /extensions folder out of the APK and into the app's data dire ctory. 774 * Copies the /assets/extensions folder out of the APK and into the app's da ta directory.
775 * Adapted from copyFiles(). 775 * Adapted from copyFilesFromPackagedAssets().
776 */ 776 */
777 private void copyExtensionsFiles() throws IOException { 777 private void copyExtensionsFromPackagedAssets() throws IOException {
778 final File applicationPackage = new File(packagePath); 778 final File applicationPackage = new File(packagePath);
779 final ZipFile zip = new ZipFile(applicationPackage); 779 final ZipFile zip = new ZipFile(applicationPackage);
780 780
781 final String assetsPrefix = "assets/";
782 final String fullPrefix = assetsPrefix + "extensions/";
783
781 try { 784 try {
782 final byte[] buffer = new byte[1024]; 785 final byte[] buffer = new byte[1024];
783 786
784 final Enumeration<? extends ZipEntry> zipEntries = zip.entries(); 787 final Enumeration<? extends ZipEntry> zipEntries = zip.entries();
785 while (zipEntries.hasMoreElements()) { 788 while (zipEntries.hasMoreElements()) {
786 final ZipEntry fileEntry = zipEntries.nextElement(); 789 final ZipEntry fileEntry = zipEntries.nextElement();
787 final String name = fileEntry.getName(); 790 final String name = fileEntry.getName();
788 791
789 if (fileEntry.isDirectory()) { 792 if (fileEntry.isDirectory()) {
790 // We'll let getDataFile deal with creating the directory hi erarchy. 793 // We'll let getDataFile deal with creating the directory hi erarchy.
791 continue; 794 continue;
792 } 795 }
793 796
794 if (!name.startsWith("extensions/")) { 797 // Read from "assets/extensions/**".
798 if (!name.startsWith(fullPrefix)) {
795 continue; 799 continue;
796 } 800 }
797 801
798 final File outFile = getDataFile(name); 802 // Write to "extensions/**".
803 final String nameWithoutPrefix = name.substring(assetsPrefix.len gth());
804 final File outFile = getDataFile(nameWithoutPrefix);
799 if (outFile == null) { 805 if (outFile == null) {
800 continue; 806 continue;
801 } 807 }
802 808
803 final InputStream fileStream = zip.getInputStream(fileEntry); 809 final InputStream fileStream = zip.getInputStream(fileEntry);
804 try { 810 try {
805 writeStream(fileStream, outFile, fileEntry.getTime(), buffer ); 811 writeStream(fileStream, outFile, fileEntry.getTime(), buffer );
806 } finally { 812 } finally {
807 fileStream.close(); 813 fileStream.close();
808 } 814 }
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 private SharedPreferences getSharedPreferences() { 1002 private SharedPreferences getSharedPreferences() {
997 final SharedPreferences settings; 1003 final SharedPreferences settings;
998 if (prefsBranch == null) { 1004 if (prefsBranch == null) {
999 settings = GeckoSharedPrefs.forApp(context); 1005 settings = GeckoSharedPrefs.forApp(context);
1000 } else { 1006 } else {
1001 settings = context.getSharedPreferences(prefsBranch, Activity.MODE_P RIVATE); 1007 settings = context.getSharedPreferences(prefsBranch, Activity.MODE_P RIVATE);
1002 } 1008 }
1003 return settings; 1009 return settings;
1004 } 1010 }
1005 } 1011 }
OLDNEW
« no previous file with comments | « no previous file | mobile/android/installer/package-manifest.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld