Repository navigation
fix(client/android): check VPN consent in VpnServiceStarter and harden foreground notification - #2892
sentry[bot] wants to merge 2 commits into
Conversation
…n foreground notification
|
| if (VpnService.prepare(context) != null) { | ||
| tunnelStore.setTunnelStatus(VpnTunnelService.TunnelStatus.DISCONNECTED); | ||
| return; | ||
| } |
There was a problem hiding this comment.
The new failure paths have no regression tests. Existing tests only cover saved tunnel data, so a later change could bring back the reported startup crash without a test failing.
Add tests showing that missing VPN consent clears the saved status without starting the service, missing launcher or icon resources still allow a notification, and a failed foreground start stops auto-connect.
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…round notification
Fixes Sentry issue
OUTLINE-CLIENTS-NE2GP(RemoteServiceException$ForegroundServiceDidNotStartInTimeException: Context.startForegroundService() did not then call Service.startForeground()).Problem
VpnServiceStartercalledcontext.startForegroundService()whenevertunnelStore.getTunnelStatus()wasCONNECTED. When the process was previously killed in the background (e.g. under low-memory conditions), that status was often stale and the device frequently no longer had VPN consent (e.g. another VPN app became active, consent was revoked, or the app ran under a secondary Android profile).startForegroundService()is called, Android requires the service to callstartForeground()within a strict deadline. Because VPN consent requires UI,VpnTunnelServicecould not prepare the VPN and aborted auto-connect before callingstartForeground(), crashing the app.small_icon) would failstartForeground()and trigger the same crash.Changes
VpnServiceStarter, checkVpnService.prepare(context) == nullbefore launching the service. If consent is absent, mark the tunnel status asDISCONNECTEDand exit early so the service is never started.VpnTunnelService, do not throw if the launcher intent cannot be resolved (falls back to a notification without a tap action), and fall back toandroid.R.drawable.ic_lock_lockifsmall_iconcannot be resolved.VpnTunnelService.startForegroundWithNotification(), log the full exception on failure and returnfalse. InstartLastSuccessfulTunnel(), abort cleanly if moving to the foreground fails.AutoStartPolicyso it can be covered by local JVM unit tests (AutoStartPolicyTest, 9 tests). Added instrumented tests (VpnServiceStarterTest,VpnTunnelServiceNotificationTest) covering boot without consent, missing launcher intent, and missing small icon fallback.Fixes OUTLINE-CLIENTS-NE2GP
@sentry <feedback>: Autofix iterates on these changes@sentry stop iterating: Autofix stops iterating on this runThis PR was automatically generated by Sentry at no cost. You can adjust this setting at any time.