Skip to content

Commit 6a7dcc1

Browse files
committed
fix: Show install error instead of uninstall dialog when target package is not installed
Closes #631
1 parent b6f15ea commit 6a7dcc1

1 file changed

Lines changed: 16 additions & 11 deletions

File tree

app/src/main/java/app/morphe/manager/ui/viewmodel/InstallViewModel.kt

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import app.morphe.manager.util.PM
2020
import app.morphe.manager.util.sha256OrNull
2121
import app.morphe.manager.util.simpleMessage
2222
import app.morphe.manager.util.toast
23+
import kotlin.time.Duration.Companion.seconds
2324
import kotlinx.coroutines.*
2425
import org.koin.core.component.KoinComponent
2526
import org.koin.core.component.inject
@@ -394,10 +395,7 @@ class InstallViewModel : ViewModel(), KoinComponent {
394395
onPersistApp(targetPackageName, InstallType.DEFAULT)
395396
handleInstallSuccess(targetPackageName)
396397
}
397-
is InstallResult.Conflict -> {
398-
Log.i(TAG, "Signature conflict for $targetPackageName")
399-
installState = InstallState.Conflict(targetPackageName)
400-
}
398+
is InstallResult.Conflict -> handleConflict(targetPackageName, result.message)
401399
is InstallResult.Failure -> handleInstallError(
402400
app.getString(R.string.install_app_fail, result.message ?: "Unknown error")
403401
)
@@ -448,10 +446,7 @@ class InstallViewModel : ViewModel(), KoinComponent {
448446
installState = InstallState.Installed(targetPackageName)
449447
app.toast(app.getString(R.string.install_app_success))
450448
}
451-
is InstallResult.Conflict -> {
452-
Log.i(TAG, "Signature conflict for $targetPackageName")
453-
installState = InstallState.Conflict(targetPackageName)
454-
}
449+
is InstallResult.Conflict -> handleConflict(targetPackageName, result.message)
455450
is InstallResult.Failure -> handleInstallError(
456451
app.getString(R.string.install_app_fail, result.message ?: "Unknown error")
457452
)
@@ -531,8 +526,8 @@ class InstallViewModel : ViewModel(), KoinComponent {
531526
externalInstallStartTime = System.currentTimeMillis()
532527

533528
// Use a lightweight sentinel so handleExternalInstallSuccess can match the package
534-
// without a full External plan we repurpose pendingExternalInstall's expectedPackage
535-
// by creating a minimal sentinel object just for the package name check.
529+
// without a full External plan - we repurpose pendingExternalInstall's expectedPackage
530+
// by creating a minimal sentinel object just for the package name check
536531
pendingIntentFallbackPackage = targetPackageName
537532

538533
sessionInstaller.launchIntentInstall(outputFile)
@@ -943,9 +938,19 @@ class InstallViewModel : ViewModel(), KoinComponent {
943938
installState = InstallState.Error(message)
944939
}
945940

941+
private fun handleConflict(targetPackageName: String, conflictMessage: String?) {
942+
Log.i(TAG, "Signature conflict for $targetPackageName")
943+
if (pm.getPackageInfo(targetPackageName) != null) {
944+
installState = InstallState.Conflict(targetPackageName)
945+
} else {
946+
// Target not installed - not a real signature conflict (e.g. renamed package)
947+
handleInstallError(app.getString(R.string.install_app_fail, conflictMessage ?: "Unknown error"))
948+
}
949+
}
950+
946951
companion object {
947952
private const val TAG = "Morphe Install"
948953
private const val EXTERNAL_INSTALL_TIMEOUT_MS = 60_000L
949-
private const val INSTALL_MONITOR_POLL_MS = 1000L
954+
private val INSTALL_MONITOR_POLL_MS = 1.seconds
950955
}
951956
}

0 commit comments

Comments
 (0)