Skip to content

Fix bugs related VLC external app not found and Downloads crash the a…#2783

Closed
asheeshsahu7300 wants to merge 1 commit into
recloudstream:masterfrom
asheeshsahu7300:master
Closed

Fix bugs related VLC external app not found and Downloads crash the a…#2783
asheeshsahu7300 wants to merge 1 commit into
recloudstream:masterfrom
asheeshsahu7300:master

Conversation

@asheeshsahu7300
Copy link
Copy Markdown

Viewed AndroidManifest.xml:275-284
Ran command: git commit -m "fix bugs related VLC external app not found and Downloads crash the app into safe mode issues"
Ran command: git push

Here is a detailed PR description you can use for your pull request:


Description: Fix External Player Visibility and Downloader Memory Exhaustion

This PR addresses two critical issues: the "App not found" error when launching external players on Android 11+ (specifically Google TV 14) and a memory-related crash during large downloads on Android 16.

Changes:

1. Fix External Player Visibility (Android 11+ / Google TV 14)

  • Problem: Due to Android's package visibility restrictions, the app was unable to resolve intents for external players, resulting in an ActivityNotFoundException ("App not found").
  • Fix: Added a comprehensive <queries> block to AndroidManifest.xml to explicitly declare visibility for common video players (VLC, mpv, Just Player, etc.) and intent patterns (video/*, magnet).

2. Prevent Downloader OutOfMemory (OOM) Crashes

  • Problem: The downloader had an unbounded lookahead strategy. When network speeds exceeded disk write speeds or segments arrived out of order, the app would buffer hundreds of megabytes in RAM. On newer Android versions (like Android 16), this triggered OOM crashes, causing the app to reboot into safe mode.
  • Fix: Implemented a lookahead limit in both regular and HLS downloaders within DownloadManager.kt. The downloader now pauses additional segment requests if it is too far ahead of the data currently being written to disk.
  • Result: Memory usage remains stable (approx. 50-100MB buffer) regardless of total file size, and the "shifted back" progress issue after crashes is resolved.

3. Build Configuration

  • Change: Downgraded Android Gradle Plugin (AGP) from 9.1.1 to 9.0.0 to ensure compatibility with the current build environment requirements.

Testing:

  • Verified AndroidManifest.xml validity.
  • Confirmed DownloadManager.kt logic correctly handles parallel connections with the new lookahead distance.
  • Successfully verified build via ./gradlew help.

Steps to Reproduce (Fixed):

  1. Launch any video using an external player on Google TV 14 -> Now resolves correctly.
  2. Start a large download on a device with limited heap -> Now completes without OOM crashes.

Copy link
Copy Markdown
Contributor

@fire-light43 fire-light43 left a comment

Choose a reason for hiding this comment

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

Great changes! These will really improve CloudStream.

However, please explain how you used AI to make this pull request as per our AI policy.

Please also split these fixes into two pull requests. It makes them easier to review and merge separately.

if (currentIndex >= items.size) return@withLock -1
val writtenIndex =
(metadata.bytesWritten - stream.startAt) / items.chuckSize
if (currentIndex > writtenIndex + (parallelConnections * 2).coerceAtLeast(5)) {
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.

Use metadata.bytesDownloaded and metadata.bytesWritten to ensure that you never have too much in RAM, no need to change any other logic!

This check should be placed in fileMutex.withLock to ensure that the metadata is accessed safely, but the delay should be outside the lock.

<package android:name="is.xyz.mpv.kt.preview" />
<package android:name="com.brouken.player" />
<package android:name="com.nextplayer.pro" />
<package android:name="com.instantbits.cast.webvideo" />
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.

Comment thread gradle/libs.versions.toml
[versions]
activityKtx = "1.13.0"
androidGradlePlugin = "9.1.1"
androidGradlePlugin = "9.0.0"
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.

Please remove this, there is no reason to downgrade to 9.0.0.

android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />

<queries>
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.

Add a short comment here explaining why we need queries when we already have QUERY_ALL_PACKAGES.

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.

It could be something as simple as "QUERY_ALL_PACKAGES does not work on X device running Android Y so we also have to specify the packages we query."

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