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.
This commit is contained in:
dadaloop82
2026-05-03 20:14:19 +00:00
parent 22e506bd66
commit 7c61ae61bb
@@ -1199,10 +1199,10 @@ class KioskActivity : AppCompatActivity() {
runOnUiThread { activeInstallBtn?.text = getString(R.string.install_btn_retry) } runOnUiThread { activeInstallBtn?.text = getString(R.string.install_btn_retry) }
return 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 // If GitHub returned a 404 HTML page, DownloadManager still reports SUCCESS
// but the file starts with '<' not 'PK' — this catches that case early. // but the file starts with '<' not 'PK' — catch that before calling PackageInstaller.
val magic = try { file.inputStream().use { it.read(4) ; true }; // read to check open val magic: ByteArray? = try {
file.inputStream().use { s -> val b = ByteArray(4); s.read(b); b } file.inputStream().use { s -> val b = ByteArray(4); s.read(b); b }
} catch (_: Exception) { null } } catch (_: Exception) { null }
val isApk = magic != null && magic[0] == 0x50.toByte() && magic[1] == 0x4B.toByte() val isApk = magic != null && magic[0] == 0x50.toByte() && magic[1] == 0x4B.toByte()