Skip to content

Commit 7adfe77

Browse files
authored
try-catch startForeground inside notifyVpnStart (#6833)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1202552961248957/task/1211418384396819?focus=true ### Description In #6808 we bubbled up the `ForegroundServiceStartNotAllowedException` to notifyVpnStart function, when calling `startForeground` method. This didn't get rid of the crashes but was a bit of an improvement. This PR will try-catch the startForeground call and return the appropriate error so that the error path can be executed. The error path sends a pixel (m_vpn_ev_notify_start_failed_c/d) are expected to increase and will also stop the service showing the disabled notification. Which is a better UX ### Steps to test this PR Smoke test the VPN and AppTP
1 parent 59a1417 commit 7adfe77

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

app-tracking-protection/vpn-impl/src/main/java/com/duckduckgo/mobile/android/vpn/service/TrackerBlockingVpnService.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -710,12 +710,17 @@ class TrackerBlockingVpnService : VpnService(), CoroutineScope by MainScope(), V
710710
}
711711
}
712712

713-
ServiceCompat.startForeground(
714-
this,
715-
VPN_FOREGROUND_SERVICE_ID,
716-
VpnEnabledNotificationBuilder.buildVpnEnabledNotification(applicationContext, vpnNotification),
717-
FOREGROUND_SERVICE_TYPE_SPECIAL_USE,
718-
)
713+
try {
714+
ServiceCompat.startForeground(
715+
this,
716+
VPN_FOREGROUND_SERVICE_ID,
717+
VpnEnabledNotificationBuilder.buildVpnEnabledNotification(applicationContext, vpnNotification),
718+
FOREGROUND_SERVICE_TYPE_SPECIAL_USE,
719+
)
720+
} catch (_: Throwable) {
721+
// signal the error
722+
return false
723+
}
719724

720725
return vpnNotification != emptyNotification
721726
}

0 commit comments

Comments
 (0)