commit bcae0035532ef214ef015bd4cf26ec87400a24bc Author: n8fr8 nathan@freitas.net Date: Fri Oct 12 16:14:17 2018 -0400
add permission to service manifest --- orbotservice/src/main/AndroidManifest.xml | 2 +- .../android/service/TorEventHandler.java | 7 +- .../org/torproject/android/service/TorService.java | 99 +++++++++++----------- .../android/service/util/NativeLoader.java | 14 +-- .../service/util/OtherResourceInstaller.java | 40 ++------- 5 files changed, 65 insertions(+), 97 deletions(-)
diff --git a/orbotservice/src/main/AndroidManifest.xml b/orbotservice/src/main/AndroidManifest.xml index 4b550d96..4b1691d7 100644 --- a/orbotservice/src/main/AndroidManifest.xml +++ b/orbotservice/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.torproject.android.service"> - + <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest> diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java b/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java index 8231803e..081a9974 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorEventHandler.java @@ -212,8 +212,8 @@ public class TorEventHandler implements EventHandler, TorServiceConstants { //get IP from last nodename if(status.equals("BUILT")){
- if (node.ipAddress == null) - mService.exec(new ExternalIPFetcher(node)); + // if (node.ipAddress == null) + // mService.exec(new ExternalIPFetcher(node));
hmBuiltNodes.put(circID, node); } @@ -227,6 +227,7 @@ public class TorEventHandler implements EventHandler, TorServiceConstants {
}
+ /** private class ExternalIPFetcher implements Runnable {
private Node mNode; @@ -307,7 +308,7 @@ public class TorEventHandler implements EventHandler, TorServiceConstants { }
- } + }**/
private String parseNodeName(String node) { diff --git a/orbotservice/src/main/java/org/torproject/android/service/TorService.java b/orbotservice/src/main/java/org/torproject/android/service/TorService.java index d1558565..0851d7e3 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/TorService.java +++ b/orbotservice/src/main/java/org/torproject/android/service/TorService.java @@ -561,10 +561,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon appBinHome = getDir(TorServiceConstants.DIRECTORY_TOR_BINARY, Application.MODE_PRIVATE); appCacheHome = getDir(TorServiceConstants.DIRECTORY_TOR_DATA,Application.MODE_PRIVATE);
- //mShell = Shell.startShell(); - fileTor= new File(appBinHome, TorServiceConstants.TOR_ASSET_KEY); - // filePolipo = new File(appBinHome, TorServiceConstants.POLIPO_ASSET_KEY); fileObfsclient = new File(appBinHome, TorServiceConstants.OBFSCLIENT_ASSET_KEY); fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY);
@@ -786,7 +783,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon /** * The entire process for starting tor and related services is run from this method. */ - private void startTor() { + private synchronized void startTor() {
String torProcId = null;
@@ -895,7 +892,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
- private boolean runTorShellCmd() throws Exception + private synchronized boolean runTorShellCmd() throws Exception { boolean result = true;
@@ -1563,59 +1560,59 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon else {
- loadBridgeDefaults (); + if (fileObfsclient.exists() && fileObfsclient.canExecute()) {
- extraLines.append("UseBridges 1").append('\n'); - - String bridgeList = new String(Prefs.getBridgesList().getBytes("ISO-8859-1")); - boolean obfsBridges = bridgeList.contains("obfs3")||bridgeList.contains("obfs4"); - boolean meekBridges = bridgeList.contains("meek"); + loadBridgeDefaults();
- //check if any PT bridges are needed - if (obfsBridges) - { - extraLines.append("ClientTransportPlugin obfs3 exec " + fileObfsclient.getCanonicalPath()).append('\n'); - extraLines.append("ClientTransportPlugin obfs4 exec " + fileObfsclient.getCanonicalPath()).append('\n'); - } + extraLines.append("UseBridges 1").append('\n');
- if (meekBridges) - { - extraLines.append("ClientTransportPlugin meek_lite exec " + fileObfsclient.getCanonicalPath()).append('\n'); - } + String bridgeList = new String(Prefs.getBridgesList().getBytes("ISO-8859-1")); + boolean obfsBridges = bridgeList.contains("obfs3") || bridgeList.contains("obfs4"); + boolean meekBridges = bridgeList.contains("meek");
- if (bridgeList != null && bridgeList.length() > 5) //longer then 1 = some real values here - { - String[] bridgeListLines = bridgeList.split("\r?\n"); - - for (String bridgeConfigLine : bridgeListLines) - { - if (!TextUtils.isEmpty(bridgeConfigLine)) - { - extraLines.append("Bridge "); - - StringTokenizer st = new StringTokenizer (bridgeConfigLine," "); - while (st.hasMoreTokens()) - extraLines.append(st.nextToken()).append(' '); - - extraLines.append("\n"); - - } - - } - - } - else - { + //check if any PT bridges are needed + if (obfsBridges) { + extraLines.append("ClientTransportPlugin obfs3 exec " + fileObfsclient.getCanonicalPath()).append('\n'); + extraLines.append("ClientTransportPlugin obfs4 exec " + fileObfsclient.getCanonicalPath()).append('\n'); + } + + if (meekBridges) { + extraLines.append("ClientTransportPlugin meek_lite exec " + fileObfsclient.getCanonicalPath()).append('\n'); + }
- String type = "obfs4"; + if (bridgeList != null && bridgeList.length() > 5) //longer then 1 = some real values here + { + String[] bridgeListLines = bridgeList.split("\r?\n");
- if (meekBridges) - type = "meek_lite"; + for (String bridgeConfigLine : bridgeListLines) { + if (!TextUtils.isEmpty(bridgeConfigLine)) { + extraLines.append("Bridge ");
- getBridges(type,extraLines); + StringTokenizer st = new StringTokenizer(bridgeConfigLine, " "); + while (st.hasMoreTokens()) + extraLines.append(st.nextToken()).append(' ');
+ extraLines.append("\n"); + + } + + } + + } else { + + String type = "obfs4"; + + if (meekBridges) + type = "meek_lite"; + + getBridges(type, extraLines); + + } + } + else + { + throw new IOException("Bridge binary does not exist: " + fileObfsclient.getCanonicalPath()); } - }
@@ -1844,14 +1841,14 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
@Override public IBinder onBind(Intent intent) { - Log.e( "CustomNotificationService", "onBind" ); + Log.e( TAG, "onBind" ); handleIntent( intent ); return null; }
private void handleIntent( Intent intent ) { if( intent != null && intent.getAction() != null ) { - Log.e( "CustomNotificationService", intent.getAction().toString() ); + Log.e( TAG, intent.getAction().toString() ); } }
diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/NativeLoader.java b/orbotservice/src/main/java/org/torproject/android/service/util/NativeLoader.java index 3e910cce..4ad10bb1 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/util/NativeLoader.java +++ b/orbotservice/src/main/java/org/torproject/android/service/util/NativeLoader.java @@ -39,12 +39,9 @@ public class NativeLoader { } out.close();
- if (Build.VERSION.SDK_INT >= 9) { - destLocalFile.setReadable(true, false); - destLocalFile.setExecutable(true, false); - destLocalFile.setWritable(true); - } - + destLocalFile.setReadable(true, false); + destLocalFile.setExecutable(true, false); + destLocalFile.setWritable(true);
return true; } catch (Exception e) { @@ -85,7 +82,6 @@ public class NativeLoader { folder = "mips"; } else { folder = "armeabi"; - //FileLog.e("tmessages", "Unsupported arch: " + Build.CPU_ABI); } } catch (Exception e) { // FileLog.e("tmessages", e); @@ -99,9 +95,7 @@ public class NativeLoader { folder = "x86"; }
- if (loadFromZip(context, binaryName, destLocalFile, folder)) { - return true; - } + return loadFromZip(context, binaryName, destLocalFile, folder);
} catch (Throwable e) { e.printStackTrace(); diff --git a/orbotservice/src/main/java/org/torproject/android/service/util/OtherResourceInstaller.java b/orbotservice/src/main/java/org/torproject/android/service/util/OtherResourceInstaller.java index c02c5c54..7903fb41 100644 --- a/orbotservice/src/main/java/org/torproject/android/service/util/OtherResourceInstaller.java +++ b/orbotservice/src/main/java/org/torproject/android/service/util/OtherResourceInstaller.java @@ -62,7 +62,7 @@ public class OtherResourceInstaller implements TorServiceConstants { /* * Extract the Tor resources from the APK file using ZIP */ - public boolean installResources () throws IOException, FileNotFoundException, TimeoutException + public boolean installResources () throws IOException {
File outFile; @@ -70,45 +70,21 @@ public class OtherResourceInstaller implements TorServiceConstants { if (!installFolder.exists()) installFolder.mkdirs();
- File libBinary = new File(getNativeLibraryDir(context),OBFSCLIENT_ASSET_KEY + ".so"); +// File libBinary = new File(getNativeLibraryDir(context),OBFSCLIENT_ASSET_KEY + ".so"); outFile = new File(installFolder, OBFSCLIENT_ASSET_KEY); - if (libBinary.exists()) { - if ((!outFile.exists()) || (libBinary.lastModified() > outFile.lastModified())) { - streamToFile(new FileInputStream(libBinary), outFile, false, true); - } - - setExecutable(outFile); - } - else - { - NativeLoader.initNativeLibs(context,OBFSCLIENT_ASSET_KEY,outFile); - } - - if (!outFile.exists()) - return false; + NativeLoader.initNativeLibs(context,OBFSCLIENT_ASSET_KEY,outFile); + // setExecutable(outFile);
- libBinary = new File(getNativeLibraryDir(context),PDNSD_ASSET_KEY + ".so"); + // libBinary = new File(getNativeLibraryDir(context),PDNSD_ASSET_KEY + ".so"); outFile = new File(installFolder, PDNSD_ASSET_KEY); - if (libBinary.exists()) { - if ((!outFile.exists()) || (libBinary.lastModified() > outFile.lastModified())) { - streamToFile(new FileInputStream(libBinary), outFile, false, true); - } - - setExecutable(outFile); - } - else - { - NativeLoader.initNativeLibs(context,PDNSD_ASSET_KEY,outFile); - } - - if (!outFile.exists()) - return false; + NativeLoader.initNativeLibs(context,PDNSD_ASSET_KEY,outFile); + // setExecutable(outFile);
return true; }
// Return Full path to the directory where native JNI libraries are stored. - private static String getNativeLibraryDir(Context context) { + public static String getNativeLibraryDir(Context context) { ApplicationInfo appInfo = context.getApplicationInfo(); return appInfo.nativeLibraryDir; }
tor-commits@lists.torproject.org