Java Code Examples for android.os.StrictMode#getThreadPolicy()
The following examples show how to use
android.os.StrictMode#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: SliceProvider.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private Slice onBindSliceStrict(Uri sliceUri, List<SliceSpec> supportedSpecs) { ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); try { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyDeath() .build()); return onBindSlice(sliceUri, new ArraySet<>(supportedSpecs)); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example 2
Source File: StrictModeContext.java From cronet with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Convenience method for disabling StrictMode for slow calls with try-with-resources. */ public static StrictModeContext allowSlowCalls() { StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder(oldPolicy).permitCustomSlowCalls().build()); return new StrictModeContext(oldPolicy); }
Example 3
Source File: Helper.java From xmrwallet with Apache License 2.0 | 5 votes |
static public boolean runWithNetwork(Action action) { StrictMode.ThreadPolicy currentPolicy = StrictMode.getThreadPolicy(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build(); StrictMode.setThreadPolicy(policy); try { return action.run(); } finally { StrictMode.setThreadPolicy(currentPolicy); } }
Example 4
Source File: InitContentProvider.java From white-label-event-app with Apache License 2.0 | 5 votes |
private void initFabricLax() { StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy(); StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX); try { initFabric(); } finally { StrictMode.setThreadPolicy(old); } }
Example 5
Source File: Utils.java From ProjectX with Apache License 2.0 | 5 votes |
/** * 检查端口是否可用 * * @param port 端口 * @return 是否可用 */ public static boolean isPortAvailable(int port) { boolean available; StrictMode.ThreadPolicy defaultPolicy = StrictMode.getThreadPolicy(); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); try { bindPort("0.0.0.0", port); bindPort(InetAddress.getLocalHost().getHostAddress(), port); available = true; } catch (IOException e) { available = false; } StrictMode.setThreadPolicy(defaultPolicy); return available; }
Example 6
Source File: XUtils.java From AppOpsXposed with GNU General Public License v3.0 | 5 votes |
public static void reloadPrefs() { if(Res.modPrefs == null) return; final StrictMode.ThreadPolicy tp = StrictMode.getThreadPolicy(); StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX); Res.modPrefs.reload(); StrictMode.setThreadPolicy(tp); }
Example 7
Source File: SyncStatusHelper.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * Sets a new StrictMode.ThreadPolicy based on the current one, but allows disk reads * and disk writes. * * The return value is the old policy, which must be applied after the disk access is finished, * by using StrictMode.setThreadPolicy(oldPolicy). * * @return the policy before allowing reads and writes. */ private static StrictMode.ThreadPolicy temporarilyAllowDiskWritesAndDiskReads() { StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); StrictMode.ThreadPolicy.Builder newPolicy = new StrictMode.ThreadPolicy.Builder(oldPolicy); newPolicy.permitDiskReads(); newPolicy.permitDiskWrites(); StrictMode.setThreadPolicy(newPolicy.build()); return oldPolicy; }
Example 8
Source File: SyncStatusHelper.java From android-chromium with BSD 2-Clause "Simplified" License | 5 votes |
/** * Sets a new StrictMode.ThreadPolicy based on the current one, but allows disk reads * and disk writes. * * The return value is the old policy, which must be applied after the disk access is finished, * by using StrictMode.setThreadPolicy(oldPolicy). * * @return the policy before allowing reads and writes. */ private static StrictMode.ThreadPolicy temporarilyAllowDiskWritesAndDiskReads() { StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy(); StrictMode.ThreadPolicy.Builder newPolicy = new StrictMode.ThreadPolicy.Builder(oldPolicy); newPolicy.permitDiskReads(); newPolicy.permitDiskWrites(); StrictMode.setThreadPolicy(newPolicy.build()); return oldPolicy; }
Example 9
Source File: StrictModeUtilsTest.java From caffeine with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void testEnableStrictModeForDevRelease() { StrictModeUtils.enableStrictModeForDevRelease(); StrictMode.ThreadPolicy threadPolicy = StrictMode.getThreadPolicy(); //No way to test this, uses masks that we don't have access to. //Is is to make sure no crashes occur. }