Skip to content

Commit 16ef577

Browse files
jsharkeyAndroid (Google) Code Review
authored andcommitted
Merge "API to adjust network stats. DO NOT MERGE." into jb-mr1-dev
2 parents 18a9172 + e7ed1ce commit 16ef577

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

core/java/android/net/INetworkStatsService.aidl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@ interface INetworkStatsService {
4545
/** Advise persistance threshold; may be overridden internally. */
4646
void advisePersistThreshold(long thresholdBytes);
4747

48+
/** Adjust recorded network stats. */
49+
void adjustNetworkStats(int uid, int tag, long rxBytes, long rxPackets, long txBytes, long txPackets, long operationCount);
50+
4851
}

core/java/android/net/TrafficStats.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,13 @@ public class TrafficStats {
8888
*/
8989
public static final int TAG_SYSTEM_BACKUP = 0xFFFFFF03;
9090

91+
/**
92+
* Default tag value for cloud messaging traffic.
93+
*
94+
* @hide
95+
*/
96+
public static final int TAG_SYSTEM_CLOUD_MESSAGING = 0xFFFFFF04;
97+
9198
private static INetworkStatsService sStatsService;
9299

93100
private synchronized static INetworkStatsService getStatsService() {
@@ -246,6 +253,27 @@ public static void incrementOperationCount(int tag, int operationCount) {
246253
}
247254
}
248255

256+
/**
257+
* Adjust network statistics for the given UID and tag by the requested
258+
* amount. This can be used to correctly account network usage performed on
259+
* behalf of another application. Values can be negative.
260+
* <p>
261+
* Requires that caller holds
262+
* {@link android.Manifest.permission#MODIFY_NETWORK_ACCOUNTING} permission.
263+
*
264+
* @see #setThreadStatsUid(int)
265+
* @hide
266+
*/
267+
public static void adjustNetworkStats(int uid, int tag, long rxBytes, long rxPackets,
268+
long txBytes, long txPackets, long operationCount) {
269+
try {
270+
getStatsService().adjustNetworkStats(
271+
uid, tag, rxBytes, rxPackets, txBytes, txPackets, operationCount);
272+
} catch (RemoteException e) {
273+
throw new RuntimeException(e);
274+
}
275+
}
276+
249277
/** {@hide} */
250278
public static void closeQuietly(INetworkStatsSession session) {
251279
// TODO: move to NetworkStatsService once it exists

services/java/com/android/server/net/NetworkStatsService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,14 @@ private void updatePersistThresholds() {
695695
mGlobalAlertBytes = mSettings.getGlobalAlertBytes(mPersistThreshold);
696696
}
697697

698+
@Override
699+
public void adjustNetworkStats(int uid, int tag, long rxBytes, long rxPackets, long txBytes,
700+
long txPackets, long operationCount) {
701+
mContext.enforceCallingOrSelfPermission(MODIFY_NETWORK_ACCOUNTING, TAG);
702+
703+
// TODO: store adjusted network stats in separate data structure
704+
}
705+
698706
/**
699707
* Receiver that watches for {@link IConnectivityManager} to claim network
700708
* interfaces. Used to associate {@link TelephonyManager#getSubscriberId()}

0 commit comments

Comments
 (0)