Handle bad decoded intent parcelables safely
Guard reading the `decoded` Scan extra in MainActivity against framework unparcel exceptions. Some external or malformed intents can trigger a NullPointerException in Parcel before app-level checks run. Return null when unparceling fails so the app falls back to the default DecodeFragment path instead of crashing on launch.
This commit is contained in:
@@ -148,11 +148,15 @@ class MainActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Intent.getScanExtra(name: String): Scan? = if (
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
|
||||
) {
|
||||
@Suppress("DEPRECATION")
|
||||
getParcelableExtra(name)
|
||||
} else {
|
||||
getParcelableExtra(name, Scan::class.java)
|
||||
private fun Intent.getScanExtra(name: String): Scan? = try {
|
||||
if (
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
|
||||
) {
|
||||
@Suppress("DEPRECATION")
|
||||
getParcelableExtra(name)
|
||||
} else {
|
||||
getParcelableExtra(name, Scan::class.java)
|
||||
}
|
||||
} catch (_: Throwable) {
|
||||
null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user