Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bannedbook committed Jun 13, 2020
1 parent 07f6b1f commit 9b94f0e
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 84 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {
compileSdkVersion = 29
buildToolsVersion = '29.0.3'
desugarLibsVersion = '1.0.5'
versionCode = 426
versionName = '5.0.6.6R'
versionCode = 439
versionName = '5.0.6.8R'
resConfigs = ['ar', 'es', 'fa', 'fr', 'ja', 'ko', 'ru', 'tr', 'zh-rCN', 'zh-rTW']
}

Expand All @@ -24,7 +24,7 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:4.0.0-beta05'
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'
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ dependencies {
api "androidx.work:work-runtime-ktx:$workVersion"
api 'com.crashlytics.sdk.android:crashlytics:2.10.1'
api 'com.google.code.gson:gson:2.8.6'
api 'com.google.firebase:firebase-analytics:17.2.2'
api 'com.google.firebase:firebase-analytics:17.4.3'
api 'dnsjava:dnsjava:2.1.9'
api "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutinesVersion"
api 'org.connectbot.jsocks:jsocks:1.0.0'
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
android:networkSecurityConfig="@xml/network_security_config"
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:usesCleartextTraffic="false">
android:usesCleartextTraffic="true">
<!-- get aip_key from https://developer.android.com/google/backup/signup.html -->
<meta-data android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIM5F-5ydWKC8n0V5PCzVXtGOerdXdgxzbf7k_5g" />
Expand Down
39 changes: 23 additions & 16 deletions core/src/main/java/com/github/shadowsocks/Core.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import java.io.File
import java.io.IOException
import java.util.*
import kotlin.reflect.KClass

object Core {
Expand Down Expand Up @@ -102,23 +103,29 @@ object Core {
fun updateBuiltinServers(activity:Activity? = null){
Log.e("updateBuiltinServers ","...")
GlobalScope.launch {
var builtinSubUrls = app.resources.getStringArray(com.github.shadowsocks.core.R.array.builtinSubUrls)
var builtinSub:SSRSub?=null
for (i in builtinSubUrls.indices) {
builtinSub= SSRSubManager.createBuiltinSub(builtinSubUrls[i],"aes")
if (builtinSub != null) {
//val randomOne=ProfileManager.getRandomVPNServer()
//if (randomOne!=null)DataStore.profileId=randomOne.id
break
val userCountry= Locale.getDefault().country
Log.e("userCountry",userCountry)
if ("CN" != userCountry){
var builtinSubUrls = app.resources.getStringArray(R.array.builtinSubUrls)
var builtinSub:SSRSub?=null
for (i in builtinSubUrls.indices) {
builtinSub= SSRSubManager.createBuiltinSub(builtinSubUrls[i],"aes")
if (builtinSub != null) {
//val randomOne=ProfileManager.getRandomVPNServer()
//if (randomOne!=null)DataStore.profileId=randomOne.id
break
}
}
if (builtinSub == null) {
activity?.runOnUiThread(){alertMessage(app.getString(R.string.status_network_error),activity)}
}else {//如果不是APP启动时更新,则停止服务,提醒重新连接
//stopService()
//activity?.runOnUiThread(){alertMessage(app.getString(R.string.update_servers_ok),activity)}
}
}

if (builtinSub == null) {
activity?.runOnUiThread(){alertMessage(app.getString(R.string.status_network_error),activity)}
}else {//如果不是APP启动时更新,则停止服务,提醒重新连接
//stopService()
//activity?.runOnUiThread(){alertMessage(app.getString(R.string.update_servers_ok),activity)}
}
if(DataStore.is_get_free_servers)importFreeSubs() //update free_servers
app.startService(Intent(app, SubscriptionService::class.java)) //update Subscription
}
}

Expand Down Expand Up @@ -216,14 +223,14 @@ object Core {
toast.show()
}

fun alertMessage(msg: String,activity:Context) {
fun alertMessage(msg: String,activity:Context,title:String="SpeedUp VPN") {
try {
if(activity==null || (activity as Activity).isFinishing)return

val builder: AlertDialog.Builder? = activity.let {
AlertDialog.Builder(activity)
}
builder?.setMessage(msg)?.setTitle("SpeedUp VPN")?.setPositiveButton("ok", DialogInterface.OnClickListener {
builder?.setMessage(msg)?.setTitle(title)?.setPositiveButton("ok", DialogInterface.OnClickListener {
_, _ ->
})
val dialog: AlertDialog? = builder?.create()
Expand Down
20 changes: 10 additions & 10 deletions core/src/main/java/com/github/shadowsocks/database/Profile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ data class Profile(
val match4 = decodedPattern_ssr_groupparam.matchEntire(match.groupValues[8])
if (match4 != null) profile.url_group = base64Decode(match4.groupValues[2])

profile
if (profile.name.startsWith("CN-GD",true) || profile.name=="地址错误")
null
else
profile
} else {
null
}
Expand Down Expand Up @@ -313,6 +316,9 @@ data class Profile(
@Query("SELECT * FROM `Profile` WHERE `id` = :id")
operator fun get(id: Long): Profile?

@Query("SELECT * FROM `Profile` WHERE `host` = :host LIMIT 1")
fun getByHost(host: String): Profile?

@Query("SELECT * FROM `Profile` WHERE `Subscription` != 2 ORDER BY `userOrder`")
fun listActive(): List<Profile>

Expand Down Expand Up @@ -377,9 +383,9 @@ data class Profile(
}
}

fun isSameHostAs(other: Profile): Boolean = other.host == host
fun isSameAs(other: Profile): Boolean = other.host == host
fun updateWith(other: Profile){
if (!isSameHostAs(other))return
if (!isSameAs(other))return
host = other.host
remotePort = other.remotePort
password = other.password
Expand All @@ -392,12 +398,6 @@ data class Profile(
url_group = other.url_group
}

fun isSameAs(other: Profile): Boolean = other.host == host && other.remotePort == remotePort &&
other.password == password && other.method == method &&
other.protocol == protocol && other.protocol_param == protocol_param &&
other.obfs == obfs && other.obfs_param == obfs_param &&
other.name == name && other.url_group == url_group

override fun toString(): String {
val flags = Base64.NO_PADDING or Base64.URL_SAFE or Base64.NO_WRAP
return "ssr://" + Base64.encodeToString("%s:%d:%s:%s:%s:%s/?obfsparam=%s&protoparam=%s&remarks=%s&group=%s"
Expand Down Expand Up @@ -489,6 +489,6 @@ data class Profile(
udpFallback = DataStore.udpFallback
}
fun isBuiltin(): Boolean {
return VpnEncrypt.vpnGroupName == url_group
return url_group == VpnEncrypt.vpnGroupName || url_group == VpnEncrypt.freesubGroupName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,19 @@ object ProfileManager {

@Throws(SQLException::class)
fun createProfile(profile: Profile = Profile()): Profile {
profile.id = 0
profile.userOrder = PrivateDatabase.profileDao.nextOrder() ?: 0
profile.id = PrivateDatabase.profileDao.create(profile)
listener?.onAdd(profile)
return profile
var existOne=PrivateDatabase.profileDao.getByHost(profile.host)
if (existOne==null) {
profile.id = 0
profile.userOrder = PrivateDatabase.profileDao.nextOrder() ?: 0
profile.id = PrivateDatabase.profileDao.create(profile)
listener?.onAdd(profile)
return profile
}
else {
existOne.updateWith(profile)
return profile
}

}

fun deletSSRSubProfiles(profiles: List<Profile>) {
Expand Down Expand Up @@ -83,7 +91,7 @@ object ProfileManager {
profiles.filter {
for (i: Profile in old) if (it.isSameAs(i)) {
old.remove(i)
return@filter false
return@filter true //change to true, because old one also need update
}
return@filter true
}.forEach {
Expand All @@ -99,7 +107,7 @@ object ProfileManager {
old.remove(activeProfile)
deletBuiltinSSRSubProfiles(old)
profiles.forEach {
if(activeProfile==null || !activeProfile.isSameHostAs(it))
if(activeProfile==null || !activeProfile.isSameAs(it))
createProfile(it)
else {
activeProfile.updateWith(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ object SSRSubManager {
profiles = profiles.shuffled().take(limit)
}

if(ssrSub.isBuiltin())
ProfileManager.createBuiltinProfilesFromSub(profiles)
else
//if(ssrSub.isBuiltin())
//ProfileManager.createBuiltinProfilesFromSub(profiles)
//else
ProfileManager.createProfilesFromSub(profiles, ssrSub.url_group)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
val directBootAware: Boolean get() = Core.directBootSupported && canToggleLocked
val tcpFastOpen: Boolean get() = TcpFastOpen.sendEnabled && publicStore.getBoolean(Key.tfo, false)
val isAutoUpdateServers: Boolean get() = publicStore.getBoolean(Key.isAutoUpdateServers, true)
val is_get_free_servers: Boolean get() = publicStore.getBoolean(Key.is_get_free_servers, false)
val is_get_free_servers: Boolean get() = publicStore.getBoolean(Key.is_get_free_servers, true)
val aclUrl: String get() = publicStore.getString(Key.aclUrl) ?: ""
val serviceMode get() = publicStore.getString(Key.serviceMode) ?: Key.modeVpn
val listenAddress get() = if (publicStore.getBoolean(Key.shareOverLan, false)) "0.0.0.0" else "127.0.0.1"
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
<string name="title_sort_servers_by_speed">按测速结果排序</string>
<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="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 All @@ -205,7 +207,7 @@
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
</head>
<body style=\'margin:0 auto;padding:5px 0;font-size:14px;text-align:center\'>
<a href=\'https://www.bannedbook.org/?utm_source=speedup.vpn.cn\' style=\'color:#e4f2fd\'>翻墙必看:每日热点禁闻,火爆评论,精彩视频</a>
<a href=\'https://play.google.com/store/apps/details?id=free.v2ray.proxy.VPN\' style=\'color:#e4f2fd\'>V2ray VPN:免费快速稳定不限流量</a>
</body>
</html>
]]>"</string>
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
<string name="title_sort_servers_by_speed">按測速結果排序</string>
<string name="toast_test_ended">啊!測試結束啦!</string>
<string name="toast_test_interrupted">"伺服器:%s或前一個伺服器導致測試中斷,請檢查之。"</string>
<string name="firstrun_tips_title">"首次啟動提示,請仔細閱讀或截圖保存"</string>
<string name="firstrun_tips">"自動更新的網路免費伺服器包括一些無效伺服器,請點右上角三個點的按鈕,執行‘測試全部配置真連接’ ,然後再執行‘刪除無效/按組排序’ 和 ‘按測速結果排序’。然後點擊選中一個服務器,再點底部中間的啟動VPN的圓形按鈕。"</string>
<string name="recommended_site_1"><![CDATA[
<html>
<body style=\'margin:0;padding:0;font-size:14px;text-align:right\'>
Expand All @@ -211,7 +213,7 @@
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
</head>
<body style=\'margin:0 auto;padding:5px 0;font-size:14px;text-align:center\'>
<a href=\'https://www.bannedbook.org/bnews/zh-tw/?utm_source=speedup.vpn.b5\' style=\'color:#e4f2fd\'>中美港臺時事熱點:每日火爆新聞,焦點評論</a>
<a href=\'https://play.google.com/store/apps/details?id=free.v2ray.proxy.VPN\' style=\'color:#e4f2fd\'>V2ray VPN:免费快速稳定不限流量</a>
</body>
</html>
]]>"</string>
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@
<string name="title_sort_servers_by_speed">Sort servers by speed</string>
<string name="toast_test_ended">The test ended successfully</string>
<string name="toast_test_interrupted">Server:%s or the previous one caused the test to be interrupted, please check them.</string>
<string name="firstrun_tips_title">First run tips,please read carefully or take screenshot.</string>
<string name="firstrun_tips">The free servers that are automatically updated include some invalid servers. Before start vpn, please click the three dots button at the upper right corner and execute \'Real test all servers\', and then execute \'Remove invalid/Sort by group\' and \'Sort servers by speed\'. Then click to select a server, and then click the round button at the bottom to start VPN connection.</string>
<string name="recommended_site_1">"<![CDATA[
<html xmlns='http://www.w3.org/1999/xhtml'>
<head profile='http://gmpg.org/xfn/11'>
Expand All @@ -213,7 +215,7 @@
<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
</head>
<body style=\'margin:0 auto;padding:5px 0;font-size:14px;text-align:center\'>
<a href=\'https://play.google.com/store/apps/details?id=com.theepochtimes.news\' style=\'color:#e4f2fd\'>The Epoch Times: Live & Breaking News</a>
<a href=\'https://play.google.com/store/apps/details?id=free.v2ray.proxy.VPN\' style=\'color:#e4f2fd\'>V2ray VPN:free,fast,stable,unmetered</a>
</body>
</html>
]]>"</string>
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/res/xml/network_security_config.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="false"/>
<base-config cleartextTrafficPermitted="true"/>
</network-security-config>
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.6 -m "release v5.0.6.6"
git tag -a v5.0.6.8 -m "release v5.0.6.8"
git push origin --tags
pause
6 changes: 3 additions & 3 deletions mobile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ dependencies {
implementation 'androidx.browser:browser:1.3.0-alpha01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
implementation 'com.google.android.gms:play-services-vision:19.0.0'
implementation 'com.google.android.gms:play-services-vision:20.1.0'
implementation 'com.google.zxing:core:3.4.0'
implementation 'com.takisoft.preferencex:preferencex-simplemenu:1.1.0'
implementation 'com.twofortyfouram:android-plugin-api-for-locale:1.0.4'
implementation 'com.google.android.gms:play-services-ads:18.3.0'
implementation 'com.google.android.gms:play-services-ads:19.1.0'
implementation 'me.zhanghai.android.fastscroll:library:1.1.0'
implementation 'xyz.belvi.mobilevision:barcodescanner:2.0.3'
implementation 'com.google.firebase:firebase-analytics:17.2.2'
implementation 'com.google.firebase:firebase-analytics:17.4.3'
implementation 'com.crashlytics.sdk.android:crashlytics:2.10.1'
}
26 changes: 21 additions & 5 deletions mobile/src/main/java/com/github/shadowsocks/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.app.Activity
import android.app.backup.BackupManager
import android.content.ActivityNotFoundException
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.ShortcutManager
import android.net.VpnService
import android.os.Build
Expand Down Expand Up @@ -58,9 +59,12 @@ import com.github.shadowsocks.utils.getBitmap
import com.github.shadowsocks.widget.ListHolderListener
import com.github.shadowsocks.widget.ServiceButton
import com.github.shadowsocks.widget.StatsBar
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.MobileAds
import com.google.android.material.navigation.NavigationView
import com.google.android.material.snackbar.Snackbar
import com.google.android.gms.ads.*
import java.lang.Exception

class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPreferenceDataStoreChangeListener,
NavigationView.OnNavigationItemSelectedListener {
Expand Down Expand Up @@ -181,6 +185,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
}
}
lateinit var mAdView : AdView
var prefs: SharedPreferences? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
//requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;//会导致statusbar有时不能自动缩回,改为在AndroidMainfest.xml设置
Expand All @@ -189,9 +194,9 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
setContentView(R.layout.layout_main)

MobileAds.initialize(this) {}
mAdView = findViewById(R.id.adView)
val adRequest = AdRequest.Builder().build()
mAdView.loadAd(adRequest)
// mAdView = findViewById(R.id.adView)
// val adRequest = AdRequest.Builder().build()
// mAdView.loadAd(adRequest)

snackbar = findViewById(R.id.snackbar)
snackbar.setOnApplyWindowInsetsListener(ListHolderListener)
Expand Down Expand Up @@ -226,10 +231,21 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
recommendedNewsView.setBackgroundColor(Color.TRANSPARENT);
recommendedNewsView.loadDataWithBaseURL(null,recnews,"text/html; charset=utf-8", "UTF-8",null)
*/
try {prefs = getSharedPreferences("free.ssr.proxy.SpeedUp.VPN", MODE_PRIVATE)}catch (e:Exception){}
//导入内置订阅
if(DataStore.isAutoUpdateServers)Core.updateBuiltinServers()
}

override fun onResume() {
super.onResume()
try {
if (prefs!!.getBoolean("firstrun", true)) {
// Do first run stuff here then set 'firstrun' as false
Core.alertMessage(getString(R.string.firstrun_tips), this,getString(R.string.firstrun_tips_title))
// using the following line to edit/commit prefs
prefs!!.edit().putBoolean("firstrun", false).commit()
}
}catch (e:Exception){}
}
override fun onPreferenceDataStoreChanged(store: PreferenceDataStore, key: String) {
when (key) {
Key.serviceMode -> handler.post {
Expand Down
Loading

0 comments on commit 9b94f0e

Please sign in to comment.