mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Max binary byte as 10 MB to prevent OOM #256
This commit is contained in:
@@ -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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user