List of usage examples for android.os StrictMode setThreadPolicy
public static void setThreadPolicy(final ThreadPolicy policy)
From source file:com.savedollars.ProductPriceDisplay.java
@SuppressWarnings({ "rawtypes", "unused" }) @Override/* ww w .ja va 2 s . c om*/ protected void onCreate(Bundle savedInstanceState) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites() .detectNetwork().penaltyLog().build()); JSONData = (getIntent().getStringExtra("JsonData")); if (JSONData != null) { parseJsonData(JSONData); } super.onCreate(savedInstanceState); setContentView(R.layout.pdtpriceview); // Setting Product Name TextView productName = (TextView) findViewById(R.id.pdtNameTextView); productName.setText(pdtName); Iterator objMapIterator = sortedMap.entrySet().iterator(); int rowIndex = 0; PDT_INFO = new String[totalCount][2]; while (objMapIterator.hasNext()) { Map.Entry keyValuePairs = (Map.Entry) objMapIterator.next(); String key = ProductTotalPriceDisplay.merchantNames[rowIndex]; PDT_INFO[rowIndex][0] = key; PDT_INFO[rowIndex][1] = "$" + sortedMap.get(key); rowIndex++; } ListViewAdapter listv = new ListViewAdapter(this, PDT_INFO); setListAdapter(listv); final ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { lv.getItemAtPosition(position); String pdtKey = PDT_INFO[position][0]; String merchantLink = (String) merchantLinkMap.get(pdtKey); Uri uri = Uri.parse(merchantLink); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } }); }
From source file:com.visva.voicerecorder.utils.Utils.java
/** * Enables strict mode. This should only be called when debugging the application and is useful * for finding some potential bugs or best practice violations. *//* w w w . ja v a 2 s. com*/ @TargetApi(11) public static void enableStrictMode() { // Strict mode is only available on gingerbread or later if (Utils.hasGingerbread()) { // Enable all thread strict mode policies StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll() .penaltyLog(); // Enable all VM strict mode policies StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll() .penaltyLog(); // Honeycomb introduced some additional strict mode features if (Utils.hasHoneycomb()) { // Flash screen when thread policy is violated threadPolicyBuilder.penaltyFlashScreen(); // For each activity class, set an instance limit of 1. Any more instances and // there could be a memory leak. vmPolicyBuilder.setClassInstanceLimit(ActivityHome.class, 1) .setClassInstanceLimit(ActivityHome.class, 1); } // Use builders to enable strict mode policies StrictMode.setThreadPolicy(threadPolicyBuilder.build()); StrictMode.setVmPolicy(vmPolicyBuilder.build()); } }
From source file:com.reicast.emulator.debug.RequestArchive.java
@SuppressLint("NewApi") protected void onPreExecute() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); }//from w w w . ja va 2 s . c om }
From source file:com.bridgeconn.autographago.ui.activities.SettingsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { getTheme().applyStyle(SharedPrefs.getFontSize().getResId(), true); super.onCreate(savedInstanceState); setContentView(R.layout.activity_settings); UtilFunctions.applyReadingMode();//w w w .jav a 2 s . c o m if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white); toolbar.setContentInsetStartWithNavigation(0); setSupportActionBar(toolbar); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(true); mTvDownload = (TextView) findViewById(R.id.download_bible); mOpenHints = (TextView) findViewById(R.id.open_hints); mProgressBar = (ProgressBar) findViewById(R.id.progress_bar); mDayMode = (ImageView) findViewById(R.id.iv_day_mode); mNightMode = (ImageView) findViewById(R.id.iv_night_mode); mInflateLayout = (LinearLayout) findViewById(R.id.inflate_layout); mSeekBarTextSize = (AppCompatSeekBar) findViewById(R.id.seekbar_text_size); mOpenHints.setOnClickListener(this); mTvDownload.setOnClickListener(this); mDayMode.setOnClickListener(this); mNightMode.setOnClickListener(this); findViewById(R.id.tv_about_us).setOnClickListener(this); mFontSize = SharedPrefs.getFontSize(); mReadingMode = SharedPrefs.getReadingMode(); mSeekBarTextSize.setMax(4); mSeekBarTextSize.setOnSeekBarChangeListener(this); mSeekBarTextSize.setProgress(getFontSizeInt(SharedPrefs.getFontSize())); switch (SharedPrefs.getReadingMode()) { case Day: { mDayMode.setColorFilter(ContextCompat.getColor(this, R.color.colorAccent)); mNightMode.setColorFilter(ContextCompat.getColor(this, R.color.black_40)); break; } case Night: { mDayMode.setColorFilter(ContextCompat.getColor(this, R.color.black_40)); mNightMode.setColorFilter(ContextCompat.getColor(this, R.color.colorAccent)); break; } } downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE); }
From source file:com.viacoin.wallet.WalletApplication.java
@Override public void onCreate() { new LinuxSecureRandom(); // init proper random number generator initLogging();//from ww w . j a v a 2s. c o m StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads() .permitDiskWrites().penaltyLog().build()); Threading.throwOnLockCycles(); log.info("=== starting app using configuration: {}, {}", Constants.TEST ? "test" : "prod", Constants.NETWORK_PARAMETERS.getId()); super.onCreate(); packageInfo = packageInfoFromContext(this); CrashReporter.init(getCacheDir()); Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread thread, final Throwable throwable) { log.info("bitcoinj uncaught exception", throwable); CrashReporter.saveBackgroundTrace(throwable, packageInfo); } }; initMnemonicCode(); config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this)); activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); blockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class); blockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED, null, this, BlockchainServiceImpl.class); blockchainServiceResetBlockchainIntent = new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this, BlockchainServiceImpl.class); walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF); loadWalletFromProtobuf(); config.updateLastVersionCode(packageInfo.versionCode); afterLoadWallet(); }
From source file:systems.soapbox.ombuds.client.WalletApplication.java
@Override public void onCreate() { new LinuxSecureRandom(); // init proper random number generator initLogging();//from w w w . j ava 2 s.c om StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().permitDiskReads() .permitDiskWrites().penaltyLog().build()); Threading.throwOnLockCycles(); log.info("=== starting app using configuration: {}, {}", Constants.TEST ? "test" : "prod", Constants.NETWORK_PARAMETERS.getId()); super.onCreate(); packageInfo = packageInfoFromContext(this); CrashReporter.init(getCacheDir()); Threading.uncaughtExceptionHandler = new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread thread, final Throwable throwable) { log.info("bitcoinj uncaught exception", throwable); CrashReporter.saveBackgroundTrace(throwable, packageInfo); } }; initMnemonicCode(); config = new Configuration(PreferenceManager.getDefaultSharedPreferences(this), getResources()); activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); blockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class); blockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED, null, this, BlockchainServiceImpl.class); blockchainServiceResetBlockchainIntent = new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this, BlockchainServiceImpl.class); walletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF); loadWalletFromProtobuf(); if (config.versionCodeCrossed(packageInfo.versionCode, VERSION_CODE_SHOW_BACKUP_REMINDER) && !wallet.getImportedKeys().isEmpty()) { log.info("showing backup reminder once, because of imported keys being present"); config.armBackupReminder(); } config.updateLastVersionCode(packageInfo.versionCode); afterLoadWallet(); cleanupFiles(); }
From source file:com.ohso.omgubuntu.MainActivity.java
@TargetApi(11) private void enableStrictMode() { if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites() .detectAll().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); }/* ww w . j a v a2 s.co m*/ }
From source file:conversandroid.pandora.PandoraConnection.java
/** * Sends the user message to the chatbot and returns the chatbot response * It is a simplification and adaptation to Android of the method with the same name in the * Pandorabots Java API: https://github.com/pandorabots/pb-java * @param input text for conversation/*from ww w . j a v a2 s. c o m*/ * @return text of bot's response * @throws PandoraException when the connection is not succesful */ public String talk(String input) throws PandoraException { String responses = ""; input = input.replace(" ", "%20"); URI uri = null; try { uri = new URI("https://" + host + "/talk/" + appId + "/" + botName + "?input=" + input + "&user_key=" + userKey); Log.d(LOGTAG, "Request to pandorabot: Botname=" + botName + ", input=\"" + input + "\"" + " uri=" + uri); } catch (URISyntaxException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.IDORHOST); } int SDK_INT = android.os.Build.VERSION.SDK_INT; if (SDK_INT > 8) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); //Why the strictmode: http://stackoverflow.com/questions/25093546/android-os-networkonmainthreadexception-at-android-os-strictmodeandroidblockgua try { Content content = Request.Post(uri).execute().returnContent(); String response = content.asString(); JSONObject jObj = new JSONObject(response); JSONArray jArray = jObj.getJSONArray("responses"); for (int i = 0; i < jArray.length(); i++) { responses += jArray.getString(i).trim(); } } catch (JSONException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.PARSE); } catch (IOException e) { Log.e(LOGTAG, e.getMessage()); throw new PandoraException(PandoraErrorCode.CONNECTION); } catch (Exception e) { throw new PandoraException(PandoraErrorCode.IDORHOST); } } if (responses.toLowerCase().contains("match failed")) { Log.e(LOGTAG, "Match failed"); throw new PandoraException(PandoraErrorCode.NOMATCH); } Log.d(LOGTAG, "Bot response:" + responses); return responses; }
From source file:com.mariogrip.octodroid.mainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { //TODO Remove StrictMode and add AsyncTask! super.onCreate(savedInstanceState); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); prefs = PreferenceManager.getDefaultSharedPreferences(mainActivity.this); getConnectionConfigurationFromPrefs(); senderr = prefs.getBoolean("err", true); boolean first = false; if (!memory.skipWelcom) { Intent i = new Intent(mainActivity.this, welcome.class); if (!util.doGeneralCheckApi()) { first = true;/*w w w . j a v a2 s . co m*/ startActivity(i); } if (!first) { if (!util.doGeneralCheckIp()) { startActivity(i); } } } betamode = prefs.getBoolean("beta", false); setContentView(R.layout.nawdraw); mTitle = mDrawerTitle = getTitle(); nawTitle = getResources().getStringArray(R.array.nawbars); nawlay = (DrawerLayout) findViewById(R.id.drawer_layout); nawList = (ListView) findViewById(R.id.left_drawer); nawList.setAdapter(new ArrayAdapter<String>(this, R.layout.nawlist, nawTitle)); nawList.setOnItemClickListener(new DrawerItemClickListener()); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); mDrawerToggle = new ActionBarDrawerToggle(this, nawlay, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { public void onDrawerClosed(View view) { getActionBar().setTitle(mTitle); invalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { getActionBar().setTitle(mDrawerTitle); invalidateOptionsMenu(); } }; nawlay.setDrawerListener(mDrawerToggle); if (savedInstanceState == null) { selectItem(0); } push = prefs.getBoolean("push", true); running = false; plwaitStart = new ProgressDialog(this); plwaitStart.setTitle("Please wait...."); plwaitStart.setMessage("Connection to " + memory.ip + "....."); plwaitStart.setButton(DialogInterface.BUTTON_NEGATIVE, "Dismiss", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { plwaitStart.dismiss(); } }); plwaitStart.setCancelable(false); plwaitStart.show(); plwateStartR = true; util.logD("Done!"); }
From source file:android.locationprivacy.algorithm.Webservice.java
@Override public Location obfuscate(Location location) { // We do it this way to run network connection in main thread. This // way is not the normal one and does not comply to best practices, // but the main thread must wait for the obfuscation service reply anyway. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); final String HOST_ADDRESS = configuration.getString("host"); String username = configuration.getString("username"); String password = configuration.getString("secret_password"); Location newLoc = new Location(location); double lat = location.getLatitude(); double lon = location.getLongitude(); String urlString = HOST_ADDRESS; urlString += "?lat=" + lat; urlString += "&lon=" + lon; URL url;/*from w ww. j ava 2 s . co m*/ try { url = new URL(urlString); } catch (MalformedURLException e) { Log.e(TAG, "Error: could not build URL"); Log.e(TAG, e.getMessage()); return null; } HttpsURLConnection connection = null; JSONObject json = null; InputStream is = null; try { connection = (HttpsURLConnection) url.openConnection(); connection.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER); connection.setRequestProperty("Authorization", "Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP)); is = connection.getInputStream(); } catch (IOException e) { Log.e(TAG, "Error while connectiong to " + url.toString()); Log.e(TAG, e.getMessage()); return null; } BufferedReader reader = new BufferedReader(new InputStreamReader(is)); try { String line = reader.readLine(); System.out.println("Line " + line); json = new JSONObject(line); newLoc.setLatitude(json.getDouble("lat")); newLoc.setLongitude(json.getDouble("lon")); } catch (IOException e) { Log.e(TAG, "Error: could not read from BufferedReader"); Log.e(TAG, e.getMessage()); return null; } catch (JSONException e) { Log.e(TAG, "Error: could not read from JSON"); Log.e(TAG, e.getMessage()); return null; } connection.disconnect(); return newLoc; }