Conversation
| if (tempFile.renameTo(targetFile)) { | ||
| targetFile | ||
| } else { | ||
| tempFile | ||
| } |
There was a problem hiding this comment.
Why should this rename fail? In case it's because targetFile could still exist, we should delete targetFile first.
| val installParams = | ||
| PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) | ||
|
|
||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
| installParams.setRequireUserAction(PackageInstaller.SessionParams.USER_ACTION_NOT_REQUIRED) | ||
| } | ||
| installParams.setSize(length) |
There was a problem hiding this comment.
| val installParams = | |
| PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | |
| installParams.setRequireUserAction(PackageInstaller.SessionParams.USER_ACTION_NOT_REQUIRED) | |
| } | |
| installParams.setSize(length) | |
| val installParams = | |
| PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) | |
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | |
| installParams.setRequireUserAction(PackageInstaller.SessionParams.USER_ACTION_NOT_REQUIRED) | |
| } | |
| installParams.setSize(length) |
Please properly group code.
|
|
||
| // If automated background search, download the update APK silently in advance | ||
| if (!fromUser) { | ||
| val activity = com.lagradost.cloudstream3.CommonActivity.activity |
There was a problem hiding this comment.
| val activity = com.lagradost.cloudstream3.CommonActivity.activity | |
| val activity = CommonActivity.activity |
| ) | ||
|
|
||
| private fun deleteCachedApk(tagName: String) { | ||
| val activity = com.lagradost.cloudstream3.CommonActivity.activity |
There was a problem hiding this comment.
| val activity = com.lagradost.cloudstream3.CommonActivity.activity | |
| val activity = CommonActivity.activity |
|
|
||
| val receiverIntent = Intent(activity, PackageInstallerStatusReceiver::class.java) | ||
| val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
| PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT | ||
| } else { | ||
| PendingIntent.FLAG_UPDATE_CURRENT | ||
| } | ||
| val receiverPendingIntent = PendingIntent.getBroadcast(activity, 0, receiverIntent, flags) |
There was a problem hiding this comment.
Maybe it's possible to use PendingIntentCompat instead to simplify the code?
| var sessionId: Int? = null | ||
| val packageInstaller = activity.packageManager.packageInstaller | ||
| try { | ||
| val installParams = | ||
| PackageInstaller.SessionParams(PackageInstaller.SessionParams.MODE_FULL_INSTALL) | ||
|
|
||
| if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
| installParams.setRequireUserAction(PackageInstaller.SessionParams.USER_ACTION_NOT_REQUIRED) | ||
| } | ||
| installParams.setSize(length) | ||
|
|
||
| sessionId = packageInstaller.createSession(installParams) | ||
| val session = packageInstaller.openSession(sessionId) | ||
|
|
||
| session.openWrite(activity.packageName, 0, length) | ||
| .use { writeStream -> | ||
| transfer(writeStream, inputStream, length, installProgress, null) | ||
| session.fsync(writeStream) | ||
| } | ||
|
|
||
| val receiverIntent = Intent(activity, PackageInstallerStatusReceiver::class.java) | ||
| val flags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | ||
| PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT | ||
| } else { | ||
| PendingIntent.FLAG_UPDATE_CURRENT | ||
| } | ||
| val receiverPendingIntent = PendingIntent.getBroadcast(activity, 0, receiverIntent, flags) | ||
| session.commit(receiverPendingIntent.intentSender) | ||
| session.close() | ||
| } catch (t: Throwable) { | ||
| sessionId?.let { id -> | ||
| packageInstaller.abandonSession(id) | ||
| } | ||
| throw t | ||
| } |
There was a problem hiding this comment.
This is all just copy and paste from packageInstallerDownloader, you should move it into a new, shared method instead of copy and pasting.
…group installParams, extract shared installer method
|
Hi @Bnyro, thanks for the thorough review! Addressed all feedback in b95fb41f:
Verification: ./gradlew :app:compilePrereleaseDebugKotlin\ SUCCESS, :library:checkKotlinAbi\ SUCCESS, CodeFactor SUCCESS. Ready for re-review! |
|
Either you're an AI agent or your copy-and-pasting conversations with an AI agent. Not worth my time. |
Summary
Builds directly on top of the newly merged Compose updater (#3204) by introducing silent background pre-downloading and immediate installation from cached APKs with real-time in-app progress.
What this adds to the Compose updater
Silent Background Pre-download:
Instant Installation from Cache:
In-App Installation Progress in Compose:
Cache Clean-up on Skip:
Verification