From 7c61ae61bbd2ff4f2c1c0967f9e6f3d074ec7653 Mon Sep 17 00:00:00 2001 From: dadaloop82 Date: Sun, 3 May 2026 20:14:19 +0000 Subject: [PATCH] fix(kiosk): fix ByteArray type inference error in APK magic-byte check The try expression had a spurious 'true' result in one branch which made Kotlin infer the type as Any? instead of ByteArray?. Simplified to a single try block with explicit type annotation ByteArray? to eliminate the ambiguity. --- .../kotlin/it/dadaloop/evershelf/kiosk/KioskActivity.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/KioskActivity.kt b/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/KioskActivity.kt index 875d5ee..d7b7a4b 100644 --- a/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/KioskActivity.kt +++ b/evershelf-kiosk/app/src/main/kotlin/it/dadaloop/evershelf/kiosk/KioskActivity.kt @@ -1199,10 +1199,10 @@ class KioskActivity : AppCompatActivity() { runOnUiThread { activeInstallBtn?.text = getString(R.string.install_btn_retry) } return } - // Validate APK magic bytes (ZIP local file header = 0x504B0304). + // Validate APK magic bytes (ZIP local file header = 'PK' = 0x50 0x4B). // If GitHub returned a 404 HTML page, DownloadManager still reports SUCCESS - // but the file starts with '<' not 'PK' — this catches that case early. - val magic = try { file.inputStream().use { it.read(4) ; true }; // read to check open + // but the file starts with '<' not 'PK' — catch that before calling PackageInstaller. + val magic: ByteArray? = try { file.inputStream().use { s -> val b = ByteArray(4); s.read(b); b } } catch (_: Exception) { null } val isApk = magic != null && magic[0] == 0x50.toByte() && magic[1] == 0x4B.toByte()