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.IntDef; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 import android.util.SparseArray; 24 25 import com.android.internal.util.MessageUtils; 26 27 import java.lang.annotation.Retention; 28 import java.lang.annotation.RetentionPolicy; 29 30 /** 31 * An event recorded by NetworkMonitor when sending a probe for finding captive portals. 32 * {@hide} 33 */ 34 @SystemApi 35 public final class ValidationProbeEvent implements Parcelable { 36 37 public static final int PROBE_DNS = 0; 38 public static final int PROBE_HTTP = 1; 39 public static final int PROBE_HTTPS = 2; 40 public static final int PROBE_PAC = 3; 41 /** {@hide} */ 42 public static final int PROBE_FALLBACK = 4; 43 44 public static final int DNS_FAILURE = 0; 45 public static final int DNS_SUCCESS = 1; 46 47 /** {@hide} */ 48 @IntDef(value = {PROBE_DNS, PROBE_HTTP, PROBE_HTTPS, PROBE_PAC}) 49 @Retention(RetentionPolicy.SOURCE) 50 public @interface ProbeType {} 51 52 /** {@hide} */ 53 @IntDef(value = {DNS_FAILURE, DNS_SUCCESS}) 54 @Retention(RetentionPolicy.SOURCE) 55 public @interface ReturnCode {} 56 57 public final int netId; 58 public final long durationMs; 59 public final @ProbeType int probeType; 60 public final @ReturnCode int returnCode; 61 62 /** {@hide} */ 63 public ValidationProbeEvent( 64 int netId, long durationMs, @ProbeType int probeType, @ReturnCode int returnCode) { 65 this.netId = netId; 66 this.durationMs = durationMs; 67 this.probeType = probeType; 68 this.returnCode = returnCode; 69 } 70 71 private ValidationProbeEvent(Parcel in) { 72 netId = in.readInt(); 73 durationMs = in.readLong(); 74 probeType = in.readInt(); 75 returnCode = in.readInt(); 76 } 77 78 @Override 79 public void writeToParcel(Parcel out, int flags) { 80 out.writeInt(netId); 81 out.writeLong(durationMs); 82 out.writeInt(probeType); 83 out.writeInt(returnCode); 84 } 85 86 @Override 87 public int describeContents() { 88 return 0; 89 } 90 91 public static final Parcelable.Creator<ValidationProbeEvent> CREATOR 92 = new Parcelable.Creator<ValidationProbeEvent>() { 93 public ValidationProbeEvent createFromParcel(Parcel in) { 94 return new ValidationProbeEvent(in); 95 } 96 97 public ValidationProbeEvent[] newArray(int size) { 98 return new ValidationProbeEvent[size]; 99 } 100 }; 101 102 /** @hide */ 103 public static String getProbeName(int probeType) { 104 return Decoder.constants.get(probeType, "PROBE_???"); 105 } 106 107 public static void logEvent(int netId, long durationMs, int probeType, int returnCode) { 108 } 109 110 @Override 111 public String toString() { 112 return String.format("ValidationProbeEvent(%d, %s:%d, %dms)", 113 netId, getProbeName(probeType), returnCode, durationMs); 114 } 115 116 final static class Decoder { 117 static final SparseArray<String> constants = MessageUtils.findMessageNames( 118 new Class[]{ValidationProbeEvent.class}, new String[]{"PROBE_"}); 119 } 120 } 121