Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
bannedbook committed Mar 7, 2020
1 parent bf7089d commit 95ed0a9
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 56 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ V2rayNG/gradle/wrapper/gradle-wrapper.properties
*.jks
V2rayNG/gradle/wrapper/gradle-wrapper.properties
V2rayNG/gradle/wrapper/gradle-wrapper.properties
V2rayNG/app/release/output.json
V2rayNG/app/release/output.json
gitupdate.bat
*.bak
5 changes: 3 additions & 2 deletions V2rayNG/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ android {
minSdkVersion 17
targetSdkVersion Integer.parseInt("$targetSdkVer")
multiDexEnabled true
versionCode 217
versionName "2.0.3"
versionCode 218
versionName "2.0.4"
}

signingConfigs {
Expand Down Expand Up @@ -93,6 +93,7 @@ dependencies {
implementation "com.android.support:cardview-v7:$supportLibVersion"
implementation "com.android.support:preference-v7:$supportLibVersion"
implementation "com.android.support:recyclerview-v7:$supportLibVersion"
implementation "com.android.support:multidex:1.0.3"
// DSL
implementation "org.jetbrains.anko:anko-sdk15:$ankoVersion"
implementation "org.jetbrains.anko:anko-support-v4:$ankoVersion"
Expand Down
12 changes: 10 additions & 2 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/AngApplication.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.v2ray.ang

import android.app.Application
import android.view.Gravity
import android.widget.Toast
//import com.squareup.leakcanary.LeakCanary
import android.support.multidex.MultiDexApplication
import com.v2ray.ang.util.AngConfigManager
import me.dozen.dpreference.DPreference
import org.jetbrains.anko.defaultSharedPreferences

class AngApplication : Application() {
class AngApplication : MultiDexApplication() {
companion object {
const val PREF_LAST_VERSION = "pref_last_version"
}
Expand All @@ -29,4 +31,10 @@ class AngApplication : Application() {
//Logger.init().logLevel(if (BuildConfig.DEBUG) LogLevel.FULL else LogLevel.NONE)
AngConfigManager.inject(this)
}

fun toast(msgid: Int) {
var toast = Toast.makeText(this, getString(msgid), Toast.LENGTH_SHORT)
toast.setGravity(Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL, 0, 500)
toast.show()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ import libv2ray.Libv2ray
import libv2ray.V2RayVPNServiceSupportsSet
import rx.Observable
import rx.Subscription
import java.net.InetAddress
import java.io.IOException
import java.io.File
import java.io.FileDescriptor
import java.io.FileInputStream
import java.lang.ref.SoftReference
import android.os.Build
import android.annotation.TargetApi
import android.util.Log
import go.Seq
import org.jetbrains.anko.doAsync
Expand Down Expand Up @@ -74,25 +69,36 @@ class V2RayVpnService : VpnService() {
*
* Source: https://android.googlesource.com/platform/frameworks/base/+/2df4c7d/services/core/java/com/android/server/ConnectivityService.java#887
*/
@TargetApi(28)
private val defaultNetworkRequest = NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
.build()
private val defaultNetworkRequest by lazy {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
NetworkRequest.Builder()
.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
.addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_RESTRICTED)
.build()
} else {
null
}
}


private val connectivity by lazy { getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager }
@TargetApi(28)
private val defaultNetworkCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
setUnderlyingNetworks(arrayOf(network))
}
override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities?) {
// it's a good idea to refresh capabilities
setUnderlyingNetworks(arrayOf(network))
}
override fun onLost(network: Network) {
setUnderlyingNetworks(null)

private val defaultNetworkCallback by lazy {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
setUnderlyingNetworks(arrayOf(network))
}
override fun onCapabilitiesChanged(network: Network, networkCapabilities: NetworkCapabilities?) {
// it's a good idea to refresh capabilities
setUnderlyingNetworks(arrayOf(network))
}
override fun onLost(network: Network) {
setUnderlyingNetworks(null)
}
}
} else {
null
}
}
private var listeningForDefaultNetwork = false
Expand Down Expand Up @@ -176,7 +182,7 @@ class V2RayVpnService : VpnService() {
}


if (Build.VERSION.SDK_INT >= 28) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
connectivity.requestNetwork(defaultNetworkRequest, defaultNetworkCallback)
listeningForDefaultNetwork = true
}
Expand Down Expand Up @@ -260,7 +266,7 @@ class V2RayVpnService : VpnService() {
// val emptyInfo = VpnNetworkInfo()
// val info = loadVpnNetworkInfo(configName, emptyInfo)!! + (lastNetworkInfo ?: emptyInfo)
// saveVpnNetworkInfo(configName, info)
if (Build.VERSION.SDK_INT >= 28) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
if (listeningForDefaultNetwork) {
connectivity.unregisterNetworkCallback(defaultNetworkCallback)
listeningForDefaultNetwork = false
Expand Down
5 changes: 5 additions & 0 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.v2ray.ang.ui

import android.support.v7.app.AppCompatActivity
import android.view.MenuItem
import com.v2ray.ang.extension.v2RayApplication

abstract class BaseActivity : AppCompatActivity() {
override fun onOptionsItemSelected(item: MenuItem) = when (item.itemId) {
Expand All @@ -11,4 +12,8 @@ abstract class BaseActivity : AppCompatActivity() {
}
else -> super.onOptionsItemSelected(item)
}

fun toast(msgid: Int) {
v2RayApplication.toast(msgid)
}
}
5 changes: 4 additions & 1 deletion V2rayNG/app/src/main/kotlin/com/v2ray/ang/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import java.util.concurrent.TimeUnit
import com.v2ray.ang.helper.SimpleItemTouchHelperCallback
import com.v2ray.ang.util.AngConfigManager.configs
import com.google.android.gms.ads.*
import com.v2ray.ang.extension.v2RayApplication

class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedListener {
companion object {
Expand Down Expand Up @@ -118,7 +119,9 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
drawer_layout.addDrawerListener(toggle)
toggle.syncState()
nav_view.setNavigationItemSelectedListener(this)
importConfigViaBuildinSub()
if(v2RayApplication.defaultDPreference.getPrefBoolean(SettingsActivity.PREF_isAutoUpdateServers, true)){
importConfigViaBuildinSub()
}
}

fun startV2Ray() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SettingsActivity : BaseActivity() {
companion object {
// const val PREF_BYPASS_MAINLAND = "pref_bypass_mainland"
// const val PREF_START_ON_BOOT = "pref_start_on_boot"
const val PREF_isAutoUpdateServers = "isAutoUpdateServers"
const val PREF_PER_APP_PROXY = "pref_per_app_proxy"
// const val PREF_MUX_ENAimport libv2ray.Libv2rayBLED = "pref_mux_enabled"
const val PREF_SPEED_ENABLED = "pref_speed_enabled"
Expand Down Expand Up @@ -57,6 +58,7 @@ class SettingsActivity : BaseActivity() {
}

class SettingsFragment : PreferenceFragment(), SharedPreferences.OnSharedPreferenceChangeListener {
val isAutoUpdateServers by lazy { findPreference(PREF_isAutoUpdateServers) as CheckBoxPreference }
val perAppProxy by lazy { findPreference(PREF_PER_APP_PROXY) as CheckBoxPreference }
val sppedEnabled by lazy { findPreference(PREF_SPEED_ENABLED) as CheckBoxPreference }
val sniffingEnabled by lazy { findPreference(PREF_SNIFFING_ENABLED) as CheckBoxPreference }
Expand Down Expand Up @@ -95,7 +97,9 @@ class SettingsActivity : BaseActivity() {
super.onCreate(savedInstanceState)
addPreferencesFromResource(R.xml.pref_settings)
var app = activity.application as AngApplication

isAutoUpdateServers.setOnPreferenceClickListener {
true
}
perAppProxy.setOnPreferenceClickListener {
if (isRunning()) {
Utils.stopVService(activity)
Expand Down
8 changes: 4 additions & 4 deletions V2rayNG/app/src/main/kotlin/com/v2ray/ang/util/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,9 @@ object Utils {
*/
fun startVService(context: Context): Boolean {
if (context.v2RayApplication.defaultDPreference.getPrefBoolean(SettingsActivity.PREF_PROXY_SHARING, false)) {
context.toast(R.string.toast_warning_pref_proxysharing_short)
context.v2RayApplication.toast(R.string.toast_warning_pref_proxysharing_short)
}else{
context.toast(R.string.toast_services_start)
context.v2RayApplication.toast(R.string.toast_services_start)
}
if (AngConfigManager.genStoreV2rayConfig(-1)) {
val configContent = AngConfigManager.currGeneratedV2rayConfig()
Expand All @@ -324,7 +324,7 @@ object Utils {
try {
Libv2ray.testConfig(configContent)
} catch (e: Exception) {
context.toast(e.toString())
context.v2RayApplication.toast(e.toString())
return false
}
}
Expand Down Expand Up @@ -356,7 +356,7 @@ object Utils {
* stopVService
*/
fun stopVService(context: Context) {
context.toast(R.string.toast_services_stop)
context.v2RayApplication.toast(R.string.toast_services_stop)
MessageUtil.sendMsg2Service(context, AppConfig.MSG_STATE_STOP, "")
}

Expand Down
12 changes: 3 additions & 9 deletions V2rayNG/app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,21 +184,15 @@
<string name="toast_warning_pref_proxysharing">其他设备可以使用socks/http协议通过您的IP地址连接到代理\nHttp 代理: http://您的ip:10809\nSocks 代理: socks(4/5)://您的ip:10808\n仅在受信任的网络中启用以避免未经授权的连接</string>
<string name="toast_warning_pref_proxysharing_short">代理共享已启用,请确保处于受信网络</string>
<string name="toast_malformed_josn">配置格式错误</string>

<string name="auto_update_servers">"自动更新服务器"</string>
<string name="auto_update_servers_summary">"应用启动后自动更新VPN服务器"</string>
<string name="recommended_site_1"><![CDATA[
<html>
<body style=\'margin:0;padding:0;font-size:14px;text-align:right\'>
<a href=\'http://dongtaiwang.com/loc/mobile/\' style=\'color:#e4f2fd\'>动态网</a>&nbsp;&nbsp;<a href=\'https://www.bannedbook.org/?utm_source=v2ray.vpn.cn\' style=\'color:#e4f2fd\'>禁闻网</a>&nbsp;&nbsp;
</body>
</html>
]]></string>
<string name="recommended_site_2"><![CDATA[
<html>
<body style=\'margin:0;padding:0;font-size:14px;text-align:right\'>
<a href=\'https://www.bannedbook.org/?utm_source=speedup.vpn.cn\' style=\'color:#e4f2fd\'>看禁闻</a>
</body>
</html>
]]></string>
<item>your_url</item>
<string name="recommended_site_2"></string>
<string name="update_builtin_servers">更新内置VPN服务器</string>
</resources>
11 changes: 3 additions & 8 deletions V2rayNG/app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,20 +186,15 @@
<string name="toast_warning_pref_proxysharing">其他設備可以使用socks/http協議通過您的IP地址連接到代理\nHttp 代理: http://您的ip:10809\nSocks 代理: socks(4/5)://您的ip:10808\n僅在受信任的網絡中啟用以避免未經授權的連接</string>
<string name="toast_warning_pref_proxysharing_short">代理共享已啟用,請確保處於受信網絡</string>
<string name="toast_malformed_josn">配置格式錯誤</string>
<string name="auto_update_servers">"自動更新服務器"</string>
<string name="auto_update_servers_summary">"應用啟動後自動更新VPN服務器"</string>
<string name="recommended_site_1"><![CDATA[
<html>
<body style=\'margin:0;padding:0;font-size:14px;text-align:right\'>
<a href=\'https://www.bannedbook.org/bnews/zh-tw/?utm_source=v2ray.vpn.b5\' style=\'color:#e4f2fd\'>禁聞網</a>&nbsp;&nbsp;<a href=\'https://www.bannedbook.org/b5/?utm_source=v2ray.vpn.b5\' style=\'color:#e4f2fd\'>禁書網</a>&nbsp;&nbsp;
</body>
</html>
]]></string>
<string name="recommended_site_2"><![CDATA[
<html>
<body style=\'margin:0;padding:0;font-size:14px;text-align:right\'>
<a href=\'https://www.bannedbook.org/b5/?utm_source=speedup.vpn.b5\' style=\'color:#e4f2fd\'>禁書網</a>
</body>
</html>
]]></string>
<item>your_url</item>
<string name="recommended_site_2"></string>
<string name="update_builtin_servers">更新內置VPN伺服器</string>
</resources>
15 changes: 11 additions & 4 deletions V2rayNG/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<string name="toast_services_failure">Start Services Failure</string>

<!--ServerActivity-->
<string name="title_server">Configuration file</string>
<string name="title_server">Config file</string>
<string name="menu_item_add_config">Add config</string>
<string name="menu_item_save_config">Save config</string>
<string name="menu_item_del_config">Delete config</string>
Expand Down Expand Up @@ -186,9 +186,16 @@
<string name="toast_warning_pref_proxysharing">Other devices can connect to proxy by your ip address through socks/http protocol\nHttp Proxy: http://yourIP:10809\nSocks Proxy: socks(4/5)://yourIP:10808\nOnly enable in trusted network to avoid unauthorized connection</string>
<string name="toast_warning_pref_proxysharing_short">Proxy sharing enabled\nMake sure you are in a trusted network</string>
<string name="toast_malformed_josn">Config malformed</string>

<string name="recommended_site_1"></string>
<string name="recommended_site_2"></string>
<string name = "auto_update_servers">Automatic Update Servers</string>
<string name = "auto_update_servers_summary">Automatically update VPN servers when App launch</string>
<string name="recommended_site_1"><![CDATA[
<html>
<body style=\'margin:0;padding:0;font-size:14px;text-align:right\'>
<a href=\'https://www.theepochtimes.com/?utm_source=ss.vpn\' style=\'color:#e4f2fd\'>News</a>&nbsp;&nbsp;<a href=\'https://github.com/killgcd/justmysocks/blob/master/en.md#head\' style=\'color:#e4f2fd\'>Ad:SS Server</a>&nbsp;&nbsp;
</body>
</html>
]]></string>
<string name="recommended_site_2"></string>
<string-array name="builtinSubUrls">
<item>your_url</item>
</string-array>
Expand Down
5 changes: 5 additions & 0 deletions V2rayNG/app/src/main/res/xml/pref_settings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/title_settings">
<CheckBoxPreference
android:defaultValue="true"
android:key="isAutoUpdateServers"
android:summary="@string/auto_update_servers_summary"
android:title="@string/auto_update_servers"/>
<CheckBoxPreference
android:key="pref_per_app_proxy"
android:summary="@string/summary_pref_per_app_proxy"
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 v2.0.3 -m "release v2.0.3"
git tag -a v2.0.4 -m "release v2.0.4"
git push origin --tags
pause

0 comments on commit 95ed0a9

Please sign in to comment.