Always use Private installer to update Private extensions (#3614)
* Use Private installer to update Private extensions This forces the Private installer for any extension which was installed privately, bypassing whichever setting the user selected in Settings > Advanced > Installer. * [skip ci] Changelog entry * [skip ci] Update CHANGELOG.md Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
@@ -240,7 +240,8 @@ class ExtensionManager(
|
||||
*/
|
||||
fun updateExtension(extension: Extension.Installed): Flow<InstallStep> {
|
||||
val availableExt = availableExtensionMapFlow.value[extension.pkgName] ?: return emptyFlow()
|
||||
return installExtension(availableExt)
|
||||
val isUpdateForPrivatelyInstalled = !extension.isShared
|
||||
return installer.downloadAndInstall(availableExt.apkUrl, availableExt, isUpdateForPrivatelyInstalled)
|
||||
}
|
||||
|
||||
fun cancelInstallUpdateExtension(extension: Extension) {
|
||||
|
||||
@@ -49,8 +49,13 @@ internal class ExtensionInstaller(
|
||||
*
|
||||
* @param url The url of the apk.
|
||||
* @param extension The extension to install.
|
||||
* @param isUpdateForPrivatelyInstalled If this is an update for a privately installed extension
|
||||
*/
|
||||
fun downloadAndInstall(url: String, extension: Extension): Flow<InstallStep> {
|
||||
fun downloadAndInstall(
|
||||
url: String,
|
||||
extension: Extension,
|
||||
isUpdateForPrivatelyInstalled: Boolean = false,
|
||||
): Flow<InstallStep> {
|
||||
val downloadId = extension.pkgName.hashCode().toLong()
|
||||
cancelInstall(extension.pkgName)
|
||||
|
||||
@@ -74,7 +79,7 @@ internal class ExtensionInstaller(
|
||||
}
|
||||
|
||||
step.value = InstallStep.Installing
|
||||
installApk(downloadId, tmpFile)
|
||||
installApk(downloadId, tmpFile, isUpdateForPrivatelyInstalled)
|
||||
} catch (e: Exception) {
|
||||
if (e is InterruptedException) {
|
||||
// Canceled
|
||||
@@ -99,8 +104,14 @@ internal class ExtensionInstaller(
|
||||
* Starts an intent to install the extension at the given uri.
|
||||
*
|
||||
* @param tempFile The file of the extension to install. Delete after use.
|
||||
* @param isUpdateForPrivatelyInstalled If this install is an update for a privately installed extension
|
||||
*/
|
||||
private fun installApk(downloadId: Long, tempFile: File) {
|
||||
private fun installApk(downloadId: Long, tempFile: File, isUpdateForPrivatelyInstalled: Boolean = false) {
|
||||
if (isUpdateForPrivatelyInstalled) {
|
||||
installApkPrivately(downloadId, tempFile)
|
||||
return
|
||||
}
|
||||
|
||||
when (val installer = extensionInstaller.get()) {
|
||||
BasePreferences.ExtensionInstaller.LEGACY -> {
|
||||
val intent = Intent(context, ExtensionInstallActivity::class.java)
|
||||
@@ -110,20 +121,11 @@ internal class ExtensionInstaller(
|
||||
|
||||
context.startActivity(intent)
|
||||
}
|
||||
BasePreferences.ExtensionInstaller.PRIVATE -> {
|
||||
try {
|
||||
if (ExtensionLoader.installPrivateExtensionFile(context, tempFile)) {
|
||||
updateInstallStep(downloadId, InstallStep.Installed)
|
||||
} else {
|
||||
updateInstallStep(downloadId, InstallStep.Error)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e) { "Failed to read downloaded extension file." }
|
||||
updateInstallStep(downloadId, InstallStep.Error)
|
||||
}
|
||||
|
||||
tempFile.delete()
|
||||
BasePreferences.ExtensionInstaller.PRIVATE -> {
|
||||
installApkPrivately(downloadId, tempFile)
|
||||
}
|
||||
|
||||
else -> {
|
||||
val intent = ExtensionInstallService.getIntent(
|
||||
context,
|
||||
@@ -136,6 +138,21 @@ internal class ExtensionInstaller(
|
||||
}
|
||||
}
|
||||
|
||||
private fun installApkPrivately(downloadId: Long, tempFile: File) {
|
||||
try {
|
||||
if (ExtensionLoader.installPrivateExtensionFile(context, tempFile)) {
|
||||
updateInstallStep(downloadId, InstallStep.Installed)
|
||||
} else {
|
||||
updateInstallStep(downloadId, InstallStep.Error)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
logcat(LogPriority.ERROR, e) { "Failed to read downloaded extension file." }
|
||||
updateInstallStep(downloadId, InstallStep.Error)
|
||||
}
|
||||
|
||||
tempFile.delete()
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels extension install and remove from download manager and installer.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user