Prevent DefaultInstaller from working on a non-existent cache file.

Ensures that the cache file exists before attempting an install using
it. This fixes a crash that can occur if the file is not yet available,
likely due to an I/O-related race condition.
This commit is contained in:
Matthew Crossman 2022-01-03 19:20:00 +11:00
parent 3e8e23e111
commit adf305ffc0
No known key found for this signature in database
GPG Key ID: C6B942B019794CC2

View File

@ -51,16 +51,18 @@ class DefaultInstaller(context: Context) : BaseInstaller(context) {
val session = sessionInstaller.openSession(id)
session.use { activeSession ->
activeSession.openWrite("package", 0, cacheFile.length()).use { packageStream ->
cacheFile.inputStream().use { fileStream ->
fileStream.copyTo(packageStream)
if (cacheFile.exists()) {
session.use { activeSession ->
activeSession.openWrite("package", 0, cacheFile.length()).use { packageStream ->
cacheFile.inputStream().use { fileStream ->
fileStream.copyTo(packageStream)
}
}
val pendingIntent = PendingIntent.getService(context, id, intent, flags)
session.commit(pendingIntent.intentSender)
}
val pendingIntent = PendingIntent.getService(context, id, intent, flags)
session.commit(pendingIntent.intentSender)
}
cacheFile.delete()
}