Skip to content

Commit

Permalink
Working on Nexus 4
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Feb 5, 2016
1 parent 735d7a9 commit 5813f21
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 232 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,30 @@
package org.getlantern.lantern.activity;

import android.app.Fragment;
import android.app.FragmentManager;
import android.content.ComponentName;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.StrictMode;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.VpnService;
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.content.pm.PackageManager;
import android.content.pm.PackageInfo;
import android.app.Activity;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.Toast;
import android.widget.ToggleButton;
import android.view.MenuItem;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.support.v7.app.AppCompatActivity;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.getlantern.lantern.config.LanternConfig;
import org.getlantern.lantern.vpn.Service;
import org.getlantern.lantern.model.UI;
import org.getlantern.lantern.sdk.Utils;
import org.getlantern.lantern.vpn.LanternVpn;
import org.getlantern.lantern.R;


Expand Down Expand Up @@ -113,7 +86,6 @@ protected void onCreate(Bundle savedInstanceState) {
try {
// configure actions to be taken whenever slider changes state
LanternUI.setupLanternSwitch();
LanternVpn.LanternUI = LanternUI;
} catch (Exception e) {
Log.d(TAG, "Got an exception " + e);
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,7 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.net.ConnectivityManager;
import android.util.Log;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.InputStream;

import java.util.Map;
import java.util.HashMap;

import org.yaml.snakeyaml.Yaml;

public class Utils {
private static final String PREFS_NAME = "LanternPrefs";
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,34 +1,17 @@
package org.getlantern.lantern.vpn;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import android.content.Context;
import android.content.SharedPreferences;

import org.getlantern.lantern.config.LanternConfig;
import org.getlantern.lantern.sdk.Utils;

import java.util.Map;
import go.lantern.Lantern;

public class Service extends VpnBuilder implements Runnable {

private static final String TAG = "VpnService";
public static boolean IsRunning = false;

private String mSessionName = "LanternVpn";

private Handler mHandler;
private LanternVpn lantern;
private Thread mThread = null;

public Service() {
mHandler = new Handler();
}

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -48,17 +31,26 @@ public int onStartCommand(Intent intent, int flags, int startId) {
public synchronized void run() {
try {
Log.d(TAG, "Loading Lantern library");
final Service service = this;
lantern = new LanternVpn(this);
lantern.Start();

Thread.sleep(1000*2);
service.configure(lantern.getSettings());
Lantern.ProtectConnections(getDnsResolver(getApplicationContext()), new Lantern.SocketProtector.Stub() {
// Protect is used to exclude a socket specified by fileDescriptor
// from the VPN connection. Once protected, the underlying connection
// is bound to the VPN device and won't be forwarded
@Override
public void Protect(long fileDescriptor) throws Exception {
if (!protect((int) fileDescriptor)) {
throw new Exception("protect socket failed");
}
}
});
int startTimeoutMillis = 60000;
String analyticsTrackingID = "UA-21815217-14";
Lantern.StartResult result = org.lantern.mobilesdk.Lantern.enable(getApplicationContext(), startTimeoutMillis, analyticsTrackingID);
configure(result.getSOCKS5Addr());

while (IsRunning) {
// sleep to avoid busy looping
Thread.sleep(100);
}
}
} catch (InterruptedException e) {
Log.e(TAG, "Exception", e);
} catch (Exception e) {
Expand All @@ -74,9 +66,7 @@ private synchronized void stop() {
try {
super.close();
Log.d(TAG, "Closing VPN interface..");
lantern.Stop();
} catch (Exception e) {

}

stopSelf();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,13 @@ public void createBuilder() {
}

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public synchronized void configure(final Map settings) throws Exception {
public synchronized void configure(final String socksAddr) throws Exception {

vpnThread = new Thread() {
public void run() {
createBuilder();

String socksAddr = "127.0.0.1:9131";
String udpgwAddr = "127.0.0.1:7300";
if (settings != null &&
settings.get("socksaddr") != null &&
settings.get("udpgwaddr") != null) {
socksAddr = (String)settings.get("socksaddr");
udpgwAddr = (String)settings.get("udpgwaddr");
}

Tun2Socks.Start(
mInterface,
Expand Down Expand Up @@ -134,20 +127,6 @@ public void close() throws Exception {
vpnThread = null;
}

public void restart(final Map settings) throws Exception {
close();
Handler mHandler = new Handler();
mHandler.postDelayed(new Runnable () {
public void run () {
try {
configure(settings);
} catch (Exception e) {
Log.e(TAG, "Could not call configure again!" + e.getMessage());
}
}
}, 2000);
}

public static String getDnsResolver(Context context)
throws Exception {
Collection<InetAddress> dnsResolvers = getDnsResolvers(context);
Expand Down
1 change: 1 addition & 0 deletions src/github.com/getlantern/lantern-mobile/jni/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ./external/badvpn/Android.mk
3 changes: 3 additions & 0 deletions src/github.com/getlantern/lantern-mobile/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
APP_OPTIM := release
APP_ABI := armeabi armeabi-v7a x86
APP_PLATFORM := android-14
16 changes: 16 additions & 0 deletions src/github.com/getlantern/lantern/lantern.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/getlantern/flashlight/config"
"github.com/getlantern/flashlight/logging"
"github.com/getlantern/golog"
"github.com/getlantern/protected"
"github.com/getlantern/tlsdialer"
)

var (
Expand All @@ -20,6 +22,20 @@ var (
startOnce sync.Once
)

type SocketProtector interface {
Protect(fileDescriptor int) error
}

// ProtectConnections allows connections made by Lantern to be protected from
// routing via a VPN. This is useful when running Lantern as a VPN on Android,
// because it keeps Lantern's own connections from being captured by the VPN and
// resulting in an infinite loop.
func ProtectConnections(dnsServer string, protector SocketProtector) {
protected.Configure(protector.Protect, dnsServer)
tlsdialer.OverrideResolve(protected.Resolve)
tlsdialer.OverrideDial(protected.Dial)
}

// StartResult provides information about the started Lantern
type StartResult struct {
HTTPAddr string
Expand Down
Loading

0 comments on commit 5813f21

Please sign in to comment.