Strict mode violations list

早过忘川 提交于 2019-12-10 14:37:25

问题


running adb logcat in the shell i see something like this

StrictMode policy violation; ~duration=337 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=23 violation=2

  1. what the policy=23 means ?
  2. what is violation=2 ?

I was searching for the meanings of this values but I couldn't find any documentation whit violation and policy list, or maybe I interpreted the results from my search in a bad way, but I will appreciate some explanation about this


回答1:


what the policy=23 means ?

You can configure StrictMode to notify you of certain things and you can tell it how you'd like to get notified (simple log message, exception, ...). See the Enabling StrictMode section in this blog post for reference.

Policy is a bitmask that keeps track of that configuration internally. Since it's a mask it more intuitive to interpret it in binary, which is 10111. Then you can look up the relevant bits within the BlockGuard.java source file. Here is a short copy from this site (not sure what android version that is, there might be more things in newer versions; I don't have the current source on my machine right now):

public static final int DISALLOW_DISK_WRITE = 0x01;
public static final int DISALLOW_DISK_READ = 0x02;
public static final int DISALLOW_NETWORK = 0x04;
public static final int PASS_RESTRICTIONS_VIA_RPC = 0x08;
public static final int PENALTY_LOG = 0x10;
public static final int PENALTY_DIALOG = 0x20;
public static final int PENALTY_DEATH = 0x40;

With that you can tell that your StrictMode is configured to notify you of DISK_READ, DISK_WRITE and NETWORK violations via a log message.

and what is violation=2 ?

This ist just the type of the vialolation as some internal int constant. It doesn't help you much since the name of the exception gives that away already. The author just defined one getMessage() method that's used across all the different, subclassed StrictMode exceptions. Just for reference, these constants are defined within StrictMode.java.



来源:https://stackoverflow.com/questions/10953701/strict-mode-violations-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!