continue to migrate service and VPN code
This commit is contained in:
parent
d5f2c063b5
commit
1db567698d
|
@ -42,6 +42,8 @@ import org.torproject.android.service.util.Prefs;
|
||||||
import org.torproject.android.service.util.TorResourceInstaller;
|
import org.torproject.android.service.util.TorResourceInstaller;
|
||||||
import org.torproject.android.service.util.TorServiceUtils;
|
import org.torproject.android.service.util.TorServiceUtils;
|
||||||
import org.torproject.android.service.util.Utils;
|
import org.torproject.android.service.util.Utils;
|
||||||
|
import org.torproject.android.service.vpn.OrbotVpnManager;
|
||||||
|
import org.torproject.android.service.vpn.TorVpnService;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -314,7 +316,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
if (action.equals(ACTION_START)) {
|
if (action.equals(ACTION_START)) {
|
||||||
replyWithStatus(mIntent);
|
replyWithStatus(mIntent);
|
||||||
startTor();
|
startTor();
|
||||||
// stopTor() is called when the Service is destroyed
|
|
||||||
}
|
}
|
||||||
else if (action.equals(ACTION_STATUS)) {
|
else if (action.equals(ACTION_STATUS)) {
|
||||||
replyWithStatus(mIntent);
|
replyWithStatus(mIntent);
|
||||||
|
@ -328,7 +329,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
} else if (action.equals(CMD_UPDATE_TRANS_PROXY)) {
|
} else if (action.equals(CMD_UPDATE_TRANS_PROXY)) {
|
||||||
processTransparentProxying();
|
processTransparentProxying();
|
||||||
} else if (action.equals(CMD_VPN)) {
|
} else if (action.equals(CMD_VPN)) {
|
||||||
enableVpnProxy();
|
startVPNService();
|
||||||
} else if (action.equals(CMD_VPN_CLEAR)) {
|
} else if (action.equals(CMD_VPN_CLEAR)) {
|
||||||
clearVpnProxy();
|
clearVpnProxy();
|
||||||
} else if (action.equals(CMD_SET_EXIT)) {
|
} else if (action.equals(CMD_SET_EXIT)) {
|
||||||
|
@ -745,7 +746,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
if (Prefs.bridgesEnabled())
|
if (Prefs.bridgesEnabled())
|
||||||
if (Prefs.useVpn() && !mIsLollipop)
|
if (Prefs.useVpn() && !mIsLollipop)
|
||||||
{
|
{
|
||||||
//TODO customEnv.add("TOR_PT_PROXY=socks5://" + OrbotVpnManager.sSocksProxyLocalhost + ":" + OrbotVpnManager.sSocksProxyServerPort);
|
customEnv.add("TOR_PT_PROXY=socks5://" + OrbotVpnManager.sSocksProxyLocalhost + ":" + OrbotVpnManager.sSocksProxyServerPort);
|
||||||
}
|
}
|
||||||
|
|
||||||
// String baseDirectory = fileTor.getParent();
|
// String baseDirectory = fileTor.getParent();
|
||||||
|
@ -1179,23 +1180,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@TargetApi(14)
|
|
||||||
public void clearVpnProxy ()
|
|
||||||
{
|
|
||||||
debug ("clearing VPN Proxy");
|
|
||||||
Prefs.putUseVpn(false);
|
|
||||||
processTransparentProxying();
|
|
||||||
|
|
||||||
/**
|
|
||||||
if (mVpnManager != null)
|
|
||||||
{
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setAction("stop");
|
|
||||||
mVpnManager.handleIntent(new Builder(), intent);
|
|
||||||
mVpnManager = null;
|
|
||||||
} **/
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -1565,7 +1549,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
if (!mIsLollipop)
|
if (!mIsLollipop)
|
||||||
{
|
{
|
||||||
String proxyType = "socks5";
|
String proxyType = "socks5";
|
||||||
//TODO VPN extraLines.append(proxyType + "Proxy" + ' ' + OrbotVpnManager.sSocksProxyLocalhost + ':' + OrbotVpnManager.sSocksProxyServerPort).append('\n');
|
extraLines.append(proxyType + "Proxy" + ' ' + OrbotVpnManager.sSocksProxyLocalhost + ':' + OrbotVpnManager.sSocksProxyServerPort).append('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1978,4 +1962,26 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
||||||
return NOTIFY_ID;
|
return NOTIFY_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void startVPNService ()
|
||||||
|
{
|
||||||
|
Intent intentVpn = new Intent(this,TorVpnService.class);
|
||||||
|
intentVpn.setAction("start");
|
||||||
|
intentVpn.putExtra("torSocks",mPortSOCKS);
|
||||||
|
startService(intentVpn);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@TargetApi(14)
|
||||||
|
public void clearVpnProxy ()
|
||||||
|
{
|
||||||
|
debug ("clearing VPN Proxy");
|
||||||
|
Prefs.putUseVpn(false);
|
||||||
|
processTransparentProxying();
|
||||||
|
|
||||||
|
Intent intentVpn = new Intent(this,TorVpnService.class);
|
||||||
|
intentVpn.setAction("stop");
|
||||||
|
startService(intentVpn);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,21 @@
|
||||||
package org.torproject.android.service.transproxy;
|
package org.torproject.android.service.transproxy;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
|
import android.content.pm.PackageInfo;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
|
import org.torproject.android.service.OrbotConstants;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.StringTokenizer;
|
||||||
|
|
||||||
public class TorifiedApp implements Comparable {
|
public class TorifiedApp implements Comparable {
|
||||||
|
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
|
@ -136,4 +150,112 @@ public class TorifiedApp implements Comparable {
|
||||||
public void setPackageName(String packageName) {
|
public void setPackageName(String packageName) {
|
||||||
this.packageName = packageName;
|
this.packageName = packageName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ArrayList<TorifiedApp> getApps (Context context, SharedPreferences prefs)
|
||||||
|
{
|
||||||
|
|
||||||
|
String tordAppString = prefs.getString(OrbotConstants.PREFS_KEY_TORIFIED, "");
|
||||||
|
String[] tordApps;
|
||||||
|
|
||||||
|
StringTokenizer st = new StringTokenizer(tordAppString,"|");
|
||||||
|
tordApps = new String[st.countTokens()];
|
||||||
|
int tordIdx = 0;
|
||||||
|
while (st.hasMoreTokens())
|
||||||
|
{
|
||||||
|
tordApps[tordIdx++] = st.nextToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
Arrays.sort(tordApps);
|
||||||
|
|
||||||
|
//else load the apps up
|
||||||
|
PackageManager pMgr = context.getPackageManager();
|
||||||
|
|
||||||
|
List<ApplicationInfo> lAppInfo = pMgr.getInstalledApplications(0);
|
||||||
|
|
||||||
|
Iterator<ApplicationInfo> itAppInfo = lAppInfo.iterator();
|
||||||
|
|
||||||
|
ArrayList<TorifiedApp> apps = new ArrayList<TorifiedApp>();
|
||||||
|
|
||||||
|
ApplicationInfo aInfo = null;
|
||||||
|
|
||||||
|
int appIdx = 0;
|
||||||
|
TorifiedApp app = null;
|
||||||
|
|
||||||
|
while (itAppInfo.hasNext())
|
||||||
|
{
|
||||||
|
aInfo = itAppInfo.next();
|
||||||
|
|
||||||
|
app = new TorifiedApp();
|
||||||
|
|
||||||
|
try {
|
||||||
|
PackageInfo pInfo = pMgr.getPackageInfo(aInfo.packageName, PackageManager.GET_PERMISSIONS);
|
||||||
|
|
||||||
|
if (pInfo != null && pInfo.requestedPermissions != null)
|
||||||
|
{
|
||||||
|
for (String permInfo:pInfo.requestedPermissions)
|
||||||
|
{
|
||||||
|
if (permInfo.equals("android.permission.INTERNET"))
|
||||||
|
{
|
||||||
|
app.setUsesInternet(true);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((aInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)
|
||||||
|
{
|
||||||
|
//System app
|
||||||
|
app.setUsesInternet(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!app.usesInternet())
|
||||||
|
continue;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
apps.add(app);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
app.setEnabled(aInfo.enabled);
|
||||||
|
app.setUid(aInfo.uid);
|
||||||
|
app.setUsername(pMgr.getNameForUid(app.getUid()));
|
||||||
|
app.setProcname(aInfo.processName);
|
||||||
|
app.setPackageName(aInfo.packageName);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
app.setName(pMgr.getApplicationLabel(aInfo).toString());
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
app.setName(aInfo.packageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//app.setIcon(pMgr.getApplicationIcon(aInfo));
|
||||||
|
|
||||||
|
// check if this application is allowed
|
||||||
|
if (Arrays.binarySearch(tordApps, app.getUsername()) >= 0) {
|
||||||
|
app.setTorified(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
app.setTorified(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
appIdx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Collections.sort(apps);
|
||||||
|
|
||||||
|
return apps;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,11 +35,10 @@ import android.widget.Toast;
|
||||||
import com.runjva.sourceforge.jsocks.protocol.ProxyServer;
|
import com.runjva.sourceforge.jsocks.protocol.ProxyServer;
|
||||||
import com.runjva.sourceforge.jsocks.server.ServerAuthenticatorNone;
|
import com.runjva.sourceforge.jsocks.server.ServerAuthenticatorNone;
|
||||||
|
|
||||||
import org.torproject.android.R;
|
import org.torproject.android.service.R;
|
||||||
import org.torproject.android.service.TorServiceConstants;
|
import org.torproject.android.service.TorServiceConstants;
|
||||||
import org.torproject.android.service.transproxy.TorifiedApp;
|
import org.torproject.android.service.transproxy.TorifiedApp;
|
||||||
import org.torproject.android.service.util.TorServiceUtils;
|
import org.torproject.android.service.util.TorServiceUtils;
|
||||||
import org.torproject.android.ui.AppManager;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
@ -66,8 +65,7 @@ public class OrbotVpnManager implements Handler.Callback {
|
||||||
public static int sSocksProxyServerPort = -1;
|
public static int sSocksProxyServerPort = -1;
|
||||||
public static String sSocksProxyLocalhost = null;
|
public static String sSocksProxyLocalhost = null;
|
||||||
private ProxyServer mSocksProxyServer;
|
private ProxyServer mSocksProxyServer;
|
||||||
|
|
||||||
|
|
||||||
private final static int VPN_MTU = 1500;
|
private final static int VPN_MTU = 1500;
|
||||||
|
|
||||||
private final static boolean mIsLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
private final static boolean mIsLollipop = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||||
|
@ -359,7 +357,7 @@ public class OrbotVpnManager implements Handler.Callback {
|
||||||
private void doLollipopAppRouting (Builder builder) throws NameNotFoundException
|
private void doLollipopAppRouting (Builder builder) throws NameNotFoundException
|
||||||
{
|
{
|
||||||
|
|
||||||
ArrayList<TorifiedApp> apps = AppManager.getApps(mService, TorServiceUtils.getSharedPrefs(mService.getApplicationContext()));
|
ArrayList<TorifiedApp> apps = TorifiedApp.getApps(mService, TorServiceUtils.getSharedPrefs(mService.getApplicationContext()));
|
||||||
|
|
||||||
boolean perAppEnabled = false;
|
boolean perAppEnabled = false;
|
||||||
|
|
||||||
|
|
|
@ -19,44 +19,24 @@ import org.torproject.android.service.util.Prefs;
|
||||||
public class TorVpnService extends VpnService {
|
public class TorVpnService extends VpnService {
|
||||||
|
|
||||||
|
|
||||||
|
OrbotVpnManager mVpnManager;
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate() {
|
||||||
|
super.onCreate();
|
||||||
|
|
||||||
|
mVpnManager = new OrbotVpnManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see android.app.Service#onStart(android.content.Intent, int)
|
* @see android.app.Service#onStart(android.content.Intent, int)
|
||||||
*/
|
*/
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
|
||||||
|
mVpnManager.handleIntent(new Builder(),intent);
|
||||||
|
|
||||||
if (!TextUtils.isEmpty(intent.getAction()))
|
|
||||||
{
|
|
||||||
if (intent.getAction().equals("start"))
|
|
||||||
enableVpnProxy();;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Service.START_STICKY;
|
return Service.START_STICKY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void enableVpnProxy () {
|
|
||||||
// debug ("enabling VPN Proxy");
|
|
||||||
|
|
||||||
OrbotVpnManager vpnManager = new OrbotVpnManager(this);
|
|
||||||
|
|
||||||
int portSocks = 9050;
|
|
||||||
|
|
||||||
Prefs.putUseVpn(true);
|
|
||||||
// processTransparentProxying();
|
|
||||||
|
|
||||||
//updateConfiguration("DNSPort",TOR_VPN_DNS_LISTEN_ADDRESS + ":" + TorServiceConstants.TOR_DNS_PORT_DEFAULT,false);
|
|
||||||
|
|
||||||
// if (mVpnManager == null)
|
|
||||||
// mVpnManager = new OrbotVpnManager (this);
|
|
||||||
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setAction("start");
|
|
||||||
intent.putExtra("torSocks", portSocks);
|
|
||||||
|
|
||||||
vpnManager.handleIntent(new Builder(),intent);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue