From 5f7069437e34e98ea53b79f36ba0531277cb4671 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Mon, 5 Jul 2021 23:40:52 -0400 Subject: [PATCH] using copyto method and also closing stream for extension installs --- .../tachiyomi/extension/util/ExtensionInstallActivity.kt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt index cdc56cfee1..64313fe277 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionInstallActivity.kt @@ -40,13 +40,7 @@ class ExtensionInstallActivity : Activity() { val sessionId = packageInstaller.createSession(params) val session = packageInstaller.openSession(sessionId) session.openWrite("package", 0, -1).use { packageInSession -> - data.use { `is` -> - val buffer = ByteArray(16384) - var n: Int - while (`is`.read(buffer).also { n = it } >= 0) { - packageInSession.write(buffer, 0, n) - } - } + data.copyTo(packageInSession) } val newIntent = Intent(this, ExtensionInstallActivity::class.java) @@ -59,6 +53,7 @@ class ExtensionInstallActivity : Activity() { session.commit(statusReceiver) val extensionManager: ExtensionManager by injectLazy() extensionManager.setInstalling(downloadId, sessionId) + data.close() } catch (error: Exception) { // Either install package can't be found (probably bots) or there's a security exception // with the download manager. Nothing we can workaround.