Skip to content

Fix StrictMode unsafe intent launch violation#2330

Merged
copybara-service[bot] merged 2 commits into
androidx:mainfrom
nift4:mbrstrict
Jun 30, 2025
Merged

Fix StrictMode unsafe intent launch violation#2330
copybara-service[bot] merged 2 commits into
androidx:mainfrom
nift4:mbrstrict

Conversation

@nift4

@nift4 nift4 commented Apr 11, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@tonihei

tonihei commented Apr 17, 2025

Copy link
Copy Markdown
Collaborator

Could you provide more details on what the issue is? I don't see any warnings/lint issues in this area in Android Studio, but it sounds like you've seen a warning using some StrictMode.

@tonihei tonihei assigned tonihei and unassigned tonihei Apr 17, 2025
@nift4

nift4 commented Apr 17, 2025

Copy link
Copy Markdown
Contributor Author

Hi @tonihei ,

in debug builds of my app I enabled the built-in platform feature StrictMode with the VmPolicy set to (among others) detect unsafe intent launches:
https://developer.android.com/reference/android/os/StrictMode.VmPolicy.Builder#detectUnsafeIntentLaunch()
with penaltyDeath (the app process will be terminated when an issue occurs). This helps catch programming mistakes.

One such issue detected by StrictMode is that when starting playback with a wired headset's play button using media resumption, the MediaButtonRetriever takes the recieved Intent, modifies it and sends it again. According to the docs, this is a possible security problem:
https://developer.android.com/reference/android/os/strictmode/UnsafeIntentLaunchViolation
However, in this case, because setComponent() is always set to our own app's component, there is no security impact at all. I still believe it's good to fix this, because it's technically not a false positive (the Intent with which the service is started does originate from another app).

And fixing this will allow me to remove the exemption of this detection from penaltyDeath and hence detect other programming mistakes that might be a real issue.

@nift4

nift4 commented May 15, 2025

Copy link
Copy Markdown
Contributor Author

Hi @tonihei, do you need any further information to proceed here?

@nift4

nift4 commented Jun 12, 2025

Copy link
Copy Markdown
Contributor Author

@tonihei sorry for the ping, could you please take a look?

@tonihei

tonihei commented Jun 30, 2025

Copy link
Copy Markdown
Collaborator

Sorry for the delay! I checked the pull request and it seems to work well to prevent the warning but also doesn't seem to remove any functionality from the incoming Intent. I'm going to import the PR now.

@copybara-service
copybara-service Bot merged commit e807fe5 into androidx:main Jun 30, 2025
1 check passed
@nift4

nift4 commented Jun 30, 2025

Copy link
Copy Markdown
Contributor Author

Thank you!

@nift4
nift4 deleted the mbrstrict branch June 30, 2025 10:27
shahdDaghash pushed a commit that referenced this pull request Jul 7, 2025
PiperOrigin-RevId: 777492666
(cherry picked from commit e807fe5)
@androidx androidx locked and limited conversation to collaborators Aug 29, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants