Skip to content

feat(core): back button event on Android, closes #8142 - #9

Open
tomerqodo wants to merge 11 commits into
sentry_only-issues-20260113-augment-codex-sentry_base_featcore_back_button_event_on_android_closes_8142_pr30from
sentry_only-issues-20260113-augment-codex-sentry_head_featcore_back_button_event_on_android_closes_8142_pr30
Open

tomerqodo wants to merge 11 commits into
sentry_only-issues-20260113-augment-codex-sentry_base_featcore_back_button_event_on_android_closes_8142_pr30from
sentry_only-issues-20260113-augment-codex-sentry_head_featcore_back_button_event_on_android_closes_8142_pr30

Conversation

@tomerqodo

Copy link
Copy Markdown

Benchmark PR from qodo-benchmark#30

Comment on lines +31 to +41
if (this@AppPlugin.webView?.canGoBack() == true) {
this@AppPlugin.webView!!.goBack()
} else {
this.isEnabled = false
this@AppPlugin.activity.onBackPressed()
this.isEnabled = true
}
} else {
val data = JSObject().apply {
put("canGoBack", this@AppPlugin.webView?.canGoBack() ?: false)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The logic in the Android back button handler is inverted. It performs default navigation when a listener is registered and tries to trigger an event when no listener exists.
Severity: CRITICAL

Suggested Fix

Invert the conditional logic in the handleOnBackPressed method. The block that calls trigger(BACK_BUTTON_EVENT, data) should be executed when hasListener(BACK_BUTTON_EVENT) is true, and the default navigation logic should be moved to the else block.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.

Location: crates/tauri/mobile/android/src/main/java/app/tauri/AppPlugin.kt#L30-L41

Potential issue: The conditional logic in the `handleOnBackPressed` method is inverted.
The code checks `if (hasListener(BACK_BUTTON_EVENT))`, and if true (meaning listeners
are registered), it proceeds to execute the default back navigation behavior instead of
notifying the listeners. Conversely, in the `else` block where no listeners are
registered, it attempts to call `trigger()` to notify listeners, which does nothing.
This effectively breaks the intended functionality of the back button event listener on
Android, as registered listeners will never be called, and the default behavior will not
work when no listener is present.

Did we get this right? 👍 / 👎 to inform future reviews.

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.

2 participants