Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bannedbook committed Sep 9, 2021
1 parent 957ab2c commit 660b8fd
Show file tree
Hide file tree
Showing 34 changed files with 127 additions and 1,073 deletions.
16 changes: 7 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.5.10'
ext {
javaVersion = JavaVersion.VERSION_1_8
kotlinVersion = '1.3.70'

ndkVersion = '21.0.6113669'
minSdkVersion = 21
sdkVersion = 29
compileSdkVersion = 29
buildToolsVersion = '29.0.3'
desugarLibsVersion = '1.0.5'
versionCode = 446
versionName = '5.0.6.13R'
versionCode = 458
versionName = '5.1.1'
resConfigs = ['ar', 'es', 'fa', 'fr', 'ja', 'ko', 'ru', 'tr', 'zh-rCN', 'zh-rTW']
}

repositories {
google()
maven {
url 'https://maven.fabric.io/public'
}
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.google.gms:google-services:4.3.3'
classpath 'io.fabric.tools:gradle:1.31.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.7.1'
classpath 'com.google.gms:google-services:4.3.10'
}
}

Expand Down
7 changes: 5 additions & 2 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,12 @@ dependencies {
api 'androidx.preference:preference:1.1.0'
api "androidx.room:room-runtime:$roomVersion"
api "androidx.work:work-runtime-ktx:$workVersion"
api 'com.crashlytics.sdk.android:crashlytics:2.10.1'
api 'com.google.firebase:firebase-analytics-ktx:19.0.1'
api 'com.google.firebase:firebase-config-ktx:21.0.1'
api 'com.google.firebase:firebase-crashlytics:18.2.1'
api 'com.google.firebase:firebase-analytics:19.0.1'
api 'com.google.code.gson:gson:2.8.6'
api 'com.google.firebase:firebase-analytics:17.4.3'
api 'com.google.firebase:firebase-config:21.0.1'
api 'dnsjava:dnsjava:2.1.9'
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
api 'org.connectbot.jsocks:jsocks:1.0.0'
Expand Down
15 changes: 6 additions & 9 deletions core/src/main/java/com/github/shadowsocks/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
import androidx.work.Configuration
import androidx.work.WorkManager
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.aidl.ShadowsocksConnection
import com.github.shadowsocks.bg.ProxyService
import com.github.shadowsocks.core.R
Expand All @@ -53,9 +52,9 @@ import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.subscription.SubscriptionService
import com.github.shadowsocks.utils.*
import com.github.shadowsocks.work.UpdateCheck
import com.google.firebase.FirebaseApp
import com.google.firebase.analytics.FirebaseAnalytics
import io.fabric.sdk.android.Fabric
import com.google.firebase.crashlytics.FirebaseCrashlytics
import com.google.firebase.ktx.Firebase
import com.google.firebase.ktx.initialize
import kotlinx.coroutines.DEBUG_PROPERTY_NAME
import kotlinx.coroutines.DEBUG_PROPERTY_VALUE_ON
import kotlinx.coroutines.GlobalScope
Expand All @@ -76,7 +75,6 @@ object Core {
val notification by lazy { app.getSystemService<NotificationManager>()!! }
val packageInfo: PackageInfo by lazy { getPackageInfo(app.packageName) }
val deviceStorage by lazy { if (Build.VERSION.SDK_INT < 24) app else DeviceStorageApp(app) }
val analytics: FirebaseAnalytics by lazy { FirebaseAnalytics.getInstance(deviceStorage) }
val directBootSupported by lazy {
Build.VERSION.SDK_INT >= 24 && app.getSystemService<DevicePolicyManager>()?.storageEncryptionStatus ==
DevicePolicyManager.ENCRYPTION_STATUS_ACTIVE_PER_USER
Expand Down Expand Up @@ -108,7 +106,7 @@ object Core {
GlobalScope.launch {
val userCountry = Locale.getDefault().country
Log.e("userCountry", userCountry)
if ("CN" != userCountry) {
//if ("CN" != userCountry){
var builtinSubUrls = app.resources.getStringArray(R.array.builtinSubUrls)
var builtinSub: SSRSub? = null
for (i in builtinSubUrls.indices) {
Expand All @@ -119,7 +117,7 @@ object Core {
break
}
}
}
//}
if (DataStore.is_get_free_servers) importFreeSubs() //update free_servers
try {app.startService(Intent(app, SubscriptionService::class.java))}catch (e:Exception){}
}
Expand Down Expand Up @@ -156,8 +154,7 @@ object Core {

// overhead of debug mode is minimal: https://github.com/Kotlin/kotlinx.coroutines/blob/f528898/docs/debugging.md#debug-mode
System.setProperty(DEBUG_PROPERTY_NAME, DEBUG_PROPERTY_VALUE_ON)
Fabric.with(deviceStorage, Crashlytics()) // multiple processes needs manual set-up
FirebaseApp.initializeApp(deviceStorage)
Firebase.initialize(deviceStorage) // multiple processes needs manual set-up
WorkManager.initialize(deviceStorage, Configuration.Builder().apply {
setExecutor { GlobalScope.launch { it.run() } }
setTaskExecutor { GlobalScope.launch { it.run() } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import android.util.Log
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.core.R
import com.github.shadowsocks.preference.DataStore
import com.github.shadowsocks.utils.Key
Expand Down Expand Up @@ -66,7 +65,6 @@ class VpnRequestActivity : AppCompatActivity() {
if (requestCode != REQUEST_CONNECT) return super.onActivityResult(requestCode, resultCode, data)
if (resultCode == RESULT_OK) Core.startService() else {
Toast.makeText(this, R.string.vpn_permission_denied, Toast.LENGTH_LONG).show()
Crashlytics.log(Log.ERROR, TAG, "Failed to start VpnService from onActivityResult: $data")
}
finish()
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/com/github/shadowsocks/bg/BaseService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import android.content.IntentFilter
import android.os.*
import android.util.Log
import androidx.core.content.getSystemService
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.BootReceiver
import com.github.shadowsocks.Core
import com.github.shadowsocks.Core.app
Expand Down Expand Up @@ -119,7 +118,8 @@ object BaseService {
repeat(count) {
try {
work(callbacks.getBroadcastItem(it))
} catch (_: RemoteException) {
} catch (e: RemoteException) {
printLog(e)
} catch (e: Exception) {
printLog(e)
}
Expand All @@ -131,7 +131,7 @@ object BaseService {

private suspend fun loop() {
while (true) {
delay(bandwidthListeners.values.min() ?: return)
delay(bandwidthListeners.values.minOrNull() ?: return)
val proxies = listOfNotNull(data?.proxy, data?.udpFallback)
val stats = proxies
.map { Pair(it.profile.id, it.trafficMonitor?.requestUpdate()) }
Expand Down Expand Up @@ -228,7 +228,7 @@ object BaseService {
when {
s == State.Stopped -> startRunner()
s.canStop -> stopRunner(true)
else -> Crashlytics.log(Log.WARN, tag, "Illegal state when invoking use: $s")
else -> printLog("Illegal state when invoking use: $s")
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/com/github/shadowsocks/bg/Executable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import android.system.Os
import android.system.OsConstants
import android.text.TextUtils
import android.util.Log
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.utils.printLog
import java.io.File
import java.io.IOException

Expand All @@ -49,8 +49,8 @@ object Executable {
} catch (e: ErrnoException) {
if (e.errno != OsConstants.ESRCH) {
e.printStackTrace()
Crashlytics.log(Log.WARN, "kill", "SIGKILL ${exe.absolutePath} (${process.name}) failed")
Crashlytics.logException(e)
printLog("kill "+"SIGKILL ${exe.absolutePath} (${process.name}) failed")
printLog(e)
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions core/src/main/java/com/github/shadowsocks/bg/GuardedProcessPool.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import android.system.Os
import android.system.OsConstants
import android.util.Log
import androidx.annotation.MainThread
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.Core
import com.github.shadowsocks.utils.Commandline
import com.github.shadowsocks.utils.printLog
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import java.io.File
Expand Down Expand Up @@ -63,10 +63,10 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
try {
while (true) {
thread(name = "stderr-$cmdName") {
streamLogger(process.errorStream) { Crashlytics.log(Log.ERROR, cmdName, it) }
streamLogger(process.errorStream) { printLog("$cmdName $it") }
}
thread(name = "stdout-$cmdName") {
streamLogger(process.inputStream) { Crashlytics.log(Log.VERBOSE, cmdName, it) }
streamLogger(process.inputStream) { printLog("$cmdName $it") }
// this thread also acts as a daemon thread for waitFor
runBlocking { exitChannel.send(process.waitFor()) }
}
Expand All @@ -76,25 +76,26 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C
when {
SystemClock.elapsedRealtime() - startTime < 1000 -> throw IOException(
"$cmdName exits too fast (exit code: $exitCode)")
exitCode == 128 + OsConstants.SIGKILL -> Crashlytics.log(Log.WARN, TAG, "$cmdName was killed")
else -> Crashlytics.logException(IOException("$cmdName unexpectedly exits with code $exitCode"))
exitCode == 128 + OsConstants.SIGKILL -> printLog("$cmdName was killed")
else -> printLog(IOException("$cmdName unexpectedly exits with code $exitCode"))
}
Crashlytics.log(Log.DEBUG, TAG,
"restart process: ${Commandline.toString(cmd)} (last exit code: $exitCode)")
printLog("restart process: ${Commandline.toString(cmd)} (last exit code: $exitCode)")
start()
running = true
onRestartCallback?.invoke()
}
} catch (e: IOException) {
Crashlytics.log(Log.WARN, TAG, "error occurred. stop guard: " + Commandline.toString(cmd))
printLog("error occurred. stop guard: " + Commandline.toString(cmd))
GlobalScope.launch(Dispatchers.Main) { onFatal(e) }
} finally {
if (running) withContext(NonCancellable) { // clean-up cannot be cancelled
if (Build.VERSION.SDK_INT < 24) {
try {
Os.kill(pid.get(process) as Int, OsConstants.SIGTERM)
} catch (e: ErrnoException) {
if (e.errno != OsConstants.ESRCH) throw e
if (e.errno != OsConstants.ESRCH) printLog(e)
} catch (e: ReflectiveOperationException) {
printLog(e)
}
if (withTimeoutOrNull(500) { exitChannel.receive() } != null) return@withContext
}
Expand All @@ -113,7 +114,7 @@ class GuardedProcessPool(private val onFatal: suspend (IOException) -> Unit) : C

@MainThread
fun start(cmd: List<String>, onRestartCallback: (suspend () -> Unit)? = null) {
Crashlytics.log(Log.DEBUG, TAG, "start process: " + Commandline.toString(cmd))
printLog("start process: " + Commandline.toString(cmd))
Guard(cmd).apply {
start() // if start fails, IOException will be thrown directly
launch { looper(onRestartCallback) }
Expand Down
10 changes: 4 additions & 6 deletions core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
package com.github.shadowsocks.net

import android.util.Log
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.acl.AclMatcher
import com.github.shadowsocks.bg.BaseService
import com.github.shadowsocks.utils.printLog
Expand Down Expand Up @@ -82,7 +81,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
private val monitor = ChannelMonitor()

override val coroutineContext = SupervisorJob() + CoroutineExceptionHandler { _, t ->
if (t is IOException) Crashlytics.log(Log.WARN, TAG, t.message) else printLog(t)
printLog(t)
}
private val acl = aclSpawn?.let { async { it() } }

Expand Down Expand Up @@ -110,7 +109,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
val request = try {
Message(packet)
} catch (e: IOException) { // we cannot parse the message, do not attempt to handle it at all
Crashlytics.log(Log.WARN, TAG, e.message)
printLog(e)
return forward(packet)
}
return supervisorScope {
Expand Down Expand Up @@ -140,7 +139,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
val localResults = try {
withTimeout(TIMEOUT) { localResolver(host) }
} catch (_: TimeoutCancellationException) {
Crashlytics.log(Log.WARN, TAG, "Local resolving timed out, falling back to remote resolving")
printLog("Local resolving timed out, falling back to remote resolving")
return@supervisorScope remote.await()
} catch (_: UnknownHostException) {
return@supervisorScope remote.await()
Expand All @@ -163,9 +162,8 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
} catch (e: Exception) {
remote.cancel()
when (e) {
is TimeoutCancellationException -> Crashlytics.log(Log.WARN, TAG, "Remote resolving timed out")
is TimeoutCancellationException -> printLog("Remote resolving timed out")
is CancellationException -> { } // ignore
is IOException -> Crashlytics.log(Log.WARN, TAG, e.message)
else -> printLog(e)
}
ByteBuffer.wrap(prepareDnsResponse(request).apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
package com.github.shadowsocks.plugin

import android.util.Log
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.utils.Commandline
import com.github.shadowsocks.utils.printLog
import java.util.*

class PluginConfiguration(val pluginsOptions: Map<String, PluginOptions>, val selected: String) {
Expand All @@ -44,7 +44,7 @@ class PluginConfiguration(val pluginsOptions: Map<String, PluginOptions>, val se
}
}
} catch (exc: Exception) {
Crashlytics.log(Log.WARN, "PluginConfiguration", exc.message)
printLog( exc)
}
opt
} else PluginOptions(line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import android.system.Os
import android.util.Base64
import android.util.Log
import androidx.core.os.bundleOf
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.Core
import com.github.shadowsocks.Core.app
import com.github.shadowsocks.bg.BaseService
Expand Down Expand Up @@ -151,7 +150,7 @@ object PluginManager {
try {
initNativeFaster(provider)?.also { return it to options }
} catch (t: Throwable) {
Crashlytics.log(Log.WARN, TAG, "Initializing native plugin faster mode failed")
printLog("Initializing native plugin faster mode failed")
failure = t
}

Expand All @@ -162,7 +161,7 @@ object PluginManager {
try {
return initNativeFast(app.contentResolver, options, uri)?.let { it to options }
} catch (t: Throwable) {
Crashlytics.log(Log.WARN, TAG, "Initializing native plugin fast mode failed")
printLog("Initializing native plugin fast mode failed")
failure?.also { t.addSuppressed(it) }
failure = t
}
Expand Down
9 changes: 7 additions & 2 deletions core/src/main/java/com/github/shadowsocks/utils/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ import android.os.Build
import android.system.ErrnoException
import android.system.Os
import android.system.OsConstants
import android.util.Log
import android.util.TypedValue
import androidx.annotation.AttrRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.preference.Preference
import com.crashlytics.android.Crashlytics
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -147,9 +147,14 @@ fun Resources.Theme.resolveResourceId(@AttrRes resId: Int): Int {
val Intent.datas get() = listOfNotNull(data) + (clipData?.asIterable()?.mapNotNull { it.uri } ?: emptyList())

fun printLog(t: Throwable) {
Crashlytics.logException(t)
Log.e("Utils","printLog",t)
t.printStackTrace()
}
fun printLog(t: String?) {
if(t==null)return
//Crashlytics.logException(t)
Log.e("Utils",t)
}

fun Preference.remove() = parent!!.removePreference(this)

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@
<string name="toast_test_ended">啊!测试结束啦!</string>
<string name="toast_test_interrupted">"服务器:%s或前一个服务器导致测试中断,请检查之。"</string>
<string name="firstrun_tips_title">"首次启动提示,请仔细阅读或截图保存"</string>
<string name="firstrun_tips">"1.自动更新的网络免费服务器包括一些无效服务器(网络免费服务器来源于网络分享,为方便网友而提供,我们不对其可靠性和安全性做任何保证),请点右上角三个点的按钮,执行‘测试全部配置真连接’ ,然后再执行‘删除无效/按组排序’ 和 ‘按测速结果排序’,然后点击选中一个服务器,再点底部中间的启动VPN的圆形按钮。\n\n2.如果您不想使用自动更新的免费服务器,请在设置选项中禁用第三方服务器。然后您需要添加或导入自己的SSR服务器才能启用VPN连接。"</string>
<string name="firstrun_tips">"1.自动更新的网络免费服务器包括一些无效服务器(网络免费服务器来源于网络分享,为方便网友而提供,我们不对其可靠性和安全性做任何保证),请点右上角三个点的按钮,执行‘测试全部配置真连接’ ,然后再执行‘删除无效/按组排序’ 和 ‘按测速结果排序’,然后点击选中一个服务器,再点底部中间的启动VPN的圆形按钮。\n\n2.如果您不想使用自动更新的免费服务器,请在设置选项中禁用第三方服务器。"</string>
<string name="recommended_site_1">"<![CDATA[
<html xmlns='http://www.w3.org/1999/xhtml' dir='ltr' lang='zh-CN'>
<head profile='http://gmpg.org/xfn/11'>
Expand Down
2 changes: 1 addition & 1 deletion gitupdate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ git pull origin master
git add -A
git commit -m "update"
git push origin master
git tag -a v5.0.6.13 -m "release v5.0.6.13"
git tag -a v5.1.1 -m "release v5.1.1"
git push origin --tags
pause
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 660b8fd

Please sign in to comment.