android.os.StrictMode#getThreadPolicy ( )源码实例Demo

下面列出了android.os.StrictMode#getThreadPolicy ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: SliceProvider.java
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);
    }
}
 
源代码2 项目: cronet   文件: StrictModeContext.java
/**
 * 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);
}
 
源代码3 项目: xmrwallet   文件: Helper.java
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);
    }
}
 
private void initFabricLax() {
    StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
    StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.LAX);
    try {
        initFabric();
    }
    finally {
        StrictMode.setThreadPolicy(old);
    }
}
 
源代码5 项目: ProjectX   文件: Utils.java
/**
 * 检查端口是否可用
 *
 * @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;
}
 
源代码6 项目: AppOpsXposed   文件: XUtils.java
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);
}
 
源代码7 项目: android-chromium   文件: SyncStatusHelper.java
/**
 * 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;
}
 
源代码8 项目: android-chromium   文件: SyncStatusHelper.java
/**
 * 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;
}
 
源代码9 项目: caffeine   文件: StrictModeUtilsTest.java
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.
}