Skip to content

Commit

Permalink
Move OrbotVPNService to a Manager and consolidate services
Browse files Browse the repository at this point in the history
This allows for the VPN service to be set in the foreground with the TorService
and reduce the chance to be killed due to lack of memory
  • Loading branch information
n8fr8 committed Mar 9, 2016
1 parent 2973eac commit 9097b79
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 45 deletions.
9 changes: 6 additions & 3 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
android:installLocation="auto"
>
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="23"/>
<!--
<permission android:name="org.torproject.android.MANAGE_TOR"
android:label="@string/permission_manage_tor_label"
android:description="@string/permission_manage_tor_description"
android:protectionLevel="signature"/>
<uses-permission android:name="org.torproject.android.MANAGE_TOR"/>
-->

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
Expand Down Expand Up @@ -88,7 +91,7 @@
<service
android:name=".service.TorService"
android:enabled="true"
android:permission="org.torproject.android.MANAGE_TOR"
android:permission="android.permission.BIND_VPN_SERVICE"
android:stopWithTask="false" >
</service>

Expand Down Expand Up @@ -118,13 +121,13 @@
</intent-filter>
</receiver>


<!--
<service android:name="org.torproject.android.vpn.OrbotVpnService"
android:permission="android.permission.BIND_VPN_SERVICE">
<intent-filter>
<action android:name="android.net.VpnService"/>
</intent-filter>
</service>

-->
</application>
</manifest>
2 changes: 2 additions & 0 deletions external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ ifeq ($(APP_ABI),armeabi)
CFLAGS += $(TARGET_thumb_release_CFLAGS)
endif



.PHONY = clean showsetup \
assets assets-clean \
openssl-static openssl-static-clean \
Expand Down
4 changes: 2 additions & 2 deletions res/values/pdnsd.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<string name="pdnsd_conf" formatted="false">
global {
perm_cache=1024;
perm_cache=0;
cache_dir="/data/data/org.torproject.android/app_bin";
server_port = 8091;
server_ip = 0.0.0.0;
Expand All @@ -12,7 +12,7 @@ global {
timeout=10;
daemon=on;
pid_file="/data/data/org.torproject.android/app_bin/pdnsd.pid";

}

server {
Expand Down
41 changes: 30 additions & 11 deletions src/org/torproject/android/service/TorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.content.SharedPreferences.Editor;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.VpnService;
import android.os.Build;
import android.os.IBinder;
import android.os.RemoteException;
Expand All @@ -46,7 +47,7 @@
import org.torproject.android.R;
import org.torproject.android.settings.AppManager;
import org.torproject.android.settings.TorifiedApp;
import org.torproject.android.vpn.OrbotVpnService;
import org.torproject.android.vpn.OrbotVpnManager;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -82,7 +83,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.TimeoutException;

public class TorService extends Service implements TorServiceConstants, OrbotConstants, EventHandler
public class TorService extends VpnService implements TorServiceConstants, OrbotConstants, EventHandler
{

private String mCurrentStatus = STATUS_OFF;
Expand Down Expand Up @@ -121,7 +122,7 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private long lastWritten = -1;

private NotificationManager mNotificationManager = null;
private Builder mNotifyBuilder;
private Notification.Builder mNotifyBuilder;
private Notification mNotification;
private boolean mNotificationShowing = false;

Expand All @@ -130,6 +131,8 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
private ExecutorService mExecutor = Executors.newFixedThreadPool(1);

private NumberFormat mNumberFormat = null;

private OrbotVpnManager mVpnManager;

public void debug(String msg)
{
Expand Down Expand Up @@ -364,6 +367,15 @@ public void onDestroy() {
unregisterReceiver(mNetworkStateReceiver);
super.onDestroy();
}

@Override
public void onRevoke ()
{
if (mVpnManager != null)
mVpnManager.onRevoke();

super.onRevoke();
}

private void stopTor() {
Log.i("TorService", "stopTor");
Expand Down Expand Up @@ -744,7 +756,7 @@ private void startTor() {
if (Prefs.bridgesEnabled())
if (Prefs.useVpn() && !mIsLollipop)
{
customEnv.add("TOR_PT_PROXY=socks5://" + OrbotVpnService.sSocksProxyLocalhost + ":" + OrbotVpnService.sSocksProxyServerPort);
customEnv.add("TOR_PT_PROXY=socks5://" + OrbotVpnManager.sSocksProxyLocalhost + ":" + OrbotVpnManager.sSocksProxyServerPort);
}

String baseDirectory = OrbotApp.fileTor.getParent();
Expand Down Expand Up @@ -1190,12 +1202,14 @@ public void enableVpnProxy () {

updateConfiguration("DNSPort",TOR_VPN_DNS_LISTEN_ADDRESS + ":" + TorServiceConstants.TOR_DNS_PORT_DEFAULT,false);

Intent intent = new Intent(TorService.this, OrbotVpnService.class);
intent.setAction("start");
if (mVpnManager == null)
mVpnManager = new OrbotVpnManager (this);

Intent intent = new Intent();
intent.setAction("start");
intent.putExtra("torSocks", mPortSOCKS);

startService(intent);
mVpnManager.handleIntent(new Builder(),intent);

}

Expand All @@ -1205,9 +1219,14 @@ public void clearVpnProxy ()
Prefs.putUseVpn(false);
processTransparentProxying();

Intent intent = new Intent(TorService.this, OrbotVpnService.class);
intent.setAction("stop");
startService(intent);
if (mVpnManager != null)
{
Intent intent = new Intent();
intent.setAction("stop");
mVpnManager.handleIntent(new Builder(), intent);
mVpnManager = null;
}

}

@Override
Expand Down Expand Up @@ -1851,7 +1870,7 @@ private boolean processSettingsImpl (StringBuffer extraLines) throws IOException
if (!mIsLollipop)
{
String proxyType = "socks5";
extraLines.append(proxyType + "Proxy" + ' ' + OrbotVpnService.sSocksProxyLocalhost + ':' + OrbotVpnService.sSocksProxyServerPort).append('\n');
extraLines.append(proxyType + "Proxy" + ' ' + OrbotVpnManager.sSocksProxyLocalhost + ':' + OrbotVpnManager.sSocksProxyServerPort).append('\n');
};

}
Expand Down

0 comments on commit 9097b79

Please sign in to comment.