Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
eedeaa6
fix(ADFA-5438): Return session ids and failure reasons when installin…
dara-abijo-adfa Nov 5, 2026
8a2de6a
fix(ADFA-5438): Track and abandon install sessions in ProxyAppInstaller
dara-abijo-adfa Nov 5, 2026
46a56b2
fix(ADFA-5438): Sweep stale PackageInstaller sessions at Quick Build …
dara-abijo-adfa Nov 5, 2026
c79f295
feat(ADFA-5438): Report TooManyInstallSessions distinctly from Instal…
dara-abijo-adfa Nov 5, 2026
636ad7c
test(ADFA-5438): Add unit tests for install session abandonment and 5…
dara-abijo-adfa Nov 6, 2026
1372ae9
fix(ADFA-5438): ignore aborted broadcasts from abandoned install sess…
dara-abijo-adfa Nov 6, 2026
585cd66
fix(ADFA-5438): Avoid cancelling in-flight user installs during sessi…
dara-abijo-adfa Nov 6, 2026
3e54fdf
Merge branch 'stage' into ADFA-5438-quick-build-session-leak
dara-abijo-adfa Nov 10, 2026
ed70b17
fix(ADFA-5438): Persist sessions across restarts
dara-abijo-adfa Nov 10, 2026
940e008
fix(ADFA-5438): Fail immediately when prompt-timeout re-issue does no…
dara-abijo-adfa Nov 12, 2026
9176e02
fix(ADFA-5438): Sweep orphaned persisted user sessions
dara-abijo-adfa Nov 12, 2026
3fe68c6
fix(ADFA-5438): Drop unnecessary flag
dara-abijo-adfa Nov 12, 2026
270fe87
test(ADFA-5438): Add unit tests
dara-abijo-adfa Nov 12, 2026
d85d25e
Merge branch 'stage' into ADFA-5438-quick-build-session-leak
dara-abijo-adfa Nov 12, 2026
a1ed677
fix(ADFA-5438): Handle thread blokcing operations
dara-abijo-adfa Nov 13, 2026
2818269
Merge branch 'stage' into ADFA-5438-quick-build-session-leak
dara-abijo-adfa Nov 13, 2026
5afa280
fix(ADFA-5438): Retain tracking on failed abandonment
dara-abijo-adfa Nov 13, 2026
0eb7add
Merge branch 'stage' into ADFA-5438-quick-build-session-leak
dara-abijo-adfa Nov 16, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 55 additions & 27 deletions app/src/main/java/com/itsaky/androidide/di/QuickBuildModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.appdevforall.cotg.quickbuild.domain.telemetry.QuickBuildMetricsSink
import org.appdevforall.cotg.quickbuild.service.deploy.DeployChannel
import org.appdevforall.cotg.quickbuild.service.deploy.DeploySender
import org.appdevforall.cotg.quickbuild.service.deploy.ProxyAppConnections
import org.appdevforall.cotg.quickbuild.service.provision.InstallLaunchResult
import org.appdevforall.cotg.quickbuild.service.provision.InstalledPackages
import org.appdevforall.cotg.quickbuild.service.provision.ProxyAppInstaller
import org.appdevforall.cotg.quickbuild.service.provision.QuickBuildClobberCheck
Expand Down Expand Up @@ -83,33 +84,53 @@ val quickBuildModule =

single {
val context = androidContext()
ProxyAppInstaller(
packages = get(),
// The exact call the Run button's install flow bottoms out in:
// same PackageInstaller session params, same InstallationResultReceiver,
// same MIUI intent fallback. Post-install launch is suppressed: the session
// switches to the proxy app itself on provisioning success, so the generic
// launch-after-install must not fire a duplicate launch on every install.
launchInstall = { apk ->
withContext(Dispatchers.Main) {
ApkInstaller.installApk(context, apk, suppressPostInstallLaunch = true)
}
},
// Register before any install: the receiver's EventBus events become the
// installer's completion signal.
broadcasts = InstallationEventFlow().also { it.register() }.broadcasts,
// Whether the install-confirm dialog can be launched right now. The
// dialog-owning subscriber (BaseEditorActivity -> InstallationResultHandler)
// is EventBus lifecycle-bound - registered onStart, unregistered onStop -
// so it can show the dialog exactly while the process is STARTED. Racy
// reads err toward waiting (the installer's timeout is the backstop).
canShowConfirmDialog = {
ProcessLifecycleOwner
.get()
.lifecycle.currentState
.isAtLeast(Lifecycle.State.STARTED)
},
)
lateinit var installer: ProxyAppInstaller
installer =
ProxyAppInstaller(
packages = get(),
// Register before any install: the receiver's EventBus events become the
// installer's completion signal.
broadcasts = InstallationEventFlow().also { it.register() }.broadcasts,
// Whether the install-confirm dialog can be launched right now. The
// dialog-owning subscriber (BaseEditorActivity -> InstallationResultHandler)
// is EventBus lifecycle-bound - registered onStart, unregistered onStop -
// so it can show the dialog exactly while the process is STARTED. Racy
// reads err toward waiting (the installer's timeout is the backstop).
canShowConfirmDialog = {
ProcessLifecycleOwner
.get()
.lifecycle.currentState
.isAtLeast(Lifecycle.State.STARTED)
},
// The exact call the Run button's install flow bottoms out in:
// same PackageInstaller session params, same InstallationResultReceiver,
// same MIUI intent fallback. Post-install launch is suppressed: the session
// switches to the proxy app itself on provisioning success, so the generic
// launch-after-install must not fire a duplicate launch on every install.
launchInstallSession = { apk ->
val result =
withContext(Dispatchers.Main) {
ApkInstaller.installApkSession(
context = context,
apk = apk,
suppressPostInstallLaunch = true,
)
}
when (result) {
is ApkInstaller.SessionLaunchResult.Started -> InstallLaunchResult.Started(result.sessionId)
ApkInstaller.SessionLaunchResult.TooManySessions -> InstallLaunchResult.TooManySessions
ApkInstaller.SessionLaunchResult.Failed -> InstallLaunchResult.Failed
}
},
abandonSession = { sessionId -> ApkInstaller.abandonSession(context, sessionId) },
sweepStaleSessions = {
ApkInstaller.abandonMySessions(
context = context,
onBeforeAbandon = installer::recordAbandonedSession,
)
},
)
installer
}

single<QuickBuildProvisioner> {
Expand Down Expand Up @@ -201,6 +222,13 @@ val quickBuildModule =
// AssetsProvider, which is API 30+. Below that an asset edit would be
// extracted and never read, so those edits rebaseline instead.
assetsLiveReloadable = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R,
sweepInstallSessions = {
val installer = get<ProxyAppInstaller>()
ApkInstaller.abandonMySessions(
context = androidContext(),
onBeforeAbandon = installer::recordAbandonedSession,
)
},
).also { manager ->
// Narration must be scoped to the session, not to an activity on screen:
// an activity-scoped collector misses every generation produced while the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,14 @@ class InstallationEventFlow {
InstallBroadcast.Status.OTHER
}
}
val sessionId =
extras.getInt(PackageInstaller.EXTRA_SESSION_ID, Int.MIN_VALUE).takeIf { it != Int.MIN_VALUE }
_broadcasts.tryEmit(
InstallBroadcast(
packageName = extras.getString(PackageInstaller.EXTRA_PACKAGE_NAME),
status = status,
message = extras.getString(PackageInstaller.EXTRA_STATUS_MESSAGE),
sessionId = sessionId,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ fun QuickBuildMessage.resolve(context: Context): String =
context.getString(R.string.quick_build_install_could_not_start)
}

QuickBuildMessage.TooManyInstallSessions -> {
context.getString(R.string.quick_build_too_many_install_sessions)
}

QuickBuildMessage.InstallFailed -> {
context.getString(R.string.quick_build_install_failed)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import android.content.Context
import android.content.Intent
import com.itsaky.androidide.buildinfo.BuildInfo
import com.itsaky.androidide.events.InstallationEvent.InstallationResultEvent
import com.itsaky.androidide.utils.ApkInstaller
import org.greenrobot.eventbus.EventBus

/**
Expand All @@ -38,6 +39,7 @@ class InstallationResultReceiver : BroadcastReceiver() {
context: Context,
intent: Intent,
) {
ApkInstaller.onInstallStatusBroadcast(intent, context)
Comment thread
dara-abijo-adfa marked this conversation as resolved.
Resolved
EventBus.getDefault().post(InstallationResultEvent(intent))
}
}
Loading