diff options
author | Jeff Sharkey <jsharkey@android.com> | 2011-04-22 13:36:59 -0700 |
---|---|---|
committer | Jeff Sharkey <jsharkey@android.com> | 2011-05-13 17:12:40 -0700 |
commit | 3fb34dc34e5b352d52b769fd3b695fbd0e2d60f8 (patch) | |
tree | d8c107d6b6ebb0d3cf312d6979f7ad65cdcdf514 /src/com/android/providers | |
parent | 665f4105ea68a05d85dcd22cc9d823f45f7e6a37 (diff) | |
download | android_packages_providers_DownloadProvider-3fb34dc34e5b352d52b769fd3b695fbd0e2d60f8.tar.gz android_packages_providers_DownloadProvider-3fb34dc34e5b352d52b769fd3b695fbd0e2d60f8.tar.bz2 android_packages_providers_DownloadProvider-3fb34dc34e5b352d52b769fd3b695fbd0e2d60f8.zip |
Add Socket tagging for granular data accounting.
Tag active downloads, and account data usage towards UID that made
the original request. Also release WakeLock only after we've cleaned
up the download.
Change-Id: I72d58c6a51beaeb357e59aae4d7c0f5ac9abaa8d
Diffstat (limited to 'src/com/android/providers')
-rw-r--r-- | src/com/android/providers/downloads/DownloadThread.java | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/src/com/android/providers/downloads/DownloadThread.java b/src/com/android/providers/downloads/DownloadThread.java index fbd3b82c..082caa22 100644 --- a/src/com/android/providers/downloads/DownloadThread.java +++ b/src/com/android/providers/downloads/DownloadThread.java @@ -24,6 +24,7 @@ import android.content.Intent; import android.drm.mobile1.DrmRawContent; import android.net.http.AndroidHttpClient; import android.net.Proxy; +import android.net.TrafficStats; import android.os.FileUtils; import android.os.PowerManager; import android.os.Process; @@ -138,13 +139,17 @@ public class DownloadThread extends Thread { wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, Constants.TAG); wakeLock.acquire(); - if (Constants.LOGV) { Log.v(Constants.TAG, "initiating download for " + mInfo.mUri); } client = AndroidHttpClient.newInstance(userAgent(), mContext); + // network traffic on this thread should be counted against the + // requesting uid, and is tagged with well-known value. + TrafficStats.setThreadStatsTag("android:DownloadManager"); + TrafficStats.setThreadStatsUid(mInfo.mUid); + boolean finished = false; while(!finished) { Log.i(Constants.TAG, "Initiating request for download " + mInfo.mId); @@ -186,10 +191,9 @@ public class DownloadThread extends Thread { finalStatus = Downloads.Impl.STATUS_UNKNOWN_ERROR; // falls through to the code that reports an error } finally { - if (wakeLock != null) { - wakeLock.release(); - wakeLock = null; - } + TrafficStats.clearThreadStatsTag(); + TrafficStats.clearThreadStatsUid(); + if (client != null) { client.close(); client = null; @@ -199,6 +203,11 @@ public class DownloadThread extends Thread { state.mGotData, state.mFilename, state.mNewUri, state.mMimeType, errorMsg); DownloadHandler.getInstance().dequeueDownload(mInfo.mId); + + if (wakeLock != null) { + wakeLock.release(); + wakeLock = null; + } } mStorageManager.incrementNumDownloadsSoFar(); } |