Commit 4dc4b4e2 authored by Mygod's avatar Mygod

Merge branch 'master' into q-beta

parents 789d34ff b1a42caa
......@@ -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"
}
}
......
......@@ -53,8 +53,8 @@ dependencies {
api 'androidx.preference:preference:1.0.0'
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 "com.takisoft.preferencex:preferencex:$preferencexVersion"
api 'dnsjava:dnsjava:2.1.8'
api 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.1.1'
......
......@@ -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)
}
}
}
}
......@@ -204,17 +204,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,
......
......@@ -76,7 +76,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) }
......
Subproject commit ba4c45d6b4d30fd6b2557e92a770ccae12ec9257
Subproject commit e8660cfae85762d3d3eaf72c47b8478f1c9f0e22
......@@ -49,11 +49,6 @@
android:entryValues="@array/route_value"
android:summary="%s"
android:title="@string/route_list"/>
<AutoSummaryEditTextPreference
android:key="remoteDns"
android:icon="@drawable/ic_action_dns"
android:title="@string/remote_dns"
app:pref_summaryHasText="%s"/>
<SwitchPreference
android:key="isIpv6"
android:icon="@drawable/ic_image_looks_6"
......@@ -65,13 +60,17 @@
android:summary="@string/proxied_apps_summary"
android:title="@string/proxied_apps"/>
<SwitchPreference
android:key="metered"
android:icon="@drawable/ic_device_data_usage"
android:summary="@string/metered_summary"
android:title="@string/metered"/>
android:key="metered"
android:icon="@drawable/ic_device_data_usage"
android:summary="@string/metered_summary"
android:title="@string/metered"/>
<AutoSummaryEditTextPreference
android:key="remoteDns"
android:icon="@drawable/ic_action_dns"
android:title="@string/remote_dns"
app:pref_summaryHasText="%s"/>
<SwitchPreference
android:key="isUdpDns"
android:icon="@drawable/ic_action_dns"
android:summary="@string/udp_dns_summary"
android:title="@string/udp_dns"/>
......
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