Skip to content

Commit

Permalink
Fix installer on some older devices (#1533)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luna712 authored Jan 31, 2025
1 parent c5577a5 commit e5ac4a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.lagradost.cloudstream3.MainActivity
import com.lagradost.cloudstream3.MainActivity.Companion.deleteFileOnExit
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.app
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.ApkInstaller
import com.lagradost.cloudstream3.utils.AppContextUtils.createNotificationChannel
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
Expand Down Expand Up @@ -106,6 +107,7 @@ class PackageInstallerService : Service() {
}
return true
} catch (e: Exception) {
logError(e)
updateNotificationProgress(0f, ApkInstaller.InstallProgressStatus.Failed)
return false
}
Expand Down Expand Up @@ -189,4 +191,4 @@ class PackageInstallerService : Service() {
.putExtra(EXTRA_URL, url)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,19 @@ class ApkInstaller(private val service: PackageInstallerService) {
}

// We must create an explicit intent or it will fail on Android 15+
val installIntent = Intent(service, PackageInstallerService::class.java).apply {
action = INSTALL_ACTION
val installIntent = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
Intent(service, PackageInstallerService::class.java)
.setAction(INSTALL_ACTION)
} else Intent(INSTALL_ACTION)

val installFlags = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE -> PendingIntent.FLAG_MUTABLE
Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> PendingIntent.FLAG_IMMUTABLE
else -> 0
}

val intentSender = PendingIntent.getBroadcast(
service,
activeSession,
installIntent,
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_MUTABLE
} else 0,
service, activeSession, installIntent, installFlags
).intentSender

// Use delayed installations on android 13 and only if "allow from unknown sources" is enabled
Expand Down Expand Up @@ -179,4 +181,4 @@ class ApkInstaller(private val service: PackageInstallerService) {
isReceiverRegistered = false
}
}
}
}

0 comments on commit e5ac4a0

Please sign in to comment.