Skip to content

Commit

Permalink
update service for VPN mode and startup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Aug 7, 2019
1 parent ea7f3f1 commit bbf5fcb
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 229 deletions.
4 changes: 2 additions & 2 deletions orbotservice/build.gradle
Expand Up @@ -13,8 +13,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 28
versionCode 16060001
versionName '16.0.6-BETA-1-tor-0.3.5.8-orbotservice'
versionCode 16111000
versionName '16.1.1-BETA-2-tor-0.4.0.4-rc-orbotservice'
archivesBaseName = "OrbotService-$versionName"

}
Expand Down

This file was deleted.

This file was deleted.

Expand Up @@ -312,12 +312,12 @@ protected void react() throws IOException {
handleEvent(lst);
else {
synchronized (waiters) {
if (!waiters.isEmpty())
{
Waiter w;
w = waiters.removeFirst();
w.setResponse(lst);
}
if (!waiters.isEmpty())
{
Waiter w;
w = waiters.removeFirst();
w.setResponse(lst);
}
}

}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -723,9 +723,10 @@ private File updateTorrcCustomFile () throws IOException, TimeoutException
extraLines.append("VirtualAddrNetwork 10.192.0.0/10").append('\n');
extraLines.append("AutomapHostsOnResolve 1").append('\n');

extraLines.append("DisableNetwork 0").append('\n');
extraLines.append("DormantClientTimeout 10 minutes").append('\n');
extraLines.append("DormantOnFirstStartup 1").append('\n');
extraLines.append("DormantOnFirstStartup 0").append('\n');

extraLines.append("DisableNetwork 0").append('\n');

if (Prefs.useDebugLogging())
{
Expand Down Expand Up @@ -1051,7 +1052,7 @@ private int initControlConnection (int maxTries, boolean isReconnect) throws Exc
torConnSocket.setSoTimeout(CONTROL_SOCKET_TIMEOUT);

conn = new TorControlConnection(torConnSocket);
conn.launchThread(true);//is daemon
conn.launchThread(false);//is daemon

break;
}
Expand Down Expand Up @@ -1197,7 +1198,6 @@ public synchronized void addEventHandler () throws Exception

conn.setEventHandler(mEventHandler);


conn.setEvents(Arrays.asList(new String[]{
"ORCONN", "CIRC", "NOTICE", "WARN", "ERR","BW"}));
// conn.setEvents(Arrays.asList(new String[]{
Expand Down Expand Up @@ -1509,11 +1509,13 @@ public void onReceive(Context context, Intent intent) {
}

mNetworkType = newNetType;
mConnectivity = newConnectivityState;

if (mConnectivity)
newIdentity();
if (newConnectivityState != mConnectivity) {
mConnectivity = newConnectivityState;

if (mConnectivity)
newIdentity();
}

/**
if (doNetworKSleep && mCurrentStatus != STATUS_OFF)
Expand Down
Expand Up @@ -64,6 +64,7 @@ public File installResources () throws IOException, TimeoutException
}
}

//it exists but we can't execute it, so copy it to a new path
if (fileTor.exists()) {
InputStream is = new FileInputStream(fileTor);
streamToFile(is, fileTor, false, true);
Expand All @@ -76,7 +77,8 @@ public File installResources () throws IOException, TimeoutException
//let's try another approach
fileTor = CustomNativeLoader.loadNativeBinary(context,TOR_ASSET_KEY,new File(installFolder, TOR_ASSET_KEY));

setExecutable(fileTor);
if (fileTor != null && fileTor.exists())
setExecutable(fileTor);

if (fileTor != null && fileTor.exists() && fileTor.canExecute())
return fileTor;
Expand Down
Expand Up @@ -95,9 +95,8 @@ public OrbotVpnManager (VpnService service) throws IOException, TimeoutException

filePdnsd = CustomNativeLoader.loadNativeBinary(service.getApplicationContext(),PDNSD_BIN,new File(service.getFilesDir(),PDNSD_BIN));

// if that fails, try again using native utils
try {
killProcess(filePdnsd, "-1"); // this is -HUP
killProcess(filePdnsd, "-1");
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -144,14 +143,17 @@ else if (action.equals(TorServiceConstants.LOCAL_ACTION_PORTS))
{
Log.d(TAG,"starting OrbotVPNService service!");

int newTorSocks = intent.getIntExtra(TorService.EXTRA_SOCKS_PROXY_PORT,-1);
int newTorDns = intent.getIntExtra(TorService.EXTRA_DNS_PORT,-1);
int torSocks = intent.getIntExtra(TorService.EXTRA_SOCKS_PROXY_PORT,-1);
int torDns = intent.getIntExtra(TorService.EXTRA_DNS_PORT,-1);

//if running, we need to restart
if ((torSocks != mTorSocks || torDns != mTorDns)) {

if ((mTorSocks != newTorSocks || mTorDns != newTorDns)) {
mTorSocks = newTorSocks;
mTorDns = newTorDns;
mTorSocks = torSocks;
mTorDns = torDns;

if (!mIsLollipop) {
stopSocksBypass();
startSocksBypass();
}

Expand Down Expand Up @@ -444,12 +446,14 @@ private boolean stopDns ()

try {
BufferedReader reader = new BufferedReader(new FileReader(filePid));
pid = reader.readLine().trim();

VpnUtils.killProcess(pid,"-9");
filePid.delete();
return true;
String line = reader.readLine();
if (line != null) {
pid = reader.readLine().trim();

VpnUtils.killProcess(pid, "-9");
filePid.delete();
return true;
}
} catch (Exception e) {
Log.e(TAG,"error killing DNS Process: " + pid,e);
}
Expand Down
Expand Up @@ -31,16 +31,26 @@ public void onCreate() {
e.printStackTrace();
}

LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.registerReceiver(mLocalBroadcastReceiver,
new IntentFilter(TorServiceConstants.LOCAL_ACTION_PORTS));

}

/* (non-Javadoc)
* @see android.app.Service#onStart(android.content.Intent, int)
*/
public int onStartCommand(Intent intent, int flags, int startId) {

if (intent.getAction().equals("start"))
{
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.registerReceiver(mLocalBroadcastReceiver,
new IntentFilter(TorServiceConstants.LOCAL_ACTION_PORTS));
}
else if (intent.getAction().equals("stop"))
{
LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(mLocalBroadcastReceiver);
}

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

return Service.START_STICKY;
Expand All @@ -50,8 +60,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
public void onDestroy() {
super.onDestroy();

LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
lbm.unregisterReceiver(mLocalBroadcastReceiver);

}

/**
Expand Down

0 comments on commit bbf5fcb

Please sign in to comment.