From 3b34f68b0ed4395dba505876120c684cba470257 Mon Sep 17 00:00:00 2001 From: MCleinman <9295855+mcleinman@users.noreply.github.com> Date: Tue, 12 Dec 2023 10:22:08 -0800 Subject: [PATCH] VPN-5900 (part 2): Don't send Android daemon metrics when switching server (#8793) * vpn-5900 fix android daemon --- .../mozilla/firefox/vpn/daemon/VPNService.kt | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/android/daemon/src/main/java/org/mozilla/firefox/vpn/daemon/VPNService.kt b/android/daemon/src/main/java/org/mozilla/firefox/vpn/daemon/VPNService.kt index 3d129b33c2..400c33377b 100644 --- a/android/daemon/src/main/java/org/mozilla/firefox/vpn/daemon/VPNService.kt +++ b/android/daemon/src/main/java/org/mozilla/firefox/vpn/daemon/VPNService.kt @@ -46,7 +46,7 @@ class VPNService : android.net.VpnService() { override fun onTick(millisUntilFinished: Long) {} override fun onFinish() { Log.i(tag, "Sending daemon_timer ping") - if (isSuperDooperMetricsActive) { + if (shouldRecordMetrics) { Pings.daemonsession.submit( Pings.daemonsessionReasonCodes.daemonTimer, ) @@ -60,6 +60,17 @@ class VPNService : android.net.VpnService() { return this.mConfig?.optBoolean("isSuperDooperFeatureActive", false) ?: false } + private val isChangingServers: Boolean + get() { + // could be user choosing new server or silent switching + return (this.mConfig?.optInt("reason") ?: 0) == 1 + } + + private val shouldRecordMetrics: Boolean + get() { + return isSuperDooperMetricsActive && !isChangingServers + } + private val isUsingShortTimerSessionPing: Boolean get() { return this.mConfig?.optBoolean("isUsingShortTimerSessionPing", false) ?: false @@ -338,7 +349,7 @@ class VPNService : android.net.VpnService() { Log.i(tag, "Setting Glean debug tag for daemon.") Glean.setDebugViewTag(gleanTag) } - if (isSuperDooperMetricsActive) { + if (shouldRecordMetrics) { val installationIdString = json.getString("installationId") installationIdString?.let { try { @@ -421,7 +432,7 @@ class VPNService : android.net.VpnService() { // Clear the notification message, so the content // is not "disconnected" in case we connect from a non-client. CannedNotification(mConfig)?.let { mNotificationHandler.hide(it) } - if (isSuperDooperMetricsActive) { + if (shouldRecordMetrics) { Session.daemonSessionEnd.set() Pings.daemonsession.submit( Pings.daemonsessionReasonCodes.daemonEnd,