本文整理匯總了Java中android.os.StrictMode類的典型用法代碼示例。如果您正苦於以下問題:Java StrictMode類的具體用法?Java StrictMode怎麽用?Java StrictMode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StrictMode類屬於android.os包,在下文中一共展示了StrictMode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onCreate
import android.os.StrictMode; //導入依賴的package包/類
@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");
}
示例2: getCoreCountPre17
import android.os.StrictMode; //導入依賴的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);
}
示例3: 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;
}
示例4: 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());
}
}
示例5: init
import android.os.StrictMode; //導入依賴的package包/類
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());
}
}
示例6: initStrictMode
import android.os.StrictMode; //導入依賴的package包/類
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()
);
}
示例7: onCreate
import android.os.StrictMode; //導入依賴的package包/類
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));
}
示例8: getDownloadsDirectory
import android.os.StrictMode; //導入依賴的package包/類
/**
* @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;
}
示例9: 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();
}
示例10: tearDown
import android.os.StrictMode; //導入依賴的package包/類
@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);
}
}
示例11: newThread
import android.os.StrictMode; //導入依賴的package包/類
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;
}
示例12: onCreate
import android.os.StrictMode; //導入依賴的package包/類
@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();
}
示例13: 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());
}
}
示例14: onCreate
import android.os.StrictMode; //導入依賴的package包/類
@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());
}
}
示例15: onCreate
import android.os.StrictMode; //導入依賴的package包/類
@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();
}
}