ValidationProbeEvent.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 ValidationProbeEvent implements Parcelable { 31 32 public static final int PROBE_DNS = 0; 33 public static final int PROBE_HTTP = 1; 34 public static final int PROBE_HTTPS = 2; 35 public static final int PROBE_PAC = 3; 36 37 public static final int DNS_FAILURE = 0; 38 public static final int DNS_SUCCESS = 1; 39 40 public final int netId; 41 public final long durationMs; 42 public final int probeType; 43 public final int returnCode; 44 45 /** @hide */ 46 public ValidationProbeEvent(int netId, long durationMs, int probeType, int returnCode) { 47 this.netId = netId; 48 this.durationMs = durationMs; 49 this.probeType = probeType; 50 this.returnCode = returnCode; 51 } 52 53 private ValidationProbeEvent(Parcel in) { 54 netId = in.readInt(); 55 durationMs = in.readLong(); 56 probeType = in.readInt(); 57 returnCode = in.readInt(); 58 } 59 60 public void writeToParcel(Parcel out, int flags) { 61 out.writeInt(netId); 62 out.writeLong(durationMs); 63 out.writeInt(probeType); 64 out.writeInt(returnCode); 65 } 66 67 public int describeContents() { 68 return 0; 69 } 70 71 public static final Parcelable.Creator<ValidationProbeEvent> CREATOR 72 = new Parcelable.Creator<ValidationProbeEvent>() { 73 public ValidationProbeEvent createFromParcel(Parcel in) { 74 return new ValidationProbeEvent(in); 75 } 76 77 public ValidationProbeEvent[] newArray(int size) { 78 return new ValidationProbeEvent[size]; 79 } 80 }; 81 82 /** @hide */ 83 public static String getProbeName(int probeType) { 84 return Decoder.constants.get(probeType, "PROBE_???"); 85 } 86 87 public static void logEvent(int netId, long durationMs, int probeType, int returnCode) { 88 } 89 90 @Override 91 public String toString() { 92 return String.format("ValidationProbeEvent(%d, %s:%d, %dms)", 93 netId, getProbeName(probeType), returnCode, durationMs); 94 } 95 96 final static class Decoder { 97 static final SparseArray<String> constants = MessageUtils.findMessageNames( 98 new Class[]{ValidationProbeEvent.class}, new String[]{"PROBE_"}); 99 } 100} 101