Strict mode violations list

2019-06-22 05:39发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-06-22 06:19

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.

查看更多
登录 后发表回答