当前位置: 首页>>代码示例>>Java>>正文


Java ThreadPolicy类代码示例

本文整理汇总了Java中android.os.StrictMode.ThreadPolicy的典型用法代码示例。如果您正苦于以下问题:Java ThreadPolicy类的具体用法?Java ThreadPolicy怎么用?Java ThreadPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ThreadPolicy类属于android.os.StrictMode包,在下文中一共展示了ThreadPolicy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: newThread

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@Override
public synchronized Thread newThread(@NonNull Runnable runnable) {
  final Thread result = new Thread(runnable, "glide-" + name + "-thread-" + threadNum) {
    @Override
    public void run() {
      android.os.Process.setThreadPriority(
          android.os.Process.THREAD_PRIORITY_BACKGROUND
          + android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE);
      if (preventNetworkOperations) {
        StrictMode.setThreadPolicy(
            new ThreadPolicy.Builder()
                .detectNetwork()
                .penaltyDeath()
                .build());
      }
      try {
        super.run();
      } catch (Throwable t) {
        uncaughtThrowableStrategy.handle(t);
      }
    }
  };
  threadNum++;
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:GlideExecutor.java

示例2: getCoreCountPre17

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Determines the number of cores available on the device (pre-v17).
 *
 * <p>Before Jellybean, {@link Runtime#availableProcessors()} returned the number of awake cores,
 * which may not be the number of available cores depending on the device's current state. See
 * https://stackoverflow.com/a/30150409.
 *
 * @return the maximum number of processors available to the VM; never smaller than one
 */
@SuppressWarnings("PMD")
private static int getCoreCountPre17() {
  // We override the current ThreadPolicy to allow disk reads.
  // This shouldn't actually do disk-IO and accesses a device file.
  // See: https://github.com/bumptech/glide/issues/1170
  File[] cpus = null;
  ThreadPolicy originalPolicy = StrictMode.allowThreadDiskReads();
  try {
    File cpuInfo = new File(CPU_LOCATION);
    final Pattern cpuNamePattern = Pattern.compile(CPU_NAME_REGEX);
    cpus = cpuInfo.listFiles(new FilenameFilter() {
      @Override
      public boolean accept(File file, String s) {
        return cpuNamePattern.matcher(s).matches();
      }
    });
  } catch (Throwable t) {
    if (Log.isLoggable(TAG, Log.ERROR)) {
      Log.e(TAG, "Failed to calculate accurate cpu count", t);
    }
  } finally {
    StrictMode.setThreadPolicy(originalPolicy);
  }
  return Math.max(1, cpus != null ? cpus.length : 0);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:RuntimeCompat.java

示例3: newThread

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@Override
public synchronized Thread newThread(@NonNull Runnable runnable) {
  final Thread result = new Thread(runnable, "glide-" + name + "-thread-" + threadNum) {
    @Override
    public void run() {
      android.os.Process.setThreadPriority(DEFAULT_PRIORITY);
      if (preventNetworkOperations) {
        StrictMode.setThreadPolicy(
            new ThreadPolicy.Builder()
                .detectNetwork()
                .penaltyDeath()
                .build());
      }
      try {
        super.run();
      } catch (Throwable t) {
        uncaughtThrowableStrategy.handle(t);
      }
    }
  };
  threadNum++;
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:GlideExecutor.java

示例4: initializeStrictMode

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
private static void initializeStrictMode() {
    if (!strictModeInitialized) {
        if (SDK_INT >= GINGERBREAD) {
            ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
            VmPolicy.Builder     vmPolicy     = new VmPolicy.Builder();

            threadPolicy.detectAll()
                        .penaltyLog();
            vmPolicy.detectAll()
                        .penaltyLog();

            if (STRICT_MODE_KILL_ON_ERROR) {
                threadPolicy.penaltyDeath();
                vmPolicy.penaltyDeath();
            }

            StrictMode.setThreadPolicy(threadPolicy.build());
            StrictMode.setVmPolicy(vmPolicy.build());

            strictModeInitialized = true;
        }
    }
}
 
开发者ID:blstream,项目名称:StudyBox_Android,代码行数:24,代码来源:DebugHelper.java

示例5: zzb

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
public static <T> T zzb(Callable<T> paramCallable)
{
  StrictMode.ThreadPolicy localThreadPolicy = StrictMode.getThreadPolicy();
  try
  {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(localThreadPolicy).permitDiskReads().permitDiskWrites().build());
    Object localObject2 = paramCallable.call();
    return localObject2;
  }
  catch (Throwable localThrowable)
  {
    zzb.e("Unexpected exception.", localThrowable);
    zzp.zzbL().zzb(localThrowable, true);
    return null;
  }
  finally
  {
    StrictMode.setThreadPolicy(localThreadPolicy);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:21,代码来源:zzja.java

示例6: calculateBestThreadCount

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Determines the number of cores available on the device.
 *
 * <p>{@link Runtime#availableProcessors()} returns the number of awake cores, which may not
 * be the number of available cores depending on the device's current state. See
 * http://goo.gl/8H670N.
 */
public static int calculateBestThreadCount() {
  // We override the current ThreadPolicy to allow disk reads.
  // This shouldn't actually do disk-IO and accesses a device file.
  // See: https://github.com/bumptech/glide/issues/1170
  ThreadPolicy originalPolicy = StrictMode.allowThreadDiskReads();
  File[] cpus = null;
  try {
    File cpuInfo = new File(CPU_LOCATION);
    final Pattern cpuNamePattern = Pattern.compile(CPU_NAME_REGEX);
    cpus = cpuInfo.listFiles(new FilenameFilter() {
      @Override
      public boolean accept(File file, String s) {
        return cpuNamePattern.matcher(s).matches();
      }
    });
  } catch (Throwable t) {
    if (Log.isLoggable(TAG, Log.ERROR)) {
      Log.e(TAG, "Failed to calculate accurate cpu count", t);
    }
  } finally {
    StrictMode.setThreadPolicy(originalPolicy);
  }

  int cpuCount = cpus != null ? cpus.length : 0;
  int availableProcessors = Math.max(1, Runtime.getRuntime().availableProcessors());
  return Math.min(MAXIMUM_AUTOMATIC_THREAD_COUNT, Math.max(availableProcessors, cpuCount));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:GlideExecutor.java

示例7: enableStrictMode

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
private void enableStrictMode() {
	if (TESTING) {
		ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
		threadPolicy.detectAll();
		threadPolicy.penaltyLog();
		StrictMode.setThreadPolicy(threadPolicy.build());
		VmPolicy.Builder vmPolicy = new VmPolicy.Builder();
		vmPolicy.detectAll();
		vmPolicy.penaltyLog();
		StrictMode.setVmPolicy(vmPolicy.build());
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:13,代码来源:SplashScreenActivity.java

示例8: resolveActivity

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Retrieves the single activity that matches the given intent, or null if none found.
 * @param intent The intent to query.
 * @return The matching activity.
 */
public ResolveInfo resolveActivity(Intent intent) {
    ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ContextUtils.getApplicationContext().getPackageManager().resolveActivity(
                intent, 0);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:15,代码来源:PackageManagerDelegate.java

示例9: getActivitiesThatCanRespondToIntent

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Retrieves the list of activities that can respond to the given intent.
 * @param intent The intent to query.
 * @return The list of activities that can respond to the intent.
 */
public List<ResolveInfo> getActivitiesThatCanRespondToIntent(Intent intent) {
    ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ContextUtils.getApplicationContext().getPackageManager().queryIntentActivities(
                intent, 0);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:15,代码来源:PackageManagerDelegate.java

示例10: getActivitiesThatCanRespondToIntentWithMetaData

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Retrieves the list of activities that can respond to the given intent. And returns the
 * activites' meta data in ResolveInfo.
 *
 * @param intent The intent to query.
 * @return The list of activities that can respond to the intent.
 */
public List<ResolveInfo> getActivitiesThatCanRespondToIntentWithMetaData(Intent intent) {
    ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ContextUtils.getApplicationContext().getPackageManager().queryIntentActivities(
                intent, PackageManager.GET_META_DATA);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:17,代码来源:PackageManagerDelegate.java

示例11: getServicesThatCanRespondToIntent

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Retrieves the list of services that can respond to the given intent.
 * @param intent The intent to query.
 * @return The list of services that can respond to the intent.
 */
public List<ResolveInfo> getServicesThatCanRespondToIntent(Intent intent) {
    ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ContextUtils.getApplicationContext().getPackageManager().queryIntentServices(
                intent, 0);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:15,代码来源:PackageManagerDelegate.java

示例12: enableNasty

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static Object enableNasty() {
	ThreadPolicy oldThreadPolicy = StrictMode.getThreadPolicy();
	StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
	StrictMode.setThreadPolicy(policy);
	return oldThreadPolicy;
}
 
开发者ID:vuze,项目名称:vuze-remote-for-android,代码行数:8,代码来源:RPC.java

示例13: revertNasty

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static void revertNasty(@Nullable ThreadPolicy oldPolicy) {
	if (oldPolicy == null) {
		return;
	}
	StrictMode.setThreadPolicy(oldPolicy);
}
 
开发者ID:vuze,项目名称:vuze-remote-for-android,代码行数:8,代码来源:RPC.java

示例14: permit

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * @param policy
 * @param runnable
 * @return
 */
@TargetApi(VERSION_CODES.HONEYCOMB)
public void permit(final Policy.Thread policy, final Runnable runnable) {
    final ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
    final ThreadPolicy.Builder builder = new ThreadPolicy.Builder(oldPolicy);

    switch (policy) {
        case PermitAll: {
            builder.permitAll();
            break;
        }
        case PermitCustomSlowCalls: {
            if (AndroidUtils.isAtLeastHoneycomb()) {
                builder.permitCustomSlowCalls();
            }
            break;
        }
        case PermitDiskReads: {
            builder.permitDiskReads();
            break;
        }
        case PermitDiskWrites: {
            builder.permitDiskWrites();
            break;
        }
        case PermitNetwork: {
            builder.permitNetwork();
            break;
        }
    }

    StrictMode.setThreadPolicy(builder.build());

    if (runnable != null) {
        runnable.run();
    }

    StrictMode.setThreadPolicy(oldPolicy);
}
 
开发者ID:remelpugh,项目名称:android-shared,代码行数:44,代码来源:StrictModeHelper.java

示例15: reset

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * @return The current instance of {@link StrictModeHelper}.
 */
public StrictModeHelper reset() {
    if (!AppHelper.with(context).isDebuggable()) {
        return this;
    }

    threadBuilder = new ThreadPolicy.Builder();
    vmBuilder = new VmPolicy.Builder();

    return this;
}
 
开发者ID:remelpugh,项目名称:android-shared,代码行数:14,代码来源:StrictModeHelper.java


注:本文中的android.os.StrictMode.ThreadPolicy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。