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