diff options
| author | 2012-07-27 17:35:32 -0700 | |
|---|---|---|
| committer | 2012-07-31 11:45:17 -0700 | |
| commit | e7ed1ce4c84fe92caafc97b1f9044c6647aa3f7f (patch) | |
| tree | 4f2b555dd7fa1eb6a8bfd812b483db4e25a820a8 | |
| parent | 7267babae3695408daa96da1f5951c8f22e823a7 (diff) | |
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
| -rw-r--r-- | core/java/android/net/INetworkStatsService.aidl | 3 | ||||
| -rw-r--r-- | core/java/android/net/TrafficStats.java | 28 | ||||
| -rw-r--r-- | services/java/com/android/server/net/NetworkStatsService.java | 8 |
3 files changed, 39 insertions, 0 deletions
diff --git a/core/java/android/net/INetworkStatsService.aidl b/core/java/android/net/INetworkStatsService.aidl index b7b87318554c..4d46334fb33e 100644 --- a/core/java/android/net/INetworkStatsService.aidl +++ b/core/java/android/net/INetworkStatsService.aidl @@ -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); + } diff --git a/core/java/android/net/TrafficStats.java b/core/java/android/net/TrafficStats.java index e437d2e3475b..b66c2fe5cf8d 100644 --- a/core/java/android/net/TrafficStats.java +++ b/core/java/android/net/TrafficStats.java @@ -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 diff --git a/services/java/com/android/server/net/NetworkStatsService.java b/services/java/com/android/server/net/NetworkStatsService.java index ba122ecdf231..373576bd8ddd 100644 --- a/services/java/com/android/server/net/NetworkStatsService.java +++ b/services/java/com/android/server/net/NetworkStatsService.java @@ -695,6 +695,14 @@ public class NetworkStatsService extends INetworkStatsService.Stub { mGlobalAlertBytes = mSettings.getGlobalAlertBytes(mPersistThreshold); } + @Override + public void adjustNetworkStats(int uid, int tag, long rxBytes, long rxPackets, long txBytes, + long txPackets, long operationCount) { + mContext.enforceCallingOrSelfPermission(MODIFY_NETWORK_ACCOUNTING, TAG); + + // TODO: store adjusted network stats in separate data structure + } + /** * Receiver that watches for {@link IConnectivityManager} to claim network * interfaces. Used to associate {@link TelephonyManager#getSubscriberId()} |