From 5bf2fda990d3136b30e9aa2ac19ddf75d3c6e029 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 18 Jul 2020 13:09:53 -0400 Subject: [PATCH 1/2] Measure traffic from outbounds With v2ray-core 4.26.0, traffic can be measured from outbounds. Stats is shown separately for proxy and direct traffic. In the future, it is possible to add stats for each server node and even historic usage graph. --- AndroidLibV2rayLite/interact.go | 2 +- V2rayNG/app/src/main/assets/v2ray_config.json | 4 ++-- .../com/v2ray/ang/service/V2RayVpnService.kt | 17 +++++++++++------ 3 files changed, 14 insertions(+), 9 deletions(-) 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..1a1dcebe 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 @@ -361,7 +361,7 @@ class V2RayVpnService : VpnService() { private fun updateNotification(contentText: String) { if (mBuilder != null) { - mBuilder?.setContentTitle(contentText) + mBuilder?.setStyle(NotificationCompat.BigTextStyle().bigText(contentText)) getNotificationManager().notify(NOTIFICATION_ID, mBuilder?.build()) } } @@ -382,13 +382,18 @@ 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()}↓") } last_zero_speed = zero_speed lastQueryTime = queryTime From 1144183da48af082f3c162eb989e02bda93b2252 Mon Sep 17 00:00:00 2001 From: yuhan6665 <1588741+yuhan6665@users.noreply.github.com> Date: Sat, 18 Jul 2020 13:09:53 -0400 Subject: [PATCH 2/2] Update notification icon based on traffic Notification icon would be a good indication for current traffic - going through proxy - connect directly - not going through v2rayNG --- .../com/v2ray/ang/service/V2RayVpnService.kt | 15 ++++++++++++--- .../app/src/main/res/drawable/ic_stat_direct.png | Bin 0 -> 1915 bytes .../app/src/main/res/drawable/ic_stat_proxy.png | Bin 0 -> 3199 bytes .../app/src/main/res/values-zh-rCN/strings.xml | 2 +- .../app/src/main/res/values-zh-rTW/strings.xml | 2 +- V2rayNG/app/src/main/res/values/strings.xml | 3 ++- 6 files changed, 16 insertions(+), 6 deletions(-) create mode 100644 V2rayNG/app/src/main/res/drawable/ic_stat_direct.png create mode 100644 V2rayNG/app/src/main/res/drawable/ic_stat_proxy.png 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 1a1dcebe..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,8 +360,15 @@ class V2RayVpnService : VpnService() { mSubscription = null } - private fun updateNotification(contentText: String) { + private fun updateNotification(contentText: String, proxyTraffic: Long, directTraffic: Long) { if (mBuilder != null) { + 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()) } @@ -393,7 +401,8 @@ class V2RayVpnService : VpnService() { updateNotification("proxy\t• ${(proxyUplink / sinceLastQueryInSeconds).toLong().toSpeedString()}↑ " + "${(proxyDownlink / sinceLastQueryInSeconds).toLong().toSpeedString()}↓\n" + "direct\t• ${(directUplink / sinceLastQueryInSeconds).toLong().toSpeedString()}↑ " + - "${(directDownlink / sinceLastQueryInSeconds).toLong().toSpeedString()}↓") + "${(directDownlink / sinceLastQueryInSeconds).toLong().toSpeedString()}↓", + proxyDownlink + proxyUplink, directDownlink + directUplink) } last_zero_speed = zero_speed lastQueryTime = queryTime @@ -408,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 0000000000000000000000000000000000000000..406a0c76906cc821cc56ddfa2f6176b32eb5736a GIT binary patch literal 1915 zcmYjSd05if8vgwtpiJ|orVgeOA;nzTL{LZzw*pr*aw|(xP*TAKgUs?r<(QLYI+~`r zC6+o_jd-oAQ<81gxMhnM)5PjJ*`khSi>6(i+cVFc=Q-y)-*>*}eb4*;aZWbRe~Xa; z+5i9mBQD1?NFO5?=TfA8eO@eg1_01U%ny}?`uVb=qzNQJv~;(Sq)15Ap96r)CPktk zDo!ZF>=wp|C9c?s);26g9PNq?q5Dz%5# zBsq;FO^zW`nM@{`;y`wAAnH4aDf=Wcfr2PWS-S}Fe+*AyN>s8qQ6`p3FpHRi-O^N< zD;7&$Bq4ue(aR(MrB9#y<&aRKw?<$DjLm55M9u%n z3dO@aljA(E~{)k7G#AHJ5L()5}+?;Itk6EyswijHaaO=K52M40Qh_! zdg>wHSkMb_@nilvYWvHtCX~jNWyW?^D9#>Z7a-?$z$!_=D9~T5Jpl|f1fk(2F^=b9 z{V0Q9fDoP*&1u`_EnrXQj81EG>^0`k&si=Qs)q5IPVAtV!JoPjO84}`rP>{~oQz9m z0{}Nd*$<__GDDF&3Ti6z3)|6{Iuymi*_C&+@M?DtpLfrDjs9+{C9Kb%*lU8p`Odd@ z*|YSmSM_#0Or(`mu`;YLR!*g2=3Ca6fCu!IA^4aSNusHHU}OD$c@j74BzP4ZHYPlbh0QUa&)P=pe?`ivKClBuVF`B);Br#jHPV-% zu0#}G;AeB_bS*UreXSL=t&bSqsN?vq-;cA{wpYr^w`j-lID=@VRa){1hk)23@fHp3F= zg!^}4gQDT%sBwK^N!rMVb7d95m9rtzHBNqgWUgim^!5Ml>8AWUkN3Uox985C%b~k3T6qwwikel zetQbCzzm&a!*JRYVqbDW=GBO@T{wDt6KIu$DC~j9ZsN>>#Q`F49-4>~4|e2Dn(uJ? zZ#8??_=QbOE`E-qFz998o-qdHy=kshf4r*5n`Ceg!|qPa3~cFp&Dzqo0e3vXkDR?Z z9aaKab-jIzyft;h?UDQ+9cUeEu;o$9vIGdCicUFW2!vrUxaD-x{#5dZ6@Y(HYkVUe)n*!q&LH=A+mBf>7TZwJM(hY-=5lnvNlk9$4;3J S#ak@?nOrY_&x`JnhyDjG=r0EV literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..daef597015daf9af35b0e84ef02d80d4a7fe9fba GIT binary patch literal 3199 zcmZ`+c{JPE`%VxVdnvk55wR9Ys3j3gm5z_4YNuLC1hF@wiDd|Ct)fAPingQFR%^9` zTEb9MBJE_R)y0z1%1}gWtNp9r-< zG0{J*1Jg&LjgTk|5`9`1g~p;VSQHxe?}D3)!f>R(Agqh^xqrzHIx~0(nH-HpA}JJ# z9>qW}iWH1QV=x#bN*}4OuX`||8xt2v_NVGb#;E>)_&*G5LJXcnj3yJKB4Ix;{R5(6 z$!2gk@&^g>UzP)T$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#sWWnN2&O);=N;}cX-@YQt9|qf;-)rk750upINtW+ zP1#?fC@W696kh=Fp{(Jq$VGR>EPXD*eQB1w)PjzHj`9NI+xGkv*d; zPw%m6^(>8aIg&Bqf`baH#8#Q-;i zPOb=-@VAe>M9Y`m8kS$`Zg;sHk{5aFw8~lEK(U3Zm!%$ruYW*riS*UZaKpuGrDAr9 z;Bz9;5`1m&MYZy~Xk@Egi^brh_Ig$A>P%KXnc$#@d;=W!toU{d1Er#!(&gH^GJh4& zBe5rn1viAJKg>MHNQhucq3iz+;C>)qnFXAzQy;Z zn*2U;1K(9O_{xU^ZgsX()G2!M)!%O{+;7LGbx))!B2@+S;cT}7F+W;S(TeO-4y$fTgt$0hcI-5z~ z_G^H?g3aY0E++d}zxQq3wCdQ-RM4dQF~eim`|G{I1rku@oSI6!6=yWd`33NmQK{nm zxxofp;BB8Q@1oVvdTiCC^yVR8NGp+N-_bty`_!V4W=0I*gl7M;6fictz8jRj*4iD~ zGF-CmckH2Sb6B+IQ$j3R;gg|qNnQu=+=?O%Vr7QtuUiZZ`)1!@3UJlKcUAI|Ip@d< z;GB?wz0H4W-!7Qw`ZCwSFDo1<#Y^gzhkr)#J6lSm&o(FTy+XoALs`35(d)^o_XdoT zs#`;^d4hM2=B~-%n`K>u{S7{Puw<9;te7ahxy!Ct?tYl=VE)|)VRF> literal 0 HcmV?d00001 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