method public static void setThreadPolicy(android.os.StrictMode.ThreadPolicy);
method public static void setViolationLogger(android.os.StrictMode.ViolationLogger);
method public static void setVmPolicy(android.os.StrictMode.VmPolicy);
+ field public static final int DETECT_CUSTOM = 8; // 0x8
+ field public static final int DETECT_DISK_READ = 2; // 0x2
+ field public static final int DETECT_DISK_WRITE = 1; // 0x1
+ field public static final int DETECT_NETWORK = 4; // 0x4
+ field public static final int DETECT_RESOURCE_MISMATCH = 16; // 0x10
+ field public static final int DETECT_UNBUFFERED_IO = 32; // 0x20
+ field public static final int DETECT_VM_ACTIVITY_LEAKS = 1024; // 0x400
+ field public static final int DETECT_VM_CLEARTEXT_NETWORK = 16384; // 0x4000
+ field public static final int DETECT_VM_CLOSABLE_LEAKS = 512; // 0x200
+ field public static final int DETECT_VM_CONTENT_URI_WITHOUT_PERMISSION = 32768; // 0x8000
+ field public static final int DETECT_VM_CURSOR_LEAKS = 256; // 0x100
+ field public static final int DETECT_VM_FILE_URI_EXPOSURE = 8192; // 0x2000
+ field public static final int DETECT_VM_INSTANCE_LEAKS = 2048; // 0x800
+ field public static final int DETECT_VM_REGISTRATION_LEAKS = 4096; // 0x1000
+ field public static final int DETECT_VM_UNTAGGED_SOCKET = -2147483648; // 0x80000000
}
public static final class StrictMode.ThreadPolicy {
// Byte 1: Thread-policy
/** @hide */
+ @TestApi
public static final int DETECT_DISK_WRITE = 0x01; // for ThreadPolicy
/** @hide */
+ @TestApi
public static final int DETECT_DISK_READ = 0x02; // for ThreadPolicy
/** @hide */
+ @TestApi
public static final int DETECT_NETWORK = 0x04; // for ThreadPolicy
/**
*
* @hide
*/
+ @TestApi
public static final int DETECT_CUSTOM = 0x08; // for ThreadPolicy
/**
*
* @hide
*/
+ @TestApi
public static final int DETECT_RESOURCE_MISMATCH = 0x10; // for ThreadPolicy
/** @hide */
+ @TestApi
public static final int DETECT_UNBUFFERED_IO = 0x20; // for ThreadPolicy
private static final int ALL_THREAD_DETECT_BITS =
*
* @hide
*/
+ @TestApi
public static final int DETECT_VM_CURSOR_LEAKS = 0x01 << 8; // for VmPolicy
/**
*
* @hide
*/
+ @TestApi
public static final int DETECT_VM_CLOSABLE_LEAKS = 0x02 << 8; // for VmPolicy
/**
*
* @hide
*/
+ @TestApi
public static final int DETECT_VM_ACTIVITY_LEAKS = 0x04 << 8; // for VmPolicy
/** @hide */
- private static final int DETECT_VM_INSTANCE_LEAKS = 0x08 << 8; // for VmPolicy
+ @TestApi
+ public static final int DETECT_VM_INSTANCE_LEAKS = 0x08 << 8; // for VmPolicy
/** @hide */
+ @TestApi
public static final int DETECT_VM_REGISTRATION_LEAKS = 0x10 << 8; // for VmPolicy
/** @hide */
- private static final int DETECT_VM_FILE_URI_EXPOSURE = 0x20 << 8; // for VmPolicy
+ @TestApi
+ public static final int DETECT_VM_FILE_URI_EXPOSURE = 0x20 << 8; // for VmPolicy
/** @hide */
- private static final int DETECT_VM_CLEARTEXT_NETWORK = 0x40 << 8; // for VmPolicy
+ @TestApi
+ public static final int DETECT_VM_CLEARTEXT_NETWORK = 0x40 << 8; // for VmPolicy
/** @hide */
- private static final int DETECT_VM_CONTENT_URI_WITHOUT_PERMISSION = 0x80 << 8; // for VmPolicy
+ @TestApi
+ public static final int DETECT_VM_CONTENT_URI_WITHOUT_PERMISSION = 0x80 << 8; // for VmPolicy
/** @hide */
- private static final int DETECT_VM_UNTAGGED_SOCKET = 0x80 << 24; // for VmPolicy
+ @TestApi
+ public static final int DETECT_VM_UNTAGGED_SOCKET = 0x80 << 24; // for VmPolicy
private static final int ALL_VM_DETECT_BITS =
DETECT_VM_CURSOR_LEAKS
}
/** @hide */
+ public static final String CLEARTEXT_DETECTED_MSG =
+ "Detected cleartext network traffic from UID ";
+
+ /** @hide */
public static void onCleartextNetworkDetected(byte[] firstPacket) {
byte[] rawAddr = null;
if (firstPacket != null) {
}
final int uid = android.os.Process.myUid();
- String msg = "Detected cleartext network traffic from UID " + uid;
+ String msg = CLEARTEXT_DETECTED_MSG + uid;
if (rawAddr != null) {
try {
- msg =
- "Detected cleartext network traffic from UID "
- + uid
- + " to "
- + InetAddress.getByAddress(rawAddr);
+ msg += " to " + InetAddress.getByAddress(rawAddr);
} catch (UnknownHostException ignored) {
}
}
}
/** @hide */
+ public static final String UNTAGGED_SOCKET_VIOLATION_MESSAGE =
+ "Untagged socket detected; use"
+ + " TrafficStats.setThreadSocketTag() to track all network usage";
+
+ /** @hide */
public static void onUntaggedSocket() {
- onVmPolicyViolation(
- null,
- new Throwable(
- "Untagged socket detected; use"
- + " TrafficStats.setThreadSocketTag() to track all network usage"));
+ onVmPolicyViolation(null, new Throwable(UNTAGGED_SOCKET_VIOLATION_MESSAGE));
}
// Map from VM violation fingerprint to uptime millis.