Skip to content

Commit 1dc60cb

Browse files
authored
VPN flags are now opt-in for plugins (#3227)
1 parent ce2055e commit 1dc60cb

4 files changed

Lines changed: 10 additions & 9 deletions

File tree

core/src/main/java/com/github/shadowsocks/acl/AclSyncer.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import androidx.work.WorkerParameters
3535
import com.github.shadowsocks.Core
3636
import com.github.shadowsocks.Core.app
3737
import com.github.shadowsocks.core.BuildConfig
38+
import com.github.shadowsocks.preference.DataStore
3839
import com.github.shadowsocks.utils.useCancellable
3940
import kotlinx.coroutines.Dispatchers
4041
import timber.log.Timber
@@ -68,7 +69,8 @@ class AclSyncer(context: Context, workerParams: WorkerParameters) : CoroutineWor
6869

6970
override suspend fun doWork(): Result = try {
7071
val route = inputData.getString(KEY_ROUTE)!!
71-
val connection = URL("https://shadowsocks.org/acl/android/v1/$route.acl").openConnection() as HttpURLConnection
72+
val connection = URL("https://shadowsocks.org/acl/android/v1/$route.acl")
73+
.openConnection(DataStore.proxy) as HttpURLConnection
7274
val acl = connection.useCancellable { inputStream.bufferedReader().use { it.readText() } }
7375
Acl.getFile(route).printWriter().use { it.write(acl) }
7476
Result.success()

core/src/main/java/com/github/shadowsocks/bg/VpnService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ class VpnService : BaseVpnService(), BaseService.Interface {
166166

167167
if (profile.ipv6) builder.addAddress(PRIVATE_VLAN6_CLIENT, 126)
168168

169+
val me = packageName
169170
if (profile.proxyApps) {
170-
val me = packageName
171171
profile.individual.split('\n')
172172
.filter { it != me }
173173
.forEach {
@@ -178,7 +178,9 @@ class VpnService : BaseVpnService(), BaseService.Interface {
178178
Timber.w(ex)
179179
}
180180
}
181-
if (!profile.bypass) builder.addAllowedApplication(me)
181+
if (profile.bypass) builder.addDisallowedApplication(me)
182+
} else {
183+
builder.addDisallowedApplication(me)
182184
}
183185

184186
when (profile.route) {

core/src/main/java/com/github/shadowsocks/net/HttpsTest.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,13 @@ import androidx.lifecycle.ViewModel
2727
import com.github.shadowsocks.Core.app
2828
import com.github.shadowsocks.core.R
2929
import com.github.shadowsocks.preference.DataStore
30-
import com.github.shadowsocks.utils.Key
3130
import com.github.shadowsocks.utils.useCancellable
3231
import kotlinx.coroutines.Dispatchers
3332
import kotlinx.coroutines.GlobalScope
3433
import kotlinx.coroutines.Job
3534
import kotlinx.coroutines.launch
3635
import java.io.IOException
3736
import java.net.HttpURLConnection
38-
import java.net.Proxy
3937
import java.net.URL
4038
import java.net.URLConnection
4139

@@ -83,9 +81,7 @@ class HttpsTest : ViewModel() {
8381
cancelTest()
8482
status.value = Status.Testing
8583
val url = URL("https://cp.cloudflare.com")
86-
val conn = (if (DataStore.serviceMode != Key.modeVpn) {
87-
url.openConnection(Proxy(Proxy.Type.SOCKS, DataStore.proxyAddress))
88-
} else url.openConnection()) as HttpURLConnection
84+
val conn = url.openConnection(DataStore.proxy) as HttpURLConnection
8985
conn.setRequestProperty("Connection", "close")
9086
conn.instanceFollowRedirects = false
9187
conn.useCaches = false

core/src/main/java/com/github/shadowsocks/preference/DataStore.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.github.shadowsocks.utils.DirectBoot
3030
import com.github.shadowsocks.utils.Key
3131
import com.github.shadowsocks.utils.parsePort
3232
import java.net.InetSocketAddress
33+
import java.net.Proxy
3334

3435
object DataStore : OnPreferenceDataStoreChangeListener {
3536
val publicStore = RoomPreferenceDataStore(PublicDatabase.kvPairDao)
@@ -68,7 +69,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
6869
var portProxy: Int
6970
get() = getLocalPort(Key.portProxy, 1080)
7071
set(value) = publicStore.putString(Key.portProxy, value.toString())
71-
val proxyAddress get() = InetSocketAddress("127.0.0.1", portProxy)
72+
val proxy get() = Proxy(Proxy.Type.SOCKS, InetSocketAddress("127.0.0.1", portProxy))
7273
var portLocalDns: Int
7374
get() = getLocalPort(Key.portLocalDns, 5450)
7475
set(value) = publicStore.putString(Key.portLocalDns, value.toString())

0 commit comments

Comments
 (0)