summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff Sharkey <jsharkey@android.com> 2018-03-26 13:11:33 -0600
committer Jeff Sharkey <jsharkey@android.com> 2018-03-26 13:12:39 -0600
commit121d565b65ab66e1e2804fc89c58e88cd91804fd (patch)
treea8a0a0d42789a9fc4fa4aa231bc4e35cd3e96f0a
parentb133cbfd0b5afb0217ee45c8e26847465c6a717a (diff)
API council requested tweaks to TrafficStats.
Test: atest android.appsecurity.cts.AppSecurityTests#testAppFailAccessPrivateData Bug: 71584606 Change-Id: I4be8a47d54a04f17cbaac735d543ff7d6370376d
-rw-r--r--api/current.txt3
-rw-r--r--api/removed.txt4
-rw-r--r--core/java/android/net/TrafficStats.java32
-rw-r--r--core/java/com/android/server/NetworkManagementSocketTagger.java4
4 files changed, 34 insertions, 9 deletions
diff --git a/api/current.txt b/api/current.txt
index 5e7fa591385e..26054ab057d7 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -27277,6 +27277,7 @@ package android.net {
method public static long getMobileTxBytes();
method public static long getMobileTxPackets();
method public static int getThreadStatsTag();
+ method public static int getThreadStatsUid();
method public static long getTotalRxBytes();
method public static long getTotalRxPackets();
method public static long getTotalTxBytes();
@@ -27296,7 +27297,7 @@ package android.net {
method public static void incrementOperationCount(int);
method public static void incrementOperationCount(int, int);
method public static void setThreadStatsTag(int);
- method public static void setThreadStatsUidSelf();
+ method public static void setThreadStatsUid(int);
method public static void tagDatagramSocket(java.net.DatagramSocket) throws java.net.SocketException;
method public static void tagFileDescriptor(java.io.FileDescriptor) throws java.io.IOException;
method public static void tagSocket(java.net.Socket) throws java.net.SocketException;
diff --git a/api/removed.txt b/api/removed.txt
index 1228fd18c71a..64a9c3f6666b 100644
--- a/api/removed.txt
+++ b/api/removed.txt
@@ -261,6 +261,10 @@ package android.net {
method public static deprecated org.apache.http.conn.ssl.SSLSocketFactory getHttpSocketFactory(int, android.net.SSLSessionCache);
}
+ public class TrafficStats {
+ method public static deprecated void setThreadStatsUidSelf();
+ }
+
}
package android.os {
diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java
index 7922276edb75..40d53b741d6b 100644
--- a/core/java/android/net/TrafficStats.java
+++ b/core/java/android/net/TrafficStats.java
@@ -16,7 +16,6 @@
package android.net;
-import android.annotation.RequiresPermission;
import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.annotation.TestApi;
@@ -259,30 +258,47 @@ public class TrafficStats {
/**
* Set specific UID to use when accounting {@link Socket} traffic
* originating from the current thread. Designed for use when performing an
- * operation on behalf of another application.
+ * operation on behalf of another application, or when another application
+ * is performing operations on your behalf.
+ * <p>
+ * Any app can <em>accept</em> blame for traffic performed on a socket
+ * originally created by another app by calling this method with the
+ * {@link android.system.Os#getuid()} value. However, only apps holding the
+ * {@code android.Manifest.permission#UPDATE_DEVICE_STATS} permission may
+ * <em>assign</em> blame to another UIDs.
* <p>
* Changes only take effect during subsequent calls to
* {@link #tagSocket(Socket)}.
- * <p>
- * To take effect, caller must hold
- * {@link android.Manifest.permission#UPDATE_DEVICE_STATS} permission.
- *
- * @hide
*/
@SystemApi
- @RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
+ @SuppressLint("Doclava125")
public static void setThreadStatsUid(int uid) {
NetworkManagementSocketTagger.setThreadSocketStatsUid(uid);
}
/**
+ * Get the active UID used when accounting {@link Socket} traffic originating
+ * from the current thread. Only one active tag per thread is supported.
+ * {@link #tagSocket(Socket)}.
+ *
+ * @see #setThreadStatsUid(int)
+ */
+ public static int getThreadStatsUid() {
+ return NetworkManagementSocketTagger.getThreadSocketStatsUid();
+ }
+
+ /**
* 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)}.
+ *
+ * @removed
+ * @deprecated use {@link #setThreadStatsUid(int)} instead.
*/
+ @Deprecated
public static void setThreadStatsUidSelf() {
setThreadStatsUid(android.os.Process.myUid());
}
diff --git a/core/java/com/android/server/NetworkManagementSocketTagger.java b/core/java/com/android/server/NetworkManagementSocketTagger.java
index 03f2bc10b551..2959667e046f 100644
--- a/core/java/com/android/server/NetworkManagementSocketTagger.java
+++ b/core/java/com/android/server/NetworkManagementSocketTagger.java
@@ -67,6 +67,10 @@ public final class NetworkManagementSocketTagger extends SocketTagger {
return old;
}
+ public static int getThreadSocketStatsUid() {
+ return threadSocketTags.get().statsUid;
+ }
+
@Override
public void tag(FileDescriptor fd) throws SocketException {
final SocketTags options = threadSocketTags.get();