API council requested tweaks to TrafficStats.
Test: atest android.appsecurity.cts.AppSecurityTests#testAppFailAccessPrivateData Bug: 71584606 Change-Id: I4be8a47d54a04f17cbaac735d543ff7d6370376d
This commit is contained in:
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
import android.annotation.RequiresPermission;
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.annotation.SystemApi;
|
import android.annotation.SystemApi;
|
||||||
import android.annotation.TestApi;
|
import android.annotation.TestApi;
|
||||||
@@ -259,22 +258,35 @@ public class TrafficStats {
|
|||||||
/**
|
/**
|
||||||
* Set specific UID to use when accounting {@link Socket} traffic
|
* Set specific UID to use when accounting {@link Socket} traffic
|
||||||
* originating from the current thread. Designed for use when performing an
|
* 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>
|
* <p>
|
||||||
* Changes only take effect during subsequent calls to
|
* Changes only take effect during subsequent calls to
|
||||||
* {@link #tagSocket(Socket)}.
|
* {@link #tagSocket(Socket)}.
|
||||||
* <p>
|
|
||||||
* To take effect, caller must hold
|
|
||||||
* {@link android.Manifest.permission#UPDATE_DEVICE_STATS} permission.
|
|
||||||
*
|
|
||||||
* @hide
|
|
||||||
*/
|
*/
|
||||||
@SystemApi
|
@SystemApi
|
||||||
@RequiresPermission(android.Manifest.permission.UPDATE_DEVICE_STATS)
|
@SuppressLint("Doclava125")
|
||||||
public static void setThreadStatsUid(int uid) {
|
public static void setThreadStatsUid(int uid) {
|
||||||
NetworkManagementSocketTagger.setThreadSocketStatsUid(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
|
* Set specific UID to use when accounting {@link Socket} traffic
|
||||||
* originating from the current thread as the calling UID. Designed for use
|
* originating from the current thread as the calling UID. Designed for use
|
||||||
@@ -282,7 +294,11 @@ public class TrafficStats {
|
|||||||
* <p>
|
* <p>
|
||||||
* Changes only take effect during subsequent calls to
|
* Changes only take effect during subsequent calls to
|
||||||
* {@link #tagSocket(Socket)}.
|
* {@link #tagSocket(Socket)}.
|
||||||
|
*
|
||||||
|
* @removed
|
||||||
|
* @deprecated use {@link #setThreadStatsUid(int)} instead.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public static void setThreadStatsUidSelf() {
|
public static void setThreadStatsUidSelf() {
|
||||||
setThreadStatsUid(android.os.Process.myUid());
|
setThreadStatsUid(android.os.Process.myUid());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user