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:com.neogb.asynctaskfragment.sample.MainActivity.java

private void enableStrictMode() {
    if (BuildConfig.DEBUG) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().build());
    }/*from   w w  w  .  j av  a 2s.co m*/
}

From source file:com.example.app_2.utils.Utils.java

@TargetApi(11)
public static void enableStrictMode() {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();/* ww w . j a  va 2s  .  c o m*/
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            vmPolicyBuilder.setClassInstanceLimit(ImageGridActivity.class, 1);
            //.setClassInstanceLimit(ImageDetailActivity.class, 1);
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:be.ehb.fallwear.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (DEVELOPER_MODE) {
        StrictMode.setThreadPolicy(//from   w w  w.j a va2 s . co  m
                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);
    setContentView(R.layout.activity_main);

    mRegistrationProgressBar = (ProgressBar) findViewById(R.id.registrationProgressBar);
    mBtnReg = (Button) findViewById(R.id.btnReg);
    mBtnUnReg = (Button) findViewById(R.id.bntUnReg);

    mRegistrationBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            mBtnReg.setVisibility(View.GONE);
            mBtnUnReg.setVisibility(View.VISIBLE);
            mBtnReg.setEnabled(true);
            mInformationTextView.setVisibility(View.VISIBLE);

            SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
            boolean sentToken = sharedPreferences.getBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false);
            String token = sharedPreferences.getString(QuickstartPreferences.TOKEN, "00");
            if (sentToken) {
                String message = getResources().getString(R.string.gcm_send_message);
                mInformationTextView.setText(String.format(message, token));
            } else {
                mInformationTextView.setText(getString(R.string.token_error_message));
            }
        }
    };

    mUnRegisterBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            mRegistrationProgressBar.setVisibility(ProgressBar.GONE);
            mInformationTextView.setVisibility(View.VISIBLE);
            mBtnReg.setVisibility(View.VISIBLE);
            mBtnUnReg.setVisibility(View.GONE);
            mBtnUnReg.setEnabled(true);
            mInformationTextView.setText(R.string.unregistered);
        }
    };

    mInformationTextView = (TextView) findViewById(R.id.informationTextView);

}

From source file:com.android.volley.misc.Utils.java

@TargetApi(11)
public static void enableStrictMode() {
    if (Utils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();//w  w  w  . j  av a  2  s. co  m
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();

        if (Utils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:com.oakclub.android.base.OakClubApplication.java

@SuppressWarnings("unused")
@Override//w  ww  .j a va 2s  .  c o  m
public void onCreate() {
    if (Config.DEVELOPER_MODE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectAll().penaltyDialog().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyDeath().build());
    }

    super.onCreate();
    pingActivities();
    initImageLoader(getApplicationContext());

}

From source file:com.androiddevbook.onyourbike.chapter11.activities.BaseActivity.java

@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private void setupStrictMode() {
    // Make sure we do nothing silly!
    if (BuildConfig.DEBUG && Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {

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

        StrictMode
                .setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().penaltyDeath().build());
    }/*from  w ww.j a v a  2s.c  o  m*/
}

From source file:it.sineo.android.tileMapEditor.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (C.DEVELOPER_MODE) {
        StrictMode.setThreadPolicy(/*from w  ww  . ja  va  2  s. c  o m*/
                new StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().penaltyDeathOnNetwork().build());
        StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());
    }

    super.onCreate(savedInstanceState);
    setContentView(R.layout.home);

    gvPreview = (GridView) findViewById(R.id.home_grid);
    /* Empty grid view */
    emptyGrid = getLayoutInflater().inflate(R.layout.home_grid_empty, null);
    emptyGrid.findViewById(R.id.home_grid_empty).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(C.DIALOG_NEW_MAP);
        }
    });
    @SuppressWarnings("deprecation")
    int emptyGrid_layout_size = LayoutParams.FILL_PARENT;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        emptyGrid_layout_size = LayoutParams.MATCH_PARENT;
    }
    addContentView(emptyGrid, new LayoutParams(emptyGrid_layout_size, emptyGrid_layout_size));
    gvPreview.setEmptyView(emptyGrid);

    /* Real grid view, with background loading */
    getSupportLoaderManager().initLoader(0, null, this);

    String[] cols = new String[] { "_id", "_name", "_json_data", "_last_update", };

    adapter = new MySimpleCursorAdapter(getApplicationContext(), R.layout.home_grid_item, null, cols, null, 0);

    gvPreview.setAdapter(adapter);
    gvPreview.setOnItemClickListener(this);

    /* Context menu */
    registerForContextMenu(gvPreview);

    // showDialog(C.DIALOG_LOADING_MAPS);
    progressDialog = ProgressDialog.show(HomeActivity.this, null, getString(R.string.home_dlg_loading_maps),
            true);
}

From source file:com.qsoft.components.gallery.utils.GalleryUtils.java

@TargetApi(VERSION_CODES.HONEYCOMB)
public static void enableStrictMode() {
    if (GalleryUtils.hasGingerbread()) {
        StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder().detectAll()
                .penaltyLog();//from  www  .  jav a  2  s . c om
        StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();

        if (GalleryUtils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
            vmPolicyBuilder.setClassInstanceLimit(DISUploadImageActivity_.class, 1);
            //                        .setClassInstanceLimit(DISUploadImageActivity_.class, 1);
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:com.andrew.apollo.ApolloApplication.java

@TargetApi(11)
private void enableStrictMode() {
    if (ApolloUtils.hasGingerbread() && BuildConfig.DEBUG) {
        final StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new StrictMode.ThreadPolicy.Builder()
                .detectAll().penaltyLog();
        final StrictMode.VmPolicy.Builder vmPolicyBuilder = new StrictMode.VmPolicy.Builder().detectAll()
                .penaltyLog();//ww w. j ava2 s  . co  m

        if (ApolloUtils.hasHoneycomb()) {
            threadPolicyBuilder.penaltyFlashScreen();
        }
        StrictMode.setThreadPolicy(threadPolicyBuilder.build());
        StrictMode.setVmPolicy(vmPolicyBuilder.build());
    }
}

From source file:com.yattatech.dbtc.activity.SplashScreen.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (FACADE.isDeviceClockOutOfSync()) {
        Debug.d(mTag, "System clock is not supported");
        showMessage(R.string.system_clock_outof_sync);
        finish();/*from w w  w  .  j  av  a 2s  .c  o m*/
        return;
    }
    setContentView(R.layout.layout_splash_screen);
    mView = findViewById(R.id.content);
    mAnim = AnimationUtils.loadAnimation(this, R.anim.activity_open_scale);
    mView.setAnimation(mAnim);
    mAnim.setAnimationListener(mViewAnimationListener);
    Crittercism.initialize(getApplicationContext(), getString(R.string.crittercism_id));
    // make sure set android:debuggable as false, avoiding 
    // execution of bellow code block in release version
    final ApplicationInfo info = getApplicationInfo();
    if ((info.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
        Debug.d(mTag, "defining thread policy");
        StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites()
                .detectNetwork().penaltyLog().build());
        Debug.d(mTag, "defining VM policy");
        StrictMode.setVmPolicy(
                new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects().penaltyLog().build());
    }
    if (Debug.isDebugable()) {
        // Usefull to know current database state using some
        // external sqlite tool to check it out, for copying
        // that file to computer use adb command line
        DbUtil.copyDatabase(Environment.getExternalStorageDirectory().getAbsolutePath());
    }
}