move jni code and VPN logic from app module to service
This commit is contained in:
parent
9f61afcdef
commit
d2cf5453e2
|
@ -63,7 +63,7 @@
|
|||
This is for ensuring the background service still runs when/if the app is swiped away
|
||||
-->
|
||||
<activity
|
||||
android:name=".service.DummyActivity"
|
||||
android:name=".service.util.DummyActivity"
|
||||
android:theme="@android:style/Theme.Translucent"
|
||||
android:enabled="true"
|
||||
android:allowTaskReparenting="true"
|
||||
|
@ -95,6 +95,16 @@
|
|||
android:stopWithTask="false" >
|
||||
</service>
|
||||
|
||||
|
||||
<service
|
||||
android:name=".service.vpn.TorVpnService"
|
||||
android:enabled="true"
|
||||
android:permission="android.permission.BIND_VPN_SERVICE" >
|
||||
<intent-filter>
|
||||
<action android:name="android.net.VpnService"/>
|
||||
</intent-filter>
|
||||
</service>
|
||||
|
||||
<receiver
|
||||
android:name=".service.StartTorReceiver"
|
||||
android:exported="true">
|
||||
|
|
|
@ -5,7 +5,7 @@ import android.content.BroadcastReceiver;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.torproject.android.service.Prefs;
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
import org.torproject.android.service.TorService;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
import org.torproject.android.vpn.VPNEnableActivity;
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
|
||||
package org.torproject.android;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.VpnService;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import org.torproject.android.service.OrbotConstants;
|
||||
import org.torproject.android.service.Prefs;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
|
||||
import org.torproject.android.settings.Languages;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Locale;
|
||||
|
||||
public class OrbotApp extends Application implements OrbotConstants
|
||||
|
@ -21,6 +22,7 @@ public class OrbotApp extends Application implements OrbotConstants
|
|||
|
||||
private Locale locale;
|
||||
|
||||
private OrbotVpnManager mVpnManager = null;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
@ -33,6 +35,21 @@ public class OrbotApp extends Application implements OrbotConstants
|
|||
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
public boolean startVPN (VpnService service, int port)
|
||||
{
|
||||
|
||||
mVpnManager = new OrbotVpnManager(service);
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("start");
|
||||
intent.putExtra("torSocks", port);
|
||||
|
||||
// mVpnManager.handleIntent(new VpnService.Builder(),intent);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
|
|
|
@ -17,10 +17,10 @@ import java.util.StringTokenizer;
|
|||
|
||||
import org.json.JSONArray;
|
||||
import org.torproject.android.service.OrbotConstants;
|
||||
import org.torproject.android.service.Prefs;
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
import org.torproject.android.service.TorService;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
import org.torproject.android.service.TorServiceUtils;
|
||||
import org.torproject.android.service.util.TorServiceUtils;
|
||||
import org.torproject.android.settings.SettingsPreferences;
|
||||
import org.torproject.android.ui.ImageProgressView;
|
||||
import org.torproject.android.ui.PromoAppsActivity;
|
||||
|
|
|
@ -19,7 +19,7 @@ import android.preference.PreferenceActivity;
|
|||
import org.torproject.android.OrbotApp;
|
||||
import org.torproject.android.R;
|
||||
import org.torproject.android.ui.AppManager;
|
||||
import org.torproject.android.service.TorServiceUtils;
|
||||
import org.torproject.android.service.util.TorServiceUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
|
|
@ -12,8 +12,8 @@ import java.util.StringTokenizer;
|
|||
|
||||
import org.torproject.android.service.OrbotConstants;
|
||||
import org.torproject.android.R;
|
||||
import org.torproject.android.service.TorServiceUtils;
|
||||
import org.torproject.android.service.TorifiedApp;
|
||||
import org.torproject.android.service.util.TorServiceUtils;
|
||||
import org.torproject.android.service.transproxy.TorifiedApp;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
|
|
|
@ -5,10 +5,9 @@ import java.io.File;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.torproject.android.R;
|
||||
import org.torproject.android.service.TorResourceInstaller;
|
||||
import org.torproject.android.service.util.TorResourceInstaller;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
|
||||
import android.app.Activity;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.torproject.android.vpn;
|
||||
|
||||
import org.torproject.android.R;
|
||||
import org.torproject.android.service.Prefs;
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
import org.torproject.android.service.TorService;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
|
||||
|
@ -12,15 +12,10 @@ import android.app.Dialog;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.VpnService;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
/*
|
||||
* To combat background service being stopped/swiped
|
||||
|
@ -161,6 +156,8 @@ public class VPNEnableActivity extends Activity {
|
|||
Intent torService = new Intent(this, TorService.class);
|
||||
torService.setAction(action);
|
||||
startService(torService);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
|
||||
|
||||
public class StartTorReceiver extends BroadcastReceiver implements TorServiceConstants {
|
||||
|
||||
|
|
|
@ -19,11 +19,8 @@ import java.util.Locale;
|
|||
import java.util.StringTokenizer;
|
||||
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.torproject.android.control.ConfigEntry;
|
||||
import org.torproject.android.control.EventHandler;
|
||||
import org.torproject.android.control.TorControlConnection;
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
|
||||
/**
|
||||
* Created by n8fr8 on 9/25/16.
|
||||
|
|
|
@ -22,8 +22,6 @@ import android.content.Intent;
|
|||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.Editor;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
@ -35,11 +33,15 @@ import android.text.TextUtils;
|
|||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.torproject.android.control.ConfigEntry;
|
||||
import org.torproject.android.control.EventHandler;
|
||||
import org.torproject.android.control.TorControlConnection;
|
||||
import org.torproject.android.service.transproxy.TorTransProxy;
|
||||
import org.torproject.android.service.transproxy.TorifiedApp;
|
||||
import org.torproject.android.service.util.DummyActivity;
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
import org.torproject.android.service.util.TorResourceInstaller;
|
||||
import org.torproject.android.service.util.TorServiceUtils;
|
||||
import org.torproject.android.service.util.Utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -50,27 +52,15 @@ import java.io.FileNotFoundException;
|
|||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PrintStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.Socket;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.text.Normalizer;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Properties;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
|
@ -121,8 +111,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
|
||||
TorEventHandler mEventHandler;
|
||||
|
||||
// private OrbotVpnManager mVpnManager;
|
||||
|
||||
public static File appBinHome;
|
||||
public static File appCacheHome;
|
||||
|
||||
|
@ -1190,25 +1178,6 @@ public class TorService extends Service implements TorServiceConstants, OrbotCon
|
|||
return mPortSOCKS;
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
public void enableVpnProxy () {
|
||||
debug ("enabling VPN Proxy");
|
||||
|
||||
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", mPortSOCKS);
|
||||
|
||||
// mVpnManager.handleIntent(new Builder(),intent);
|
||||
|
||||
}
|
||||
|
||||
@TargetApi(14)
|
||||
public void clearVpnProxy ()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package org.torproject.android.service;
|
||||
package org.torproject.android.service.transproxy;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -14,6 +14,11 @@ import android.content.pm.ApplicationInfo;
|
|||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import org.torproject.android.service.OrbotConstants;
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
import org.torproject.android.service.TorService;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
|
||||
public class TorTransProxy implements TorServiceConstants {
|
||||
|
||||
private String mSysIptables = null;
|
|
@ -1,4 +1,4 @@
|
|||
package org.torproject.android.service;
|
||||
package org.torproject.android.service.transproxy;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package org.torproject.android.service;
|
||||
package org.torproject.android.service.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
|
@ -1,11 +1,8 @@
|
|||
|
||||
package org.torproject.android.service;
|
||||
package org.torproject.android.service.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.torproject.android.service.TorServiceUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
|
||||
/* See LICENSE for licensing information */
|
||||
|
||||
package org.torproject.android.service;
|
||||
package org.torproject.android.service.util;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
@ -22,6 +22,10 @@ import android.content.Context;
|
|||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import org.torproject.android.service.OrbotConstants;
|
||||
import org.torproject.android.service.R;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
|
||||
public class TorResourceInstaller implements TorServiceConstants {
|
||||
|
||||
|
|
@ -1,23 +1,21 @@
|
|||
/* Copyright (c) 2009, Nathan Freitas, Orbot / The Guardian Project - http://openideals.com/guardian */
|
||||
/* See LICENSE for licensing information */
|
||||
package org.torproject.android.service;
|
||||
package org.torproject.android.service.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import org.torproject.android.service.OrbotConstants;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
|
||||
public class TorServiceUtils implements TorServiceConstants {
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
/* See LICENSE for licensing information */
|
||||
|
||||
|
||||
package org.torproject.android.service;
|
||||
package org.torproject.android.service.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
|
@ -14,27 +14,9 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.torproject.android.vpn;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import org.torproject.android.OrbotApp;
|
||||
import org.torproject.android.R;
|
||||
import org.torproject.android.service.TorService;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
import org.torproject.android.service.TorServiceUtils;
|
||||
import org.torproject.android.service.TorifiedApp;
|
||||
import org.torproject.android.ui.AppManager;
|
||||
package org.torproject.android.service.vpn;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Application;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
|
@ -53,6 +35,21 @@ import android.widget.Toast;
|
|||
import com.runjva.sourceforge.jsocks.protocol.ProxyServer;
|
||||
import com.runjva.sourceforge.jsocks.server.ServerAuthenticatorNone;
|
||||
|
||||
import org.torproject.android.R;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
import org.torproject.android.service.transproxy.TorifiedApp;
|
||||
import org.torproject.android.service.util.TorServiceUtils;
|
||||
import org.torproject.android.ui.AppManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.net.InetAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
public class OrbotVpnManager implements Handler.Callback {
|
||||
private static final String TAG = "OrbotVpnService";
|
|
@ -0,0 +1,62 @@
|
|||
package org.torproject.android.service.vpn;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.net.VpnService;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import org.torproject.android.service.OrbotConstants;
|
||||
import org.torproject.android.service.TorServiceConstants;
|
||||
import org.torproject.android.service.util.Prefs;
|
||||
|
||||
/**
|
||||
* Created by n8fr8 on 9/26/16.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
|
||||
public class TorVpnService extends VpnService {
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Service#onStart(android.content.Intent, int)
|
||||
*/
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
|
||||
|
||||
|
||||
if (!TextUtils.isEmpty(intent.getAction()))
|
||||
{
|
||||
if (intent.getAction().equals("start"))
|
||||
enableVpnProxy();;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package org.torproject.android.vpn;
|
||||
package org.torproject.android.service.vpn;
|
||||
|
||||
/*
|
||||
* Copyright (c) 2013, Psiphon Inc.
|
||||
|
@ -19,14 +19,14 @@ package org.torproject.android.vpn;
|
|||
*
|
||||
*/
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.util.Log;
|
||||
|
||||
import java.net.DatagramSocket;
|
||||
import java.net.Socket;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
|
||||
public class Tun2Socks
|
||||
{
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue