Java 类android.os.StrictMode 实例源码

项目:GitHub    文件:WeatherApplication.java   
@Override
    public void onCreate() {
        super.onCreate();
        Log.d(TAG, "onCreate start");
        if (BuildConfig.DEBUG) {
            StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
        }

        applicationComponent = DaggerApplicationComponent.builder()
                .applicationModule(new ApplicationModule(this))
                .build();

//        Fabric.with(this, new Crashlytics());
        Stetho.initializeWithDefaults(this.getApplicationContext());

        weatherApplicationInstance = this;

        //初始化ApiClient
        ApiConfiguration apiConfiguration = ApiConfiguration.builder()
                .dataSourceType(ApiConstants.WEATHER_DATA_SOURCE_TYPE_KNOW)
                .build();
        ApiClient.init(apiConfiguration);
        Log.d(TAG, "onCreate end");
    }
项目:GitHub    文件:RuntimeCompat.java   
/**
 * 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);
}
项目:GitHub    文件:GlideExecutor.java   
@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;
}
项目:Pluto-Android    文件:Utils.java   
/**
 * 需要设置哪个页面的限制缓存到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());
    }
}
项目:MvpPlus    文件:StrictModeWrapper.java   
public static void init(Context context) {
    // check if android:debuggable is set to true
    int appFlags = context.getApplicationInfo().flags;
    if ((appFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectDiskReads()
                .detectDiskWrites()
                .detectNetwork()
                .penaltyLog()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectLeakedSqlLiteObjects()
                .penaltyLog()
                .penaltyDeath()
                .build());
    }
}
项目:CurrentActivity    文件:CurrentActivity.java   
private void initStrictMode() {
    StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder()
            .detectDiskReads()
            .detectDiskWrites()
            .detectNetwork()
            .detectCustomSlowCalls()
            .penaltyDeath();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        threadPolicyBuilder.detectResourceMismatches();
    }

    StrictMode.setThreadPolicy(threadPolicyBuilder.build());

    StrictMode.setVmPolicy(
            new StrictMode.VmPolicy.Builder()
                    .detectLeakedSqlLiteObjects()
                    .detectLeakedClosableObjects()
                    .detectLeakedRegistrationObjects()
                    .detectActivityLeaks()
                    .penaltyDeath()
                    .build()
    );
}
项目:moppepojkar    文件:Settings.java   
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);


     StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
     StrictMode.setThreadPolicy(policy);

    setContentView(R.layout.socket_connection_build);
    ed_host = (EditText) findViewById(R.id.ed_host);
    ed_port = (EditText) findViewById(R.id.ed_port);
    btn_connect = (Button) findViewById(R.id.btn_connect);

    /* Fetch earlier defined host ip and port numbers and write them as default 
     * (to avoid retyping this, typically standard, info) */
    SharedPreferences mSharedPreferences = getSharedPreferences("list",MODE_PRIVATE);
    String oldHost = mSharedPreferences.getString("host", null); 
    if (oldHost != null)
        ed_host.setText(oldHost);
    int oldPortCommunicator = mSharedPreferences.getInt("port",0);
    if (oldPortCommunicator != 0)
        ed_port.setText(Integer.toString(oldPortCommunicator));



}
项目:chromium-net-for-android    文件:PathUtils.java   
/**
 * @return the public downloads directory.
 */
@SuppressWarnings("unused")
@CalledByNative
private static String getDownloadsDirectory(Context appContext) {
    // Temporarily allowing disk access while fixing. TODO: http://crbug.com/508615
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    String downloadsPath;
    try {
        long time = SystemClock.elapsedRealtime();
        downloadsPath = Environment.getExternalStoragePublicDirectory(
                Environment.DIRECTORY_DOWNLOADS).getPath();
        RecordHistogram.recordTimesHistogram("Android.StrictMode.DownloadsDir",
                SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
    return downloadsPath;
}
项目:chromium-net-for-android    文件:EarlyTraceEvent.java   
/** @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();
}
项目:chromium-net-for-android    文件:UploadDataProvidersTest.java   
@SuppressFBWarnings("DM_GC") // Used to trigger strictmode detecting leaked closeables
@Override
protected void tearDown() throws Exception {
    try {
        NativeTestServer.shutdownNativeTestServer();
        mTestFramework.mCronetEngine.shutdown();
        assertTrue(mFile.delete());
        // Run GC and finalizers a few times to pick up leaked closeables
        for (int i = 0; i < 10; i++) {
            System.gc();
            System.runFinalization();
        }
        System.gc();
        System.runFinalization();
        super.tearDown();
    } finally {
        StrictMode.setVmPolicy(mOldVmPolicy);
    }
}
项目:chromium-net-for-android    文件:CronetUrlRequestContextTest.java   
public Thread newThread(final Runnable r) {
    mNetworkQualityThread = new Thread(new Runnable() {
        @Override
        public void run() {
            StrictMode.ThreadPolicy threadPolicy = StrictMode.getThreadPolicy();
            try {
                StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                                                   .detectNetwork()
                                                   .penaltyLog()
                                                   .penaltyDeath()
                                                   .build());
                r.run();
            } finally {
                StrictMode.setThreadPolicy(threadPolicy);
            }
        }
    });
    return mNetworkQualityThread;
}
项目:javaide    文件:JecApp.java   
@Override
public void onCreate() {
    super.onCreate();
    context = getApplicationContext();

    if (startupTimestamp == 0)
        startupTimestamp = System.currentTimeMillis();

    if (SysUtils.isDebug(this))
    {
        L.debug = true;
        //内存泄漏监控
        StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
        builder.detectAll();
        builder.penaltyLog();
        StrictMode.setVmPolicy(builder.build());
    }
    installMonitor();
}
项目:GCSApp    文件:Utils.java   
@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());
    }


}
项目:sekai    文件:AdUnitsSampleApplication.java   
@Override
public void onCreate() {
    super.onCreate();

    DebugSettings.initialize(this);
    if (DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
    }
}
项目:MDRXL    文件:SampleApplication.java   
@Override
public void onCreate() {
    super.onCreate();
    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(DISK_THREAD_POLICY);
        StrictMode.setVmPolicy(DISK_VM_POLICY);
    }

    applicationComponent = DaggerApplicationComponent.builder()
            .commonModule(new CommonModule(this))
            .build();

    for (final ProfilingProcessor processor : applicationComponent.profilingProcessors()) {
        processor.enable();
    }
}
项目:Dendroid-HTTP-RAT    文件:MyService.java   
public boolean isNetworkAvailable() {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        return true;

//        ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
//        NetworkInfo netInfo = cm.getActiveNetworkInfo();
//        if (netInfo != null && netInfo.isConnected()) {
//            try {
//                URL url = new URL("http://www.google.com");
//                HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
//                urlc.setConnectTimeout(3000);
//                urlc.connect();
//                if (urlc.getResponseCode() == 200) {
//                    return new Boolean(true);
//                }
//            } catch (MalformedURLException e1) {
//                // TODO Auto-generated catch block
//                e1.printStackTrace();
//            } catch (IOException e) {
//                // TODO Auto-generated catch block
//                e.printStackTrace();
//            }
//        }
//        return false;
    }
项目:chromium-for-android-56-debug-video    文件:WebappActivity.java   
/**
 * Saves the tab data out to a file.
 */
void saveState(File activityDirectory) {
    String tabFileName = TabState.getTabStateFilename(getActivityTab().getId(), false);
    File tabFile = new File(activityDirectory, tabFileName);

    // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        long time = SystemClock.elapsedRealtime();
        TabState.saveState(tabFile, getActivityTab().getState(), false);
        RecordHistogram.recordTimesHistogram("Android.StrictMode.WebappSaveState",
                SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
项目:DisplayingBitmaps    文件:Utils.java   
@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());
    }
}
项目:chromium-for-android-56-debug-video    文件:WebappDirectoryManager.java   
/**
 * Returns the directory for a web app, creating it if necessary.
 * @param webappId ID for the web app.  Used as a subdirectory name.
 * @return File for storing information about the web app.
 */
File getWebappDirectory(Context context, String webappId) {
    // Temporarily allowing disk access while fixing. TODO: http://crbug.com/525781
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        long time = SystemClock.elapsedRealtime();
        File webappDirectory = new File(getBaseWebappDirectory(context), webappId);
        if (!webappDirectory.exists() && !webappDirectory.mkdir()) {
            Log.e(TAG, "Failed to create web app directory.");
        }
        RecordHistogram.recordTimesHistogram("Android.StrictMode.WebappDir",
                SystemClock.elapsedRealtime() - time, TimeUnit.MILLISECONDS);
        return webappDirectory;
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
项目:chromium-for-android-56-debug-video    文件:BackgroundSyncLauncher.java   
private static boolean removeScheduledTasks(GcmNetworkManager scheduler) {
    // Third-party code causes broadcast to touch disk. http://crbug.com/614679
    StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        scheduler.cancelTask(TASK_TAG, ChromeBackgroundService.class);
    } catch (IllegalArgumentException e) {
        // This occurs when BackgroundSyncLauncherService is not found in the application
        // manifest. This should not happen in code that reaches here, but has been seen in
        // the past. See https://crbug.com/548314
        // Disable GCM for the remainder of this session.
        setGCMEnabled(false);
        // Return false so that the failure will be logged.
        return false;
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
    return true;
}
项目:chromium-for-android-56-debug-video    文件:FeatureUtilities.java   
/**
 * @return Which flavor of Herb is being tested.
 *         See {@link ChromeSwitches#HERB_FLAVOR_ELDERBERRY} and its related switches.
 */
public static String getHerbFlavor() {
    Context context = ContextUtils.getApplicationContext();
    if (isHerbDisallowed(context)) return ChromeSwitches.HERB_FLAVOR_DISABLED;

    if (!sIsHerbFlavorCached) {
        sCachedHerbFlavor = null;

        // Allowing disk access for preferences while prototyping.
        StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
        try {
            sCachedHerbFlavor =
                    ChromePreferenceManager.getInstance(context).getCachedHerbFlavor();
        } finally {
            StrictMode.setThreadPolicy(oldPolicy);
        }

        sIsHerbFlavorCached = true;
        Log.d(TAG, "Retrieved cached Herb flavor: " + sCachedHerbFlavor);
    }

    return sCachedHerbFlavor;
}
项目:GitHub    文件:GlideExecutor.java   
/**
 * 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));
}
项目:Boilerplate    文件:TlApplication.java   
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());
    }
}
项目:GitHub    文件:SampleApplication.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setStrictMode() {
    if (Integer.valueOf(Build.VERSION.SDK) > 3) {
        Log.d(LOG_TAG, "Enabling StrictMode policy over Sample application");
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDeath()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
    }
}
项目:KTools    文件:KApplication.java   
private void enableThreadPolicy() {
    StrictMode.setThreadPolicy(
            new StrictMode.ThreadPolicy.Builder()
                    .detectAll()
                    .penaltyLog()
                    .build()
    );
}
项目:ImageLoaderSupportGif    文件:UILApplication.java   
@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());
}
项目:GitHub    文件:MockGlideExecutor.java   
@Override
public void execute(@NonNull final Runnable command) {
  delegate.execute(new Runnable() {
    @Override
    public void run() {
      StrictMode.ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
      StrictMode.setThreadPolicy(THREAD_POLICY);
      try {
        command.run();
      } finally {
        StrictMode.setThreadPolicy(oldPolicy);
      }
    }
  });
}
项目:GitHub    文件:SampleApplication.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setStrictMode() {
    if (Integer.valueOf(Build.VERSION.SDK) > 3) {
        Log.d(LOG_TAG, "Enabling StrictMode policy over Sample application");
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDeath()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
    }
}
项目:GitHub    文件:SampleApplication.java   
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setStrictMode() {
    if (Integer.valueOf(Build.VERSION.SDK) > 3) {
        Log.d(LOG_TAG, "Enabling StrictMode policy over Sample application");
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDeath()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
    }
}
项目:GitHub    文件:UILApplication.java   
@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());
}
项目:subscriptions-leak-example    文件:App.java   
private void initStrictMode() {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectAll()
            .penaltyLog()
            .build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
            .detectAll()
            .penaltyLog()
            .build());
}
项目:smart-lens    文件:MyApplication.java   
@Override
public void onCreate() {
    super.onCreate();

    //Enable strict mode
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
            .detectAll()
            .penaltyLog()
            .build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
            .detectAll()
            .penaltyLog()
            .build());

    //Init shetho
    Stetho.initializeWithDefaults(this);

    //Enable timber
    Timber.plant(new Timber.DebugTree() {
        @Override
        protected String createStackElementTag(StackTraceElement element) {
            return super.createStackElementTag(element)
                    + ":" + element.getMethodName()
                    + " ->L" + element.getLineNumber();
        }
    });
}
项目:AndroidAsyncHTTP    文件:SampleApplication.java   
@RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
private void setStrictMode() {
    if (Integer.valueOf(Build.VERSION.SDK) > 3) {
        Log.d(LOG_TAG, "Enabling StrictMode policy over Sample application");
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDeath()
                .build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .build());
    }
}
项目:firefox-tv    文件:Locales.java   
/**
 * Is only required by locale aware activities, AND  Application. In most cases you should be
 * using LocaleAwareAppCompatActivity or friends.
 * @param context
 */
public static void initializeLocale(Context context) {
    final LocaleManager localeManager = LocaleManager.getInstance();
    final StrictMode.ThreadPolicy savedPolicy = StrictMode.allowThreadDiskReads();
    StrictMode.allowThreadDiskWrites();
    try {
        localeManager.getAndApplyPersistedLocale(context);
    } finally {
        StrictMode.setThreadPolicy(savedPolicy);
    }
}
项目:BadIntent    文件:TransactionHooks.java   
protected Thread sendParcel(ParcelContainer container, int code, int flags) throws IOException {
    //Prevent from casting exceptions with respect to "Network Access on Main Thread"
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
    String resource = "/parcel/" + container.getParcelID();

    URL url = ConnectionUtils.getBadIntentURL(resource, sPrefs, port);
    String jsonData = SerializationUtils.getJson(container, code, flags);

    final HttpURLConnection conn = ConnectionUtils.getBadIntentHttpURLConnection(url, sPrefs);

    conn.setRequestMethod("POST");
    conn.setRequestProperty("__BadIntent__", "Parcel");
    conn.setRequestProperty("__BadIntent__.package", lpparam.packageName);
    conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
    conn.setRequestProperty("Accept", "application/json");
    conn.setDoOutput(true);
    conn.connect();

    DataOutputStream writer = new DataOutputStream(conn.getOutputStream());

    writer.writeBytes(jsonData);
    writer.flush();
    writer.close();

    //create new thread, which reads HTTP result
    return ConnectionUtils.readResponseAndCloseConnection(conn);


}
项目:Nird2    文件:SplashScreenActivity.java   
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());
    }
}
项目:Nird2    文件:SplashScreenActivity.java   
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());
    }
}
项目:Acg    文件:DebugDemoApp.java   
private void init() {
    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }

    applicationComponent = DaggerApplicationComponent.builder()
            .applicationModule(new ApplicationModule(this))
            .build();
}
项目:SensorDataVisualizer    文件:MainActivity.java   
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
        StrictMode.setThreadPolicy(policy);

        ActionBar ab = this.getActionBar();
        // Enable the Up button
        if (ab != null) {
            ab.setDisplayHomeAsUpEnabled(true);
        }

        // TODO remove ugly test code :D
//        Calendar calendar = Calendar.getInstance(Locale.GERMANY);
//        calendar.set(2017, 9, 31);
//        try {
//            ParticluateMatters particluateMatters = new ParticluateMatters();
//            particluateMatters.read(5837, calendar.getTime());
//            calendar.add(Calendar.DAY_OF_YEAR, -1);
//            particluateMatters.read(5837, calendar.getTime());
//            calendar.add(Calendar.DAY_OF_YEAR, -1);
//            particluateMatters.read(5837, calendar.getTime());
//            System.out.println(particluateMatters.getMinValue() + " - " + particluateMatters.getMaxValue());
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
    }
项目:MainCalendar    文件:MainApplication.java   
private void enabledStrictMode() {
    if (SDK_INT >= GINGERBREAD) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
                .detectAll()
                .penaltyLog()
                .penaltyDeath()
                .build());
    }
}