MinimumElapsedSinceStartInterceptor.kt
TLDR
This file is a part of the LeakCanary library and contains the MinimumElapsedSinceStartInterceptor
class. This class is responsible for intercepting heap analysis in order to ensure that a minimum elapsed time has passed since the start of the app.
Classes
MinimumElapsedSinceStartInterceptor
The MinimumElapsedSinceStartInterceptor
class is a part of the LeakCanary library. It implements the HeapAnalysisInterceptor
interface and is responsible for intercepting the heap analysis process. It checks whether the app has been running for a minimum elapsed time and cancels the analysis if the time is less than a specified threshold. This class is used to prevent analysis of heap dumps that are generated during the early stages of app startup.
package leakcanary
import android.annotation.SuppressLint
import leakcanary.HeapAnalysisInterceptor.Chain
import leakcanary.HeapAnalysisJob.Result
import java.util.concurrent.TimeUnit
@SuppressLint("NewApi")
class MinimumElapsedSinceStartInterceptor(
private val minimumElapsedSinceStartMillis: Long = TimeUnit.SECONDS.toMillis(30),
private val processInfo: ProcessInfo = ProcessInfo.Real
) : HeapAnalysisInterceptor {
override fun intercept(chain: Chain): Result {
if (processInfo.elapsedMillisSinceStart < minimumElapsedSinceStartMillis) {
chain.job.cancel("app started less than $minimumElapsedSinceStartMillis ms ago.")
}
return chain.proceed()
}
}