Question

I've setup Strict mode and then I've set up Bugsense handler. This resulted in StrictMode policy violation.

Is there any logical explanation why it happens? How can I get rid of it?

MyApplication.java:

    android.os.StrictMode.ThreadPolicy.Builder threadPolicyBuilder = new android.os.StrictMode.ThreadPolicy.Builder();
    android.os.StrictMode.VmPolicy.Builder vmPolicyBuilder = new android.os.StrictMode.VmPolicy.Builder();
    android.os.StrictMode.setThreadPolicy(threadPolicyBuilder.detectAll().penaltyLog().build());
    android.os.StrictMode.setVmPolicy(vmPolicyBuilder.detectAll().penaltyLog().build());

    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {

                BugSenseHandler.initAndStartSession(MyApplication.this, "my-id");

            return null;
        }
    }.execute();

Stacktace:

01-21 09:43:40.889: D/StrictMode(29660): StrictMode policy violation: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2
01-21 09:43:40.889: D/StrictMode(29660):    at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:745)
01-21 09:43:40.889: D/StrictMode(29660):    at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:228)
01-21 09:43:40.889: D/StrictMode(29660):    at java.io.FileInputStream.<init>(FileInputStream.java:80)
01-21 09:43:40.889: D/StrictMode(29660):    at android.app.ContextImpl.getSharedPreferences(ContextImpl.java:381)
01-21 09:43:40.889: D/StrictMode(29660):    at android.content.ContextWrapper.getSharedPreferences(ContextWrapper.java:146)
01-21 09:43:40.889: D/StrictMode(29660):    at com.bugsense.trace.BugSenseHandler.initAndStartSession(Unknown Source)
01-21 09:43:40.889: D/StrictMode(29660):    at com.bugsense.trace.BugSenseHandler.initAndStartSession(Unknown Source)
01-21 09:43:40.889: D/StrictMode(29660):    at my.app$1.doInBackground(MyApplication.java:52)
01-21 09:43:40.889: D/StrictMode(29660):    at my.app$1.doInBackground(MyApplication.java:1)
01-21 09:43:40.889: D/StrictMode(29660):    at android.os.AsyncTask$2.call(AsyncTask.java:185)
01-21 09:43:40.889: D/StrictMode(29660):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
01-21 09:43:40.889: D/StrictMode(29660):    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
01-21 09:43:40.889: D/StrictMode(29660):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
01-21 09:43:40.889: D/StrictMode(29660):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
01-21 09:43:40.889: D/StrictMode(29660):    at java.lang.Thread.run(Thread.java:1019)
Was it helpful?

Solution

you get this error because the plugin reads information from the SharedPreferences in the main thread.

Unfortunately for the moment there is no way to get over this, except for lowering the policy of the Strict mode.

We are working on this and the next version of the BugSense plugin that will be released soon will be working great with Strict Mode.

Thank you for your feedback, it's very valuable, if you have any other question I will be happy to answer it at our support forums!

OTHER TIPS

Have you tried with the new release of the BugSense SDK (3.2)? They have fixed Strict Mode issues.

Check the changelog here.

I had similar problem. I created DEVELOPER_MODE for my app. It's just boolean flag which tells app if I am in developer mode. I enable strictmode only in developer mode, there is no reason to enable strictmode for published app. On the other hand I disable bugsense for developer mode because I don't need bugs report if I see them in LogCat. My code looks like this

public static final boolean DEVELOPER_MODE = true;


@Override
public void onCreate() {

    if (DEVELOPER_MODE) {
    StrictMode.setThreadPolicy(new  StrictMode.ThreadPolicy.Builder().detectAll().penaltyLog().build());
    StrictMode.setVmPolicy(new  StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());

    }else{
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {

                BugSenseHandler.initAndStartSession(MyApplication.this, "my-id");

            return null;
            }
        }.execute();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top