TrafficStats.java revision 2b4abcd0c7c4361af8ab6d5d7b073fb75ac6d219
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
17package android.net;
18
19import android.util.Log;
20
21import java.io.File;
22import java.io.RandomAccessFile;
23import java.io.IOException;
24
25/**
26 * Class that provides network traffic statistics.  These statistics include
27 * bytes transmitted and received and network packets transmitted and received,
28 * over all interfaces, over the mobile interface, and on a per-UID basis.
29 * <p>
30 * These statistics may not be available on all platforms.  If the statistics
31 * are not supported by this device, {@link #UNSUPPORTED} will be returned.
32 */
33public class TrafficStats {
34    /**
35     * The return value to indicate that the device does not support the statistic.
36     */
37    public final static int UNSUPPORTED = -1;
38
39    /**
40     * Get the total number of packets transmitted through the mobile interface.
41     *
42     * @return number of packets.  If the statistics are not supported by this device,
43     * {@link #UNSUPPORTED} will be returned.
44     */
45    public static native long getMobileTxPackets();
46
47    /**
48     * Get the total number of packets received through the mobile interface.
49     *
50     * @return number of packets.  If the statistics are not supported by this device,
51     * {@link #UNSUPPORTED} will be returned.
52     */
53    public static native long getMobileRxPackets();
54
55    /**
56     * Get the total number of bytes transmitted through the mobile interface.
57     *
58     * @return number of bytes.  If the statistics are not supported by this device,
59     * {@link #UNSUPPORTED} will be returned.
60     */
61      public static native long getMobileTxBytes();
62
63    /**
64     * Get the total number of bytes received through the mobile interface.
65     *
66     * @return number of bytes.  If the statistics are not supported by this device,
67     * {@link #UNSUPPORTED} will be returned.
68     */
69    public static native long getMobileRxBytes();
70
71    /**
72     * Get the total number of packets sent through all network interfaces.
73     *
74     * @return the number of packets.  If the statistics are not supported by this device,
75     * {@link #UNSUPPORTED} will be returned.
76     */
77    public static native long getTotalTxPackets();
78
79    /**
80     * Get the total number of packets received through all network interfaces.
81     *
82     * @return number of packets.  If the statistics are not supported by this device,
83     * {@link #UNSUPPORTED} will be returned.
84     */
85    public static native long getTotalRxPackets();
86
87    /**
88     * Get the total number of bytes sent through all network interfaces.
89     *
90     * @return number of bytes.  If the statistics are not supported by this device,
91     * {@link #UNSUPPORTED} will be returned.
92     */
93    public static native long getTotalTxBytes();
94
95    /**
96     * Get the total number of bytes received through all network interfaces.
97     *
98     * @return number of bytes.  If the statistics are not supported by this device,
99     * {@link #UNSUPPORTED} will be returned.
100     */
101    public static native long getTotalRxBytes();
102
103    /**
104     * Get the number of bytes sent through the network for this UID.
105     * The statistics are across all interfaces.
106     *
107     * {@see android.os.Process#myUid()}.
108     *
109     * @param uid The UID of the process to examine.
110     * @return number of bytes.  If the statistics are not supported by this device,
111     * {@link #UNSUPPORTED} will be returned.
112     */
113    public static native long getUidTxBytes(int uid);
114
115    /**
116     * Get the number of bytes received through the network for this UID.
117     * The statistics are across all interfaces.
118     *
119     * {@see android.os.Process#myUid()}.
120     *
121     * @param uid The UID of the process to examine.
122     * @return number of bytes
123     */
124    public static native long getUidRxBytes(int uid);
125}
126