MinimumDiskSpaceInterceptor.kt
TLDR
This file contains the MinimumDiskSpaceInterceptor
class, which is used to intercept heap analysis operations and check if the available disk space is above a minimum threshold.
Classes
MinimumDiskSpaceInterceptor
The MinimumDiskSpaceInterceptor
class implements the HeapAnalysisInterceptor
interface. It checks the available disk space and cancels the heap analysis job if the space is below a specified threshold. The class takes an Application
object, the minimum required disk space in bytes, and a ProcessInfo
object as parameter in its constructor.
Methods
There are no methods in this file.
package leakcanary
import android.app.Application
import leakcanary.HeapAnalysisInterceptor.Chain
import leakcanary.HeapAnalysisJob.Result
class MinimumDiskSpaceInterceptor(
private val application: Application,
private val minimumDiskSpaceBytes: Long = 200_000_000,
private val processInfo: ProcessInfo = ProcessInfo.Real
) : HeapAnalysisInterceptor {
override fun intercept(chain: Chain): Result {
val availableDiskSpace = processInfo.availableDiskSpaceBytes(application.filesDir!!)
if (availableDiskSpace < minimumDiskSpaceBytes) {
chain.job.cancel("availableDiskSpace $availableDiskSpace < minimumDiskSpaceBytes $minimumDiskSpaceBytes")
}
return chain.proceed()
}
}