blob: e0a026ed678d1937bd3c868d41b83050a8482791 [file] [log] [blame]
Erik Kline5b25a0f2016-04-12 15:31:13 +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
Hugo Benichicf6b12f2016-07-04 11:28:05 +090019import android.annotation.IntDef;
Hugo Benichi4b6dfc22016-04-15 12:15:47 +090020import android.annotation.SystemApi;
Erik Kline5b25a0f2016-04-12 15:31:13 +090021import android.os.Parcel;
22import android.os.Parcelable;
Hugo Benichi5df9d722016-04-25 17:16:35 +090023import android.util.SparseArray;
24
25import com.android.internal.util.MessageUtils;
Erik Kline5b25a0f2016-04-12 15:31:13 +090026
Hugo Benichicf6b12f2016-07-04 11:28:05 +090027import java.lang.annotation.Retention;
28import java.lang.annotation.RetentionPolicy;
29
Erik Kline5b25a0f2016-04-12 15:31:13 +090030/**
Hugo Benichicf6b12f2016-07-04 11:28:05 +090031 * An event recorded by IpManager when IP provisioning completes for a network or
32 * when a network disconnects.
Erik Kline5b25a0f2016-04-12 15:31:13 +090033 * {@hide}
34 */
Hugo Benichi4b6dfc22016-04-15 12:15:47 +090035@SystemApi
Hugo Benichicfddd682016-05-31 16:28:06 +090036public final class IpManagerEvent implements Parcelable {
Hugo Benichi5df9d722016-04-25 17:16:35 +090037
38 public static final int PROVISIONING_OK = 1;
39 public static final int PROVISIONING_FAIL = 2;
40 public static final int COMPLETE_LIFECYCLE = 3;
Erik Klinee4526602016-10-14 18:33:22 +090041 /** @hide */ public static final int ERROR_STARTING_IPV4 = 4;
42 /** @hide */ public static final int ERROR_STARTING_IPV6 = 5;
43 /** @hide */ public static final int ERROR_STARTING_IPREACHABILITYMONITOR = 6;
Hugo Benichi5df9d722016-04-25 17:16:35 +090044
Hugo Benichicf6b12f2016-07-04 11:28:05 +090045 /** {@hide} */
Erik Klinee4526602016-10-14 18:33:22 +090046 @IntDef(value = {
47 PROVISIONING_OK, PROVISIONING_FAIL, COMPLETE_LIFECYCLE,
48 ERROR_STARTING_IPV4, ERROR_STARTING_IPV6, ERROR_STARTING_IPREACHABILITYMONITOR,
49 })
Hugo Benichicf6b12f2016-07-04 11:28:05 +090050 @Retention(RetentionPolicy.SOURCE)
51 public @interface EventType {}
52
Hugo Benichi627b4242016-04-15 16:56:28 +090053 public final String ifName;
Hugo Benichicf6b12f2016-07-04 11:28:05 +090054 public final @EventType int eventType;
Hugo Benichi627b4242016-04-15 16:56:28 +090055 public final long durationMs;
Erik Kline5b25a0f2016-04-12 15:31:13 +090056
Hugo Benichicfddd682016-05-31 16:28:06 +090057 /** {@hide} */
Hugo Benichicf6b12f2016-07-04 11:28:05 +090058 public IpManagerEvent(String ifName, @EventType int eventType, long duration) {
Hugo Benichi627b4242016-04-15 16:56:28 +090059 this.ifName = ifName;
Hugo Benichi5df9d722016-04-25 17:16:35 +090060 this.eventType = eventType;
Hugo Benichi627b4242016-04-15 16:56:28 +090061 this.durationMs = duration;
Erik Kline5b25a0f2016-04-12 15:31:13 +090062 }
63
Hugo Benichi627b4242016-04-15 16:56:28 +090064 private IpManagerEvent(Parcel in) {
65 this.ifName = in.readString();
Hugo Benichi5df9d722016-04-25 17:16:35 +090066 this.eventType = in.readInt();
Hugo Benichi627b4242016-04-15 16:56:28 +090067 this.durationMs = in.readLong();
Erik Kline5b25a0f2016-04-12 15:31:13 +090068 }
69
Hugo Benichicf6b12f2016-07-04 11:28:05 +090070 @Override
Erik Kline5b25a0f2016-04-12 15:31:13 +090071 public void writeToParcel(Parcel out, int flags) {
Hugo Benichi627b4242016-04-15 16:56:28 +090072 out.writeString(ifName);
Hugo Benichi5df9d722016-04-25 17:16:35 +090073 out.writeInt(eventType);
Hugo Benichi627b4242016-04-15 16:56:28 +090074 out.writeLong(durationMs);
75 }
76
Hugo Benichicf6b12f2016-07-04 11:28:05 +090077 @Override
Hugo Benichi627b4242016-04-15 16:56:28 +090078 public int describeContents() {
79 return 0;
Erik Kline5b25a0f2016-04-12 15:31:13 +090080 }
81
82 public static final Parcelable.Creator<IpManagerEvent> CREATOR
83 = new Parcelable.Creator<IpManagerEvent>() {
84 public IpManagerEvent createFromParcel(Parcel in) {
85 return new IpManagerEvent(in);
86 }
87
88 public IpManagerEvent[] newArray(int size) {
89 return new IpManagerEvent[size];
90 }
91 };
92
93 public static void logEvent(int eventType, String ifName, long durationMs) {
Hugo Benichi5df9d722016-04-25 17:16:35 +090094 }
95
96 @Override
97 public String toString() {
98 return String.format("IpManagerEvent(%s, %s, %dms)",
99 ifName, Decoder.constants.get(eventType), durationMs);
100 }
101
102 final static class Decoder {
103 static final SparseArray<String> constants = MessageUtils.findMessageNames(
Erik Klinee4526602016-10-14 18:33:22 +0900104 new Class[]{IpManagerEvent.class},
105 new String[]{"PROVISIONING_", "COMPLETE_", "ERROR_"});
Erik Kline5b25a0f2016-04-12 15:31:13 +0900106 }
Hugo Benichicfddd682016-05-31 16:28:06 +0900107}