mirror of
https://github.com/bitwarden/android.git
synced 2025-03-16 19:28:44 +03:00
PM-10878: Access parcelable data in a safe manor across SDK versions (#3727)
This commit is contained in:
parent
2bed4986a1
commit
499bc20850
1 changed files with 8 additions and 21 deletions
|
@ -3,37 +3,24 @@
|
|||
package com.x8bit.bitwarden.data.platform.util
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.os.Parcelable
|
||||
import androidx.core.content.IntentCompat
|
||||
import androidx.core.os.BundleCompat
|
||||
import com.x8bit.bitwarden.data.platform.annotation.OmitFromCoverage
|
||||
|
||||
/**
|
||||
* A means of retrieving a [Parcelable] from an [Intent] using the given [name] in a manner that
|
||||
* is safe across SDK versions.
|
||||
*/
|
||||
inline fun <reified T> Intent.getSafeParcelableExtra(name: String): T? =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
getParcelableExtra(
|
||||
name,
|
||||
T::class.java,
|
||||
)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
getParcelableExtra(name)
|
||||
}
|
||||
inline fun <reified T> Intent.getSafeParcelableExtra(
|
||||
name: String,
|
||||
): T? = IntentCompat.getParcelableExtra(this, name, T::class.java)
|
||||
|
||||
/**
|
||||
* A means of retrieving a [Parcelable] from a [Bundle] using the given [name] in a manner that
|
||||
* is safe across SDK versions.
|
||||
*/
|
||||
inline fun <reified T> Bundle.getSafeParcelableExtra(name: String): T? =
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
getParcelable(
|
||||
name,
|
||||
T::class.java,
|
||||
)
|
||||
} else {
|
||||
@Suppress("DEPRECATION")
|
||||
getParcelable(name)
|
||||
}
|
||||
inline fun <reified T> Bundle.getSafeParcelableExtra(
|
||||
name: String,
|
||||
): T? = BundleCompat.getParcelable(this, name, T::class.java)
|
||||
|
|
Loading…
Add table
Reference in a new issue