From 6b05c0221b5cf02de17242fa84db2a6f5f50cbcf Mon Sep 17 00:00:00 2001 From: Akash Yadav Date: Tue, 22 Aug 2023 21:34:02 +0530 Subject: [PATCH] fix: package installation sessions are not abandoned properly (fixes #1213) --- .../androidide/activities/editor/BaseEditorActivity.kt | 6 ------ .../androidide/utils/ApkInstallationSessionCallback.kt | 10 +++++++++- .../java/com/itsaky/androidide/utils/ApkInstaller.kt | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt b/app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt index 334cdc25cf..d4ebc202ef 100644 --- a/app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt +++ b/app/src/main/java/com/itsaky/androidide/activities/editor/BaseEditorActivity.kt @@ -66,21 +66,15 @@ import com.itsaky.androidide.fragments.SearchResultFragment import com.itsaky.androidide.handlers.EditorActivityLifecyclerObserver import com.itsaky.androidide.handlers.LspHandler.registerLanguageServers import com.itsaky.androidide.interfaces.DiagnosticClickListener -import com.itsaky.androidide.logsender.LogSender import com.itsaky.androidide.lookup.Lookup import com.itsaky.androidide.lsp.models.DiagnosticItem import com.itsaky.androidide.models.DiagnosticGroup -import com.itsaky.androidide.models.LogLine import com.itsaky.androidide.models.OpenedFile import com.itsaky.androidide.models.Range import com.itsaky.androidide.models.SearchResult -import com.itsaky.androidide.preferences.logsenderEnabled import com.itsaky.androidide.projects.ProjectManager.getProjectDirPath import com.itsaky.androidide.projects.ProjectManager.projectPath import com.itsaky.androidide.projects.builder.BuildService -import com.itsaky.androidide.services.log.LogReceiverService -import com.itsaky.androidide.services.log.LogReceiverServiceConnection -import com.itsaky.androidide.services.log.lookupLogService import com.itsaky.androidide.ui.editor.CodeEditorView import com.itsaky.androidide.uidesigner.UIDesignerActivity import com.itsaky.androidide.utils.ActionMenuUtils.createMenu diff --git a/app/src/main/java/com/itsaky/androidide/utils/ApkInstallationSessionCallback.kt b/app/src/main/java/com/itsaky/androidide/utils/ApkInstallationSessionCallback.kt index cd5ed55475..cc95c557d1 100644 --- a/app/src/main/java/com/itsaky/androidide/utils/ApkInstallationSessionCallback.kt +++ b/app/src/main/java/com/itsaky/androidide/utils/ApkInstallationSessionCallback.kt @@ -26,9 +26,11 @@ class ApkInstallationSessionCallback(private var activity: BaseEditorActivity?) SingleSessionCallback() { private val log = ILogger.newInstance("InstallationSessionCallback") + private var sessionId = -1 override fun onCreated(sessionId: Int) { - log.debug("on session created:", sessionId) + this.sessionId = sessionId + log.debug("Created package installation session:", sessionId) activity?.binding?.apply { bottomSheet.setActionText(activity!!.getString(string.msg_installing_apk)) bottomSheet.setActionProgress(0) @@ -56,6 +58,12 @@ class ApkInstallationSessionCallback(private var activity: BaseEditorActivity?) } fun destroy() { + this.activity?.let { + if (this.sessionId != -1) { + it.packageManager?.packageInstaller?.abandonSession(this.sessionId) + } + } this.activity = null + this.sessionId = -1 } } diff --git a/common/src/main/java/com/itsaky/androidide/utils/ApkInstaller.kt b/common/src/main/java/com/itsaky/androidide/utils/ApkInstaller.kt index a59d886a34..632f9320fb 100644 --- a/common/src/main/java/com/itsaky/androidide/utils/ApkInstaller.kt +++ b/common/src/main/java/com/itsaky/androidide/utils/ApkInstaller.kt @@ -96,6 +96,7 @@ object ApkInstaller { } } } catch (io: IOException) { + session?.abandon() log.error("Package installation failed", io) } catch (runtime: RuntimeException) { session?.abandon()