Fix ghost notifications on Android 10; fix MediaBrowser exposed #12412
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is it?
Description of the changes in your PR
This PR resolves a security-related TODO from #12044: making sure only packages with the right permissions can access NewPipe's MediaBrowser through
onGetRoot()
. ThePackageValidator
file is taken from https://github.com/android/uamp/blob/329a21b63c247e9bd35f6858d4fc0e448fa38603/common/src/main/java/com/example/android/uamp/media/PackageValidator.kt, as suggested in the Android docs here.Furthermore, this PR fixes #12400, which was caused by an invalid media resumption notification being created by the system after closing the player. The notification was being created because the system was querying
onGetRoot()
to get information about resumption, and our code returned aBrowserRoot
instead of returningnull
, indicating that we supported media resumption as described here. Now the code only returns aBrowserRoot
ifrootHints?.getBoolean(EXTRA_RECENT) != true
, since theEXTRA_RECENT
hint is what identifies a media resumption request. This is also how UAMP and the Android docs identify it.I tested the fix for #12400 on an Android 10 emulator, and while I could reproduce before this commit, now I can't anymore. I also tested the Android Auto implementation with android-head-unit and it still works (i.e. the Android Auto app passes the
PackageValidator
tests).For reference, VLC's implementation is quite different (no validation checks, package check to identify Android Auto), though I think it's buggy as I get ghost notifications with VLC too: https://github.com/videolan/vlc-android/blob/13567cd0ddc3ae93b853229a532694eee25a526d/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt#L1909
I've learned something about MediaBrowser tonight ;-)
Fixes the following issue(s)
APK testing
The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR. You can find more info and a video demonstration on this wiki page.
Due diligence