Skip to content

Postpone fallback warning notification when VpnWarningActivity starts successfully - #35

Merged
DisabledAbel merged 3 commits into
mainfrom
jules-6792269727374199170-0a3c5d18
Aug 12, 2026
Merged

Postpone fallback warning notification when VpnWarningActivity starts successfully#35
DisabledAbel merged 3 commits into
mainfrom
jules-6792269727374199170-0a3c5d18

Conversation

@DisabledAbel

@DisabledAbel DisabledAbel commented Aug 12, 2026

Copy link
Copy Markdown
Owner

This change resolves the issue where the on-screen warning pop-up (VpnWarningActivity) triggers when a protected application is opened without VPN, but also posts/displays an unnecessary notification that is immediately cancelled on entry.

By postponing the fallback notification's delivery by 1000ms inside TunnelGuardVpnService, we verify if the VpnWarningActivity has successfully launched in the foreground and consumed the 'pendingWarningId'. If so, we completely skip posting the fallback notification, preventing redundant flashes, sounds, and icons on TV and mobile screens. If the direct launch is silently blocked (e.g., due to background activity limits), the fallback notification is successfully posted as intended after the delay.


PR created automatically by Jules for task 6792269727374199170 started by @DisabledAbel

Summary by CodeRabbit

  • Bug Fixes
    • Improved VPN warning handling by delaying fallback notifications briefly after attempting to open the warning screen.
    • Prevented redundant notifications when the warning screen launches successfully.
    • Preserved high-priority alerts and full-screen warning behavior when needed.

…ns when VpnWarningActivity starts successfully
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@DisabledAbel, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 16816a3d-8f64-413e-9372-0c3e52e1ca18

📥 Commits

Reviewing files that changed from the base of the PR and between 4df59a7 and 2c3612b.

📒 Files selected for processing (3)
  • app/src/main/java/com/tunnelguard/app/TunnelGuardVpnService.kt
  • app/src/main/java/com/tunnelguard/app/VpnWarningActivity.kt
  • app/src/test/java/com/tunnelguard/app/TunnelGuardVpnServiceWarningTest.kt
📝 Walkthrough

Walkthrough

The VPN warning fallback now waits one second after attempting to launch VpnWarningActivity. It posts the notification only if the warning remains pending.

Changes

VPN warning fallback

Layer / File(s) Summary
Delayed fallback notification
app/src/main/java/com/tunnelguard/app/TunnelGuardVpnService.kt
The service delays fallback notification creation and posting. It skips the notification when the warning activity launches successfully.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the delayed fallback notification when VpnWarningActivity starts successfully.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/com/tunnelguard/app/TunnelGuardVpnService.kt`:
- Around line 236-285: Add a shared warning lock accessible to both
TunnelGuardVpnService and VpnWarningActivity, and synchronize the fallback block
around the pendingWarningId check through manager.notify(1002,
warningNotification). Update the activity’s matching-ID validation, clearing of
pendingWarningId, and cancellation of notification 1002 to use the same lock,
preserving the existing behavior while preventing cancellation and fallback
posting from interleaving.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 57c81de0-4138-4913-ac96-f13e343e275c

📥 Commits

Reviewing files that changed from the base of the PR and between 93d331a and 4df59a7.

📒 Files selected for processing (1)
  • app/src/main/java/com/tunnelguard/app/TunnelGuardVpnService.kt

Comment on lines +236 to +285
serviceScope.launch {
delay(1000)
if (pendingWarningId == warningId) {
config.addLog("VpnWarningActivity did not launch in time. Posting fallback warning notification.")
val options = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
android.app.ActivityOptions.makeBasic().setPendingIntentCreatorBackgroundActivityStartMode(
android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
).toBundle()
} else {
null
}

val pendingIntent = PendingIntent.getActivity(
this@TunnelGuardVpnService,
1002,
warningIntent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT,
options
)

var appLabel = currentApp
try {
val pm = packageManager
val appInfo = pm.getApplicationInfo(currentApp, 0)
appLabel = pm.getApplicationLabel(appInfo).toString()
} catch (e: Exception) {
// Ignore
}

val warningNotificationBuilder = NotificationCompat.Builder(this@TunnelGuardVpnService, ALERT_CHANNEL_ID)
.setContentTitle("Security Warning")
.setContentText("$appLabel opened without an active VPN connection!")
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_ALARM)
.setAutoCancel(true)
.setContentIntent(pendingIntent)

// Only call setFullScreenIntent when permission is available according to NotificationManagerCompat
val managerCompat = androidx.core.app.NotificationManagerCompat.from(this@TunnelGuardVpnService)
if (managerCompat.canUseFullScreenIntent()) {
warningNotificationBuilder.setFullScreenIntent(pendingIntent, true)
}

val warningNotification = warningNotificationBuilder.build()
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
manager.notify(1002, warningNotification)
} else {
config.addLog("VpnWarningActivity launched successfully. Skipping fallback notification.")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Synchronize warning acknowledgement with fallback posting.

@Volatile makes pendingWarningId visible. It does not make the check at Line 238 and manager.notify at Line 282 atomic.

VpnWarningActivity.kt:37-45 can clear the matching ID and cancel notification 1002 after this check but before this notification post. In that order, the cancellation occurs first and the fallback notification remains posted.

Use one shared warning lock in both files. Hold it while the activity validates and clears the ID and cancels notification 1002. Hold the same lock while this coroutine checks the ID and posts the notification.

🧰 Tools
🪛 detekt (1.23.8)

[warning] 261-261: The caught exception is swallowed. The original exception could be lost.

(detekt.exceptions.SwallowedException)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/tunnelguard/app/TunnelGuardVpnService.kt` around lines
236 - 285, Add a shared warning lock accessible to both TunnelGuardVpnService
and VpnWarningActivity, and synchronize the fallback block around the
pendingWarningId check through manager.notify(1002, warningNotification). Update
the activity’s matching-ID validation, clearing of pendingWarningId, and
cancellation of notification 1002 to use the same lock, preserving the existing
behavior while preventing cancellation and fallback posting from interleaving.

@DisabledAbel

Copy link
Copy Markdown
Owner Author

@coderabbitai do unit tests

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '=== Candidate files ==='
fd -t f . | rg '(^|/)(TunnelGuardVpnService|VpnWarningActivity).*\.(kt|java)$|(^|/).*(Test|Spec)\.(kt|java)$|(^|/)(build\.gradle(\.kts)?|settings\.gradle(\.kts)?)$'

printf '%s\n' '=== Service outline ==='
ast-grep outline app/src/main/java/com/tunnelguard/app/TunnelGuardVpnService.kt --items all --view expanded || true

printf '%s\n' '=== Test declarations and framework usage ==='
rg -n -C 3 --glob '*.{kt,java,kts,gradle}' \
  'org\.junit|kotlin\.test|MockK|Mockito|Robolectric|androidx\.test|testImplementation|androidTestImplementation' \
  .

Length of output: 30206


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '=== Warning-flow references ==='
rg -n -C 8 --glob '*.{kt,java}' \
  'pendingWarningId|VpnWarningActivity|NotificationCompat|Handler|postDelayed|warning' \
  app/src

printf '%s\n' '=== Warning activity outline ==='
warning_activity="$(fd -t f -a '^VpnWarningActivity\.(kt|java)$' app/src | head -n 1)"
if [ -n "$warning_activity" ]; then
  ast-grep outline "$warning_activity" --items all --view expanded
fi

Length of output: 54543


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '=== Existing warning tests ==='
sed -n '1,310p' app/src/test/java/com/tunnelguard/app/TunnelGuardVpnServiceWarningTest.kt

printf '%s\n' '=== Production fallback flow ==='
sed -n '86,120p;200,305p' app/src/main/java/com/tunnelguard/app/TunnelGuardVpnService.kt

printf '%s\n' '=== Pull request file changes ==='
gh pr view 35 --repo DisabledAbel/TunnelGuard --json files --jq '.files[] | "\(.path): +\(.additions) -\(.deletions)"'

Length of output: 19656


@DisabledAbel Unit tests are already included in this PR.

TunnelGuardVpnServiceWarningTest covers these cases:

  • The activity acknowledges the warning. The fallback is skipped.
  • The activity does not acknowledge the warning. The fallback remains eligible.
  • A stale warning ID does not post a fallback.
  • Warning acknowledgement uses warningLock.
  • A stale activity launch does not clear the current warning.
  • A replaced warning ID does not allow the earlier fallback.

The tests validate the fallback decision logic. They do not execute the 1000 ms coroutine delay or verify NotificationManager.notify, because those operations are embedded in the monitoring coroutine.

You are interacting with an AI system.

@DisabledAbel
DisabledAbel merged commit d9143c8 into main Aug 12, 2026
3 checks passed
@DisabledAbel
DisabledAbel deleted the jules-6792269727374199170-0a3c5d18 branch August 12, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant