diff options
| author | Benedict Wong <benedictwong@google.com> | 2017-12-18 21:56:41 +0000 |
|---|---|---|
| committer | android-build-merger <android-build-merger@google.com> | 2017-12-18 21:56:41 +0000 |
| commit | 570970f6b2a72e10dcfbb27ad706c41074af3aba (patch) | |
| tree | 313198376c7b23e065b6f9fe3f9dc6c46bf11fbb /core/java/android | |
| parent | cab953250fff4b2926fc7e32e9e4464987a5cbca (diff) | |
| parent | 826657a9c274e2e2cd2789fc3ed535fd5729dd9c (diff) | |
Merge "[CHERRY-PICK] API for apps to tag sockets with their own UID." am: bef8c59634
am: 826657a9c2
Change-Id: Ia06653e6c1cccddcd2de17dd88a9ef47263f5c79
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/net/TrafficStats.java | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java index c339856f4388..954e59c2c424 100644 --- a/core/java/android/net/TrafficStats.java +++ b/core/java/android/net/TrafficStats.java @@ -17,6 +17,7 @@ package android.net; import android.annotation.RequiresPermission; +import android.annotation.SuppressLint; import android.annotation.SystemApi; import android.app.DownloadManager; import android.app.backup.BackupManager; @@ -30,6 +31,8 @@ import com.android.server.NetworkManagementSocketTagger; import dalvik.system.SocketTagger; +import java.io.FileDescriptor; +import java.io.IOException; import java.net.DatagramSocket; import java.net.Socket; import java.net.SocketException; @@ -264,14 +267,25 @@ public class TrafficStats { } /** + * Set specific UID to use when accounting {@link Socket} traffic + * originating from the current thread as the calling UID. Designed for use + * when another application is performing operations on your behalf. + * <p> + * Changes only take effect during subsequent calls to + * {@link #tagSocket(Socket)}. + */ + public static void setThreadStatsUidSelf() { + setThreadStatsUid(android.os.Process.myUid()); + } + + /** * Clear any active UID set to account {@link Socket} traffic originating * from the current thread. * * @see #setThreadStatsUid(int) - * @hide */ @SystemApi - @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS) + @SuppressLint("Doclava125") public static void clearThreadStatsUid() { NetworkManagementSocketTagger.setThreadSocketStatsUid(-1); } @@ -316,6 +330,27 @@ public class TrafficStats { } /** + * Tag the given {@link FileDescriptor} socket with any statistics + * parameters active for the current thread. Subsequent calls always replace + * any existing parameters. When finished, call + * {@link #untagFileDescriptor(FileDescriptor)} to remove statistics + * parameters. + * + * @see #setThreadStatsTag(int) + */ + public static void tagFileDescriptor(FileDescriptor fd) throws IOException { + SocketTagger.get().tag(fd); + } + + /** + * Remove any statistics parameters from the given {@link FileDescriptor} + * socket. + */ + public static void untagFileDescriptor(FileDescriptor fd) throws IOException { + SocketTagger.get().untag(fd); + } + + /** * Start profiling data usage for current UID. Only one profiling session * can be active at a time. * |
