Skip to content

chore(runway): cherry-pick fix: Android In-App Browser Crash#22269

Merged
joaoloureirop merged 1 commit intorelease/7.58.1from
cherry-pick-7-58-1-5c63946
Nov 6, 2025
Merged

chore(runway): cherry-pick fix: Android In-App Browser Crash#22269
joaoloureirop merged 1 commit intorelease/7.58.1from
cherry-pick-7-58-1-5c63946

Conversation

@runway-github
Copy link
Contributor

@runway-github runway-github bot commented Nov 6, 2025

Description

The app crashes on Android when users grant camera + microphone
permissions through the in-app browser (e.g., visiting
https://permission.site/).

Root Cause:
The WebView permission handling code had a fundamental architectural
flaw when multiple permissions (camera + microphone) were requested
simultaneously:
Old behavior: Showed separate dialogs for each permission (one for
camera, one for microphone)
Each dialog's "Allow" button independently called request.grant()
Android's WebView API only allows calling grant() or deny() once per
permission request
When the user clicked "Allow" on the second dialog → CRASH: "Either
grant() or deny() has been already called"

Solution:
Rewrote the permission handling logic in RNCWebChromeClient.java:
Changed permission handling to show ONE dialog for all permissions:

  • "Allow example.com to use your camera and microphone?"
  • Call grant() only once with all permissions together
  • Added error handling to prevent crashes in edge cases

Android build for this PR:
https://app.bitrise.io/build/560c02e8-611e-4bfd-a24c-34e69751c86b?tab=artifacts

PR to browser:
MetaMask/react-native-webview-mm#72

Changelog

CHANGELOG entry:null

Related issues

Fixes: #22162

Manual testing steps

Feature: Fix Android double permission bug on webview

  Scenario: App does not crash when user grant/deny camera + microphone permission
    Given user navigates to website https://permission.site in website

    When user select Camera + Microphone 
    Then user is able give/deny permission to Camera and Microphone without app crashing

Screenshots/Recordings

Before

Android Before
Android Before

After

Android After
Android After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the
    app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described
    in the ticket it closes and includes the necessary testing evidence such
    as recordings and or screenshots.

Note

Aggregates Android WebView camera/microphone permission flows into a single confirmation and safely grants once, wired via a Yarn patch to @metamask/react-native-webview.

  • Android WebView permissions:
    • Reset state at request start and consolidate multiple permission prompts into a single dialog (e.g., camera and microphone).
    • Map OS-level permissions to WebView resources and grant once (with try/catch) to avoid IllegalStateException.
    • Request missing system permissions as needed; clean up grantedPermissions/permissionRequest consistently.
  • Tooling/Deps:
    • Switch @metamask/react-native-webview@14.5.0 to a Yarn patch via .yarn/patches/@metamask-react-native-webview-*.patch and update yarn.lock.

Written by Cursor Bugbot for commit 712412c. This will update automatically on new commits. Configure here.


Co-authored-by: metamaskbot metamaskbot@users.noreply.github.com 5c63946

<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

The app crashes on Android when users grant **camera + microphone**
permissions through the in-app browser (e.g., visiting
https://permission.site/).

Root Cause:
The WebView permission handling code had a fundamental architectural
flaw when multiple permissions (camera + microphone) were requested
simultaneously:
Old behavior: Showed separate dialogs for each permission (one for
camera, one for microphone)
Each dialog's "Allow" button independently called request.grant()
Android's WebView API only allows calling grant() or deny() once per
permission request
When the user clicked "Allow" on the second dialog → CRASH: "Either
grant() or deny() has been already called"

Solution:
Rewrote the permission handling logic in RNCWebChromeClient.java:
Changed permission handling to show ONE dialog for all permissions:
- "Allow example.com to use your camera and microphone?"
- Call grant() only once with all permissions together
- Added error handling to prevent crashes in edge cases

Android build for this PR:
https://app.bitrise.io/build/560c02e8-611e-4bfd-a24c-34e69751c86b?tab=artifacts

PR to browser:
MetaMask/react-native-webview-mm#72

<!--
If this PR is not End-User-Facing and should not show up in the
CHANGELOG, you can choose to either:
1. Write `CHANGELOG entry: null`
2. Label with `no-changelog`

If this PR is End-User-Facing, please write a short User-Facing
description in the past tense like:
`CHANGELOG entry: Added a new tab for users to see their NFTs`
`CHANGELOG entry: Fixed a bug that was causing some NFTs to flicker`

(This helps the Release Engineer do their job more quickly and
accurately)
-->

CHANGELOG entry:null

Fixes: #22162

```gherkin
Feature: Fix Android double permission bug on webview

  Scenario: App does not crash when user grant/deny camera + microphone permission
    Given user navigates to website https://permission.site in website

    When user select Camera + Microphone
    Then user is able give/deny permission to Camera and Microphone without app crashing
```

<!-- If applicable, add screenshots and/or recordings to visualize the
before and after of your change. -->

Android Before
![Android
Before](https://github.com/user-attachments/assets/8e4ab52e-9464-47b6-90d5-2edc5fbfca2a)

Android After
![Android
After](https://github.com/user-attachments/assets/f0b28c3a-24cb-447e-bcff-585104109d47)

<!-- [screenshots/recordings] -->

- [x] I’ve followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Consolidates Android WebView permission flow into a single dialog with
a single grant call for multiple resources, adds error handling, and
delivers via a Yarn patch of @metamask/react-native-webview.
>
> - **Android WebView (`RNCWebChromeClient.java`)**:
> - Show a single confirmation dialog for multiple already-OS-granted
permissions with a combined message.
> - Aggregate requested resources and call `request.grant()` once; map
`CAMERA` → `RESOURCE_VIDEO_CAPTURE`, `RECORD_AUDIO` →
`RESOURCE_AUDIO_CAPTURE`, handle `RESOURCE_PROTECTED_MEDIA_ID`.
> - Reset state before handling requests; manage
`permissionRequest`/`grantedPermissions` lifecycle; only set
`permissionRequest` when system permissions must be requested.
> - Wrap `grant()` with `try/catch` to ignore `IllegalStateException`
and prevent duplicate grant/deny errors.
> - Minor UX: delay enabling the "Allow" button to avoid accidental
taps.
> - **Dependencies**:
> - Use Yarn patch for `@metamask/react-native-webview@14.5.0` via
`.yarn/patches/...`; update `package.json` and `yarn.lock`.
>
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
7396b7f. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: metamaskbot <metamaskbot@users.noreply.github.com>
@runway-github runway-github bot requested a review from a team as a code owner November 6, 2025 18:37
@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-bots Bot team (for MetaMask Bot, Runway Bot, etc.) label Nov 6, 2025
@github-actions github-actions bot added the size-M label Nov 6, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 6, 2025

@joaoloureirop joaoloureirop merged commit c376d31 into release/7.58.1 Nov 6, 2025
79 of 86 checks passed
@joaoloureirop joaoloureirop deleted the cherry-pick-7-58-1-5c63946 branch November 6, 2025 19:03
@github-actions github-actions bot locked and limited conversation to collaborators Nov 6, 2025
@metamaskbot metamaskbot added the release-7.58.1 Issue or pull request that will be included in release 7.58.1 label Nov 6, 2025
@metamaskbot
Copy link
Collaborator

No release label on PR. Adding release label release-7.58.1 on PR, as PR was cherry-picked in branch 7.58.1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.58.1 Issue or pull request that will be included in release 7.58.1 size-M team-bots Bot team (for MetaMask Bot, Runway Bot, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants