From 5391d383626a06b515b65165155c9032483763fe Mon Sep 17 00:00:00 2001 From: Kevin Hufnagle Date: Sat, 6 Feb 2021 02:47:36 +0000 Subject: [PATCH] docs: Can leave StrictMode enabled in prod Google Play now checks StrictMode elements based on target SDK version, so it's safe for apps to leave StrictMode checks enabled in their production code. Bug: 179525953 Change-Id: I5a68d4892d521f5e62c25f57621f934c39436008 Test: m ds-docs-java Exempt-From-Owner-Approval: Docs-only change --- core/java/android/os/StrictMode.java | 30 ++++++++++++---------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java index 1189fdb0b04a0..fdf8ef0920069 100644 --- a/core/java/android/os/StrictMode.java +++ b/core/java/android/os/StrictMode.java @@ -114,20 +114,18 @@ import java.util.function.Consumer; * *
  * public void onCreate() {
- *     if (DEVELOPER_MODE) {
- *         StrictMode.setThreadPolicy(new {@link ThreadPolicy.Builder StrictMode.ThreadPolicy.Builder}()
- *                 .detectDiskReads()
- *                 .detectDiskWrites()
- *                 .detectNetwork()   // or .detectAll() for all detectable problems
- *                 .penaltyLog()
- *                 .build());
- *         StrictMode.setVmPolicy(new {@link VmPolicy.Builder StrictMode.VmPolicy.Builder}()
- *                 .detectLeakedSqlLiteObjects()
- *                 .detectLeakedClosableObjects()
- *                 .penaltyLog()
- *                 .penaltyDeath()
- *                 .build());
- *     }
+ *     StrictMode.setThreadPolicy(new {@link ThreadPolicy.Builder StrictMode.ThreadPolicy.Builder}()
+ *             .detectDiskReads()
+ *             .detectDiskWrites()
+ *             .detectNetwork()   // or .detectAll() for all detectable problems
+ *             .penaltyLog()
+ *             .build());
+ *     StrictMode.setVmPolicy(new {@link VmPolicy.Builder StrictMode.VmPolicy.Builder}()
+ *             .detectLeakedSqlLiteObjects()
+ *             .detectLeakedClosableObjects()
+ *             .penaltyLog()
+ *             .penaltyDeath()
+ *             .build());
  *     super.onCreate();
  * }
  * 
@@ -146,9 +144,7 @@ import java.util.function.Consumer; *

StrictMode is not a security mechanism and is not guaranteed to find all disk or * network accesses. While it does propagate its state across process boundaries when doing {@link * android.os.Binder} calls, it's still ultimately a best effort mechanism. Notably, disk or network - * access from JNI calls won't necessarily trigger it. Future versions of Android may catch more (or - * fewer) operations, so you should never leave StrictMode enabled in applications distributed on - * Google Play. + * access from JNI calls won't necessarily trigger it. */ public final class StrictMode { private static final String TAG = "StrictMode";