continued re-integration of VPN feature

This commit is contained in:
Nathan Freitas 2016-10-04 23:46:17 -04:00
parent 1614921e34
commit ca238c6521
6 changed files with 31 additions and 30 deletions

View File

@ -30,7 +30,6 @@ public class OrbotApp extends Application implements OrbotConstants
Languages.setup(OrbotMainActivity.class, R.string.menu_settings); Languages.setup(OrbotMainActivity.class, R.string.menu_settings);
Languages.setLanguage(this, Prefs.getDefaultLocale(), true); Languages.setLanguage(this, Prefs.getDefaultLocale(), true);
} }
@Override @Override

View File

@ -4,13 +4,18 @@ android {
compileSdkVersion 23 compileSdkVersion 23
buildToolsVersion "23.0.3" buildToolsVersion "23.0.3"
sourceSets.main.jni.srcDirs = [] sourceSets {
main {
jni.srcDirs = []
}
}
defaultConfig { defaultConfig {
minSdkVersion 9 minSdkVersion 9
targetSdkVersion 23 targetSdkVersion 23
versionCode 1 versionCode 1
versionName "1.0" versionName "1.0"
} }
buildTypes { buildTypes {
release { release {
@ -22,7 +27,7 @@ android {
dependencies { dependencies {
compile project(':jsocksAndroid') compile project(':jsocksAndroid')
compile 'com.android.support:appcompat-v7:23.+' compile 'com.android.support:appcompat-v7:23.4.0'
compile fileTree(dir: 'libs', include: ['*.jar']) compile fileTree(dir: 'libs', include: ['*.jar','*.so'])
testCompile 'junit:junit:4.12' testCompile 'junit:junit:4.12'
} }

View File

@ -182,8 +182,9 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
if (mNotificationManager != null) if (mNotificationManager != null)
mNotificationManager.cancelAll(); mNotificationManager.cancelAll();
if (mEventHandler != null)
mEventHandler.getNodes().clear();
mEventHandler.getNodes().clear();
mNotificationShowing = false; mNotificationShowing = false;
} }
@ -243,7 +244,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
expandedView.setTextViewText(R.id.info, notifyMsg); expandedView.setTextViewText(R.id.info, notifyMsg);
} }
if (mEventHandler.getNodes().size() > 0) if (mEventHandler != null && mEventHandler.getNodes().size() > 0)
{ {
Set<String> itBuiltNodes = mEventHandler.getNodes().keySet(); Set<String> itBuiltNodes = mEventHandler.getNodes().keySet();
for (String key : itBuiltNodes) for (String key : itBuiltNodes)
@ -532,6 +533,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY); fileTorRc = new File(appBinHome, TorServiceConstants.TORRC_ASSET_KEY);
filePdnsd = new File(appBinHome, TorServiceConstants.PDNSD_ASSET_KEY); filePdnsd = new File(appBinHome, TorServiceConstants.PDNSD_ASSET_KEY);
mEventHandler = new TorEventHandler(this);
if (mNotificationManager == null) if (mNotificationManager == null)
{ {
@ -735,7 +737,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
try { try {
// make sure there are no stray daemons running // make sure there are no stray daemons running
killAllDaemons(); // killAllDaemons();
sendCallbackStatus(STATUS_STARTING); sendCallbackStatus(STATUS_STARTING);
sendCallbackLogMessage(getString(R.string.status_starting_up)); sendCallbackLogMessage(getString(R.string.status_starting_up));
@ -1146,15 +1148,15 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
return result; return result;
} }
public void addEventHandler () throws Exception public synchronized void addEventHandler () throws Exception
{ {
// We extend NullEventHandler so that we don't need to provide empty // We extend NullEventHandler so that we don't need to provide empty
// implementations for all the events we don't care about. // implementations for all the events we don't care about.
// ... // ...
logNotice( "adding control port event handler"); logNotice( "adding control port event handler");
mEventHandler = new TorEventHandler(this);
conn.setEventHandler(mEventHandler); conn.setEventHandler(mEventHandler);
conn.setEvents(Arrays.asList(new String[]{ conn.setEvents(Arrays.asList(new String[]{
"ORCONN", "CIRC", "NOTICE", "WARN", "ERR","BW"})); "ORCONN", "CIRC", "NOTICE", "WARN", "ERR","BW"}));

View File

@ -17,6 +17,7 @@
package org.torproject.android.service.vpn; package org.torproject.android.service.vpn;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.app.Application;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.app.Service; import android.app.Service;
import android.content.Context; import android.content.Context;
@ -73,20 +74,21 @@ public class OrbotVpnManager implements Handler.Callback {
//this is the actual DNS server we talk to over UDP or TCP (now using Tor's DNS port) //this is the actual DNS server we talk to over UDP or TCP (now using Tor's DNS port)
private final static String DEFAULT_ACTUAL_DNS_HOST = "127.0.0.1"; private final static String DEFAULT_ACTUAL_DNS_HOST = "127.0.0.1";
private final static int DEFAULT_ACTUAL_DNS_PORT = TorServiceConstants.TOR_DNS_PORT_DEFAULT; private final static int DEFAULT_ACTUAL_DNS_PORT = TorServiceConstants.TOR_DNS_PORT_DEFAULT;
private boolean isRestart = false;
File filePdnsd = null;
private boolean isRestart = false;
private VpnService mService; private VpnService mService;
static{
System.loadLibrary("tun2socks");
}
public OrbotVpnManager (VpnService service) public OrbotVpnManager (VpnService service)
{ {
mService = service; mService = service;
} filePdnsd = mService.getDir(TorServiceConstants.DIRECTORY_TOR_BINARY, Application.MODE_PRIVATE);
}
//public int onStartCommand(Intent intent, int flags, int startId) { //public int onStartCommand(Intent intent, int flags, int startId) {
public int handleIntent(Builder builder, Intent intent) { public int handleIntent(Builder builder, Intent intent) {
@ -394,12 +396,8 @@ public class OrbotVpnManager implements Handler.Callback {
} }
File filePdnsd = null;
private void startDNS (String dns, int port) throws IOException, TimeoutException private void startDNS (String dns, int port) throws IOException, TimeoutException
{ {
File filePdnsd = null;//getDir(TorServiceConstants.DIRECTORY_TOR_BINARY, Application.MODE_PRIVATE);
makePdnsdConf(mService, dns, port,filePdnsd.getParentFile() ); makePdnsdConf(mService, dns, port,filePdnsd.getParentFile() );
ArrayList<String> customEnv = new ArrayList<String>(); ArrayList<String> customEnv = new ArrayList<String>();

View File

@ -30,6 +30,11 @@ import java.net.Socket;
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
public class Tun2Socks public class Tun2Socks
{ {
static{
System.loadLibrary("tun2socks");
}
public static interface IProtectSocket public static interface IProtectSocket
{ {
boolean doVpnProtect(Socket socket); boolean doVpnProtect(Socket socket);
@ -51,9 +56,7 @@ public class Tun2Socks
// Note: this class isn't a singleton, but you can't run more // Note: this class isn't a singleton, but you can't run more
// than one instance due to the use of global state (the lwip // than one instance due to the use of global state (the lwip
// module, etc.) in the native code. // module, etc.) in the native code.
private static boolean mLibLoaded = false;
public static void Start( public static void Start(
ParcelFileDescriptor vpnInterfaceFileDescriptor, ParcelFileDescriptor vpnInterfaceFileDescriptor,
int vpnInterfaceMTU, int vpnInterfaceMTU,
@ -63,12 +66,6 @@ public class Tun2Socks
String udpgwServerAddress, String udpgwServerAddress,
boolean udpgwTransparentDNS) boolean udpgwTransparentDNS)
{ {
if (!mLibLoaded)
{
System.loadLibrary("tun2socks");
mLibLoaded = true;
}
mVpnInterfaceFileDescriptor = vpnInterfaceFileDescriptor; mVpnInterfaceFileDescriptor = vpnInterfaceFileDescriptor;
mVpnInterfaceMTU = vpnInterfaceMTU; mVpnInterfaceMTU = vpnInterfaceMTU;

View File

@ -1,5 +1,5 @@
#APP_ABI := armeabi x86 #APP_ABI := armeabi x86
APP_ABI := armeabi APP_ABI := armeabi
APP_PLATFORM := android-10 APP_PLATFORM := android-14
APP_STL := stlport_static APP_STL := stlport_static
NDK_TOOLCHAIN_VERSION := 4.8 NDK_TOOLCHAIN_VERSION := 4.8