android.os.StrictMode Java Examples
The following examples show how to use
android.os.StrictMode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Application.java From materialistic with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); AppCompatDelegate.setDefaultNightMode(Preferences.Theme.getAutoDayNightMode(this)); AlgoliaClient.sSortByTime = Preferences.isSortByRecent(this); mRefWatcher = LeakCanary.install(this); if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyFlashScreen() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build()); } Preferences.migrate(this); TYPE_FACE = FontCache.getInstance().get(this, Preferences.Theme.getTypeface(this)); AppUtils.registerAccountsUpdatedListener(this); AdBlocker.init(this, Schedulers.io()); }
Example #2
Source File: SyncStatusHelper.java From android-chromium with BSD 2-Clause "Simplified" License | 6 votes |
/** * Register with Android Sync Manager. This is what causes the "Chrome" option to appear in * Settings -> Accounts / Sync . * * @param account the account to enable Chrome sync on */ private void makeSyncable(Account account) { synchronized (mCachedSettings) { mCachedSettings.setIsSyncable(account); } StrictMode.ThreadPolicy oldPolicy = temporarilyAllowDiskWritesAndDiskReads(); // Disable the syncability of Chrome for all other accounts. Don't use // our cache as we're touching many accounts that aren't signed in, so this saves // extra calls to Android sync configuration. Account[] googleAccounts = AccountManagerHelper.get(mApplicationContext). getGoogleAccounts(); for (Account accountToSetNotSyncable : googleAccounts) { if (!accountToSetNotSyncable.equals(account) && mSyncContentResolverWrapper.getIsSyncable( accountToSetNotSyncable, mContractAuthority) > 0) { mSyncContentResolverWrapper.setIsSyncable(accountToSetNotSyncable, mContractAuthority, 0); } } StrictMode.setThreadPolicy(oldPolicy); }
Example #3
Source File: DUtils.java From UTubeTV with The Unlicense | 6 votes |
public static void activateStrictMode() { if (isDebugBuild()) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() // .detectAll() // for all detectable problems .detectDiskReads() // .detectDiskWrites() .detectNetwork().penaltyLog() // .penaltyDialog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .detectActivityLeaks().detectLeakedRegistrationObjects() // .penaltyDeath() .build()); } }
Example #4
Source File: PathUtils.java From 365browser with Apache License 2.0 | 6 votes |
/** * @return the public downloads directory. */ @SuppressWarnings("unused") @CalledByNative private static String getDownloadsDirectory() { // 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; }
Example #5
Source File: AndroidUtils.java From Android-Next with Apache License 2.0 | 6 votes |
@TargetApi(11) public static void setStrictMode(boolean enable) { if (!enable) { return; } StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog(); StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog(); StrictMode.setThreadPolicy(threadPolicyBuilder.build()); StrictMode.setVmPolicy(vmPolicyBuilder.build()); }
Example #6
Source File: DaoImpl.java From Cangol-appcore with Apache License 2.0 | 6 votes |
@Override public int create(T paramT) throws SQLException { final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase(); long result = -1; try { db.beginTransaction(); result = db.insert(mTableName, null, DatabaseUtils.getContentValues(paramT)); db.setTransactionSuccessful(); } catch (Exception e) { throw new SQLException(mTableName, e); } finally { db.endTransaction(); } StrictMode.setThreadPolicy(oldPolicy); return (int) result; }
Example #7
Source File: App.java From scissors with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); refWatcher = LeakCanary.install(this); 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()); // If using Android-Universal-Image-Loader // Create global configuration and initialize ImageLoader with default config // ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build(); // ImageLoader.getInstance().init(config); }
Example #8
Source File: AccessibilityHierarchyAndroid.java From Accessibility-Test-Framework-for-Android with Apache License 2.0 | 6 votes |
private static @Nullable Class<?> getClassByName( ViewHierarchyElementAndroid view, String className) { StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { ClassLoader classLoader = view.getClass().getClassLoader(); if (classLoader != null) { return classLoader.loadClass(className); } else { LogUtils.w(TAG, "Unsuccessful attempt to get ClassLoader to load %1$s", className); } } catch (ClassNotFoundException e) { LogUtils.w(TAG, "Unsuccessful attempt to load class %1$s.", className); } finally { StrictMode.setThreadPolicy(oldPolicy); } return null; }
Example #9
Source File: AccessibilityChecks.java From android-test with Apache License 2.0 | 6 votes |
@Override public void check(View view, NoMatchingViewException noViewFoundException) { if (noViewFoundException != null) { Log.e( TAG, String.format( "'accessibility checks could not be performed because view '%s' was not" + "found.\n", noViewFoundException.getViewMatcherDescription())); throw noViewFoundException; } if (view == null) { throw new NullPointerException(); } StrictMode.ThreadPolicy originalPolicy = StrictMode.allowThreadDiskWrites(); try { CHECK_EXECUTOR.checkAndReturnResults(view); } finally { StrictMode.setThreadPolicy(originalPolicy); } }
Example #10
Source File: InitContentProvider.java From white-label-event-app with Apache License 2.0 | 6 votes |
private void initStrictMode() { // Complain loudly of strict mode violations when in debug mode. if (BuildConfig.DEBUG) { final StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyFlashScreen() .penaltyLog() .build(); StrictMode.setThreadPolicy(policy); final StrictMode.VmPolicy vm_policy = new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build(); StrictMode.setVmPolicy(vm_policy); logger.info("Strict Mode in effect for the main thread"); } }
Example #11
Source File: GApplication.java From android-project-wo2b with Apache License 2.0 | 6 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressWarnings("unused") @Override public void onCreate() { if (BaseApplication.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(); mContext = getApplicationContext(); // 保存文件目录 mVersion = getGVerion(); // XPreferenceManager.putGVersion(mVersion); // MemoryHelper.loadDefaultVmPolicy(); }
Example #12
Source File: ContributorsApplication.java From Retrofit2SampleApp with MIT License | 6 votes |
@Override public void onCreate() { super.onCreate(); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectAll() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); Timber.plant(new Timber.DebugTree()); contributorsService = new ContributorsService(); }
Example #13
Source File: DaoImpl.java From Cangol-appcore with Apache License 2.0 | 6 votes |
@Override public int create(Collection<T> paramTs) throws SQLException { final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); final SQLiteDatabase db = mDatabaseHelper.getWritableDatabase(); long result = -1; try { db.beginTransaction(); for (final T paramT : paramTs) { result = result + db.insert(mTableName, null, DatabaseUtils.getContentValues(paramT)); } db.setTransactionSuccessful(); } catch (Exception e) { throw new SQLException(mTableName, e); } finally { db.endTransaction(); } StrictMode.setThreadPolicy(oldPolicy); return (int) result; }
Example #14
Source File: ApplicationAndroidStarter.java From AndroidStarter with Apache License 2.0 | 6 votes |
@Override public void onCreate() { super.onCreate(); sSharedApplication = this; Logger.init(TAG) .logLevel(LogLevel.FULL); buildComponent(); mComponentApplication.inject(this); merlin.bind(); final StrictMode.ThreadPolicy loStrictModeThreadPolicy = new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyDeath() .build(); StrictMode.setThreadPolicy(loStrictModeThreadPolicy); }
Example #15
Source File: OrderFragmentHandler.java From mobikul-standalone-pos with MIT License | 6 votes |
public void generateInvoice(OrderEntity orderData) { ActivityCompat.requestPermissions((BaseActivity) context, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_EXTERNAL_STORAGE}, 666); int result = ContextCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE); if (result == PackageManager.PERMISSION_GRANTED) { if (Helper.getInstanse().generateInvoice(context, orderData) != null) { File file = Helper.getInstanse().generateInvoice(context, orderData); StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); Uri path = Uri.fromFile(file); Intent pdfOpenIntent = new Intent(Intent.ACTION_VIEW); pdfOpenIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); pdfOpenIntent.setDataAndType(path, "application/pdf"); try { context.startActivity(pdfOpenIntent); } catch (ActivityNotFoundException e) { e.printStackTrace(); ToastHelper.showToast(context, "No Application Available to View PDF", Toast.LENGTH_SHORT); } } else ToastHelper.showToast(context, "ERROR in generating pdf", Toast.LENGTH_SHORT); } }
Example #16
Source File: MainActivity.java From T0rlib4Android with Apache License 2.0 | 6 votes |
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); } }
Example #17
Source File: ShaderEditorApp.java From ShaderEditor with MIT License | 6 votes |
@Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) { StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build()); StrictMode.setVmPolicy( new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .penaltyLog() .penaltyDeath() .build()); } preferences.init(this); db.open(this); }
Example #18
Source File: VrDaydreamApiImpl.java From 365browser with Apache License 2.0 | 6 votes |
@Override public Boolean isDaydreamCurrentViewer() { DaydreamApi daydreamApi = DaydreamApi.create(mContext); if (daydreamApi == null) return false; // If this is the first time any app reads the daydream config file, daydream may create its // config directory... crbug.com/686104 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); int type = GvrApi.ViewerType.CARDBOARD; try { type = daydreamApi.getCurrentViewerType(); } finally { StrictMode.setThreadPolicy(oldPolicy); } daydreamApi.close(); return type == GvrApi.ViewerType.DAYDREAM; }
Example #19
Source File: DaoImpl.java From Cangol-appcore with Apache License 2.0 | 6 votes |
@Override public T queryForId(I paramID, String... columns) throws SQLException { final StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskWrites(); T obj = null; try { final SQLiteDatabase db = mDatabaseHelper.getReadableDatabase(); final QueryBuilder queryBuilder = new QueryBuilder(mClazz); queryBuilder.addQuery(DatabaseUtils.getIdColumnName(mClazz), paramID, "="); final Cursor cursor = query(db, queryBuilder); if (cursor.getCount() > 0 && cursor.moveToFirst()) { obj = DatabaseUtils.cursorToClassObject(mClazz, cursor, columns); } cursor.close(); } catch (Exception e) { throw new SQLException(mTableName, e); } StrictMode.setThreadPolicy(oldPolicy); return obj; }
Example #20
Source File: LangAppCompatActivity.java From InviZible with GNU General Public License v3.0 | 6 votes |
@Override protected void onCreate(@Nullable Bundle savedInstanceState) { if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() .detectAll() //for all detectable problems .penaltyLog() .penaltyFlashScreen () .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); } super.onCreate(savedInstanceState); Language.setFromPreference(this, "pref_fast_language"); }
Example #21
Source File: UrlBar.java From AndroidChromium with Apache License 2.0 | 5 votes |
@Override public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) { // Certain OEM implementations of onInitializeAccessibilityNodeInfo trigger disk reads // to access the clipboard. crbug.com/640993 StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { super.onInitializeAccessibilityNodeInfo(info); } finally { StrictMode.setThreadPolicy(oldPolicy); } if (mAccessibilityTextOverride != null) { info.setText(mAccessibilityTextOverride); } }
Example #22
Source File: Locales.java From firefox-echo-show with Mozilla Public License 2.0 | 5 votes |
/** * 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); } }
Example #23
Source File: GSAServiceClient.java From 365browser with Apache License 2.0 | 5 votes |
/** * Establishes a connection to the service. Call this method once the callback passed here is * ready to handle calls. * If you pass in an GSA context, it will be sent up the service as soon as the connection is * established. * @return Whether or not the connection to the service was established successfully. */ boolean connect() { if (mService != null) Log.e(TAG, "Already connected."); Intent intent = new Intent(GSA_SERVICE).setPackage(GSAState.SEARCH_INTENT_PACKAGE); // Third-party modifications to the framework lead to StrictMode violations in // Context#bindService(). See crbug.com/670195. StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { return mContext.bindService( intent, mConnection, Context.BIND_AUTO_CREATE | Context.BIND_NOT_FOREGROUND); } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example #24
Source File: Helper.java From mobikul-standalone-pos with MIT License | 5 votes |
public static long getCurrentNetworkTime() { long returnTime = 0; NTPUDPClient timeClient = new NTPUDPClient(); timeClient.setDefaultTimeout(1000); // Connect to network. Try again on timeout (max 6). for (int retries = 7; retries >= 0; retries--) { try { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); // Try connecting to network to get time. May timeout. InetAddress inetAddress = InetAddress.getByName(TIME_SERVER); TimeInfo timeInfo = timeClient.getTime(inetAddress); long networkTimeLong = timeInfo.getMessage().getTransmitTimeStamp().getTime(); // Convert long to Date, and Date to String. Log results. Date networkTimeDate = new Date(networkTimeLong); Log.i("Time", "Time from " + TIME_SERVER + ": " + networkTimeDate); returnTime = networkTimeDate.getTime(); break; // Return resulting time as a String. } catch (IOException e) { // Max of 6 retries. Log.i("RTCTestActivity", "Unable to connect. Retries left: " + (retries - 1)); } } return returnTime; }
Example #25
Source File: FileUtil.java From Share2 with Apache License 2.0 | 5 votes |
/** * forceGetFileUri * @param shareFile shareFile * @return Uri */ private static Uri forceGetFileUri(File shareFile) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { try { @SuppressLint("PrivateApi") Method rMethod = StrictMode.class.getDeclaredMethod("disableDeathOnFileUriExposure"); rMethod.invoke(null); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } } return Uri.parse("file://" + shareFile.getAbsolutePath()); }
Example #26
Source File: BaseActivity.java From Bop with Apache License 2.0 | 5 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Checking if changes were made, look these methods for better understanding refreshTheme(); refreshMode(); //just using it for limited time, will use File provider soon StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder(); StrictMode.setVmPolicy(builder.build()); }
Example #27
Source File: PackageManagerDelegate.java From 365browser with Apache License 2.0 | 5 votes |
/** * 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); } }
Example #28
Source File: AnsApplication.java From ans-android-sdk with GNU General Public License v3.0 | 5 votes |
/** * 设置严苛模式 */ private void strictMode() { if (isDebug) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectAll() .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectAll() .penaltyLog() .build()); } }
Example #29
Source File: VrClassesWrapperImpl.java From 365browser with Apache License 2.0 | 5 votes |
@Override public NonPresentingGvrContext createNonPresentingGvrContext(ChromeActivity activity) { StrictMode.ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads(); try { return new NonPresentingGvrContextImpl(activity); } catch (Exception ex) { Log.e(TAG, "Unable to instantiate NonPresentingGvrContextImpl", ex); return null; } finally { StrictMode.setThreadPolicy(oldPolicy); } }
Example #30
Source File: ChromeStrictMode.java From 365browser with Apache License 2.0 | 5 votes |
private static void turnOnDetection(StrictMode.ThreadPolicy.Builder threadPolicy, StrictMode.VmPolicy.Builder vmPolicy) { threadPolicy.detectAll(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { vmPolicy.detectAll(); } else { // Explicitly enable detection of all violations except file URI leaks, as that // results in false positives when file URI intents are passed between Chrome // activities in separate processes. See http://crbug.com/508282#c11. vmPolicy.detectActivityLeaks() .detectLeakedClosableObjects() .detectLeakedRegistrationObjects() .detectLeakedSqlLiteObjects(); } }