DnsEvent.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; 22 23/** 24 * {@hide} 25 */ 26@SystemApi 27final public class DnsEvent implements Parcelable { 28 public final int netId; 29 30 // The event type is currently only 1 or 2, so we store it as a byte. 31 public final byte[] eventTypes; 32 // Current getaddrinfo codes go from 1 to EAI_MAX = 15. gethostbyname returns errno, but there 33 // are fewer than 255 errno values. So we store the result code in a byte as well. 34 public final byte[] returnCodes; 35 // The latency is an integer because a) short arrays aren't parcelable and b) a short can only 36 // store a maximum latency of 32757 or 65535 ms, which is too short for pathologically slow 37 // queries. 38 public final int[] latenciesMs; 39 40 /** {@hide} */ 41 public DnsEvent(int netId, byte[] eventTypes, byte[] returnCodes, int[] latenciesMs) { 42 this.netId = netId; 43 this.eventTypes = eventTypes; 44 this.returnCodes = returnCodes; 45 this.latenciesMs = latenciesMs; 46 } 47 48 private DnsEvent(Parcel in) { 49 this.netId = in.readInt(); 50 this.eventTypes = in.createByteArray(); 51 this.returnCodes = in.createByteArray(); 52 this.latenciesMs = in.createIntArray(); 53 } 54 55 @Override 56 public void writeToParcel(Parcel out, int flags) { 57 out.writeInt(netId); 58 out.writeByteArray(eventTypes); 59 out.writeByteArray(returnCodes); 60 out.writeIntArray(latenciesMs); 61 } 62 63 public int describeContents() { 64 return 0; 65 } 66 67 @Override 68 public String toString() { 69 return String.format("DnsEvent(%d, %d events)", netId, eventTypes.length); 70 } 71 72 public static final Parcelable.Creator<DnsEvent> CREATOR = new Parcelable.Creator<DnsEvent>() { 73 @Override 74 public DnsEvent createFromParcel(Parcel in) { 75 return new DnsEvent(in); 76 } 77 78 @Override 79 public DnsEvent[] newArray(int size) { 80 return new DnsEvent[size]; 81 } 82 }; 83 84 public static void logEvent( 85 int netId, byte[] eventTypes, byte[] returnCodes, int[] latenciesMs) { 86 } 87} 88