Merge "IpConn metrics: correctly read RA lifetimes" into nyc-mr1-dev

This commit is contained in:
Hugo Benichi
2016-07-05 12:25:54 +00:00
committed by Android (Google) Code Review
3 changed files with 150 additions and 37 deletions

View File

@@ -27,6 +27,9 @@ import android.os.Parcelable;
@SystemApi
public final class RaEvent implements Parcelable {
/** {@hide} */
public static final long NO_LIFETIME = -1L;
// Lifetime in seconds of options found in a single RA packet.
// When an option is not set, the value of the associated field is -1;
public final long routerLifetime;
@@ -92,4 +95,60 @@ public final class RaEvent implements Parcelable {
return new RaEvent[size];
}
};
/** {@hide} */
public static class Builder {
long routerLifetime = NO_LIFETIME;
long prefixValidLifetime = NO_LIFETIME;
long prefixPreferredLifetime = NO_LIFETIME;
long routeInfoLifetime = NO_LIFETIME;
long rdnssLifetime = NO_LIFETIME;
long dnsslLifetime = NO_LIFETIME;
public Builder() {
}
public RaEvent build() {
return new RaEvent(routerLifetime, prefixValidLifetime, prefixPreferredLifetime,
routeInfoLifetime, rdnssLifetime, dnsslLifetime);
}
public Builder updateRouterLifetime(long lifetime) {
routerLifetime = updateLifetime(routerLifetime, lifetime);
return this;
}
public Builder updatePrefixValidLifetime(long lifetime) {
prefixValidLifetime = updateLifetime(prefixValidLifetime, lifetime);
return this;
}
public Builder updatePrefixPreferredLifetime(long lifetime) {
prefixPreferredLifetime = updateLifetime(prefixPreferredLifetime, lifetime);
return this;
}
public Builder updateRouteInfoLifetime(long lifetime) {
routeInfoLifetime = updateLifetime(routeInfoLifetime, lifetime);
return this;
}
public Builder updateRdnssLifetime(long lifetime) {
rdnssLifetime = updateLifetime(rdnssLifetime, lifetime);
return this;
}
public Builder updateDnsslLifetime(long lifetime) {
dnsslLifetime = updateLifetime(dnsslLifetime, lifetime);
return this;
}
private long updateLifetime(long currentLifetime, long newLifetime) {
if (currentLifetime == RaEvent.NO_LIFETIME) {
return newLifetime;
}
return Math.min(currentLifetime, newLifetime);
}
}
}