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


Java StrictMode.setThreadPolicy方法代码示例

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


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

示例1: enableStrictMode

import android.os.StrictMode; //导入方法依赖的package包/类
@TargetApi(VERSION_CODES.HONEYCOMB)
public static void enableStrictMode() {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
                new StrictMode.ThreadPolicy.Builder()
                        .detectAll()
                        .penaltyLog();
        StrictMode.VmPolicy.Builder vmPolicyBuilder =
                new StrictMode.VmPolicy.Builder()
                        .detectAll()
                        .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            vmPolicyBuilder
                    .setClassInstanceLimit(ImageGridActivity.class, 1)
                    .setClassInstanceLimit(ImageDetailActivity.class, 1);
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}
 
开发者ID:jjuiddong,项目名称:Android-Practice,代码行数:23,代码来源:Utils.java

示例2: isFolderAlreadyExists

import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public boolean isFolderAlreadyExists(String folder) {
    ListFolderResult dropboxFolders = null;
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        try {
            String dir = "/" + folder.substring(0, folder.lastIndexOf("/"));
            dropboxFolders = DropboxClientFactory.getClient().files().listFolder(dir);
        } catch (DbxException e) {
            e.printStackTrace();
        }
    }
    if (dropboxFolders != null) {
        Log.d(TAG, dropboxFolders.toString());
        String s = dropboxFolders.toStringMultiline();
        if (s.contains("/" + folder))
            return true;
    }
    return false;
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:22,代码来源:DropboxManager.java

示例3: startActivityIfNeeded

import android.os.StrictMode; //导入方法依赖的package包/类
@Override
public boolean startActivityIfNeeded(Intent intent, boolean proxy) {
    boolean activityWasLaunched;
    // Only touches disk on Kitkat. See http://crbug.com/617725 for more context.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites();
    StrictMode.allowThreadDiskReads();
    try {
        forcePdfViewerAsIntentHandlerIfNeeded(mApplicationContext, intent);
        if (proxy) {
            dispatchAuthenticatedIntent(intent);
            activityWasLaunched = true;
        } else {
            Context context = getAvailableContext();
            if (context instanceof Activity) {
                activityWasLaunched = ((Activity) context).startActivityIfNeeded(intent, -1);
            } else {
                activityWasLaunched = false;
            }
        }
        if (activityWasLaunched) recordExternalNavigationDispatched(intent);
        return activityWasLaunched;
    } catch (RuntimeException e) {
        IntentUtils.logTransactionTooLargeOrRethrow(e, intent);
        return false;
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:29,代码来源:ExternalNavigationDelegateImpl.java

示例4: enableStrictMode

import android.os.StrictMode; //导入方法依赖的package包/类
@SuppressLint("NewApi")
public static void enableStrictMode() {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
                new StrictMode.ThreadPolicy.Builder()
                        .detectAll()
                        .penaltyLog();
        StrictMode.VmPolicy.Builder vmPolicyBuilder =
                new StrictMode.VmPolicy.Builder()
                        .detectAll()
                        .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            vmPolicyBuilder
                    .setClassInstanceLimit(ImageGridActivity.class, 1);
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }


}
 
开发者ID:mangestudio,项目名称:GCSApp,代码行数:24,代码来源:Utils.java

示例5: verifyStoragePermissions

import android.os.StrictMode; //导入方法依赖的package包/类
public static void verifyStoragePermissions(Activity activity) {
    // Check if we have write permission
    int permission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE);

    if (permission != PackageManager.PERMISSION_GRANTED) {
        // We don't have permission so prompt the user
        ActivityCompat.requestPermissions(
                activity,
                PERMISSIONS_STORAGE,
                REQUEST_EXTERNAL_STORAGE
        );
    }
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4Android,代码行数:18,代码来源:MainActivity.java

示例6: newThread

import android.os.StrictMode; //导入方法依赖的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

示例7: maybeEnable

import android.os.StrictMode; //导入方法依赖的package包/类
/** @see TraceEvent#MaybeEnableEarlyTracing().
 */
@SuppressFBWarnings("DMI_HARDCODED_ABSOLUTE_FILENAME")
static void maybeEnable() {
    boolean shouldEnable = false;
    // Checking for the trace config filename touches the disk.
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        if (CommandLine.isInitialized()
                && CommandLine.getInstance().hasSwitch("trace-startup")) {
            shouldEnable = true;
        } else {
            try {
                shouldEnable = (new File(TRACE_CONFIG_FILENAME)).exists();
            } catch (SecurityException e) {
                // Access denied, not enabled.
            }
        }
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
    if (shouldEnable) enable();
}
 
开发者ID:lizhangqu,项目名称:chromium-net-for-android,代码行数:24,代码来源:EarlyTraceEvent.java

示例8: enableStrictModeForDebug

import android.os.StrictMode; //导入方法依赖的package包/类
private void enableStrictModeForDebug() {
    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()   // or .detectAll() for all detectable problems
                .penaltyLog()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectLeakedSqlLiteObjects()
                .detectLeakedClosableObjects()
                .penaltyLog()
                .penaltyDeath()
                .build());
    }
}
 
开发者ID:cahergil,项目名称:Farmacias,代码行数:17,代码来源:MainActivity.java

示例9: enableStrictMode

import android.os.StrictMode; //导入方法依赖的package包/类
/**
 * 需要设置哪个页面的限制缓存到VM中
 */
@TargetApi(11)
public static void enableStrictMode(Class<?> clazz) {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder =
                new StrictMode.ThreadPolicy.Builder()
                        .detectAll()
                        .penaltyLog();
        StrictMode.VmPolicy.Builder vmPolicyBuilder =
                new StrictMode.VmPolicy.Builder()
                        .detectAll()
                        .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            vmPolicyBuilder.setClassInstanceLimit(clazz, 1);
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}
 
开发者ID:PlutoArchitecture,项目名称:Pluto-Android,代码行数:24,代码来源:Utils.java

示例10: checkGooglePlayServicesAvailable

import android.os.StrictMode; //导入方法依赖的package包/类
/**
 * Invokes whatever external code is necessary to check if Google Play Services is available
 * and returns the code produced by the attempt. Subclasses can override to force the behavior
 * one way or another, or to change the way that the check is performed.
 * @param context The current context.
 * @return The code produced by calling the external code
 */
protected int checkGooglePlayServicesAvailable(final Context context) {
    // Temporarily allowing disk access. TODO: Fix. See http://crbug.com/577190
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        long time = SystemClock.elapsedRealtime();
        int isAvailable =
                GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context);
        mRegistrationTimeHistogramSample.record(SystemClock.elapsedRealtime() - time);
        return isAvailable;
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:22,代码来源:ExternalAuthUtils.java

示例11: calculateBestThreadCount

import android.os.StrictMode; //导入方法依赖的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

示例12: turnOnStrictMode

import android.os.StrictMode; //导入方法依赖的package包/类
private void turnOnStrictMode() {
    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDeath()
                .build());
    }
}
 
开发者ID:TigranSarkisian,项目名称:Boilerplate,代码行数:14,代码来源:TlApplication.java

示例13: enabledStrictMode

import android.os.StrictMode; //导入方法依赖的package包/类
private void enabledStrictMode() {
    if (SDK_INT >= GINGERBREAD) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDeath()
                .build());
    }
}
 
开发者ID:mainh,项目名称:MainCalendar,代码行数:10,代码来源:MainApplication.java

示例14: onCreate

import android.os.StrictMode; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressWarnings("unused")
@Override
public void onCreate() {
	if (Constants.Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
		StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
		StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
	}

	super.onCreate();

	initImageLoader(getApplicationContext());
}
 
开发者ID:siwangqishiq,项目名称:ImageLoaderSupportGif,代码行数:14,代码来源:UILApplication.java

示例15: LoginRefresh

import android.os.StrictMode; //导入方法依赖的package包/类
public LoginRefresh(Context context,PreferencesShared pref) throws IOException {
    this.context = context;
    preferencesShared = pref;
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    con = (HttpURLConnection) (new URL(this.context.getString(R.string.api_url)+this.context.getString(R.string.login_url))).openConnection();
    con.setRequestMethod("POST");
    con.setDoInput(true);
    con.setDoOutput(true);
    con.setUseCaches(true);
    con.connect();

}
 
开发者ID:TudorRosca,项目名称:enklave,代码行数:14,代码来源:LoginRefresh.java


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