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.os.Parcel; 21 import android.os.Parcelable; 22 import android.util.SparseArray; 23 24 import com.android.internal.util.MessageUtils; 25 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 29 /** 30 * An event recorded by IpManager when IP provisioning completes for a network or 31 * when a network disconnects. 32 * {@hide} 33 */ 34 public final class IpManagerEvent implements Parcelable { 35 36 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; 42 public static final int ERROR_INVALID_PROVISIONING = 7; 43 public static final int ERROR_INTERFACE_NOT_FOUND = 8; 44 45 @IntDef(value = { 46 PROVISIONING_OK, PROVISIONING_FAIL, COMPLETE_LIFECYCLE, 47 ERROR_STARTING_IPV4, ERROR_STARTING_IPV6, ERROR_STARTING_IPREACHABILITYMONITOR, 48 ERROR_INVALID_PROVISIONING, ERROR_INTERFACE_NOT_FOUND, 49 }) 50 @Retention(RetentionPolicy.SOURCE) 51 public @interface EventType {} 52 53 public final @EventType int eventType; 54 public final long durationMs; 55 IpManagerEvent(@ventType int eventType, long duration)56 public IpManagerEvent(@EventType int eventType, long duration) { 57 this.eventType = eventType; 58 this.durationMs = duration; 59 } 60 IpManagerEvent(Parcel in)61 private IpManagerEvent(Parcel in) { 62 this.eventType = in.readInt(); 63 this.durationMs = in.readLong(); 64 } 65 66 @Override writeToParcel(Parcel out, int flags)67 public void writeToParcel(Parcel out, int flags) { 68 out.writeInt(eventType); 69 out.writeLong(durationMs); 70 } 71 72 @Override describeContents()73 public int describeContents() { 74 return 0; 75 } 76 77 public static final Parcelable.Creator<IpManagerEvent> CREATOR 78 = new Parcelable.Creator<IpManagerEvent>() { 79 public IpManagerEvent createFromParcel(Parcel in) { 80 return new IpManagerEvent(in); 81 } 82 83 public IpManagerEvent[] newArray(int size) { 84 return new IpManagerEvent[size]; 85 } 86 }; 87 88 @Override toString()89 public String toString() { 90 return String.format("IpManagerEvent(%s, %dms)", 91 Decoder.constants.get(eventType), durationMs); 92 } 93 94 final static class Decoder { 95 static final SparseArray<String> constants = MessageUtils.findMessageNames( 96 new Class[]{IpManagerEvent.class}, 97 new String[]{"PROVISIONING_", "COMPLETE_", "ERROR_"}); 98 } 99 } 100