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 import android.util.SparseArray; 25 26 import com.android.internal.util.MessageUtils; 27 28 /** 29 * An event recorded when IpReachabilityMonitor sends a neighbor probe or receives 30 * a neighbor probe result. 31 * {@hide} 32 * @deprecated The event may not be sent in Android S and above. The events 33 * are logged by a single caller in the system using signature permissions 34 * and that caller is migrating to statsd. 35 */ 36 @Deprecated 37 @SystemApi 38 public final class IpReachabilityEvent implements IpConnectivityLog.Event { 39 40 // Event types. 41 /** A probe forced by IpReachabilityMonitor. */ 42 public static final int PROBE = 1 << 8; 43 /** Neighbor unreachable after a forced probe. */ 44 public static final int NUD_FAILED = 2 << 8; 45 /** Neighbor unreachable after a forced probe, IP provisioning is also lost. */ 46 public static final int PROVISIONING_LOST = 3 << 8; 47 /** Neighbor unreachable notification from kernel. */ 48 public static final int NUD_FAILED_ORGANIC = 4 << 8; 49 /** Neighbor unreachable notification from kernel, IP provisioning is also lost. */ 50 public static final int PROVISIONING_LOST_ORGANIC = 5 << 8; 51 52 // eventType byte format (MSB to LSB): 53 // byte 0: unused 54 // byte 1: unused 55 // byte 2: type of event: PROBE, NUD_FAILED, PROVISIONING_LOST 56 // byte 3: when byte 2 == PROBE, errno code from RTNetlink or IpReachabilityMonitor. 57 /** @hide */ 58 public final int eventType; 59 IpReachabilityEvent(int eventType)60 public IpReachabilityEvent(int eventType) { 61 this.eventType = eventType; 62 } 63 IpReachabilityEvent(Parcel in)64 private IpReachabilityEvent(Parcel in) { 65 this.eventType = in.readInt(); 66 } 67 68 /** @hide */ 69 @Override writeToParcel(Parcel out, int flags)70 public void writeToParcel(Parcel out, int flags) { 71 out.writeInt(eventType); 72 } 73 74 /** @hide */ 75 @Override describeContents()76 public int describeContents() { 77 return 0; 78 } 79 80 /** @hide */ 81 public static final @android.annotation.NonNull Parcelable.Creator<IpReachabilityEvent> CREATOR 82 = new Parcelable.Creator<IpReachabilityEvent>() { 83 public IpReachabilityEvent createFromParcel(Parcel in) { 84 return new IpReachabilityEvent(in); 85 } 86 87 public IpReachabilityEvent[] newArray(int size) { 88 return new IpReachabilityEvent[size]; 89 } 90 }; 91 92 @NonNull 93 @Override toString()94 public String toString() { 95 int hi = eventType & 0xff00; 96 int lo = eventType & 0x00ff; 97 String eventName = Decoder.constants.get(hi); 98 return String.format("IpReachabilityEvent(%s:%02x)", eventName, lo); 99 } 100 101 @Override equals(@ullable Object obj)102 public boolean equals(@Nullable Object obj) { 103 if (obj == null || !(obj.getClass().equals(IpReachabilityEvent.class))) return false; 104 final IpReachabilityEvent other = (IpReachabilityEvent) obj; 105 return eventType == other.eventType; 106 } 107 108 final static class Decoder { 109 static final SparseArray<String> constants = 110 MessageUtils.findMessageNames(new Class[]{IpReachabilityEvent.class}, 111 new String[]{"PROBE", "PROVISIONING_", "NUD_"}); 112 } 113 } 114