diff --git a/AndroidLibV2rayLite/interact.go b/AndroidLibV2rayLite/interact.go index 6b49ed3c..e05c00ea 100644 --- a/AndroidLibV2rayLite/interact.go +++ b/AndroidLibV2rayLite/interact.go @@ -119,7 +119,7 @@ func (v V2RayPoint) QueryStats(tag string, direct string) int64 { if v.statsManager == nil { return 0 } - counter := v.statsManager.GetCounter(fmt.Sprintf("inbound>>>%s>>>traffic>>>%s", tag, direct)) + counter := v.statsManager.GetCounter(fmt.Sprintf("outbound>>>%s>>>traffic>>>%s", tag, direct)) if counter == nil { return 0 } diff --git a/V2rayNG/app/src/main/assets/v2ray_config.json b/V2rayNG/app/src/main/assets/v2ray_config.json index c88ca53c..2783ec74 100644 --- a/V2rayNG/app/src/main/assets/v2ray_config.json +++ b/V2rayNG/app/src/main/assets/v2ray_config.json @@ -13,8 +13,8 @@ } }, "system": { - "statsInboundUplink": true, - "statsInboundDownlink": true + "statsOutboundUplink": true, + "statsOutboundDownlink": true } }, "inbounds": [{ diff --git a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt index a07941af..7c614210 100644 --- a/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt +++ b/V2rayNG/app/src/main/kotlin/com/v2ray/ang/service/V2RayVpnService.kt @@ -40,6 +40,7 @@ class V2RayVpnService : VpnService() { const val NOTIFICATION_ID = 1 const val NOTIFICATION_PENDING_INTENT_CONTENT = 0 const val NOTIFICATION_PENDING_INTENT_STOP_V2RAY = 1 + const val NOTIFICATION_ICON_THRESHOLD = 3000 fun startV2Ray(context: Context) { val intent = Intent(context.applicationContext, V2RayVpnService::class.java) @@ -359,9 +360,16 @@ class V2RayVpnService : VpnService() { mSubscription = null } - private fun updateNotification(contentText: String) { + private fun updateNotification(contentText: String, proxyTraffic: Long, directTraffic: Long) { if (mBuilder != null) { - mBuilder?.setContentTitle(contentText) + if (proxyTraffic < NOTIFICATION_ICON_THRESHOLD && directTraffic < NOTIFICATION_ICON_THRESHOLD) { + mBuilder?.setSmallIcon(R.drawable.ic_v) + } else if (proxyTraffic > directTraffic) { + mBuilder?.setSmallIcon(R.drawable.ic_stat_proxy) + } else { + mBuilder?.setSmallIcon(R.drawable.ic_stat_direct) + } + mBuilder?.setStyle(NotificationCompat.BigTextStyle().bigText(contentText)) getNotificationManager().notify(NOTIFICATION_ID, mBuilder?.build()) } } @@ -382,13 +390,19 @@ class V2RayVpnService : VpnService() { 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) + val proxyUplink = v2rayPoint.queryStats("proxy", "uplink") + val proxyDownlink = v2rayPoint.queryStats("proxy", "downlink") + val directUplink = v2rayPoint.queryStats("direct", "uplink") + val directDownlink = v2rayPoint.queryStats("direct", "downlink") + val zero_speed = (proxyUplink == 0L && proxyDownlink == 0L && directUplink == 0L && directDownlink == 0L) val queryTime = System.currentTimeMillis() if (!zero_speed || !last_zero_speed) { - updateNotification("${cf_name} • ${(uplink * 1000 / (queryTime - lastQueryTime)).toSpeedString()}↑" + - " ${(downlink * 1000 / (queryTime - lastQueryTime)).toSpeedString()}↓") + val sinceLastQueryInSeconds = (queryTime - lastQueryTime) / 1000.0 + updateNotification("proxy\t• ${(proxyUplink / sinceLastQueryInSeconds).toLong().toSpeedString()}↑ " + + "${(proxyDownlink / sinceLastQueryInSeconds).toLong().toSpeedString()}↓\n" + + "direct\t• ${(directUplink / sinceLastQueryInSeconds).toLong().toSpeedString()}↑ " + + "${(directDownlink / sinceLastQueryInSeconds).toLong().toSpeedString()}↓", + proxyDownlink + proxyUplink, directDownlink + directUplink) } last_zero_speed = zero_speed lastQueryTime = queryTime @@ -403,7 +417,7 @@ class V2RayVpnService : VpnService() { mSubscription = null val cf_name = defaultDPreference.getPrefString(AppConfig.PREF_CURR_CONFIG_NAME, "") - updateNotification(cf_name) + updateNotification(cf_name, 0, 0) } } diff --git a/V2rayNG/app/src/main/res/drawable/ic_stat_direct.png b/V2rayNG/app/src/main/res/drawable/ic_stat_direct.png new file mode 100644 index 00000000..406a0c76 Binary files /dev/null and b/V2rayNG/app/src/main/res/drawable/ic_stat_direct.png differ diff --git a/V2rayNG/app/src/main/res/drawable/ic_stat_proxy.png b/V2rayNG/app/src/main/res/drawable/ic_stat_proxy.png new file mode 100644 index 00000000..daef5970 Binary files /dev/null and b/V2rayNG/app/src/main/res/drawable/ic_stat_proxy.png differ diff --git a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml index 535748f3..3b0079fb 100644 --- a/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rCN/strings.xml @@ -83,7 +83,7 @@ 开启可能会加速,关闭可能会减少断流 启用速度显示 - 在通知中显示当前速度 + 在通知中显示当前速度\n小图标显示流量的路由情况 启用流量探测 流量探测 diff --git a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml index fde2fb1e..452be54d 100644 --- a/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml +++ b/V2rayNG/app/src/main/res/values-zh-rTW/strings.xml @@ -84,7 +84,7 @@ 啟用或許會加快網路速度,切換或許會閃爍 啟用速度顯示 - 在通知中顯示當前速度 + 在通知中顯示當前速度\n小圖標顯示流量的路由情況 啟用流量探測 流量探測 diff --git a/V2rayNG/app/src/main/res/values/strings.xml b/V2rayNG/app/src/main/res/values/strings.xml index 6865872a..76a6e653 100644 --- a/V2rayNG/app/src/main/res/values/strings.xml +++ b/V2rayNG/app/src/main/res/values/strings.xml @@ -84,7 +84,8 @@ Enable maybe speed up network and switch network maybe flash Enable speed display - Display current speed in the notification + Display current speed in the notification.\nNotification icon would change based on + usage. Enable Sniffing Sniffing