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:com.netcompss.ffmpeg4android_client.BaseVideo.java

public boolean execute(String actiosaveImagen, JSONArray args, CallbackContext callbackContext)
        throws JSONException {
    this.callbackContext = callbackContext;
    context = this.cordova.getActivity().getApplicationContext();
    contexts = this.cordova.getActivity().getApplicationContext();
    _prefs = new Prefs();
    _prefs.setContext(this.cordova.getActivity().getApplicationContext());
    jsondata = args.toString();//from  ww w . j  ava 2 s  . c  om
    Log.e("json", args.toString() + " ddddd " + args.length());
    cd = new ConnectionDetector(context);
    isInternetPresent = cd.isConnectingToInternet();
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    // pd = new
    // ProgressDialog(this.cordova.getActivity().getApplicationContext());
    // pd.setCancelable(true);
    // pd.setMessage("Please Wait...");
    if (isInternetPresent) {
        if (args != null && args.length() > 0) {
            JSONArray arry = new JSONArray(jsondata);
            JSONObject obj = arry.getJSONObject(2);
            sgn = obj.getString("video");

            if (obj.has("video_thumbnail")) {
                String image = obj.getString("video_thumbnail");
                if (image != null) {
                    Log.d("image", image);
                    if (image.contains("content") || image.contains("file")) {
                        Log.d("content", "content");
                        String getString = getFileNameByUri(context, Uri.parse(image));
                        String thumb = reporteds(getString);
                        video(thumb, true);
                    } else {
                        Log.d("image", "image");
                        String thumb = reporteds(image);
                        video(thumb, true);
                    }
                } else {
                    Log.d("one", "videopath1");
                    Log.d("two-2", video_thumbpath.getAbsolutePath());
                    String thumb = reporteds(video_thumbpath.getAbsolutePath());
                    if (thumb != null) {
                        Log.d("thumb", thumb);
                        video(thumb, true);
                        Log.d("image path32", video_thumbpath.getAbsolutePath());
                    }
                }
            } else {
                Log.d("one", "videopath2");
                Log.d("two-2", video_thumbpath.getAbsolutePath());
                String thumb = reporteds(video_thumbpath.getAbsolutePath());
                if (thumb != null) {
                    Log.d("thumb", thumb);
                    video(thumb, true);
                    Log.d("image path32", video_thumbpath.getAbsolutePath());
                }
            }

        } else {
            PluginResult progressResult = new PluginResult(PluginResult.Status.ERROR,
                    "parameter required or incorrect");
            progressResult.setKeepCallback(true);
            callbackContext.sendPluginResult(progressResult);
        }

    } else {
        toastsettext("No Internet Connection");
    }

    return true;// super.execute(action, args, callbackContext);
}

From source file:de.langerhans.wallet.WalletApplication.java

@Override
public void onCreate() {
    new LinuxSecureRandom(); // init proper random number generator

    initLogging();/*ww w .  ja  va2s.  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();

    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.Anderson.example.games.tanc.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    // Create the Google API Client with access to Games
    mGoogleApiClient = new GoogleApiClient.Builder(this).addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this).addApi(Games.API).addScope(Games.SCOPE_GAMES).build();

    mGoogleApiClient.connect();/*from   w w  w  .j a va  2 s. c  o m*/
    mMainMenuFragment = new MainMenuFragment();
    mGameplayFragment = new GameplayFragment();
    mWinFragment = new WinFragment();
    mListFragment = new com.Anderson.example.games.tanc.ListFragment();
    // listen to fragment events
    mListFragment.setListener(this);
    mMainMenuFragment.setListener(this);
    mGameplayFragment.setListener(this);
    mWinFragment.setListener(this);
    // add initial fragment (welcome fragment)
    getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, mMainMenuFragment).commit();
    try {
        AssetFileDescriptor afd = getAssets().openFd("sounds/backgroundSound.mp3");
        bg.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        bg.prepare();
        bg.setLooping(true);
        bg.setVolume(20, 20);
        bg.start();
        afd = getAssets().openFd("sounds/buttonSound.wav");
        mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
        mp.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }

    // IMPORTANT: if this Activity supported rotation, we'd have to be
    // more careful about adding the fragment, since the fragment would
    // already be there after rotation and trying to add it again would
    // result in overlapping fragments. But since we don't support rotation,
    // we don't deal with that for code simplicity.
}

From source file:com.savedollars.ProductTotalPriceDisplay.java

@Override
protected void onCreate(Bundle savedInstanceState) {

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

    String barcodeNumber = (getIntent().getStringExtra("barcodeNumber"));

    /*// w  w  w.  ja  v a  2 s  . c  om
     * If barcode number is scanned from main screen, Google API server call
     * is made to retrieve the product information. If we are returning from
     * existing view ( shipping, stocks) no server call is made. We display
     * the product information already stored in JSONData
     */

    if (barcodeNumber != null) {
        getProductDetails(barcodeNumber);
    } else {
        JSONData = (getIntent().getStringExtra("JsonData"));
        parseJsonData(JSONData);
    }
    super.onCreate(savedInstanceState);

    if (totalCount == 0) {
        setContentView(R.layout.nopdtinfo);
    } else {

        setContentView(R.layout.pdttotalpriceview);

        // 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();
            PDT_INFO[rowIndex][0] = String.valueOf(keyValuePairs.getKey());
            PDT_INFO[rowIndex][1] = "$" + String.valueOf(keyValuePairs.getValue());
            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:libraryjava.parseJSON.java

private void StrictMode() {

    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }//  w  ww  . j ava  2 s.c o m
}

From source file:org.hopestarter.wallet.WalletApplication.java

@Override
public void onCreate() {
    new LinuxSecureRandom(); // init proper random number generator

    initLogging();/*  ww w.  j  a va 2  s.c om*/

    getDefaultTracker();

    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();

    mPackageInfo = 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, mPackageInfo);
        }
    };

    initMnemonicCode();

    initServerApi();

    mConfig = new Configuration(PreferenceManager.getDefaultSharedPreferences(this), getResources());
    mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    mBlockchainServiceIntent = new Intent(this, BlockchainServiceImpl.class);
    mBlockchainServiceCancelCoinsReceivedIntent = new Intent(BlockchainService.ACTION_CANCEL_COINS_RECEIVED,
            null, this, BlockchainServiceImpl.class);
    mBlockchainServiceResetBlockchainIntent = new Intent(BlockchainService.ACTION_RESET_BLOCKCHAIN, null, this,
            BlockchainServiceImpl.class);

    mWalletFile = getFileStreamPath(Constants.Files.WALLET_FILENAME_PROTOBUF);

    loadWalletFromProtobuf();

    if (mConfig.versionCodeCrossed(mPackageInfo.versionCode, VERSION_CODE_SHOW_BACKUP_REMINDER)
            && !mWallet.getImportedKeys().isEmpty()) {
        log.info("showing backup reminder once, because of imported keys being present");
        mConfig.armBackupReminder();
    }

    mConfig.updateLastVersionCode(mPackageInfo.versionCode);
    mConfig.setExchangeCurrencyCode("EUR");

    afterLoadWallet();

    cleanupFiles();
}

From source file:biz.wiz.android.wallet.WalletApplication.java

@Override
public void onCreate() {

    new LinuxSecureRandom(); // init proper random number generator

    initLogging();//from w  w w .j  av a 2  s  . 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:com.jamsuni.jamsunicodescan.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //autoFocus = (CheckBox) findViewById(R.id.auto_focus);
    //useFlash = (CheckBox) findViewById(R.id.use_flash);
    barcodeValue = (TextView) findViewById(R.id.tvScanData);
    //barcodeFormat = (TextView)findViewById(R.id.tvCodeFormat);

    //autoFocus.setChecked(true);

    findViewById(R.id.btnScan).setOnClickListener(this);
    findViewById(R.id.btnHistory).setOnClickListener(this);
    findViewById(R.id.btnContentView).setOnClickListener(this);

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

    //checkPermissionsForAboveMarshmallow();
}

From source file:com.android.tv.TvApplication.java

@Override
public void onCreate() {
    super.onCreate();
    SharedPreferencesUtils.initialize(this);
    try {/* w  ww  . ja va2 s .  c o  m*/
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        mVersionName = pInfo.versionName;
    } catch (PackageManager.NameNotFoundException e) {
        Log.w(TAG, "Unable to find package '" + getPackageName() + "'.", e);
        mVersionName = "";
    }
    Log.i(TAG, "Starting Live TV " + getVersionName());
    // Only set StrictMode for ENG builds because the build server only produces userdebug
    // builds.
    if (BuildConfig.ENG && SystemProperties.ALLOW_STRICT_MODE.getValue()) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();
        if (BuildConfig.ENG && SystemProperties.ALLOW_DEATH_PENALTY.getValue()
                && !TvCommonUtils.isRunningInTest()) {
            // TODO turn on death penalty for tests when they stop leaking MainActivity
        }
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
    if (BuildConfig.ENG && !SystemProperties.ALLOW_ANALYTICS_IN_ENG.getValue()) {
        mAnalytics = StubAnalytics.getInstance(this);
    } else {
        mAnalytics = StubAnalytics.getInstance(this);
    }
    mTracker = mAnalytics.getDefaultTracker();
    mTvInputManagerHelper = new TvInputManagerHelper(this);
    mTvInputManagerHelper.start();
    mTvInputManagerHelper.addCallback(new TvInputCallback() {
        @Override
        public void onInputAdded(String inputId) {
            handleInputCountChanged();
        }

        @Override
        public void onInputRemoved(String inputId) {
            handleInputCountChanged();
        }
    });
    if (CommonFeatures.DVR.isEnabled(this) && BuildCompat.isAtLeastN()) {
        mDvrManager = new DvrManager(this);
        //NOTE: DvrRecordingService just keeps running.
        DvrRecordingService.startService(this);
    }
    // In SetupFragment, transitions are set in the constructor. Because the fragment can be
    // created in Activity.onCreate() by the framework, SetupAnimationHelper should be
    // initialized here before Activity.onCreate() is called.
    SetupAnimationHelper.initialize(this);
    if (DEBUG)
        Log.i(TAG, "Started Live TV " + mVersionName);
}

From source file:com.minglang.suiuu.application.SuiuuApplication.java

/**
 * ?OSS//  w  ww. j  a v  a2 s.c  o  m
 */
public void initAboutOSS() {
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);

    // ?
    ossService.setApplicationContext(this);
    ossService.setGlobalDefaultTokenGenerator(new TokenGenerator() { // 
        @Override
        public String generateToken(String httpMethod, String md5, String type, String date, String ossHeaders,
                String resource) {
            String content = httpMethod + "\n" + md5 + "\n" + type + "\n" + date + "\n" + ossHeaders + resource;
            return OSSToolKit.generateToken(accessKey, screctKey, content);
        }
    });

    ossService.setGlobalDefaultHostId("oss-cn-hongkong.aliyuncs.com");
    ossService.setCustomStandardTimeWithEpochSec(System.currentTimeMillis() / 1000);
    ossService.setGlobalDefaultACL(AccessControlList.PRIVATE); // private

    ClientConfiguration conf = new ClientConfiguration();
    conf.setConnectTimeout(15 * 1000); // 30s
    conf.setSocketTimeout(15 * 1000); // socket30s
    conf.setMaxConnections(50); // ?, 50
    ossService.setClientConfiguration(conf);
}