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

Side by Side Diff: src/org/adblockplus/android/configurators/IptablesProxyConfigurator.java

Issue 5169693514006528: Issue 1498 - Look for iptables on the system first (Closed)
Patch Set: Created Jan. 14, 2015, 6:26 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 | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <http://adblockplus.org/>, 2 * This file is part of Adblock Plus <http://adblockplus.org/>,
3 * Copyright (C) 2006-2014 Eyeo GmbH 3 * Copyright (C) 2006-2014 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 @Override 51 @Override
52 public boolean initialize() 52 public boolean initialize()
53 { 53 {
54 try 54 try
55 { 55 {
56 if (!RootTools.isAccessGiven()) 56 if (!RootTools.isAccessGiven())
57 { 57 {
58 throw new IllegalStateException("No root access"); 58 throw new IllegalStateException("No root access");
59 } 59 }
60 60
61 final File ipt = this.context.getFileStreamPath("iptables"); 61 final String path = getIptablesExecutablePath();
62
63 if (!ipt.exists())
64 {
65 throw new FileNotFoundException("No iptables executable");
66 }
67
68 final String path = ipt.getAbsolutePath();
69 62
70 RootTools.sendShell("chmod 700 " + path, DEFAULT_TIMEOUT); 63 RootTools.sendShell("chmod 700 " + path, DEFAULT_TIMEOUT);
71 64
72 boolean compatible = false; 65 boolean compatible = false;
73 boolean version = false; 66 boolean version = false;
74 67
75 final String command = path + " --version\n" + path + " -L -t nat -n\n"; 68 final String command = path + " --version\n" + path + " -L -t nat -n\n";
76 69
77 final List<String> result = RootTools.sendShell(command, DEFAULT_TIMEOUT); 70 final List<String> result = RootTools.sendShell(command, DEFAULT_TIMEOUT);
78 71
(...skipping 17 matching lines...) Expand all
96 this.iptables = path; 89 this.iptables = path;
97 90
98 return true; 91 return true;
99 } 92 }
100 catch (final Exception e) 93 catch (final Exception e)
101 { 94 {
102 return false; 95 return false;
103 } 96 }
104 } 97 }
105 98
99 private String getIptablesExecutablePath() throws FileNotFoundException
100 {
101 File iptablesExecutable = new File("/system/bin/iptables");
102 if (!iptablesExecutable.exists())
103 {
104 Log.i(TAG, "iptables not found on the system, using embedded binary");
105 iptablesExecutable = context.getFileStreamPath("iptables");
106 }
107 if (!iptablesExecutable.exists())
108 throw new FileNotFoundException("No iptables executable");
109 return iptablesExecutable.getAbsolutePath();
110 }
111
106 @Override 112 @Override
107 public boolean registerProxy(final InetAddress address, final int port) 113 public boolean registerProxy(final InetAddress address, final int port)
108 { 114 {
109 try 115 try
110 { 116 {
111 final int uid = this.context.getPackageManager().getPackageInfo(this.conte xt.getPackageName(), 0).applicationInfo.uid; 117 final int uid = this.context.getPackageManager().getPackageInfo(this.conte xt.getPackageName(), 0).applicationInfo.uid;
112 118
113 final StringBuilder cmd = new StringBuilder(); 119 final StringBuilder cmd = new StringBuilder();
114 cmd.append(this.iptables); 120 cmd.append(this.iptables);
115 cmd.append(IPTABLES_RETURN.replace("{{UID}}", String.valueOf(uid))); 121 cmd.append(IPTABLES_RETURN.replace("{{UID}}", String.valueOf(uid)));
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 { 231 {
226 return false; 232 return false;
227 } 233 }
228 234
229 @Override 235 @Override
230 public String toString() 236 public String toString()
231 { 237 {
232 return "[ProxyConfigurator: " + this.getType() + "]"; 238 return "[ProxyConfigurator: " + this.getType() + "]";
233 } 239 }
234 } 240 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld