API to adjust network stats. DO NOT MERGE.

Enables system apps to correctly account network usage performed on
behalf of another application.

Bug: 6695246
Change-Id: I39e243afd57936b6b30157a6ca511a17b6c55c39
This commit is contained in:
Jeff Sharkey
2012-07-27 17:35:32 -07:00
parent e94ac8b67e
commit 6615400fe8
3 changed files with 39 additions and 0 deletions

View File

@@ -45,4 +45,7 @@ interface INetworkStatsService {
/** Advise persistance threshold; may be overridden internally. */
void advisePersistThreshold(long thresholdBytes);
/** Adjust recorded network stats. */
void adjustNetworkStats(int uid, int tag, long rxBytes, long rxPackets, long txBytes, long txPackets, long operationCount);
}

View File

@@ -88,6 +88,13 @@ public class TrafficStats {
*/
public static final int TAG_SYSTEM_BACKUP = 0xFFFFFF03;
/**
* Default tag value for cloud messaging traffic.
*
* @hide
*/
public static final int TAG_SYSTEM_CLOUD_MESSAGING = 0xFFFFFF04;
private static INetworkStatsService sStatsService;
private synchronized static INetworkStatsService getStatsService() {
@@ -246,6 +253,27 @@ public class TrafficStats {
}
}
/**
* Adjust network statistics for the given UID and tag by the requested
* amount. This can be used to correctly account network usage performed on
* behalf of another application. Values can be negative.
* <p>
* Requires that caller holds
* {@link android.Manifest.permission#MODIFY_NETWORK_ACCOUNTING} permission.
*
* @see #setThreadStatsUid(int)
* @hide
*/
public static void adjustNetworkStats(int uid, int tag, long rxBytes, long rxPackets,
long txBytes, long txPackets, long operationCount) {
try {
getStatsService().adjustNetworkStats(
uid, tag, rxBytes, rxPackets, txBytes, txPackets, operationCount);
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
/** {@hide} */
public static void closeQuietly(INetworkStatsSession session) {
// TODO: move to NetworkStatsService once it exists