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.SystemApi; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 import android.util.SparseArray; 23 24 import com.android.internal.util.MessageUtils; 25 26 /** 27 * {@hide} 28 */ 29 @SystemApi 30 public final class IpManagerEvent extends IpConnectivityEvent implements Parcelable { 31 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 36 public final String ifName; 37 public final int eventType; 38 public final long durationMs; 39 IpManagerEvent(String ifName, int eventType, long duration)40 private IpManagerEvent(String ifName, int eventType, long duration) { 41 this.ifName = ifName; 42 this.eventType = eventType; 43 this.durationMs = duration; 44 } 45 IpManagerEvent(Parcel in)46 private IpManagerEvent(Parcel in) { 47 this.ifName = in.readString(); 48 this.eventType = in.readInt(); 49 this.durationMs = in.readLong(); 50 } 51 writeToParcel(Parcel out, int flags)52 public void writeToParcel(Parcel out, int flags) { 53 out.writeString(ifName); 54 out.writeInt(eventType); 55 out.writeLong(durationMs); 56 } 57 describeContents()58 public int describeContents() { 59 return 0; 60 } 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 logEvent(int eventType, String ifName, long durationMs)73 public static void logEvent(int eventType, String ifName, long durationMs) { 74 logEvent(new IpManagerEvent(ifName, eventType, durationMs)); 75 } 76 77 @Override toString()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_"}); 86 } 87 }; 88