Example usage for android.os StrictMode setThreadPolicy

List of usage examples for android.os StrictMode setThreadPolicy

Introduction

In this page you can find the example usage for android.os StrictMode setThreadPolicy.

Prototype

public static void setThreadPolicy(final ThreadPolicy policy) 

Source Link

Document

Sets the policy for what actions on the current thread should be detected, as well as the penalty if such actions occur.

Usage

From source file:pw.dedominic.airc.App.java

@Override
protected void onCreate(Bundle savedInstance) {
    super.onCreate(savedInstance);

    // I have no clue
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    handler = new IrcEventHandler(getMainLooper(), this);

    // recover state from previous run
    if (savedInstance != null) {
        selectedServer = (Server) savedInstance.get("selectedServer");
        channelConvos = (Map<String, Conversation>) savedInstance.get("channelConvos");
    }/*from w  w w.  j a v  a  2s  . c  om*/
    if (channelConvos == null) {
        channelConvos = new HashMap<String, Conversation>();
    }

    // database init
    DatabaseSingleton.initializeInstance(this);
    databaseSingleton = DatabaseSingleton.getInstance();
    dao = databaseSingleton.getDatabase();
    // settings
    settings = new Settings(this);

    // layout
    actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setHomeButtonEnabled(true);
    setContentView(R.layout.app_layout);
    drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    navView = (NavigationView) findViewById(R.id.navigation_view);
    navView.setNavigationItemSelectedListener(this);

    // init layout
    if (selectedServer == null) {
        actionBar.setTitle("Not Connected");
    }
    toggle = new ActionBarDrawerToggle(this, drawer, 0, 0) {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            invalidateOptionsMenu();
        }
    };
    if (ircConnection != null) {
        ircConnection.close();
        thread = null;
    }
    drawer.setDrawerListener(toggle);
    recreateDrawerItems();
    changeServer(selectedServer);
}

From source file:com.isol.app.tracker.Utilita.java

public static JSONObject getJSONObjectFromArray(String parms) {
    try {//from   w  w w .  j  av a2  s . c  om

        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
        String res = getHttpData(Constants.serviceURL + parms);
        JSONArray jArray = new JSONArray(res);
        JSONObject obj = jArray.getJSONObject(0);
        return obj;
    } catch (Exception ex) {
        return null;
    }

}

From source file:au.com.wallaceit.reddinator.Rservice.java

@Override
public void onCreate() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    endOfFeed = false;/*  w  w  w  .  ja v  a 2  s.  c o m*/
    // get thumbnail load preference for the widget
    loadThumbnails = mSharedPreferences.getBoolean("thumbnails-" + appWidgetId, true);
    bigThumbs = mSharedPreferences.getBoolean("bigthumbs-" + appWidgetId, false);
    hideInf = mSharedPreferences.getBoolean("hideinf-" + appWidgetId, false);
}

From source file:com.vuze.android.remote.rpc.RPC.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static Object enableNasty() {
    ThreadPolicy oldThreadPolicy = StrictMode.getThreadPolicy();
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
    StrictMode.setThreadPolicy(policy);
    return oldThreadPolicy;
}

From source file:nl.sebastiaanschool.contact.app.MainActivity.java

private void initializeStrictMode() {
    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog()
                .penaltyFlashScreen().penaltyDeathOnNetwork().build());

        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog()
                .setClassInstanceLimit(BackendInterface.class, 1)
                .setClassInstanceLimit(DownloadManagerInterface.class, 1).build());
    }/*from   ww  w . j av a2 s. c  om*/
}

From source file:com.dsi.ant.antplus.pluginsampler.heartrate.Activity_HeartRateDisplayBase.java

protected void showDataDisplay(String status) {
    setContentView(R.layout.activity_heart_rate);

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }/*from   www . j  a v  a 2  s  . com*/

    tv_status = (TextView) findViewById(R.id.textView_Status);

    tv_estTimestamp = (TextView) findViewById(R.id.textView_EstTimestamp);

    tv_rssi = (TextView) findViewById(R.id.textView_Rssi);

    tv_computedHeartRate = (TextView) findViewById(R.id.textView_ComputedHeartRate);
    tv_heartBeatCounter = (TextView) findViewById(R.id.textView_HeartBeatCounter);
    tv_heartBeatEventTime = (TextView) findViewById(R.id.textView_HeartBeatEventTime);

    tv_manufacturerSpecificByte = (TextView) findViewById(R.id.textView_ManufacturerSpecificByte);
    tv_previousHeartBeatEventTime = (TextView) findViewById(R.id.textView_PreviousHeartBeatEventTime);

    tv_calculatedRrInterval = (TextView) findViewById(R.id.textView_CalculatedRrInterval);

    tv_cumulativeOperatingTime = (TextView) findViewById(R.id.textView_CumulativeOperatingTime);

    tv_manufacturerID = (TextView) findViewById(R.id.textView_ManufacturerID);
    tv_serialNumber = (TextView) findViewById(R.id.textView_SerialNumber);

    tv_hardwareVersion = (TextView) findViewById(R.id.textView_HardwareVersion);
    tv_softwareVersion = (TextView) findViewById(R.id.textView_SoftwareVersion);
    tv_modelNumber = (TextView) findViewById(R.id.textView_ModelNumber);

    tv_dataStatus = (TextView) findViewById(R.id.textView_DataStatus);
    tv_rrFlag = (TextView) findViewById(R.id.textView_rRFlag);

    //Reset the text display
    tv_status.setText(status);

    tv_estTimestamp.setText("---");

    tv_rssi.setText("---");

    tv_computedHeartRate.setText("---");
    tv_heartBeatCounter.setText("---");
    tv_heartBeatEventTime.setText("---");

    tv_manufacturerSpecificByte.setText("---");
    tv_previousHeartBeatEventTime.setText("---");

    tv_calculatedRrInterval.setText("---");

    tv_cumulativeOperatingTime.setText("---");

    tv_manufacturerID.setText("---");
    tv_serialNumber.setText("---");

    tv_hardwareVersion.setText("---");
    tv_softwareVersion.setText("---");
    tv_modelNumber.setText("---");
    tv_dataStatus.setText("---");
    tv_rrFlag.setText("---");

    /*        Log.i("CallAPI", "CallAPI- Before API Call");
            new SendHttpRequestTask().execute();   
    */ }

From source file:httbdd.cse.nghiatran.halofind.fragment.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.demo, container, false);
    mSlidingUpPanelLayout = (SlidingUpPanelLayout) rootView.findViewById(R.id.slidingLayout);
    mSlidingUpPanelLayout.setEnableDragViewTouchEvents(true);

    int mapHeight = getResources().getDimensionPixelSize(R.dimen.map_height);
    mSlidingUpPanelLayout.setPanelHeight(mapHeight); // you can use different height here

    mSlidingUpPanelLayout.setPanelSlideListener((SlidingUpPanelLayout.PanelSlideListener) getActivity());
    mapView = (MapView) rootView.findViewById(R.id.mapView);
    //        lat = getIntent().getDoubleExtra("lat", lat);
    //        longt = getIntent().getDoubleExtra("long", longt);
    //        addresss = getIntent().getStringExtra("address");
    //        title = getIntent().getStringExtra("title");
    mapView.onCreate(savedInstanceState);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    updateValuesFromBundle(savedInstanceState);
    if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
        AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
        alert.setMessage("GPS is disabled in your device. Would you like to enable it?");
        alert.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();//from www.  java 2 s.c o  m
            }
        });
        alert.setNegativeButton("Go to Settings", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                Intent I = new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                startActivity(I);
            }
        });
        AlertDialog al_gps = alert.create();
        al_gps.show();
    } else {
        if (ActivityCompat.checkSelfPermission(getActivity(),
                Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
                && ActivityCompat.checkSelfPermission(getActivity(),
                        Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                    (android.location.LocationListener) this);
        }
    }
    mapView.getMapAsync(this);
    createLocationRequest();
    return rootView;
}

From source file:com.commonsware.cwac.locpoll.demo.LocationReceiver.java

@SuppressLint("NewApi")
public static String downloadPage(String url) {

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }//from  w w w  .j ava2s . co  m
    String page = "";

    BufferedReader in = null;
    try {
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(url);
        HttpParams params = request.getParams();
        HttpConnectionParams.setSoTimeout(params, 60000); // 1 minute timeout               
        HttpResponse response = client.execute(request);

        //Predifined buffer size
        /*
         * 
          in = new BufferedReader(
                  new InputStreamReader(
                 response.getEntity().getContent()),8*2000);
         * 
         * */

        in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

        StringBuffer sb = new StringBuffer("");
        String line = "";
        //String NL = System.getProperty("line.separator");
        while ((line = in.readLine()) != null) {
            sb.append(line);
        }
        in.close();
        page = sb.toString();
        Log.v(DEBUG_TAG, "Pagina descargada --> " + page);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException e) {
                Log.v(DEBUG_TAG, "Error en la descarga de la pagina");
                e.printStackTrace();
            }
        }
    }
    return page;
}

From source file:com.fbbackup.FriendAlbumList.java

@SuppressLint("NewApi")
@Override//from   w w w  . j  a  va  2s. com
public void onCreate(Bundle savedInstanceState) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        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());

    }

    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);

    extStorageDirectory = Environment.getExternalStorageDirectory().toString();

    Log.w("fbtest", extStorageDirectory);

    mImageThumbSize = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_size);
    mImageThumbSpacing = getResources().getDimensionPixelSize(R.dimen.image_thumbnail_spacing);

    facebook = new Facebook("134348190059034");

    albumArray = getArguments().getStringArray("albumArray");

    albumCoverArray = getArguments().getStringArray("albumCoverArray");

    albumCoverUrlArray = getArguments().getStringArray("albumCoverUrlArray");

    albumNameArray = getArguments().getStringArray("albumNameArray");

    albumPhotoAccountArray = getArguments().getStringArray("albumPhotoAccountArray");

    token = getArguments().getString("token");

    name = getArguments().getString("userName");

    Log.w("fbtest", "first token:" + token);

    mAdapter = new ImageAdapter(getActivity());

    imageLoader = new ImageLoader(getActivity());

    getAlbumCoverUrl();

    ImageCacheParams cacheParams = new ImageCacheParams(getActivity(), IMAGE_CACHE_DIR);

    cacheParams.setMemCacheSizePercent(0.25f); // Set memory cache to 25% of
    // app memory

    // The ImageFetcher takes care of loading images into our ImageView
    // children asynchronously
    mImageFetcher = new ImageFetcher(getActivity(), mImageThumbSize);
    mImageFetcher.setLoadingImage(R.drawable.ic_launcher);
    mImageFetcher.addImageCache(getActivity().getSupportFragmentManager(), cacheParams);

    MyFriendFragmentActivity.controlPanelHandler.sendEmptyMessage(MyFriendFragmentActivity.HIDE_CONTROL_PANEL);
}

From source file:com.nfc.gemkey.MainActivity.java

@Override
public void onCreate(Bundle icicle) {
    if (DEBUG)/*from w w w  . j a v  a 2  s .  c  o  m*/
        Log.d(TAG, "onCreate");
    super.onCreate(icicle);
    setContentView(R.layout.activity_main);

    mAdapter = NfcAdapter.getDefaultAdapter(this);

    // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
    // will fill in the intent with the details of the discovered tag before delivering to
    // this activity.
    mPendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    // Setup an intent filter for all MIME based dispatches
    IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    tagDetected.addCategory(Intent.CATEGORY_DEFAULT);
    mFilters = new IntentFilter[] { tagDetected };

    mUsbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
    mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);

    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    registerReceiver(mUsbReceiver, filter);

    if (getLastNonConfigurationInstance() != null) {
        Log.i(TAG, "open usb accessory@onCreate");
        mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
        openAccessory(mAccessory);
    }

    buttonLED = (ToggleButton) findViewById(R.id.nfc_btn);
    buttonLED.setBackgroundResource(
            buttonLED.isChecked() ? R.drawable.btn_toggle_yes : R.drawable.btn_toggle_no);
    buttonLED.setOnCheckedChangeListener(mKeyLockListener);

    tagId = (TextView) findViewById(R.id.nfc_tag);
    tagId.setText(R.string.nfc_scan_tag);

    // Avoid NetworkOnMainThreadException
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());

    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());

    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}