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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBlockGuard.BlockGuardPolicyExceptionstatic interfaceBlockGuard.Policy -
Field Summary
Fields Modifier and Type Field Description static intDISALLOW_DISK_READstatic intDISALLOW_DISK_WRITEstatic intDISALLOW_NETWORKstatic BlockGuard.PolicyLAX_POLICYThe default, permissive policy that doesn't prevent any operations.static intPASS_RESTRICTIONS_VIA_RPCstatic intPENALTY_DEATHstatic intPENALTY_DIALOGstatic intPENALTY_LOG -
Method Summary
Modifier and Type Method Description static BlockGuard.PolicygetThreadPolicy()Get the current thread's policy.static voidsetThreadPolicy(BlockGuard.Policy policy)Sets the current thread's block guard policy.
-
Field Details
-
DISALLOW_DISK_WRITE
public static final int DISALLOW_DISK_WRITE- See Also:
- Constant Field Values
-
DISALLOW_DISK_READ
public static final int DISALLOW_DISK_READ- See Also:
- Constant Field Values
-
DISALLOW_NETWORK
public static final int DISALLOW_NETWORK- See Also:
- Constant Field Values
-
PASS_RESTRICTIONS_VIA_RPC
public static final int PASS_RESTRICTIONS_VIA_RPC- See Also:
- Constant Field Values
-
PENALTY_LOG
public static final int PENALTY_LOG- See Also:
- Constant Field Values
-
PENALTY_DIALOG
public static final int PENALTY_DIALOG- See Also:
- Constant Field Values
-
PENALTY_DEATH
public static final int PENALTY_DEATH- See Also:
- Constant Field Values
-
LAX_POLICY
The default, permissive policy that doesn't prevent any operations.
-
-
Method Details
-
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
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.
-