List of usage examples for android.os StrictMode setThreadPolicy
public static void setThreadPolicy(final ThreadPolicy policy)
From source file:com.isol.app.tracker.Utilita.java
public static void JSONAction(String parms) { try {//from w w w . j a va 2 s. c o m StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); String res = getHttpData(Constants.serviceURL + parms); } catch (Exception ex) { } }
From source file:net.wespot.pim.view.InqImageDetailFragment.java
public static void enableStrictMode(InqImageDetailFragment context) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites() .detectNetwork().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().penaltyLog().build()); }
From source file:org.fdroid.fdroid.FDroidApp.java
@TargetApi(9) @Override/*from w ww . j ava2 s . c o m*/ public void onCreate() { super.onCreate(); if (Build.VERSION.SDK_INT >= 9 && BuildConfig.DEBUG) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build()); } updateLanguage(); ACRA.init(this); // Needs to be setup before anything else tries to access it. // Perhaps the constructor is a better place, but then again, // it is more deterministic as to when this gets called... Preferences.setup(this); curTheme = Preferences.get().getTheme(); // Apply the Google PRNG fixes to properly seed SecureRandom PRNGFixes.apply(); // Check that the installed app cache hasn't gotten out of sync somehow. // e.g. if we crashed/ran out of battery half way through responding // to a package installed intent. It doesn't really matter where // we put this in the bootstrap process, because it runs on a different // thread, which will be delayed by some seconds to avoid an error where // the database is locked due to the database updater. InstalledAppCacheUpdater.updateInBackground(getApplicationContext()); // make sure the current proxy stuff is configured Preferences.get().configureProxy(); // If the user changes the preference to do with filtering rooted apps, // it is easier to just notify a change in the app provider, // so that the newly updated list will correctly filter relevant apps. Preferences.get().registerAppsRequiringRootChangeListener(new Preferences.ChangeListener() { @Override public void onPreferenceChange() { getContentResolver().notifyChange(AppProvider.getContentUri(), null); } }); // This is added so that the bluetooth:// scheme we use for URLs the BluetoothDownloader // understands is not treated as invalid by the java.net.URL class. The actual Handler does // nothing, but its presence is enough. URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(String protocol) { return TextUtils.equals(protocol, "bluetooth") ? new Handler() : null; } }); final Context context = this; Preferences.get().registerUnstableUpdatesChangeListener(new Preferences.ChangeListener() { @Override public void onPreferenceChange() { AppProvider.Helper.calcDetailsFromIndex(context); } }); // Clear cached apk files. We used to just remove them after they'd // been installed, but this causes problems for proprietary gapps // users since the introduction of verification (on pre-4.2 Android), // because the install intent says it's finished when it hasn't. if (!Preferences.get().shouldCacheApks()) { Utils.deleteFiles(Utils.getApkCacheDir(this), null, ".apk"); } // Index files which downloaded, but were not removed (e.g. due to F-Droid being force // closed during processing of the file, before getting a chance to delete). This may // include both "index-*-downloaded" and "index-*-extracted.xml" files. The first is from // either signed or unsigned repos, and the later is from signed repos. Utils.deleteFiles(getCacheDir(), "index-", null); // As above, but for legacy F-Droid clients that downloaded under a different name, and // extracted to the files directory rather than the cache directory. // TODO: This can be removed in a a few months or a year (e.g. 2016) because people will // have upgraded their clients, this code will have executed, and they will not have any // left over files any more. Even if they do hold off upgrading until this code is removed, // the only side effect is that they will have a few more MiB of storage taken up on their // device until they uninstall and re-install F-Droid. Utils.deleteFiles(getCacheDir(), "dl-", null); Utils.deleteFiles(getFilesDir(), "index-", null); UpdateService.schedule(getApplicationContext()); bluetoothAdapter = getBluetoothAdapter(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) .imageDownloader(new IconDownloader(getApplicationContext())) .diskCache(new LimitedAgeDiskCache( new File(StorageUtils.getCacheDirectory(getApplicationContext(), true), "icons"), null, new FileNameGenerator() { @Override public String generate(String imageUri) { return imageUri.substring(imageUri.lastIndexOf('/') + 1); } }, // 30 days in secs: 30*24*60*60 = 2592000 2592000)) .threadPoolSize(4).threadPriority(Thread.NORM_PRIORITY - 2) // Default is NORM_PRIORITY - 1 .build(); ImageLoader.getInstance().init(config); // TODO reintroduce PinningTrustManager and MemorizingTrustManager // initialized the local repo information FDroidApp.initWifiSettings(); startService(new Intent(this, WifiStateChangeService.class)); // if the HTTPS pref changes, then update all affected things Preferences.get().registerLocalRepoHttpsListeners(new ChangeListener() { @Override public void onPreferenceChange() { startService(new Intent(FDroidApp.this, WifiStateChangeService.class)); } }); configureTor(Preferences.get().isTorEnabled()); }
From source file:com.jtechme.apphub.FDroidApp.java
@TargetApi(9) @Override/*from w w w. j a v a 2s . co m*/ public void onCreate() { if (Build.VERSION.SDK_INT >= 9 && BuildConfig.DEBUG) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build()); } updateLanguage(); super.onCreate(); ACRA.init(this); // Needs to be setup before anything else tries to access it. // Perhaps the constructor is a better place, but then again, // it is more deterministic as to when this gets called... Preferences.setup(this); // Apply the Google PRNG fixes to properly seed SecureRandom PRNGFixes.apply(); // Check that the installed app cache hasn't gotten out of sync somehow. // e.g. if we crashed/ran out of battery half way through responding // to a package installed intent. It doesn't really matter where // we put this in the bootstrap process, because it runs on a different // thread, which will be delayed by some seconds to avoid an error where // the database is locked due to the database updater. InstalledAppCacheUpdater.updateInBackground(getApplicationContext()); // If the user changes the preference to do with filtering rooted apps, // it is easier to just notify a change in the app provider, // so that the newly updated list will correctly filter relevant apps. Preferences.get().registerAppsRequiringRootChangeListener(new Preferences.ChangeListener() { @Override public void onPreferenceChange() { getContentResolver().notifyChange(AppProvider.getContentUri(), null); } }); // This is added so that the bluetooth:// scheme we use for URLs the BluetoothDownloader // understands is not treated as invalid by the java.net.URL class. The actual Handler does // nothing, but its presence is enough. URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory() { @Override public URLStreamHandler createURLStreamHandler(String protocol) { return TextUtils.equals(protocol, "bluetooth") ? new Handler() : null; } }); final Context context = this; Preferences.get().registerUnstableUpdatesChangeListener(new Preferences.ChangeListener() { @Override public void onPreferenceChange() { AppProvider.Helper.calcDetailsFromIndex(context); } }); // Clear cached apk files. We used to just remove them after they'd // been installed, but this causes problems for proprietary gapps // users since the introduction of verification (on pre-4.2 Android), // because the install intent says it's finished when it hasn't. SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); curTheme = Theme.valueOf(prefs.getString(Preferences.PREF_THEME, Preferences.DEFAULT_THEME)); Utils.deleteFiles(Utils.getApkDownloadDir(this), null, ".apk"); if (!Preferences.get().shouldCacheApks()) { Utils.deleteFiles(Utils.getApkCacheDir(this), null, ".apk"); } // Index files which downloaded, but were not removed (e.g. due to F-Droid being force // closed during processing of the file, before getting a chance to delete). This may // include both "index-*-downloaded" and "index-*-extracted.xml" files. The first is from // either signed or unsigned repos, and the later is from signed repos. Utils.deleteFiles(getCacheDir(), "index-", null); // As above, but for legacy F-Droid clients that downloaded under a different name, and // extracted to the files directory rather than the cache directory. // TODO: This can be removed in a a few months or a year (e.g. 2016) because people will // have upgraded their clients, this code will have executed, and they will not have any // left over files any more. Even if they do hold off upgrading until this code is removed, // the only side effect is that they will have a few more MiB of storage taken up on their // device until they uninstall and re-install F-Droid. Utils.deleteFiles(getCacheDir(), "dl-", null); Utils.deleteFiles(getFilesDir(), "index-", null); UpdateService.schedule(getApplicationContext()); bluetoothAdapter = getBluetoothAdapter(); ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) .imageDownloader(new IconDownloader(getApplicationContext())) .diskCache(new LimitedAgeDiskCache( new File(StorageUtils.getCacheDirectory(getApplicationContext(), true), "icons"), null, new FileNameGenerator() { @Override public String generate(String imageUri) { return imageUri.substring(imageUri.lastIndexOf('/') + 1); } }, // 30 days in secs: 30*24*60*60 = 2592000 2592000)) .threadPoolSize(4).threadPriority(Thread.NORM_PRIORITY - 2) // Default is NORM_PRIORITY - 1 .build(); ImageLoader.getInstance().init(config); // TODO reintroduce PinningTrustManager and MemorizingTrustManager // initialized the local repo information FDroidApp.initWifiSettings(); startService(new Intent(this, WifiStateChangeService.class)); // if the HTTPS pref changes, then update all affected things Preferences.get().registerLocalRepoHttpsListeners(new ChangeListener() { @Override public void onPreferenceChange() { startService(new Intent(FDroidApp.this, WifiStateChangeService.class)); } }); }
From source file:com.kanchi.periyava.old.Activity.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); loadLanguage(LANGUAGE.ENGLISH);/*from w w w .java2 s.com*/ setContentView(R.layout.activity_main); context = this; if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } initComponents(savedInstanceState); /* Retrieve a PendingIntent that will perform a broadcast */ Intent alarmIntent = new Intent(MainActivity.this, AlarmReceiver.class); pendingIntent = PendingIntent.getBroadcast(MainActivity.this, 0, alarmIntent, 0); UserProfile.getInstance(); PreferenceData.getInstance(context); GeneralSetting.getInstance(); Message msg = Message.obtain(); msg.what = ConstValues.WELCOME; getFlowHandler().sendMessage(msg); }
From source file:com.justone.android.main.MainActivity.java
@SuppressWarnings("deprecation") @Override/* www.j a va2s .com*/ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); currentContext = this; //listviewview this.viewMap = new HashMap<String, ListViewAdapter>(); // this.asynImageLoader = JustOne.getAsynImageLoader(); this.dataOp = JustOne.getDataOp(); // this.res = getResources(); // Resource object to get Drawables // StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites() .detectNetwork().penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); justOne = (JustOne) getApplication(); justOne.pushActivity(this); // view LayoutInflater inflater = LayoutInflater.from(this); //details_page_setitem = inflater.inflate(R.layout.one_details_page_setitem, null); main_item = inflater.inflate(R.layout.activity_main, null); bind_item = inflater.inflate(R.layout.one_details_page_binditem, null); about_one = inflater.inflate(R.layout.about_one, null); //microblog = inflater.inflate(R.layout.one_details_page_microblog, null); feedback = inflater.inflate(R.layout.feedback, null); setContentView(main_item); initData(); // view mListView = (ListView) findViewById(R.id.tab2); //ArrayList<ArrayList<String>> list_data = loadData("list",data); listAdapter = new ListViewAdapter(this, mList, mGist, R.id.scrollview, R.layout.list_item); mListView.setAdapter(listAdapter); /* mListView1 = (ListView) findViewById(R.id.tab1); //ArrayList<ArrayList<String>> collect_data = loadData("collect",data); collectAdapter = new ListViewAdapter(this,mList, mGist, R.id.collectScrollview, R.layout.collect_item); mListView1.setAdapter(collectAdapter); */ homeListView = (ListView) findViewById(R.id.homeTab); homeAdapter = new ListViewAdapter(this, mList, mGist, R.id.homeScrollView, R.layout.home_item); homeListView.setAdapter(homeAdapter); qaListView = (ListView) findViewById(R.id.QAtab); //ArrayList<ArrayList<String>> QA_data = loadData("QA",data); QAAdapter = new ListViewAdapter(this, mList, mGist, R.id.qaScrollView, R.layout.qa_item); qaListView.setAdapter(QAAdapter); //detailView = (ListView) findViewById(R.id.tab3); //ArrayList<ArrayList<String>> detail_data = loadData("detail",data); //detailAdapter = new ListViewAdapter(this, // mList, mGist, // R.id.detailScrollView, R.layout.detail_item); //detailView.setAdapter(detailAdapter); /*//loading list view loadingView = (ListView) findViewById(R.id.loading_view); //ArrayList<ArrayList<String>> detail_data = loadData("detail",data); loadingAdapter = new ListViewAdapter(this, mList, mGist, R.id.loadingScrollView, R.layout.one_welcome_ad); loadingView.setAdapter(loadingAdapter); */ tabs = (TabHost) findViewById(R.id.tabhost); tabWidget = (TabWidget) findViewById(android.R.id.tabs); int width = 100; int height = 100; tabs.setup(); tabs.addTab(tabs.newTabSpec("home tab").setIndicator("", this.res.getDrawable(R.drawable.home_tab_selector)) .setContent(R.id.homeTab)); tabs.addTab(tabs.newTabSpec("list tab").setIndicator("", this.res.getDrawable(R.drawable.one_tab_selector)) .setContent(R.id.tab2)); tabs.addTab(tabs.newTabSpec("QA Tab").setIndicator("", this.res.getDrawable(R.drawable.qa_tab_selector)) .setContent(R.id.QAtab)); /* tabs.addTab(tabs.newTabSpec("second tab").setIndicator("", null) .setContent(R.id.tab1));*/ //tabs.addTab(tabs.newTabSpec("second tab").setIndicator("",this.res.getDrawable(R.drawable.more_tab_selector)) // .setContent(R.id.tab3)); tabs.setCurrentTab(0); for (int i = 0; i < tabWidget.getChildCount(); i++) { /** * fill_parent */ tabWidget.getChildAt(i).getLayoutParams().height = height; tabWidget.getChildAt(i).getLayoutParams().width = width; /** * tab */ final TextView tv = (TextView) tabWidget.getChildAt(i).findViewById(android.R.id.title); tv.setTextColor(this.getResources().getColorStateList(android.R.color.white)); tv.setTextSize(15); tv.setGravity(Gravity.TOP); } mActivityName = getString(R.string.activity_c_label); mStatusTracker.setStatus(mActivityName, getString(R.string.on_create)); Utils.printStatus(mStatusView, mStatusAllView); detector = new GestureDetector(this); viewMap.put("home", this.homeAdapter); // View returnBackToIndex = main_item.findViewById(R.id.returnBackToIndex_layout); returnBackToIndex.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { MainActivity.this.finish(); // TODO Auto-generated method stub } }); userFirstTips(); }
From source file:com.example.hudpassthrough.BluetoothChat.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (D)//from w w w . j ava2 s. co m Log.e(TAG, "+++ ON CREATE +++"); // Set up the window layout requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); setContentView(R.layout.main); getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title); // Set up the custom title mTitle = (TextView) findViewById(R.id.title_left_text); mTitle.setText(R.string.app_name); mTitle = (TextView) findViewById(R.id.title_right_text); // Get local Bluetooth adapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); // If the adapter is null, then Bluetooth is not supported if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } mCamera = Camera.open(); if (mCamera == null) Log.e("Camera", "mCamera is null!"); //mCamera.enableShutterSound(false); //Questionable Legality! CamPreview camPreview = new CamPreview(this, mCamera); camPreview.setSurfaceTextureListener(camPreview); FrameLayout preview = (FrameLayout) findViewById(R.id.cameraView); preview.addView(camPreview); CamCallback camCallback = new CamCallback(); mCamera.setPreviewCallback(camCallback); StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build()); people = new PeopleDB(); }
From source file:com.hp.map.CustomerMapActivity.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @SuppressLint("NewApi") @Override/*from ww w .j ava 2s .c o m*/ protected void onCreate(Bundle savedInstanceState) { if (android.os.Build.VERSION.SDK_INT > 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } super.onCreate(savedInstanceState); setContentView(R.layout.customer_map); //Action bar getActionBar().setHomeButtonEnabled(true); getActionBar().setLogo(R.drawable.ic_launcher); getActionBar().setDisplayHomeAsUpEnabled(true); // /Action bar //Get POSITION Intent i = getIntent(); customerSelected = null; customerSelected = i.getStringExtra("POSITION_CLICK"); for (int j = 0; j < CustomerAPI.customerList.size(); j++) { if (customerSelected.compareTo(CustomerAPI.customerList.get(j).getMaDoiTuong()) == 0) { positionClick = j; mSelectedCustomer = CustomerAPI.customerList.get(j); } } Button sendLocation = (Button) findViewById(R.id.send_location); //if(Rest.mStaff.getId().equalsIgnoreCase(CustomerAPI.customerList.get(positionClick).getMaNhanVien())) if (Rest.mStaff.getPermission() == 1 || Rest.mStaff.getPermission() == 3) sendLocation.setVisibility(View.VISIBLE); customer_name = (TextView) findViewById(R.id.customer_name); customer_id = (TextView) findViewById(R.id.customer_id); customer_phone = (TextView) findViewById(R.id.customer_phone); customer_address = (TextView) findViewById(R.id.customer_address); customer_name.setText(CustomerAPI.customerList.get(positionClick).getDoiTuong()); customer_id.setText(CustomerAPI.customerList.get(positionClick).getMaDoiTuong()); customer_phone.setText(CustomerAPI.customerList.get(positionClick).getDienThoai()); customer_address.setText(CustomerAPI.customerList.get(positionClick).getDiaChi()); setUpMapIfNeeded(); }
From source file:ca.ualberta.cmput301f13t13.storyhoard.serverClasses.ServerManager.java
/** * Builds a string query to randomly sort stories on the server and * retrieves a maximum of one to return (of there are no stories on * the server, null will be returned). It also uses the retrieve * method from the ESRetrieval class to do so. </br></br> * //from www .ja v a 2s . c o m * Example call: </br> * Story story = getRandom(); </br></br> * * One more thing to note is that this operation is currently done on the * main UI thread of the android application, which is why the * ThreadPolicy code is needed. * */ public Story getRandom() { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); String query = "{\"query\": {\"custom_score\" : {\"script\" : " + "\"random()\", \"query\" : {\"match_all\" : {}}}}, " + "\"sort\" : {\"_score\" : {\"order\" :\"desc\"}}, \"size\" :" + " 1 }"; ArrayList<Story> stories = new ArrayList<Story>(); try { stories = esRetrieval.retrieve(query, server); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } if (stories.size() != 1) { return null; } else { return stories.get(0); } }
From source file:org.totschnig.myexpenses.activity.ProtectedFragmentActivity.java
@TargetApi(9) private void enableStrictMode() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) { 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()); }/*from w w w. j av a 2 s. co m*/ }