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