1 /* 2 * Copyright (C) 2016 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.metrics; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 import android.annotation.SystemApi; 22 import android.compat.annotation.UnsupportedAppUsage; 23 import android.os.Build; 24 import android.os.Parcel; 25 import android.os.Parcelable; 26 27 /** 28 * An event logged for an interface with APF capabilities when its IpClient state machine exits. 29 * {@hide} 30 * @deprecated The event may not be sent in Android S and above. The events 31 * are logged by a single caller in the system using signature permissions 32 * and that caller is migrating to statsd. 33 */ 34 @Deprecated 35 @SystemApi 36 public final class ApfStats implements IpConnectivityLog.Event { 37 38 /** 39 * time interval in milliseconds these stastistics covers. 40 * @hide 41 */ 42 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 43 public final long durationMs; 44 /** 45 * number of received RAs. 46 * @hide 47 */ 48 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 49 public final int receivedRas; 50 /** 51 * number of received RAs matching a known RA. 52 * @hide 53 */ 54 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 55 public final int matchingRas; 56 /** 57 * number of received RAs ignored due to the MAX_RAS limit. 58 * @hide 59 */ 60 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 61 public final int droppedRas; 62 /** 63 * number of received RAs with a minimum lifetime of 0. 64 * @hide 65 */ 66 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 67 public final int zeroLifetimeRas; 68 /** 69 * number of received RAs that could not be parsed. 70 * @hide 71 */ 72 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 73 public final int parseErrors; 74 /** 75 * number of APF program updates from receiving RAs. 76 * @hide 77 */ 78 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 79 public final int programUpdates; 80 /** 81 * total number of APF program updates. 82 * @hide 83 */ 84 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 85 public final int programUpdatesAll; 86 /** 87 * number of APF program updates from allowing multicast traffic. 88 * @hide 89 */ 90 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 91 public final int programUpdatesAllowingMulticast; 92 /** 93 * maximum APF program size advertised by hardware. 94 * @hide 95 */ 96 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 97 public final int maxProgramSize; 98 ApfStats(Parcel in)99 private ApfStats(Parcel in) { 100 this.durationMs = in.readLong(); 101 this.receivedRas = in.readInt(); 102 this.matchingRas = in.readInt(); 103 this.droppedRas = in.readInt(); 104 this.zeroLifetimeRas = in.readInt(); 105 this.parseErrors = in.readInt(); 106 this.programUpdates = in.readInt(); 107 this.programUpdatesAll = in.readInt(); 108 this.programUpdatesAllowingMulticast = in.readInt(); 109 this.maxProgramSize = in.readInt(); 110 } 111 ApfStats(long durationMs, int receivedRas, int matchingRas, int droppedRas, int zeroLifetimeRas, int parseErrors, int programUpdates, int programUpdatesAll, int programUpdatesAllowingMulticast, int maxProgramSize)112 private ApfStats(long durationMs, int receivedRas, int matchingRas, int droppedRas, 113 int zeroLifetimeRas, int parseErrors, int programUpdates, int programUpdatesAll, 114 int programUpdatesAllowingMulticast, int maxProgramSize) { 115 this.durationMs = durationMs; 116 this.receivedRas = receivedRas; 117 this.matchingRas = matchingRas; 118 this.droppedRas = droppedRas; 119 this.zeroLifetimeRas = zeroLifetimeRas; 120 this.parseErrors = parseErrors; 121 this.programUpdates = programUpdates; 122 this.programUpdatesAll = programUpdatesAll; 123 this.programUpdatesAllowingMulticast = programUpdatesAllowingMulticast; 124 this.maxProgramSize = maxProgramSize; 125 } 126 127 /** 128 * Utility to create an instance of {@link ApfStats}. 129 * @hide 130 */ 131 @SystemApi 132 public static final class Builder { 133 private long mDurationMs; 134 private int mReceivedRas; 135 private int mMatchingRas; 136 private int mDroppedRas; 137 private int mZeroLifetimeRas; 138 private int mParseErrors; 139 private int mProgramUpdates; 140 private int mProgramUpdatesAll; 141 private int mProgramUpdatesAllowingMulticast; 142 private int mMaxProgramSize; 143 144 /** 145 * Set the time interval in milliseconds these statistics covers. 146 */ 147 @NonNull setDurationMs(long durationMs)148 public Builder setDurationMs(long durationMs) { 149 mDurationMs = durationMs; 150 return this; 151 } 152 153 /** 154 * Set the number of received RAs. 155 */ 156 @NonNull setReceivedRas(int receivedRas)157 public Builder setReceivedRas(int receivedRas) { 158 mReceivedRas = receivedRas; 159 return this; 160 } 161 162 /** 163 * Set the number of received RAs matching a known RA. 164 */ 165 @NonNull setMatchingRas(int matchingRas)166 public Builder setMatchingRas(int matchingRas) { 167 mMatchingRas = matchingRas; 168 return this; 169 } 170 171 /** 172 * Set the number of received RAs ignored due to the MAX_RAS limit. 173 */ 174 @NonNull setDroppedRas(int droppedRas)175 public Builder setDroppedRas(int droppedRas) { 176 mDroppedRas = droppedRas; 177 return this; 178 } 179 180 /** 181 * Set the number of received RAs with a minimum lifetime of 0. 182 */ 183 @NonNull setZeroLifetimeRas(int zeroLifetimeRas)184 public Builder setZeroLifetimeRas(int zeroLifetimeRas) { 185 mZeroLifetimeRas = zeroLifetimeRas; 186 return this; 187 } 188 189 /** 190 * Set the number of received RAs that could not be parsed. 191 */ 192 @NonNull setParseErrors(int parseErrors)193 public Builder setParseErrors(int parseErrors) { 194 mParseErrors = parseErrors; 195 return this; 196 } 197 198 /** 199 * Set the number of APF program updates from receiving RAs. 200 */ 201 @NonNull setProgramUpdates(int programUpdates)202 public Builder setProgramUpdates(int programUpdates) { 203 mProgramUpdates = programUpdates; 204 return this; 205 } 206 207 /** 208 * Set the total number of APF program updates. 209 */ 210 @NonNull setProgramUpdatesAll(int programUpdatesAll)211 public Builder setProgramUpdatesAll(int programUpdatesAll) { 212 mProgramUpdatesAll = programUpdatesAll; 213 return this; 214 } 215 216 /** 217 * Set the number of APF program updates from allowing multicast traffic. 218 */ 219 @NonNull setProgramUpdatesAllowingMulticast(int programUpdatesAllowingMulticast)220 public Builder setProgramUpdatesAllowingMulticast(int programUpdatesAllowingMulticast) { 221 mProgramUpdatesAllowingMulticast = programUpdatesAllowingMulticast; 222 return this; 223 } 224 225 /** 226 * Set the maximum APF program size advertised by hardware. 227 */ 228 @NonNull setMaxProgramSize(int maxProgramSize)229 public Builder setMaxProgramSize(int maxProgramSize) { 230 mMaxProgramSize = maxProgramSize; 231 return this; 232 } 233 234 /** 235 * Create a new {@link ApfStats}. 236 */ 237 @NonNull build()238 public ApfStats build() { 239 return new ApfStats(mDurationMs, mReceivedRas, mMatchingRas, mDroppedRas, 240 mZeroLifetimeRas, mParseErrors, mProgramUpdates, mProgramUpdatesAll, 241 mProgramUpdatesAllowingMulticast, mMaxProgramSize); 242 } 243 } 244 245 /** @hide */ 246 @Override writeToParcel(Parcel out, int flags)247 public void writeToParcel(Parcel out, int flags) { 248 out.writeLong(durationMs); 249 out.writeInt(receivedRas); 250 out.writeInt(matchingRas); 251 out.writeInt(droppedRas); 252 out.writeInt(zeroLifetimeRas); 253 out.writeInt(parseErrors); 254 out.writeInt(programUpdates); 255 out.writeInt(programUpdatesAll); 256 out.writeInt(programUpdatesAllowingMulticast); 257 out.writeInt(maxProgramSize); 258 } 259 260 /** @hide */ 261 @Override describeContents()262 public int describeContents() { 263 return 0; 264 } 265 266 @NonNull 267 @Override toString()268 public String toString() { 269 return new StringBuilder("ApfStats(") 270 .append(String.format("%dms ", durationMs)) 271 .append(String.format("%dB RA: {", maxProgramSize)) 272 .append(String.format("%d received, ", receivedRas)) 273 .append(String.format("%d matching, ", matchingRas)) 274 .append(String.format("%d dropped, ", droppedRas)) 275 .append(String.format("%d zero lifetime, ", zeroLifetimeRas)) 276 .append(String.format("%d parse errors}, ", parseErrors)) 277 .append(String.format("updates: {all: %d, RAs: %d, allow multicast: %d})", 278 programUpdatesAll, programUpdates, programUpdatesAllowingMulticast)) 279 .toString(); 280 } 281 282 @Override equals(@ullable Object obj)283 public boolean equals(@Nullable Object obj) { 284 if (obj == null || !(obj.getClass().equals(ApfStats.class))) return false; 285 final ApfStats other = (ApfStats) obj; 286 return durationMs == other.durationMs 287 && receivedRas == other.receivedRas 288 && matchingRas == other.matchingRas 289 && droppedRas == other.droppedRas 290 && zeroLifetimeRas == other.zeroLifetimeRas 291 && parseErrors == other.parseErrors 292 && programUpdates == other.programUpdates 293 && programUpdatesAll == other.programUpdatesAll 294 && programUpdatesAllowingMulticast == other.programUpdatesAllowingMulticast 295 && maxProgramSize == other.maxProgramSize; 296 } 297 298 /** @hide */ 299 public static final @android.annotation.NonNull Parcelable.Creator<ApfStats> CREATOR = new Parcelable.Creator<ApfStats>() { 300 public ApfStats createFromParcel(Parcel in) { 301 return new ApfStats(in); 302 } 303 304 public ApfStats[] newArray(int size) { 305 return new ApfStats[size]; 306 } 307 }; 308 } 309