Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 492b4748 authored by DaVinci9196's avatar DaVinci9196 Committed by GitHub
Browse files

Split Install: Restore from broken session (#3040)



Co-authored-by: default avatarMarvin W <git@larma.de>
parent f3e89988
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ private suspend fun Context.installPackagesInternal(
    } catch (e: Exception) {
        Log.w(TAG, "Error setting dontKillApp", e)
    }
    val sessionId: Int
    var sessionId: Int
    var session: PackageInstaller.Session? = null
    try {
        val sessionInfo = packageInstaller.mySessions.firstOrNull{ it.appLabel == key }
@@ -147,7 +147,7 @@ private suspend fun Context.installPackagesInternal(

        for (component in componentNames) {
            val currentSize: Long = try {
                val inputStream = session.openRead(component)
                val inputStream = session!!.openRead(component)
                val totalSize = withContext(Dispatchers.IO) {
                    val buffer = ByteArray(4096)
                    var total = 0L
@@ -162,10 +162,17 @@ private suspend fun Context.installPackagesInternal(
            } catch (e: IOException) {
                Log.w(TAG, "installPackagesInternal session open read error, ${e.message}")
                0L
            } catch (e: SecurityException) {
                Log.w(TAG, "installPackagesInternal session open read error, ${e.message}")
                //Handling exceptions java.lang.SecurityException: openRead not allowed after commit
                session!!.abandon()
                sessionId = packageInstaller.createSession(params)
                session = packageInstaller.openSession(sessionId)
                0L
            }

            Log.d(TAG, "installPackagesInternal component: $component currentSize:$currentSize")
            session.openWrite(component, currentSize, -1).use { outputStream ->
            session!!.openWrite(component, currentSize, -1).use { outputStream ->
                try {
                    writeComponent(currentSize, notifyId, component, outputStream)
                    session.fsync(outputStream)
@@ -197,7 +204,7 @@ private suspend fun Context.installPackagesInternal(
        )!!

        emitProgress(notifyId, CommitingSession)
        session.commit(pendingIntent.intentSender)
        session!!.commit(pendingIntent.intentSender)
        // don't abandon if `finally` step is reached after this point
        //session.close()