Example usage for android.os StrictMode setVmPolicy

List of usage examples for android.os StrictMode setVmPolicy

Introduction

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

Prototype

public static void setVmPolicy(final VmPolicy policy) 

Source Link

Document

Sets the policy for what actions in the VM process (on any thread) should be detected, as well as the penalty if such actions occur.

Usage

From source file:cc.softwarefactory.lokki.android.MainApplication.java

@Override
public void onCreate() {

    Log.e(TAG, "Lokki started component");

    loadSetting();//from www.  j  a v  a2  s  .  c  o  m

    locationDisabledPromptShown = false;

    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); // Use 1/8th of the available memory for this memory cache.
    final int cacheSize = maxMemory / 8;
    avatarCache = new LruCache<String, Bitmap>(cacheSize) {
        @Override
        protected int sizeOf(String key, Bitmap bitmap) {
            // The cache size will be measured in kilobytes rather than number of items.
            return (bitmap.getRowBytes() * bitmap.getHeight()) / 1024;
        }
    };

    String iDontWantToSeeString = PreferenceUtils.getString(this, PreferenceUtils.KEY_I_DONT_WANT_TO_SEE);
    if (!iDontWantToSeeString.isEmpty()) {
        try {
            MainApplication.iDontWantToSee = new JSONObject(iDontWantToSeeString);
        } catch (JSONException e) {
            MainApplication.iDontWantToSee = null;
            Log.e(TAG, e.getMessage());
        }
    } else {
        MainApplication.iDontWantToSee = new JSONObject();
    }
    Log.e(TAG, "MainApplication.iDontWantToSee: " + MainApplication.iDontWantToSee);

    if (DEVELOPER_MODE) {

        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());

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

    super.onCreate();
}

From source file:com.github.notizklotz.derbunddownloader.issuesgrid.DownloadedIssuesActivity.java

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

    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }/*from   w  ww. j  ava 2 s.c  o m*/

    PreferenceManager.setDefaultValues(getApplicationContext(), R.xml.preferences, false);

    if (!PreferenceManager.getDefaultSharedPreferences(this).contains(KEY_ALARM_MIGRATED)) {
        Log.i(getClass().getSimpleName(), "Migrating alarms");
        AutomaticIssueDownloadAlarmManager_.getInstance_(this).updateAlarm();
        PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean(KEY_ALARM_MIGRATED, true).apply();
    }
}

From source file:com.devspark.sidenavigation.meiriyiwen.MainActivity.java

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

    setContentView(R.layout.activity_main);
    icon = (ImageView) findViewById(android.R.id.icon);
    sideNavigationView = (SideNavigationView) findViewById(R.id.side_navigation_view);
    sideNavigationView.setMenuItems(R.menu.side_navigation_menu);
    sideNavigationView.setMenuClickCallback(this);

    if (getIntent().hasExtra(EXTRA_TITLE)) {
        String title = getIntent().getStringExtra(EXTRA_TITLE);
        int resId = getIntent().getIntExtra(EXTRA_RESOURCE_ID, 0);
        setTitle(title);//w w  w .  jav a  2  s .  c  o m
        icon.setImageResource(resId);
        sideNavigationView.setMode(getIntent().getIntExtra(EXTRA_MODE, 0) == 0 ? Mode.LEFT : Mode.RIGHT);
    }

    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
            .detectNetwork().penaltyLog().build());
    StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects()
            .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build());
    {
        String title = "http://meiriyiwen.com/index/mobile";
        //setTitle(title);
        WebView uiwebview = (WebView) findViewById(R.id.meiriyiwenWeb);
        uiwebview.setBackgroundColor(Color.BLACK);
        uiwebview.setWebViewClient(new Callback());
        uiwebview.getSettings().setBuiltInZoomControls(true);
        uiwebview.getSettings().setJavaScriptEnabled(true);
        uiwebview.loadUrl(title);

    }

    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

}

From source file:com.jalotsav.aalayamnavjivan.ActvtyBookView.java

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.lo_actvty_book_view);
    ButterKnife.bind(this);

    ActionBar mActionBar = getSupportActionBar();
    if (mActionBar != null)
        mActionBar.setDisplayHomeAsUpEnabled(true);

    mStorageRef = FirebaseStorage.getInstance().getReference();

    // for "Uri.fromFile()" in Share book
    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    StrictMode.setVmPolicy(builder.build());

    String selectedLanguage = getIntent().getStringExtra(AppConstants.PUT_EXTRA_LANGUAGE_NAME);
    if (selectedLanguage.equalsIgnoreCase(AppConstants.LANGUAGE_SHORTCODE_GUJARATI)) {
        mRequestedBookName = AppConstants.BOOKNAME_NAVJIVAN_GU;
        if (mActionBar != null)
            mActionBar.setTitle(// ww  w  .jav a2s .  c o m
                    getString(R.string.app_name).concat(" - ").concat(getString(R.string.gujarati_sml)));
    } else {
        mRequestedBookName = AppConstants.BOOKNAME_NAVJIVAN_EN;
        if (mActionBar != null)
            mActionBar.setTitle(
                    getString(R.string.app_name).concat(" - ").concat(getString(R.string.english_sml)));
    }

    checkAppPermission();
}

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. j  a va  2 s  .c  o m
@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.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());
    }//from ww  w . j a  v a 2 s.c o m
}

From source file:com.glm.trainer.NewMainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (mConnection == null)
        mConnection = new TrainerServiceConnection(this);
    if (false) {/*from w  ww.  j av  a 2  s .  c om*/
        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() //or .detectAll() for all detectable problems
                        .penaltyLog().penaltyDeath().build());
    }

    setContentView(R.layout.activity_new_main);

    oSummary = new SummaryFragment();
    oWorkout = new WorkoutFragment();
    oStore = new StoreFragment();
    oAbout = new AboutFragment();

    Rate.app_launched(this);
    super.onCreate(savedInstanceState);
}

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

@Override
public void onCreate() {
    super.onCreate();
    SharedPreferencesUtils.initialize(this);
    try {//from w w w . ja  v a  2 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: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 w  ww  . j av a  2  s  .co m
}

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

@Override
public void onCreate(Bundle icicle) {
    if (DEBUG)/*w  w w.j a  va 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);
}