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)
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!