Fast no-op path for StrictMode.Span on user builds.

Change-Id: I3eb75288d670a8ac1e10547715d8c1a855a5fdc9
diff --git a/core/java/android/os/StrictMode.java b/core/java/android/os/StrictMode.java
index 8762512..97f015b 100644
--- a/core/java/android/os/StrictMode.java
+++ b/core/java/android/os/StrictMode.java
@@ -106,6 +106,8 @@
     private static final String TAG = "StrictMode";
     private static final boolean LOG_V = false;
 
+    private static final boolean IS_USER_BUILD = "user".equals(Build.TYPE);
+
     // Only log a duplicate stack trace to the logs every second.
     private static final long MIN_LOG_INTERVAL_MS = 1000;
 
@@ -693,7 +695,7 @@
     public static boolean conditionallyEnableDebugLogging() {
         // For debug builds, log event loop stalls to dropbox for analysis.
         // Similar logic also appears in ActivityThread.java for system apps.
-        if ("user".equals(Build.TYPE)) {
+        if (IS_USER_BUILD) {
             setCloseGuardEnabled(false);
             return false;
         }
@@ -1240,6 +1242,11 @@
             mContainerState = threadState;
         }
 
+        // Empty constructor for the NO_OP_SPAN
+        protected Span() {
+            mContainerState = null;
+        }
+
         /**
          * To be called when the critical span is complete (i.e. the
          * animation is done animating).  This can be called on any
@@ -1286,6 +1293,13 @@
         }
     }
 
+    // The no-op span that's used in user builds.
+    private static final Span NO_OP_SPAN = new Span() {
+            public void finish() {
+                // Do nothing.
+            }
+        };
+
     /**
      * Linked lists of active spans and a freelist.
      *
@@ -1327,6 +1341,9 @@
      * @hide
      */
     public static Span enterCriticalSpan(String name) {
+        if (IS_USER_BUILD) {
+            return NO_OP_SPAN;
+        }
         if (name == null || name.isEmpty()) {
             throw new IllegalArgumentException("name must be non-null and non-empty");
         }