• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
17 package android.net.metrics;
18 
19 import android.annotation.IntDef;
20 import android.annotation.SystemApi;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 import android.util.SparseArray;
24 
25 import com.android.internal.util.MessageUtils;
26 
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29 
30 /**
31  * An event recorded by IpManager when IP provisioning completes for a network or
32  * when a network disconnects.
33  * {@hide}
34  */
35 @SystemApi
36 public final class IpManagerEvent implements Parcelable {
37 
38     public static final int PROVISIONING_OK    = 1;
39     public static final int PROVISIONING_FAIL  = 2;
40     public static final int COMPLETE_LIFECYCLE = 3;
41 
42     /** {@hide} */
43     @IntDef(value = {PROVISIONING_OK, PROVISIONING_FAIL, COMPLETE_LIFECYCLE})
44     @Retention(RetentionPolicy.SOURCE)
45     public @interface EventType {}
46 
47     public final String ifName;
48     public final @EventType int eventType;
49     public final long durationMs;
50 
51     /** {@hide} */
IpManagerEvent(String ifName, @EventType int eventType, long duration)52     public IpManagerEvent(String ifName, @EventType int eventType, long duration) {
53         this.ifName = ifName;
54         this.eventType = eventType;
55         this.durationMs = duration;
56     }
57 
IpManagerEvent(Parcel in)58     private IpManagerEvent(Parcel in) {
59         this.ifName = in.readString();
60         this.eventType = in.readInt();
61         this.durationMs = in.readLong();
62     }
63 
64     @Override
writeToParcel(Parcel out, int flags)65     public void writeToParcel(Parcel out, int flags) {
66         out.writeString(ifName);
67         out.writeInt(eventType);
68         out.writeLong(durationMs);
69     }
70 
71     @Override
describeContents()72     public int describeContents() {
73         return 0;
74     }
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 
logEvent(int eventType, String ifName, long durationMs)87     public static void logEvent(int eventType, String ifName, long durationMs) {
88     }
89 
90     @Override
toString()91     public String toString() {
92         return String.format("IpManagerEvent(%s, %s, %dms)",
93                 ifName, Decoder.constants.get(eventType), durationMs);
94     }
95 
96     final static class Decoder {
97         static final SparseArray<String> constants = MessageUtils.findMessageNames(
98                 new Class[]{IpManagerEvent.class}, new String[]{"PROVISIONING_", "COMPLETE_"});
99     }
100 }
101