Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: package installation sessions are not abandoned properly (fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Aug 22, 2023
1 parent d30967c commit 6b05c02
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ object ApkInstaller {
}
}
} catch (io: IOException) {
session?.abandon()
log.error("Package installation failed", io)
} catch (runtime: RuntimeException) {
session?.abandon()
Expand Down

0 comments on commit 6b05c02

Please sign in to comment.