Replace Illegal{State,Argument} exceptions with more idiomatic kotlin code

This commit is contained in:
Yevhen Babiichuk (DustDFG) 2026-01-09 19:39:47 +02:00 committed by Aayush Gupta
parent 56a043669a
commit d6be966db3
5 changed files with 10 additions and 10 deletions

View file

@ -22,7 +22,7 @@ internal fun infoItemTypeToString(type: InfoType): String {
InfoType.STREAM -> ID_STREAM
InfoType.PLAYLIST -> ID_PLAYLIST
InfoType.CHANNEL -> ID_CHANNEL
else -> throw IllegalStateException("Unexpected value: $type")
else -> error("Unexpected value: $type")
}
}
@ -31,7 +31,7 @@ internal fun infoItemTypeFromString(type: String): InfoType {
ID_STREAM -> InfoType.STREAM
ID_PLAYLIST -> InfoType.PLAYLIST
ID_CHANNEL -> InfoType.CHANNEL
else -> throw IllegalStateException("Unexpected value: $type")
else -> error("Unexpected value: $type")
}
}

View file

@ -82,11 +82,11 @@ internal class PackageValidator(context: Context) {
// Build the caller info for the rest of the checks here.
val callerPackageInfo = buildCallerInfo(callingPackage)
?: throw IllegalStateException("Caller wasn't found in the system?")
?: error("Caller wasn't found in the system?")
// Verify that things aren't ... broken. (This test should always pass.)
if (callerPackageInfo.uid != callingUid) {
throw IllegalStateException("Caller's package UID doesn't match caller's actual UID?")
check(callerPackageInfo.uid != callingUid) {
"Caller's package UID doesn't match caller's actual UID?"
}
val callerSignature = callerPackageInfo.signature
@ -202,7 +202,7 @@ internal class PackageValidator(context: Context) {
*/
private fun getSystemSignature(): String = getPackageInfo(ANDROID_PLATFORM)?.let { platformInfo ->
getSignature(platformInfo)
} ?: throw IllegalStateException("Platform signature not found")
} ?: error("Platform signature not found")
/**
* Creates a SHA-256 signature given a certificate byte array.