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:
Jeff Sharkey
2011-06-24 17:05:24 -07:00
parent 2778a1ea73
commit 9279006a00
2 changed files with 39 additions and 6 deletions

View File

@@ -16,7 +16,10 @@
package android.net;
import android.app.DownloadManager;
import android.app.backup.BackupManager;
import android.content.Context;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.os.INetworkManagementService;
import android.os.RemoteException;
@@ -49,6 +52,27 @@ public class TrafficStats {
*/
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
* session started, or {@code null} if no session active.
@@ -67,12 +91,20 @@ public class TrafficStats {
* Changes only take effect during subsequent calls to
* {@link #tagSocket(Socket)}.
*/
public static void setThreadStatsTag(String tag) {
public static void setThreadStatsTag(int tag) {
BlockGuard.setThreadSocketStatsTag(tag);
}
/**
* @deprecated unsupported, will eventually be removed
*/
@Deprecated
public static void setThreadStatsTag(String tag) {
setThreadStatsTag(tag.hashCode());
}
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
* statistics parameters.
*
* @see #setThreadStatsTag(String)
* @see #setThreadStatsTag(int)
* @see #setThreadStatsUid(int)
*/
public static void tagSocket(Socket socket) throws SocketException {

View File

@@ -124,8 +124,6 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
private PendingIntent mPollIntent;
// 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
private static final long KB_IN_BYTES = 1024;
@@ -506,8 +504,11 @@ public class NetworkStatsService extends INetworkStatsService.Stub {
try {
networkSnapshot = mNetworkManager.getNetworkStatsSummary();
uidSnapshot = detailedPoll ? mNetworkManager.getNetworkStatsDetail() : null;
} catch (IllegalStateException e) {
Slog.w(TAG, "problem reading network stats: " + e);
return;
} catch (RemoteException e) {
Slog.w(TAG, "problem reading network stats");
Slog.w(TAG, "problem reading network stats: " + e);
return;
}