IpManagerEvent.java revision cfddd6879283860bb4d2cf2972ea086f585a37ec
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 17package android.net.metrics; 18 19import android.annotation.SystemApi; 20import android.os.Parcel; 21import android.os.Parcelable; 22import android.util.SparseArray; 23 24import com.android.internal.util.MessageUtils; 25 26/** 27 * {@hide} 28 */ 29@SystemApi 30public final class IpManagerEvent 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 40 /** {@hide} */ 41 public IpManagerEvent(String ifName, int eventType, long duration) { 42 this.ifName = ifName; 43 this.eventType = eventType; 44 this.durationMs = duration; 45 } 46 47 private IpManagerEvent(Parcel in) { 48 this.ifName = in.readString(); 49 this.eventType = in.readInt(); 50 this.durationMs = in.readLong(); 51 } 52 53 public void writeToParcel(Parcel out, int flags) { 54 out.writeString(ifName); 55 out.writeInt(eventType); 56 out.writeLong(durationMs); 57 } 58 59 public int describeContents() { 60 return 0; 61 } 62 63 public static final Parcelable.Creator<IpManagerEvent> CREATOR 64 = new Parcelable.Creator<IpManagerEvent>() { 65 public IpManagerEvent createFromParcel(Parcel in) { 66 return new IpManagerEvent(in); 67 } 68 69 public IpManagerEvent[] newArray(int size) { 70 return new IpManagerEvent[size]; 71 } 72 }; 73 74 public static void logEvent(int eventType, String ifName, long 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_"}); 86 } 87} 88