blob: fcc76085d60785c79438d858fc08bd077bc715b4 [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 Benichi4b6dfc22016-04-15 12:15:47 +090019import android.annotation.SystemApi;
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
26/**
27 * {@hide}
28 */
Hugo Benichi4b6dfc22016-04-15 12:15:47 +090029@SystemApi
Hugo Benichi627b4242016-04-15 16:56:28 +090030public final class IpManagerEvent extends IpConnectivityEvent implements Parcelable {
Hugo Benichi5df9d722016-04-25 17:16:35 +090031
32 public static final int PROVISIONING_OK = 1;
33 public static final int PROVISIONING_FAIL = 2;
34 public static final int COMPLETE_LIFECYCLE = 3;
35
Hugo Benichi627b4242016-04-15 16:56:28 +090036 public final String ifName;
Hugo Benichi5df9d722016-04-25 17:16:35 +090037 public final int eventType;
Hugo Benichi627b4242016-04-15 16:56:28 +090038 public final long durationMs;
Erik Kline5b25a0f2016-04-12 15:31:13 +090039
Hugo Benichi5df9d722016-04-25 17:16:35 +090040 private IpManagerEvent(String ifName, int eventType, long duration) {
Hugo Benichi627b4242016-04-15 16:56:28 +090041 this.ifName = ifName;
Hugo Benichi5df9d722016-04-25 17:16:35 +090042 this.eventType = eventType;
Hugo Benichi627b4242016-04-15 16:56:28 +090043 this.durationMs = duration;
Erik Kline5b25a0f2016-04-12 15:31:13 +090044 }
45
Hugo Benichi627b4242016-04-15 16:56:28 +090046 private IpManagerEvent(Parcel in) {
47 this.ifName = in.readString();
Hugo Benichi5df9d722016-04-25 17:16:35 +090048 this.eventType = in.readInt();
Hugo Benichi627b4242016-04-15 16:56:28 +090049 this.durationMs = in.readLong();
Erik Kline5b25a0f2016-04-12 15:31:13 +090050 }
51
52 public void writeToParcel(Parcel out, int flags) {
Hugo Benichi627b4242016-04-15 16:56:28 +090053 out.writeString(ifName);
Hugo Benichi5df9d722016-04-25 17:16:35 +090054 out.writeInt(eventType);
Hugo Benichi627b4242016-04-15 16:56:28 +090055 out.writeLong(durationMs);
56 }
57
58 public int describeContents() {
59 return 0;
Erik Kline5b25a0f2016-04-12 15:31:13 +090060 }
61
62 public static final Parcelable.Creator<IpManagerEvent> CREATOR
63 = new Parcelable.Creator<IpManagerEvent>() {
64 public IpManagerEvent createFromParcel(Parcel in) {
65 return new IpManagerEvent(in);
66 }
67
68 public IpManagerEvent[] newArray(int size) {
69 return new IpManagerEvent[size];
70 }
71 };
72
73 public static void logEvent(int eventType, String ifName, long durationMs) {
Hugo Benichi5df9d722016-04-25 17:16:35 +090074 logEvent(IPCE_IPMGR_BASE, new IpManagerEvent(ifName, eventType, durationMs));
75 }
76
77 @Override
78 public String toString() {
79 return String.format("IpManagerEvent(%s, %s, %dms)",
80 ifName, Decoder.constants.get(eventType), durationMs);
81 }
82
83 final static class Decoder {
84 static final SparseArray<String> constants = MessageUtils.findMessageNames(
85 new Class[]{IpManagerEvent.class}, new String[]{"PROVISIONING_", "COMPLETE_"});
Erik Kline5b25a0f2016-04-12 15:31:13 +090086 }
87};