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 extends IpConnectivityEvent 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 private ValidationProbeEvent(int netId, long durationMs, int probeType, int returnCode) { 46 this.netId = netId; 47 this.durationMs = durationMs; 48 this.probeType = probeType; 49 this.returnCode = returnCode; 50 } 51 52 private ValidationProbeEvent(Parcel in) { 53 netId = in.readInt(); 54 durationMs = in.readLong(); 55 probeType = in.readInt(); 56 returnCode = in.readInt(); 57 } 58 59 public void writeToParcel(Parcel out, int flags) { 60 out.writeInt(netId); 61 out.writeLong(durationMs); 62 out.writeInt(probeType); 63 out.writeInt(returnCode); 64 } 65 66 public int describeContents() { 67 return 0; 68 } 69 70 public static final Parcelable.Creator<ValidationProbeEvent> CREATOR 71 = new Parcelable.Creator<ValidationProbeEvent>() { 72 public ValidationProbeEvent createFromParcel(Parcel in) { 73 return new ValidationProbeEvent(in); 74 } 75 76 public ValidationProbeEvent[] newArray(int size) { 77 return new ValidationProbeEvent[size]; 78 } 79 }; 80 81 /** @hide */ 82 public static String getProbeName(int probeType) { 83 return Decoder.constants.get(probeType, "PROBE_???"); 84 } 85 86 public static void logEvent(int netId, long durationMs, int probeType, int returnCode) { 87 logEvent(new ValidationProbeEvent(netId, durationMs, probeType, 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