Max binary byte as 10 MB to prevent OOM #256

This commit is contained in:
J-Jamet
2022-02-20 17:16:36 +01:00
parent 1d98eb2b95
commit 74107b90bb

View File

@@ -180,12 +180,16 @@ abstract class BinaryData : Parcelable {
companion object { companion object {
private val TAG = BinaryData::class.java.name private val TAG = BinaryData::class.java.name
private const val MAX_BINARY_BYTE = 10485760 // 10 MB
fun canMemoryBeAllocatedInRAM(context: Context, memoryWanted: Long): Boolean { fun canMemoryBeAllocatedInRAM(context: Context, memoryWanted: Long): Boolean {
if (memoryWanted > MAX_BINARY_BYTE)
return false
val memoryInfo = ActivityManager.MemoryInfo() val memoryInfo = ActivityManager.MemoryInfo()
(context.getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager).getMemoryInfo(memoryInfo) (context.getSystemService(Context.ACTIVITY_SERVICE)
as? ActivityManager?)?.getMemoryInfo(memoryInfo)
val availableMemory = memoryInfo.availMem val availableMemory = memoryInfo.availMem
return availableMemory > memoryWanted * 3 return availableMemory > (memoryWanted * 5)
} }
} }