Skip to content

Commit 50cb8a6

Browse files
committed
removed more cruft from OrbotVpnManager
1 parent 3348531 commit 50cb8a6

File tree

2 files changed

+21
-28
lines changed

2 files changed

+21
-28
lines changed

app/src/main/java/org/torproject/android/service/util/NetworkUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ object NetworkUtils {
4242
socket.connect(InetSocketAddress(ip, port), timeout)
4343
socket.close()
4444
return true
45-
} catch (ex: Exception) {
45+
} catch (_: Exception) {
4646
return false
4747
}
4848
}

app/src/main/java/org/torproject/android/service/vpn/OrbotVpnManager.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public class OrbotVpnManager implements Handler.Callback {
4949
boolean isStarted = false;
5050
private ParcelFileDescriptor mInterface;
5151
private int mTorSocks = -1;
52-
private int mTorDns = -1;
5352
private final VpnService mService;
5453
private final SharedPreferences prefs;
5554

@@ -79,17 +78,14 @@ public void handleIntent(VpnService.Builder builder, Intent intent) {
7978

8079
//reset ports
8180
mTorSocks = -1;
82-
mTorDns = -1;
8381
}
8482
case LOCAL_ACTION_PORTS -> {
8583
Log.d(TAG, "setting VPN ports");
86-
int torSocks = intent.getIntExtra(EXTRA_SOCKS_PROXY_PORT, -1);
87-
int torDns = intent.getIntExtra(EXTRA_DNS_PORT, -1);
84+
var torSocks = intent.getIntExtra(EXTRA_SOCKS_PROXY_PORT, -1);
8885

8986
//if running, we need to restart
90-
if ((torSocks != -1 && torSocks != mTorSocks && torDns != -1 && torDns != mTorDns)) {
87+
if ((torSocks != -1 && torSocks != mTorSocks)) {
9188
mTorSocks = torSocks;
92-
mTorDns = torDns;
9389
setupTun2Socks(builder);
9490
}
9591
}
@@ -102,27 +98,24 @@ public void restartVPN(VpnService.Builder builder) {
10298
}
10399

104100
private void stopVPN() {
101+
if (mInterface == null) return;
102+
try {
103+
Log.d(TAG, "closing interface, destroying VPN interface");
104+
TProxyService.TProxyStopService();
105+
if (fis != null) {
106+
fis.close();
107+
fis = null;
108+
}
105109

106-
if (mInterface != null) {
107-
try {
108-
Log.d(TAG, "closing interface, destroying VPN interface");
109-
// IPtProxy.stopSocks();
110-
TProxyService.TProxyStopService();
111-
if (fis != null) {
112-
fis.close();
113-
fis = null;
114-
}
115-
116-
if (fos != null) {
117-
fos.close();
118-
fos = null;
119-
}
120-
121-
mInterface.close();
122-
mInterface = null;
123-
} catch (Exception | Error e) {
124-
Log.d(TAG, "error stopping tun2socks", e);
110+
if (fos != null) {
111+
fos.close();
112+
fos = null;
125113
}
114+
115+
mInterface.close();
116+
mInterface = null;
117+
} catch (Exception | Error e) {
118+
Log.d(TAG, "error stopping tun2socks", e);
126119
}
127120
}
128121

@@ -134,10 +127,10 @@ public boolean handleMessage(@NonNull Message message) {
134127

135128
private synchronized void setupTun2Socks(final VpnService.Builder builder) {
136129
try {
137-
builder.setMtu(TProxyService.TUNNEL_MTU);
138130
builder.addAddress(TProxyService.VIRTUAL_GATEWAY_IPV4, 32)
131+
.setMtu(TProxyService.TUNNEL_MTU)
139132
.addRoute("0.0.0.0", 0)
140-
.addDnsServer(TProxyService.FAKE_DNS) //just setting a value here so DNS is captured by TUN interface
133+
.addDnsServer(TProxyService.FAKE_DNS)
141134
.setSession(Notifications.getVpnSessionName(mService))
142135
//handle ipv6
143136
.addAddress(TProxyService.VIRTUAL_GATEWAY_IPV6, 128)

0 commit comments

Comments
 (0)