Enable StrictMode checks for explicit garbageCollection from T.
This disallows calls to runtime.gc() in the new version of Android. Explicit GC calls are blocking and can thus cause runtime overhead. They used to be performed as a pattern in order to avoid GC_FOR_ALLOC. However, that was only the case for Dalvik, that is now discouraged for ART. Bug: 3400644 Test: m Test: atest StrictModeTest Change-Id: I4720f2b4c4047bb90a88b924c539690e3c202e08
This commit is contained in:
@@ -30707,6 +30707,7 @@ package android.os {
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder detectCustomSlowCalls();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder detectDiskReads();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder detectDiskWrites();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder detectExplicitGc();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder detectNetwork();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder detectResourceMismatches();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder detectUnbufferedIo();
|
||||
@@ -30721,6 +30722,7 @@ package android.os {
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder permitCustomSlowCalls();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder permitDiskReads();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder permitDiskWrites();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder permitExplicitGc();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder permitNetwork();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder permitResourceMismatches();
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder permitUnbufferedIo();
|
||||
@@ -31260,6 +31262,9 @@ package android.os.strictmode {
|
||||
public final class DiskWriteViolation extends android.os.strictmode.Violation {
|
||||
}
|
||||
|
||||
public final class ExplicitGcViolation extends android.os.strictmode.Violation {
|
||||
}
|
||||
|
||||
public final class FileUriExposedViolation extends android.os.strictmode.Violation {
|
||||
}
|
||||
|
||||
|
||||
@@ -1737,10 +1737,6 @@ package android.os {
|
||||
method public static void setViolationLogger(android.os.StrictMode.ViolationLogger);
|
||||
}
|
||||
|
||||
public static final class StrictMode.ThreadPolicy.Builder {
|
||||
method @NonNull public android.os.StrictMode.ThreadPolicy.Builder detectExplicitGc();
|
||||
}
|
||||
|
||||
public static final class StrictMode.ViolationInfo implements android.os.Parcelable {
|
||||
ctor public StrictMode.ViolationInfo(android.os.Parcel);
|
||||
ctor public StrictMode.ViolationInfo(android.os.Parcel, boolean);
|
||||
@@ -1959,13 +1955,6 @@ package android.os.storage {
|
||||
|
||||
}
|
||||
|
||||
package android.os.strictmode {
|
||||
|
||||
public final class ExplicitGcViolation extends android.os.strictmode.Violation {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
package android.os.vibrator {
|
||||
|
||||
public final class PrebakedSegment extends android.os.vibrator.VibrationEffectSegment {
|
||||
|
||||
@@ -26,6 +26,9 @@ import android.annotation.TestApi;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityThread;
|
||||
import android.app.IActivityManager;
|
||||
import android.app.compat.CompatChanges;
|
||||
import android.compat.annotation.ChangeId;
|
||||
import android.compat.annotation.EnabledSince;
|
||||
import android.compat.annotation.UnsupportedAppUsage;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -348,6 +351,13 @@ public final class StrictMode {
|
||||
public static final int NETWORK_POLICY_LOG = 1;
|
||||
/** {@hide} */
|
||||
public static final int NETWORK_POLICY_REJECT = 2;
|
||||
|
||||
/**
|
||||
* Detect explicit calls to {@link Runtime#gc()}.
|
||||
*/
|
||||
@ChangeId
|
||||
@EnabledSince(targetSdkVersion = Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
static final long DETECT_EXPLICIT_GC = 3400644L;
|
||||
|
||||
// TODO: wrap in some ImmutableHashMap thing.
|
||||
// Note: must be before static initialization of sVmPolicy.
|
||||
@@ -500,6 +510,7 @@ public final class StrictMode {
|
||||
* <p>As of the Gingerbread release this includes network and disk operations but will
|
||||
* likely expand in future releases.
|
||||
*/
|
||||
@SuppressWarnings("AndroidFrameworkCompatChange")
|
||||
public @NonNull Builder detectAll() {
|
||||
detectDiskReads();
|
||||
detectDiskWrites();
|
||||
@@ -515,6 +526,9 @@ public final class StrictMode {
|
||||
if (targetSdk >= Build.VERSION_CODES.O) {
|
||||
detectUnbufferedIo();
|
||||
}
|
||||
if (CompatChanges.isChangeEnabled(DETECT_EXPLICIT_GC)) {
|
||||
detectExplicitGc();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -595,26 +609,16 @@ public final class StrictMode {
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect explicit GC requests, i.e. calls to Runtime.gc().
|
||||
*
|
||||
* @hide
|
||||
* Detect calls to {@link Runtime#gc()}.
|
||||
*/
|
||||
@TestApi
|
||||
public @NonNull Builder detectExplicitGc() {
|
||||
// TODO(b/3400644): Un-hide this for next API update
|
||||
// TODO(b/3400644): Un-hide ExplicitGcViolation for next API update
|
||||
// TODO(b/3400644): Make DETECT_EXPLICIT_GC a @TestApi for next API update
|
||||
// TODO(b/3400644): Call this from detectAll in next API update
|
||||
return enable(DETECT_THREAD_EXPLICIT_GC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disable detection of explicit GC requests, i.e. calls to Runtime.gc().
|
||||
*
|
||||
* @hide
|
||||
* Disable detection of calls to {@link Runtime#gc()}.
|
||||
*/
|
||||
public @NonNull Builder permitExplicitGc() {
|
||||
// TODO(b/3400644): Un-hide this for next API update
|
||||
return disable(DETECT_THREAD_EXPLICIT_GC);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,10 +19,7 @@ import android.annotation.TestApi;
|
||||
|
||||
/**
|
||||
* See #{@link android.os.StrictMode.ThreadPolicy.Builder#detectExplicitGc()}.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
@TestApi
|
||||
public final class ExplicitGcViolation extends Violation {
|
||||
/** @hide */
|
||||
public ExplicitGcViolation() {
|
||||
|
||||
Reference in New Issue
Block a user