Commit 576ab96c authored by Mygod's avatar Mygod

Merge branch 'master' into preference-1.1

parents 76dee1cf 1fb8589f
......@@ -29,4 +29,4 @@
branch = stable
[submodule "core/src/main/jni/libev"]
path = core/src/main/jni/libev
url = https://github.com/shadowsocks/libev.git
url = https://git.lighttpd.net/libev.git
......@@ -30,7 +30,7 @@ buildscript {
classpath 'com.github.ben-manes:gradle-versions-plugin:0.21.0'
classpath 'com.google.gms:google-services:4.2.0'
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.8.0'
classpath 'io.fabric.tools:gradle:1.27.1'
classpath 'io.fabric.tools:gradle:1.28.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
}
}
......
......@@ -54,8 +54,8 @@ dependencies {
api 'androidx.preference:preference:1.1.0-alpha04'
api "androidx.room:room-runtime:$roomVersion"
api 'com.crashlytics.sdk.android:crashlytics:2.9.9'
api 'com.google.firebase:firebase-config:16.1.3'
api 'com.google.firebase:firebase-core:16.0.7'
api 'com.google.firebase:firebase-config:16.4.1'
api 'com.google.firebase:firebase-core:16.0.8'
api 'dnsjava:dnsjava:2.1.8'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
api 'org.connectbot.jsocks:jsocks:1.0.0'
......
......@@ -90,10 +90,6 @@ object BaseService {
binder.stateChanged(s, msg)
state = s
}
init {
RemoteConfig.fetch()
}
}
class Binder(private var data: Data? = null) : IShadowsocksService.Stub(), AutoCloseable {
......@@ -341,7 +337,6 @@ object BaseService {
proxy.scheduleUpdate()
data.udpFallback?.scheduleUpdate()
RemoteConfig.fetch()
data.changeState(State.Connected)
} catch (_: CancellationException) {
......
......@@ -40,6 +40,7 @@ import kotlinx.coroutines.*
import java.io.File
import java.io.IOException
import java.net.HttpURLConnection
import java.net.URL
import java.net.UnknownHostException
import java.security.MessageDigest
......@@ -51,12 +52,16 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
var trafficMonitor: TrafficMonitor? = null
private val plugin = PluginConfiguration(profile.plugin ?: "").selectedOptions
val pluginPath by lazy { PluginManager.init(plugin) }
private var scheduleConfigUpdate = false
suspend fun init(service: BaseService.Interface) {
if (profile.host == "198.199.101.152") {
scheduleConfigUpdate = true
val mdg = MessageDigest.getInstance("SHA-1")
mdg.update(Core.packageInfo.signaturesCompat.first().toByteArray())
val conn = service.openConnection(RemoteConfig.proxyUrl) as HttpURLConnection
val (config, success) = RemoteConfig.fetch()
scheduleConfigUpdate = !success
val conn = service.openConnection(URL(config.getString("proxy_url"))) as HttpURLConnection
conn.requestMethod = "POST"
conn.doOutput = true
......@@ -134,6 +139,7 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
fun scheduleUpdate() {
if (route !in arrayOf(Acl.ALL, Acl.CUSTOM_RULES)) AclSyncer.schedule(route)
if (scheduleConfigUpdate) RemoteConfig.scheduleFetch()
}
fun shutdown(scope: CoroutineScope) {
......
......@@ -25,18 +25,30 @@ import androidx.core.os.bundleOf
import com.github.shadowsocks.Core
import com.github.shadowsocks.core.R
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import java.net.URL
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume
object RemoteConfig {
private val config = FirebaseRemoteConfig.getInstance().apply { setDefaults(R.xml.default_configs) }
private val config by lazy { FirebaseRemoteConfig.getInstance().apply { setDefaults(R.xml.default_configs) } }
val proxyUrl get() = URL(config.getString("proxy_url"))
private fun Exception.log() {
Log.w("RemoteConfig", this)
Core.analytics.logEvent("femote_config_failure", bundleOf(Pair(javaClass.simpleName, message)))
}
fun scheduleFetch() = config.fetch().addOnCompleteListener {
if (it.isSuccessful) config.activateFetched() else it.exception?.log()
}
fun fetch() = config.fetch().addOnCompleteListener {
if (it.isSuccessful) config.activateFetched() else {
val e = it.exception ?: return@addOnCompleteListener
Log.w("RemoteConfig", e)
Core.analytics.logEvent("femote_config_failure", bundleOf(Pair(e.javaClass.simpleName, e.message)))
suspend fun fetch() = suspendCancellableCoroutine<Pair<FirebaseRemoteConfig, Boolean>> { cont ->
config.fetch().addOnCompleteListener {
if (it.isSuccessful) {
config.activateFetched()
cont.resume(config to true)
} else {
it.exception?.log()
cont.resume(config to false)
}
}
}
}
......@@ -199,17 +199,14 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
val conn = builder.establish() ?: throw NullConnectionException()
this.conn = conn
val fd = conn.fd
val cmd = arrayListOf(File(applicationInfo.nativeLibraryDir, Executable.TUN2SOCKS).absolutePath,
"--netif-ipaddr", PRIVATE_VLAN4_ROUTER,
"--netif-netmask", "255.255.255.0",
"--socks-server-addr", "${DataStore.listenAddress}:${DataStore.portProxy}",
"--tunfd", fd.toString(),
"--tunmtu", VPN_MTU.toString(),
"--sock-path", "sock_path",
"--dnsgw", "127.0.0.1:${DataStore.portLocalDns}",
"--loglevel", "3")
"--loglevel", "warning")
if (profile.ipv6) {
cmd += "--netif-ip6addr"
cmd += PRIVATE_VLAN6_ROUTER
......
......@@ -54,7 +54,7 @@ data class Profile(
var password: String = "u1rRWTssNv0p",
var method: String = "aes-256-cfb",
var route: String = "all",
var remoteDns: String = "8.8.8.8",
var remoteDns: String = "dns.google",
var proxyApps: Boolean = false,
var bypass: Boolean = false,
var udpdns: Boolean = false,
......
......@@ -89,7 +89,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
private val job = SupervisorJob()
override val coroutineContext = job + CoroutineExceptionHandler { _, t -> printLog(t) }
suspend fun start(listen: SocketAddress) = DatagramChannel.open().apply {
suspend fun start(listen: SocketAddress) = DatagramChannel.open().run {
configureBlocking(false)
socket().bind(listen)
monitor.register(this, SelectionKey.OP_READ) { handlePacket(this) }
......
......@@ -114,7 +114,7 @@ include $(CLEAR_VARS)
LIBEVENT_SOURCES := \
buffer.c bufferevent.c event.c \
bufferevent_sock.c bufferevent_ratelim.c \
evthread.c log.c evutil.c evutil_time.c evmap.c epoll.c poll.c signal.c select.c
evthread.c log.c evutil.c evutil_rand.c evutil_time.c evmap.c epoll.c poll.c signal.c select.c
LOCAL_MODULE := event
LOCAL_SRC_FILES := $(addprefix libevent/, $(LIBEVENT_SOURCES))
......
Subproject commit ba4c45d6b4d30fd6b2557e92a770ccae12ec9257
Subproject commit e8660cfae85762d3d3eaf72c47b8478f1c9f0e22
libev @ 31ca40b7
Subproject commit 5213419011ec5de302f8bc1716f348de1fb53b12
Subproject commit 31ca40b7a18ed424213a4ecba0d57706ed3e56a0
Subproject commit fec4c92d81189e0394ad94e14f238a837c81385e
Subproject commit b732443c442239c2e0184820e9b23cca0de0828c
Subproject commit 4f0929189ab43e020b0d441919abf6bab02baf11
Subproject commit 9f4f8eec93dd1f32d78e0bcceddbef0ca570e66f
Subproject commit 274334f14839431ae003774d99c3d1de337afff4
Subproject commit d9954892ba96627748efab2901f38d7e20d6d0a2
Subproject commit b430124ed82973d4edf345dfadbe556f93377484
Subproject commit b0c6ba494509473e269f7ae5b5e769e09bb9b6ee
......@@ -33,6 +33,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.github.shadowsocks.database.Profile
import com.github.shadowsocks.database.ProfileManager
import com.github.shadowsocks.plugin.PluginConfiguration
import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.resolveResourceId
......@@ -61,7 +62,7 @@ class UdpFallbackProfileActivity : AppCompatActivity() {
inner class ProfilesAdapter : RecyclerView.Adapter<ProfileViewHolder>() {
internal val profiles = (ProfileManager.getAllProfiles()?.toMutableList() ?: mutableListOf())
.filter { it.id != editingId && it.plugin.isNullOrEmpty() }
.filter { it.id != editingId && PluginConfiguration(it.plugin ?: "").selected.isEmpty() }
override fun onBindViewHolder(holder: ProfileViewHolder, position: Int) =
holder.bind(if (position == 0) null else profiles[position - 1])
......
......@@ -42,11 +42,6 @@
app:entryValues="@array/route_value"
app:title="@string/route_list"
app:useSimpleSummaryProvider="true"/>
<EditTextPreference
app:key="remoteDns"
app:icon="@drawable/ic_action_dns"
app:title="@string/remote_dns"
app:useSimpleSummaryProvider="true"/>
<SwitchPreference
app:key="isIpv6"
app:icon="@drawable/ic_image_looks_6"
......@@ -57,16 +52,21 @@
app:icon="@drawable/ic_navigation_apps"
app:summary="@string/proxied_apps_summary"
app:title="@string/proxied_apps"/>
<SwitchPreference
app:key="isUdpDns"
app:icon="@drawable/ic_action_dns"
app:summary="@string/udp_dns_summary"
app:title="@string/udp_dns"/>
<SwitchPreference
app:key="metered"
app:icon="@drawable/ic_device_data_usage"
app:summary="@string/metered_summary"
app:title="@string/metered"/>
<EditTextPreference
app:key="remoteDns"
app:icon="@drawable/ic_action_dns"
app:title="@string/remote_dns"
app:useSimpleSummaryProvider="true"/>
<SwitchPreference
app:key="isUdpDns"
app:icon="@drawable/ic_action_dns"
app:summary="@string/udp_dns_summary"
app:title="@string/udp_dns"/>
</PreferenceCategory>
......
......@@ -50,7 +50,7 @@ mavenPublish {
dependencies {
api 'androidx.core:core-ktx:1.0.1'
api 'com.google.android.material:material:1.1.0-alpha04'
api 'com.google.android.material:material:1.1.0-alpha05'
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
testImplementation "junit:junit:$junitVersion"
androidTestImplementation "androidx.test:runner:$androidTestVersion"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment