blob: 77908e6593adca480588eb85a9d944d12636bdfc [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;
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090020import android.annotation.SystemApi;
21import android.annotation.TestApi;
Erik Kline5b25a0f2016-04-12 15:31:13 +090022import android.os.Parcel;
23import android.os.Parcelable;
Hugo Benichi5df9d722016-04-25 17:16:35 +090024import android.util.SparseArray;
25
26import com.android.internal.util.MessageUtils;
Erik Kline5b25a0f2016-04-12 15:31:13 +090027
Hugo Benichicf6b12f2016-07-04 11:28:05 +090028import java.lang.annotation.Retention;
29import java.lang.annotation.RetentionPolicy;
30
Erik Kline5b25a0f2016-04-12 15:31:13 +090031/**
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090032 * An event recorded by IpClient when IP provisioning completes for a network or
Hugo Benichicf6b12f2016-07-04 11:28:05 +090033 * when a network disconnects.
Erik Kline5b25a0f2016-04-12 15:31:13 +090034 * {@hide}
35 */
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090036@SystemApi
37@TestApi
38public final class IpManagerEvent implements IpConnectivityLog.Event {
Hugo Benichi5df9d722016-04-25 17:16:35 +090039
Hugo Benichi95cb2262017-01-11 10:11:26 +090040 public static final int PROVISIONING_OK = 1;
41 public static final int PROVISIONING_FAIL = 2;
42 public static final int COMPLETE_LIFECYCLE = 3;
43 public static final int ERROR_STARTING_IPV4 = 4;
44 public static final int ERROR_STARTING_IPV6 = 5;
45 public static final int ERROR_STARTING_IPREACHABILITYMONITOR = 6;
Hugo Benichia4283922017-07-14 07:25:51 +090046 public static final int ERROR_INVALID_PROVISIONING = 7;
Erik Klineb152cd02018-03-02 16:51:13 +090047 public static final int ERROR_INTERFACE_NOT_FOUND = 8;
Hugo Benichi5df9d722016-04-25 17:16:35 +090048
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090049 /** @hide */
Erik Klinee4526602016-10-14 18:33:22 +090050 @IntDef(value = {
51 PROVISIONING_OK, PROVISIONING_FAIL, COMPLETE_LIFECYCLE,
52 ERROR_STARTING_IPV4, ERROR_STARTING_IPV6, ERROR_STARTING_IPREACHABILITYMONITOR,
Erik Klineb152cd02018-03-02 16:51:13 +090053 ERROR_INVALID_PROVISIONING, ERROR_INTERFACE_NOT_FOUND,
Erik Klinee4526602016-10-14 18:33:22 +090054 })
Hugo Benichicf6b12f2016-07-04 11:28:05 +090055 @Retention(RetentionPolicy.SOURCE)
56 public @interface EventType {}
57
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090058 /** @hide */
Hugo Benichicf6b12f2016-07-04 11:28:05 +090059 public final @EventType int eventType;
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090060 /** @hide */
Hugo Benichi627b4242016-04-15 16:56:28 +090061 public final long durationMs;
Erik Kline5b25a0f2016-04-12 15:31:13 +090062
Hugo Benichi948a8592017-03-16 16:33:47 +090063 public IpManagerEvent(@EventType int eventType, long duration) {
Hugo Benichi5df9d722016-04-25 17:16:35 +090064 this.eventType = eventType;
Hugo Benichi627b4242016-04-15 16:56:28 +090065 this.durationMs = duration;
Erik Kline5b25a0f2016-04-12 15:31:13 +090066 }
67
Hugo Benichi627b4242016-04-15 16:56:28 +090068 private IpManagerEvent(Parcel in) {
Hugo Benichi5df9d722016-04-25 17:16:35 +090069 this.eventType = in.readInt();
Hugo Benichi627b4242016-04-15 16:56:28 +090070 this.durationMs = in.readLong();
Erik Kline5b25a0f2016-04-12 15:31:13 +090071 }
72
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090073 /** @hide */
Hugo Benichicf6b12f2016-07-04 11:28:05 +090074 @Override
Erik Kline5b25a0f2016-04-12 15:31:13 +090075 public void writeToParcel(Parcel out, int flags) {
Hugo Benichi5df9d722016-04-25 17:16:35 +090076 out.writeInt(eventType);
Hugo Benichi627b4242016-04-15 16:56:28 +090077 out.writeLong(durationMs);
78 }
79
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090080 /** @hide */
Hugo Benichicf6b12f2016-07-04 11:28:05 +090081 @Override
Hugo Benichi627b4242016-04-15 16:56:28 +090082 public int describeContents() {
83 return 0;
Erik Kline5b25a0f2016-04-12 15:31:13 +090084 }
85
Remi NGUYEN VAN7b84fb32019-01-19 21:13:24 +090086 /** @hide */
Erik Kline5b25a0f2016-04-12 15:31:13 +090087 public static final Parcelable.Creator<IpManagerEvent> CREATOR
88 = new Parcelable.Creator<IpManagerEvent>() {
89 public IpManagerEvent createFromParcel(Parcel in) {
90 return new IpManagerEvent(in);
91 }
92
93 public IpManagerEvent[] newArray(int size) {
94 return new IpManagerEvent[size];
95 }
96 };
97
Hugo Benichi5df9d722016-04-25 17:16:35 +090098 @Override
99 public String toString() {
Hugo Benichi948a8592017-03-16 16:33:47 +0900100 return String.format("IpManagerEvent(%s, %dms)",
101 Decoder.constants.get(eventType), durationMs);
Hugo Benichi5df9d722016-04-25 17:16:35 +0900102 }
103
paulhuf32da692019-04-18 15:24:48 +0800104 @Override
105 public boolean equals(Object obj) {
106 if (obj == null || !(obj.getClass().equals(IpManagerEvent.class))) return false;
107 final IpManagerEvent other = (IpManagerEvent) obj;
108 return eventType == other.eventType
109 && durationMs == other.durationMs;
110 }
111
Hugo Benichi5df9d722016-04-25 17:16:35 +0900112 final static class Decoder {
113 static final SparseArray<String> constants = MessageUtils.findMessageNames(
Erik Klinee4526602016-10-14 18:33:22 +0900114 new Class[]{IpManagerEvent.class},
115 new String[]{"PROVISIONING_", "COMPLETE_", "ERROR_"});
Erik Kline5b25a0f2016-04-12 15:31:13 +0900116 }
Hugo Benichicfddd682016-05-31 16:28:06 +0900117}