Better network stats parsing, integer tags, async.
Change NMS parsing to handle extended /proc/ stats formats by pairing values with header keys. Move TrafficStats to integer tags to match kernel internals, and offer well-known tags for system services. Async policy event dispatch from NPMS, and update tests to block for event dispatch. Narrow app policy to exclude apps signed with system key, which are usually critical. Bug: 4948913, 4903489, 4585280 Change-Id: Idb357227ccaa617906411f309371cea18d7bc519
This commit is contained in:
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package android.net;
|
package android.net;
|
||||||
|
|
||||||
|
import android.app.DownloadManager;
|
||||||
|
import android.app.backup.BackupManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.media.MediaPlayer;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.os.INetworkManagementService;
|
import android.os.INetworkManagementService;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
@@ -49,6 +52,27 @@ public class TrafficStats {
|
|||||||
*/
|
*/
|
||||||
public static final int UID_REMOVED = -4;
|
public static final int UID_REMOVED = -4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default tag value for {@link DownloadManager} traffic.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int TAG_SYSTEM_DOWNLOAD = 0xFFFF0001;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default tag value for {@link MediaPlayer} traffic.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int TAG_SYSTEM_MEDIA = 0xFFFF0002;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default tag value for {@link BackupManager} traffic.
|
||||||
|
*
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static final int TAG_SYSTEM_BACKUP = 0xFFFF0003;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Snapshot of {@link NetworkStats} when the currently active profiling
|
* Snapshot of {@link NetworkStats} when the currently active profiling
|
||||||
* session started, or {@code null} if no session active.
|
* session started, or {@code null} if no session active.
|
||||||
@@ -67,12 +91,20 @@ public class TrafficStats {
|
|||||||
* Changes only take effect during subsequent calls to
|
* Changes only take effect during subsequent calls to
|
||||||
* {@link #tagSocket(Socket)}.
|
* {@link #tagSocket(Socket)}.
|
||||||
*/
|
*/
|
||||||
public static void setThreadStatsTag(String tag) {
|
public static void setThreadStatsTag(int tag) {
|
||||||
BlockGuard.setThreadSocketStatsTag(tag);
|
BlockGuard.setThreadSocketStatsTag(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated unsupported, will eventually be removed
|
||||||
|
*/
|
||||||
|
@Deprecated
|
||||||
|
public static void setThreadStatsTag(String tag) {
|
||||||
|
setThreadStatsTag(tag.hashCode());
|
||||||
|
}
|
||||||
|
|
||||||
public static void clearThreadStatsTag() {
|
public static void clearThreadStatsTag() {
|
||||||
BlockGuard.setThreadSocketStatsTag(null);
|
BlockGuard.setThreadSocketStatsTag(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +135,7 @@ public class TrafficStats {
|
|||||||
* parameters. When finished, call {@link #untagSocket(Socket)} to remove
|
* parameters. When finished, call {@link #untagSocket(Socket)} to remove
|
||||||
* statistics parameters.
|
* statistics parameters.
|
||||||
*
|
*
|
||||||
* @see #setThreadStatsTag(String)
|
* @see #setThreadStatsTag(int)
|
||||||
* @see #setThreadStatsUid(int)
|
* @see #setThreadStatsUid(int)
|
||||||
*/
|
*/
|
||||||
public static void tagSocket(Socket socket) throws SocketException {
|
public static void tagSocket(Socket socket) throws SocketException {
|
||||||
|
|||||||
@@ -124,8 +124,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
private PendingIntent mPollIntent;
|
private PendingIntent mPollIntent;
|
||||||
|
|
||||||
// TODO: listen for kernel push events through netd instead of polling
|
// TODO: listen for kernel push events through netd instead of polling
|
||||||
// TODO: watch for UID uninstall, and transfer stats into single bucket
|
|
||||||
|
|
||||||
// TODO: trim empty history objects entirely
|
// TODO: trim empty history objects entirely
|
||||||
|
|
||||||
private static final long KB_IN_BYTES = 1024;
|
private static final long KB_IN_BYTES = 1024;
|
||||||
@@ -506,8 +504,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
|
|||||||
try {
|
try {
|
||||||
networkSnapshot = mNetworkManager.getNetworkStatsSummary();
|
networkSnapshot = mNetworkManager.getNetworkStatsSummary();
|
||||||
uidSnapshot = detailedPoll ? mNetworkManager.getNetworkStatsDetail() : null;
|
uidSnapshot = detailedPoll ? mNetworkManager.getNetworkStatsDetail() : null;
|
||||||
|
} catch (IllegalStateException e) {
|
||||||
|
Slog.w(TAG, "problem reading network stats: " + e);
|
||||||
|
return;
|
||||||
} catch (RemoteException e) {
|
} catch (RemoteException e) {
|
||||||
Slog.w(TAG, "problem reading network stats");
|
Slog.w(TAG, "problem reading network stats: " + e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user