androidandroid-strictmode

StrictMode violation when using a phone number in a TextView


There is a StrictModeDiskRead violation when creating a layout containing a TextView with a phone number using the parameter android:autoLink="phone".

This is using com.android.support:appcompat-v7:22.2.0

Removing the autoLink parameter causes the violation to not occur.

Is there a way to fix this?

Stacktrace:

D/StrictMode﹕ StrictMode policy violation; ~duration=108 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=31 violation=2 at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1135) at libcore.io.BlockGuardOs.open(BlockGuardOs.java:106) at libcore.io.IoBridge.open(IoBridge.java:393) at java.io.RandomAccessFile.(RandomAccessFile.java:118) at java.io.RandomAccessFile.(RandomAccessFile.java:150) at java.util.zip.ZipFile.(ZipFile.java:149) at java.util.jar.JarFile.(JarFile.java:187) at libcore.net.url.JarURLConnectionImpl.openJarFile(JarURLConnectionImpl.java:136) at libcore.net.url.JarURLConnectionImpl.findJarFile(JarURLConnectionImpl.java:113) at libcore.net.url.JarURLConnectionImpl.connect(JarURLConnectionImpl.java:82) at libcore.net.url.JarURLConnectionImpl.getInputStream(JarURLConnectionImpl.java:215) at java.net.URL.openStream(URL.java:470) at java.lang.ClassLoader.getResourceAsStream(ClassLoader.java:432) at java.lang.Class.getResourceAsStream(Class.java:1037) at com.android.i18n.phonenumbers.PhoneNumberUtil.loadMetadataFromFile(PhoneNumberUtil.java:585) at com.android.i18n.phonenumbers.PhoneNumberUtil.getMetadataForRegion(PhoneNumberUtil.java:1925) at com.android.i18n.phonenumbers.PhoneNumberUtil.parseHelper(PhoneNumberUtil.java:2766) at com.android.i18n.phonenumbers.PhoneNumberUtil.parseAndKeepRawInput(PhoneNumberUtil.java:2679) at com.android.i18n.phonenumbers.PhoneNumberUtil.parseAndKeepRawInput(PhoneNumberUtil.java:2668) at com.android.i18n.phonenumbers.PhoneNumberMatcher.parseAndVerify(PhoneNumberMatcher.java:418) at com.android.i18n.phonenumbers.PhoneNumberMatcher.extractMatch(PhoneNumberMatcher.java:310) at com.android.i18n.phonenumbers.PhoneNumberMatcher.find(PhoneNumberMatcher.java:240) at com.android.i18n.phonenumbers.PhoneNumberMatcher.hasNext(PhoneNumberMatcher.java:652) at android.text.util.Linkify.gatherTelLinks(Linkify.java:454) at android.text.util.Linkify.addLinks(Linkify.java:230) at android.widget.TextView.setText(TextView.java:3749) at android.widget.TextView.setText(TextView.java:3671) at android.widget.TextView.(TextView.java:1270) at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:44) at android.support.v7.widget.AppCompatTextView.(AppCompatTextView.java:40) at android.support.v7.internal.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:103) at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:802) at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:832) at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44) at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684) at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839) at android.view.LayoutInflater.rInflate(LayoutInflater.java:745) at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) at android.view.LayoutInflater.inflate(LayoutInflater.java:492) at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

Edit: I am now using a ViewStub to load this view on-demand so it doesn't slow down the normal loading of the app


Solution

  • The stacktrace certainly looks like something normal. At least, it is not your code, it's system.

    From the docs:

    But don't feel compelled to fix everything that StrictMode finds. In particular, many cases of disk access are often necessary during the normal activity lifecycle. Use StrictMode to find things you did by accident.