与华为Mate 9 Nougat的Android StrictMode问题

时间:2018-02-21 03:59:22

标签: android automated-tests android-espresso android-strictmode

我有一个Android Instrumented测试,我尝试启动我的应用程序并执行以下操作:

open class MyApplication : Application() {

...

  override fun onCreate() {
    super.onCreate()

    initialiseLogging()
    initialiseStrictMode()
    initialiseDependencyGraph()
  }

  private fun initialiseDependencyGraph() {
    applicationComponent = createApplicationComponent()
    applicationComponent.inject(this)
  }

...

  private fun initialiseStrictMode() {
    StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
      .detectDiskReads()
      .detectDiskWrites()
      .detectNetwork()
      .penaltyDeath()
      .build())
  }
}
当我在Firebase上运行时,

所有测试都会在大多数设备上传递,但带有Nougat的华为Mate 9(带有API 24的Android 7.0)除外。当我对这个设备运行我的测试时,我收到以下错误:

02-19 15:25:13.822: E/InstrumentationResultPrinter(10431): Failed to mark test No Tests as finished after process crash
02-19 15:25:13.822: E/MonitoringInstr(10431): Exception encountered by: au.com.dius.powersensor.platform.TestApp@2b58cb5. Dumping thread state to outputs and pining for the fjords.
02-19 15:25:13.822: E/MonitoringInstr(10431): android.os.StrictMode$StrictModeViolation: policy=262151 violation=2
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.os.StrictMode.executeDeathPenalty(StrictMode.java:1556)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.os.StrictMode.-wrap3(StrictMode.java)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.os.StrictMode$AndroidBlockGuardPolicy.handleViolation(StrictMode.java:1549)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.os.StrictMode$AndroidBlockGuardPolicy.handleViolationWithTimingAttempt(StrictMode.java:1367)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.os.StrictMode$AndroidBlockGuardPolicy.startHandlingViolationException(StrictMode.java:1337)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1306)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at java.io.UnixFileSystem.checkAccess(UnixFileSystem.java:249)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at java.io.File.exists(File.java:780)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.graphics.Typeface.initHwFontConfig(Typeface.java:295)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.graphics.Typeface.updateFont(Typeface.java:361)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.graphics.Typeface.loadSystemFonts(Typeface.java:444)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5671)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.app.ActivityThread.-wrap2(ActivityThread.java)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1637)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.os.Handler.dispatchMessage(Handler.java:102)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.os.Looper.loop(Looper.java:156)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at android.app.ActivityThread.main(ActivityThread.java:6524)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at java.lang.reflect.Method.invoke(Native Method)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:941)
02-19 15:25:13.822: E/MonitoringInstr(10431):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:831)

我很清楚,StricMode发现了一个奇怪的错误,ActivityThread尝试通过使用主线程从磁盘加载字体系统来初始化字体系统。

网上没有提供此漏洞的解决方案,我的测试仅针对此特定设备失败,这似乎很奇怪。

任何人对如何解决此问题或可能导致此问题的想法有任何想法?

0 个答案:

没有答案