Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.net; |
| 18 | |
Christopher Tate | a2496de | 2014-08-06 14:19:56 -0700 | [diff] [blame] | 19 | import android.annotation.SystemApi; |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 20 | import android.app.DownloadManager; |
| 21 | import android.app.backup.BackupManager; |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 22 | import android.content.Context; |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 23 | import android.media.MediaPlayer; |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 24 | import android.os.RemoteException; |
| 25 | import android.os.ServiceManager; |
| 26 | |
Jesse Wilson | 8568db5 | 2011-06-28 19:06:31 -0700 | [diff] [blame] | 27 | import com.android.server.NetworkManagementSocketTagger; |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 28 | |
Jesse Wilson | 8568db5 | 2011-06-28 19:06:31 -0700 | [diff] [blame] | 29 | import dalvik.system.SocketTagger; |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 30 | |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 31 | import java.net.Socket; |
| 32 | import java.net.SocketException; |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 33 | |
| 34 | /** |
Dan Egnor | 2b4abcd | 2010-04-07 17:30:50 -0700 | [diff] [blame] | 35 | * Class that provides network traffic statistics. These statistics include |
| 36 | * bytes transmitted and received and network packets transmitted and received, |
| 37 | * over all interfaces, over the mobile interface, and on a per-UID basis. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 38 | * <p> |
Dan Egnor | 2b4abcd | 2010-04-07 17:30:50 -0700 | [diff] [blame] | 39 | * These statistics may not be available on all platforms. If the statistics |
| 40 | * are not supported by this device, {@link #UNSUPPORTED} will be returned. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 41 | */ |
| 42 | public class TrafficStats { |
| 43 | /** |
| 44 | * The return value to indicate that the device does not support the statistic. |
| 45 | */ |
| 46 | public final static int UNSUPPORTED = -1; |
| 47 | |
Jeff Sharkey | 241dde2 | 2012-02-03 14:50:07 -0800 | [diff] [blame] | 48 | /** @hide */ |
| 49 | public static final long KB_IN_BYTES = 1024; |
| 50 | /** @hide */ |
| 51 | public static final long MB_IN_BYTES = KB_IN_BYTES * 1024; |
| 52 | /** @hide */ |
| 53 | public static final long GB_IN_BYTES = MB_IN_BYTES * 1024; |
| 54 | |
Jeff Sharkey | d2a4587 | 2011-05-28 20:56:34 -0700 | [diff] [blame] | 55 | /** |
Jeff Sharkey | b09540f | 2011-06-19 01:08:12 -0700 | [diff] [blame] | 56 | * Special UID value used when collecting {@link NetworkStatsHistory} for |
| 57 | * removed applications. |
| 58 | * |
| 59 | * @hide |
| 60 | */ |
| 61 | public static final int UID_REMOVED = -4; |
| 62 | |
| 63 | /** |
Jeff Sharkey | cdd02c5d | 2011-09-16 01:52:49 -0700 | [diff] [blame] | 64 | * Special UID value used when collecting {@link NetworkStatsHistory} for |
| 65 | * tethering traffic. |
| 66 | * |
| 67 | * @hide |
| 68 | */ |
| 69 | public static final int UID_TETHERING = -5; |
| 70 | |
| 71 | /** |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 72 | * Default tag value for {@link DownloadManager} traffic. |
| 73 | * |
| 74 | * @hide |
| 75 | */ |
Jeff Sharkey | cdd02c5d | 2011-09-16 01:52:49 -0700 | [diff] [blame] | 76 | public static final int TAG_SYSTEM_DOWNLOAD = 0xFFFFFF01; |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Default tag value for {@link MediaPlayer} traffic. |
| 80 | * |
| 81 | * @hide |
| 82 | */ |
Jeff Sharkey | cdd02c5d | 2011-09-16 01:52:49 -0700 | [diff] [blame] | 83 | public static final int TAG_SYSTEM_MEDIA = 0xFFFFFF02; |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Default tag value for {@link BackupManager} traffic. |
| 87 | * |
| 88 | * @hide |
| 89 | */ |
Jeff Sharkey | cdd02c5d | 2011-09-16 01:52:49 -0700 | [diff] [blame] | 90 | public static final int TAG_SYSTEM_BACKUP = 0xFFFFFF03; |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 91 | |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 92 | private static INetworkStatsService sStatsService; |
| 93 | |
| 94 | private synchronized static INetworkStatsService getStatsService() { |
| 95 | if (sStatsService == null) { |
| 96 | sStatsService = INetworkStatsService.Stub.asInterface( |
| 97 | ServiceManager.getService(Context.NETWORK_STATS_SERVICE)); |
| 98 | } |
| 99 | return sStatsService; |
| 100 | } |
| 101 | |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 102 | /** |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 103 | * Snapshot of {@link NetworkStats} when the currently active profiling |
| 104 | * session started, or {@code null} if no session active. |
| 105 | * |
| 106 | * @see #startDataProfiling(Context) |
| 107 | * @see #stopDataProfiling(Context) |
| 108 | */ |
| 109 | private static NetworkStats sActiveProfilingStart; |
| 110 | |
| 111 | private static Object sProfilingLock = new Object(); |
| 112 | |
| 113 | /** |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 114 | * Set active tag to use when accounting {@link Socket} traffic originating |
| 115 | * from the current thread. Only one active tag per thread is supported. |
| 116 | * <p> |
| 117 | * Changes only take effect during subsequent calls to |
| 118 | * {@link #tagSocket(Socket)}. |
Jeff Sharkey | cdd02c5d | 2011-09-16 01:52:49 -0700 | [diff] [blame] | 119 | * <p> |
| 120 | * Tags between {@code 0xFFFFFF00} and {@code 0xFFFFFFFF} are reserved and |
| 121 | * used internally by system services like {@link DownloadManager} when |
| 122 | * performing traffic on behalf of an application. |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 123 | * |
| 124 | * @see #clearThreadStatsTag() |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 125 | */ |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 126 | public static void setThreadStatsTag(int tag) { |
Jesse Wilson | 8568db5 | 2011-06-28 19:06:31 -0700 | [diff] [blame] | 127 | NetworkManagementSocketTagger.setThreadSocketStatsTag(tag); |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 128 | } |
| 129 | |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 130 | /** |
Christopher Tate | a2496de | 2014-08-06 14:19:56 -0700 | [diff] [blame] | 131 | * System API for backup-related support components to tag network traffic |
| 132 | * appropriately. |
| 133 | * @hide |
| 134 | */ |
| 135 | @SystemApi |
| 136 | public static void setThreadStatsTagBackup() { |
| 137 | setThreadStatsTag(TAG_SYSTEM_BACKUP); |
| 138 | } |
| 139 | |
| 140 | /** |
Alon Albert | eaef351 | 2011-07-19 11:16:09 +0300 | [diff] [blame] | 141 | * Get the active tag used when accounting {@link Socket} traffic originating |
| 142 | * from the current thread. Only one active tag per thread is supported. |
| 143 | * {@link #tagSocket(Socket)}. |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 144 | * |
| 145 | * @see #setThreadStatsTag(int) |
Alon Albert | eaef351 | 2011-07-19 11:16:09 +0300 | [diff] [blame] | 146 | */ |
| 147 | public static int getThreadStatsTag() { |
| 148 | return NetworkManagementSocketTagger.getThreadSocketStatsTag(); |
| 149 | } |
| 150 | |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 151 | /** |
| 152 | * Clear any active tag set to account {@link Socket} traffic originating |
| 153 | * from the current thread. |
| 154 | * |
| 155 | * @see #setThreadStatsTag(int) |
| 156 | */ |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 157 | public static void clearThreadStatsTag() { |
Jesse Wilson | 8568db5 | 2011-06-28 19:06:31 -0700 | [diff] [blame] | 158 | NetworkManagementSocketTagger.setThreadSocketStatsTag(-1); |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /** |
| 162 | * Set specific UID to use when accounting {@link Socket} traffic |
| 163 | * originating from the current thread. Designed for use when performing an |
| 164 | * operation on behalf of another application. |
| 165 | * <p> |
| 166 | * Changes only take effect during subsequent calls to |
| 167 | * {@link #tagSocket(Socket)}. |
| 168 | * <p> |
| 169 | * To take effect, caller must hold |
| 170 | * {@link android.Manifest.permission#UPDATE_DEVICE_STATS} permission. |
| 171 | * |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 172 | * @hide |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 173 | */ |
Christopher Tate | a2496de | 2014-08-06 14:19:56 -0700 | [diff] [blame] | 174 | @SystemApi |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 175 | public static void setThreadStatsUid(int uid) { |
Jesse Wilson | 8568db5 | 2011-06-28 19:06:31 -0700 | [diff] [blame] | 176 | NetworkManagementSocketTagger.setThreadSocketStatsUid(uid); |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | /** {@hide} */ |
Christopher Tate | a2496de | 2014-08-06 14:19:56 -0700 | [diff] [blame] | 180 | @SystemApi |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 181 | public static void clearThreadStatsUid() { |
Jesse Wilson | 8568db5 | 2011-06-28 19:06:31 -0700 | [diff] [blame] | 182 | NetworkManagementSocketTagger.setThreadSocketStatsUid(-1); |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Tag the given {@link Socket} with any statistics parameters active for |
| 187 | * the current thread. Subsequent calls always replace any existing |
| 188 | * parameters. When finished, call {@link #untagSocket(Socket)} to remove |
| 189 | * statistics parameters. |
| 190 | * |
Jeff Sharkey | 4414cea | 2011-06-24 17:05:24 -0700 | [diff] [blame] | 191 | * @see #setThreadStatsTag(int) |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 192 | * @see #setThreadStatsUid(int) |
| 193 | */ |
| 194 | public static void tagSocket(Socket socket) throws SocketException { |
Jesse Wilson | 8568db5 | 2011-06-28 19:06:31 -0700 | [diff] [blame] | 195 | SocketTagger.get().tag(socket); |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Remove any statistics parameters from the given {@link Socket}. |
| 200 | */ |
| 201 | public static void untagSocket(Socket socket) throws SocketException { |
Jesse Wilson | 8568db5 | 2011-06-28 19:06:31 -0700 | [diff] [blame] | 202 | SocketTagger.get().untag(socket); |
Jeff Sharkey | 43be174 | 2011-04-21 18:45:43 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | /** |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 206 | * Start profiling data usage for current UID. Only one profiling session |
| 207 | * can be active at a time. |
| 208 | * |
| 209 | * @hide |
| 210 | */ |
| 211 | public static void startDataProfiling(Context context) { |
| 212 | synchronized (sProfilingLock) { |
| 213 | if (sActiveProfilingStart != null) { |
| 214 | throw new IllegalStateException("already profiling data"); |
| 215 | } |
| 216 | |
| 217 | // take snapshot in time; we calculate delta later |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 218 | sActiveProfilingStart = getDataLayerSnapshotForUid(context); |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 219 | } |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Stop profiling data usage for current UID. |
| 224 | * |
| 225 | * @return Detailed {@link NetworkStats} of data that occurred since last |
| 226 | * {@link #startDataProfiling(Context)} call. |
| 227 | * @hide |
| 228 | */ |
| 229 | public static NetworkStats stopDataProfiling(Context context) { |
| 230 | synchronized (sProfilingLock) { |
| 231 | if (sActiveProfilingStart == null) { |
| 232 | throw new IllegalStateException("not profiling data"); |
| 233 | } |
| 234 | |
Jeff Sharkey | 5a7bcf3 | 2012-01-10 17:24:44 -0800 | [diff] [blame] | 235 | // subtract starting values and return delta |
| 236 | final NetworkStats profilingStop = getDataLayerSnapshotForUid(context); |
| 237 | final NetworkStats profilingDelta = NetworkStats.subtract( |
Jeff Sharkey | 63abc37 | 2012-01-11 18:38:16 -0800 | [diff] [blame] | 238 | profilingStop, sActiveProfilingStart, null, null); |
Jeff Sharkey | 5a7bcf3 | 2012-01-10 17:24:44 -0800 | [diff] [blame] | 239 | sActiveProfilingStart = null; |
| 240 | return profilingDelta; |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 241 | } |
| 242 | } |
| 243 | |
| 244 | /** |
Jeff Sharkey | 558a232 | 2011-08-24 15:42:09 -0700 | [diff] [blame] | 245 | * Increment count of network operations performed under the accounting tag |
| 246 | * currently active on the calling thread. This can be used to derive |
| 247 | * bytes-per-operation. |
| 248 | * |
| 249 | * @param operationCount Number of operations to increment count by. |
| 250 | */ |
| 251 | public static void incrementOperationCount(int operationCount) { |
| 252 | final int tag = getThreadStatsTag(); |
| 253 | incrementOperationCount(tag, operationCount); |
| 254 | } |
| 255 | |
| 256 | /** |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 257 | * Increment count of network operations performed under the given |
| 258 | * accounting tag. This can be used to derive bytes-per-operation. |
| 259 | * |
| 260 | * @param tag Accounting tag used in {@link #setThreadStatsTag(int)}. |
| 261 | * @param operationCount Number of operations to increment count by. |
| 262 | */ |
| 263 | public static void incrementOperationCount(int tag, int operationCount) { |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 264 | final int uid = android.os.Process.myUid(); |
| 265 | try { |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 266 | getStatsService().incrementOperationCount(uid, tag, operationCount); |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 267 | } catch (RemoteException e) { |
| 268 | throw new RuntimeException(e); |
| 269 | } |
| 270 | } |
| 271 | |
Jeff Sharkey | b52e3e5 | 2012-04-06 11:12:08 -0700 | [diff] [blame] | 272 | /** {@hide} */ |
| 273 | public static void closeQuietly(INetworkStatsSession session) { |
| 274 | // TODO: move to NetworkStatsService once it exists |
| 275 | if (session != null) { |
| 276 | try { |
| 277 | session.close(); |
| 278 | } catch (RuntimeException rethrown) { |
| 279 | throw rethrown; |
| 280 | } catch (Exception ignored) { |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 285 | /** |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 286 | * Return number of packets transmitted across mobile networks since device |
| 287 | * boot. Counts packets across all mobile network interfaces, and always |
| 288 | * increases monotonically since device boot. Statistics are measured at the |
| 289 | * network layer, so they include both TCP and UDP usage. |
| 290 | * <p> |
| 291 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may |
| 292 | * return {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 293 | */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 294 | public static long getMobileTxPackets() { |
| 295 | long total = 0; |
| 296 | for (String iface : getMobileIfaces()) { |
| 297 | total += getTxPackets(iface); |
| 298 | } |
| 299 | return total; |
| 300 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 301 | |
| 302 | /** |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 303 | * Return number of packets received across mobile networks since device |
| 304 | * boot. Counts packets across all mobile network interfaces, and always |
| 305 | * increases monotonically since device boot. Statistics are measured at the |
| 306 | * network layer, so they include both TCP and UDP usage. |
| 307 | * <p> |
| 308 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may |
| 309 | * return {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 310 | */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 311 | public static long getMobileRxPackets() { |
| 312 | long total = 0; |
| 313 | for (String iface : getMobileIfaces()) { |
| 314 | total += getRxPackets(iface); |
| 315 | } |
| 316 | return total; |
| 317 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 318 | |
| 319 | /** |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 320 | * Return number of bytes transmitted across mobile networks since device |
| 321 | * boot. Counts packets across all mobile network interfaces, and always |
| 322 | * increases monotonically since device boot. Statistics are measured at the |
| 323 | * network layer, so they include both TCP and UDP usage. |
| 324 | * <p> |
| 325 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may |
| 326 | * return {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 327 | */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 328 | public static long getMobileTxBytes() { |
| 329 | long total = 0; |
| 330 | for (String iface : getMobileIfaces()) { |
| 331 | total += getTxBytes(iface); |
| 332 | } |
| 333 | return total; |
| 334 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 335 | |
| 336 | /** |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 337 | * Return number of bytes received across mobile networks since device boot. |
| 338 | * Counts packets across all mobile network interfaces, and always increases |
| 339 | * monotonically since device boot. Statistics are measured at the network |
| 340 | * layer, so they include both TCP and UDP usage. |
| 341 | * <p> |
| 342 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may |
| 343 | * return {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 344 | */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 345 | public static long getMobileRxBytes() { |
| 346 | long total = 0; |
| 347 | for (String iface : getMobileIfaces()) { |
| 348 | total += getRxBytes(iface); |
| 349 | } |
| 350 | return total; |
| 351 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 352 | |
Jeff Sharkey | 4b17a13 | 2013-02-05 21:32:33 -0800 | [diff] [blame] | 353 | /** {@hide} */ |
| 354 | public static long getMobileTcpRxPackets() { |
| 355 | long total = 0; |
| 356 | for (String iface : getMobileIfaces()) { |
| 357 | final long stat = nativeGetIfaceStat(iface, TYPE_TCP_RX_PACKETS); |
| 358 | if (stat != UNSUPPORTED) { |
| 359 | total += stat; |
| 360 | } |
| 361 | } |
| 362 | return total; |
| 363 | } |
| 364 | |
| 365 | /** {@hide} */ |
| 366 | public static long getMobileTcpTxPackets() { |
| 367 | long total = 0; |
| 368 | for (String iface : getMobileIfaces()) { |
| 369 | final long stat = nativeGetIfaceStat(iface, TYPE_TCP_TX_PACKETS); |
| 370 | if (stat != UNSUPPORTED) { |
| 371 | total += stat; |
| 372 | } |
| 373 | } |
| 374 | return total; |
| 375 | } |
| 376 | |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 377 | /** {@hide} */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 378 | public static long getTxPackets(String iface) { |
| 379 | return nativeGetIfaceStat(iface, TYPE_TX_PACKETS); |
| 380 | } |
Irfan Sheriff | 227bec4 | 2011-02-15 19:30:27 -0800 | [diff] [blame] | 381 | |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 382 | /** {@hide} */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 383 | public static long getRxPackets(String iface) { |
| 384 | return nativeGetIfaceStat(iface, TYPE_RX_PACKETS); |
| 385 | } |
Irfan Sheriff | 227bec4 | 2011-02-15 19:30:27 -0800 | [diff] [blame] | 386 | |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 387 | /** {@hide} */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 388 | public static long getTxBytes(String iface) { |
| 389 | return nativeGetIfaceStat(iface, TYPE_TX_BYTES); |
| 390 | } |
Irfan Sheriff | 227bec4 | 2011-02-15 19:30:27 -0800 | [diff] [blame] | 391 | |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 392 | /** {@hide} */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 393 | public static long getRxBytes(String iface) { |
| 394 | return nativeGetIfaceStat(iface, TYPE_RX_BYTES); |
| 395 | } |
Irfan Sheriff | 227bec4 | 2011-02-15 19:30:27 -0800 | [diff] [blame] | 396 | |
| 397 | /** |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 398 | * Return number of packets transmitted since device boot. Counts packets |
| 399 | * across all network interfaces, and always increases monotonically since |
| 400 | * device boot. Statistics are measured at the network layer, so they |
| 401 | * include both TCP and UDP usage. |
| 402 | * <p> |
| 403 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may |
| 404 | * return {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 405 | */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 406 | public static long getTotalTxPackets() { |
| 407 | return nativeGetTotalStat(TYPE_TX_PACKETS); |
| 408 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 409 | |
| 410 | /** |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 411 | * Return number of packets received since device boot. Counts packets |
| 412 | * across all network interfaces, and always increases monotonically since |
| 413 | * device boot. Statistics are measured at the network layer, so they |
| 414 | * include both TCP and UDP usage. |
| 415 | * <p> |
| 416 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may |
| 417 | * return {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 418 | */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 419 | public static long getTotalRxPackets() { |
| 420 | return nativeGetTotalStat(TYPE_RX_PACKETS); |
| 421 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 422 | |
| 423 | /** |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 424 | * Return number of bytes transmitted since device boot. Counts packets |
| 425 | * across all network interfaces, and always increases monotonically since |
| 426 | * device boot. Statistics are measured at the network layer, so they |
| 427 | * include both TCP and UDP usage. |
| 428 | * <p> |
| 429 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may |
| 430 | * return {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 431 | */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 432 | public static long getTotalTxBytes() { |
| 433 | return nativeGetTotalStat(TYPE_TX_BYTES); |
| 434 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 435 | |
| 436 | /** |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 437 | * Return number of bytes received since device boot. Counts packets across |
| 438 | * all network interfaces, and always increases monotonically since device |
| 439 | * boot. Statistics are measured at the network layer, so they include both |
| 440 | * TCP and UDP usage. |
| 441 | * <p> |
| 442 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may |
| 443 | * return {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 444 | */ |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 445 | public static long getTotalRxBytes() { |
| 446 | return nativeGetTotalStat(TYPE_RX_BYTES); |
| 447 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 448 | |
| 449 | /** |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 450 | * Return number of bytes transmitted by the given UID since device boot. |
| 451 | * Counts packets across all network interfaces, and always increases |
| 452 | * monotonically since device boot. Statistics are measured at the network |
| 453 | * layer, so they include both TCP and UDP usage. |
| 454 | * <p> |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 455 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may return |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 456 | * {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 457 | * |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 458 | * @see android.os.Process#myUid() |
| 459 | * @see android.content.pm.ApplicationInfo#uid |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 460 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 461 | public static long getUidTxBytes(int uid) { |
| 462 | return nativeGetUidStat(uid, TYPE_TX_BYTES); |
| 463 | } |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 464 | |
| 465 | /** |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 466 | * Return number of bytes received by the given UID since device boot. |
| 467 | * Counts packets across all network interfaces, and always increases |
| 468 | * monotonically since device boot. Statistics are measured at the network |
| 469 | * layer, so they include both TCP and UDP usage. |
| 470 | * <p> |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 471 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may return |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 472 | * {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 473 | * |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 474 | * @see android.os.Process#myUid() |
| 475 | * @see android.content.pm.ApplicationInfo#uid |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 476 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 477 | public static long getUidRxBytes(int uid) { |
| 478 | return nativeGetUidStat(uid, TYPE_RX_BYTES); |
| 479 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 480 | |
| 481 | /** |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 482 | * Return number of packets transmitted by the given UID since device boot. |
| 483 | * Counts packets across all network interfaces, and always increases |
| 484 | * monotonically since device boot. Statistics are measured at the network |
| 485 | * layer, so they include both TCP and UDP usage. |
| 486 | * <p> |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 487 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may return |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 488 | * {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 489 | * |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 490 | * @see android.os.Process#myUid() |
| 491 | * @see android.content.pm.ApplicationInfo#uid |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 492 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 493 | public static long getUidTxPackets(int uid) { |
| 494 | return nativeGetUidStat(uid, TYPE_TX_PACKETS); |
| 495 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 496 | |
| 497 | /** |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 498 | * Return number of packets received by the given UID since device boot. |
| 499 | * Counts packets across all network interfaces, and always increases |
| 500 | * monotonically since device boot. Statistics are measured at the network |
| 501 | * layer, so they include both TCP and UDP usage. |
| 502 | * <p> |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 503 | * Before {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, this may return |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 504 | * {@link #UNSUPPORTED} on devices where statistics aren't available. |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 505 | * |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 506 | * @see android.os.Process#myUid() |
| 507 | * @see android.content.pm.ApplicationInfo#uid |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 508 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 509 | public static long getUidRxPackets(int uid) { |
| 510 | return nativeGetUidStat(uid, TYPE_RX_PACKETS); |
| 511 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 512 | |
| 513 | /** |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 514 | * @deprecated Starting in {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 515 | * transport layer statistics are no longer available, and will |
| 516 | * always return {@link #UNSUPPORTED}. |
| 517 | * @see #getUidTxBytes(int) |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 518 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 519 | @Deprecated |
| 520 | public static long getUidTcpTxBytes(int uid) { |
| 521 | return UNSUPPORTED; |
| 522 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 523 | |
| 524 | /** |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 525 | * @deprecated Starting in {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 526 | * transport layer statistics are no longer available, and will |
| 527 | * always return {@link #UNSUPPORTED}. |
| 528 | * @see #getUidRxBytes(int) |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 529 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 530 | @Deprecated |
| 531 | public static long getUidTcpRxBytes(int uid) { |
| 532 | return UNSUPPORTED; |
| 533 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 534 | |
| 535 | /** |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 536 | * @deprecated Starting in {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 537 | * transport layer statistics are no longer available, and will |
| 538 | * always return {@link #UNSUPPORTED}. |
| 539 | * @see #getUidTxBytes(int) |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 540 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 541 | @Deprecated |
| 542 | public static long getUidUdpTxBytes(int uid) { |
| 543 | return UNSUPPORTED; |
| 544 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 545 | |
| 546 | /** |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 547 | * @deprecated Starting in {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 548 | * transport layer statistics are no longer available, and will |
| 549 | * always return {@link #UNSUPPORTED}. |
| 550 | * @see #getUidRxBytes(int) |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 551 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 552 | @Deprecated |
| 553 | public static long getUidUdpRxBytes(int uid) { |
| 554 | return UNSUPPORTED; |
| 555 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 556 | |
| 557 | /** |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 558 | * @deprecated Starting in {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 559 | * transport layer statistics are no longer available, and will |
| 560 | * always return {@link #UNSUPPORTED}. |
| 561 | * @see #getUidTxPackets(int) |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 562 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 563 | @Deprecated |
| 564 | public static long getUidTcpTxSegments(int uid) { |
| 565 | return UNSUPPORTED; |
| 566 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 567 | |
| 568 | /** |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 569 | * @deprecated Starting in {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 570 | * transport layer statistics are no longer available, and will |
| 571 | * always return {@link #UNSUPPORTED}. |
| 572 | * @see #getUidRxPackets(int) |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 573 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 574 | @Deprecated |
| 575 | public static long getUidTcpRxSegments(int uid) { |
| 576 | return UNSUPPORTED; |
| 577 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 578 | |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 579 | /** |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 580 | * @deprecated Starting in {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 581 | * transport layer statistics are no longer available, and will |
| 582 | * always return {@link #UNSUPPORTED}. |
| 583 | * @see #getUidTxPackets(int) |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 584 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 585 | @Deprecated |
| 586 | public static long getUidUdpTxPackets(int uid) { |
| 587 | return UNSUPPORTED; |
| 588 | } |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 589 | |
| 590 | /** |
Dianne Hackborn | 45e9ede | 2013-02-25 15:55:37 -0800 | [diff] [blame] | 591 | * @deprecated Starting in {@link android.os.Build.VERSION_CODES#JELLY_BEAN_MR2}, |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 592 | * transport layer statistics are no longer available, and will |
| 593 | * always return {@link #UNSUPPORTED}. |
| 594 | * @see #getUidRxPackets(int) |
Ashish Sharma | c39c1d4 | 2011-01-27 15:52:38 -0800 | [diff] [blame] | 595 | */ |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 596 | @Deprecated |
| 597 | public static long getUidUdpRxPackets(int uid) { |
| 598 | return UNSUPPORTED; |
| 599 | } |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 600 | |
| 601 | /** |
| 602 | * Return detailed {@link NetworkStats} for the current UID. Requires no |
| 603 | * special permission. |
| 604 | */ |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 605 | private static NetworkStats getDataLayerSnapshotForUid(Context context) { |
Jeff Sharkey | dddace7 | 2013-03-26 13:46:05 -0700 | [diff] [blame] | 606 | // TODO: take snapshot locally, since proc file is now visible |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 607 | final int uid = android.os.Process.myUid(); |
| 608 | try { |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 609 | return getStatsService().getDataLayerSnapshotForUid(uid); |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 610 | } catch (RemoteException e) { |
| 611 | throw new RuntimeException(e); |
| 612 | } |
| 613 | } |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 614 | |
| 615 | /** |
| 616 | * Return set of any ifaces associated with mobile networks since boot. |
| 617 | * Interfaces are never removed from this list, so counters should always be |
| 618 | * monotonic. |
| 619 | */ |
| 620 | private static String[] getMobileIfaces() { |
| 621 | try { |
| 622 | return getStatsService().getMobileIfaces(); |
| 623 | } catch (RemoteException e) { |
| 624 | throw new RuntimeException(e); |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | // NOTE: keep these in sync with android_net_TrafficStats.cpp |
| 629 | private static final int TYPE_RX_BYTES = 0; |
| 630 | private static final int TYPE_RX_PACKETS = 1; |
| 631 | private static final int TYPE_TX_BYTES = 2; |
| 632 | private static final int TYPE_TX_PACKETS = 3; |
Jeff Sharkey | 4b17a13 | 2013-02-05 21:32:33 -0800 | [diff] [blame] | 633 | private static final int TYPE_TCP_RX_PACKETS = 4; |
| 634 | private static final int TYPE_TCP_TX_PACKETS = 5; |
Jeff Sharkey | 234766a | 2012-04-10 19:48:07 -0700 | [diff] [blame] | 635 | |
| 636 | private static native long nativeGetTotalStat(int type); |
| 637 | private static native long nativeGetIfaceStat(String iface, int type); |
Jeff Sharkey | 92be93a | 2013-01-15 17:25:09 -0800 | [diff] [blame] | 638 | private static native long nativeGetUidStat(int uid, int type); |
Ken Shirriff | f7d0b01 | 2009-12-07 15:56:05 -0800 | [diff] [blame] | 639 | } |