xref: /aosp_15_r20/external/leakcanary2/leakcanary-android-utils/src/main/java/leakcanary/internal/Handlers.kt (revision d9e8da70d8c9df9a41d7848ae506fb3115cae6e6)
1 package leakcanary.internal
2 
3 import android.os.Handler
4 import android.os.Looper
5 
<lambda>null6 internal val mainHandler by lazy { Handler(Looper.getMainLooper()) }
7 
8 internal val isMainThread: Boolean get() = Looper.getMainLooper().thread === Thread.currentThread()
9 
checkMainThreadnull10 internal fun checkMainThread() {
11   check(isMainThread) {
12     "Should be called from the main thread, not ${Thread.currentThread()}"
13   }
14 }
15 
checkNotMainThreadnull16 internal fun checkNotMainThread() {
17   check(!isMainThread) {
18     "Should not be called from the main thread"
19   }
20 }
21