Compare commits

...

9 Commits
1.0.1 ... 1.0.3

Author SHA1 Message Date
2dust
2b571e2a94 Merge pull request #44 from cutelua/dev
improved notification
2019-07-30 14:47:38 +08:00
cutelua
ba30697309 no need for USER_PRESENT 2019-07-11 09:19:30 +08:00
2dust
879e25bb82 sdk28 2019-07-10 14:24:09 +08:00
cutelua
17c858d24c only show speed if core isrunning 2019-07-09 15:58:36 +08:00
cutelua
71a6531835 stop speed query when screen off; resume when screen on 2019-07-09 14:32:47 +08:00
cutelua
5d760382d7 pass callback as V2RayPoint arg; stop on LowMemory 2019-07-09 13:06:28 +08:00
cutelua
4dda36673a allow go to shutdown VpnService 2019-07-09 11:43:31 +08:00
cutelua
5aca55cb8f only use title to show speed 2019-07-07 16:42:22 +08:00
cutelua
82f14f0d07 show total speed as notification title 2019-07-07 16:42:22 +08:00
15 changed files with 149 additions and 108 deletions

View File

@@ -3,8 +3,8 @@ apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdkVersion 28
buildToolsVersion '28.0.3'
compileOptions {
targetCompatibility = "8"
@@ -16,8 +16,8 @@ android {
minSdkVersion 17
targetSdkVersion Integer.parseInt("$targetSdkVer")
multiDexEnabled true
versionCode 210
versionName "1.0.1"
versionCode 212
versionName "1.0.2"
}
signingConfigs {
@@ -96,7 +96,7 @@ dependencies {
implementation "org.jetbrains.anko:anko-support-v4:$ankoVersion"
implementation "org.jetbrains.anko:anko-appcompat-v7:$ankoVersion"
implementation "org.jetbrains.anko:anko-design:$ankoVersion"
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'io.reactivex:rxjava:1.3.4'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'com.tbruyelle.rxpermissions:rxpermissions:0.9.4@aar'

View File

@@ -9,7 +9,7 @@
<!-- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<!-- <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> -->
<application
android:name=".AngApplication"

View File

@@ -55,8 +55,7 @@ class V2RayVpnService : VpnService() {
}
}
private val v2rayPoint = Libv2ray.newV2RayPoint()
private val v2rayCallback = V2RayCallback()
private val v2rayPoint = Libv2ray.newV2RayPoint(V2RayCallback())
private lateinit var configContent: String
private lateinit var mInterface: ParcelFileDescriptor
val fd: Int get() = mInterface.fd
@@ -110,9 +109,13 @@ class V2RayVpnService : VpnService() {
stopV2Ray()
}
override fun onLowMemory() {
stopV2Ray()
super.onLowMemory()
}
override fun onDestroy() {
super.onDestroy()
cancelNotification()
}
@@ -180,22 +183,11 @@ class V2RayVpnService : VpnService() {
// Create a new interface using the builder and save the parameters.
mInterface = builder.establish()
sendFd()
if (defaultDPreference.getPrefBoolean(SettingsActivity.PREF_SPEED_ENABLED, false)) {
mSubscription = Observable.interval(3, java.util.concurrent.TimeUnit.SECONDS)
.subscribe {
val uplink = v2rayPoint.queryStats("socks", "uplink")
val downlink = v2rayPoint.queryStats("socks", "downlink")
updateNotification("${(uplink / 3).toSpeedString()}${(downlink / 3).toSpeedString()}")
}
}
startSpeedNotification()
}
fun shutdown() {
try {
mInterface.close()
} catch (ignored: Exception) {
}
stopV2Ray(true)
}
fun sendFd() {
@@ -231,12 +223,15 @@ class V2RayVpnService : VpnService() {
if (!v2rayPoint.isRunning) {
try {
registerReceiver(mMsgReceive, IntentFilter(AppConfig.BROADCAST_ACTION_SERVICE))
val mFilter = IntentFilter(AppConfig.BROADCAST_ACTION_SERVICE)
mFilter.addAction(Intent.ACTION_SCREEN_ON)
mFilter.addAction(Intent.ACTION_SCREEN_OFF)
mFilter.addAction(Intent.ACTION_USER_PRESENT)
registerReceiver(mMsgReceive, mFilter)
} catch (e: Exception) {
}
configContent = defaultDPreference.getPrefString(AppConfig.PREF_CURR_CONFIG, "")
v2rayPoint.supportSet = v2rayCallback
v2rayPoint.configureFileContent = configContent
v2rayPoint.enableLocalDNS = defaultDPreference.getPrefBoolean(SettingsActivity.PREF_LOCAL_DNS_ENABLED, false)
v2rayPoint.forwardIpv6 = defaultDPreference.getPrefBoolean(SettingsActivity.PREF_FORWARD_IPV6, false)
@@ -321,7 +316,6 @@ class V2RayVpnService : VpnService() {
mBuilder = NotificationCompat.Builder(applicationContext, channelId)
.setSmallIcon(R.drawable.ic_v)
.setContentTitle(defaultDPreference.getPrefString(AppConfig.PREF_CURR_CONFIG_NAME, ""))
.setContentText(getString(R.string.notification_action_more))
.setPriority(NotificationCompat.PRIORITY_MIN)
.setOngoing(true)
.setShowWhen(false)
@@ -359,7 +353,7 @@ class V2RayVpnService : VpnService() {
private fun updateNotification(contentText: String) {
if (mBuilder != null) {
mBuilder?.setContentText(contentText)
mBuilder?.setContentTitle(contentText)
getNotificationManager().notify(NOTIFICATION_ID, mBuilder?.build())
}
}
@@ -371,8 +365,41 @@ class V2RayVpnService : VpnService() {
return mNotificationManager!!
}
fun startSpeedNotification() {
if (mSubscription == null &&
v2rayPoint.isRunning &&
defaultDPreference.getPrefBoolean(SettingsActivity.PREF_SPEED_ENABLED, false)) {
val cf_name = defaultDPreference.getPrefString(AppConfig.PREF_CURR_CONFIG_NAME, "")
var last_zero_speed = false
mSubscription = Observable.interval(3, java.util.concurrent.TimeUnit.SECONDS)
.subscribe {
val uplink = v2rayPoint.queryStats("socks", "uplink")
val downlink = v2rayPoint.queryStats("socks", "downlink")
val zero_speed = (uplink == 0L && downlink == 0L)
if (!zero_speed || !last_zero_speed) {
updateNotification("${cf_name}${(uplink / 3).toSpeedString()}${(downlink / 3).toSpeedString()}")
}
last_zero_speed = zero_speed
}
}
}
fun stopSpeedNotification() {
if (mSubscription != null) {
mSubscription?.unsubscribe() //stop queryStats
mSubscription = null
val cf_name = defaultDPreference.getPrefString(AppConfig.PREF_CURR_CONFIG_NAME, "")
updateNotification(cf_name)
}
}
private inner class V2RayCallback : V2RayVPNServiceSupportsSet {
override fun shutdown(): Long {
// called by go
// shutdown the whole vpn service
try {
this@V2RayVpnService.shutdown()
return 0
@@ -447,6 +474,17 @@ class V2RayVpnService : VpnService() {
vpnService?.startV2ray()
}
}
when (intent?.action) {
Intent.ACTION_SCREEN_OFF -> {
Log.d(AppConfig.ANG_PACKAGE, "SCREEN_OFF, stop querying stats")
vpnService?.stopSpeedNotification()
}
Intent.ACTION_SCREEN_ON -> {
Log.d(AppConfig.ANG_PACKAGE, "SCREEN_ON, start querying stats")
vpnService?.startSpeedNotification()
}
}
}
}
}

View File

@@ -98,7 +98,7 @@ class PerAppProxyActivity : BaseActivity() {
recycler_view.addOnScrollListener(object : RecyclerView.OnScrollListener() {
var dst = 0
val threshold = resources.getDimensionPixelSize(R.dimen.bypass_list_header_height) * 3
override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
dst += dy
if (dst > threshold) {
header_view.hide()

View File

@@ -62,6 +62,7 @@ class PerAppProxyAdapter(val activity: BaseActivity, val apps: List<AppInfo>, bl
val icon = itemView.icon!!
val name = itemView.name!!
val package_name = itemView.package_name!!
val checkBox = itemView.check_box!!
fun bind(appInfo: AppInfo) {
@@ -71,10 +72,7 @@ class PerAppProxyAdapter(val activity: BaseActivity, val apps: List<AppInfo>, bl
// name.text = appInfo.appName
checkBox.isChecked = inBlacklist
// name.textColor = mActivity.resources.getColor(if (appInfo.isSystemApp)
// R.color.color_highlight_material else R.color.abc_secondary_text_material_light)
package_name.text = appInfo.packageName
if (appInfo.isSystemApp) {
name.text = String.format("** %1s", appInfo.appName)
name.textColor = Color.RED

View File

@@ -34,7 +34,7 @@ class SettingsActivity : BaseActivity() {
const val PREF_DOMESTIC_DNS = "pref_domestic_dns"
// const val PREF_SOCKS_PORT = "pref_socks_port"
// const val PREF_LANCONN_PORT = "pref_lanconn_port"
// const val PREF_HTTP_PORT = "pref_http_port"
const val PREF_ROUTING_DOMAIN_STRATEGY = "pref_routing_domain_strategy"
const val PREF_ROUTING_MODE = "pref_routing_mode"
@@ -67,7 +67,7 @@ class SettingsActivity : BaseActivity() {
val forwardIpv6 by lazy { findPreference(PREF_FORWARD_IPV6) as CheckBoxPreference }
// val socksPort by lazy { findPreference(PREF_SOCKS_PORT) as EditTextPreference }
// val lanconnPort by lazy { findPreference(PREF_LANCONN_PORT) as EditTextPreference }
// val httpPort by lazy { findPreference(PREF_HTTP_PORT) as EditTextPreference }
val routingCustom: Preference by lazy { findPreference(PREF_ROUTING_CUSTOM) }
// val donate: Preference by lazy { findPreference(PREF_DONATE) }
@@ -132,8 +132,8 @@ class SettingsActivity : BaseActivity() {
// socksPort.summary = any as String
// true
// }
// lanconnPort.setOnPreferenceChangeListener { preference, any ->
// lanconnPort.summary = any as String
// httpPort.setOnPreferenceChangeListener { preference, any ->
// httpPort.summary = any as String
// true
// }
@@ -156,7 +156,7 @@ class SettingsActivity : BaseActivity() {
}
// socksPort.summary = defaultSharedPreferences.getString(PREF_SOCKS_PORT, "10808")
// lanconnPort.summary = defaultSharedPreferences.getString(PREF_LANCONN_PORT, "")
// lanconnPort.summary = defaultSharedPreferences.getString(PREF_HTTP_PORT, "")
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(this)
}

View File

@@ -131,7 +131,7 @@ object V2rayConfigUtil {
try {
v2rayConfig.inbounds[0].port = 10808
// val socksPort = Utils.parseInt(app.defaultDPreference.getPrefString(SettingsActivity.PREF_SOCKS_PORT, "10808"))
// val lanconnPort = Utils.parseInt(app.defaultDPreference.getPrefString(SettingsActivity.PREF_LANCONN_PORT, ""))
// val lanconnPort = Utils.parseInt(app.defaultDPreference.getPrefString(SettingsActivity.PREF_HTTP_PORT, ""))
// if (socksPort > 0) {
// v2rayConfig.inbounds[0].port = socksPort

View File

@@ -54,7 +54,7 @@
android:layout_toLeftOf="@id/switch_per_app_proxy"
android:layout_toStartOf="@id/switch_per_app_proxy"
android:text="@string/title_pref_per_app_proxy"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</RelativeLayout>
@@ -81,7 +81,7 @@
android:layout_toLeftOf="@id/switch_bypass_apps"
android:layout_toStartOf="@id/switch_bypass_apps"
android:text="@string/switch_bypass_apps_mode"
android:textAppearance="@style/TextAppearance.AppCompat.Medium" />
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</RelativeLayout>

View File

@@ -8,25 +8,41 @@
android:id="@+id/icon"
android:layout_width="46dp"
android:layout_height="46dp"
android:paddingEnd="10dp"
android:paddingStart="14dp"
android:paddingLeft="14dp"
android:paddingRight="10dp"
android:paddingStart="14dp" />
android:paddingEnd="10dp"
android:paddingRight="10dp" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/name"
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1.0" />
android:layout_height="46dp"
android:layout_weight="1.0"
android:gravity="center"
android:orientation="vertical"
android:paddingStart="@dimen/layout_margin_right_height"
android:paddingEnd="@dimen/layout_margin_right_height">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v7.widget.AppCompatTextView
android:id="@+id/package_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Small" />
</LinearLayout>
<android.support.v7.widget.AppCompatCheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:paddingEnd="6dp"
android:paddingStart="2dp"
android:paddingLeft="2dp"
android:paddingRight="6dp"
android:paddingStart="2dp" />
android:paddingEnd="6dp"
android:paddingRight="6dp" />
</LinearLayout>

View File

@@ -112,8 +112,8 @@
<string name="title_pref_socks_port">SOCKS5代理端口</string>
<string name="summary_pref_socks_port">SOCKS5代理端口</string>
<string name="title_pref_lanconn_port">HTTP代理端口(0=不允许)</string>
<string name="summary_pref_lanconn_port">HTTP代理端口</string>
<string name="title_pref_http_port">HTTP代理端口</string>
<string name="summary_pref_http_port">HTTP代理端口</string>
<string name="title_pref_feedback">反馈</string>
<string name="summary_pref_feedback">反馈改进或漏洞至 GitHub</string>

View File

@@ -113,8 +113,8 @@
<string name="title_pref_socks_port">SOCKS5代理端口</string>
<string name="summary_pref_socks_port">SOCKS5代理端口</string>
<string name="title_pref_lanconn_port">HTTP代理端口(0=不允許)</string>
<string name="summary_pref_lanconn_port">HTTP代理端口</string>
<string name="title_pref_http_port">HTTP代理端口</string>
<string name="summary_pref_http_port">HTTP代理端口</string>
<string name="title_pref_feedback">回饋</string>

View File

@@ -113,8 +113,8 @@
<string name="title_pref_socks_port">SOCKS5 proxy port</string>
<string name="summary_pref_socks_port">SOCKS5 proxy port</string>
<string name="title_pref_lanconn_port">HTTP proxy port(0=not allowed)</string>
<string name="summary_pref_lanconn_port">HTTP proxy port</string>
<string name="title_pref_http_port">HTTP proxy port</string>
<string name="summary_pref_http_port">HTTP proxy port</string>
<string name="title_pref_feedback">Feedback</string>
<string name="summary_pref_feedback">Feedback enhancements or bugs to GitHub</string>

View File

@@ -1,10 +1,6 @@
<?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:key="pref_bypass_mainland"-->
<!--android:summary="@string/summary_pref_bypass_mainland"-->
<!--android:title="@string/title_pref_bypass_mainland" />-->
<CheckBoxPreference
android:key="pref_per_app_proxy"
android:summary="@string/summary_pref_per_app_proxy"
@@ -28,45 +24,6 @@
</PreferenceCategory>
<PreferenceCategory android:title="@string/title_advanced">
<CheckBoxPreference
android:key="pref_forward_ipv6"
android:summary="@string/summary_pref_forward_ipv6"
android:title="@string/title_pref_forward_ipv6" />
<CheckBoxPreference
android:key="pref_local_dns_enabled"
android:summary="@string/summary_pref_local_dns_enabled"
android:title="@string/title_pref_local_dns_enabled" />
<EditTextPreference
android:key="pref_domestic_dns"
android:summary="@string/summary_pref_domestic_dns"
android:title="@string/title_pref_domestic_dns" />
<EditTextPreference
android:key="pref_remote_dns"
android:summary="@string/summary_pref_remote_dns"
android:title="@string/title_pref_remote_dns" />
<!--<EditTextPreference-->
<!--android:enabled="false"-->
<!--android:defaultValue="10808"-->
<!--android:key="pref_socks_port"-->
<!--android:summary="@string/summary_pref_socks_port"-->
<!--android:title="@string/title_pref_socks_port" />-->
<!--<EditTextPreference-->
<!--android:defaultValue="0"-->
<!--android:key="pref_lanconn_port"-->
<!--android:summary="@string/summary_pref_lanconn_port"-->
<!--android:title="@string/title_pref_lanconn_port" />-->
</PreferenceCategory>
<PreferenceCategory android:title="@string/title_pref_routing">
<ListPreference
android:defaultValue="IPIfNonMatch"
@@ -88,15 +45,47 @@
android:key="pref_routing_custom"
android:summary="@string/title_pref_routing_custom"
android:title="@string/title_pref_routing_custom" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/title_advanced">
<CheckBoxPreference
android:key="pref_forward_ipv6"
android:summary="@string/summary_pref_forward_ipv6"
android:title="@string/title_pref_forward_ipv6" />
<CheckBoxPreference
android:key="pref_local_dns_enabled"
android:summary="@string/summary_pref_local_dns_enabled"
android:title="@string/title_pref_local_dns_enabled" />
<EditTextPreference
android:key="pref_domestic_dns"
android:summary="@string/summary_pref_domestic_dns"
android:title="@string/title_pref_domestic_dns" />
<EditTextPreference
android:key="pref_remote_dns"
android:summary="@string/summary_pref_remote_dns"
android:title="@string/title_pref_remote_dns" />
<Preference
android:key="pref_socks_port"
android:summary="10808"
android:title="@string/title_pref_socks_port" />
<Preference
android:key="pref_http_port"
android:summary="10809"
android:title="@string/title_pref_http_port" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/title_about">
<!--<Preference-->
<!--android:key="pref_donate"-->
<!--android:summary="@string/summary_pref_donate"-->
<!--android:title="@string/title_pref_donate" />-->
</PreferenceCategory>
<PreferenceCategory android:title="@string/title_about">
<!--<Preference-->
<!--android:key="pref_licenses"-->
<!--android:title="@string/notices_title" />-->

View File

@@ -1,8 +1,8 @@
apply plugin: 'com.android.library'
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
minSdkVersion 17

View File

@@ -14,9 +14,9 @@
# org.gradle.parallel=true
#Fri Jun 02 14:08:42 CST 2017
ankoVersion=0.10.8
kotlinVersion=1.3.10
supportLibVersion=27.1.1
buildToolsVer=27.0.3
compileSdkVer=27
kotlinVersion=1.3.40
supportLibVersion=28.0.0
buildToolsVer=28.0.3
compileSdkVer=28
kotlin.incremental=true
targetSdkVer=27
targetSdkVer=28