Merge "Some StrictMode API changes." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
b1bbe99aaa
@@ -129270,7 +129270,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<method name="getThreadBlockingPolicy"
|
<method name="allowThreadDiskReads"
|
||||||
return="int"
|
return="int"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
native="false"
|
native="false"
|
||||||
@@ -129281,7 +129281,29 @@
|
|||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
</method>
|
</method>
|
||||||
<method name="setThreadBlockingPolicy"
|
<method name="allowThreadDiskWrites"
|
||||||
|
return="int"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="true"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="getThreadPolicy"
|
||||||
|
return="int"
|
||||||
|
abstract="false"
|
||||||
|
native="false"
|
||||||
|
synchronized="false"
|
||||||
|
static="true"
|
||||||
|
final="false"
|
||||||
|
deprecated="not deprecated"
|
||||||
|
visibility="public"
|
||||||
|
>
|
||||||
|
</method>
|
||||||
|
<method name="setThreadPolicy"
|
||||||
return="void"
|
return="void"
|
||||||
abstract="false"
|
abstract="false"
|
||||||
native="false"
|
native="false"
|
||||||
@@ -258023,7 +258045,7 @@
|
|||||||
>
|
>
|
||||||
<parameter name="numBits" type="int">
|
<parameter name="numBits" type="int">
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="rnd" type="java.util.Random">
|
<parameter name="random" type="java.util.Random">
|
||||||
</parameter>
|
</parameter>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor name="BigInteger"
|
<constructor name="BigInteger"
|
||||||
@@ -258037,7 +258059,7 @@
|
|||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="certainty" type="int">
|
<parameter name="certainty" type="int">
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="rnd" type="java.util.Random">
|
<parameter name="unused" type="java.util.Random">
|
||||||
</parameter>
|
</parameter>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor name="BigInteger"
|
<constructor name="BigInteger"
|
||||||
@@ -258047,7 +258069,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.lang.String">
|
<parameter name="value" type="java.lang.String">
|
||||||
</parameter>
|
</parameter>
|
||||||
</constructor>
|
</constructor>
|
||||||
<constructor name="BigInteger"
|
<constructor name="BigInteger"
|
||||||
@@ -258057,7 +258079,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.lang.String">
|
<parameter name="value" type="java.lang.String">
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="radix" type="int">
|
<parameter name="radix" type="int">
|
||||||
</parameter>
|
</parameter>
|
||||||
@@ -258081,7 +258103,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="byte[]">
|
<parameter name="value" type="byte[]">
|
||||||
</parameter>
|
</parameter>
|
||||||
</constructor>
|
</constructor>
|
||||||
<method name="abs"
|
<method name="abs"
|
||||||
@@ -258105,7 +258127,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="and"
|
<method name="and"
|
||||||
@@ -258118,7 +258140,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="andNot"
|
<method name="andNot"
|
||||||
@@ -258131,7 +258153,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="bitCount"
|
<method name="bitCount"
|
||||||
@@ -258179,7 +258201,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="divide"
|
<method name="divide"
|
||||||
@@ -258253,7 +258275,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="getLowestSetBit"
|
<method name="getLowestSetBit"
|
||||||
@@ -258312,7 +258334,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="min"
|
<method name="min"
|
||||||
@@ -258325,7 +258347,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="mod"
|
<method name="mod"
|
||||||
@@ -258379,7 +258401,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="negate"
|
<method name="negate"
|
||||||
@@ -258425,7 +258447,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="pow"
|
<method name="pow"
|
||||||
@@ -258453,7 +258475,7 @@
|
|||||||
>
|
>
|
||||||
<parameter name="bitLength" type="int">
|
<parameter name="bitLength" type="int">
|
||||||
</parameter>
|
</parameter>
|
||||||
<parameter name="rnd" type="java.util.Random">
|
<parameter name="unused" type="java.util.Random">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="remainder"
|
<method name="remainder"
|
||||||
@@ -258529,7 +258551,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="testBit"
|
<method name="testBit"
|
||||||
@@ -258579,7 +258601,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="long">
|
<parameter name="value" type="long">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<method name="xor"
|
<method name="xor"
|
||||||
@@ -258592,7 +258614,7 @@
|
|||||||
deprecated="not deprecated"
|
deprecated="not deprecated"
|
||||||
visibility="public"
|
visibility="public"
|
||||||
>
|
>
|
||||||
<parameter name="val" type="java.math.BigInteger">
|
<parameter name="value" type="java.math.BigInteger">
|
||||||
</parameter>
|
</parameter>
|
||||||
</method>
|
</method>
|
||||||
<field name="ONE"
|
<field name="ONE"
|
||||||
|
|||||||
@@ -3106,7 +3106,7 @@ public final class ActivityThread {
|
|||||||
(ApplicationInfo.FLAG_SYSTEM |
|
(ApplicationInfo.FLAG_SYSTEM |
|
||||||
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0 &&
|
ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) != 0 &&
|
||||||
!"user".equals(Build.TYPE)) {
|
!"user".equals(Build.TYPE)) {
|
||||||
StrictMode.setThreadBlockingPolicy(
|
StrictMode.setThreadPolicy(
|
||||||
StrictMode.DISALLOW_DISK_WRITE |
|
StrictMode.DISALLOW_DISK_WRITE |
|
||||||
StrictMode.DISALLOW_DISK_READ |
|
StrictMode.DISALLOW_DISK_READ |
|
||||||
StrictMode.DISALLOW_NETWORK |
|
StrictMode.DISALLOW_NETWORK |
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ public final class StrictMode {
|
|||||||
*
|
*
|
||||||
* @param policyMask a bitmask of DISALLOW_* and PENALTY_* values.
|
* @param policyMask a bitmask of DISALLOW_* and PENALTY_* values.
|
||||||
*/
|
*/
|
||||||
public static void setThreadBlockingPolicy(final int policyMask) {
|
public static void setThreadPolicy(final int policyMask) {
|
||||||
// In addition to the Java-level thread-local in Dalvik's
|
// In addition to the Java-level thread-local in Dalvik's
|
||||||
// BlockGuard, we also need to keep a native thread-local in
|
// BlockGuard, we also need to keep a native thread-local in
|
||||||
// Binder in order to propagate the value across Binder calls,
|
// Binder in order to propagate the value across Binder calls,
|
||||||
@@ -164,10 +164,42 @@ public final class StrictMode {
|
|||||||
*
|
*
|
||||||
* @return the bitmask of all the DISALLOW_* and PENALTY_* bits currently enabled
|
* @return the bitmask of all the DISALLOW_* and PENALTY_* bits currently enabled
|
||||||
*/
|
*/
|
||||||
public static int getThreadBlockingPolicy() {
|
public static int getThreadPolicy() {
|
||||||
return BlockGuard.getThreadPolicy().getPolicyMask();
|
return BlockGuard.getThreadPolicy().getPolicyMask();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current thread's policy mask to allow reading &
|
||||||
|
* writing to disk.
|
||||||
|
*
|
||||||
|
* @return the old policy mask, to be passed to setThreadPolicy to
|
||||||
|
* restore the policy.
|
||||||
|
*/
|
||||||
|
public static int allowThreadDiskWrites() {
|
||||||
|
int oldPolicy = getThreadPolicy();
|
||||||
|
int newPolicy = oldPolicy & ~(DISALLOW_DISK_WRITE | DISALLOW_DISK_READ);
|
||||||
|
if (newPolicy != oldPolicy) {
|
||||||
|
setThreadPolicy(newPolicy);
|
||||||
|
}
|
||||||
|
return oldPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the current thread's policy mask to allow reading from
|
||||||
|
* disk.
|
||||||
|
*
|
||||||
|
* @return the old policy mask, to be passed to setThreadPolicy to
|
||||||
|
* restore the policy.
|
||||||
|
*/
|
||||||
|
public static int allowThreadDiskReads() {
|
||||||
|
int oldPolicy = getThreadPolicy();
|
||||||
|
int newPolicy = oldPolicy & ~(DISALLOW_DISK_READ);
|
||||||
|
if (newPolicy != oldPolicy) {
|
||||||
|
setThreadPolicy(newPolicy);
|
||||||
|
}
|
||||||
|
return oldPolicy;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the BlockGuard policy mask out from the Exception's
|
* Parses the BlockGuard policy mask out from the Exception's
|
||||||
* getMessage() String value. Kinda gross, but least
|
* getMessage() String value. Kinda gross, but least
|
||||||
@@ -413,13 +445,13 @@ public final class StrictMode {
|
|||||||
if (violationMaskSubset != 0) {
|
if (violationMaskSubset != 0) {
|
||||||
int violationBit = parseViolationFromMessage(info.crashInfo.exceptionMessage);
|
int violationBit = parseViolationFromMessage(info.crashInfo.exceptionMessage);
|
||||||
violationMaskSubset |= violationBit;
|
violationMaskSubset |= violationBit;
|
||||||
final int savedPolicy = getThreadBlockingPolicy();
|
final int savedPolicy = getThreadPolicy();
|
||||||
try {
|
try {
|
||||||
// First, remove any policy before we call into the Activity Manager,
|
// First, remove any policy before we call into the Activity Manager,
|
||||||
// otherwise we'll infinite recurse as we try to log policy violations
|
// otherwise we'll infinite recurse as we try to log policy violations
|
||||||
// to disk, thus violating policy, thus requiring logging, etc...
|
// to disk, thus violating policy, thus requiring logging, etc...
|
||||||
// We restore the current policy below, in the finally block.
|
// We restore the current policy below, in the finally block.
|
||||||
setThreadBlockingPolicy(0);
|
setThreadPolicy(0);
|
||||||
|
|
||||||
ActivityManagerNative.getDefault().handleApplicationStrictModeViolation(
|
ActivityManagerNative.getDefault().handleApplicationStrictModeViolation(
|
||||||
RuntimeInit.getApplicationObject(),
|
RuntimeInit.getApplicationObject(),
|
||||||
@@ -429,7 +461,7 @@ public final class StrictMode {
|
|||||||
Log.e(TAG, "RemoteException trying to handle StrictMode violation", e);
|
Log.e(TAG, "RemoteException trying to handle StrictMode violation", e);
|
||||||
} finally {
|
} finally {
|
||||||
// Restore the policy.
|
// Restore the policy.
|
||||||
setThreadBlockingPolicy(savedPolicy);
|
setThreadPolicy(savedPolicy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,7 +519,7 @@ public final class StrictMode {
|
|||||||
new LogStackTrace().printStackTrace(new PrintWriter(sw));
|
new LogStackTrace().printStackTrace(new PrintWriter(sw));
|
||||||
String ourStack = sw.toString();
|
String ourStack = sw.toString();
|
||||||
|
|
||||||
int policyMask = getThreadBlockingPolicy();
|
int policyMask = getThreadPolicy();
|
||||||
boolean currentlyGathering = (policyMask & PENALTY_GATHER) != 0;
|
boolean currentlyGathering = (policyMask & PENALTY_GATHER) != 0;
|
||||||
|
|
||||||
int numViolations = p.readInt();
|
int numViolations = p.readInt();
|
||||||
|
|||||||
Reference in New Issue
Block a user