Fix alreadyInProgress issue

This commit is contained in:
franzap
2025-12-25 20:13:27 -03:00
parent b34b7ec48e
commit fc566a4345
2 changed files with 11 additions and 31 deletions
@@ -470,15 +470,16 @@ class AndroidPackageManagerPlugin : FlutterPlugin, MethodCallHandler,
}
if (hasActiveSession(packageName)) {
pendingUserActionIntents[packageName]?.let { launchConfirmDialog(packageName, it) }
// IMPORTANT: Emit an event so Dart can transition out of active states.
if (pendingUserActionIntents.containsKey(packageName)) {
// Real pending dialog - re-launch it and let user complete
pendingUserActionIntents[packageName]?.let { launchConfirmDialog(packageName, it) }
emitInstallStatus(packageName, InstallStatus.PENDING_USER_ACTION, "User confirmation pending")
} else {
emitInstallStatus(packageName, InstallStatus.ALREADY_IN_PROGRESS, "Installation already in progress", ErrorCode.ALREADY_IN_PROGRESS)
result.success(mapOf("started" to false, "alreadyInProgress" to true))
return
}
result.success(mapOf("started" to false, "alreadyInProgress" to true))
return
// No pending dialog = stale session. Abandon and proceed with fresh install.
Log.d(TAG, "Abandoning stale session for $packageName")
abandonExistingSession(packageName)
}
if (expectedHash != null && expectedSize != null) {
@@ -170,19 +170,8 @@ final class AndroidPackageManager extends PackageManager {
break;
case InstallStatus.alreadyInProgress:
// Native is stuck thinking an install is in progress.
// Treat as failure so user can see the issue and retry manually.
setOperation(
appId,
OperationFailed(
target: target,
type: FailureType.installFailed,
message: 'Android is busy. Please try again in a moment.',
filePath: filePath,
),
);
// Move on to next app in queue
_advanceAfterDelay();
// Real pending dialog exists - Kotlin will also send pendingUserAction event
// which transitions to Installing. Nothing to do here.
break;
case InstallStatus.success:
@@ -376,18 +365,8 @@ final class AndroidPackageManager extends PackageManager {
final resultMap = Map<String, dynamic>.from(result ?? {});
if (resultMap['alreadyInProgress'] == true) {
// Native is stuck thinking an install is in progress.
// Treat as failure so user can see and retry manually.
setOperation(
appId,
OperationFailed(
target: target,
type: FailureType.installFailed,
message: 'Android is busy. Please try again in a moment.',
filePath: filePath,
),
);
_advanceAfterDelay();
// Real pending dialog exists - Kotlin re-launched it and sent pendingUserAction
// event which transitions to Installing. Nothing to do here.
return;
}