Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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 | |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 19 | import static com.android.internal.util.Preconditions.checkNotNull; |
| 20 | |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 21 | import android.os.Parcel; |
| 22 | import android.os.Parcelable; |
| 23 | import android.os.SystemClock; |
Jeff Sharkey | 61ee0bb | 2011-05-29 22:50:42 -0700 | [diff] [blame] | 24 | import android.util.SparseBooleanArray; |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 25 | |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 26 | import com.android.internal.util.Objects; |
| 27 | |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 28 | import java.io.CharArrayWriter; |
| 29 | import java.io.PrintWriter; |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 30 | import java.util.Arrays; |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 31 | import java.util.HashSet; |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 34 | * Collection of active network statistics. Can contain summary details across |
| 35 | * all interfaces, or details with per-UID granularity. Internally stores data |
| 36 | * as a large table, closely matching {@code /proc/} data format. This structure |
| 37 | * optimizes for rapid in-memory comparison, but consider using |
| 38 | * {@link NetworkStatsHistory} when persisting. |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 39 | * |
| 40 | * @hide |
| 41 | */ |
| 42 | public class NetworkStats implements Parcelable { |
Jeff Sharkey | 47eb102 | 2011-08-25 17:48:52 -0700 | [diff] [blame] | 43 | private static final String TAG = "NetworkStats"; |
| 44 | |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 45 | /** {@link #iface} value when interface details unavailable. */ |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 46 | public static final String IFACE_ALL = null; |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 47 | /** {@link #uid} value when UID details unavailable. */ |
| 48 | public static final int UID_ALL = -1; |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 49 | /** {@link #set} value when all sets combined. */ |
| 50 | public static final int SET_ALL = -1; |
| 51 | /** {@link #set} value where background data is accounted. */ |
| 52 | public static final int SET_DEFAULT = 0; |
| 53 | /** {@link #set} value where foreground data is accounted. */ |
| 54 | public static final int SET_FOREGROUND = 1; |
| 55 | /** {@link #tag} value for total data across all tags. */ |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 56 | public static final int TAG_NONE = 0; |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 57 | |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 58 | // TODO: move fields to "mVariable" notation |
| 59 | |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 60 | /** |
| 61 | * {@link SystemClock#elapsedRealtime()} timestamp when this data was |
| 62 | * generated. |
| 63 | */ |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 64 | private final long elapsedRealtime; |
| 65 | private int size; |
| 66 | private String[] iface; |
| 67 | private int[] uid; |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 68 | private int[] set; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 69 | private int[] tag; |
| 70 | private long[] rxBytes; |
| 71 | private long[] rxPackets; |
| 72 | private long[] txBytes; |
| 73 | private long[] txPackets; |
Jeff Sharkey | 63d27a9 | 2011-08-03 17:04:22 -0700 | [diff] [blame] | 74 | private long[] operations; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 75 | |
| 76 | public static class Entry { |
| 77 | public String iface; |
| 78 | public int uid; |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 79 | public int set; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 80 | public int tag; |
| 81 | public long rxBytes; |
| 82 | public long rxPackets; |
| 83 | public long txBytes; |
| 84 | public long txPackets; |
Jeff Sharkey | 63d27a9 | 2011-08-03 17:04:22 -0700 | [diff] [blame] | 85 | public long operations; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 86 | |
| 87 | public Entry() { |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 88 | this(IFACE_ALL, UID_ALL, SET_DEFAULT, TAG_NONE, 0L, 0L, 0L, 0L, 0L); |
Jeff Sharkey | 63d27a9 | 2011-08-03 17:04:22 -0700 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | public Entry(long rxBytes, long rxPackets, long txBytes, long txPackets, long operations) { |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 92 | this(IFACE_ALL, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, |
| 93 | operations); |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 94 | } |
| 95 | |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 96 | public Entry(String iface, int uid, int set, int tag, long rxBytes, long rxPackets, |
| 97 | long txBytes, long txPackets, long operations) { |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 98 | this.iface = iface; |
| 99 | this.uid = uid; |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 100 | this.set = set; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 101 | this.tag = tag; |
| 102 | this.rxBytes = rxBytes; |
| 103 | this.rxPackets = rxPackets; |
| 104 | this.txBytes = txBytes; |
| 105 | this.txPackets = txPackets; |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 106 | this.operations = operations; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 107 | } |
Jeff Sharkey | b3d5957 | 2011-09-07 17:20:27 -0700 | [diff] [blame] | 108 | |
| 109 | @Override |
| 110 | public String toString() { |
| 111 | final StringBuilder builder = new StringBuilder(); |
| 112 | builder.append("iface=").append(iface); |
| 113 | builder.append(" uid=").append(uid); |
| 114 | builder.append(" set=").append(setToString(set)); |
| 115 | builder.append(" tag=").append(tagToString(tag)); |
| 116 | builder.append(" rxBytes=").append(rxBytes); |
| 117 | builder.append(" rxPackets=").append(rxPackets); |
| 118 | builder.append(" txBytes=").append(txBytes); |
| 119 | builder.append(" txPackets=").append(txPackets); |
| 120 | builder.append(" operations=").append(operations); |
| 121 | return builder.toString(); |
| 122 | } |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 123 | } |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 124 | |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 125 | public NetworkStats(long elapsedRealtime, int initialSize) { |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 126 | this.elapsedRealtime = elapsedRealtime; |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 127 | this.size = 0; |
| 128 | this.iface = new String[initialSize]; |
| 129 | this.uid = new int[initialSize]; |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 130 | this.set = new int[initialSize]; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 131 | this.tag = new int[initialSize]; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 132 | this.rxBytes = new long[initialSize]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 133 | this.rxPackets = new long[initialSize]; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 134 | this.txBytes = new long[initialSize]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 135 | this.txPackets = new long[initialSize]; |
Jeff Sharkey | 63d27a9 | 2011-08-03 17:04:22 -0700 | [diff] [blame] | 136 | this.operations = new long[initialSize]; |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | public NetworkStats(Parcel parcel) { |
| 140 | elapsedRealtime = parcel.readLong(); |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 141 | size = parcel.readInt(); |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 142 | iface = parcel.createStringArray(); |
| 143 | uid = parcel.createIntArray(); |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 144 | set = parcel.createIntArray(); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 145 | tag = parcel.createIntArray(); |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 146 | rxBytes = parcel.createLongArray(); |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 147 | rxPackets = parcel.createLongArray(); |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 148 | txBytes = parcel.createLongArray(); |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 149 | txPackets = parcel.createLongArray(); |
Jeff Sharkey | 63d27a9 | 2011-08-03 17:04:22 -0700 | [diff] [blame] | 150 | operations = parcel.createLongArray(); |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /** {@inheritDoc} */ |
| 154 | public void writeToParcel(Parcel dest, int flags) { |
| 155 | dest.writeLong(elapsedRealtime); |
| 156 | dest.writeInt(size); |
| 157 | dest.writeStringArray(iface); |
| 158 | dest.writeIntArray(uid); |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 159 | dest.writeIntArray(set); |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 160 | dest.writeIntArray(tag); |
| 161 | dest.writeLongArray(rxBytes); |
| 162 | dest.writeLongArray(rxPackets); |
| 163 | dest.writeLongArray(txBytes); |
| 164 | dest.writeLongArray(txPackets); |
Jeff Sharkey | 63d27a9 | 2011-08-03 17:04:22 -0700 | [diff] [blame] | 165 | dest.writeLongArray(operations); |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 166 | } |
| 167 | |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 168 | // @VisibleForTesting |
| 169 | public NetworkStats addIfaceValues( |
| 170 | String iface, long rxBytes, long rxPackets, long txBytes, long txPackets) { |
| 171 | return addValues( |
| 172 | iface, UID_ALL, SET_DEFAULT, TAG_NONE, rxBytes, rxPackets, txBytes, txPackets, 0L); |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 175 | // @VisibleForTesting |
| 176 | public NetworkStats addValues(String iface, int uid, int set, int tag, long rxBytes, |
| 177 | long rxPackets, long txBytes, long txPackets, long operations) { |
| 178 | return addValues(new Entry( |
| 179 | iface, uid, set, tag, rxBytes, rxPackets, txBytes, txPackets, operations)); |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Add new stats entry, copying from given {@link Entry}. The {@link Entry} |
| 184 | * object can be recycled across multiple calls. |
| 185 | */ |
| 186 | public NetworkStats addValues(Entry entry) { |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 187 | if (size >= this.iface.length) { |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 188 | final int newLength = Math.max(iface.length, 10) * 3 / 2; |
| 189 | iface = Arrays.copyOf(iface, newLength); |
| 190 | uid = Arrays.copyOf(uid, newLength); |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 191 | set = Arrays.copyOf(set, newLength); |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 192 | tag = Arrays.copyOf(tag, newLength); |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 193 | rxBytes = Arrays.copyOf(rxBytes, newLength); |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 194 | rxPackets = Arrays.copyOf(rxPackets, newLength); |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 195 | txBytes = Arrays.copyOf(txBytes, newLength); |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 196 | txPackets = Arrays.copyOf(txPackets, newLength); |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 197 | operations = Arrays.copyOf(operations, newLength); |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 200 | iface[size] = entry.iface; |
| 201 | uid[size] = entry.uid; |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 202 | set[size] = entry.set; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 203 | tag[size] = entry.tag; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 204 | rxBytes[size] = entry.rxBytes; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 205 | rxPackets[size] = entry.rxPackets; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 206 | txBytes[size] = entry.txBytes; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 207 | txPackets[size] = entry.txPackets; |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 208 | operations[size] = entry.operations; |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 209 | size++; |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 210 | |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 211 | return this; |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 214 | /** |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 215 | * Return specific stats entry. |
| 216 | */ |
| 217 | public Entry getValues(int i, Entry recycle) { |
| 218 | final Entry entry = recycle != null ? recycle : new Entry(); |
| 219 | entry.iface = iface[i]; |
| 220 | entry.uid = uid[i]; |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 221 | entry.set = set[i]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 222 | entry.tag = tag[i]; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 223 | entry.rxBytes = rxBytes[i]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 224 | entry.rxPackets = rxPackets[i]; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 225 | entry.txBytes = txBytes[i]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 226 | entry.txPackets = txPackets[i]; |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 227 | entry.operations = operations[i]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 228 | return entry; |
| 229 | } |
| 230 | |
| 231 | public long getElapsedRealtime() { |
| 232 | return elapsedRealtime; |
| 233 | } |
| 234 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 235 | /** |
| 236 | * Return age of this {@link NetworkStats} object with respect to |
| 237 | * {@link SystemClock#elapsedRealtime()}. |
| 238 | */ |
| 239 | public long getElapsedRealtimeAge() { |
| 240 | return SystemClock.elapsedRealtime() - elapsedRealtime; |
| 241 | } |
| 242 | |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 243 | public int size() { |
| 244 | return size; |
| 245 | } |
| 246 | |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 247 | // @VisibleForTesting |
| 248 | public int internalSize() { |
| 249 | return iface.length; |
| 250 | } |
| 251 | |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 252 | @Deprecated |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 253 | public NetworkStats combineValues(String iface, int uid, int tag, long rxBytes, long rxPackets, |
Jeff Sharkey | 63d27a9 | 2011-08-03 17:04:22 -0700 | [diff] [blame] | 254 | long txBytes, long txPackets, long operations) { |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 255 | return combineValues( |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 256 | iface, uid, SET_DEFAULT, tag, rxBytes, rxPackets, txBytes, txPackets, operations); |
| 257 | } |
| 258 | |
| 259 | public NetworkStats combineValues(String iface, int uid, int set, int tag, long rxBytes, |
| 260 | long rxPackets, long txBytes, long txPackets, long operations) { |
| 261 | return combineValues(new Entry( |
| 262 | iface, uid, set, tag, rxBytes, rxPackets, txBytes, txPackets, operations)); |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 265 | /** |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 266 | * Combine given values with an existing row, or create a new row if |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 267 | * {@link #findIndex(String, int, int, int)} is unable to find match. Can |
| 268 | * also be used to subtract values from existing rows. |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 269 | */ |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 270 | public NetworkStats combineValues(Entry entry) { |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 271 | final int i = findIndex(entry.iface, entry.uid, entry.set, entry.tag); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 272 | if (i == -1) { |
| 273 | // only create new entry when positive contribution |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 274 | addValues(entry); |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 275 | } else { |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 276 | rxBytes[i] += entry.rxBytes; |
| 277 | rxPackets[i] += entry.rxPackets; |
| 278 | txBytes[i] += entry.txBytes; |
| 279 | txPackets[i] += entry.txPackets; |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 280 | operations[i] += entry.operations; |
Jeff Sharkey | 1b5a2a9 | 2011-06-18 18:34:16 -0700 | [diff] [blame] | 281 | } |
| 282 | return this; |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 283 | } |
| 284 | |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 285 | /** |
Jeff Sharkey | 905b589 | 2011-09-30 15:19:49 -0700 | [diff] [blame] | 286 | * Combine all values from another {@link NetworkStats} into this object. |
| 287 | */ |
| 288 | public void combineAllValues(NetworkStats another) { |
| 289 | NetworkStats.Entry entry = null; |
| 290 | for (int i = 0; i < another.size; i++) { |
| 291 | entry = another.getValues(i, entry); |
| 292 | combineValues(entry); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | /** |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 297 | * Find first stats index that matches the requested parameters. |
| 298 | */ |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 299 | public int findIndex(String iface, int uid, int set, int tag) { |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 300 | for (int i = 0; i < size; i++) { |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 301 | if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i] |
| 302 | && Objects.equal(iface, this.iface[i])) { |
| 303 | return i; |
| 304 | } |
| 305 | } |
| 306 | return -1; |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Find first stats index that matches the requested parameters, starting |
| 311 | * search around the hinted index as an optimization. |
| 312 | */ |
| 313 | // @VisibleForTesting |
| 314 | public int findIndexHinted(String iface, int uid, int set, int tag, int hintIndex) { |
| 315 | for (int offset = 0; offset < size; offset++) { |
| 316 | final int halfOffset = offset / 2; |
| 317 | |
| 318 | // search outwards from hint index, alternating forward and backward |
| 319 | final int i; |
| 320 | if (offset % 2 == 0) { |
| 321 | i = (hintIndex + halfOffset) % size; |
| 322 | } else { |
| 323 | i = (size + hintIndex - halfOffset - 1) % size; |
| 324 | } |
| 325 | |
| 326 | if (uid == this.uid[i] && set == this.set[i] && tag == this.tag[i] |
| 327 | && Objects.equal(iface, this.iface[i])) { |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 328 | return i; |
| 329 | } |
| 330 | } |
| 331 | return -1; |
| 332 | } |
| 333 | |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 334 | /** |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 335 | * Splice in {@link #operations} from the given {@link NetworkStats} based |
| 336 | * on matching {@link #uid} and {@link #tag} rows. Ignores {@link #iface}, |
| 337 | * since operation counts are at data layer. |
| 338 | */ |
| 339 | public void spliceOperationsFrom(NetworkStats stats) { |
| 340 | for (int i = 0; i < size; i++) { |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 341 | final int j = stats.findIndex(IFACE_ALL, uid[i], set[i], tag[i]); |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 342 | if (j == -1) { |
| 343 | operations[i] = 0; |
| 344 | } else { |
| 345 | operations[i] = stats.operations[j]; |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | /** |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 351 | * Return list of unique interfaces known by this data structure. |
| 352 | */ |
Jeff Sharkey | 61ee0bb | 2011-05-29 22:50:42 -0700 | [diff] [blame] | 353 | public String[] getUniqueIfaces() { |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 354 | final HashSet<String> ifaces = new HashSet<String>(); |
| 355 | for (String iface : this.iface) { |
| 356 | if (iface != IFACE_ALL) { |
| 357 | ifaces.add(iface); |
| 358 | } |
| 359 | } |
| 360 | return ifaces.toArray(new String[ifaces.size()]); |
| 361 | } |
| 362 | |
| 363 | /** |
Jeff Sharkey | 61ee0bb | 2011-05-29 22:50:42 -0700 | [diff] [blame] | 364 | * Return list of unique UIDs known by this data structure. |
| 365 | */ |
| 366 | public int[] getUniqueUids() { |
| 367 | final SparseBooleanArray uids = new SparseBooleanArray(); |
| 368 | for (int uid : this.uid) { |
| 369 | uids.put(uid, true); |
| 370 | } |
| 371 | |
| 372 | final int size = uids.size(); |
| 373 | final int[] result = new int[size]; |
| 374 | for (int i = 0; i < size; i++) { |
| 375 | result[i] = uids.keyAt(i); |
| 376 | } |
| 377 | return result; |
| 378 | } |
| 379 | |
| 380 | /** |
Jeff Sharkey | 8e9992a | 2011-08-23 18:37:23 -0700 | [diff] [blame] | 381 | * Return total bytes represented by this snapshot object, usually used when |
| 382 | * checking if a {@link #subtract(NetworkStats)} delta passes a threshold. |
| 383 | */ |
| 384 | public long getTotalBytes() { |
Jeff Sharkey | 07b0dd9 | 2011-09-01 13:06:19 -0700 | [diff] [blame] | 385 | final Entry entry = getTotal(null); |
| 386 | return entry.rxBytes + entry.txBytes; |
| 387 | } |
| 388 | |
| 389 | /** |
| 390 | * Return total of all fields represented by this snapshot object. |
| 391 | */ |
| 392 | public Entry getTotal(Entry recycle) { |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 393 | return getTotal(recycle, null, UID_ALL); |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Return total of all fields represented by this snapshot object matching |
| 398 | * the requested {@link #uid}. |
| 399 | */ |
| 400 | public Entry getTotal(Entry recycle, int limitUid) { |
| 401 | return getTotal(recycle, null, limitUid); |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * Return total of all fields represented by this snapshot object matching |
| 406 | * the requested {@link #iface}. |
| 407 | */ |
| 408 | public Entry getTotal(Entry recycle, HashSet<String> limitIface) { |
| 409 | return getTotal(recycle, limitIface, UID_ALL); |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Return total of all fields represented by this snapshot object matching |
| 414 | * the requested {@link #iface} and {@link #uid}. |
| 415 | * |
| 416 | * @param limitIface Set of {@link #iface} to include in total; or {@code |
| 417 | * null} to include all ifaces. |
| 418 | */ |
| 419 | private Entry getTotal(Entry recycle, HashSet<String> limitIface, int limitUid) { |
Jeff Sharkey | 07b0dd9 | 2011-09-01 13:06:19 -0700 | [diff] [blame] | 420 | final Entry entry = recycle != null ? recycle : new Entry(); |
| 421 | |
| 422 | entry.iface = IFACE_ALL; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 423 | entry.uid = limitUid; |
Jeff Sharkey | 07b0dd9 | 2011-09-01 13:06:19 -0700 | [diff] [blame] | 424 | entry.set = SET_ALL; |
| 425 | entry.tag = TAG_NONE; |
| 426 | entry.rxBytes = 0; |
| 427 | entry.rxPackets = 0; |
| 428 | entry.txBytes = 0; |
| 429 | entry.txPackets = 0; |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 430 | entry.operations = 0; |
Jeff Sharkey | 07b0dd9 | 2011-09-01 13:06:19 -0700 | [diff] [blame] | 431 | |
Jeff Sharkey | 8e9992a | 2011-08-23 18:37:23 -0700 | [diff] [blame] | 432 | for (int i = 0; i < size; i++) { |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 433 | final boolean matchesUid = (limitUid == UID_ALL) || (limitUid == uid[i]); |
| 434 | final boolean matchesIface = (limitIface == null) || (limitIface.contains(iface[i])); |
Jeff Sharkey | 8e9992a | 2011-08-23 18:37:23 -0700 | [diff] [blame] | 435 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 436 | if (matchesUid && matchesIface) { |
| 437 | // skip specific tags, since already counted in TAG_NONE |
| 438 | if (tag[i] != TAG_NONE) continue; |
| 439 | |
| 440 | entry.rxBytes += rxBytes[i]; |
| 441 | entry.rxPackets += rxPackets[i]; |
| 442 | entry.txBytes += txBytes[i]; |
| 443 | entry.txPackets += txPackets[i]; |
| 444 | entry.operations += operations[i]; |
| 445 | } |
Jeff Sharkey | 8e9992a | 2011-08-23 18:37:23 -0700 | [diff] [blame] | 446 | } |
Jeff Sharkey | 07b0dd9 | 2011-09-01 13:06:19 -0700 | [diff] [blame] | 447 | return entry; |
Jeff Sharkey | 8e9992a | 2011-08-23 18:37:23 -0700 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | /** |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 451 | * Subtract the given {@link NetworkStats}, effectively leaving the delta |
| 452 | * between two snapshots in time. Assumes that statistics rows collect over |
| 453 | * time, and that none of them have disappeared. |
Jeff Sharkey | 3f39135 | 2011-06-05 17:42:53 -0700 | [diff] [blame] | 454 | */ |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 455 | public NetworkStats subtract(NetworkStats value) throws NonMonotonicException { |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 456 | final long deltaRealtime = this.elapsedRealtime - value.elapsedRealtime; |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 457 | if (deltaRealtime < 0) { |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 458 | throw new IllegalArgumentException("found non-monotonic realtime"); |
| 459 | } |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 460 | |
Jeff Sharkey | 7527990 | 2011-05-24 18:39:45 -0700 | [diff] [blame] | 461 | // result will have our rows, and elapsed time between snapshots |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 462 | final Entry entry = new Entry(); |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 463 | final NetworkStats result = new NetworkStats(deltaRealtime, size); |
| 464 | for (int i = 0; i < size; i++) { |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 465 | entry.iface = iface[i]; |
| 466 | entry.uid = uid[i]; |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 467 | entry.set = set[i]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 468 | entry.tag = tag[i]; |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 469 | |
| 470 | // find remote row that matches, and subtract |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 471 | final int j = value.findIndexHinted(entry.iface, entry.uid, entry.set, entry.tag, i); |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 472 | if (j == -1) { |
| 473 | // newly appearing row, return entire value |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 474 | entry.rxBytes = rxBytes[i]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 475 | entry.rxPackets = rxPackets[i]; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 476 | entry.txBytes = txBytes[i]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 477 | entry.txPackets = txPackets[i]; |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 478 | entry.operations = operations[i]; |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 479 | } else { |
| 480 | // existing row, subtract remote value |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 481 | entry.rxBytes = rxBytes[i] - value.rxBytes[j]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 482 | entry.rxPackets = rxPackets[i] - value.rxPackets[j]; |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 483 | entry.txBytes = txBytes[i] - value.txBytes[j]; |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 484 | entry.txPackets = txPackets[i] - value.txPackets[j]; |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 485 | entry.operations = operations[i] - value.operations[j]; |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 486 | |
| 487 | if (entry.rxBytes < 0 || entry.rxPackets < 0 || entry.txBytes < 0 |
| 488 | || entry.txPackets < 0 || entry.operations < 0) { |
| 489 | throw new NonMonotonicException(this, i, value, j); |
Jeff Sharkey | 3f39135 | 2011-06-05 17:42:53 -0700 | [diff] [blame] | 490 | } |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 491 | } |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 492 | |
| 493 | result.addValues(entry); |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Jeff Sharkey | 4a97122 | 2011-06-11 22:16:55 -0700 | [diff] [blame] | 496 | return result; |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Jeff Sharkey | 905b589 | 2011-09-30 15:19:49 -0700 | [diff] [blame] | 499 | /** |
| 500 | * Return total statistics grouped by {@link #iface}; doesn't mutate the |
| 501 | * original structure. |
| 502 | */ |
| 503 | public NetworkStats groupedByIface() { |
| 504 | final NetworkStats stats = new NetworkStats(elapsedRealtime, 10); |
| 505 | |
| 506 | final Entry entry = new Entry(); |
| 507 | entry.uid = UID_ALL; |
| 508 | entry.set = SET_ALL; |
| 509 | entry.tag = TAG_NONE; |
| 510 | entry.operations = 0L; |
| 511 | |
| 512 | for (int i = 0; i < size; i++) { |
| 513 | // skip specific tags, since already counted in TAG_NONE |
| 514 | if (tag[i] != TAG_NONE) continue; |
| 515 | |
| 516 | entry.iface = iface[i]; |
| 517 | entry.rxBytes = rxBytes[i]; |
| 518 | entry.rxPackets = rxPackets[i]; |
| 519 | entry.txBytes = txBytes[i]; |
| 520 | entry.txPackets = txPackets[i]; |
| 521 | stats.combineValues(entry); |
| 522 | } |
| 523 | |
| 524 | return stats; |
| 525 | } |
| 526 | |
Jeff Sharkey | 1059c3c | 2011-10-04 16:54:49 -0700 | [diff] [blame] | 527 | /** |
| 528 | * Return total statistics grouped by {@link #uid}; doesn't mutate the |
| 529 | * original structure. |
| 530 | */ |
| 531 | public NetworkStats groupedByUid() { |
| 532 | final NetworkStats stats = new NetworkStats(elapsedRealtime, 10); |
| 533 | |
| 534 | final Entry entry = new Entry(); |
| 535 | entry.iface = IFACE_ALL; |
| 536 | entry.set = SET_ALL; |
| 537 | entry.tag = TAG_NONE; |
| 538 | |
| 539 | for (int i = 0; i < size; i++) { |
| 540 | // skip specific tags, since already counted in TAG_NONE |
| 541 | if (tag[i] != TAG_NONE) continue; |
| 542 | |
| 543 | entry.uid = uid[i]; |
| 544 | entry.rxBytes = rxBytes[i]; |
| 545 | entry.rxPackets = rxPackets[i]; |
| 546 | entry.txBytes = txBytes[i]; |
| 547 | entry.txPackets = txPackets[i]; |
| 548 | entry.operations = operations[i]; |
| 549 | stats.combineValues(entry); |
| 550 | } |
| 551 | |
| 552 | return stats; |
| 553 | } |
| 554 | |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 555 | /** |
| 556 | * Return all rows except those attributed to the requested UID; doesn't |
| 557 | * mutate the original structure. |
| 558 | */ |
| 559 | public NetworkStats withoutUid(int uid) { |
| 560 | final NetworkStats stats = new NetworkStats(elapsedRealtime, 10); |
| 561 | |
| 562 | Entry entry = new Entry(); |
| 563 | for (int i = 0; i < size; i++) { |
| 564 | entry = getValues(i, entry); |
| 565 | if (entry.uid != uid) { |
| 566 | stats.addValues(entry); |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | return stats; |
| 571 | } |
| 572 | |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 573 | public void dump(String prefix, PrintWriter pw) { |
| 574 | pw.print(prefix); |
| 575 | pw.print("NetworkStats: elapsedRealtime="); pw.println(elapsedRealtime); |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 576 | for (int i = 0; i < size; i++) { |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 577 | pw.print(prefix); |
| 578 | pw.print(" iface="); pw.print(iface[i]); |
| 579 | pw.print(" uid="); pw.print(uid[i]); |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 580 | pw.print(" set="); pw.print(setToString(set[i])); |
| 581 | pw.print(" tag="); pw.print(tagToString(tag[i])); |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 582 | pw.print(" rxBytes="); pw.print(rxBytes[i]); |
Jeff Sharkey | fd8be3e | 2011-07-11 14:36:15 -0700 | [diff] [blame] | 583 | pw.print(" rxPackets="); pw.print(rxPackets[i]); |
Jeff Sharkey | d37948f | 2011-07-12 13:57:00 -0700 | [diff] [blame] | 584 | pw.print(" txBytes="); pw.print(txBytes[i]); |
Jeff Sharkey | a63ba59 | 2011-07-19 23:47:12 -0700 | [diff] [blame] | 585 | pw.print(" txPackets="); pw.print(txPackets[i]); |
| 586 | pw.print(" operations="); pw.println(operations[i]); |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 587 | } |
| 588 | } |
| 589 | |
Jeff Sharkey | b5d55e3 | 2011-08-10 17:53:27 -0700 | [diff] [blame] | 590 | /** |
| 591 | * Return text description of {@link #set} value. |
| 592 | */ |
| 593 | public static String setToString(int set) { |
| 594 | switch (set) { |
| 595 | case SET_ALL: |
| 596 | return "ALL"; |
| 597 | case SET_DEFAULT: |
| 598 | return "DEFAULT"; |
| 599 | case SET_FOREGROUND: |
| 600 | return "FOREGROUND"; |
| 601 | default: |
| 602 | return "UNKNOWN"; |
| 603 | } |
| 604 | } |
| 605 | |
| 606 | /** |
| 607 | * Return text description of {@link #tag} value. |
| 608 | */ |
| 609 | public static String tagToString(int tag) { |
| 610 | return "0x" + Integer.toHexString(tag); |
| 611 | } |
| 612 | |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 613 | @Override |
| 614 | public String toString() { |
| 615 | final CharArrayWriter writer = new CharArrayWriter(); |
| 616 | dump("", new PrintWriter(writer)); |
| 617 | return writer.toString(); |
| 618 | } |
| 619 | |
| 620 | /** {@inheritDoc} */ |
Jeff Sharkey | eedcb95 | 2011-05-17 14:55:15 -0700 | [diff] [blame] | 621 | public int describeContents() { |
| 622 | return 0; |
| 623 | } |
| 624 | |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 625 | public static final Creator<NetworkStats> CREATOR = new Creator<NetworkStats>() { |
| 626 | public NetworkStats createFromParcel(Parcel in) { |
| 627 | return new NetworkStats(in); |
| 628 | } |
| 629 | |
| 630 | public NetworkStats[] newArray(int size) { |
| 631 | return new NetworkStats[size]; |
| 632 | } |
| 633 | }; |
Jeff Sharkey | 163e644 | 2011-10-31 16:37:52 -0700 | [diff] [blame^] | 634 | |
| 635 | public static class NonMonotonicException extends Exception { |
| 636 | public final NetworkStats left; |
| 637 | public final NetworkStats right; |
| 638 | public final int leftIndex; |
| 639 | public final int rightIndex; |
| 640 | |
| 641 | public NonMonotonicException( |
| 642 | NetworkStats left, int leftIndex, NetworkStats right, int rightIndex) { |
| 643 | this.left = checkNotNull(left, "missing left"); |
| 644 | this.right = checkNotNull(right, "missing right"); |
| 645 | this.leftIndex = leftIndex; |
| 646 | this.rightIndex = rightIndex; |
| 647 | } |
| 648 | } |
Jeff Sharkey | 9a13f36 | 2011-04-26 16:25:36 -0700 | [diff] [blame] | 649 | } |