Skip to content

Commit

Permalink
Add pixels for snooze (#3897)
Browse files Browse the repository at this point in the history
<!--
Note: This checklist is a reminder of our shared engineering
expectations.
The items in Bold are required
If your PR involves UI changes:
1. Upload screenshots or screencasts that illustrate the changes before
/ after
2. Add them under the UI changes section (feel free to add more columns
if needed)
If your PR does not involve UI changes, you can remove the **UI
changes** section

At a minimum, make sure your changes are tested in API 23 and one of the
more recent API levels available.
-->

Task/Issue URL: https://app.asana.com/0/0/1205947647495715/f

### Description
See attached task description

### Steps to test this PR
https://app.asana.com/0/0/1206000100414551/f
  • Loading branch information
karlenDimla authored Nov 23, 2023
1 parent 35d24a1 commit 0ab9e00
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
android:exported="false"
android:process=":vpn">
<intent-filter>
<action android:name="com.duckduckgo.vpn.ACTION_VPN_ENABLE" />
<action android:name="com.duckduckgo.vpn.ACTION_VPN_SNOOZE_END" />
<action android:name="com.duckduckgo.vpn.ACTION_VPN_DISABLE" />
<action android:name="com.duckduckgo.vpn.ACTION_VPN_SNOOZE" />
</intent-filter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,5 +213,10 @@ enum class DeviceShieldPixelNames(override val pixelName: String, val enqueue: B
REPORT_NOTIFY_START_FAILURE_DAILY("m_vpn_ev_notify_start_failed_c"),

REPORT_TLS_PARSING_ERROR_CODE_DAILY("m_atp_tls_parsing_error_code_%d_d"),

VPN_SNOOZE_STARTED("m_vpn_ev_snooze_started_c", enqueue = true),
VPN_SNOOZE_STARTED_DAILY("m_vpn_ev_snooze_started_d", enqueue = true),
VPN_SNOOZE_ENDED("m_vpn_ev_snooze_ended_c", enqueue = true),
VPN_SNOOZE_ENDED_DAILY("m_vpn_ev_snooze_ended_d", enqueue = true),
;
}
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ interface DeviceShieldPixels {
fun notifyStartFailed()

fun reportTLSParsingError(errorCode: Int)

fun reportVpnSnoozedStarted()
fun reportVpnSnoozedEnded()
}

@ContributesBinding(AppScope::class)
Expand Down Expand Up @@ -734,6 +737,16 @@ class RealDeviceShieldPixels @Inject constructor(
firePixel(DeviceShieldPixelNames.ATP_REPORT_DEVICE_CONNECTIVITY_ERROR)
}

override fun reportVpnSnoozedStarted() {
tryToFireDailyPixel(DeviceShieldPixelNames.VPN_SNOOZE_STARTED_DAILY)
firePixel(DeviceShieldPixelNames.VPN_SNOOZE_STARTED)
}

override fun reportVpnSnoozedEnded() {
tryToFireDailyPixel(DeviceShieldPixelNames.VPN_SNOOZE_ENDED_DAILY)
firePixel(DeviceShieldPixelNames.VPN_SNOOZE_ENDED)
}

private fun suddenKill() {
firePixel(DeviceShieldPixelNames.ATP_KILLED)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.ReceiverScope
import com.duckduckgo.mobile.android.vpn.Vpn
import com.duckduckgo.mobile.android.vpn.pixels.DeviceShieldPixels
import dagger.android.AndroidInjection
import java.util.concurrent.TimeUnit
import javax.inject.Inject
Expand All @@ -41,6 +42,8 @@ class VpnActionReceiver : BroadcastReceiver() {

@Inject lateinit var context: Context

@Inject lateinit var deviceShieldPixels: DeviceShieldPixels

override fun onReceive(
context: Context,
intent: Intent,
Expand All @@ -51,9 +54,10 @@ class VpnActionReceiver : BroadcastReceiver() {
val pendingResult = goAsync()

when (intent.action) {
ACTION_VPN_ENABLE -> {
ACTION_VPN_SNOOZE_END -> {
logcat { "Entire VPN will be enabled because the user asked it" }
goAsync(pendingResult) {
deviceShieldPixels.reportVpnSnoozedEnded()
vpn.start()
}
}
Expand All @@ -68,6 +72,7 @@ class VpnActionReceiver : BroadcastReceiver() {
ACTION_VPN_SNOOZE -> {
logcat { "Entire VPN will snooze because the user asked it" }
goAsync(pendingResult) {
deviceShieldPixels.reportVpnSnoozedStarted()
snoozeAndScheduleWakeUp()
}
}
Expand All @@ -87,7 +92,7 @@ class VpnActionReceiver : BroadcastReceiver() {
context,
0,
Intent(context, VpnActionReceiver::class.java).apply {
action = ACTION_VPN_ENABLE
action = ACTION_VPN_SNOOZE_END
},
PendingIntent.FLAG_IMMUTABLE,
)
Expand All @@ -102,7 +107,7 @@ class VpnActionReceiver : BroadcastReceiver() {
}

companion object {
internal const val ACTION_VPN_ENABLE = "com.duckduckgo.vpn.ACTION_VPN_ENABLE"
internal const val ACTION_VPN_SNOOZE_END = "com.duckduckgo.vpn.ACTION_VPN_SNOOZE_END"
internal const val ACTION_VPN_DISABLE = "com.duckduckgo.vpn.ACTION_VPN_DISABLE"
internal const val ACTION_VPN_SNOOZE = "com.duckduckgo.vpn.ACTION_VPN_SNOOZE"
private val DEFAULT_SNOOZE_LENGTH_IN_MILLIS = TimeUnit.MINUTES.toMillis(20)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
android:process=":vpn">
<intent-filter>
<action android:name="com.duckduckgo.networkprotection.notification.ACTION_NETP_ENABLE" />
<action android:name="com.duckduckgo.vpn.ACTION_VPN_ENABLE" />
<action android:name="com.duckduckgo.vpn.ACTION_VPN_SNOOZE_CANCEL" />
</intent-filter>
</receiver>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RealNetPDisabledNotificationBuilder @Inject constructor(
context,
0,
Intent(context, NetPEnableReceiver::class.java).apply {
action = NetPEnableReceiver.ACTION_VPN_ENABLE
action = NetPEnableReceiver.ACTION_VPN_SNOOZE_CANCEL
},
PendingIntent.FLAG_IMMUTABLE,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.duckduckgo.di.scopes.ReceiverScope
import com.duckduckgo.mobile.android.vpn.Vpn
import com.duckduckgo.mobile.android.vpn.VpnFeaturesRegistry
import com.duckduckgo.networkprotection.impl.NetPVpnFeature
import com.duckduckgo.networkprotection.impl.pixels.NetworkProtectionPixels
import dagger.android.AndroidInjection
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
Expand All @@ -40,6 +41,8 @@ class NetPEnableReceiver : BroadcastReceiver() {

@Inject lateinit var vpn: Vpn

@Inject lateinit var pixels: NetworkProtectionPixels

override fun onReceive(
context: Context,
intent: Intent,
Expand All @@ -54,9 +57,10 @@ class NetPEnableReceiver : BroadcastReceiver() {
goAsync(pendingResult) {
vpnFeaturesRegistry.registerFeature(NetPVpnFeature.NETP_VPN)
}
} else if (intent.action == ACTION_VPN_ENABLE) {
} else if (intent.action == ACTION_VPN_SNOOZE_CANCEL) {
logcat { "Entire VPN will be enabled because the user asked it" }
goAsync(pendingResult) {
pixels.reportVpnSnoozedCanceled()
vpn.start()
}
} else {
Expand All @@ -67,7 +71,7 @@ class NetPEnableReceiver : BroadcastReceiver() {

companion object {
internal const val ACTION_NETP_ENABLE = "com.duckduckgo.networkprotection.notification.ACTION_NETP_ENABLE"
internal const val ACTION_VPN_ENABLE = "com.duckduckgo.vpn.ACTION_VPN_ENABLE"
internal const val ACTION_VPN_SNOOZE_CANCEL = "com.duckduckgo.vpn.ACTION_VPN_SNOOZE_CANCEL"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ enum class NetworkProtectionPixelNames(
NETP_TUNNEL_FAILURE_DAILY("m_netp_ev_tunnel_failure_d", enqueue = true),
NETP_TUNNEL_FAILURE("m_netp_ev_tunnel_failure_c", enqueue = true),
NETP_TUNNEL_FAILURE_RECOVERED("m_netp_ev_tunnel_failure_recovered_c", enqueue = true),
VPN_SNOOZE_CANCELED("m_vpn_ev_snooze_canceled_c", enqueue = true),
VPN_SNOOZE_CANCELED_DAILY("m_vpn_ev_snooze_canceled_d", enqueue = true),
}
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ interface NetworkProtectionPixels {
* Fires count pixel when a tunnel failure (handshake with egress) is recovered on its own before VPN is disabled
*/
fun reportTunnelFailureRecovered()
fun reportVpnSnoozedCanceled()
}

@ContributesBinding(AppScope::class)
Expand Down Expand Up @@ -540,6 +541,11 @@ class RealNetworkProtectionPixel @Inject constructor(
firePixel(NETP_TUNNEL_FAILURE_RECOVERED)
}

override fun reportVpnSnoozedCanceled() {
tryToFireDailyPixel(VPN_SNOOZE_CANCELED_DAILY)
firePixel(VPN_SNOOZE_CANCELED)
}

private fun firePixel(
p: NetworkProtectionPixelNames,
payload: Map<String, String> = emptyMap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class NetworkProtectionPixelNamesTest {
@Test
fun allNetworkProtectionPixelsShallBePrefixed() {
NetworkProtectionPixelNames.values().map { it.pixelName }.forEach { pixel ->
assertTrue(pixel.startsWith("m_netp"))
assertTrue(pixel.startsWith("m_netp") || pixel.startsWith("m_vpn"))
}
}
}

0 comments on commit 0ab9e00

Please sign in to comment.