main

square/leakcanary

Last updated at: 29/12/2023 09:38

Handlers.kt

TLDR

This file provides utility functions and variables related to handlers and threads in the LeakCanary library.

Methods

There are no methods defined in this file.

Classes

There are no classes defined in this file.

package org.leakcanary.util

import android.os.Handler
import android.os.Looper

val mainHandler by lazy { Handler(Looper.getMainLooper()) }

val isMainThread: Boolean get() = Looper.getMainLooper().thread === Thread.currentThread()

fun checkMainThread() {
  check(isMainThread) {
    "Should be called from the main thread, not ${Thread.currentThread()}"
  }
}

fun checkNotMainThread() {
  check(!isMainThread) {
    "Should not be called from the main thread"
  }
}