Java Code Examples for dalvik.system.BlockGuard#getThreadPolicy()
The following examples show how to use
dalvik.system.BlockGuard#getThreadPolicy() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StrictMode.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Called from Parcel.readException() when the exception is EX_STRICT_MODE_VIOLATIONS, we here * read back all the encoded violations. */ /* package */ static void readAndHandleBinderCallViolations(Parcel p) { Throwable localCallSite = new Throwable(); final int policyMask = getThreadPolicyMask(); final boolean currentlyGathering = (policyMask & PENALTY_GATHER) != 0; final int size = p.readInt(); for (int i = 0; i < size; i++) { final ViolationInfo info = new ViolationInfo(p, !currentlyGathering); info.addLocalStack(localCallSite); BlockGuard.Policy policy = BlockGuard.getThreadPolicy(); if (policy instanceof AndroidBlockGuardPolicy) { ((AndroidBlockGuardPolicy) policy).handleViolationWithTimingAttempt(info); } } }
Example 2
Source File: StrictMode.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static void setBlockGuardPolicy(final int policyMask) { if (policyMask == 0) { BlockGuard.setThreadPolicy(BlockGuard.LAX_POLICY); return; } final BlockGuard.Policy policy = BlockGuard.getThreadPolicy(); final AndroidBlockGuardPolicy androidPolicy; if (policy instanceof AndroidBlockGuardPolicy) { androidPolicy = (AndroidBlockGuardPolicy) policy; } else { androidPolicy = THREAD_ANDROID_POLICY.get(); BlockGuard.setThreadPolicy(androidPolicy); } androidPolicy.setPolicyMask(policyMask); }
Example 3
Source File: StrictMode.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * For code to note that it's slow. This is a no-op unless the current thread's {@link * android.os.StrictMode.ThreadPolicy} has {@link * android.os.StrictMode.ThreadPolicy.Builder#detectCustomSlowCalls} enabled. * * @param name a short string for the exception stack trace that's built if when this fires. */ public static void noteSlowCall(String name) { BlockGuard.Policy policy = BlockGuard.getThreadPolicy(); if (!(policy instanceof AndroidBlockGuardPolicy)) { // StrictMode not enabled. return; } ((AndroidBlockGuardPolicy) policy).onCustomSlowCall(name); }
Example 4
Source File: StrictMode.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * For code to note that a resource was obtained using a type other than its defined type. This * is a no-op unless the current thread's {@link android.os.StrictMode.ThreadPolicy} has {@link * android.os.StrictMode.ThreadPolicy.Builder#detectResourceMismatches()} enabled. * * @param tag an object for the exception stack trace that's built if when this fires. * @hide */ public static void noteResourceMismatch(Object tag) { BlockGuard.Policy policy = BlockGuard.getThreadPolicy(); if (!(policy instanceof AndroidBlockGuardPolicy)) { // StrictMode not enabled. return; } ((AndroidBlockGuardPolicy) policy).onResourceMismatch(tag); }
Example 5
Source File: StrictMode.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ public static void noteUnbufferedIO() { BlockGuard.Policy policy = BlockGuard.getThreadPolicy(); if (!(policy instanceof AndroidBlockGuardPolicy)) { // StrictMode not enabled. return; } policy.onUnbufferedIO(); }
Example 6
Source File: StrictMode.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ public static void noteDiskRead() { BlockGuard.Policy policy = BlockGuard.getThreadPolicy(); if (!(policy instanceof AndroidBlockGuardPolicy)) { // StrictMode not enabled. return; } policy.onReadFromDisk(); }
Example 7
Source File: StrictMode.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** @hide */ public static void noteDiskWrite() { BlockGuard.Policy policy = BlockGuard.getThreadPolicy(); if (!(policy instanceof AndroidBlockGuardPolicy)) { // StrictMode not enabled. return; } policy.onWriteToDisk(); }
Example 8
Source File: URLTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testHashCodeAndEqualsDoesNotPerformNetworkIo() throws Exception { final BlockGuard.Policy oldPolicy = BlockGuard.getThreadPolicy(); BlockGuard.setThreadPolicy(new BlockGuard.Policy() { @Override public void onWriteToDisk() { fail("Blockguard.Policy.onWriteToDisk"); } @Override public void onReadFromDisk() { fail("Blockguard.Policy.onReadFromDisk"); } @Override public void onNetwork() { fail("Blockguard.Policy.onNetwork"); } @Override public int getPolicyMask() { return 0; } }); try { URL url = new URL("http://www.google.com/"); URL url2 = new URL("http://www.nest.com/"); url.equals(url2); url2.hashCode(); } finally { BlockGuard.setThreadPolicy(oldPolicy); } }