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.os.Parcel; 23 import android.os.Parcelable; 24 25 /** 26 * An event logged when the APF packet socket receives an RA packet. 27 * {@hide} 28 * @deprecated The event may not be sent in Android S and above. The events 29 * are logged by a single caller in the system using signature permissions 30 * and that caller is migrating to statsd. 31 */ 32 @Deprecated 33 @SystemApi 34 public final class RaEvent implements IpConnectivityLog.Event { 35 36 private static final long NO_LIFETIME = -1L; 37 38 // Lifetime in seconds of options found in a single RA packet. 39 // When an option is not set, the value of the associated field is -1; 40 /** @hide */ 41 public final long routerLifetime; 42 /** @hide */ 43 public final long prefixValidLifetime; 44 /** @hide */ 45 public final long prefixPreferredLifetime; 46 /** @hide */ 47 public final long routeInfoLifetime; 48 /** @hide */ 49 public final long rdnssLifetime; 50 /** @hide */ 51 public final long dnsslLifetime; 52 53 /** @hide */ RaEvent(long routerLifetime, long prefixValidLifetime, long prefixPreferredLifetime, long routeInfoLifetime, long rdnssLifetime, long dnsslLifetime)54 public RaEvent(long routerLifetime, long prefixValidLifetime, long prefixPreferredLifetime, 55 long routeInfoLifetime, long rdnssLifetime, long dnsslLifetime) { 56 this.routerLifetime = routerLifetime; 57 this.prefixValidLifetime = prefixValidLifetime; 58 this.prefixPreferredLifetime = prefixPreferredLifetime; 59 this.routeInfoLifetime = routeInfoLifetime; 60 this.rdnssLifetime = rdnssLifetime; 61 this.dnsslLifetime = dnsslLifetime; 62 } 63 64 /** @hide */ RaEvent(Parcel in)65 private RaEvent(Parcel in) { 66 routerLifetime = in.readLong(); 67 prefixValidLifetime = in.readLong(); 68 prefixPreferredLifetime = in.readLong(); 69 routeInfoLifetime = in.readLong(); 70 rdnssLifetime = in.readLong(); 71 dnsslLifetime = in.readLong(); 72 } 73 74 /** @hide */ 75 @Override writeToParcel(Parcel out, int flags)76 public void writeToParcel(Parcel out, int flags) { 77 out.writeLong(routerLifetime); 78 out.writeLong(prefixValidLifetime); 79 out.writeLong(prefixPreferredLifetime); 80 out.writeLong(routeInfoLifetime); 81 out.writeLong(rdnssLifetime); 82 out.writeLong(dnsslLifetime); 83 } 84 85 /** @hide */ 86 @Override describeContents()87 public int describeContents() { 88 return 0; 89 } 90 91 @NonNull 92 @Override toString()93 public String toString() { 94 return new StringBuilder("RaEvent(lifetimes: ") 95 .append(String.format("router=%ds, ", routerLifetime)) 96 .append(String.format("prefix_valid=%ds, ", prefixValidLifetime)) 97 .append(String.format("prefix_preferred=%ds, ", prefixPreferredLifetime)) 98 .append(String.format("route_info=%ds, ", routeInfoLifetime)) 99 .append(String.format("rdnss=%ds, ", rdnssLifetime)) 100 .append(String.format("dnssl=%ds)", dnsslLifetime)) 101 .toString(); 102 } 103 104 @Override equals(@ullable Object obj)105 public boolean equals(@Nullable Object obj) { 106 if (obj == null || !(obj.getClass().equals(RaEvent.class))) return false; 107 final RaEvent other = (RaEvent) obj; 108 return routerLifetime == other.routerLifetime 109 && prefixValidLifetime == other.prefixValidLifetime 110 && prefixPreferredLifetime == other.prefixPreferredLifetime 111 && routeInfoLifetime == other.routeInfoLifetime 112 && rdnssLifetime == other.rdnssLifetime 113 && dnsslLifetime == other.dnsslLifetime; 114 } 115 116 /** @hide */ 117 public static final @android.annotation.NonNull Parcelable.Creator<RaEvent> CREATOR = new Parcelable.Creator<RaEvent>() { 118 public RaEvent createFromParcel(Parcel in) { 119 return new RaEvent(in); 120 } 121 122 public RaEvent[] newArray(int size) { 123 return new RaEvent[size]; 124 } 125 }; 126 127 public static final class Builder { 128 129 long routerLifetime = NO_LIFETIME; 130 long prefixValidLifetime = NO_LIFETIME; 131 long prefixPreferredLifetime = NO_LIFETIME; 132 long routeInfoLifetime = NO_LIFETIME; 133 long rdnssLifetime = NO_LIFETIME; 134 long dnsslLifetime = NO_LIFETIME; 135 Builder()136 public Builder() { 137 } 138 build()139 public @NonNull RaEvent build() { 140 return new RaEvent(routerLifetime, prefixValidLifetime, prefixPreferredLifetime, 141 routeInfoLifetime, rdnssLifetime, dnsslLifetime); 142 } 143 updateRouterLifetime(long lifetime)144 public @NonNull Builder updateRouterLifetime(long lifetime) { 145 routerLifetime = updateLifetime(routerLifetime, lifetime); 146 return this; 147 } 148 updatePrefixValidLifetime(long lifetime)149 public @NonNull Builder updatePrefixValidLifetime(long lifetime) { 150 prefixValidLifetime = updateLifetime(prefixValidLifetime, lifetime); 151 return this; 152 } 153 updatePrefixPreferredLifetime(long lifetime)154 public @NonNull Builder updatePrefixPreferredLifetime(long lifetime) { 155 prefixPreferredLifetime = updateLifetime(prefixPreferredLifetime, lifetime); 156 return this; 157 } 158 updateRouteInfoLifetime(long lifetime)159 public @NonNull Builder updateRouteInfoLifetime(long lifetime) { 160 routeInfoLifetime = updateLifetime(routeInfoLifetime, lifetime); 161 return this; 162 } 163 updateRdnssLifetime(long lifetime)164 public @NonNull Builder updateRdnssLifetime(long lifetime) { 165 rdnssLifetime = updateLifetime(rdnssLifetime, lifetime); 166 return this; 167 } 168 updateDnsslLifetime(long lifetime)169 public @NonNull Builder updateDnsslLifetime(long lifetime) { 170 dnsslLifetime = updateLifetime(dnsslLifetime, lifetime); 171 return this; 172 } 173 updateLifetime(long currentLifetime, long newLifetime)174 private long updateLifetime(long currentLifetime, long newLifetime) { 175 if (currentLifetime == RaEvent.NO_LIFETIME) { 176 return newLifetime; 177 } 178 return Math.min(currentLifetime, newLifetime); 179 } 180 } 181 } 182