blob: a94b9284df3b48e53a4992a2f9ab06545ac7b601 [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;
Erik Kline5b25a0f2016-04-12 15:31:13 +090020import android.os.Parcel;
21import android.os.Parcelable;
Hugo Benichi5df9d722016-04-25 17:16:35 +090022import android.util.SparseArray;
23
24import com.android.internal.util.MessageUtils;
Erik Kline5b25a0f2016-04-12 15:31:13 +090025
Hugo Benichicf6b12f2016-07-04 11:28:05 +090026import java.lang.annotation.Retention;
27import java.lang.annotation.RetentionPolicy;
28
Erik Kline5b25a0f2016-04-12 15:31:13 +090029/**
Hugo Benichicf6b12f2016-07-04 11:28:05 +090030 * An event recorded by IpManager when IP provisioning completes for a network or
31 * when a network disconnects.
Erik Kline5b25a0f2016-04-12 15:31:13 +090032 * {@hide}
33 */
Hugo Benichicfddd682016-05-31 16:28:06 +090034public final class IpManagerEvent implements Parcelable {
Hugo Benichi5df9d722016-04-25 17:16:35 +090035
Hugo Benichi95cb2262017-01-11 10:11:26 +090036 public static final int PROVISIONING_OK = 1;
37 public static final int PROVISIONING_FAIL = 2;
38 public static final int COMPLETE_LIFECYCLE = 3;
39 public static final int ERROR_STARTING_IPV4 = 4;
40 public static final int ERROR_STARTING_IPV6 = 5;
41 public static final int ERROR_STARTING_IPREACHABILITYMONITOR = 6;
Hugo Benichia4283922017-07-14 07:25:51 +090042 public static final int ERROR_INVALID_PROVISIONING = 7;
Hugo Benichi5df9d722016-04-25 17:16:35 +090043
Erik Klinee4526602016-10-14 18:33:22 +090044 @IntDef(value = {
45 PROVISIONING_OK, PROVISIONING_FAIL, COMPLETE_LIFECYCLE,
46 ERROR_STARTING_IPV4, ERROR_STARTING_IPV6, ERROR_STARTING_IPREACHABILITYMONITOR,
Hugo Benichifd31b9d2017-06-23 10:07:08 +090047 ERROR_INVALID_PROVISIONING,
Erik Klinee4526602016-10-14 18:33:22 +090048 })
Hugo Benichicf6b12f2016-07-04 11:28:05 +090049 @Retention(RetentionPolicy.SOURCE)
50 public @interface EventType {}
51
Hugo Benichicf6b12f2016-07-04 11:28:05 +090052 public final @EventType int eventType;
Hugo Benichi627b4242016-04-15 16:56:28 +090053 public final long durationMs;
Erik Kline5b25a0f2016-04-12 15:31:13 +090054
Hugo Benichi948a8592017-03-16 16:33:47 +090055 public IpManagerEvent(@EventType int eventType, long duration) {
Hugo Benichi5df9d722016-04-25 17:16:35 +090056 this.eventType = eventType;
Hugo Benichi627b4242016-04-15 16:56:28 +090057 this.durationMs = duration;
Erik Kline5b25a0f2016-04-12 15:31:13 +090058 }
59
Hugo Benichi627b4242016-04-15 16:56:28 +090060 private IpManagerEvent(Parcel in) {
Hugo Benichi5df9d722016-04-25 17:16:35 +090061 this.eventType = in.readInt();
Hugo Benichi627b4242016-04-15 16:56:28 +090062 this.durationMs = in.readLong();
Erik Kline5b25a0f2016-04-12 15:31:13 +090063 }
64
Hugo Benichicf6b12f2016-07-04 11:28:05 +090065 @Override
Erik Kline5b25a0f2016-04-12 15:31:13 +090066 public void writeToParcel(Parcel out, int flags) {
Hugo Benichi5df9d722016-04-25 17:16:35 +090067 out.writeInt(eventType);
Hugo Benichi627b4242016-04-15 16:56:28 +090068 out.writeLong(durationMs);
69 }
70
Hugo Benichicf6b12f2016-07-04 11:28:05 +090071 @Override
Hugo Benichi627b4242016-04-15 16:56:28 +090072 public int describeContents() {
73 return 0;
Erik Kline5b25a0f2016-04-12 15:31:13 +090074 }
75
76 public static final Parcelable.Creator<IpManagerEvent> CREATOR
77 = new Parcelable.Creator<IpManagerEvent>() {
78 public IpManagerEvent createFromParcel(Parcel in) {
79 return new IpManagerEvent(in);
80 }
81
82 public IpManagerEvent[] newArray(int size) {
83 return new IpManagerEvent[size];
84 }
85 };
86
Hugo Benichi5df9d722016-04-25 17:16:35 +090087 @Override
88 public String toString() {
Hugo Benichi948a8592017-03-16 16:33:47 +090089 return String.format("IpManagerEvent(%s, %dms)",
90 Decoder.constants.get(eventType), durationMs);
Hugo Benichi5df9d722016-04-25 17:16:35 +090091 }
92
93 final static class Decoder {
94 static final SparseArray<String> constants = MessageUtils.findMessageNames(
Erik Klinee4526602016-10-14 18:33:22 +090095 new Class[]{IpManagerEvent.class},
96 new String[]{"PROVISIONING_", "COMPLETE_", "ERROR_"});
Erik Kline5b25a0f2016-04-12 15:31:13 +090097 }
Hugo Benichicfddd682016-05-31 16:28:06 +090098}