Option to enable StrictMode flashing on userdebug builds.

Change-Id: Ifc8e733ea0e0f6bda234a18ad84bcd230879e802
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index 854428f..c2ecf13 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -113,6 +113,13 @@
     private static final boolean IS_USER_BUILD = "user".equals(Build.TYPE);
     private static final boolean IS_ENG_BUILD = "eng".equals(Build.TYPE);
 
+    /**
+     * The boolean system property to control screen flashes on violations.
+     *
+     * @hide
+     */
+    public static final String VISUAL_PROPERTY = "persist.sys.strictmode.visual";
+
     // Only log a duplicate stack trace to the logs every second.
     private static final long MIN_LOG_INTERVAL_MS = 1000;
 
@@ -718,23 +725,36 @@
      * @hide
      */
     public static boolean conditionallyEnableDebugLogging() {
+        boolean doFlashes = SystemProperties.getBoolean(VISUAL_PROPERTY, IS_ENG_BUILD);
+
         // For debug builds, log event loop stalls to dropbox for analysis.
         // Similar logic also appears in ActivityThread.java for system apps.
-        if (IS_USER_BUILD) {
+        if (IS_USER_BUILD && !doFlashes) {
             setCloseGuardEnabled(false);
             return false;
         }
-        StrictMode.setThreadPolicyMask(
-            StrictMode.DETECT_DISK_WRITE |
-            StrictMode.DETECT_DISK_READ |
-            StrictMode.DETECT_NETWORK |
-            StrictMode.PENALTY_DROPBOX |
-            (IS_ENG_BUILD ? StrictMode.PENALTY_FLASH : 0)
-        );
-        sVmPolicyMask = StrictMode.DETECT_VM_CURSOR_LEAKS |
-                StrictMode.DETECT_VM_CLOSABLE_LEAKS |
-                StrictMode.PENALTY_DROPBOX;
-        setCloseGuardEnabled(vmClosableObjectLeaksEnabled());
+
+        int threadPolicyMask = StrictMode.DETECT_DISK_WRITE |
+                StrictMode.DETECT_DISK_READ |
+                StrictMode.DETECT_NETWORK;
+
+        if (!IS_USER_BUILD) {
+            threadPolicyMask |= StrictMode.PENALTY_DROPBOX;
+        }
+        if (doFlashes) {
+            threadPolicyMask |= StrictMode.PENALTY_FLASH;
+        }
+
+        StrictMode.setThreadPolicyMask(threadPolicyMask);
+
+        if (IS_USER_BUILD) {
+            setCloseGuardEnabled(false);
+        } else {
+            sVmPolicyMask = StrictMode.DETECT_VM_CURSOR_LEAKS |
+                    StrictMode.DETECT_VM_CLOSABLE_LEAKS |
+                    StrictMode.PENALTY_DROPBOX;
+            setCloseGuardEnabled(vmClosableObjectLeaksEnabled());
+        }
         return true;
     }
 
diff --git a/core/java/android/os/SystemProperties.java b/core/java/android/os/SystemProperties.java
index 4a036ec..619bf8d 100644
--- a/core/java/android/os/SystemProperties.java
+++ b/core/java/android/os/SystemProperties.java
@@ -93,7 +93,7 @@
      * Get the value for the given key, returned as a boolean.
      * Values 'n', 'no', '0', 'false' or 'off' are considered false.
      * Values 'y', 'yes', '1', 'true' or 'on' are considered true.
-     * (case insensitive).
+     * (case sensitive).
      * If the key does not exist, or has any other value, then the default
      * result is returned.
      * @param key the key to lookup
diff --git a/core/java/android/view/IWindowManager.aidl b/core/java/android/view/IWindowManager.aidl
index d964e2f..beda099 100644
--- a/core/java/android/view/IWindowManager.aidl
+++ b/core/java/android/view/IWindowManager.aidl
@@ -140,6 +140,12 @@
     // on screen)
     void showStrictModeViolation(boolean on);
 
+    // Proxy to set the system property for whether the flashing
+    // should be enabled.  The 'enabled' value is null or blank for
+    // the system default (differs per build variant) or any valid
+    // boolean string as parsed by SystemProperties.getBoolean().
+    void setStrictModeVisualIndicatorPreference(String enabled);
+
     // These can only be called with the SET_ORIENTATION permission.
     /**
      * Change the current screen rotation, constants as per
diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java
index 5c32c38..89512ae 100644
--- a/services/java/com/android/server/WindowManagerService.java
+++ b/services/java/com/android/server/WindowManagerService.java
@@ -4918,6 +4918,10 @@
         }
     }
 
+    public void setStrictModeVisualIndicatorPreference(String value) {
+        SystemProperties.set(StrictMode.VISUAL_PROPERTY, value);
+    }
+
     public void freezeRotation() {
         if (!checkCallingPermission(android.Manifest.permission.SET_ORIENTATION,
                 "setRotation()")) {