blob: 73dcb947f9f687c05f5096d3e5598955899ecff6 [file] [log] [blame]
Hugo Benichi25bf8f52016-04-19 09:52:39 +09001/*
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
17package android.net.metrics;
18
19import android.annotation.SystemApi;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
24 * {@hide}
25 */
26@SystemApi
27public final class IpReachabilityEvent extends IpConnectivityEvent implements Parcelable {
28
29 public static final int PROBE = 1 << 8;
30 public static final int NUD_FAILED = 2 << 8;
31 public static final int PROVISIONING_LOST = 3 << 8;
32
33 public final String ifName;
34 // eventType byte format (MSB to LSB):
35 // byte 0: unused
36 // byte 1: unused
37 // byte 2: type of event: PROBE, NUD_FAILED, PROVISIONING_LOST
38 // byte 3: kernel errno from RTNetlink or IpReachabilityMonitor
39 public final int eventType;
40
41 private IpReachabilityEvent(String ifName, int eventType) {
42 this.ifName = ifName;
43 this.eventType = eventType;
44 }
45
46 private IpReachabilityEvent(Parcel in) {
47 this.ifName = in.readString();
48 this.eventType = in.readInt();
49 }
50
51 public void writeToParcel(Parcel out, int flags) {
52 out.writeString(ifName);
53 out.writeInt(eventType);
54 }
55
56 public int describeContents() {
57 return 0;
58 }
59
60 public static final Parcelable.Creator<IpReachabilityEvent> CREATOR
61 = new Parcelable.Creator<IpReachabilityEvent>() {
62 public IpReachabilityEvent createFromParcel(Parcel in) {
63 return new IpReachabilityEvent(in);
64 }
65
66 public IpReachabilityEvent[] newArray(int size) {
67 return new IpReachabilityEvent[size];
68 }
69 };
70
71 public static void logProbeEvent(String ifName, int nlErrorCode) {
72 final int tag = (nlErrorCode == 0) ? IPCE_IPRM_PROBE_STARTED : IPCE_IPRM_PROBE_FAILURE;
73 final int eventType = PROBE | (nlErrorCode & 0xFF);
74 logEvent(tag, new IpReachabilityEvent(ifName, eventType));
75 }
76
77 public static void logNudFailed(String ifName) {
78 logEvent(IPCE_IPRM_NUD_FAILED, new IpReachabilityEvent(ifName, NUD_FAILED));
79 }
80
81 public static void logProvisioningLost(String ifName) {
82 logEvent(IPCE_IPRM_PROVISIONING_LOST, new IpReachabilityEvent(ifName, PROVISIONING_LOST));
83 }
84};