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.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.SystemApi; 23 import android.os.Parcel; 24 import android.os.Parcelable; 25 import android.util.SparseArray; 26 27 import com.android.internal.util.MessageUtils; 28 29 import java.lang.annotation.Retention; 30 import java.lang.annotation.RetentionPolicy; 31 32 /** 33 * An event recorded by IpClient when IP provisioning completes for a network or 34 * when a network disconnects. 35 * {@hide} 36 * @deprecated The event may not be sent in Android S and above. The events 37 * are logged by a single caller in the system using signature permissions 38 * and that caller is migrating to statsd. 39 */ 40 @Deprecated 41 @SystemApi 42 public final class IpManagerEvent implements IpConnectivityLog.Event { 43 44 public static final int PROVISIONING_OK = 1; 45 public static final int PROVISIONING_FAIL = 2; 46 public static final int COMPLETE_LIFECYCLE = 3; 47 public static final int ERROR_STARTING_IPV4 = 4; 48 public static final int ERROR_STARTING_IPV6 = 5; 49 public static final int ERROR_STARTING_IPREACHABILITYMONITOR = 6; 50 public static final int ERROR_INVALID_PROVISIONING = 7; 51 public static final int ERROR_INTERFACE_NOT_FOUND = 8; 52 53 /** @hide */ 54 @IntDef(value = { 55 PROVISIONING_OK, PROVISIONING_FAIL, COMPLETE_LIFECYCLE, 56 ERROR_STARTING_IPV4, ERROR_STARTING_IPV6, ERROR_STARTING_IPREACHABILITYMONITOR, 57 ERROR_INVALID_PROVISIONING, ERROR_INTERFACE_NOT_FOUND, 58 }) 59 @Retention(RetentionPolicy.SOURCE) 60 public @interface EventType {} 61 62 /** @hide */ 63 public final @EventType int eventType; 64 /** @hide */ 65 public final long durationMs; 66 IpManagerEvent(@ventType int eventType, long duration)67 public IpManagerEvent(@EventType int eventType, long duration) { 68 this.eventType = eventType; 69 this.durationMs = duration; 70 } 71 IpManagerEvent(Parcel in)72 private IpManagerEvent(Parcel in) { 73 this.eventType = in.readInt(); 74 this.durationMs = in.readLong(); 75 } 76 77 /** @hide */ 78 @Override writeToParcel(Parcel out, int flags)79 public void writeToParcel(Parcel out, int flags) { 80 out.writeInt(eventType); 81 out.writeLong(durationMs); 82 } 83 84 /** @hide */ 85 @Override describeContents()86 public int describeContents() { 87 return 0; 88 } 89 90 /** @hide */ 91 public static final @android.annotation.NonNull Parcelable.Creator<IpManagerEvent> CREATOR 92 = new Parcelable.Creator<IpManagerEvent>() { 93 public IpManagerEvent createFromParcel(Parcel in) { 94 return new IpManagerEvent(in); 95 } 96 97 public IpManagerEvent[] newArray(int size) { 98 return new IpManagerEvent[size]; 99 } 100 }; 101 102 @NonNull 103 @Override toString()104 public String toString() { 105 return String.format("IpManagerEvent(%s, %dms)", 106 Decoder.constants.get(eventType), durationMs); 107 } 108 109 @Override equals(@ullable Object obj)110 public boolean equals(@Nullable Object obj) { 111 if (obj == null || !(obj.getClass().equals(IpManagerEvent.class))) return false; 112 final IpManagerEvent other = (IpManagerEvent) obj; 113 return eventType == other.eventType 114 && durationMs == other.durationMs; 115 } 116 117 final static class Decoder { 118 static final SparseArray<String> constants = MessageUtils.findMessageNames( 119 new Class[]{IpManagerEvent.class}, 120 new String[]{"PROVISIONING_", "COMPLETE_", "ERROR_"}); 121 } 122 } 123