From 88748fd4b2dd8263d7353cf08e80a4476d74d221 Mon Sep 17 00:00:00 2001 From: jigar-f <132374182+jigar-f@users.noreply.github.com> Date: Tue, 5 Mar 2024 08:08:51 +0530 Subject: [PATCH] Bandwidth fix (#991) * Updates to LanternHttpClient and integrate MockK (#900) * Add Kotlin-based LanternHttpClient * Kotlin-based LanternHttpClient * Kotlin-based LanternHttpClient * Updates to LanternHttpClient * Add tests * Add tests * Add LanternHttpClientTest * formatting * Add ProUser data class * Formatting --------- Co-authored-by: atavism * Use Plausible for app analytics (#929) * Remove datadog * Update CI * update Makefile * update Makefile * remove datadog directory * Use Sentry for crash reporting (#927) * update Makefile * Add back Sentry for crash reporting * remove datadog from gradle config * Add plausible * integrate plausible analytics * integrate plausible analytics * track when ads are shown * track when ads are shown * add Plausible class * track when Replica content is viewed * track searches and uploads * Formatting * Track when ads fail to load as well * updated translations... * Don't switch languages that we don't support. (#944) * Google Pay updates (#948) * play payments updates * Add check isPlayVersion * skip play check * Add play checkout page * Add play checkout page * clean-ups * show dialog after successful payment * clean-ups, show loading spinner submitting payment * Add plan step and enter email text * Add Flexible * show price summary * Add com.android.vending.BILLING permission * Add logging * Add logging * Remove use of ProgressDialog and some clean-ups * Remove use of ProgressDialog and some clean-ups * Update Google Play billing client * Add liblantern-all * Update go.sum * Update golang.org/x/mobile/cmd/gomobile * run go mod tidy * Update go.sum * set GOPRIVATE var * formatting * code review updates * Fix typo, do not append currency in-app billing * fix typo, run ktlint * fix typo, run ktlint * Add setState and do not push page do pop * Simplify method and fix error message. * Removed billing-ktx since its not needed. --------- Co-authored-by: Jigar-f * Updated to the latest flashlight with go 1.19 support * update branch name * update branch name * use GITHUB_TOKEN * use GITHUB_TOKEN * Get build working with latest flashlight * update golang.org/x/mobile (#958) * update branch name * update branch name * use GITHUB_TOKEN * use GITHUB_TOKEN * update golang.org/x/mobile * update golang.org/x/mobile * Test building release * run go mod tidy * fix email validation on play checkout page * fix email validation on play checkout page * Update how release workflow is triggered * rename branch to android-legacy to trigger release workflow * Ads update (#953) * Added artificial delay while connecting VPN. * Remove static delay. * fix typo and do not show delay if user does not have permissions. * don't set changesNotSentForReview * initialize plausible sdk in application class (#959) * initialize Plausible after Lantern starts * Make accountInitDialog nullable (#960) * set accountInitDialog to null instead of lateinit * remove unused imports * Update to latest flashlight * fixed missing device linking functionality (#965) * bumped flashlight to version that properly notifies on geo updates * Update PlausibleClient to check files for cached events exist (#966) * Date Fix (#967) * Refresh user data after purchase request. * Refactor code and Hide date is vaules comes null or 0 from server. * Fixed merge conflicts. * Added Ads delay changes in go model. * Downgrade to flashlight 7.6.19 due to IOS issue * Make changes to run on Android & IOS. * Implemented google ads. * Updated Google Ads sdk. * Update ipproxy * check for null * check for null * remove changesNotSentForReview since its causing an error * Fix Expecting a condition in parentheses * add pathdb dependency * Updating to latest flashlight supporting go 1.20 * fix compile error * Bump go version * bump go.mod version * do not check go version in Makefile * Test building Android installer * quick test * Remove more references to datadog * update flashlight * ipproxy updates * Android crash fixes (#975) * Refactor reportIssue code on Kotlin and flutter. * Upgrade webview and fix onStartCommand issue * change Device linking API. * Updated error message. * Upgrade stripe and updated error object to multiple place * Revert back stripe version. * Added try catch and added formatter * Update dnsgrab * protect connections again * Change null condition on payment method. * use working ipproxy * revert CI changes * Update ipproxy again * run go mod tidy, update protected * Update ipproxy * Update ipproxy * update ipproxy, restore DialUDP * Update ipproxy * Added GDPR consent and updated google ads plugin. (#978) * Update ipproxy and flashlight, use Go 1.21 (#970) * Update ipproxy * Fix Expecting a condition in parentheses * add pathdb dependency * Test building Android installer * quick test * update flashlight * ipproxy updates * Update dnsgrab * protect connections again * use working ipproxy * revert CI changes * Update ipproxy again * run go mod tidy, update protected * Update ipproxy * Update ipproxy * update ipproxy, restore DialUDP * Update ipproxy * use go version from go.mod * Update ipproxy * Update flashlight to v7.6.42 * update flashlight * Use ios specific flashlight version and fix proto duplicate issue. * use flashlight v7.6.43 again * use flashlight v7.6.44 and restore protobuf messages * Payment changes (#982) * Added icon payload in plansV3 API. * Removed plans API. * Updated API payload and use Network images. * Update vpn.proto * Added search feature in split tunneling screen. (#980) * Added search feature in split tunneling screen. * Made UI changes to split tunneling screen. * Fix issue with update ui while search * Added padding to bottom. * fix showError call in report issue * Updates to Plausible client (#981) * updates to Plausible client * do not track when user switches vpn on/off * update domain for now * override X-Forwarded-For header with the correct IP address of the client * use magnet link when tracking Replica page views * Add comment * Add comment * revert domain to android.lantern.io * fix tests * Upgrade sentry * Remove changes to protect connections (#986) * Update sentry * remove changes to protect connections * upgrade flashlight to v7.6.47 * update release workflow branch * update CI to install protoc-gen-go * set default selected tab to vpn/home screen * use ANDROID_ARCH=all in make android-release * Migrate to go-llsqlite/crawshaw (#987) * Migrate to go-llsqlite/crawshaw * Fix error fetching metadata for object info response * Update liblantern-all.aar * Minor fixes * Update flashlight * Updated flashlight and pods * Use http client that goes uses domain fronting and proxying * update flashlight * Fix missing method error in invokeMethod getlantern/engineering#1193 * do not use BuildContext across async boundaries * Remove secret and use env file (#990) * Update .gitignore * Added env file support. * updated file name and fix ios issue. * updated emoji picker. * merge latest * Do not show bandwidth if user is pro and some other changes to bandwidth. * If service is not running update status. * fixed merged conflicts. --------- Co-authored-by: atavism Co-authored-by: atavism Co-authored-by: git Co-authored-by: Adam Fisk Co-authored-by: atavism Co-authored-by: Eli Yukelzon Co-authored-by: Matt Joiner --- .../getlantern/mobilesdk/model/SessionManager.kt | 3 ++- .../src/main/kotlin/io/lantern/model/VpnModel.kt | 15 +++++++++++++++ .../kotlin/org/getlantern/lantern/MainActivity.kt | 8 ++++++-- internalsdk/vpn_model.go | 14 ++++++++++++++ lib/vpn/vpn_bandwidth.dart | 2 ++ lib/vpn/vpn_switch.dart | 1 + lib/vpn/vpn_tab.dart | 4 ++-- 7 files changed, 42 insertions(+), 5 deletions(-) diff --git a/android/app/src/main/java/org/getlantern/mobilesdk/model/SessionManager.kt b/android/app/src/main/java/org/getlantern/mobilesdk/model/SessionManager.kt index 716ad96b5..a798b8253 100644 --- a/android/app/src/main/java/org/getlantern/mobilesdk/model/SessionManager.kt +++ b/android/app/src/main/java/org/getlantern/mobilesdk/model/SessionManager.kt @@ -367,8 +367,9 @@ abstract class SessionManager(application: Application) : Session { override fun bandwidthUpdate(percent: Long, remaining: Long, allowed: Long, ttlSeconds: Long) { val b = Bandwidth(percent, remaining, allowed, ttlSeconds) + Logger.debug("bandwidth", b.toString()) saveLatestBandwidth(b) - EventBus.getDefault().post(b) + EventBus.getDefault().postSticky(b) } fun setSurveyLinkOpened(url: String?) { diff --git a/android/app/src/main/kotlin/io/lantern/model/VpnModel.kt b/android/app/src/main/kotlin/io/lantern/model/VpnModel.kt index bc8aa57df..f7ebcabc0 100644 --- a/android/app/src/main/kotlin/io/lantern/model/VpnModel.kt +++ b/android/app/src/main/kotlin/io/lantern/model/VpnModel.kt @@ -4,6 +4,8 @@ import internalsdk.VPNManager import internalsdk.VPNModel import io.flutter.embedding.engine.FlutterEngine import io.lantern.model.dbadapter.DBAdapter +import org.getlantern.lantern.model.Bandwidth +import org.getlantern.mobilesdk.Logger class VpnModel( flutterEngine: FlutterEngine, @@ -39,4 +41,17 @@ class VpnModel( fun updateStatus(vpnOn: Boolean) { model.saveVPNStatus(if (vpnOn) "connected" else "disconnected") } + + fun updateBandwidth(bandwidth: Bandwidth) { + try { + model.updateBandwidth( + bandwidth.percent, + bandwidth.remaining, + bandwidth.allowed, + bandwidth.ttlSeconds, + ) + } catch (t: Throwable) { + Logger.error("VPNModel","Error updating bandwidth", t) + } + } } diff --git a/android/app/src/main/kotlin/org/getlantern/lantern/MainActivity.kt b/android/app/src/main/kotlin/org/getlantern/lantern/MainActivity.kt index 03a2671d0..83f8846d6 100644 --- a/android/app/src/main/kotlin/org/getlantern/lantern/MainActivity.kt +++ b/android/app/src/main/kotlin/org/getlantern/lantern/MainActivity.kt @@ -176,9 +176,7 @@ class MainActivity : FlutterActivity(), MethodChannel.MethodCallHandler, override fun onResume() { val start = System.currentTimeMillis() - super.onResume() - Logger.debug(TAG, "super.onResume() finished at ${System.currentTimeMillis() - start}") val isServiceRunning = Utils.isServiceRunning(activity, LanternVpnService::class.java) if (vpnModel.isConnectedToVpn() && !isServiceRunning) { @@ -292,6 +290,12 @@ class MainActivity : FlutterActivity(), MethodChannel.MethodCallHandler, ) } + @Subscribe(threadMode = ThreadMode.MAIN) + fun bandwidthUpdated(bandwidth: Bandwidth) { + Logger.debug("bandwidth updated", bandwidth.toString()) + vpnModel.updateBandwidth(bandwidth) + } + private fun updateUserData() { lanternClient.userData( object : ProUserCallback { diff --git a/internalsdk/vpn_model.go b/internalsdk/vpn_model.go index de541013b..d9acbcd6a 100644 --- a/internalsdk/vpn_model.go +++ b/internalsdk/vpn_model.go @@ -2,6 +2,7 @@ package internalsdk import ( "github.com/getlantern/errors" + "github.com/getlantern/lantern-client/internalsdk/protos" "github.com/getlantern/pathdb" "github.com/getlantern/pathdb/minisql" ) @@ -30,6 +31,7 @@ func NewVPNModel(mdb minisql.DB) (*VPNModel, error) { } model := &VPNModel{baseModel: base} model.baseModel.doInvokeMethod = model.doInvokeMethod + base.db.RegisterType(5000, &protos.Bandwidth{}) return model, model.initVpnModel() } @@ -100,6 +102,18 @@ func (m *VPNModel) SaveVPNStatus(status string) error { }) } +func (m *VPNModel) UpdateBandwidth(percent int64, remaining int64, allowedint int64, ttlSeconds int64) error { + return pathdb.Mutate(m.db, func(tx pathdb.TX) error { + bandwidth := &protos.Bandwidth{ + Percent: percent, + Remaining: remaining, + Allowed: allowedint, + TtlSeconds: ttlSeconds, + } + return pathdb.Put(tx, pathBandwidth, bandwidth, "") + }) +} + func (m *VPNModel) GetVPNStatus() (string, error) { return pathdb.Get[string](m.db, pathVPNStatus) } diff --git a/lib/vpn/vpn_bandwidth.dart b/lib/vpn/vpn_bandwidth.dart index b37f1cd56..1cb8ca2da 100644 --- a/lib/vpn/vpn_bandwidth.dart +++ b/lib/vpn/vpn_bandwidth.dart @@ -1,6 +1,8 @@ import 'package:lantern/vpn/vpn.dart'; class VPNBandwidth extends StatelessWidget { + const VPNBandwidth({super.key}); + @override Widget build(BuildContext context) { return vpnModel diff --git a/lib/vpn/vpn_switch.dart b/lib/vpn/vpn_switch.dart index bbe44ab07..2c68eaac7 100644 --- a/lib/vpn/vpn_switch.dart +++ b/lib/vpn/vpn_switch.dart @@ -1,3 +1,4 @@ +import 'package:lantern/ad_helper.dart'; import 'package:lantern/common/common.dart'; import 'package:lantern/common/common_desktop.dart'; import 'package:lantern/vpn/vpn.dart'; diff --git a/lib/vpn/vpn_tab.dart b/lib/vpn/vpn_tab.dart index b7209f000..6f0362638 100644 --- a/lib/vpn/vpn_tab.dart +++ b/lib/vpn/vpn_tab.dart @@ -49,8 +49,8 @@ class VPNTab extends StatelessWidget { if(Platform.isAndroid)...{ const CDivider(height: 32.0), SplitTunnelingWidget(), - // Not sure about this - VPNBandwidth(), + if(!proUser) + const VPNBandwidth(), } ], ),