support zip file raw assets

This commit is contained in:
Nathan Freitas 2012-01-25 20:07:15 -05:00
parent f1d6934ee3
commit 5dae040303
1 changed files with 27 additions and 4 deletions

View File

@ -74,6 +74,19 @@ public class TorBinaryInstaller implements TorServiceConstants {
outFile = new File(installFolder, PRIVOXYCONFIG_ASSET_KEY); outFile = new File(installFolder, PRIVOXYCONFIG_ASSET_KEY);
streamToFile(is,outFile, false, false); streamToFile(is,outFile, false, false);
return true;
}
/*
* Extract the Tor binary from the APK file using ZIP
*/
public boolean installGeoIP () throws IOException, FileNotFoundException
{
InputStream is;
File outFile;
is = context.getResources().openRawResource(R.raw.geoip); is = context.getResources().openRawResource(R.raw.geoip);
outFile = new File(installFolder, GEOIP_ASSET_KEY); outFile = new File(installFolder, GEOIP_ASSET_KEY);
streamToFile(is, outFile, false, true); streamToFile(is, outFile, false, true);
@ -200,12 +213,20 @@ public class TorBinaryInstaller implements TorServiceConstants {
* @throws IOException on error * @throws IOException on error
* @throws InterruptedException when interrupted * @throws InterruptedException when interrupted
*/ */
private static void copyRawFile(Context ctx, int resid, File file, String mode) throws IOException, InterruptedException private static void copyRawFile(Context ctx, int resid, File file, String mode, boolean isZipd) throws IOException, InterruptedException
{ {
final String abspath = file.getAbsolutePath(); final String abspath = file.getAbsolutePath();
// Write the iptables binary // Write the iptables binary
final FileOutputStream out = new FileOutputStream(file); final FileOutputStream out = new FileOutputStream(file);
final InputStream is = ctx.getResources().openRawResource(resid); InputStream is = ctx.getResources().openRawResource(resid);
if (isZipd)
{
ZipInputStream zis = new ZipInputStream(is);
ZipEntry ze = zis.getNextEntry();
is = zis;
}
byte buf[] = new byte[1024]; byte buf[] = new byte[1024];
int len; int len;
while ((len = is.read(buf)) > 0) { while ((len = is.read(buf)) > 0) {
@ -229,14 +250,16 @@ public class TorBinaryInstaller implements TorServiceConstants {
File file = new File(ctx.getDir("bin",0), "iptables"); File file = new File(ctx.getDir("bin",0), "iptables");
if ((!file.exists()) && isARMv6()) { if ((!file.exists()) && isARMv6()) {
copyRawFile(ctx, R.raw.iptables_g1, file, CHMOD_EXEC); copyRawFile(ctx, R.raw.iptables_g1, file, CHMOD_EXEC, false);
changed = true; changed = true;
} }
// Check iptables_n1 // Check iptables_n1
file = new File(ctx.getDir("bin",0), "iptables"); file = new File(ctx.getDir("bin",0), "iptables");
if ((!file.exists()) && (!isARMv6())) { if ((!file.exists()) && (!isARMv6())) {
copyRawFile(ctx, R.raw.iptables_n1, file, CHMOD_EXEC); copyRawFile(ctx, R.raw.iptables_n1, file, CHMOD_EXEC, false);
changed = true; changed = true;
} }