Add TrafficStats integration

Allow Request subclasses to set their TrafficStats tags. By default,
this is the hostname's hashCode() so that requests to different hosts
have different colors in DDMS.

Change-Id: Ibedf06fdcee108dcd170f5eb70aaecea5647d55d
diff --git a/src/com/android/volley/Request.java b/src/com/android/volley/Request.java
index f37727d..9fee0a0 100644
--- a/src/com/android/volley/Request.java
+++ b/src/com/android/volley/Request.java
@@ -16,11 +16,14 @@
 
 package com.android.volley;
 
-import com.android.volley.VolleyLog.MarkerLog;
-
+import android.net.TrafficStats;
+import android.net.Uri;
 import android.os.Handler;
 import android.os.Looper;
 import android.os.SystemClock;
+import android.text.TextUtils;
+
+import com.android.volley.VolleyLog.MarkerLog;
 
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
@@ -59,6 +62,9 @@
     /** URL of this request. */
     private final String mUrl;
 
+    /** Default tag for {@link TrafficStats}. */
+    private final int mDefaultTrafficStatsTag;
+
     /** Listener interface for errors. */
     private final Response.ErrorListener mErrorListener;
 
@@ -119,6 +125,8 @@
         mUrl = url;
         mErrorListener = listener;
         setRetryPolicy(new DefaultRetryPolicy());
+
+        mDefaultTrafficStatsTag = TextUtils.isEmpty(url) ? 0: Uri.parse(url).getHost().hashCode();
     }
 
     /**
@@ -145,6 +153,13 @@
     }
 
     /**
+     * @return A tag for use with {@link TrafficStats#setThreadStatsTag(int)}
+     */
+    public int getTrafficStatsTag() {
+        return mDefaultTrafficStatsTag;
+    }
+
+    /**
      * Sets the retry policy for this request.
      */
     public void setRetryPolicy(RetryPolicy retryPolicy) {
@@ -521,6 +536,8 @@
 
     @Override
     public String toString() {
-        return (mCanceled ? "[X] " : "[ ] ") + getUrl() + " " + getPriority() + " " + mSequence;
+        String trafficStatsTag = "0x" + Integer.toHexString(getTrafficStatsTag());
+        return (mCanceled ? "[X] " : "[ ] ") + getUrl() + " " + trafficStatsTag + " "
+                + getPriority() + " " + mSequence;
     }
 }