Package dalvik.system

Class BlockGuard

java.lang.Object
dalvik.system.BlockGuard

public final class BlockGuard
extends Object
Mechanism to let threads set restrictions on what code is allowed to do in their thread.

This is meant for applications to prevent certain blocking operations from running on their main event loop (or "UI") threads.

Note that this is all best-effort to catch most accidental mistakes and isn't intended to be a perfect mechanism, nor provide any sort of security.

  • Field Details

  • Method Details

    • getThreadPolicy

      public static BlockGuard.Policy getThreadPolicy()
      Get the current thread's policy.
      Returns:
      the current thread's policy. Never returns null. Will return the LAX_POLICY instance if nothing else is set.
    • setThreadPolicy

      public static void setThreadPolicy​(BlockGuard.Policy policy)
      Sets the current thread's block guard policy.
      Parameters:
      policy - policy to set. May not be null. Use the public LAX_POLICY if you want to unset the active policy.